| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace addons\StarChain\common\services;
- use addons\StarChain\common\models\Goods;
- use addons\StarChain\common\models\Storage;
- use yii\data\Pagination;
- use yii\helpers\Json;
- /**
- * 商品库服务
- */
- class StorageService extends BaseService
- {
- /**
- * 获取商品库列表
- *
- * @param array $params
- * @return array
- */
- public function getStorageList($params)
- {
- $limit = $params['limit'] ?? 10;
- $model = Storage::find();
- $model->with(['goods' => function ($query) {
- $query->with([
- 'category1', 'category2', 'category3',
- ])->select('id, name, spu_id, category_id_1, category_id_2, category_id_3, carousel_img_list, status');
- }]);
- $model->andWhere(['mall_id' => $this->mall_id, 'is_delete' => 0]);
- if (isset($params['category_ids'][0])) {
- $model->andWhere([
- 'spu_id' => Goods::find()->where(['category_id_1' => $params['category_ids'][0]])->select('spu_id')
- ]);
- }
- if (isset($params['category_ids'][1])) {
- $model->andWhere([
- 'spu_id' => Goods::find()->where(['category_id_2' => $params['category_ids'][1]])->select('spu_id')
- ]);
- }
- if (isset($params['category_ids'][2])) {
- $model->andWhere([
- 'spu_id' => Goods::find()->where(['category_id_3' => $params['category_ids'][2]])->select('spu_id')
- ]);
- }
- if (!empty($params['name'])) {
- $model->andWhere([
- 'spu_id' => Goods::find()->andWhere(['like', 'name', $params['name']])->select('spu_id')
- ]);
- }
- if (isset($params['import']) && $params['import'] !== '') {
- $model->andWhere([
- 'import' => $params['import']
- ]);
- }
- $pagination = new Pagination(['totalCount' => $model->count(), 'pageSize' => $limit]);
- $model->limit($pagination->limit)->offset($pagination->offset);
- $list = $model->orderBy('id desc')
- ->asArray()
- ->all();
- foreach ($list as $k => $v) {
- $list[$k]['goods']['carousel_img_list'] = Json::decode($v['goods']['carousel_img_list']);
- }
- $data['list'] = $list;
- $data['page_count'] = $pagination->pageCount;
- return $data;
- }
- }
|