151 lines
4.4 KiB
PHP
151 lines
4.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use App\Constants\Common\GoodCode;
|
|
use Hyperf\Collection\Collection;
|
|
use Hyperf\Database\Model\Builder;
|
|
use Hyperf\DbConnection\Model\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $spu_id
|
|
* @property string $title
|
|
* @property string $sub_title
|
|
* @property string $image_ids
|
|
* @property string $price
|
|
* @property string $param
|
|
* @property string $extra
|
|
* @property int $total_stock
|
|
* @property int $surplus_stock
|
|
* @property int $chef_id
|
|
* @property int $sales_num
|
|
* @property int $order_num
|
|
* @property int $cancel_num
|
|
* @property int $refund_num
|
|
* @property int $saleable
|
|
* @property int $sort
|
|
* @property int $is_del
|
|
* @property int $code_number
|
|
* @property int $occupied
|
|
* @property int $favorable
|
|
* @property int $origin_sku_id
|
|
* @property int $is_add_staple_food
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
*/
|
|
class Sku extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'sku';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = [];
|
|
|
|
protected array $guarded = [];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = [
|
|
'id' => 'integer',
|
|
'spu_id' => 'integer',
|
|
'chef_id' => 'integer',
|
|
'total_stock' => 'integer',
|
|
'surplus_stock' => 'integer',
|
|
'sales_num' => 'integer',
|
|
'order_num' => 'integer',
|
|
'cancel_num' => 'integer',
|
|
'refund_num' => 'integer',
|
|
'saleable' => 'integer',
|
|
'sort' => 'integer',
|
|
'is_add_staple_food' => 'integer',
|
|
'code_number' => 'integer',
|
|
'occupied' => 'integer',
|
|
'favorable' => 'integer',
|
|
'origin_sku_id' => 'integer',
|
|
];
|
|
|
|
const string CREATED_AT = 'create_time';
|
|
const string UPDATED_AT = 'update_time';
|
|
|
|
/**
|
|
* @param int $id
|
|
* @return Builder|\Hyperf\Database\Model\Model|null
|
|
*/
|
|
public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null
|
|
{
|
|
return $this->where('id',$id)->where('is_del',GoodCode::SKU_IS_NO_DEL)->first();
|
|
}
|
|
|
|
/**
|
|
* @param array $spuIds
|
|
* @return Collection
|
|
*/
|
|
public function getListBySpuIds(array $spuIds): Collection
|
|
{
|
|
return $this
|
|
->whereIn('spu_id',$spuIds)
|
|
->where('is_del',GoodCode::SKU_IS_NO_DEL)
|
|
->where('saleable',GoodCode::LISTING)
|
|
// ->where('is_add_staple_food',GoodCode::IS_NOT_ADD_STAPLE_FOOD)
|
|
->orderBy('sort')
|
|
->select(['id','spu_id','title','image_ids','price','param','extra','total_stock','surplus_stock','order_num','is_add_staple_food','occupied','chef_id'])
|
|
->get();
|
|
}
|
|
|
|
|
|
/**
|
|
* @param array $spuIds
|
|
* @return \Hyperf\Database\Model\Model|\Hyperf\Database\Query\Builder|null
|
|
*/
|
|
public function getAddStapleFoodListBySpuIds(array $spuIds): \Hyperf\Database\Query\Builder|\Hyperf\Database\Model\Model|null
|
|
{
|
|
return $this
|
|
->whereIn('spu_id',$spuIds)
|
|
->where('is_del',GoodCode::SKU_IS_NO_DEL)
|
|
->where('saleable',GoodCode::LISTING)
|
|
->where('is_add_staple_food',GoodCode::IS_ADD_STAPLE_FOOD)
|
|
->orderBy('sort')
|
|
->select(['id','spu_id','title','image_ids','price','param','extra','total_stock','surplus_stock','order_num','is_add_staple_food','occupied','chef_id'])
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* @param int $spuId
|
|
* @return Builder[]|\Hyperf\Database\Model\Collection
|
|
*/
|
|
public function getListBySpuId(int $spuId): \Hyperf\Database\Model\Collection|array
|
|
{
|
|
return $this
|
|
->where('spu_id',$spuId)
|
|
->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','is_add_staple_food','occupied','chef_id','sub_title'])
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
* @param array $ids
|
|
* @return array
|
|
*/
|
|
public function getDataArrByIds(array $ids): array
|
|
{
|
|
$res = $this
|
|
->whereIn('id',$ids)
|
|
->orderBy('sort')
|
|
->get();
|
|
|
|
if ($res->isEmpty()) return [];
|
|
|
|
return $res->toArray();
|
|
}
|
|
}
|