feat: sku

This commit is contained in:
2025-01-22 11:15:02 +08:00
parent 9b7390129d
commit acca7ba7c7
4 changed files with 23 additions and 1 deletions

View File

@@ -21,4 +21,10 @@ class GoodCode
*/ */
CONST INT SPU_TYPE_OPTIONAL = 1; CONST INT SPU_TYPE_OPTIONAL = 1;
CONST INT SPU_TYPE_MEAL = 2; CONST INT SPU_TYPE_MEAL = 2;
/**
* @var int 1=上架 2=下架
*/
CONST INT LISTING = 1;
CONST INT DELIST = 2;
} }

View File

@@ -24,6 +24,7 @@ use Hyperf\DbConnection\Model\Model;
* @property int $ahead_refund_num * @property int $ahead_refund_num
* @property int $behind_refund_num * @property int $behind_refund_num
* @property int $saleable * @property int $saleable
* @property int $sort
* @property int $is_del * @property int $is_del
* @property string $create_time * @property string $create_time
* @property string $update_time * @property string $update_time
@@ -45,7 +46,7 @@ class Sku extends Model
/** /**
* The attributes that should be cast to native types. * 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 CREATED_AT = 'create_time';
const string UPDATED_AT = 'update_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(); 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();
}
} }

View File

@@ -80,7 +80,9 @@ class Spu extends Model
->where('kitchen_id',$kitchenId) ->where('kitchen_id',$kitchenId)
->where('is_del',GoodCode::SPU_IS_NO_DEL) ->where('is_del',GoodCode::SPU_IS_NO_DEL)
->where('type',$type) ->where('type',$type)
->where('saleable',GoodCode::LISTING)
->orderBy('sort') ->orderBy('sort')
->select(['id','cycle_id','chef_id','title','title','sub_title','category_id'])
->get(); ->get();
} }
} }

View File

@@ -83,6 +83,7 @@ class SkuService extends BaseService
$insertModel->ahead_refund_num = 0; $insertModel->ahead_refund_num = 0;
$insertModel->behind_refund_num = 0; $insertModel->behind_refund_num = 0;
$insertModel->saleable = $this->request->input('saleable'); $insertModel->saleable = $this->request->input('saleable');
$insertModel->sort = $this->request->input('sort');
if (!$insertModel->save()) throw new ErrException('添加失败'); if (!$insertModel->save()) throw new ErrException('添加失败');
@@ -136,6 +137,7 @@ class SkuService extends BaseService
$skuInfo->total_stock = $this->request->input('stock'); $skuInfo->total_stock = $this->request->input('stock');
$skuInfo->saleable = $this->request->input('saleable'); $skuInfo->saleable = $this->request->input('saleable');
$skuInfo->title = $this->request->input('title'); $skuInfo->title = $this->request->input('title');
$skuInfo->sort = $this->request->input('sort');
if (!$skuInfo->save()) throw new ErrException('修改失败'); if (!$skuInfo->save()) throw new ErrException('修改失败');