Commit 162cf54a authored by 万继龙's avatar 万继龙

Merge branch 'develop' into 'test'

add: 增加商品过期时间的判断

See merge request bp/pay!29
parents def5e688 16cfbbea
...@@ -26,6 +26,8 @@ class PayException extends BaseException ...@@ -26,6 +26,8 @@ class PayException extends BaseException
11 => '商家仅允许核销自己的订单,请管理员关注', 11 => '商家仅允许核销自己的订单,请管理员关注',
12 => '支付订单预结算失败,结算资金不能负数,请核对配置', 12 => '支付订单预结算失败,结算资金不能负数,请核对配置',
13 => '生活号获取管理员ID失败,请联系管理员', 13 => '生活号获取管理员ID失败,请联系管理员',
14 => '订单缺少商品信息,请联系管理员',
15 => '订单商品存在过期商品,不能支付',
......
...@@ -11,96 +11,66 @@ use Helpers\DingTalk; ...@@ -11,96 +11,66 @@ use Helpers\DingTalk;
class TccController extends Base class TccController extends Base
{ {
/** /**
* 创建支付订单,返回前端ping++的支付信息 * tcc test
*/ */
public function tryAction() public function tryAction()
{ {
if(!empty($this->params['sleep'])) { if(!empty($this->params['sleep'])) {
sleep($this->params['sleep']); sleep($this->params['sleep']);
} }
if(!empty($this->params['throw'])) { if(!empty($this->params['error'])) {
throw new \Exception('test for Exception.', '3001'); throw new \App\Exception\BaseException(['msg'=>'try is error', 'code'=>2001]);
}
if(!empty($this->params['lock'])) {
//todo make a lock for mysql
} }
$this->success(['result'=>[]]); $this->success(['result'=>[]]);
} }
public function confirmAction() { public function mainAction() {
if(!empty($this->params['sleep'])) { if(!empty($this->params['sleep'])) {
sleep($this->params['sleep']); sleep($this->params['sleep']);
} }
if(!empty($this->params['throw'])) { if(!empty($this->params['error'])) {
throw new \Exception('test for Exception.', '3001'); $this->success(['data'=>2]);
} }
if(!empty($this->params['lock'])) { $this->success(['data'=>1]);
}
public function sleepAction() {
//todo make a lock for mysql if(!empty($this->params['sleep'])) {
sleep($this->params['sleep']);
} }
$this->success(['result'=>[]]); $this->success(['result'=>$this->params]);
} }
public function cancelAction() { public function confirmAction() {
if(!empty($this->params['sleep'])) { if(!empty($this->params['sleep'])) {
sleep($this->params['sleep']); sleep($this->params['sleep']);
} }
if(!empty($this->params['throw'])) { if(!empty($this->params['error'])) {
throw new \Exception('test for Exception.', '3001'); throw new \App\Exception\BaseException(['msg'=>'confirm is error', 'code'=>2001]);
}
if(!empty($this->params['lock'])) {
//todo make a lock for mysql
} }
$this->success(['result'=>[]]); $this->success(['result'=>[]]);
}
public function traceAction() {
\Helpers\Tracer::info('traceId', '');
} }
public function cancelAction() {
public function pdoAction() { if(!empty($this->params['sleep'])) {
sleep($this->params['sleep']);
$dsn = 'mysql:dbname=testdb;host=127.0.0.1'; }
$user = 'dbuser';
$password = 'dbpass';
$user = config('mysql', 'pay.username');
$password = config('mysql', 'pay.password');
$host = config('mysql', 'pay.write.host');
$db = config('mysql', 'pay.database_name');
$dsn = 'mysql:dbname=' . $db . ';host=' . $host;
$dbh = new PDO($dsn, $user, $password);
sleep(15);
$sth = $dbh->prepare('SELECT * FROM pay_order WHERE user_id = ? limit 1');
var_dump($sth, '----');
$sth->execute([510226436112]);
$one = $sth->fetchAll();
$sth->execute([510230120298]);
$two = $sth->fetchAll();
$this->success(['one'=>$one, 'two'=>$two]); if(!empty($this->params['error'])) {
throw new \App\Exception\BaseException(['msg'=>'confirm is error', 'code'=>2001]);
}
$this->success(['result'=>[]]);
} }
} }
...@@ -50,6 +50,10 @@ class PayService ...@@ -50,6 +50,10 @@ class PayService
throw new PayException(['cus' => 3]); throw new PayException(['cus' => 3]);
} }
if(empty($data['result']['order_item_list'])) {
throw new PayException(['cus' => 14]);
}
$metadata = [ $metadata = [
'app_id'=>'merchant-c', 'app_id'=>'merchant-c',
'environ'=>Application::app()->environ(), 'environ'=>Application::app()->environ(),
...@@ -57,12 +61,22 @@ class PayService ...@@ -57,12 +61,22 @@ class PayService
'goods'=>[], 'goods'=>[],
'order_item_id'=>[], 'order_item_id'=>[],
]; ];
$min_expire_time = $now = time();
foreach ($data['result']['order_item_list'] as $item) { foreach ($data['result']['order_item_list'] as $item) {
if(strtotime($item['expiration_time']) < $min_expire_time) {
$min_expire_time = strtotime($item['expiration_time']);
}
$metadata['goods'][$item['goods_sku_id']] = $item['goods_num']; $metadata['goods'][$item['goods_sku_id']] = $item['goods_num'];
array_push($metadata['order_item_id'], $item['order_item_id']); array_push($metadata['order_item_id'], $item['order_item_id']);
} }
if($now > $min_expire_time) {
throw new PayException(['cus' => 15]);
}
// 判断是否存在有效订单 // 判断是否存在有效订单
$max_expire_time = config('pay','pay.expire_time') ?? 1800; $max_expire_time = config('pay','pay.expire_time') ?? 1800;
$expire_time = time() + $max_expire_time; $expire_time = time() + $max_expire_time;
......
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