Files
hyperf_service/app/Model/Site.php
2024-11-13 17:08:31 +08:00

100 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
use App\Constants\Common\SiteCode;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Collection;
use Hyperf\DbConnection\Model\Model;
/**
* @property int $id
* @property int $pid
* @property string $name
* @property int $city_id
* @property int $kitchen_id
* @property string $address
* @property string $lng
* @property string $lat
* @property string $remark
* @property string $expected_delivery_time
* @property string $distance
* @property string $expected_spend_time
* @property int $status
* @property int $image_id
* @property int $delivered_id
* @property int $sequence
* @property string $create_time
* @property string $update_time
* @property int $is_del
*/
class Site extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'site';
/**
* 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', 'pid' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'status' => 'integer', 'image_id' => 'integer', 'delivered_id' => 'integer', 'is_del' => 'integer'];
const string CREATED_AT = 'create_time';
const string UPDATED_AT = 'update_time';
/**
* 禁用厨房下所有点
* @param int $kitchenId
* @return int
*/
public function disableStatusByKitchenId(int $kitchenId)
{
return $this
->where('kitchen_id',$kitchenId)
->where('is_del',SiteCode::SITE_NO_DEL)
->update(['status' => SiteCode::SITE_DISABLE]);
}
/**
* @param string $name
* @return Builder|\Hyperf\Database\Model\Model|null
*/
public function getInfoByName(string $name): \Hyperf\Database\Model\Model|Builder|null
{
return $this->where('name',$name)->where('is_del',SiteCode::SITE_NO_DEL)->first();
}
/**
* @param int $id
* @return \Hyperf\Database\Model\Model|Builder|null
*/
public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null
{
return $this->where('id',$id)->where('is_del',SiteCode::SITE_NO_DEL)->first();
}
/**
* @param int $driverId
* @return Collection|array
*/
public function getSiteSequenceListByDriver(int $driverId): Collection|array
{
return $this
->where('is_del',SiteCode::SITE_NO_DEL)
->where('status',SiteCode::SITE_ENABLE)
->where('delivered_id',$driverId)
->get(['id','name', 'sequence']);
}
}