| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\product_traceability\models\form;
- use app\models\Cat;
- use app\models\Goods;
- use app\models\GoodsCat;
- use app\models\MchCat;
- use app\models\MchGoodsCat;
- use app\plugins\product_traceability\models\ProductBatch;
- use app\plugins\product_traceability\models\ProductBatchProcess;
- use app\plugins\product_traceability\models\ProductBatchProcessLog;
- use app\plugins\product_traceability\models\ProductBatchProcessLogSheet;
- use app\plugins\product_traceability\models\ProductBatchProcessSheet;
- use yii\base\Model;
- use yii\helpers\Json;
- use app\jobs\SyncMdGoodsJob;
- use app\utils\Tools;
- class SearchAllGoodsForm extends Model
- {
- public $id;
- public $store_id;
- public $process_user_id;
- public $product_batch_id;
- public $process_name;
- public $sort;
- public $is_change_sheet;
- public $form_list;
- /**
- * 初始化
- */
- public function init()
- {
- $this->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
- ];
- }
- }
|