Commit 6957ea96 6957ea96f1ba1a3a38c430aa3ee3eac67eb07041 by lemon

提现申请

1 parent ccf45dbb
......@@ -2,15 +2,17 @@
namespace App\ApiInterface;
use App\Models\Legal\StakeholderIncomeSyncApp;
/**
* Interface PaymentInterface
* @package App\ApiInterface
*/
interface WithdrawInterface
{
public function advance(string $serial_no);
public function advance(StakeholderIncomeSyncApp $app);
public function success(string $serial_no);
public function success(StakeholderIncomeSyncApp $app);
public function fail(string $serial_no);
public function fail(StakeholderIncomeSyncApp $app);
}
......
......@@ -126,8 +126,6 @@ class StakeholderIncomeSyncCommand extends Command
DB::rollBack();
Log::channel('api')->error(__METHOD__, ['msg'=>$e->getMessage(), 'request'=>$request, 'response'=>$response]);
}
}
/**
......
......@@ -20,6 +20,8 @@ class ErrorCode
const WITHDRAW_NO_RECORD = 40051;
const WITHDRAW_HANDLE_ERROR = 40052;
const WITHDRAW_CONFIRM_BILLS_FAIL = 40053;
const WITHDRAW_APPLY_FAIL = 40054;
/**
......@@ -39,6 +41,7 @@ class ErrorCode
self::WITHDRAW_NO_RECORD => '未匹配有效提现记录',
self::WITHDRAW_HANDLE_ERROR => '提现操作失败',
self::WITHDRAW_CONFIRM_BILLS_FAIL => '确认账单失败',
self::WITHDRAW_APPLY_FAIL => '提现申请失败',
];
......
......@@ -8,6 +8,7 @@ use App\Http\Requests\Musician\MusicianWithdrawReceiptByNameRequest;
use App\Http\Requests\Musician\MusicianWithdrawReceiptRequest;
use App\Http\Requests\Musician\MusicianWithdrawStatusRequest;
use App\Services\MusicianWithdrawService;
use App\Services\WithdrawService;
/**
* Class MusicianWithdrawController
......@@ -53,8 +54,8 @@ class MusicianWithdrawController extends Controller
* 提现状态修改
* @return \Illuminate\Http\JsonResponse
*/
public function withdraw(MusicianWithdrawStatusRequest $request)
public function withdraw(MusicianWithdrawStatusRequest $request, WithdrawService $withdrawService)
{
return $this->musicianWithdrawService->Withdraw();
return $this->musicianWithdrawService->Withdraw($withdrawService);
}
}
......
<?php
namespace App\Models\Legal;
use App\Models\BaseModel;
use Illuminate\Support\Facades\DB;
/**
* Class StakeholderWithdrawAppLogs
* @package App\Models\Legal
*/
class StakeholderWithdrawAppLogs extends BaseModel
{
/**
* @var string
*/
protected $table = 'stakeholder_withdraw_app_logs';
/**
* @var array
*/
protected $guarded = [];
}
......@@ -114,9 +114,19 @@ class MusicianWithdrawService extends Service
* 修改提现状态
* @return \Illuminate\Http\JsonResponse|mixed
*/
public function withdraw()
public function withdraw(WithdrawService $withdrawService)
{
if (!$app = StakeholderIncomeSyncApp::query()->where([
'serial_no'=>$this->request->serial_no,
'identifier'=>$this->identifier->identifier,
'sync_status'=>1,
])
->first()) {
return Response::error(ErrorCode::WITHDRAW_NO_RECORD);
}
return call_user_func([$withdrawService, $this->request->type], $app);
}
}
......
......@@ -3,6 +3,13 @@
namespace App\Services;
use App\ApiInterface\WithdrawInterface;
use App\Helper\ErrorCode;
use App\Helper\Response;
use App\Models\Legal\StakeholderBalanceByPayer;
use App\Models\Legal\StakeholderIncomeSyncApp;
use App\Models\Legal\StakeholderWithdrawAppLogs;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
/**
* Class MusicianAgreementService
......@@ -12,29 +19,70 @@ class WithdrawService extends Service implements WithdrawInterface
{
/**
* 提现申请
* @param string $serial_no
* @return \Illuminate\Http\JsonResponse
* @param StakeholderIncomeSyncApp $app
*/
public function advance(string $serial_no)
public function advance(StakeholderIncomeSyncApp $app)
{
$condition = $this->compose($app);
DB::beginTransaction();
try {
//修改状态-》提现中
StakeholderIncomeSyncApp::query()->where(['serial_no'=>$app->serial_no, 'identifier'=>$this->identifier->identifier, 'sync_status'=>1, 'withdraw_status'=>1])->update([
'withdraw_status'=>2
]);
//修改资金账户
StakeholderBalanceByPayer::query()->where(['condition'=>$condition])->where('balance', '>=', $app->total_money)->update([
'freeze' => DB::raw("freeze + {$app->total_money}"),
'balance'=> DB::raw("balance - {$app->total_money}"),
]);
//提现申请日志
StakeholderWithdrawAppLogs::query()->create([
'serial_no' => $app->serial_no,
'identifier' => $this->identifier->identifier,
'type' => __FUNCTION__,
'withdraw_money' => $app->total_money,
]);
DB::commit();
return Response::success();
} catch (\Exception $e) {
DB::rollBack();
Log::channel('api')->error(__METHOD__, ['msg'=>$e->getMessage()]);
return Response::error(ErrorCode::WITHDRAW_APPLY_FAIL);
}
}
/**
* 提现成功
* @param string $serial_no
* @param StakeholderIncomeSyncApp $app
*/
public function success(string $serial_no)
public function success(StakeholderIncomeSyncApp $app)
{
// TODO: Implement success() method.
$condition = $this->compose($app);
}
/**
* 提现失败
* @param string $serial_no
* @param StakeholderIncomeSyncApp $app
*/
public function fail(StakeholderIncomeSyncApp $app)
{
$condition = $this->compose($app);
}
/**
* @param StakeholderIncomeSyncApp $app
* @return string
*/
public function fail(string $serial_no)
private function compose(StakeholderIncomeSyncApp $app)
{
// TODO: Implement fail() method.
return $app->stakeholder_id .'|'. $app->subject_no;
}
}
......
......@@ -40,7 +40,7 @@ Route::group([], function (){
//账单状态修改
Route::post('withdraw/bill_confirm', 'MusicianWithdrawController@billConfirm');
//账单状态修改
Route::post('withdraw/status', 'MusicianWithdrawController@withdraw');
Route::any('withdraw/status', 'MusicianWithdrawController@withdraw');
//钱包-账单收益
Route::get('wallet/detail', 'MusicianWalletController@walletDetail');
......