...
|
...
|
@@ -4,12 +4,18 @@ |
|
|
namespace app\api\controller;
|
|
|
|
|
|
|
|
|
use addons\epay\library\Service;
|
|
|
use app\api\model\GoodsComment;
|
|
|
use app\api\model\RiderOrder;
|
|
|
use app\api\model\Third;
|
|
|
use app\api\model\UserMoneyLog;
|
|
|
use app\api\model\Withdraw;
|
|
|
use app\common\controller\Api;
|
|
|
use app\common\model\User;
|
|
|
use think\Config;
|
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
|
use think\exception\PDOException;
|
|
|
|
|
|
/**
|
|
|
* 骑手
|
...
|
...
|
@@ -356,15 +362,52 @@ class Rider extends Api |
|
|
$money = $this->request->post('money');
|
|
|
$user = $this->auth->getUser();
|
|
|
if ($user['money'] < $money) $this->error('可提现金额不足');
|
|
|
$data = [
|
|
|
'user_id' => $this->auth->id,
|
|
|
'money' => -$money,
|
|
|
'before' => $user->money,
|
|
|
'after' => $user->money-$money,
|
|
|
'memo' => '提现'
|
|
|
];
|
|
|
UserMoneyLog::create($data);
|
|
|
$user->setDec('money',$money);
|
|
|
// 禁止连点
|
|
|
!empty(cache('withdraw_'.$user['id'])) && $this->error('提现频繁,请稍后再试');
|
|
|
cache('withdraw_'.$user['id'],'123',5);
|
|
|
|
|
|
Db::startTrans();
|
|
|
try{
|
|
|
$money = 0.01;
|
|
|
$order_sn = date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
|
|
|
$withdraw = Withdraw::create([
|
|
|
'user_id' => $user['id'],
|
|
|
'order_sn' => $order_sn,
|
|
|
'money' => $money,
|
|
|
]);
|
|
|
// 变更会员余额
|
|
|
User::money(-$money,$user['id'],'提现');
|
|
|
|
|
|
$config = Service::getConfig('wechat');
|
|
|
$config['app_id'] = $config['miniapp_id'];
|
|
|
$app = Factory::payment($config);
|
|
|
$result = $app->transfer->toBalance([
|
|
|
'partner_trade_no' => $order_sn, // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
|
|
|
'openid' => Third::where('user_id',$this->auth->id)->value('openid'),
|
|
|
'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
|
|
|
// 're_user_name' => '王小帅', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
|
|
|
'amount' => $money * 100, // 企业付款金额,单位为分
|
|
|
'desc' => '骑手提现', // 企业付款操作说明信息。必填
|
|
|
]);
|
|
|
\think\Log::write('企业付款到返回数据:'.json_encode($result,JSON_UNESCAPED_UNICODE));
|
|
|
if($result['result_code'] != 'SUCCESS'){
|
|
|
$this->error($result['err_code_des']);
|
|
|
}
|
|
|
|
|
|
// 记录企业付款单号
|
|
|
$withdraw->payment_no = $result['payment_no'];
|
|
|
$withdraw->payment_time = $result['payment_time'];
|
|
|
$withdraw->status = '1';
|
|
|
$withdraw->save();
|
|
|
|
|
|
Db::commit();
|
|
|
} catch (PDOException $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
$this->success('提现成功');
|
|
|
}
|
|
|
|
...
|
...
|
|