'storeCount', 'updateStore' => 'updateStore', ]; /** * @var mixed */ protected $result; /** * @var string */ protected $errorMsg; /** * @var int */ public $mall_id; public function init() { if (empty($this->mall_id)) { $this->mall_id = 0; } } protected function success($result = []) { $this->result = $result; return true; } protected function error($msg) { $this->errorMsg = $msg; return false; } public function getResult() { return $this->result; } public function getError() { return $this->errorMsg; } /** * 执行触发器 * * @param string $type * @return boolean */ public function hander(string $type) { if (!in_array($type, $this->hander)) { return $this->error('处理方式不存在'); } if ($this->hasMethod($method = $this->hander[$type])) { return $this->$method(); } } /** * 获取选品数量 * * @return boolean */ protected function storeCount() { $list = GoodsSkuModel::getImportedGoodsIds($this->mall_id); return $this->success( count($list) ); } /** * 更新已导入选品信息 * * @return boolean */ protected function updateStore() { // $list = StorageModel::getListByMallIdAndImported($this->mall_id, ['id', 'goods_id']); $list = GoodsSkuModel::getImportedGoodsIds($this->mall_id); $list = static::dataGroup($list); foreach ($list as $arr) { $goods_ids = array_column($arr, 'id'); Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, [ 'ids' => $goods_ids, 'mall_id' => $this->mall_id, ], QiGoodsService::class, 'handleSync'); } return $this->success(); } private static function dataGroup(array $data, $limit = 20) { $num = ceil(count($data) / $limit); $page_data = []; for ($i = 0; $i < $num; $i++) { isset($data[$i * $limit]) && $page_data[] = array_slice($data, $i * $limit, $limit); } return $page_data; } }