|
|
|
@ -25,7 +25,6 @@ use think\model\relation\BelongsTo; |
|
|
|
|
use think\model\relation\HasMany; |
|
|
|
|
use think\model\relation\HasOne; |
|
|
|
|
use think\Paginator; |
|
|
|
|
use app\common\model\Channel; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 商品模型 |
|
|
|
@ -130,16 +129,18 @@ class Goods extends BaseModel |
|
|
|
|
*/ |
|
|
|
|
public function skuList(): HasMany |
|
|
|
|
{ |
|
|
|
|
return $this->hasMany('GoodsSku','spu_id')->order(['id' => 'asc']); |
|
|
|
|
return $this->hasMany('GoodsSku', 'spu_id')->order(['id' => 'asc']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 关联商品规格表 |
|
|
|
|
* @return HasMany |
|
|
|
|
*/ |
|
|
|
|
public function skuList1(): HasMany |
|
|
|
|
{ |
|
|
|
|
return $this->hasMany('GoodsSku','goods_id')->order(['id' => 'asc']); |
|
|
|
|
return $this->hasMany('GoodsSku', 'goods_id')->order(['id' => 'asc']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 关联商品规格关系表 |
|
|
|
|
* @return HasMany |
|
|
|
@ -175,6 +176,7 @@ class Goods extends BaseModel |
|
|
|
|
{ |
|
|
|
|
return $this->hasMany('Comment'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取商品列表 |
|
|
|
|
* @param array $param 查询条件 |
|
|
|
@ -206,7 +208,7 @@ class Goods extends BaseModel |
|
|
|
|
// 执行查询 |
|
|
|
|
$list = $query |
|
|
|
|
->alias($this->name) |
|
|
|
|
->field(['goods.goods_id','goods.goods_name','cmmdty_model','link','cost_price_min','stock_total','link_other','goods_price_min']) |
|
|
|
|
->field(['goods.goods_id', 'goods.goods_name', 'cmmdty_model', 'link', 'cost_price_min', 'stock_total', 'link_other', 'goods_price_min']) |
|
|
|
|
->where('is_delete', '=', 0) |
|
|
|
|
->order($sort) |
|
|
|
|
->paginate($listRows); |
|
|
|
@ -307,6 +309,12 @@ class Goods extends BaseModel |
|
|
|
|
|
|
|
|
|
$field = $this->getAliasFields($this->name, ['content']); |
|
|
|
|
$field[] = 'selling_point'; |
|
|
|
|
|
|
|
|
|
//关键字搜索 wanghousheng |
|
|
|
|
if (!empty($param['keyword'])) { |
|
|
|
|
$query = $query->where('goods_name', 'like', "%{$param['keyword']}%") |
|
|
|
|
->whereOr('goods_no', 'like', "%{$param['keyword']}%"); |
|
|
|
|
} |
|
|
|
|
// 执行查询 |
|
|
|
|
$list = $query->with(['images.file']) |
|
|
|
|
->alias($this->name) |
|
|
|
@ -366,7 +374,7 @@ class Goods extends BaseModel |
|
|
|
|
'keywords' => '', |
|
|
|
|
'role' => '', |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 实例化新查询对象 |
|
|
|
|
$query = $this->getNewQuery(); |
|
|
|
|
// 筛选条件 |
|
|
|
@ -388,7 +396,7 @@ class Goods extends BaseModel |
|
|
|
|
$filter[] = ['stock_total', '=', 0]; // 已售罄 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 商品状态 |
|
|
|
|
$params['status'] > 0 && $filter[] = ['status', '=', (int)$params['status']]; |
|
|
|
|
$a = 1; |
|
|
|
@ -398,7 +406,7 @@ class Goods extends BaseModel |
|
|
|
|
$GoodsCategoryRelName = (new GoodsCategoryRelModel())->getName(); |
|
|
|
|
$query->join($GoodsCategoryRelName, "{$GoodsCategoryRelName}.goods_id = {$this->name}.goods_id"); |
|
|
|
|
// 设置分类ID条件 |
|
|
|
|
$query->where('goods_category_rel.category_id', 'in', explode(",", (string)$params['categoryId'])); |
|
|
|
|
$query->where('goods_category_rel.category_id', 'in', explode(",", (string)$params['categoryId'])); |
|
|
|
|
// $query->where([ |
|
|
|
|
// 'goods_category_rel.category_id' => (int)$params['categoryId'], |
|
|
|
|
// //'goods.store_id' => (int)$params['store_id'], |
|
|
|
@ -407,7 +415,7 @@ class Goods extends BaseModel |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
// 商品名称 |
|
|
|
|
foreach (explode(",", $params['keywords']?? '') as $val) { |
|
|
|
|
foreach (explode(",", $params['keywords'] ?? '') as $val) { |
|
|
|
|
$filter[] = ['goods_name', 'like', "%{$val}%"]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -439,7 +447,7 @@ class Goods extends BaseModel |
|
|
|
|
$filter[] = ['is_in_store', '=', $params['is_in_store']]; |
|
|
|
|
} |
|
|
|
|
if (isset($param['role']) && $param['role'] == 1) { |
|
|
|
|
$filter[] = ['channel', 'in', ['jd','sn','zy']]; |
|
|
|
|
$filter[] = ['channel', 'in', ['jd', 'sn', 'zy']]; |
|
|
|
|
} |
|
|
|
|
if (isset($param['store_id']) && $param['store_id'] !== '') { |
|
|
|
|
$filter[] = ['goods.store_id', '=', $params['store_id']]; |
|
|
|
|