85 lines
1.9 KiB
PHP
85 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use App\Constants\Common\SiteCode;
|
|
use Hyperf\Database\Model\Builder;
|
|
use Hyperf\DbConnection\Model\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $city_id
|
|
* @property string $name
|
|
* @property string $address
|
|
* @property string $lng
|
|
* @property string $lat
|
|
* @property int $status
|
|
* @property int $is_del
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
*/
|
|
class Kitchen extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'kitchen';
|
|
|
|
/**
|
|
* 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', 'city_id' => 'integer', 'status' => 'integer'];
|
|
|
|
const string CREATED_AT = 'create_time';
|
|
|
|
const string UPDATED_AT = 'update_time';
|
|
|
|
/**
|
|
* @param string $name
|
|
* @return \Hyperf\Database\Model\Model|Builder|null
|
|
*/
|
|
public function getInfoByName(string $name): \Hyperf\Database\Model\Model|Builder|null
|
|
{
|
|
return $this->where('name', $name)->where('is_del',SiteCode::KITCHEN_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::KITCHEN_NO_DEL)->first();
|
|
}
|
|
|
|
/**
|
|
* 获取所有数据
|
|
* @param array $ids
|
|
* @return array
|
|
*/
|
|
public function getDataByIds(array $ids): array
|
|
{
|
|
$data = $this->whereIn('id',$ids)->get();
|
|
if (empty($data)){
|
|
return [];
|
|
}
|
|
|
|
$res = [];
|
|
foreach ($data->toArray() as $one)
|
|
{
|
|
$res[$one['id']] = $one;
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
}
|