*
Showing
7 changed files
with
178 additions
and
148 deletions
| ... | @@ -21,7 +21,7 @@ class Response | ... | @@ -21,7 +21,7 @@ class Response |
| 21 | { | 21 | { |
| 22 | return response()->json([ | 22 | return response()->json([ |
| 23 | 'code' => ErrorCode::SERVER_OK, | 23 | 'code' => ErrorCode::SERVER_OK, |
| 24 | 'data' => $data instanceof LengthAwarePaginator ? self::paginator($data) : $data | 24 | 'data' => $data instanceof LengthAwarePaginator ? self::paginator($data) : $data |
| 25 | ]); | 25 | ]); |
| 26 | } | 26 | } |
| 27 | 27 | ... | ... |
| ... | @@ -3,9 +3,15 @@ | ... | @@ -3,9 +3,15 @@ |
| 3 | namespace App\Http\Controllers\Musician; | 3 | namespace App\Http\Controllers\Musician; |
| 4 | 4 | ||
| 5 | use App\Http\Controllers\Controller; | 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Http\Requests\Musician\MusicianWithdrawReceiptRequest; | ||
| 6 | use App\Http\Requests\Musician\MusicianWithdrawRequest; | 7 | use App\Http\Requests\Musician\MusicianWithdrawRequest; |
| 8 | use App\Http\Requests\Musician\MusicianWithdrawStatusRequest; | ||
| 7 | use App\Services\MusicianWithdrawService; | 9 | use App\Services\MusicianWithdrawService; |
| 8 | 10 | ||
| 11 | /** | ||
| 12 | * Class MusicianWithdrawController | ||
| 13 | * @package App\Http\Controllers\Musician | ||
| 14 | */ | ||
| 9 | class MusicianWithdrawController extends Controller | 15 | class MusicianWithdrawController extends Controller |
| 10 | { | 16 | { |
| 11 | /** | 17 | /** |
| ... | @@ -23,12 +29,20 @@ class MusicianWithdrawController extends Controller | ... | @@ -23,12 +29,20 @@ class MusicianWithdrawController extends Controller |
| 23 | } | 29 | } |
| 24 | 30 | ||
| 25 | /** | 31 | /** |
| 26 | * 冻结资金 | 32 | * 发票信息 |
| 27 | * @return \Illuminate\Http\JsonResponse | 33 | * @return \Illuminate\Http\JsonResponse |
| 28 | */ | 34 | */ |
| 29 | public function prepare(MusicianWithdrawRequest $musicianWithdrawRequest) | 35 | public function receipt(MusicianWithdrawReceiptRequest $request) |
| 30 | { | 36 | { |
| 31 | return $this->musicianWithdrawService->prepare(); | 37 | return $this->musicianWithdrawService->receiptInfo(); |
| 32 | } | 38 | } |
| 33 | 39 | ||
| 40 | /** | ||
| 41 | * 提现修改状态 | ||
| 42 | * @return \Illuminate\Http\JsonResponse | ||
| 43 | */ | ||
| 44 | public function status(MusicianWithdrawStatusRequest $request) | ||
| 45 | { | ||
| 46 | return $this->musicianWithdrawService->changeStatus(); | ||
| 47 | } | ||
| 34 | } | 48 | } | ... | ... |
| 1 | <?php | ||
| 2 | |||
| 3 | namespace App\Http\Requests\Musician; | ||
| 4 | |||
| 5 | use Illuminate\Foundation\Http\FormRequest; | ||
| 6 | |||
| 7 | class MusicianWithdrawReceiptRequest extends FormRequest | ||
| 8 | { | ||
| 9 | /** | ||
| 10 | * Determine if the user is authorized to make this request. | ||
| 11 | * | ||
| 12 | * @return bool | ||
| 13 | */ | ||
| 14 | public function authorize() | ||
| 15 | { | ||
| 16 | return true; | ||
| 17 | } | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Get the validation rules that apply to the request. | ||
| 21 | * | ||
| 22 | * @return array | ||
| 23 | */ | ||
| 24 | public function rules() | ||
| 25 | { | ||
| 26 | return [ | ||
| 27 | 'serial_no' => ['required', 'bail', 'array', 'filled'], | ||
| 28 | ]; | ||
| 29 | } | ||
| 30 | |||
| 31 | /** | ||
| 32 | * @return string[] | ||
| 33 | */ | ||
| 34 | public function messages(): array | ||
| 35 | { | ||
| 36 | return [ | ||
| 37 | 'serial_no.required' => '请提供流水号', | ||
| 38 | ]; | ||
| 39 | } | ||
| 40 | } |
| 1 | <?php | ||
| 2 | |||
| 3 | namespace App\Http\Requests\Musician; | ||
| 4 | |||
| 5 | use Illuminate\Foundation\Http\FormRequest; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * Class MusicianWithdrawStatusRequest | ||
| 9 | * @package App\Http\Requests\Musician | ||
| 10 | */ | ||
| 11 | class MusicianWithdrawStatusRequest extends FormRequest | ||
| 12 | { | ||
| 13 | /** | ||
| 14 | * Determine if the user is authorized to make this request. | ||
| 15 | * | ||
| 16 | * @return bool | ||
| 17 | */ | ||
| 18 | public function authorize() | ||
| 19 | { | ||
| 20 | return true; | ||
| 21 | } | ||
| 22 | |||
| 23 | /** | ||
| 24 | * Get the validation rules that apply to the request. | ||
| 25 | * | ||
| 26 | * @return array | ||
| 27 | */ | ||
| 28 | public function rules() | ||
| 29 | { | ||
| 30 | return [ | ||
| 31 | 'serial_no' => ['required', 'bail', 'array', 'filled'], | ||
| 32 | 'type' => ['required', 'bail', 'in:success,fail,advance'], | ||
| 33 | ]; | ||
| 34 | } | ||
| 35 | |||
| 36 | /** | ||
| 37 | * @return string[] | ||
| 38 | */ | ||
| 39 | public function messages(): array | ||
| 40 | { | ||
| 41 | return [ | ||
| 42 | 'serial_no.required'=> '请提供流水号', | ||
| 43 | 'type.required' => '请提供有效的提现状态变更', | ||
| 44 | ]; | ||
| 45 | } | ||
| 46 | } |
| 1 | <?php | ||
| 2 | |||
| 3 | namespace App\Models\Legal; | ||
| 4 | |||
| 5 | use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
| 6 | use Illuminate\Database\Eloquent\Model; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * 进账收益流水 | ||
| 10 | * Class StakeholderIncomeByPayer | ||
| 11 | * @package App\Models\Legal | ||
| 12 | */ | ||
| 13 | class StakeholderIncomeByPayer extends Model | ||
| 14 | { | ||
| 15 | use HasFactory; | ||
| 16 | |||
| 17 | public $table = 'stakeholder_income_by_payer'; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
| 21 | */ | ||
| 22 | public function company() | ||
| 23 | { | ||
| 24 | return $this->belongsTo(Company::class, 'company_id', 'company_id'); | ||
| 25 | } | ||
| 26 | } |
| ... | @@ -3,13 +3,8 @@ | ... | @@ -3,13 +3,8 @@ |
| 3 | namespace App\Services; | 3 | namespace App\Services; |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | use App\Helper\ErrorCode; | ||
| 7 | use App\Helper\RedisClient; | ||
| 8 | use App\Helper\Response; | 6 | use App\Helper\Response; |
| 9 | use App\Models\Legal\StakeholderBalance; | 7 | use App\Models\Legal\StakeholderIncomeByPayer; |
| 10 | use App\Models\Legal\StakeholderBalanceByPayer; | ||
| 11 | use App\Models\Musician\CashOutOrder; | ||
| 12 | use Illuminate\Support\Facades\DB; | ||
| 13 | 8 | ||
| 14 | /** | 9 | /** |
| 15 | * Class MusicianAgreementService | 10 | * Class MusicianAgreementService |
| ... | @@ -18,154 +13,60 @@ use Illuminate\Support\Facades\DB; | ... | @@ -18,154 +13,60 @@ use Illuminate\Support\Facades\DB; |
| 18 | class MusicianWithdrawService extends Service | 13 | class MusicianWithdrawService extends Service |
| 19 | { | 14 | { |
| 20 | /** | 15 | /** |
| 21 | * 冻结资金 | 16 | * 发票信息 |
| 22 | * @return \Illuminate\Http\JsonResponse | 17 | * @return \Illuminate\Http\JsonResponse |
| 23 | */ | 18 | */ |
| 24 | public function prepare() | 19 | public function receiptInfo() |
| 25 | { | 20 | { |
| 26 | $order_id = $this->request->input('order_id'); | 21 | $receipt = []; |
| 27 | 22 | ||
| 28 | if (!RedisClient::instance()->set(str_replace('#order#', $order_id, config('cachekey.withdraw.prepare')), true, "nx", "ex", 3)) { | 23 | StakeholderIncomeByPayer::query()->with('company:company_id,receipt_name,receipt_no,receipt_tel,receipt_address,receipt_bank,receipt_bank_no') |
| 29 | return Response::error(ErrorCode::REPEAT_SUBMIT); | 24 | ->whereIn('serial_no', $this->request->input('serial_no'))->get()->map(function ($item) use (&$receipt) { |
| 30 | } | 25 | |
| 31 | 26 | if (!empty($item->company)) { | |
| 32 | $order = CashOutOrder::query()->where(['order_id'=>$order_id, 'withdraw_state'=>CashOutOrder::WITHDRAW_STATE_DEFAULT, 'status'=>CashOutOrder::STATUS_WAIT])->first(); | 27 | $receipt[$item->company_id] = [ |
| 33 | 28 | 'receipt_name'=>$item->company->receipt_name, | |
| 34 | //订单非法 | 29 | 'receipt_no' =>$item->company->receipt_no, |
| 35 | if (empty($order)) return Response::error(ErrorCode::ORDER_ILLEGAl); | 30 | 'receipt_tel' =>$item->company->receipt_tel, |
| 36 | if (empty($order->balance_detail)) return Response::error(ErrorCode::ORDER_WITHDRAW_ERROR); | 31 | 'receipt_address'=>$item->company->receipt_address, |
| 37 | if (empty($order->cash_out_money)) return Response::error(ErrorCode::ORDER_MONEY_ERROR); | 32 | 'receipt_bank'=>$item->company->receipt_bank, |
| 38 | 33 | 'receipt_bank_no'=>$item->company->receipt_bank_no, | |
| 39 | Db::beginTransaction(); | 34 | ]; |
| 40 | try { | 35 | } |
| 41 | //付款方集合 | 36 | |
| 42 | foreach ($order->balance_detail['detail'] as $item) { | 37 | return $receipt; |
| 43 | 38 | }); | |
| 44 | //付款方账户 | 39 | |
| 45 | StakeholderBalanceByPayer::query()->where(['stakeholder_id'=>$item['stakeholderId'], 'subject_no'=>$item['no']]) | 40 | return Response::success($receipt); |
| 46 | ->where('balance', '>=', $item['balance']) | ||
| 47 | ->update([ | ||
| 48 | 'balance'=>Db::raw("balance - {$item['balance']}"), | ||
| 49 | 'freeze'=>Db::raw("freeze + {$item['balance']}"), | ||
| 50 | ]); | ||
| 51 | |||
| 52 | //总账户 | ||
| 53 | StakeholderBalance::query()->where(['stakeholder_id'=>$item['stakeholderId']])->where('balance', '>=', $item['balance']) | ||
| 54 | ->update([ | ||
| 55 | 'balance'=>Db::raw("balance - {$item['balance']}"), | ||
| 56 | 'freeze'=>Db::raw("freeze + {$item['balance']}"), | ||
| 57 | ]); | ||
| 58 | } | ||
| 59 | |||
| 60 | CashOutOrder::query()->where(['order_id'=>$order_id, 'withdraw_state'=>CashOutOrder::WITHDRAW_STATE_DEFAULT, 'status'=>CashOutOrder::STATUS_WAIT])->update([ | ||
| 61 | 'withdraw_state' => CashOutOrder::WITHDRAW_STATE_WAIT, | ||
| 62 | ]); | ||
| 63 | |||
| 64 | DB::commit(); | ||
| 65 | |||
| 66 | return Response::success(['order_id'=>$order->order_id]); | ||
| 67 | |||
| 68 | } catch (\Exception $e) { | ||
| 69 | DB::rollBack(); | ||
| 70 | return Response::error(); | ||
| 71 | } | ||
| 72 | |||
| 73 | } | 41 | } |
| 74 | 42 | ||
| 75 | /** | 43 | /** |
| 76 | * 后台提现 | 44 | * 修改提现状态 |
| 77 | * @return \Illuminate\Http\JsonResponse | 45 | * @return \Illuminate\Http\JsonResponse|mixed |
| 78 | */ | 46 | */ |
| 79 | public function withdraw() | 47 | public function changeStatus() |
| 80 | { | 48 | { |
| 81 | $order_id = $this->request->input('order_id'); | 49 | $withdraw_status = ''; |
| 82 | 50 | ||
| 83 | if (!RedisClient::instance()->set(str_replace('#order#', $order_id, config('cachekey.withdraw.audit')), true, "nx", "ex", 3)) { | 51 | switch ($this->request->input('type')) { |
| 84 | return Response::error(ErrorCode::REPEAT_SUBMIT); | 52 | case 'fail': |
| 53 | $withdraw_status = 0; | ||
| 54 | break; | ||
| 55 | case 'advance': | ||
| 56 | $withdraw_status = 1; | ||
| 57 | break; | ||
| 58 | case 'success': | ||
| 59 | $withdraw_status = 2; | ||
| 60 | break; | ||
| 85 | } | 61 | } |
| 86 | 62 | ||
| 87 | $order = CashOutOrder::query()->where(['order_id'=>$order_id, 'withdraw_state'=>CashOutOrder::WITHDRAW_STATE_WAIT, 'status'=>$this->request->input('status')])->first(); | ||
| 88 | |||
| 89 | //订单非法 | ||
| 90 | if (empty($order)) return Response::error(ErrorCode::ORDER_ILLEGAl); | ||
| 91 | if (empty($order->balance_detail)) return Response::error(ErrorCode::ORDER_WITHDRAW_ERROR); | ||
| 92 | |||
| 93 | Db::beginTransaction(); | ||
| 94 | |||
| 95 | try { | ||
| 96 | |||
| 97 | switch (intval($this->request->input('status'))) { | ||
| 98 | case 1: | ||
| 99 | //审核通过 | ||
| 100 | $this->withdrawAuditSuccess($order); | ||
| 101 | break; | ||
| 102 | case 2: | ||
| 103 | //审核失败 | ||
| 104 | $this->withdrawAuditFail($order); | ||
| 105 | break; | ||
| 106 | } | ||
| 107 | |||
| 108 | CashOutOrder::query()->where(['order_id'=>$order_id, 'withdraw_state'=>CashOutOrder::WITHDRAW_STATE_WAIT, 'status'=>$this->request->input('status')])->update([ | ||
| 109 | 'withdraw_state'=>$this->request->input('status') | ||
| 110 | ]); | ||
| 111 | 63 | ||
| 112 | Db::commit(); | 64 | if (StakeholderIncomeByPayer::query()->whereIn('serial_no', $this->request->input('serial_no'))->update([ |
| 65 | 'withdraw_status'=>$withdraw_status, | ||
| 66 | ])) { | ||
| 113 | return Response::success(); | 67 | return Response::success(); |
| 114 | 68 | } else { | |
| 115 | } catch (\Exception $e) { | 69 | return Response::error(); |
| 116 | Db::rollBack(); | ||
| 117 | return Response::error(ErrorCode::WITHDRAW_HANDLE_ERROR); | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | /** | ||
| 122 | * 提现审核成功 | ||
| 123 | * @param CashOutOrder $order | ||
| 124 | */ | ||
| 125 | private function withdrawAuditSuccess(CashOutOrder $order) | ||
| 126 | { | ||
| 127 | foreach ($order->balance_detail['detail'] as $item) { | ||
| 128 | |||
| 129 | //付款方维度 | ||
| 130 | StakeholderBalanceByPayer::query()->where(['stakeholder_id'=>$item['stakeholderId'], 'subject_no'=>$item['no']]) | ||
| 131 | ->where('freeze', '>=', $item['balance']) | ||
| 132 | ->update([ | ||
| 133 | 'freeze'=>Db::raw("freeze - {$item['balance']}"), | ||
| 134 | 'pay_out'=>Db::raw("pay_out + {$item['balance']}"), | ||
| 135 | ]); | ||
| 136 | |||
| 137 | //修改总的资金账户 | ||
| 138 | StakeholderBalance::query()->where(['stakeholder_id'=>$item['stakeholderId']])->where('freeze', '>=', $item['balance']) | ||
| 139 | ->update([ | ||
| 140 | 'freeze'=>Db::raw("freeze - {$item['balance']}"), | ||
| 141 | 'pay_out'=>Db::raw("pay_out + {$item['balance']}"), | ||
| 142 | ]); | ||
| 143 | |||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | /** | ||
| 148 | * 提现审核失败 | ||
| 149 | * @param CashOutOrder $order | ||
| 150 | */ | ||
| 151 | private function withdrawAuditFail(CashOutOrder $order) | ||
| 152 | { | ||
| 153 | |||
| 154 | foreach ($order->balance_detail['detail'] as $item) { | ||
| 155 | |||
| 156 | StakeholderBalanceByPayer::query()->where(['stakeholder_id'=>$item['stakeholderId'], 'subject_no'=>$item['no']]) | ||
| 157 | ->where('freeze', '>=', $item['balance']) | ||
| 158 | ->update([ | ||
| 159 | 'freeze'=>Db::raw("freeze - {$item['balance']}"), | ||
| 160 | 'balance'=>Db::raw("balance + {$item['balance']}"), | ||
| 161 | ]); | ||
| 162 | |||
| 163 | StakeholderBalance::query()->where(['stakeholder_id'=>$item['stakeholderId']])->where('freeze', '>=', $item['balance']) | ||
| 164 | ->update([ | ||
| 165 | 'freeze'=>Db::raw("freeze - {$item['balance']}"), | ||
| 166 | 'balance'=>Db::raw("balance + {$item['balance']}"), | ||
| 167 | ]); | ||
| 168 | |||
| 169 | } | 70 | } |
| 170 | } | 71 | } |
| 171 | } | 72 | } | ... | ... |
| ... | @@ -34,7 +34,10 @@ Route::group([], function (){ | ... | @@ -34,7 +34,10 @@ Route::group([], function (){ |
| 34 | Route::get('musician_balance/account', 'MusicianBalanceController@account'); | 34 | Route::get('musician_balance/account', 'MusicianBalanceController@account'); |
| 35 | //钱包-账户详情 | 35 | //钱包-账户详情 |
| 36 | Route::get('musician_balance/account_detail', 'MusicianBalanceController@accountDetail'); | 36 | Route::get('musician_balance/account_detail', 'MusicianBalanceController@accountDetail'); |
| 37 | //提现请求 | 37 | |
| 38 | Route::post('musician/withdraw_prepare', 'MusicianWithdrawController@prepare'); | 38 | //提现发票抬头 |
| 39 | Route::post('/withdraw/receipt', 'MusicianWithdrawController@receipt'); | ||
| 40 | //账单状态修改 | ||
| 41 | Route::post('/withdraw/status', 'MusicianWithdrawController@status'); | ||
| 39 | 42 | ||
| 40 | }); | 43 | }); | ... | ... |
-
Please register or sign in to post a comment