|
|
@@ -4,6 +4,7 @@ namespace bizHd\goods\classes;
|
|
|
|
|
|
use bizHd\goods\models\GoodsCategory;
|
|
|
use common\components\business;
|
|
|
+use common\components\util;
|
|
|
use Yii;
|
|
|
use bizHd\base\classes\BaseClass;
|
|
|
|
|
|
@@ -13,55 +14,85 @@ class GoodsCategoryClass extends BaseClass
|
|
|
public static $baseFile = '\bizHd\goods\models\GoodsCategory';
|
|
|
|
|
|
//$params 必须预留字段,为后面做准备
|
|
|
- public static function getGoodsList($where, $shop, $custom, $params = [])
|
|
|
+ public static function getGoodsList($askInfo, $shop, $custom, $params = [])
|
|
|
{
|
|
|
- // 获取分页参数
|
|
|
- $get = Yii::$app->request->get();
|
|
|
- $page = $get['page'] ?? 1;
|
|
|
- $pageSize = $get['pageSize'] ?? 20;
|
|
|
+ $requestType = $askInfo['requestType'] ?? '';
|
|
|
+ $page = $askInfo['page'] ?? 1;
|
|
|
+ $pageSize = $askInfo['pageSize'] ?? 20;
|
|
|
+ if (empty($requestType)) {
|
|
|
+ util::fail('没有请求类型');
|
|
|
+ }
|
|
|
|
|
|
- //目前只有商品名称、商品的分类和商品的排序,在xhGoodsCategory里冗余,并且商品的排序只在xhGoodsCategory有
|
|
|
+ /** GoodsCategory 版块查询 **/
|
|
|
$mainId = $shop->mainId;
|
|
|
- // 查询某分类下有库存的商品
|
|
|
$query = GoodsCategory::find();
|
|
|
$query->where(['xhGoodsCategory.mainId' => $mainId]);
|
|
|
- if (!empty($where['cId'])) {
|
|
|
- $query->andWhere(['xhGoodsCategory.cId' => $where['cId']]);
|
|
|
+ if (!empty($askInfo['cId']) || !empty($askInfo['categoryId'])) {
|
|
|
+ $cId = $askInfo['cId'] ?? 0;
|
|
|
+ if (empty($cId)) {
|
|
|
+ $cId = $askInfo['categoryId'] ?? 0;
|
|
|
+ }
|
|
|
+ $query->andWhere(['xhGoodsCategory.cId' => $cId]);
|
|
|
}
|
|
|
- if (!empty($where['name'])) {
|
|
|
- $query->andWhere(['like', 'xhGoodsCategory.name', $where['name']]);
|
|
|
+ if (!empty($askInfo['searchText'])) {
|
|
|
+ $query->andWhere(['like', 'xhGoodsCategory.name', $askInfo['searchText']]);
|
|
|
}
|
|
|
|
|
|
- $flowerNum = $params['flowerNum'] ?? -1;
|
|
|
- $priceStatus = $where['priceStatus'] ?? -1;
|
|
|
- $stockStatus = $where['stockStatus'] ?? -1;
|
|
|
- $requestType = $get['requestType'] ?? '';
|
|
|
+ $query->joinWith(['goods' => function ($query) use ($askInfo,$requestType) {
|
|
|
|
|
|
- $query->joinWith(['goods' => function ($query) use ($flowerNum, $priceStatus, $stockStatus, $requestType) {
|
|
|
if ($requestType == 'kd') {
|
|
|
+ //花束开单
|
|
|
+ $query->andWhere(['xhGoods.delStatus' => 0]);
|
|
|
$query->andWhere(['>', 'xhGoods.stock', 0]);
|
|
|
- }
|
|
|
- if ($stockStatus == 1) {
|
|
|
- $query->andWhere(['>', 'xhGoods.stock', 0]);
|
|
|
- }
|
|
|
- if ($stockStatus == 2) {
|
|
|
- $query->andWhere(['xhGoods.stock' => 0]);
|
|
|
- }
|
|
|
- if ($priceStatus == 1) {
|
|
|
- $query->andWhere(['xhGoods.priceType' => 1]);
|
|
|
- }
|
|
|
- if ($priceStatus == 2) {
|
|
|
+ } elseif ($requestType == 'goodsList') {
|
|
|
+ //花束管理列表
|
|
|
+ $query->andWhere(['xhGoods.delStatus' => 0]);
|
|
|
+
|
|
|
+ $priceStatus = $askInfo['priceStatus'] ?? -1;
|
|
|
+ if ($priceStatus > -1) {
|
|
|
+ //1 有价格,2 无价格
|
|
|
+ if ($priceStatus == 1) {
|
|
|
+ $query->andWhere(['xhGoods.priceType' => 1]);
|
|
|
+ }
|
|
|
+ if ($priceStatus == 2) {
|
|
|
+ $query->andWhere(['xhGoods.priceType' => 0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $stockStatus = $askInfo['stockStatus'] ?? -1;
|
|
|
+ if ($stockStatus > -1) {
|
|
|
+ //1 有库存,2 无库存
|
|
|
+ if ($stockStatus == 1) {
|
|
|
+ $query->andWhere(['>', 'xhGoods.stock', 0]);
|
|
|
+ }
|
|
|
+ if ($stockStatus == 2) {
|
|
|
+ $query->andWhere(['xhGoods.stock' => 0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $flowerNum = $askInfo['flowerNum'] ?? 0;
|
|
|
+ if ($flowerNum > 0) {
|
|
|
+ $query->andWhere(['xhGoods.flowerNum' => $flowerNum]);
|
|
|
+ }
|
|
|
+ } elseif ($requestType == 'mall') {
|
|
|
+ //花束商城
|
|
|
+ $query->andWhere(['xhGoods.delStatus' => 0]);
|
|
|
+ $query->andWhere(['xhGoods.status' => 1]);
|
|
|
+ $query->andWhere(['xhGoods.priceType' => 0]);
|
|
|
+ } elseif ($requestType == 'album') {
|
|
|
+ //图集
|
|
|
+ $query->andWhere(['xhGoods.delStatus' => 0]);
|
|
|
+ $query->andWhere(['xhGoods.status' => 1]);
|
|
|
$query->andWhere(['xhGoods.priceType' => 0]);
|
|
|
}
|
|
|
- if ($flowerNum > 0) {
|
|
|
- $query->andWhere(['xhGoods.flowerNum' => $flowerNum]);
|
|
|
- }
|
|
|
+
|
|
|
}]);
|
|
|
- $query->orderBy(['inTurn' => SORT_DESC]);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ $query->orderBy(['inTurn' => SORT_DESC]);
|
|
|
// 获取总数
|
|
|
$total = $query->count();
|
|
|
-
|
|
|
// 分页查询
|
|
|
$goodsCategoryInfoList = $query->offset(($page - 1) * $pageSize)
|
|
|
->limit($pageSize)
|