1. 更新 UserWithdrawController.php 文件,优化用户提现逻辑。

2. 更新 MerchantLogic.php 文件,优化商户逻辑
This commit is contained in:
mkm 2024-05-23 11:57:11 +08:00
parent 99c2020aa2
commit 358dfe078b
2 changed files with 13 additions and 7 deletions

View File

@ -56,10 +56,9 @@ class UserWithdrawController extends BaseApiController
public function withdraw()
{
$params = (new MerchantWithdrawValidate())->post()->goCheck('withdraw');
// $uid = $this->request->userInfo['user_id'];
$uid = $this->request->userId;
// $merchant = Merchant::where('uid',$uid)->findOrEmpty();
// $supplier = Supplier::where('uid',$uid)->findOrEmpty();
$supplier = $this->request->userInfo['supplier'];
$supplier = Supplier::where('uid',$uid)->findOrEmpty();
if (!$supplier) {
return $this->fail('当前用户非供应商');
}
@ -94,6 +93,8 @@ class UserWithdrawController extends BaseApiController
'admin_id' => 0,
'create_time' => time(),
];
$supplier->mer_money =bcsub($supplier->mer_money, $params['amount'], 2);
$supplier->save();
(new MerchantWithdraw)->save($save_data);
return $this->success('提现成功,等待管理员审核');
// }else{

View File

@ -19,14 +19,17 @@ class MerchantLogic extends BaseLogic
public static function amount_account($merchant)
{
try {
$mer_money = Merchant::where('mer_id', $merchant['mer_id'])->value('mer_money');
$bank_list = MerchantBank::where('mer_id', $merchant['mer_id'])->where('is_check', 1)->select()->each(function ($data) {
$bank_info = Bank::where('id', $data['bank_id'])->findOrEmpty();
$data['bank_name'] = !$bank_info->isEmpty() ? $bank_info['name'] : '';
$data['bank_image'] = !$bank_info->isEmpty() ? $bank_info['image'] : '';
return $data;
})->toArray();
return $bank_list;
return [
'balance' => $mer_money,
'bank_list' => $bank_list
];
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
@ -53,6 +56,8 @@ class MerchantLogic extends BaseLogic
'admin_id' => 0,
'create_time' => time(),
];
$merchant->mer_money =bcsub($merchant->mer_money, $params['amount'], 2);
$merchant->save();
(new MerchantWithdraw)->save($save_data);
return true;
} catch (\Exception $e) {
@ -64,7 +69,8 @@ class MerchantLogic extends BaseLogic
/**
* 提现信息
*/
public static function taking_info($merchant){
public static function taking_info($merchant)
{
try {
$total_amount = MerchantWithdraw::where('mer_id', $merchant['mer_id'])->where('is_check', 1)->where('is_arrival', 1)->sum('amount');
$count = MerchantWithdraw::where('mer_id', $merchant['mer_id'])->where('is_check', 1)->where('is_arrival', 1)->count();
@ -73,6 +79,5 @@ class MerchantLogic extends BaseLogic
self::setError($e->getMessage());
return false;
}
}
}