where(['mall_id' => $mall_id])->each() as $each) { echo $each->goods_id . "\n"; $storage_id = StorageModel::byGoodsIdFindStorageId([$each->goods_id]); // 更新插件商品库的商品信息 $service = new GoodsService(); $service->importLocal($storage_id); // 更新系统商品库的信息 QiGoodsService::queueAdd($storage_id, $mall_id); } } } public function actionOrder() { try { // order_source = '' AND pay_status = 1 AND created_at > 1718097620 AND order_status = 1 foreach (\common\models\order\Order::find() ->where(['and', ['order_source' => 'QiJuhe'], ['pay_status' => 1], ['>', 'created_at', 1718097620], ['order_status' => 1], ['not in', 'id', [806, 807, 808, 809, 888, 889]]]) ->each() as $each) { echo "{$each->id} \n"; try { \addons\QiJuhe\common\service\OrderService::createOrderV2($each->id); } catch (\Exception $e) { echo ($e->getMessage() .'--'. $e->getFile() .'--'. $e->getLine() . "\n"); } } // \addons\QiJuhe\common\service\OrderService::createOrderV2(889); } catch (\Exception $e) { var_dump($e->getMessage(), $e->getFile(), $e->getLine()); } } public function actionTest() { // (new \addons\QiJuhe\common\service\OrderService([]))->updateLogistic('s20240724225942824475'); // \addons\QiJuhe\common\listeners\OrderPaidListener::async_handle(['id' => 4218]); $RefundService = new \addons\QiJuhe\common\service\RefundService(['mall_id' => 1]); $RefundService->after_sales_pass('s20241220184903474265', 1028); } public function actionRefund() { $db = \Yii::$app->db->beginTransaction(); try { $params = [ 'order_detail_id' => 7373, 'type' => 1 ]; $order_detail = OrderDetail::findOne(['id' => $params['order_detail_id']]); // 订单是否聚合 $order = MallOrderModel::find()->where(['id' => $order_detail['order_id']])->select('id, order_no, mall_id, shipping_money, order_source')->one(); if($order->order_source == AddonsEnum::ADDONS_NAME_CARD_COUPONS){ $goods = Goods::findOne($order_detail['goods_id']); if(!$goods || $goods['goods_source'] != QiJuheEnum::PLUGIN_SIGN) throw new \Exception('该订单不是聚合供应链订单'); }else{ if ($order->order_source != QiJuheEnum::PLUGIN_SIGN) throw new \Exception('该订单不是聚合供应链订单'); } // 中台订单 $supply_order = OrderModel::find()->where(['order_id' => $order->id,'order_detail_id'=>$order_detail['id']])->one(); if (empty($supply_order)) { throw new \Exception('供应链订单不存在'); } // 添加聚合售后 OrderRefundModel::add([ 'user_id' => $order_detail->user_id, 'order_no' => $order->order_no, 'mall_id' => $order->mall_id, 'supply_id' => $supply_order->supply_id, 'order_id' => $order_detail['order_id'], 'order_detail_id' => $order_detail['id'], 'order_refund_id' => 529, 'num' => $order_detail->num, 'data' => $this->getSendData($params, $order, $supply_order), ]); $db->commit(); } catch (\Exception $e) { $db->rollBack(); var_dump($e->getMessage()); } } /** * 获取推送数据 * * @param array $params * @return array */ public function getSendData($params, $order, $supply_order) { return [ 'third_order_sn' => $order->order_no, // 订单id与采购端订单号两个必传一个 'order_item_id' => (int)$supply_order->getOrderItemId(), // 子订单id 'reason_type' => (int)$params['reason_id'], // 售后原因(售后原因API返回) 'reason' => $params['remark'], // 售后原因是 其他的的时候填写 'description' => $params['remark'], // 描述 'is_received' => (int)RefundTypeEnum::getReasonParam($params['type'])['is_received'], // 是否收到货 1是0否 'detail_images' => $params['pic_list'] ?? [], // 图片凭证 'refund_type' => (int)RefundTypeEnum::getReasonParam($params['type'])['after_sale_type'], // 0退款 1退货退款 ]; } public function actionStorage() { foreach (Mall::getAllMallIds() as $mall_id) { \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, ['mall_id' => $mall_id], self::class, 'handleSync'); echo "同步选品库: $mall_id \n"; } } public function actionAudit() { $cids = []; /** * @var $storage StorageModel */ foreach (StorageModel::find()->batch() as $storages) { $ids = []; foreach ($storages as $storage) { $ids[] = $storage->middle_goods_id; } $_ids = GoodsSkuModel::find()->where(['supply_goods_id' => $ids])->select('supply_goods_id')->di->column(); if (count($_ids) != count($ids)) { // echo implode(',', array_diff($ids, $_ids)) . "\n"; array_push($cids, ...array_diff($ids, $_ids)); } } $__ids = array_unique($cids); /** * @var $good GoodsSkuModel */ foreach (GoodsSkuModel::find()->where(['supply_goods_id' => $__ids])->batch() as $goods) { foreach ($goods as $good) { $api = ApiService::getConnect($good->mall_id, $good->supply_id); // 添加选品库 $ret = $api->addStorage([$good->supply_goods_id]); if ($ret === false) { echo "添加选品库失败: {$good->supply_goods_id} $api->error \n"; } } } } public function actionBasic() { /** * @var $good GoodsSkuModel */ foreach (GoodsSkuModel::find()->where(['mall_id' => 7])->batch() as $goods) { foreach ($goods as $good) { $api = ApiService::getConnect($good->mall_id, $good->supply_id); // 添加选品库 $ret = $api->addStorage([$good->supply_goods_id]); if ($ret === false) { echo "添加选品库失败: {$good->supply_goods_id} $api->error \n"; } else { echo "{$good->supply_goods_id} \n"; } } } } public static function handleSync($params) { $mall_id = $params['mall_id']; $supply_ids = StorageModel::find()->where(['mall_id' => $mall_id])->select('supply_id')->distinct()->column(); if (empty($supply_ids)) return; foreach ($supply_ids as $supply_id) { if (empty($supply_id)) continue; $t = 1; /** * @var $storage StorageModel */ foreach (StorageModel::find()->where(['mall_id' => $mall_id])->andWhere(['supply_id' => $supply_id])->batch() as $storages) { $ids = []; foreach ($storages as $storage) { $ids[] = $storage->middle_goods_id; } } /** * @var $storage StorageModel */ foreach (StorageModel::find()->where(['mall_id' => $mall_id])->andWhere(['is_delete' => 0])->andWhere(['supply_id' => $supply_id])->each() as $storage) { $ids[] = $storage->middle_goods_id; if (count($ids) === 20) { \Yii::error("同步选品库: $mall_id $supply_id $t -- " . json_encode($ids)); $api = ApiService::getConnect($mall_id, $supply_id); // 添加选品库 $ret = $api->addStorage($ids); if (!$ret) { \Yii::error("同步选品库失败: $mall_id $supply_id $t -- ". $api->error .'--'. json_encode($ids)); } $ids = []; ++$t; } } } } }