79 lines
2.0 KiB
PHP
79 lines
2.0 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace app\api\logic\merchant;
|
||
|
|
||
|
use app\common\logic\BaseLogic;
|
||
|
use app\common\model\bank\Bank;
|
||
|
use app\common\model\merchant\Merchant;
|
||
|
use app\common\model\merchant\MerchantBank;
|
||
|
use app\common\model\withdraw\MerchantWithdraw;
|
||
|
use think\facade\Db;
|
||
|
|
||
|
class MerchantLogic extends BaseLogic
|
||
|
{
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 获取用户余额和绑定银行账户信息
|
||
|
*/
|
||
|
public static function amount_account($merchant)
|
||
|
{
|
||
|
try {
|
||
|
|
||
|
$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;
|
||
|
} catch (\Exception $e) {
|
||
|
self::setError($e->getMessage());
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 用户提现操作
|
||
|
*/
|
||
|
public static function withdraw($params, $merchant)
|
||
|
{
|
||
|
try {
|
||
|
$merchant = Merchant::where('mer_id', $merchant['mer_id'])->find();
|
||
|
if ($params['amount'] > $merchant['mer_money']) {
|
||
|
self::setError('提现余额不足');
|
||
|
return false;
|
||
|
}
|
||
|
$save_data = [
|
||
|
'mer_id' => $merchant['mer_id'],
|
||
|
'merchant_bank_id' => $params['merchant_bank_id'],
|
||
|
'amount' => $params['amount'],
|
||
|
'is_check' => 0,
|
||
|
'is_arrival' => 0,
|
||
|
'admin_id' => 0,
|
||
|
'create_time' => time(),
|
||
|
];
|
||
|
(new MerchantWithdraw)->save($save_data);
|
||
|
return true;
|
||
|
} catch (\Exception $e) {
|
||
|
self::setError($e->getMessage());
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 提现信息
|
||
|
*/
|
||
|
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();
|
||
|
return ['total' => $total_amount, 'count' => $count];
|
||
|
} catch (\Exception $e) {
|
||
|
self::setError($e->getMessage());
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|