|
@@ -22,11 +22,16 @@ class Unishop extends Api
|
|
|
$pay_type = input('pay_type','alipay');
|
|
|
$platform = input('platform','wap');
|
|
|
$orderid = input('order_id',0);
|
|
|
+
|
|
|
if(empty($orderid)){
|
|
|
$this->error();
|
|
|
}
|
|
|
$orderid = Hashids::decodeHex($orderid);
|
|
|
|
|
|
+ if(!in_array($pay_type,['wechat','alipay','wallet'])){
|
|
|
+ $this->error();
|
|
|
+ }
|
|
|
+
|
|
|
$uid = $this->auth->id;
|
|
|
|
|
|
$map = [
|
|
@@ -40,15 +45,39 @@ class Unishop extends Api
|
|
|
$this->error('请刷新重试');
|
|
|
}
|
|
|
|
|
|
- //银行卡特殊处理
|
|
|
- if($pay_type == 'bank'){
|
|
|
- Db::name('unishop_order')->where('id',$orderid)->update(['pay_type'=>2,'updatetime'=>time()]);
|
|
|
- $this->success('请从银行卡打款');
|
|
|
+ //余额支付
|
|
|
+ if($pay_type == 'wallet'){
|
|
|
+ Db::startTrans();
|
|
|
+
|
|
|
+ //扣钱
|
|
|
+ $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'money',$orderinfo['total_price'],31,'购物','unishop_order',$orderid);
|
|
|
+ if($rs_wallet['status'] == false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($rs_wallet['msg']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单改为已支付
|
|
|
+ $order_update['pay_type'] = 'wallet';
|
|
|
+ $order_update['have_paid'] = time();
|
|
|
+ $update_rs = Db::name('unishop_order')->where('id',$orderid)->where('have_paid',0)->update($order_update);
|
|
|
+ if(!$update_rs){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('支付失败,重试一下吧');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+
|
|
|
+ $result = [
|
|
|
+ 'pay_type' => $pay_type,
|
|
|
+ 'pay_params' => '',
|
|
|
+ ];
|
|
|
+ $this->success(1,$result);
|
|
|
}
|
|
|
|
|
|
//创建订单
|
|
|
+ $data = [];
|
|
|
$data['user_id'] = $uid;
|
|
|
- $data['out_trade_no'] = createUniqueNo('P',$uid); // 数据库订单号加密
|
|
|
+ $data['out_trade_no'] = createUniqueNo('U',$uid); // 数据库订单号加密
|
|
|
$data['order_amount'] = $orderinfo['total_price'];
|
|
|
$data['createtime'] = time();
|
|
|
|
|
@@ -68,17 +97,24 @@ class Unishop extends Api
|
|
|
'amount' => $data['order_amount'],
|
|
|
// 'amount' => 0.01,
|
|
|
'method' => $platform,
|
|
|
- 'notifyurl' => config('pay_notify_url').'/api/pay/order_notify_base/paytype/'.$pay_type,
|
|
|
- 'returnurl' => config('h5_url').'/#/pages/order/order?status=0',
|
|
|
+ 'notifyurl' => config('pay_notify_url').'/api/unishop/order_notify_base/paytype/'.$pay_type,
|
|
|
+ 'returnurl' => '',
|
|
|
];
|
|
|
|
|
|
$res = Service::submitOrder($params);
|
|
|
|
|
|
+ $result = [
|
|
|
+ 'pay_type'=> $pay_type,
|
|
|
+ 'pay_params'=> $pay_type
|
|
|
+
|
|
|
+ ];
|
|
|
if($pay_type == 'wechat'){
|
|
|
- $this->success('success',json_decode($res,true));
|
|
|
+ $result['pay_params'] = json_decode($res,true);
|
|
|
}else{
|
|
|
- $this->success('success',$res);
|
|
|
+ $result['pay_params'] = $res;
|
|
|
}
|
|
|
+
|
|
|
+ $this->success(1,$result);
|
|
|
}
|
|
|
|
|
|
//异步回调对外方法
|
|
@@ -143,13 +179,13 @@ class Unishop extends Api
|
|
|
|
|
|
//逻辑开始
|
|
|
$nowtime = time();
|
|
|
-// $nowtime = jiesuan_tendays_ago()-1; //仅测试用
|
|
|
|
|
|
$paytype_enum = [
|
|
|
'wechat' => 3,
|
|
|
'alipay' => 4,
|
|
|
];
|
|
|
|
|
|
+ //订单改为已支付
|
|
|
$update = [
|
|
|
'have_paid'=>$nowtime,
|
|
|
'pay_type' =>$paytype_enum[$paytype]
|
|
@@ -159,9 +195,6 @@ class Unishop extends Api
|
|
|
Db::rollback();
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
- //修改用户活跃,自动滑落用
|
|
|
- Db::name('user')->where('id',$orderInfo['user_id'])->update(['last_paytime'=>$nowtime]);
|
|
|
//逻辑结束
|
|
|
|
|
|
//状态
|
|
@@ -186,7 +219,7 @@ class Unishop extends Api
|
|
|
ignore_user_abort(); // run script in background
|
|
|
set_time_limit(30);
|
|
|
// 日志文件 start
|
|
|
- $log_base_dir = '../paylog/'.$paytype.'/';
|
|
|
+ $log_base_dir = '../epaylog/'.$paytype.'/';
|
|
|
if (!is_dir($log_base_dir))
|
|
|
{
|
|
|
mkdir($log_base_dir, 0770, true);
|