diff --git a/app/Constants/Common/GoodCode.php b/app/Constants/Common/GoodCode.php index 9d83000..3b96833 100644 --- a/app/Constants/Common/GoodCode.php +++ b/app/Constants/Common/GoodCode.php @@ -21,4 +21,10 @@ class GoodCode */ CONST INT SPU_TYPE_OPTIONAL = 1; CONST INT SPU_TYPE_MEAL = 2; + + /** + * @var int 1=上架 2=下架 + */ + CONST INT LISTING = 1; + CONST INT DELIST = 2; } \ No newline at end of file diff --git a/app/Model/Sku.php b/app/Model/Sku.php index 44b1cd5..89a0bad 100644 --- a/app/Model/Sku.php +++ b/app/Model/Sku.php @@ -24,6 +24,7 @@ use Hyperf\DbConnection\Model\Model; * @property int $ahead_refund_num * @property int $behind_refund_num * @property int $saleable + * @property int $sort * @property int $is_del * @property string $create_time * @property string $update_time @@ -45,7 +46,7 @@ class Sku extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => 'integer', 'spu_id' => 'integer', 'total_stock' => 'integer', 'surplus_stock' => 'integer', 'sales_num' => 'integer', 'order_num' => 'integer', 'cancel_num' => 'integer', 'ahead_refund_num' => 'integer', 'behind_refund_num' => 'integer', 'saleable' => 'integer']; + protected array $casts = ['id' => 'integer', 'spu_id' => 'integer', 'total_stock' => 'integer', 'surplus_stock' => 'integer', 'sales_num' => 'integer', 'order_num' => 'integer', 'cancel_num' => 'integer', 'ahead_refund_num' => 'integer', 'behind_refund_num' => 'integer', 'saleable' => 'integer','sort' => 'integer']; const string CREATED_AT = 'create_time'; const string UPDATED_AT = 'update_time'; @@ -58,4 +59,15 @@ class Sku extends Model { return $this->where('id',$id)->where('is_del',GoodCode::SKU_IS_NO_DEL)->first(); } + + public function getListBySpuIds(array $spuIds): array + { + return $this->skuModel + ->whereIn('spu_id',$spuIds) + ->where('is_del',GoodCode::SKU_IS_NO_DEL) + ->where('saleable',GoodCode::LISTING) + ->orderBy('sort') + ->select(['id','spu_id','title','image_ids','price','param','extra','total_stock','surplus_stock','order_num']) + ->get(); + } } diff --git a/app/Model/Spu.php b/app/Model/Spu.php index 8e42199..92f9602 100644 --- a/app/Model/Spu.php +++ b/app/Model/Spu.php @@ -80,7 +80,9 @@ class Spu extends Model ->where('kitchen_id',$kitchenId) ->where('is_del',GoodCode::SPU_IS_NO_DEL) ->where('type',$type) + ->where('saleable',GoodCode::LISTING) ->orderBy('sort') + ->select(['id','cycle_id','chef_id','title','title','sub_title','category_id']) ->get(); } } diff --git a/app/Service/Admin/Good/SkuService.php b/app/Service/Admin/Good/SkuService.php index b1792a0..0e42f33 100644 --- a/app/Service/Admin/Good/SkuService.php +++ b/app/Service/Admin/Good/SkuService.php @@ -83,6 +83,7 @@ class SkuService extends BaseService $insertModel->ahead_refund_num = 0; $insertModel->behind_refund_num = 0; $insertModel->saleable = $this->request->input('saleable'); + $insertModel->sort = $this->request->input('sort'); if (!$insertModel->save()) throw new ErrException('添加失败'); @@ -136,6 +137,7 @@ class SkuService extends BaseService $skuInfo->total_stock = $this->request->input('stock'); $skuInfo->saleable = $this->request->input('saleable'); $skuInfo->title = $this->request->input('title'); + $skuInfo->sort = $this->request->input('sort'); if (!$skuInfo->save()) throw new ErrException('修改失败');