Commit 7a757390 authored by 万继龙's avatar 万继龙

Merge branch 'pay_wanjl_0830' into 'master'

Pay wanjl 0830

See merge request bp/pay!74
parents b734e336 b84d1743
...@@ -29,6 +29,8 @@ class PayException extends BaseException ...@@ -29,6 +29,8 @@ class PayException extends BaseException
14 => '订单缺少商品信息,请联系管理员', 14 => '订单缺少商品信息,请联系管理员',
15 => '订单存在过期商品,不能支付', 15 => '订单存在过期商品,不能支付',
16 => '订单过期,不允许支付', 16 => '订单过期,不允许支付',
17 => '订单缺少过期时间,请联系管理员',
18 => '订单不存在,请重试',
]; ];
} }
...@@ -18,14 +18,14 @@ class PayOrder extends MysqlBase ...@@ -18,14 +18,14 @@ class PayOrder extends MysqlBase
self::beginTransaction(); self::beginTransaction();
try{ try{
$_date = date('Y-m-d H:i:s'); $order = self::getMaster('*', ['order_id'=>$order_id]);
$order = self::getMaster('*', ['order_id'=>$order_id, 'expire_time[>]'=>$_date]);
if(empty($order)) { if(empty($order)) {
$cnt = self::insert($pay_order, ['rowCount'=>true]); $cnt = self::insert($pay_order, ['rowCount'=>true]);
if($cnt) { if($cnt) {
$order = $pay_order; $order = $pay_order;
} }
} }
self::commit(); self::commit();
}catch (\PDOException $e) { }catch (\PDOException $e) {
......
...@@ -61,6 +61,16 @@ class OrderController extends Base ...@@ -61,6 +61,16 @@ class OrderController extends Base
$this->success(['result'=>$ret]); $this->success(['result'=>$ret]);
} }
public function chargesAction() {
$params = $this->getRequest()->getPost();
$order_id = $params['order_id'] ?? '';
$paySrv = new PayService();
$ret = $paySrv->pay_charges($order_id);
$this->success(['result'=>$ret]);
}
public function write_offAction() { public function write_offAction() {
$params = $this->params; $params = $this->params;
......
...@@ -49,12 +49,13 @@ class PayService ...@@ -49,12 +49,13 @@ class PayService
throw new PayException(['cus' => 3]); throw new PayException(['cus' => 3]);
} }
if (!empty($order_info['pay_expiration_time'])) { if (empty($order_info['pay_expiration_time'])) {
throw new PayException(['cus' => 17]);
}
$pay_expiration_time = strtotime($order_info['pay_expiration_time']); $pay_expiration_time = strtotime($order_info['pay_expiration_time']);
if($pay_expiration_time < time()) { if($pay_expiration_time < time()) {
throw new PayException(['cus' => 16]); throw new PayException(['cus' => 16]);
}
} }
if(empty($data['result']['order_item_list'])) { if(empty($data['result']['order_item_list'])) {
...@@ -93,9 +94,11 @@ class PayService ...@@ -93,9 +94,11 @@ class PayService
throw new PayException(['cus' => 15]); throw new PayException(['cus' => 15]);
} }
// 判断是否存在有效订单 //订单过期时间必须满足 70s+
$max_expire_time = config('pay','pay.expire_time') ?? 1800; if($pay_expiration_time - $now < 70 ) {
$expire_time = time() + $max_expire_time; $pay_expiration_time = $now + 70;
}
$pay_order_id = $this->gen_pay_order_id($user_id); $pay_order_id = $this->gen_pay_order_id($user_id);
$new_pay_order = [ $new_pay_order = [
'pay_order_id' => $pay_order_id, 'pay_order_id' => $pay_order_id,
...@@ -107,7 +110,7 @@ class PayService ...@@ -107,7 +110,7 @@ class PayService
'pay_amount' => $order_info['payment'], 'pay_amount' => $order_info['payment'],
'pay_channel' => $pay_method_id, 'pay_channel' => $pay_method_id,
'third_order_id' => '', 'third_order_id' => '',
'expire_time' => date('Y-m-d H:i:s', $expire_time), 'expire_time' => date('Y-m-d H:i:s', $pay_expiration_time),
'source_name' => 10, 'source_name' => 10,
'service_name' => 1, 'service_name' => 1,
'business_from' => $order_info['business_from'], 'business_from' => $order_info['business_from'],
...@@ -120,6 +123,11 @@ class PayService ...@@ -120,6 +123,11 @@ class PayService
throw new PayException(['cus' => 4]); throw new PayException(['cus' => 4]);
} }
//不支持修改订单过期时间,再次调用支付服务
if(strtotime($pay_order['expire_time']) < time()) {
throw new PayException(['cus' => 16]);
}
if ($pay_order['pay_order_status'] == Dictionary::O_PAY_STATUS_PAYED) { if ($pay_order['pay_order_status'] == Dictionary::O_PAY_STATUS_PAYED) {
throw new PayException(['cus' => 5]); throw new PayException(['cus' => 5]);
} }
...@@ -168,13 +176,25 @@ class PayService ...@@ -168,13 +176,25 @@ class PayService
$ret['exist'] = true; $ret['exist'] = true;
} }
$channel_exist = false;
$channel = $this->getChannel($pay_method_id);
if(!empty($ret['charges']['data'])) {
//是否存在
foreach ($ret['charges']['data'] as $ch) {
if($ch['channel'] == $channel) {
$channel_exist = true;
}
}
}
//判断是否做过pay操作 charge //判断是否做过pay操作 charge
if(empty($ret['charge'])) { if($channel_exist == false) {
// 创建支付单 // 创建支付单
$payment = [ $payment = [
'charge_order_no'=> $pay_order['pay_order_id'], 'charge_order_no'=> $pay_order['pay_order_id'],
'charge_amount'=> $pay_order['pay_amount'], 'charge_amount'=> $pay_order['pay_amount'],
'channel'=> $this->getChannel($pay_method_id), 'channel'=> $channel,
'extra'=> $extra, 'extra'=> $extra,
]; ];
...@@ -292,6 +312,64 @@ class PayService ...@@ -292,6 +312,64 @@ class PayService
return ['pay_order_id' => $pay_order_id]; return ['pay_order_id' => $pay_order_id];
} }
/**
* @param $order_id
* @return array
* @throws BaseException
* @throws PayException
* 返回订单状态及订单渠道列表
*/
public function pay_charges($order_id) {
$pay_order = PayOrder::get('*', ['order_id'=>$order_id]);
if(empty($pay_order)) {
throw new PayException(['cus' => 18]);
}
$data = [
'status'=>'created',
'max_expire_time'=>$pay_order['expire_time'],
'list'=>[]
];
$max_expire_time = strtotime($pay_order['expire_time']);
if($max_expire_time < time()) {
$data["status"] = 'canceled';
}
if(empty($pay_order['third_order_id'])) {
return $data;
}
//paid、refunded、canceled、created
$ret = PingxxService::getInstance()->getOrder($pay_order['third_order_id']);
if (!empty($ret['error'])) {
throw new BaseException(['msg'=>$ret['error']['message'], 'code'=>'2301']);
}
$data["status"] = $ret["status"];
if(!empty($ret['charges']['data'])) {
//是否存在
foreach ($ret['charges']['data'] as $ch) {
$data["list"][] = [
'paid'=>$ch['paid'],
'refunded'=>$ch['refunded'],
'channel'=>$ch['channel'],
'time_expire'=>$ch['time_expire'],
];
if($max_expire_time < $ch['time_expire']) {
$max_expire_time = $ch['time_expire'];
}
}
}
$data['max_expire_time'] = date('Y-m-d H:i:s', $max_expire_time);
return $data;
}
/** /**
* @param $order_item_id * @param $order_item_id
* @param $life_account_id * @param $life_account_id
......
...@@ -144,6 +144,7 @@ class PingxxService ...@@ -144,6 +144,7 @@ class PingxxService
"body" => "购买商品", "body" => "购买商品",
"uid" => $order['user_id'], "uid" => $order['user_id'],
"client_ip" => IP::ip(), "client_ip" => IP::ip(),
"time_expire" => strtotime($order['expire_time']), //订单过期时间 expire_time
'receipt_app' => Pingpp::getAppId(), // 收款方应用 'receipt_app' => Pingpp::getAppId(), // 收款方应用
'service_app' => Pingpp::getAppId(), // 服务方应用 'service_app' => Pingpp::getAppId(), // 服务方应用
'metadata' => $metadata, // 商户定制信息 'metadata' => $metadata, // 商户定制信息
......
...@@ -23,6 +23,19 @@ class WalletService ...@@ -23,6 +23,19 @@ class WalletService
throw new CodeSpecialException("failed"); throw new CodeSpecialException("failed");
} }
// 服务增加签名
$appid = \Yaf\Application::app()->getConfig()->get('wallet.appid');
$secret = \Yaf\Application::app()->getConfig()->get('wallet.secret');
$params['time'] = date('Y-m-d H:i:s');
$params['transfer_service_id'] = $appid;
$params['sign'] = self::sign($params, $secret);
return Sdk::call($url, $params); return Sdk::call($url, $params);
} }
private function sign($params, $secret) {
$sign = md5($params['time'] . $secret);
return $sign;
}
} }
\ No newline at end of file
...@@ -41,12 +41,22 @@ dingTalk.keys[]="SEC0298ad3f80e16df12cd4d6f6c39e961b500e2ff486f4c4377c0e2af8f453 ...@@ -41,12 +41,22 @@ dingTalk.keys[]="SEC0298ad3f80e16df12cd4d6f6c39e961b500e2ff486f4c4377c0e2af8f453
pingxx.appid = "app_9m1ubDG4e1mPXLCG" pingxx.appid = "app_9m1ubDG4e1mPXLCG"
wxApp.jw.order = "https://wx.appgc.cn/%23/bpmp/ticket/my" wxApp.jw.order = "https://wx.appgc.cn/%23/bpmp/ticket/my"
[perf : common : exception : dingTalk] wallet.appid = "21091014413030105002"
wallet.secret = "b62eff98ba17160df0161ede4eef2346"
[pref : prod : common : exception : dingTalk]
pingxx.appid = "app_XfjznTPSa5aLfvfH" pingxx.appid = "app_XfjznTPSa5aLfvfH"
[test : common : exception : dingTalk] [test : common : exception : dingTalk]
pingxx.appid = "app_W10Oe5XrvbzHfP4W" pingxx.appid = "app_W10Oe5XrvbzHfP4W"
wxApp.jw.order = "https://testwx.appgc.cn/%23/bpmp/ticket/my" wxApp.jw.order = "https://testwx.appgc.cn/%23/bpmp/ticket/my"
[dev : common : exception] wallet.appid = "21090716133838205004"
wallet.secret = "f97c50e880d377a0e0f79aee1f639777"
[dev : common : exception : dingTalk]
pingxx.appid = "app_W10Oe5XrvbzHfP4W" pingxx.appid = "app_W10Oe5XrvbzHfP4W"
wxApp.jw.order = "https://testwx.appgc.cn/%23/bpmp/ticket/my"
wallet.appid = "21090716133838205004"
wallet.secret = "f97c50e880d377a0e0f79aee1f639777"
\ No newline at end of file
...@@ -15,14 +15,26 @@ dingTalk.tokens[]="5d754d76cac8c64aad495bc44f481677745ff831aee0517b6e5b3565be6ba ...@@ -15,14 +15,26 @@ dingTalk.tokens[]="5d754d76cac8c64aad495bc44f481677745ff831aee0517b6e5b3565be6ba
dingTalk.keys[]="SEC0298ad3f80e16df12cd4d6f6c39e961b500e2ff486f4c4377c0e2af8f4539a74" dingTalk.keys[]="SEC0298ad3f80e16df12cd4d6f6c39e961b500e2ff486f4c4377c0e2af8f4539a74"
[prod : common : dingTalk] [prod : common : exception : dingTalk]
pingxx.appid = "app_9m1ubDG4e1mPXLCG" pingxx.appid = "app_9m1ubDG4e1mPXLCG"
wxApp.jw.order = "https://wx.appgc.cn/%23/bpmp/ticket/my"
[perf : common : dingTalk] wallet.appid = "21091014413030105002"
wallet.secret = "b62eff98ba17160df0161ede4eef2346"
[pref : prod : common : exception : dingTalk]
pingxx.appid = "app_XfjznTPSa5aLfvfH" pingxx.appid = "app_XfjznTPSa5aLfvfH"
[test: common : dingTalk] [test : common : exception : dingTalk]
pingxx.appid = "app_W10Oe5XrvbzHfP4W" pingxx.appid = "app_W10Oe5XrvbzHfP4W"
wxApp.jw.order = "https://testwx.appgc.cn/%23/bpmp/ticket/my"
wallet.appid = "21090716133838205004"
wallet.secret = "f97c50e880d377a0e0f79aee1f639777"
[dev : common ] [dev : common : exception : dingTalk]
pingxx.appid = "app_W10Oe5XrvbzHfP4W" pingxx.appid = "app_W10Oe5XrvbzHfP4W"
wxApp.jw.order = "https://testwx.appgc.cn/%23/bpmp/ticket/my"
wallet.appid = "21090716133838205004"
wallet.secret = "f97c50e880d377a0e0f79aee1f639777"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment