作者 何书鹏
1 个管道 的构建 通过 耗费 0 秒

提现恢复

... ... @@ -840,36 +840,36 @@ class User extends Api
!empty(cache('withdraw_token'.$this->auth->id)) && $this->error('提现频繁,请稍后再试');
cache('withdraw_token'.$this->auth->id,'123',5);
// Db::startTrans();
// try{
// $withdraw = Withdraw::create([
// 'user_id' => $this->auth->id,
// 'order_sn' => get_order_sn(),
// 'money' => $money,
// ]);
// // 变更会员余额
// UserModel::money(-$money,$this->auth->id,'提现',['withdraw_id' => $withdraw['id']]);
//
// // 发起企业付款
// $Wechat = new Wechat;
// $openid = Db::name('third')->where('user_id',$this->auth->id)->value('openid');
// if(!$balance = $Wechat->toBalance($withdraw['order_sn'], $openid, $withdraw['money'] * 100)){
// $this->error($Wechat->getError());
// }
// // 记录企业付款单号
// $withdraw->payment_no = $balance['payment_no'];
// $withdraw->payment_time = $balance['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());
// }
Db::startTrans();
try{
$withdraw = Withdraw::create([
'user_id' => $this->auth->id,
'order_sn' => get_order_sn(),
'money' => $money,
]);
// 变更会员余额
UserModel::money(-$money,$this->auth->id,'提现',['withdraw_id' => $withdraw['id']]);
// 发起企业付款
$Wechat = new Wechat;
$openid = Db::name('third')->where('user_id',$this->auth->id)->value('openid');
if(!$balance = $Wechat->toBalance($withdraw['order_sn'], $openid, $withdraw['money'] * 100)){
$this->error($Wechat->getError());
}
// 记录企业付款单号
$withdraw->payment_no = $balance['payment_no'];
$withdraw->payment_time = $balance['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('成功');
}
... ...