setName('xQueue:KamiOrderErrorRefund')->setDescription('[ 卡密列表 - 自动同步 ] 错误订单退款'); } /** * @param Input $input * @param Output $output * @throws \think\admin\Exception */ protected function execute(Input $input, Output $output) { ini_set('memory_limit', '1024M'); $kami91server = Kami91OrderService::instance(); $cur = time(); $time = 300; $whereRaw = $cur . '-unix_timestamp(create_at) >=' . $time; list($count, $total) = [0, $kami91server->db()->whereRaw('status = 1 and ' . $whereRaw)->count()]; // $taobao = new \app\openapi\controller\Taobao($this->app); $kami91server->db()->whereRaw('status = 1 and ' . $whereRaw)->chunk(100, function (Collection $data) use (&$count, $total, $kami91server) { // var_dump($orderlist);die; foreach ($data->toArray() as $vo) { $merchant_order_id = $vo['merchant_order_id']; // $orderService = OrderService::instance(); if(str_ends_with($merchant_order_id, '-00')){ $merchant_order_id = substr($merchant_order_id, 0, -3); } // $orderService = OrderService::instance(); $order = OrderService::instance()->get('',$merchant_order_id, $vo['mid']); if (!$order) { $upData = []; $upData['order_id'] = 'E' . $vo['merchant_order_id']; $upData['status'] = '3'; $upData['callback_msg'] = '{-错误订单-}'; $upData['callback_at'] = date('Y-m-d H:i:s'); $kami91server->db()->where(array('merchant_order_id' => $vo['merchant_order_id']))->update($upData); # 失败... $apiParams['coop_order_status'] = 'FAILED'; $apiParams['failed_code'] = '1067'; $apiParams['failed_reason'] = '淘宝订单不存在'; $merchant = MerchantService::instance()->getInfo($vo['mid']); $msg = $this->notify($merchant, $merchant_order_id, $apiParams); if ($msg == 'success') { $count++; $this->setQueueProgress("错误订单退款 {$vo['merchant_order_id']} ", $count / $total * 100); } } } }); $this->setQueueSuccess("总计 {$total} 个, 处理成功 {$count} 个错误订单退款!"); } public function notify($merchant, $merchant_order_id, $apiParams) { $requestParam = [ 'coopId' => '2217166441303', 'tbOrderSnap' => ' ' ]; if(isset($merchant['other_param'])){ $other_param = json_decode($merchant['other_param'],true); if(is_array($other_param) && isset($other_param['tbCoopId'])){ $requestParam['coopId'] = $other_param['tbCoopId']; } } $request = [ 'order_id' => 'E' . $merchant_order_id, 'merchant_order_id' => $merchant_order_id ]; try { $senddata = Coretb::doaction($merchant, $request, $requestParam, $apiParams); } catch (\Exception $e) { Log::write('errorTip', 'taobao_notify', $e->getMessage()); return 'error'; } $data = (array)$senddata; if (isset($data['update_result']) == 'T') { return 'success'; } else { return json_encode($data); } } }