transfer and withdraw

This commit is contained in:
Tokumeikoi 2020-05-10 18:38:02 +08:00
parent c46b8b1b40
commit 15a28e7bd3
7 changed files with 94 additions and 3 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Http\Requests\User\TicketSave;
use App\Http\Requests\User\TicketWithdraw;
use Illuminate\Http\Request;
use App\Models\Ticket;
use App\Models\TicketMessage;
@ -144,4 +145,40 @@ class TicketController extends Controller
->orderBy('id', 'DESC')
->first();
}
public function withdraw(TicketWithdraw $request)
{
DB::beginTransaction();
$subject = '[提现申请]本工单由系统发出';
$ticket = Ticket::create([
'subject' => $subject,
'level' => 2,
'user_id' => $request->session()->get('id'),
'last_reply_user_id' => $request->session()->get('id')
]);
if (!$ticket) {
DB::rollback();
abort(500, '工单创建失败');
}
$methodText = [
'alipay' => '支付宝',
'paypal' => '贝宝(Paypal)',
'usdt' => 'USDT',
'btc' => '比特币'
];
$message = "提现方式:{$methodText[$request->input('withdraw_method')]}\r\n提现账号:{$request->input('withdraw_account')}\r\n";
$ticketMessage = TicketMessage::create([
'user_id' => $request->session()->get('id'),
'ticket_id' => $ticket->id,
'message' => $message
]);
if (!$ticketMessage) {
DB::rollback();
abort(500, '工单创建失败');
}
DB::commit();
return response([
'data' => true
]);
}
}

View File

@ -137,4 +137,26 @@ class UserController extends Controller
'data' => true
]);
}
public function transfer(Request $request)
{
$user = User::find($request->session()->get('id'));
if (!$user) {
abort(500, '该用户不存在');
}
if ($request->input('transfer_amount') <= 0) {
abort(500, '参数错误');
}
if ($request->input('transfer_amount') > $user->commission_balance) {
abort(500, '推广佣金余额不足');
}
$user->commission_balance = $user->commission_balance - $request->input('transfer_amount');
$user->balance = $user->balance + $request->input('transfer_amount');
if (!$user->save()) {
abort(500, '划转失败');
}
return response([
'data' => true
]);
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests\User;
use Illuminate\Foundation\Http\FormRequest;
class TicketWithdraw extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'withdraw_method' => 'required|in:alipay,paypal,usdt,btc',
'withdraw_account' => 'required'
];
}
public function messages()
{
return [
'withdraw_method.required' => '提现方式不能为空',
'withdraw_method.in' => '提现方式不支持',
'withdraw_account.required' => '提现账号不能为空'
];
}
}

View File

@ -19,6 +19,7 @@ class UserRoute
$router->post('/update', 'User\\UserController@update');
$router->get ('/getSubscribe', 'User\\UserController@getSubscribe');
$router->get ('/getStat', 'User\\UserController@getStat');
$router->post('/transfer', 'User\\UserController@transfer');
// Order
$router->post('/order/save', 'User\\OrderController@save');
$router->post('/order/checkout', 'User\\OrderController@checkout');
@ -44,6 +45,7 @@ class UserRoute
$router->post('/ticket/close', 'User\\TicketController@close');
$router->post('/ticket/save', 'User\\TicketController@save');
$router->get ('/ticket/fetch', 'User\\TicketController@fetch');
$router->post('/ticket/withdraw', 'User\\TicketController@withdraw');
// Server
$router->get ('/server/fetch', 'User\\ServerController@fetch');
$router->get ('/server/log/fetch', 'User\\ServerController@logFetch');

View File

@ -236,5 +236,5 @@ return [
| The only modification by laravel config
|
*/
'version' => '1.3'
'version' => '1.3-pre5'
];

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long