setName('xQueue:TaobaoAutoUpOrDown')->setDescription('[ 淘宝直充 - 自动同步 ] 特定渠道库存或余额不足自动下架'); } /** * @param Input $input * @param Output $output * @throws \think\admin\Exception */ protected function execute(Input $input, Output $output) { ini_set('memory_limit', '1024M'); $this->redis(); $orderService = OrderService::instance(); $where1 = [ 'status' => '3' , ]; $where[] = [ 'product_key','like','%cardbuy%' ]; $ck[] = [ 'response','like','%msg%' ]; $ck1[] = [ 'create_at','>',date("Y-m-d H:i:s",strtotime(date("Y-m-d H:i:s")) - 10) ]; $field = "id,order_id,merchant_order_id,cid,response";//需要数据库返回的字段 list($count, $total) = [0, $orderService->db()->field($field)->where($where1)->where($where)->where($ck)->where($ck1)->order('id desc')->count()]; $mid = '1'; $merchant = MerchantService::instance()->get($mid); $orderService->db()->field($field)->where($where1)->where($where)->where($ck)->where($ck1)->order('id desc')->chunk(100, function (Collection $data) use (&$count, $total,$merchant) { // var_dump($orderlist);die; $array = $data->toArray(); $url = 'send_group_msg'; # $param = array(); $atqq = '373103766';#需要艾特的qq $atqq1 = '785557837'; $param['group_id'] = '770225115';#群组号 $send = new Qqbot($this->app); $up = true; $json = json_encode($array,JSON_UNESCAPED_UNICODE); if (str_contains($json,"您的资金不足,请联系您的上级" )) { $itemId = [ 0 => '768693874089', 1 => '768689877212', 2 => '768694799018', 3 => '768577922760', 4 => '768692862582', 5 => '768612772765', 6 => '768698287210', 7 => '768695082610', 8 => '768695022095', 9 => '768693018899', ]; $errorItem = ''; foreach ($itemId as $vo) { $upItemStatus = $this->DownItemStatus($vo, $merchant['access_token']); $json = json_encode($upItemStatus); $array = json_decode($json,true); if(isset($array['result']) && $array['result'] = 'success'){ $up = false; }else{ $up = true; $errorItem = $errorItem." \r " .$vo; } } if(empty($errorItem)){ $param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "] 众茂卡密资金不足,已经自动下架全部商品,新及时核实并处理 " ; // $response = $send->send($url, $param); $response =[ 'status' =>'ok' ]; if (isset($response['status']) && $response['status'] == 'ok') { $this->setQueueProgress(" 众茂卡密资金不足并通知客服成功", $count / $total * 100); } else { $this->setQueueProgress(" 众茂卡密资金不足并通知客服失败", $count / $total * 100); } }else{ $param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "] 众茂卡密资金不足,已经自动下架部分商品,还有商品 ".$errorItem."没有下架成功,,新及时核实并处理 " ; // $response = $send->send($url, $param); $response =[ 'status' =>'ok' ]; if (isset($response['status']) && $response['status'] == 'ok') { $this->setQueueProgress(" 众茂卡密资金不足并通知客服成功", $count / $total * 100); } else { $this->setQueueProgress(" 众茂卡密资金不足并通知客服失败", $count / $total * 100); } } } if (str_contains($json,"限购" )) { $itemId = [ 0 => '768693874089', 1 => '768689877212', 2 => '768694799018', 3 => '768577922760', 4 => '768692862582', 5 => '768612772765', 6 => '768698287210', 7 => '768695082610', 8 => '768695022095', 9 => '768693018899', ]; $errorItem = ''; if($up){ foreach ($itemId as $vo) { $upItemStatus = $this->DownItemStatus($vo, $merchant['access_token']); $json = json_encode($upItemStatus); $array = json_decode($json,true); if(isset($array['result']) && $array['result'] = 'success'){ $up = false; }else{ $errorItem = $errorItem." \r " .$vo; } } if(empty($errorItem)){ $param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "] 众茂卡密出现限购,已经自动下架全部商品,请及时核实并处理 " ; // $response = $send->send($url, $param); $response =[ 'status' =>'ok' ]; if (isset($response['status']) && $response['status'] == 'ok') { $this->setQueueProgress(" 众茂卡密出现限购并通知客服成功", $count / $total * 100); } else { $this->setQueueProgress(" 众茂卡密出现限购并通知客服失败", $count / $total * 100); } }else{ $param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "] 众茂卡密出现限购,已经自动下架部分商品,还有商品 ".$errorItem."没有下架成功,请及时核实并处理 " ; // $response = $send->send($url, $param); $response =[ 'status' =>'ok' ]; if (isset($response['status']) && $response['status'] == 'ok') { $this->setQueueProgress(" 众茂卡密出现限购并通知客服成功", $count / $total * 100); } else { $this->setQueueProgress(" 众茂卡密出现限购并通知客服失败", $count / $total * 100); } } } } if (str_contains($json,"余额不足" )) { // $itemId = [ // 0 => '767466259222', // 1 => '767466359547', // 2 => '767452201528', // 3 => '767450321268', // 4 => '767449685071', // 5 => '767462566926', // 6 => '767461794349', // 7 => '767448993185', // 8 => '767444593836', // 9 => '767372188152', // ]; // // $errorItem = ''; // if($up){ // foreach ($itemId as $vo) { // $upItemStatus = $this->DownItemStatus($vo, $merchant['access_token']); // $json = json_encode($upItemStatus); // $array = json_decode($json,true); // // if(isset($array['result']) && $array['result'] = 'success'){ // $up = false; // // }else{ // $errorItem = $errorItem." \r " .$vo; // } // } // if(empty($errorItem)){ // // $param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "] 众茂卡密出现限购,已经自动下架全部商品,请及时核实并处理 " ; // // $response = $send->send($url, $param); // if (isset($response['status']) && $response['status'] == 'ok') { // $this->setQueueProgress(" 众茂卡密出现限购并通知客服成功", $count / $total * 100); // } else { // $this->setQueueProgress(" 众茂卡密出现限购并通知客服失败", $count / $total * 100); // } // }else{ // $param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "] 众茂卡密出现限购,已经自动下架部分商品,还有商品 ".$errorItem."没有下架成功,请及时核实并处理 " ; // // $response = $send->send($url, $param); // if (isset($response['status']) && $response['status'] == 'ok') { // $this->setQueueProgress(" 众茂卡密出现限购并通知客服成功", $count / $total * 100); // } else { // $this->setQueueProgress(" 众茂卡密出现限购并通知客服失败", $count / $total * 100); // } // } // } } }); $this->setQueueSuccess("共发现 {$total} 个异常失败订单!"); } public function send($url, $param) { $geturl = 'http://124.70.52.119:7374/' . $url; return http_post($geturl, $param); } public function DownItemStatus($itemId,$access_token) { $request = []; $request['agentId'] = '34656002'; $request['agentkey'] = 'c38fd5c6d8473fbf02084dd8cfd00ffb'; $request['itemId'] = $itemId; $request['access_token'] = $access_token; return Coretb::taobaosdk('itemDownshelf', $request); } protected function redis() { if (!$this->redis) { $this->redis = RedisService::getInstance(); } } }