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

订单倒计时自动确认

... ... @@ -534,40 +534,10 @@ class Order extends Api
empty($order_id) && $this->error('缺少必需参数');
$order = $this->model->get($order_id);
empty($order) && $this->error('订单信息不存在');
$grab = $order['grab_success'];
$order['status'] != '3' && $this->error('订单不合法');
Db::startTrans();
try{
// 发单和抢单状态都改为已完成
$grab->save(['status'=>'4']);
$order->save(['status'=>'4']);
// 给抢单用户发送"已完成"通知
(new Message)->save([
'user_id' => $grab['user_id'],
'order_id' => $grab['order_id'],
'order_grab_id' => $grab['id'],
'type' => '1',
'grab_status' => '3',
]);
// 添加抢单价格到抢单用户余额
User::money($grab['grab_price'],$grab['user_id'],'订单完成',['order_id' => $order_id]);
// 把定金多余金额退回发单用户余额
if($order['deposit'] > $grab['grab_price']){
$dec = $order['deposit'] - $grab['grab_price'];
User::money($dec,$order['user_id'],'退定金余额',['order_id' => $order_id]);
}
// 订单完成通知
$send_data = [
"first" => '刚刚完成了一笔订单',
"keyword1" => $order['deposit'],
"keyword2" => $order['license_plate'],
"keyword3" => date('Y年m月d日H点i分'),
"keyword4" => $order['market_name'],
"remark" => ['请点击查看详情','#FF0000'],
];
$openid = Third::where('user_id',$grab['user_id'])->value('openid');
$templateid = config('tmplmsg.template')['order_complete'];
$url = config('tmplmsg.vue_url').'/indenta?id='.$grab['id'].'&type=4';
(new Wechat)->tmplmsg($openid,$send_data,$templateid,$url);
self::confirmAction($order);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
... ... @@ -580,6 +550,47 @@ class Order extends Api
}
/**
* @ApiInternal
* @ApiTitle (待确认-确认-操作)
* @ApiSummary (待确认-确认-操作)
*/
public static function confirmAction($order){
$grab = $order['grab_success'];
// 发单和抢单状态都改为已完成
$grab->save(['status'=>'4']);
$order->save(['status'=>'4']);
// 给抢单用户发送"已完成"通知
(new Message)->save([
'user_id' => $grab['user_id'],
'order_id' => $grab['order_id'],
'order_grab_id' => $grab['id'],
'type' => '1',
'grab_status' => '3',
]);
// 添加抢单价格到抢单用户余额
User::money($grab['grab_price'],$grab['user_id'],'订单完成',['order_id' => $order['id']]);
// 把定金多余金额退回发单用户余额
if($order['deposit'] > $grab['grab_price']){
$dec = $order['deposit'] - $grab['grab_price'];
User::money($dec,$order['user_id'],'退定金余额',['order_id' => $order['id']]);
}
// 订单完成通知
$send_data = [
"first" => '刚刚完成了一笔订单',
"keyword1" => $order['deposit'],
"keyword2" => $order['license_plate'],
"keyword3" => date('Y年m月d日H点i分'),
"keyword4" => $order['market_name'],
"remark" => ['请点击查看详情','#FF0000'],
];
$openid = Third::where('user_id',$grab['user_id'])->value('openid');
$templateid = config('tmplmsg.template')['order_complete'];
$url = config('tmplmsg.vue_url').'/indenta?id='.$grab['id'].'&type=4';
(new Wechat)->tmplmsg($openid,$send_data,$templateid,$url);
return true;
}
/**
* @ApiWeigh (81)
* @ApiTitle (待确认-问题反馈)
* @ApiSummary (待确认-问题反馈)
... ...
... ... @@ -401,6 +401,7 @@ class OrderGrab extends Api
$templateid = config('tmplmsg.template')['trade_alert'];
$url = config('tmplmsg.vue_url').'/indent?id='.$order['id'].'&type=3';
(new Wechat)->tmplmsg($openid,$send_data,$templateid,$url);
\think\Queue::later(config('countdown.complete'), '\app\api\job\OrderAutoOper@autoComplete', ['order_id'=>$order['id']], 'parking');
Db::commit();
} catch (PDOException $e) {
Db::rollback();
... ...
... ... @@ -17,9 +17,7 @@ class OrderAutoOper extends BaseJob
*/
public function autoCancel(Job $job, $data){
try {
$order = $data['order'];
$order = Order::get($order['id']);
$order = Order::get($data['order_id']);
$grab_success = $order['grab_success'];
if ($order['status'] == '1' && !$grab_success) {
... ... @@ -35,4 +33,25 @@ class OrderAutoOper extends BaseJob
\think\Log::write('queue-' . get_class() . '-autoClose' . ':执行失败,错误信息:' . $e->getMessage());
}
}
/**
* 订单自动完成
*/
public function autoComplete(Job $job, $data){
try {
$order = Order::get($data['order_id']);
if ($order['status'] == '3') {
\think\Db::transaction(function () use ($order) {
\app\api\controller\Order::comfirmAction($order);
});
}
// 删除 job
$job->delete();
} catch (\Exception $e) {
// 队列执行失败
\think\Log::write('queue-' . get_class() . '-autoComplete' . ':执行失败,错误信息:' . $e->getMessage());
}
}
}
\ No newline at end of file
... ...
... ... @@ -10,6 +10,7 @@
// +----------------------------------------------------------------------
return [
'grab' => 300, // 抢单倒计时(秒)
'pay' => 300, // 缴费倒计时(秒)
'grab' => 300, // 抢单倒计时,5分钟=300秒
'pay' => 300, // 缴费倒计时,5分钟=300秒
'complete' => 60, // 自动确认成交,24小时=86400秒
];
... ...
... ... @@ -110,7 +110,7 @@ class Notify extends Frontend
foreach ($list as $v) {
(new Wechat)->tmplmsg($v['openid'],$send_data,$templateid,$url);
}
\think\Queue::later(config('countdown.grab'), '\app\api\job\OrderAutoOper@autoCancel', ['order' => $order], 'parking');
\think\Queue::later(config('countdown.grab'), '\app\api\job\OrderAutoOper@autoCancel', ['order_id'=>$order['id']], 'parking');
return true;
}
... ...