| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- namespace addons\QiJuhe\console\controllers;
- use addons\QiJuhe\common\enums\QiJuheEnum;
- use addons\QiJuhe\common\enums\RefundTypeEnum;
- use addons\QiJuhe\common\models\GoodsModel;
- use addons\QiJuhe\common\models\GoodsSkuModel;
- use addons\QiJuhe\common\models\MallOrderModel;
- use addons\QiJuhe\common\models\OrderModel;
- use addons\QiJuhe\common\models\OrderRefundModel;
- use addons\QiJuhe\common\models\StorageModel;
- use addons\QiJuhe\common\service\ApiService;
- use addons\QiJuhe\common\service\GoodsService;
- use addons\QiJuhe\common\service\QiGoodsService;
- use common\enums\AddonsEnum;
- use common\enums\RabbitMqEnum;
- use common\models\goods\Goods;
- use common\models\mall\Mall;
- use common\models\order\Order;
- use common\models\order\OrderDetail;
- use yii\console\Controller;
- class FixController extends Controller
- {
- public function actionGoods()
- {
- $mall_ids = [1, 11];
- foreach ($mall_ids as $mall_id) {
- /**
- * @var $each GoodsModel
- */
- foreach (GoodsModel::find()->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;
- }
- }
- }
- }
- }
|