GoodsSearchForm.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. use app\models\Cat;
  9. use app\models\Goods;
  10. use app\models\GoodsCat;
  11. use app\models\GoodsFullMinus;
  12. use yii\base\Model;
  13. class GoodsSearchForm extends Model
  14. {
  15. public $id;
  16. public function rules()
  17. {
  18. return [
  19. [['id'], 'integer'],
  20. ];
  21. }
  22. public function fullMinusSearch()
  23. {
  24. $query = GoodsFullMinus::find()->alias('gfm')->select(['gfm.*', 'g.name', 'c.name AS cname', 'g.status'])
  25. ->where(['gfm.store_id' => get_store_id(), 'g.is_delete' => 0, 'g.store_id' => get_store_id(), 'gfm.is_delete' => 0])
  26. ->leftJoin(['g' => Goods::tableName()], 'g.id=gfm.goods_id')
  27. ->leftJoin(['gc' => GoodsCat::tableName()], 'gc.goods_id=g.id')
  28. ->leftJoin(['c' => Cat::tableName()], 'gc.cat_id=c.id');
  29. $query->andWhere(['or', ['gc.is_delete' => 0, 'gc.store_id' => get_store_id()], 'isnull(gc.id)']);
  30. $query->andWhere('gfm.goods_id=:goods_id', [':goods_id' => $this->id])->groupBy('id');
  31. $res = pagination_make($query);
  32. return [
  33. 'code' => 0,
  34. 'data' => $res
  35. ];
  36. }
  37. }