260 lines
9.6 KiB
PHP
260 lines
9.6 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Model;
|
||
|
||
|
||
|
||
use Carbon\Carbon;
|
||
use Hyperf\Database\Model\Collection;
|
||
use Hyperf\Database\Model\Relations\HasMany;
|
||
use Hyperf\Database\Model\Relations\HasOne;
|
||
use Hyperf\Snowflake\Concern\Snowflake;
|
||
|
||
/**
|
||
* @property int $order_product_id 主键id
|
||
* @property int $order_inquiry_id 订单-问诊id
|
||
* @property int $order_prescription_id 订单-处方id
|
||
* @property int $order_id 订单id
|
||
* @property int $doctor_id 医生id
|
||
* @property int $patient_id 患者id
|
||
* @property int $family_id 家庭成员id(就诊用户)
|
||
* @property string $order_product_no 订单编号
|
||
* @property string $escrow_trade_no 第三方支付流水号
|
||
* @property int $order_product_status 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||
* @property int $pay_channel 支付渠道(1:小程序支付 2:微信扫码支付)
|
||
* @property int $pay_status 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||
* @property int $is_delete 删除状态(0:否 1:是)
|
||
* @property int $cancel_reason 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时 4:客服取消)
|
||
* @property string $amount_total 订单金额
|
||
* @property string $coupon_amount_total 优惠卷总金额
|
||
* @property string $payment_amount_total 实际付款金额
|
||
* @property string $logistics_fee 运费金额
|
||
* @property string $logistics_no 物流编号
|
||
* @property string $logistics_company_code 快递公司编码
|
||
* @property int $sub_logistics_status 快递推送订阅状态(0:未订阅/无需订阅 1:已订阅 2:订阅失败)
|
||
* @property string $delivery_time 发货时间
|
||
* @property string $pay_time 支付时间
|
||
* @property string $remarks 订单备注
|
||
* @property int $refund_status 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||
* @property string $cancel_time 订单取消时间
|
||
* @property string $cancel_remarks 订单取消备注(自动添加)
|
||
* @property int $report_pre_status 上报处方平台状态(0:未上报 1:已上报 2:上报失败 3:上报取消)
|
||
* @property string $report_pre_time 上报处方平台时间
|
||
* @property string $report_pre_fail_reason 上报失败原因
|
||
* @property int $province_id 省份id
|
||
* @property string $province 省份
|
||
* @property int $city_id 城市id
|
||
* @property string $city 城市
|
||
* @property int $county_id 区县id
|
||
* @property string $county 区县
|
||
* @property string $address 详细地址
|
||
* @property string $address_mask 详细地址(掩码)
|
||
* @property string $consignee_name 收货人姓名
|
||
* @property string $consignee_name_mask 收货人姓名(掩码)
|
||
* @property string $consignee_tel 收货人电话
|
||
* @property string $consignee_tel_mask 收货人电话(掩码)
|
||
* @property Carbon $created_at 创建时间
|
||
* @property Carbon $updated_at 修改时间
|
||
* @property-read Collection|OrderProductItem[]|null $OrderProductItem
|
||
* @property-read OrderPrescription|null $OrderPrescription
|
||
* @property-read PatientFamily|null $PatientFamily
|
||
* @property-read Collection|OrderPrescriptionIcd[]|null $OrderPrescriptionIcd
|
||
*/
|
||
class OrderProduct extends Model
|
||
{
|
||
use Snowflake;
|
||
|
||
/**
|
||
* The table associated with the model.
|
||
*/
|
||
protected ?string $table = 'order_product';
|
||
|
||
/**
|
||
* The attributes that are mass assignable.
|
||
*/
|
||
protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'order_id', 'doctor_id', 'patient_id', 'family_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'is_delete', 'cancel_reason', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'logistics_company_code', 'sub_logistics_status', 'delivery_time', 'pay_time', 'remarks', 'refund_status', 'cancel_time', 'cancel_remarks', 'report_pre_status', 'report_pre_time', 'report_pre_fail_reason', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at'];
|
||
|
||
protected string $primaryKey = "order_product_id";
|
||
|
||
/**
|
||
* 关联订单商品item表
|
||
*/
|
||
public function OrderProductItem(): HasMany
|
||
{
|
||
return $this->HasMany(OrderProductItem::class, 'order_product_id','order_product_id');
|
||
}
|
||
|
||
/**
|
||
* 关联订单-处方表
|
||
*/
|
||
public function OrderPrescription(): HasOne
|
||
{
|
||
return $this->hasOne(OrderPrescription::class, 'order_prescription_id','order_prescription_id');
|
||
}
|
||
|
||
/**
|
||
* 关联患者家庭成员信息表-基本信息
|
||
*/
|
||
public function PatientFamily(): HasOne
|
||
{
|
||
return $this->hasOne(PatientFamily::class, 'family_id','family_id');
|
||
}
|
||
|
||
/**
|
||
* 关联处方关联疾病表
|
||
*/
|
||
public function OrderPrescriptionIcd(): HasMany
|
||
{
|
||
return $this->HasMany(OrderPrescriptionIcd::class, 'order_prescription_id','order_prescription_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 $params
|
||
* @return bool
|
||
*/
|
||
public static function getExists(array $params): bool
|
||
{
|
||
return self::where($params)->exists();
|
||
}
|
||
|
||
/**
|
||
* 获取数量
|
||
* @param array $params
|
||
* @return int
|
||
*/
|
||
public static function getCount(array $params): int
|
||
{
|
||
return self::where($params)->count();
|
||
}
|
||
|
||
/**
|
||
* 获取药品订单分页
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @param int|null $page
|
||
* @param int|null $per_page
|
||
* @return array
|
||
*/
|
||
public static function getPatientOrderProductPage(array $params,array $fields = ["*"], int $page = null, ?int $per_page = 10): array
|
||
{
|
||
$result = self::with([
|
||
"OrderProductItem:product_item_id,order_product_id,product_id,product_name,amount,manufacturer,product_cover_img,product_spec",
|
||
])
|
||
->where($params)
|
||
->orderBy("created_at",'desc')
|
||
->paginate($per_page, $fields, "page", $page);
|
||
|
||
$data = array();
|
||
$data['current_page'] = $result->currentPage();// 当前页码
|
||
$data['total'] = $result->total();// 数据总数
|
||
$data['data'] = $result->items();// 数据
|
||
$data['per_page'] = $result->perPage();// 每页个数
|
||
$data['last_page'] = $result->lastPage();// 最后一页
|
||
|
||
return $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 $data
|
||
* @return \Hyperf\Database\Model\Model|OrderProduct
|
||
*/
|
||
public static function addOrderProduct(array $data): \Hyperf\Database\Model\Model|OrderProduct
|
||
{
|
||
return self::create($data);
|
||
}
|
||
|
||
/**
|
||
* 患者用药记录查询
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @param int|null $page
|
||
* @param int|null $per_page
|
||
* @return array
|
||
*/
|
||
public static function getProductRecordPage(array $params,array $fields = ["*"], int $page = null, ?int $per_page = 10): array
|
||
{
|
||
$result = self::with([
|
||
"OrderProductItem:product_item_id,order_product_id,product_id,product_name,amount,manufacturer,product_cover_img,product_spec",
|
||
"OrderPrescriptionIcd:prescription_icd_id,order_prescription_id,icd_id,icd_name",
|
||
"PatientFamily:family_id,card_name_mask,sex,age",
|
||
])
|
||
->where($params)
|
||
->paginate($per_page, $fields, "page", $page);
|
||
|
||
$data = array();
|
||
$data['current_page'] = $result->currentPage();// 当前页码
|
||
$data['total'] = $result->total();// 数据总数
|
||
$data['data'] = $result->items();// 数据
|
||
$data['per_page'] = $result->perPage();// 每页个数
|
||
$data['last_page'] = $result->lastPage();// 最后一页
|
||
|
||
return $data;
|
||
}
|
||
|
||
/**
|
||
* 获取某一状态下的订单
|
||
* @param array $params
|
||
* @param array $order_product_status
|
||
* @param array $fields
|
||
* @return Collection|array
|
||
*/
|
||
public static function getStatusList(array $params = [],array $order_product_status = [], array $fields = ['*']): Collection|array
|
||
{
|
||
return self::where($params)->whereIn('order_product_status',$order_product_status)->get($fields);
|
||
}
|
||
|
||
/**
|
||
* 获取患者某一时间段药品订单-创建时间
|
||
* @param array $params
|
||
* @param array $created_at 接诊时间区间
|
||
* @param array $order_product_status
|
||
* @return Collection|array
|
||
*/
|
||
public static function getProductWithCreateTime(array $params, array $created_at,array $order_product_status): Collection|array
|
||
{
|
||
return self::where($params)
|
||
->whereIn('order_product_status', $order_product_status)
|
||
->whereBetween('created_at', $created_at)
|
||
->orderBy('created_at')
|
||
->get();
|
||
}
|
||
|
||
}
|