作者 潘浩文
1 个管道 的构建 通过 耗费 4 秒

XIAOPAN

... ... @@ -439,4 +439,47 @@ class UsersController extends HomeBaseController{
$return['fee']=\db('users')->where('id',$user_id)->value('fee');
$this->apiResponse(200,'success',$return);
}
/**
* @title 用户提现
* @description
* @author panhaowen
* @url /portal/users/withdraw
* @method GET
* @param name:user_id type:String require:1 default:无 other: desc:用户id
* @param name:fee type:int require:1 default:无 other: desc:用户id
*/
public function withdraw(){
$user_id=input('user_id');
$fee=$this->request->param('fee');
$user=Db::name('users')->where('id',$user_id)->find();
if ($user['fee']>=$fee) {
$order_sn=cmf_get_order_sn();
Db::name('users')->setDec('fee', $fee);
Db::name('withdraw')->insert([
'user_id'=>$user_id,
'money'=>$fee,
'create_time'=>time(),
'order_sn'=>$order_sn
]);
$app = new Application($this->options);
$merchantPay = $app->merchant_pay;
$merchantPayData = [
'partner_trade_no' => $order_sn, //随机字符串作为订单号,跟红包和支付一个概念。
'openid' => $user['open_id'], //收款人的openid
'check_name' => 'NO_CHECK', //文档中有三种校验实名的方法 NO_CHECK OPTION_CHECK FORCE_CHECK
// 're_user_name'=>'张三', //OPTION_CHECK FORCE_CHECK 校验实名的时候必须提交
'amount' => $fee * 100, //单位为分
// 'amount' => 100, //单位为分
'desc' => '企业付款',
'spbill_create_ip' => get_client_ip(0, true), //发起交易的IP地址
];
$re = $merchantPay->send($merchantPayData);
$this->apiResponse(200,'success',$re);
}else{
$this->apiResponse(300,'余额不足提现失败');
}
}
}
\ No newline at end of file
... ...