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

@@ -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();
}
}