From 7ff94df4c5b3844252e45443b93d03f256250d87 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Tue, 16 Apr 2024 17:35:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BF=AB=E7=BB=93=E6=9D=9F=E6=9C=8D=E5=8A=A1=E5=8C=85=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E8=87=B3=E6=9C=8D=E5=8A=A1=E5=8C=85=E7=BB=93=E6=9D=9F?= =?UTF-8?q?=E9=98=9F=E5=88=97=E5=91=BD=E4=BB=A4=E8=A1=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AddServicePackageFinishQueueCommand.php | 109 ++++++++++++++++++ app/Command/GrantUserCouponCommand.php | 3 + app/Command/MoveOrderCommand.php | 2 +- .../editDoctorInquiryConfigCommand.php | 3 + app/Command/editDoctorQrCodeCommand.php | 3 + app/Model/OrderServicePackage.php | 26 ++++- 6 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 app/Command/AddServicePackageFinishQueueCommand.php diff --git a/app/Command/AddServicePackageFinishQueueCommand.php b/app/Command/AddServicePackageFinishQueueCommand.php new file mode 100644 index 0000000..976f11e --- /dev/null +++ b/app/Command/AddServicePackageFinishQueueCommand.php @@ -0,0 +1,109 @@ +setDescription('添加快结束服务包订单至服务包结束队列'); + } + + public function handle(): void + { + $this->line('开始'); + + try { + // 获取需执行的订单 + $order_service_packages = $this->getExecOrder(); + if (empty($order_service_packages)){ + $this->line("结束,无订单可执行"); + return; + } + }catch (\Throwable $e){ + $this->line($e->getMessage()); + return; + } + + foreach ($order_service_packages as $order_service_package){ + Db::beginTransaction(); + try { + // 修改订单成功执行 + $this->putAddFinishStatus($order_service_package['order_service_id'],1); + + // 添加服务包订单完成延迟队列 + + Db::commit(); + }catch (\Throwable $e){ + // 修改订单执行失败 + Db::rollBack(); + $this->line($e->getMessage()); + $this->putAddFinishStatus($order_service_package['order_service_id'],2,$e->getMessage()); + } + } + + $this->line("全部结束"); + } + + /** + * 获取需执行的订单 + * @return array + */ + public function getExecOrder(): array + { + // 获取三天后结束时间 + $three_day_finish_time = date('Y-m-d H:i:s',strtotime('+3 days', time())); + $finish_time_params = [date('Y-m-d H:i:s',time()),$three_day_finish_time]; + + $params = array(); + $params['order_service_status'] = 3; // 订单状态(1:待支付 2:未开始 3:服务中 4:服务完成 5:服务取消) + $params['pay_status'] = 2; // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款) + $params['refund_status'] = 0; // 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常) + $params['add_finish_status'] = 0; // 添加完成订单延迟队列状态(0:未添加 1:已添加 2:添加失败) + + + $order_service_packages = OrderServicePackage::getInquiryWithFinishTime($params,$finish_time_params); + if (empty($order_service_packages)){ + return []; + } + + return $order_service_packages->toArray(); + } + + /** + * 修改订单状态 + * @param string $order_service_id + * @param int $add_finish_status + * @param string $add_finish_fail_reason + * @return void + */ + public function putAddFinishStatus(string $order_service_id,int $add_finish_status,string $add_finish_fail_reason = ""): void + { + $params = array(); + $params['order_service_id'] = $order_service_id; + + $data = array(); + $data['add_finish_status'] = $add_finish_status; + $data['add_finish_time'] = date('Y-m-d H:i:s',time()); + if (!empty($add_finish_fail_reason)){ + $data['add_finish_fail_reason'] = $add_finish_fail_reason; + } + + OrderServicePackage::edit($params,$data); + } +} diff --git a/app/Command/GrantUserCouponCommand.php b/app/Command/GrantUserCouponCommand.php index 84ff3e9..040e0ec 100644 --- a/app/Command/GrantUserCouponCommand.php +++ b/app/Command/GrantUserCouponCommand.php @@ -13,6 +13,9 @@ use Hyperf\Command\Annotation\Command; use Hyperf\DbConnection\Db; use Psr\Container\ContainerInterface; +/** + * 发放优惠卷 + */ #[Command] class GrantUserCouponCommand extends HyperfCommand { diff --git a/app/Command/MoveOrderCommand.php b/app/Command/MoveOrderCommand.php index 6bddb37..1c25ec8 100644 --- a/app/Command/MoveOrderCommand.php +++ b/app/Command/MoveOrderCommand.php @@ -21,7 +21,7 @@ use Hyperf\DbConnection\Db; use Psr\Container\ContainerInterface; /** - * 迁移订单 + * 迁移订单 v1.3使用 */ #[Command] class MoveOrderCommand extends HyperfCommand diff --git a/app/Command/editDoctorInquiryConfigCommand.php b/app/Command/editDoctorInquiryConfigCommand.php index f116e23..365a053 100644 --- a/app/Command/editDoctorInquiryConfigCommand.php +++ b/app/Command/editDoctorInquiryConfigCommand.php @@ -12,6 +12,9 @@ use Hyperf\Command\Annotation\Command; use Hyperf\DbConnection\Db; use Psr\Container\ContainerInterface; +/** + * 废弃 + */ #[Command] class editDoctorInquiryConfigCommand extends HyperfCommand { diff --git a/app/Command/editDoctorQrCodeCommand.php b/app/Command/editDoctorQrCodeCommand.php index 14740d2..e1feb2c 100644 --- a/app/Command/editDoctorQrCodeCommand.php +++ b/app/Command/editDoctorQrCodeCommand.php @@ -11,6 +11,9 @@ use Hyperf\Command\Command as HyperfCommand; use Hyperf\Command\Annotation\Command; use Psr\Container\ContainerInterface; +/** + * 废弃 + */ #[Command] class editDoctorQrCodeCommand extends HyperfCommand { diff --git a/app/Model/OrderServicePackage.php b/app/Model/OrderServicePackage.php index 8af19f9..98a99f1 100644 --- a/app/Model/OrderServicePackage.php +++ b/app/Model/OrderServicePackage.php @@ -34,12 +34,16 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property string $finish_time 结束服务时间 * @property string $cancel_time 订单取消时间 * @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 $created_at 创建时间 - * @property Carbon $updated_at 修改时间 + * @property \Carbon\Carbon $created_at 创建时间 + * @property \Carbon\Carbon $updated_at 修改时间 + * @property-read OrderServicePackageCase|null $OrderServicePackageCase */ class OrderServicePackage extends Model { @@ -53,7 +57,7 @@ class OrderServicePackage extends Model /** * 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_remarks', 'patient_name', 'patient_name_mask', 'patient_sex', 'patient_age', 'created_at', 'updated_at']; + 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_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"; @@ -136,7 +140,7 @@ class OrderServicePackage extends Model /** * 获取服务包订单-分页 * @param array $params - * @param array $order_service_status + * @param array $order_service_status_params * @param array $fields * @param int|null $page * @param int|null $per_page @@ -163,4 +167,18 @@ class OrderServicePackage extends Model return $data; } + + /** + * 获取某一时间段服务包订单-结束时间 + * @param array $params + * @param array $finish_time_params 接诊时间区间 + * @return Collection|array + */ + public static function getInquiryWithFinishTime(array $params, array $finish_time_params): Collection|array + { + return self::where($params) + ->whereBetween('finish_time', $finish_time_params) + ->orderBy('finish_time') + ->get(); + } }