121 lines
3.4 KiB
PHP
121 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use App\Constants\Common\CategoryCode;
|
|
use App\Constants\Common\GoodCode;
|
|
use Hyperf\Database\Model\Builder;
|
|
use Hyperf\Database\Model\Collection;
|
|
use Hyperf\DbConnection\Model\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $cycle_id
|
|
* @property int $city_id
|
|
* @property int $kitchen_id
|
|
* @property int $chef_id
|
|
* @property int $caterer_id
|
|
* @property string $title
|
|
* @property string $sub_title
|
|
* @property int $category_id
|
|
* @property int $saleable
|
|
* @property int $type
|
|
* @property int $favorable
|
|
* @property int $sort
|
|
* @property int $is_del
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
*/
|
|
class Spu extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'spu';
|
|
|
|
/**
|
|
* 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', 'cycle_id' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer','chef_id' => 'integer','caterer_id' => 'integer','category_id' => 'integer', 'saleable' => 'integer','type' => 'integer','sort' => 'integer','favorable' => 'integer'];
|
|
|
|
const string CREATED_AT = 'create_time';
|
|
const string UPDATED_AT = 'update_time';
|
|
|
|
/**
|
|
* @param int $cityId
|
|
* @param int $cycleId
|
|
* @param string $title
|
|
* @return Builder|\Hyperf\Database\Model\Model|null
|
|
*/
|
|
public function getInfoByCityIdAndCycleId(int $cityId, int $cycleId,string $title): \Hyperf\Database\Model\Model|Builder|null
|
|
{
|
|
return $this->where('city_id', $cityId)->where('cycle_id', $cycleId)->where('title',$title)->where('is_del',GoodCode::SPU_IS_NO_DEL)->first();
|
|
}
|
|
|
|
/**
|
|
* @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::SPU_IS_NO_DEL)->first();
|
|
}
|
|
|
|
/**
|
|
* @param int $cycleId
|
|
* @param int $kitchenId
|
|
* @param int $type
|
|
* @return Builder[]|Collection|null
|
|
*/
|
|
public function getListByCycleIdAndType(int $cycleId, int $kitchenId, int $type): Collection|array|null
|
|
{
|
|
return $this
|
|
->where('cycle_id',$cycleId)
|
|
->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','favorable'])
|
|
->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();
|
|
}
|
|
|
|
/**
|
|
* @param int $cycle_id
|
|
* @return array
|
|
*/
|
|
public function getCycleIdAddStapleFoodSkuIds(int $cycle_id): array
|
|
{
|
|
return $this
|
|
->leftJoin('sku','sku.spu_id','=','spu.id')
|
|
->where('spu.cycle_id',$cycle_id)
|
|
->where('spu.category_id',CategoryCode::EXTRA_STAPLE)->pluck('sku.id')
|
|
->toArray();
|
|
}
|
|
}
|