request->isAjax && \Yii::$app->request->isGet) { $data = Yii::$app->request->get(); $valid = Yii::$app->services->validate->validate($data, [ [['limit', 'page', 'cate_id', 'goods_id', 'goods_type', 'discount', 'goods_id'], 'integer'], [['sort', 'sort_type', 'goods_name'], 'string'], ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 取数据 // 判断需要本地的数据还是第三方的数据 $config = (new SettingService())->get($this->mall_id); if (!empty($config['is_default'])) { $ret = (new GoodsService())->thirdPage($this->mall_id, $data); } else { if (empty($config['is_enable'])) { return $this->error('请设置基础设置'); } foreach (Mall::getEnableMallIds() as $mall_id) { $config = (new SettingService())->get($mall_id); if (!empty($config['is_default'])) break; $config = null; } if (empty($config)) return $this->error('还未指定标准选品库'); $ret = (new GoodsService())->localPage($mall_id, $data); } if (!empty($ret['list'])) { $ids = array_column($ret['list'], "goods_id"); $local_list = QiDingDongGoods::lists([ 'where' => [ ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]], ['third_goods_id' => $ids], ['mall_id' => $this->mall_id], ], 'select'=> 'third_goods_id', 'index' => 'third_goods_id' ]); foreach ($ret['list'] as &$item) { $item['is_storage'] = !empty($local_list[$item['goods_id']]); } } return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret); } $cats = CategoryService::custom($this->mall_id); return $this->render('index',['cats' => Json::encode(!empty($cats) ? $cats : []), 'rate' => MallService::rate($this->mall_id)]); } /** * @return mixed|null */ public function actionImport() { $data = Yii::$app->request->post(); $valid = Yii::$app->services->validate->validate($data, [ [['goods'], 'required'], ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 这里执行? $ret = (new GoodsService())->batchImport($this->mall_id, Json::decode($data['goods'])); return is_string($ret) ? $this->error($ret) : $this->success('导入成功'); } /** * 商品详情 * @return mixed|null * @throws \Exception */ public function actionDetail() { $data = Yii::$app->request->get(); $valid = Yii::$app->services->validate->validate($data, [ [['id'], 'required'], ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); try { $ret = (new GoodsService())->detail($this->mall_id, $data['id']); if (is_array($ret)) { $ret['rate'] = MallService::rate($this->mall_id); } return $this->success('获取成功', $ret); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 商品详情 * @return mixed|null * @throws \Exception */ public function actionDel() { $data = Yii::$app->request->post(); $valid = Yii::$app->services->validate->validate($data, [ [['id'], 'required'], ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); try { $ret = (new GoodsService())->delete($this->mall_id, $data['id']); return is_string($ret) ? $this->error($ret) : $this->success('删除成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function actionWrite() { $data = Yii::$app->request->post(); $valid = Yii::$app->services->validate->validate($data, [ [['id'], 'required'], ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); try { $ret = (new GoodsService())->write([ 'mall_id' => $this->mall_id, 'id' => $data['id'] ]); return is_string($ret) ? $this->error($ret) : $this->success('导入成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function actionBatchWrite() { $data = Yii::$app->request->post(); $valid = Yii::$app->services->validate->validate($data, [ [['id'], 'required'], [['id'], 'safe'], ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); try { $cnt = 0; if (!empty($data['id'])) { $ids = QiDingDongGoods::find()->where(['mall_id' => $this->mall_id]) ->andWhere(['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]) ->andWhere(['goods_id' => 0]) ->andWhere(['id' => $data['id']])->select('id')->column(); if (!empty($ids)) { $cnt = count($ids); foreach ($ids as $id) { \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, [ 'mall_id' => $this->mall_id, 'id' => $id ], GoodsService::class, 'write'); } } } return $this->success("后台正在导入 $cnt 件商品"); } catch (\Exception $e) { return $this->error($e->getMessage()); } } }