store_id = get_store_id(); } /** * @return array */ public function rules() { return [ [['store_id', 'process_user_id', 'product_batch_id','form_list', 'process_name', 'sort'], 'required'], [['store_id', 'id', 'process_user_id', 'product_batch_id', 'is_change_sheet' ,'sort', 'id'], 'integer'], [['process_name',], 'string', 'max' => 255], [['form_list',], 'safe',], [['product_batch_id', 'is_change_sheet'], 'default', 'value' => 0], ]; } public function attributeLabels() { return [ 'id' => 'ID', 'store_id' => '商城id', 'process_name' => '流程名称', 'process_user_id' => '流程操作用户', 'product_batch_id' => '批次id', 'created_at' => '创建时间', 'updated_at' => '更新时间', 'is_delete' => 'Is Delete', 'sort' => 'sort', ]; } /** * @param array $arr | status 状态 name 名称 cat_id 分类id mch_id 入驻商 is_verify 审核 select 查询数据 * @return array */ public static function getList ($arr = []) { $query = Goods::find()->alias('g') ->where(['g.store_id' => get_store_id(), 'g.is_delete' => 0, 'g.md_food_id' => 0])->andWhere(['not like', 'g.name', '当面付']); if (isset($arr['status']) && $arr['status'] > -1) { $query->andWhere([ 'g.status' => $arr['status'] ]); } if (!empty($arr['is_verify_card'])) { $query->andWhere([ 'g.product_type' => 0, 'g.status' => 1 ]); } else { if (isset($arr['product_type']) && in_array($arr['product_type'], Goods::$validProductType)) { $query->andWhere([ 'g.product_type' => $arr['product_type'] ]); } } //是否是云仓商品 if (isset($arr['is_cloud']) && $arr['is_cloud'] ) { $query->andWhere([ '>', 'g.cloud_goods_id' , 0 ]); } if (isset($arr['name']) && !empty($arr['name'])) { $query->andWhere([ 'like', 'g.name', $arr['name'] ]); } if (isset($arr['cat_id']) && $arr['cat_id'] > 0) { if ($arr['mch_id'] > 0) { $query->leftJoin(['mgc' => MchGoodsCat::tableName()], 'g.id = mgc.goods_id')->andWhere([ 'mgc.cat_id' => MchCat::getCatId($arr['cat_id']) ])->groupBy('mgc.goods_id'); } else { $query->leftJoin(['gc' => GoodsCat::tableName()], 'g.id = gc.goods_id')->andWhere([ 'gc.cat_id' => Cat::getCatId($arr['cat_id']) ])->groupBy('gc.goods_id'); } } if (isset($arr['mch_cat_id']) && $arr['mch_cat_id'] > 0) { $query->leftJoin(['mgc' => MchGoodsCat::tableName()], 'g.id = mgc.goods_id')->andWhere([ 'mgc.cat_id' => MchCat::getCatId($arr['mch_cat_id']) ])->groupBy('mgc.goods_id'); } // 根据入驻商查询 0 平台 -1 全部入驻商 >0 对应入驻商 if (empty($arr['mch_id'])) { $query->andWhere(['g.mch_id' => 0]); } elseif(isset($arr['mch_id']) && $arr['mch_id'] == -1) { $query->andWhere([ '>', 'g.mch_id', 0 ]); } elseif (isset($arr['mch_id']) && $arr['mch_id'] > 0){ $query->andWhere(['g.mch_id' => $arr['mch_id']]); } // 获取入驻商待审核商品 if (isset($arr['is_verify'])) { $query->andWhere([ 'g.is_verify' => $arr['is_verify'] ]); } if (!empty($arr['select'])) { $select = $arr['select']; } else { $select = ['g.id', 'g.name', 'g.status', 'g.service', 'g.updated_at', 'g.virtual_sales', 'g.is_verify', 'g.is_negotiable', 'g.price', 'g.goods_num', 'g.sort' ,'g.cover_pic', 'g.original_price', 'g.quick_purchase', 'g.attr', 'g.mch_id', 'g.detail', 'g.use_attr', 'g.product_type', 'g.is_recommend']; } $query->with(['mch'])->select($select) ->orderBy(['g.sort' => SORT_DESC, 'g.id' => SORT_DESC]); // return $query->createCommand()->getRawSql(); $pagination = pagination_make($query); $pagination['data'] = $pagination['list']; foreach($pagination['data'] as $k => $v) { $goods_cat = GoodsCat::find()->alias('gc') ->leftJoin(['c' => Cat::tableName()], 'gc.cat_id=c.id') ->where([ 'gc.goods_id' => $v['id'] ]) ->select(['c.name']) ->asArray() ->all(); $pagination['data'][$k]['cat'] = $goods_cat; } unset($pagination['list']); $book_goods_ids = Goods::checkBookGoods(); return [ 'code' => 0, 'msg' => 'success', 'book_goods_ids' => $book_goods_ids, 'data' => $pagination ]; } }