refactor(order): 优化订单取消逻辑
- 修改了订单取消的查询条件,使用 <= 替代 >= - 优化了订单取消的处理流程,使用 chunk 分批处理 - 增加了商户列表的获取和遍历逻辑 - 调整了变量命名和代码结构,提高了可读性
This commit is contained in:
parent
b97c1ffe94
commit
d7729119c5
@ -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'));
|
||||
|
||||
$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'];
|
||||
}
|
||||
*/
|
||||
$page = 1;
|
||||
while ($this->finishOne_lastWeek($day, $page)) {
|
||||
$page++;
|
||||
// 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)
|
||||
|
@ -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++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user