| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace addons\StarChain\common\services;
- use addons\StarChain\common\listeners\CategorysImportListener;
- use addons\StarChain\common\models\Category;
- use common\enums\RabbitMqEnum;
- use Yii;
- /**
- * 分类服务
- */
- class CategorysService extends BaseService
- {
- /**
- * 导入分类
- *
- * @return void
- */
- public function import($id = 0)
- {
- Yii::$app->services->rabbitMq->push(
- RabbitMqEnum::EXCHANGE_ORDER,
- RabbitMqEnum::TASK_QUEUE,
- [
- 'mall_id' => $this->mall_id,
- 'id' => $id,
- ],
- CategorysImportListener::class,
- 'async_handle'
- );
- return true;
- }
- /**
- * 任务执行导入
- *
- * @param integer $id
- * @return boolean
- */
- public function taskImport($id = 0)
- {
- $list = $this->api->getCategorys(['id' => $id]);
- if (empty($list)) {
- return true;
- }
- $list = array_map(function ($v) use ($id) {
- $v['category_id'] = $v['id'];
- $v['pid'] = $id;
- $v['created_at'] = $v['updated_at'] = time();
- unset($v['id']);
- return $v;
- }, $list);
- foreach ($list as $v) {
- $this->import($v['category_id']);
- }
- Category::batchInsert($list);
- }
- /**
- * 分类列表
- *
- * @return array
- */
- public function list($pid = 0)
- {
- return $this->api->getCategorys(['id' => $pid]);
- $list = Category::find()->where([
- // 'mall_id' => $this->mall_id,
- 'pid' => $pid,
- ])->asArray()->all();
- return $list;
- }
- }
|