where(['id' => $supplys_id])->one() : SupplysModel::find()->where(['app_secret' => $sign])->one(); if (empty($supply)) { NoticeModel::updateAll([ 'response' =>"supply 不存在,sign:{$sign}", 'response_time' => time(), ], ['id' => $notice_id]); \Yii::error("supply 不存在,sign:{$sign}"); return true; } $service = new self(['mall_id' => $supply->mall_id, 'supply_id' => $supply->id, 'data' => $data]); if (!method_exists($service, $method)) { NoticeModel::updateAll([ 'response' => "qijuhe供应链回调:类型处理方法不存在", 'response_time' => time(), ], ['id' => $notice_id]); \Yii::error("qijuhe供应链回调:类型处理方法不存在"); return true; } $service->mall_id = $supply->mall_id; $service->supply_id = $supply->id; $service->before($data); try { $res = $service->$method(); } catch (\Exception $e) { \Yii::error("qijuhe供应链处理失败:" . $e->getMessage()); $res = $e->getMessage(); } $service->after($notice_id, $res); return -4; } public function before($data) { } public function after($id, $response) { $res = is_array($response) ? Json::encode($response) : $response; $notice_id = $this->data['notice_id'] ?? ''; NoticeModel::updateAll([ 'mall_id' => $this->mall_id, 'supply_id' => $this->supply_id, 'response' => $res, 'response_time' => time(), ], ['id' => $id]); } // 商品价格修改 public function goods_price_alter() { $goods_id = $this->data['product_id'] ?? 0; if (empty($goods_id)) { return true; } $goods_id = is_array($goods_id) ? $goods_id : [$goods_id]; return $this->_update_goods($goods_id); } // 商品修改 public function goods_alter() { $goods_id = $this->data['product_id'] ?? 0; if (empty($goods_id)) { return true; } $goods_id = is_array($goods_id) ? $goods_id : [$goods_id]; return $this->_update_goods($goods_id); } // 商品上架 public function goods_on_sale() { $goods_id = $this->data['product_id'] ?? 0; if (empty($goods_id)) { return true; } $goods_id = is_array($goods_id) ? $goods_id : [$goods_id]; return $this->_update_goods($goods_id); } // 商品下架 public function goods_undercarriage() { $goods_id = $this->data['product_id'] ?? 0; if (empty($goods_id)) { return true; } $goods_id = is_array($goods_id) ? $goods_id : [$goods_id]; return $this->_update_goods($goods_id); } // 商品删除 public function goods_delete() { $goods_id = $this->data['product_id'] ?? 0; if (empty($goods_id)) { return true; } $goods_id = is_array($goods_id) ? $goods_id : [$goods_id]; return $this->_del_goods($goods_id); } // 订单取消 public function order_cancel() { } /** * 售后确认收货 * * @return void */ public function after_sales_receiving() { // 不处理 // 商家发货 {"order_item_id":452,"third_order_sn":"s20240611195720484922","after_sales_id":58,"message_type":"after_sales.receiving","member_sign":"0e2207362367b5803930dc4da38e0003"} $third_order_sn = $this->data['third_order_sn'] ?? 0; $after_sales_id = $this->data['after_sales_id'] ?? 0; if (empty($third_order_sn)) { return true; } $service = new RefundService(['mall_id' => $this->mall_id]); try { $service->after_sales_receiving($third_order_sn, $after_sales_id); } catch (\Exception $e) { \Yii::error(FormatHelper::exception($e, __METHOD__)); return false; } return true; } /** * 售后审核成功 * * @return boolean */ public function after_sales_pass() { $third_order_sn = $this->data['third_order_sn'] ?? 0; $after_sales_id = $this->data['after_sales_id'] ?? 0; if (empty($third_order_sn)) { return true; } $service = new RefundService(['mall_id' => $this->mall_id]); $service->after_sales_pass($third_order_sn, $after_sales_id, $this->data['order_item_id'] ?? 0); return true; } /** * 售后确认退款 * * @return boolean */ public function after_sales_complete() { $third_order_sn = $this->data['third_order_sn'] ?? 0; if (empty($third_order_sn)) { return true; } $service = new RefundService(['mall_id' => $this->mall_id]); $service->after_sales_complete($third_order_sn, $this->data['after_sales_id'] ?? 0); return true; } /** * 售后审核驳回 * * @return boolean */ public function after_sales_reject() { $third_order_sn = $this->data['third_order_sn'] ?? 0; $after_sales_id = $this->data['after_sales_id'] ?? 0; $order_item_id = $this->data['order_item_id'] ?? 0; $service = new RefundService(['mall_id' => $this->mall_id]); $service->after_sales_reject($third_order_sn, $after_sales_id, $order_item_id); return true; } // 订单发货 public function order_delivery() { $order_sn = $this->data['order_sn'] ?? 0; if (empty($order_sn)) { return true; } $service = new OrderService([]); $res = $service->updateLogistic($order_sn); return ['msg' => 'ok']; } public function order_sending() { return $this->order_delivery(); } public function after_sales_close() { // $order_sn = $this->data['order_sn'] ?? 0; // $after_sales_id = $this->data['after_sales_id'] ?? 0; // if (empty($order_sn) || empty($after_sales_id)) { // return true; // } // // $service = new RefundService([]); // $res = $service->thirdCancel($order_sn, $after_sales_id); return $this->after_sales_reject(); } private function _update_goods($goods_id) { // 获取选品库id $storage_id = StorageModel::byGoodsIdFindStorageId($goods_id); // 更新插件商品库的商品信息 $service = new GoodsService(); $service->importLocal($storage_id); // 更新系统商品库的信息 QiGoodsService::queueAdd($storage_id, $this->mall_id, true); return ['msg' => 'ok']; } /** * 处理删除商品 * * @param array $goods_ids * @return void */ protected function _del_goods(array $goods_ids) { // 修改选品库 StorageModel::changeStatusByMidGoodsIds($this->mall_id, $goods_ids, 3); // 直接下架商品 MallGoodsModel::updateDown($this->mall_id, StorageModel::getMallGoodsIds($this->mall_id, $goods_ids)); return ['msg' => 'ok']; } }