Files
oil/server-tp6/app/common/model/Checkout.php
T
2026-09-01 22:15:50 +08:00

97 lines
2.0 KiB
PHP

<?php
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use think\model\relation\BelongsTo;
/**
* 结账模型
* Class Checkout
* @package app\common\model
*/
class Checkout extends BaseModel
{
protected $name = 'checkout';
// 定义主键
protected $pk = 'checkout_id';
/**
* 获取结账人信息
* @return BelongsTo
*/
public function user(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\store\\User", 'store_user_id');
}
/**
* 结账详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['checkout_id' => (int)$where];
return static::get($where, $with);
}
/**
* 获取全部
* @return mixed
*/
public static function getAll()
{
$model = new static;
return $model->order(['checkout_id' => 'asc'])->select();
}
/**
* 开始时间
* @param $value
* @return false|string
*/
public function getStartTimeAttr($value)
{
return format_time($value);
}
/**
* 结束时间
* @param $value
* @return false|string
*/
public function getEndTimeAttr($value)
{
return format_time($value);
}
/**
* 获取指定
* @param array $filter
* @return mixed
*/
public static function getQuery($filter): array
{
$model = new static;
return $model->where($filter)->order(['checkout_id' => 'asc'])->select()->toArray();
}
/**
* 获取最新一条记录
* @param array $filter
* @return array|null
*/
public static function getSingle(array $filter = []): ?array
{
$model = new static;
$data = $model->where($filter)->order(['checkout_id' => 'desc'])->find();
return $data ? $data->toArray() : null;
}
}