load->_model('Model_express','express'); $this->load->_model("Model_logic_ding","logic_ding"); } public function panduan($order_info,$type,$express_info){ if(empty($order_info)){ return ; } if(!is_array($order_info)){ return ; } //目前只有 4 店铺才处理 if(!in_array($order_info['shop'],[4])){ return ; } $express_info = $this->express->read($order_info['express']); if($type == 1){ return ; return $this->orderCreated($order_info,$express_info); } if($type == 2){ return $this->sendOutWarehouse($order_info,$express_info); } if($type == 3){ return $this->orderPredelivery($order_info,$express_info); } if($type == 4){ return $this->orderDelivery($order_info,$express_info); } } //处理转化接口需要的数据 protected function transferData($order_info,$express_info){ $len = strlen((string)$order_info['shop']); //var_dump($order_info['orderinfo']); $increment_id = substr($order_info['orderinfo'],$len); //var_dump($increment_id); $item_list = [ // [ // "title"=>"", // "sku"=>"", // "qty"=>0, // ] ]; $sku_list = explode(",",$order_info['issku']); $product_list = explode(",",$order_info['product']); $qty_list = explode(";",$order_info['quantity']); $flag = false; foreach($sku_list as $key => $value){ if(empty($product_list[$key])){ $flag= true; } $item_list[] = [ "name"=>$product_list[$key], "sku"=>$value, "qty"=>isset($qty_list[$key])?$qty_list[$key]:1, ]; } if($flag){ return ; } // foreach($sku_list as $key => $value){ // $item_list[] = [ // "name"=>$product_list[$key], // "sku"=>$value, // "qty"=>isset($qty_list[$key])?$qty_list[$key]:1, // ]; // } $address = ""; if(!empty($order_info['street'])){ $address .= $order_info['street']; } if(!empty($order_info['address'])){ $address .= $order_info['address']; } if(!empty($order_info['address2'])){ $address .= $order_info['address2']; } $info = [ "website_id"=>(int)$order_info['shop'], "orderinfo"=>[ "increment_id"=>$increment_id, "store_id"=>$order_info['shop'], "customer_id"=>0, "customer_name"=>$order_info['client'], "customer_email"=>$order_info['email'], "customer_phone"=>$order_info['phone'], "grand_total" =>$order_info['shouldmoney'], "country"=>$order_info['al'], "product_items"=>$item_list, "created_at"=>$order_info['dtime'],//建议只精确到天 不要时分秒 "updated_at"=>0,//发货时间 "address"=>[ "street"=> $address, "city"=> $order_info['city'], "province"=> $order_info['province'], "zip"=> $order_info['zipcode'], "country"=> $order_info['al'], "phone"=> $order_info['phone'], ] ] ]; return $info; } //订单创建 protected function orderCreated($order_info,$express_info = []){ $info = $this->transferData($order_info,$express_info); if(empty($info)){ return ; } $info['updated_at'] = $order_info['time']; $info["act"] = "order_created"; $info["status"]='pending';//订单进行中 $this->sendOrderNotice(json_encode($info)); } //向crm发送订单出货通知 /** * @param $order_info 订单信息 * @param $express_info 快递公司信息 */ protected function sendOutWarehouse($order_info,$express_info =[]){ $info = $this->transferData($order_info,$express_info); if(empty($info)){ return ; } $info['updated_at'] = time(); $info["act"] = "order_shipped"; $info["status"]='processing';//订单进行中 $info['orderinfo']['tracking_number'] = $order_info['waybill']; $info['orderinfo']['carrier'] = $express_info['iscode']; $info['orderinfo']['tracking_url'] = $express_info['url']; $this->sendOrderNotice(json_encode($info)); } //订单预计送达时间 protected function orderPredelivery($order_info,$express_info =[]){ $info = $this->transferData($order_info,$express_info); if(empty($info)){ return ; } $info['updated_at'] = time(); $info["act"] = "order_predelivery"; $info["status"]='processing';//订单进行中 $info['orderinfo']['tracking_number'] = $order_info['waybill']; $info['orderinfo']['carrier'] = $express_info['iscode']; $info['orderinfo']['tracking_url'] = $express_info['url']; $this->sendOrderNotice(json_encode($info)); } //向crm 发送订单收获通知 protected function orderDelivery($order_info,$express_info =[]){ $info = $this->transferData($order_info,$express_info); if(empty($info)){ return ; } $info['updated_at'] = time(); $info["act"] = "order_delivery"; $info["status"]='processing';//订单进行中 $info['orderinfo']['tracking_number'] = $order_info['waybill']; $info['orderinfo']['carrier'] = $express_info['iscode']; $info['orderinfo']['tracking_url'] = $express_info['url']; $this->sendOrderNotice(json_encode($info)); } //向crm发送订单通知 protected function sendOrderNotice($params){ $all_url = "http://crm.hnwmzp.cn/sqs"; $ch = curl_init($all_url); // 设置cURL选项 $options = array( CURLOPT_SSL_VERIFYPEER=>false, CURLOPT_SSL_VERIFYHOST=>false, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $params, CURLOPT_HTTPHEADER => [ 'lytoken'=>'lytec', 'Content-Type: application/json' ], ); // 应用这些选项到cURL会话 curl_setopt_array($ch, $options); // 执行cURL会话并获取响应 $response = curl_exec($ch); //var_dump( $response ); // 检查是否有错误发生 if ($response === false) { $error = curl_error($ch); curl_close($ch); return [ "code"=> -1, "msg"=> $error ]; } // 关闭cURL会话 curl_close($ch); // 输出响应内容 return json_decode($response,true); } }