240 lines
9.3 KiB
PHP
240 lines
9.3 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Model;
|
||
|
||
|
||
|
||
use Carbon\Carbon;
|
||
use Hyperf\Database\Model\Collection;
|
||
use Hyperf\Database\Model\Relations\HasOne;
|
||
use Hyperf\DbConnection\Db;
|
||
use Hyperf\Snowflake\Concern\Snowflake;
|
||
|
||
/**
|
||
* @property int $order_service_id 主键id
|
||
* @property int $order_id 订单id
|
||
* @property int $user_id 用户id-患者
|
||
* @property int $patient_id 患者id
|
||
* @property int $doctor_id 医生id
|
||
* @property int $family_id 家庭成员id(就诊用户)
|
||
* @property int $order_service_type 服务包类型(1:健康包 2:随访包)
|
||
* @property int $order_service_status 订单状态(1:待支付 2:未开始 3:服务中 4:服务完成 5:服务取消)
|
||
* @property int $is_delete 删除状态(0:否 1:是)
|
||
* @property int $refund_status 订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款)
|
||
* @property int $pay_channel 支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付)
|
||
* @property int $pay_status 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||
* @property string $order_service_no 系统订单编号
|
||
* @property string $escrow_trade_no 第三方支付流水号
|
||
* @property string $amount_total 订单金额
|
||
* @property string $coupon_amount_total 优惠卷总金额
|
||
* @property string $payment_amount_total 实际付款金额
|
||
* @property string $pay_time 支付时间
|
||
* @property string $start_time 开始服务时间
|
||
* @property string $finish_time 结束服务时间
|
||
* @property string $cancel_time 订单取消时间
|
||
* @property int $cancel_reason 取消订单原因(1:医生未接受服务 2:主动取消 4:客服取消 5:支付超时)
|
||
* @property string $cancel_remarks 取消订单备注
|
||
* @property int $add_finish_status 添加完成订单延迟队列状态(0:未添加 1:已添加 2:添加失败)
|
||
* @property string $add_finish_time 添加完成订单延迟队列时间
|
||
* @property string $add_finish_fail_reason 添加完成订单延迟队列失败原因
|
||
* @property string $patient_name 患者姓名-就诊人
|
||
* @property string $patient_name_mask 患者姓名-就诊人(掩码)
|
||
* @property int $patient_sex 患者性别-就诊人(0:未知 1:男 2:女)
|
||
* @property int $patient_age 患者年龄-就诊人
|
||
* @property \Carbon\Carbon $created_at 创建时间
|
||
* @property \Carbon\Carbon $updated_at 修改时间
|
||
* @property-read OrderServicePackageCase|null $OrderServicePackageCase
|
||
*/
|
||
class OrderServicePackage extends Model
|
||
{
|
||
use Snowflake;
|
||
|
||
/**
|
||
* The table associated with the model.
|
||
*/
|
||
protected ?string $table = 'order_service_package';
|
||
|
||
/**
|
||
* The attributes that are mass assignable.
|
||
*/
|
||
protected array $fillable = ['order_service_id', 'order_id', 'user_id', 'patient_id', 'doctor_id', 'family_id', 'order_service_type', 'order_service_status', 'is_delete', 'refund_status', 'pay_channel', 'pay_status', 'order_service_no', 'escrow_trade_no', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'pay_time', 'start_time', 'finish_time', 'cancel_time', 'cancel_reason', 'cancel_remarks', 'add_finish_status', 'add_finish_time', 'add_finish_fail_reason', 'patient_name', 'patient_name_mask', 'patient_sex', 'patient_age', 'created_at', 'updated_at'];
|
||
|
||
protected string $primaryKey = "order_service_id";
|
||
|
||
/**
|
||
* 关联服务包病例表
|
||
*/
|
||
public function OrderServicePackageCase(): HasOne
|
||
{
|
||
return $this->hasOne(OrderServicePackageCase::class, 'order_service_id', 'order_service_id');
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取信息-单条
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return object|null
|
||
*/
|
||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)->first($fields);
|
||
}
|
||
|
||
/**
|
||
* 多条
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return Collection|array
|
||
*/
|
||
public static function getList(array $params, array $fields = ['*']): Collection|array
|
||
{
|
||
return self::where($params)->get($fields);
|
||
}
|
||
|
||
/**
|
||
* 新增
|
||
* @param array $data
|
||
* @return OrderServicePackage|\Hyperf\Database\Model\Model
|
||
*/
|
||
public static function addOrderServicePackage(array $data): \Hyperf\Database\Model\Model|OrderServicePackage
|
||
{
|
||
return self::create($data);
|
||
}
|
||
|
||
/**
|
||
* 修改
|
||
* @param array $params
|
||
* @param array $data
|
||
* @return int
|
||
*/
|
||
public static function edit(array $params = [], array $data = []): int
|
||
{
|
||
return self::where($params)->update($data);
|
||
}
|
||
|
||
/**
|
||
* 获取某一状态下的订单-多条
|
||
* @param array $params
|
||
* @param array $order_service_status
|
||
* @param array $fields
|
||
* @return Collection|array
|
||
*/
|
||
public static function getStatusList(array $params = [],array $order_service_status = [], array $fields = ['*']): Collection|array
|
||
{
|
||
return self::where($params)->whereIn('order_service_status',$order_service_status)->get($fields);
|
||
}
|
||
|
||
/**
|
||
* 获取某一状态下的订单-单条
|
||
* @param array $params
|
||
* @param array $order_service_status
|
||
* @param array $fields
|
||
* @return object|null
|
||
*/
|
||
public static function getStatusOne(array $params = [],array $order_service_status = [], array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)->whereIn('order_service_status',$order_service_status)->first($fields);
|
||
}
|
||
|
||
/**
|
||
* 获取服务包订单-分页
|
||
* @param array $params
|
||
* @param array $order_service_status_params
|
||
* @param array $fields
|
||
* @param int|null $page
|
||
* @param int|null $per_page
|
||
* @return int|mixed|string
|
||
*/
|
||
public static function getPatientOrderServicePage(array $params, array $order_service_status_params, array $fields = ["*"], int $page = null, ?int $per_page = 10): mixed
|
||
{
|
||
$raw = self::with([
|
||
'OrderServicePackageCase:order_service_case_id,order_service_id,disease_desc',
|
||
])
|
||
->where($params)
|
||
->when($order_service_status_params, function ($query, $order_service_status_params) {
|
||
$query->whereIn('order_service_status', $order_service_status_params);
|
||
})
|
||
->orderBy('created_at', 'desc')
|
||
->paginate($per_page, $fields, "page", $page);
|
||
|
||
$data = array();
|
||
$data['current_page'] = $raw->currentPage();// 当前页码
|
||
$data['total'] = $raw->total();//数据总数
|
||
$data['data'] = $raw->items();//数据
|
||
$data['per_page'] = $raw->perPage();//每页个数
|
||
$data['last_page'] = $raw->lastPage();//最后一页
|
||
|
||
return $data;
|
||
}
|
||
|
||
/**
|
||
* 获取某一时间段服务包订单-结束时间
|
||
* @param array $params
|
||
* @param array $order_service_status_params
|
||
* @param array $finish_time_params 结束时间区间
|
||
* @return Collection|array
|
||
*/
|
||
public static function getInquiryWithFinishTime(array $params, array $order_service_status_params, array $finish_time_params): Collection|array
|
||
{
|
||
return self::where($params)
|
||
->whereIn('order_service_status',$order_service_status_params)
|
||
->whereBetween('finish_time', $finish_time_params)
|
||
->orderBy('finish_time')
|
||
->get();
|
||
}
|
||
|
||
/**
|
||
* 获取医生当日的服务包订单
|
||
* @param array $params
|
||
* @param array $order_service_status_params
|
||
* @param array $start_time_params 开始时间区间
|
||
* @return Collection|array
|
||
*/
|
||
public static function getDoctorDayOrderServiceWithStartTime(array $params, array $order_service_status_params,array $start_time_params): Collection|array
|
||
{
|
||
return self::where($params)
|
||
->whereIn('order_service_status',$order_service_status_params)
|
||
->whereIn('refund_status',[0,4,5])
|
||
->whereBetween('start_time', $start_time_params)
|
||
->orderBy('start_time')
|
||
->get();
|
||
}
|
||
|
||
/**
|
||
* 获取医生当日未结束的服务包订单
|
||
* @param array $params
|
||
* @param array $order_service_status_params
|
||
* @param string $finish_time_params 当前时间
|
||
* @return Collection|array
|
||
*/
|
||
public static function getDoctorDayNoFinishOrderService(array $params, array $order_service_status_params,string $finish_time_params): Collection|array
|
||
{
|
||
return self::where($params)
|
||
->whereIn('order_service_status',$order_service_status_params)
|
||
->whereIn('refund_status',[0,4,5])
|
||
->where('finish_time','>', $finish_time_params)
|
||
->orderBy('start_time')
|
||
->get();
|
||
}
|
||
|
||
/**
|
||
* 获取医生每月账单数据
|
||
* @param array $params
|
||
* @param string $year
|
||
* @param array $fields
|
||
* @return \Hyperf\Collection\Collection
|
||
*/
|
||
public static function getMonthlyGroupBill(array $params, string $year,array $fields = ["*"]): \Hyperf\Collection\Collection
|
||
{
|
||
return self::select([Db::raw('YEAR(start_time) AS `year`') ,Db::raw('MONTH(start_time) AS `month`')])
|
||
->where($params)
|
||
->whereIn('order_service_status', [3,4,5])
|
||
->where(Db::raw('YEAR(start_time)'), $year)
|
||
->groupBy([Db::raw('YEAR(start_time)'),Db::raw('MONTH(start_time)')])
|
||
->get($fields);
|
||
}
|
||
}
|