From d7729119c599f7120688273cb8503add48db2f3e Mon Sep 17 00:00:00 2001 From: mzeros Date: Thu, 2 Jan 2025 16:08:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor(order):=20=E4=BC=98=E5=8C=96=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=8F=96=E6=B6=88=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改了订单取消的查询条件,使用 <= 替代 >= - 优化了订单取消的处理流程,使用 chunk 分批处理 - 增加了商户列表的获取和遍历逻辑 - 调整了变量命名和代码结构,提高了可读性 --- app/openapi/controller/Test.php | 94 +++++++++++++++++++++---- app/queue/command/order/OrderCancel.php | 5 +- 2 files changed, 83 insertions(+), 16 deletions(-) diff --git a/app/openapi/controller/Test.php b/app/openapi/controller/Test.php index 7822677..ab1e2c0 100644 --- a/app/openapi/controller/Test.php +++ b/app/openapi/controller/Test.php @@ -1056,21 +1056,87 @@ class Test extends Core public function execute() { ini_set('memory_limit', '1024M'); - $day = input('day'); - $page = 1; - $this->finishOne_lastWeek($day, $page); -// var_dump($day);die; -// var_dump($day);die; -// MerchantService::instance()->init($day); - /* - if (!$day) { - $day = date('Y-m-d', strtotime('-1 day')); - } - */ - $page = 1; - while ($this->finishOne_lastWeek($day, $page)) { - $page++; + + $channelService = ChannelService::instance(); + + $channelList = $channelService->db()->where(['cancel_status'=>1,'status'=>1])->select()->toArray(); + $merchantService = MerchantService::instance(); + $merchantList = $merchantService->db()->where(['cancel_support'=>1,'status'=>1])->select()->toArray(); + $merchantList_num = count($merchantList); + $count_sum = 0; + $total_sum=0; + +// $channelList_num = count($channelList); +// $count_sum = 0; +// $total_sum=0; + $class = OrderService::instance(); + foreach ($merchantList as $merchant) { + $mid = $merchant['id']; + $other_param = $merchant['other_param']; + $array = json_decode($other_param,true); + $timeout_cancel = 3600; + if(isset($array['timeout_cancel'])){ + $timeout_cancel = $array['timeout_cancel']; + } +// if(isset($array['timeout_cancel_form'])){ +// $timeout_cancel = $array['timeout_cancel_form']; +// } + + foreach($channelList as $channel) { + if(isset($array['timeout_cancel_form'])){ + $timeout_cancel = $array['timeout_cancel_form']; + $where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['create_at','>=',date('Y-m-d H:i:s',time()-$timeout_cancel)]]; + + }else{ + $where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['expire_time','<=',date('Y-m-d H:i:s',time()+$timeout_cancel)]]; + } + + + + + list($count, $total) = [0, $class->db()->where($where)->order('id asc')->count()]; + $total_sum += $total; +// $data = $class->db()->where($where)->limit(100)->select()->toArray(); + $class->db()->where($where)->order('id asc')->chunk(100, function (Collection $data) use (&$count, $total,$channel,$channelService,&$count_sum,$class) { + $array = $data->toArray(); + if($array){ + + + foreach ($array as $k => $vo) { + $class->db()->where(['order_id'=>$vo['order_id']] )->update(['apply_refund'=>1]); + if(isset($vo['num']) && $vo['num']>0) { + $vo['order_id'] = $vo['order_id'].'_'.$vo['num']; + } + var_dump($vo);die; + + + $result = $channelService->call('cancel', $vo['cid'], $vo); + if ($result) { + $count_sum++; + $count++; + } + } + } + + + + }); + + + + + } + } + + + + + + + + + } public function finishOne_lastWeek($day, $page) diff --git a/app/queue/command/order/OrderCancel.php b/app/queue/command/order/OrderCancel.php index f9e97e0..427ad48 100644 --- a/app/queue/command/order/OrderCancel.php +++ b/app/queue/command/order/OrderCancel.php @@ -65,7 +65,7 @@ class OrderCancel extends Command foreach($channelList as $channel) { if(isset($array['timeout_cancel_form'])){ $timeout_cancel = $array['timeout_cancel_form']; - $where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['create_at','>=',date('Y-m-d H:i:s',time()-$timeout_cancel)]]; + $where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['create_at','<=',date('Y-m-d H:i:s',time()-$timeout_cancel)]]; }else{ $where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['expire_time','<=',date('Y-m-d H:i:s',time()+$timeout_cancel)]]; @@ -82,11 +82,12 @@ class OrderCancel extends Command if($array){ foreach ($array as $k => $vo) { - $class->db()->where(['order_id','=',$vo['order_id']] )->update(['apply_refund'=>1]); + $class->db()->where(['order_id'=>$vo['order_id']] )->update(['apply_refund'=>1]); if(isset($vo['num']) && $vo['num']>0) { $vo['order_id'] = $vo['order_id'].'_'.$vo['num']; } + $result = $channelService->call('cancel', $vo['cid'], $vo); if ($result) { $count_sum++;