|
@@ -109,9 +109,14 @@ class ProductService extends Service
|
|
|
*/
|
|
|
public function productCategoryList($data,$user){
|
|
|
$model = ProductCategory::TopClear($user,$data);
|
|
|
- $model = $model->where('del_time',0)
|
|
|
- ->select('title','id','parent_id','is_edit_unit_price')
|
|
|
- ->orderby('id','asc');
|
|
|
+ $model = $model->leftJoin('product_category_orderby as a', function ($join) {
|
|
|
+ $join->on('product_category.id', '=', 'a.category_id')
|
|
|
+ ->where('a.del_time',0);
|
|
|
+ })
|
|
|
+ ->where('product_category.del_time',0)
|
|
|
+ ->select('product_category.title','product_category.id','product_category.parent_id','product_category.is_edit_unit_price')
|
|
|
+ ->orderByRaw('IF(a.sort IS NULL, product_category.id, a.sort) ASC'); // 排序逻辑:优先按 a.sort 排序,没有关联时按主表 id 排序
|
|
|
+
|
|
|
if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
if(isset($data['is_edit_unit_price'])) $model->where('is_edit_unit_price', $data['is_edit_unit_price']);
|
|
|
|
|
@@ -134,10 +139,14 @@ class ProductService extends Service
|
|
|
$now_top_depart_id = $this->getDepart($user);
|
|
|
|
|
|
//总社分类
|
|
|
- $head = ProductCategory::where('del_time',0)
|
|
|
- ->where('top_depart_id', $head_top_depart_id)
|
|
|
- ->select('title','id','parent_id')
|
|
|
- ->orderby('id','asc')
|
|
|
+ $head = ProductCategory::leftJoin('product_category_orderby as a', function ($join) {
|
|
|
+ $join->on('product_category.id', '=', 'a.category_id')
|
|
|
+ ->where('a.del_time',0);
|
|
|
+ })
|
|
|
+ ->where('product_category.del_time',0)
|
|
|
+ ->where('product_category.top_depart_id', $head_top_depart_id)
|
|
|
+ ->select('product_category.title','product_category.id','product_category.parent_id')
|
|
|
+ ->orderByRaw('IF(a.sort IS NULL, product_category.id, a.sort) ASC') // 排序逻辑:优先按 a.sort 排序,没有关联时按主表 id 排序
|
|
|
->get()->toArray();
|
|
|
$head_tree = [];
|
|
|
if(! empty($head)) {
|