635 lines
23 KiB
PHP
635 lines
23 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Command;
|
||
|
||
use App\Model\DoctorWithdrawalOrder;
|
||
use App\Model\Order;
|
||
use App\Model\OrderCoupon;
|
||
use App\Model\OrderDetection;
|
||
use App\Model\OrderDetectionRefund;
|
||
use App\Model\OrderInquiry;
|
||
use App\Model\OrderInquiryCoupon;
|
||
use App\Model\OrderInquiryRefund;
|
||
use App\Model\OrderProduct;
|
||
use App\Model\OrderProductCoupon;
|
||
use App\Model\OrderProductRefund;
|
||
use App\Model\OrderRefund;
|
||
use Hyperf\Command\Command as HyperfCommand;
|
||
use Hyperf\Command\Annotation\Command;
|
||
use Hyperf\DbConnection\Db;
|
||
use Psr\Container\ContainerInterface;
|
||
|
||
/**
|
||
* 迁移订单 v1.3使用
|
||
*/
|
||
#[Command]
|
||
class MoveOrderCommand extends HyperfCommand
|
||
{
|
||
public function __construct(protected ContainerInterface $container)
|
||
{
|
||
parent::__construct('MoveOrder:command');
|
||
}
|
||
|
||
public function configure()
|
||
{
|
||
parent::configure();
|
||
$this->setDescription('迁移历史订单');
|
||
}
|
||
|
||
public function handle()
|
||
{
|
||
$this->line("开始");
|
||
|
||
// 处理问诊订单
|
||
$this->handleOrderInquiry();
|
||
|
||
// 处理问诊订单退款
|
||
$this->handleOrderInquiryRefund();
|
||
|
||
// 处理问诊订单优惠卷
|
||
$this->handleOrderInquiryCoupon();
|
||
|
||
// 处理药品订单
|
||
$this->handleOrderProduct();
|
||
|
||
// 处理药品订单退款
|
||
$this->handleOrderProductRefund();
|
||
|
||
// 处理药品订单优惠卷
|
||
$this->handleOrderProductCoupon();
|
||
|
||
// 处理检测订单
|
||
$this->handleOrderDetection();
|
||
|
||
// 处理检测订单退款
|
||
$this->handleOrderDetectionRefund();
|
||
|
||
// 修正医生提现关联订单表数据
|
||
$this->handleDoctorWithdrawalOrder();
|
||
}
|
||
|
||
/**
|
||
* 处理问诊订单
|
||
* @return void
|
||
*/
|
||
public function handleOrderInquiry(): void
|
||
{
|
||
$params = array();
|
||
$order_inquirys = OrderInquiry::getList($params);
|
||
if (empty($order_inquirys)){
|
||
$this->line("无问诊订单需要执行");
|
||
return;
|
||
}
|
||
|
||
foreach ($order_inquirys as $order_inquiry){
|
||
if (!empty($order_inquiry['order_id'])){
|
||
// 已存在订单id,跳过
|
||
continue;
|
||
}
|
||
|
||
$params = array();
|
||
$params['order_no'] = $order_inquiry['inquiry_no'];
|
||
$order = Order::getOne($params);
|
||
if (!empty($order)){
|
||
// 已存在订单,跳过
|
||
continue;
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 生成订单表
|
||
$data = array();
|
||
$data['user_id'] = $order_inquiry['user_id'];
|
||
$data['patient_id'] = $order_inquiry['patient_id'];
|
||
if (!empty($order_inquiry['doctor_id'])){
|
||
$data['doctor_id'] = $order_inquiry['doctor_id'];
|
||
}
|
||
$data['order_type'] = 1;
|
||
$data['is_delete'] = $order_inquiry['is_delete']; // 删除状态(0:否 1:是)
|
||
$data['pay_channel'] = $order_inquiry['inquiry_pay_channel'];
|
||
$data['pay_status'] = $order_inquiry['inquiry_pay_status'];
|
||
$data['pay_time'] = $order_inquiry['pay_time'];
|
||
$data['refund_status'] = $order_inquiry['inquiry_refund_status'];
|
||
$data['order_no'] = $order_inquiry['inquiry_no'];
|
||
$data['escrow_trade_no'] = $order_inquiry['escrow_trade_no'];
|
||
$data['amount_total'] = $order_inquiry['amount_total'];
|
||
$data['coupon_amount_total'] = $order_inquiry['coupon_amount_total'];
|
||
$data['payment_amount_total'] = $order_inquiry['payment_amount_total'];
|
||
if ($order_inquiry['inquiry_status'] == 7){
|
||
$data['cancel_status'] = 1;
|
||
}
|
||
$data['cancel_time'] = $order_inquiry['cancel_time'];
|
||
if (!empty($order_inquiry['cancel_reason'])){
|
||
$data['cancel_remarks'] = inquiryCancelReasonToString($order_inquiry['cancel_reason']);
|
||
}
|
||
|
||
$data['is_withdrawal'] = $order_inquiry['is_withdrawal'];
|
||
$data['withdrawal_time'] = $order_inquiry['withdrawal_time'];
|
||
$order = Order::addOrder($data);
|
||
if (empty($order)) {
|
||
Db::rollBack();
|
||
$this->line("添加问诊订单失败");
|
||
}
|
||
|
||
// 修改问诊订单表
|
||
$data = array();
|
||
$data['order_id'] = $order['order_id'];
|
||
|
||
$params = array();
|
||
$params['inquiry_no'] = $order['order_no'];
|
||
OrderInquiry::edit($params,$data);
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
$this->line($e->getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 处理问诊订单退款
|
||
* @return void
|
||
*/
|
||
public function handleOrderInquiryRefund(): void
|
||
{
|
||
$params = array();
|
||
$order_inquiry_refunds = OrderInquiryRefund::getList($params);
|
||
if (empty($order_inquiry_refunds)){
|
||
$this->line("无问诊退款订单需要执行");
|
||
return;
|
||
}
|
||
|
||
foreach ($order_inquiry_refunds as $order_inquiry_refund){
|
||
$params = array();
|
||
$params['order_no'] = $order_inquiry_refund['inquiry_no'];
|
||
$order_refund = OrderRefund::getOne($params);
|
||
if (!empty($order_refund)){
|
||
// 已存在订单,跳过
|
||
continue;
|
||
}
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_no'] = $order_inquiry_refund['inquiry_no'];
|
||
$order = Order::getOne($params);
|
||
if (empty($order)){
|
||
// 已存在订单,跳过
|
||
$this->line("无对应订单数据");
|
||
continue;
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 生成订单表
|
||
$data = array();
|
||
$data['order_id'] = $order['order_id'];
|
||
$data['patient_id'] = $order_inquiry_refund['patient_id'];
|
||
$data['order_no'] = $order['order_no'];
|
||
$data['refund_no'] = $order_inquiry_refund['inquiry_refund_no'];
|
||
$data['refund_id'] = $order_inquiry_refund['refund_id'];
|
||
$data['refund_status'] = $order_inquiry_refund['inquiry_refund_status'];
|
||
$data['refund_total'] = $order_inquiry_refund['refund_total'];
|
||
$data['refund_reason'] = $order_inquiry_refund['refund_reason'];
|
||
$data['success_time'] = $order_inquiry_refund['success_time'];
|
||
$order_refund = OrderRefund::addOrderRefund($data);
|
||
if (empty($order_refund)) {
|
||
Db::rollBack();
|
||
$this->line("添加问诊退款订单失败");
|
||
}
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
$this->line($e->getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 处理问诊订单优惠卷
|
||
* @return void
|
||
*/
|
||
public function handleOrderInquiryCoupon(): void
|
||
{
|
||
$params = array();
|
||
$order_inquiry_coupons = OrderInquiryCoupon::getList($params);
|
||
if (empty($order_inquiry_coupons)){
|
||
$this->line("无问诊订单优惠卷需要执行");
|
||
return;
|
||
}
|
||
|
||
foreach ($order_inquiry_coupons as $order_inquiry_coupon){
|
||
// 获取问诊订单详情
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_coupon['order_inquiry_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)){
|
||
$this->line("问诊订单数据错误");
|
||
continue;
|
||
}
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_no'] = $order_inquiry['inquiry_no'];
|
||
$order = Order::getOne($params);
|
||
if (empty($order)){
|
||
$this->line("无对应订单数据");
|
||
continue;
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 生成订单表
|
||
$data = array();
|
||
$data['order_id'] = $order['order_id'];
|
||
$data['user_coupon_id'] = $order_inquiry_coupon['user_coupon_id'];
|
||
$data['coupon_name'] = $order_inquiry_coupon['coupon_name'];
|
||
$data['coupon_use_price'] = $order_inquiry_coupon['coupon_use_price'];
|
||
$order_coupon = OrderCoupon::addOrderCoupon($data);
|
||
if (empty($order_coupon)) {
|
||
Db::rollBack();
|
||
$this->line("添加问诊订单优惠卷失败");
|
||
}
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
$this->line($e->getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 处理药品订单
|
||
* @return void
|
||
*/
|
||
public function handleOrderProduct(): void
|
||
{
|
||
$params = array();
|
||
$order_products = OrderProduct::getList($params);
|
||
if (empty($order_products)){
|
||
$this->line("无药品订单需要执行");
|
||
return;
|
||
}
|
||
|
||
foreach ($order_products as $order_product){
|
||
if (!empty($order_product['order_id'])){
|
||
// 已存在订单id,跳过
|
||
continue;
|
||
}
|
||
|
||
$params = array();
|
||
$params['order_no'] = $order_product['order_product_no'];
|
||
$order = Order::getOne($params);
|
||
if (!empty($order)){
|
||
// 已存在订单,跳过
|
||
continue;
|
||
}
|
||
|
||
// 获取问诊订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_product['order_inquiry_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)){
|
||
$this->line("无问诊订单数据");
|
||
continue;
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 生成订单表
|
||
$data = array();
|
||
$data['user_id'] = $order_inquiry['user_id'];
|
||
$data['patient_id'] = $order_product['patient_id'];
|
||
$data['doctor_id'] = $order_product['doctor_id'];
|
||
$data['order_type'] = 2;
|
||
$data['is_delete'] = $order_product['is_delete']; // 删除状态(0:否 1:是)
|
||
$data['pay_channel'] = $order_product['pay_channel'];
|
||
$data['pay_status'] = $order_product['pay_status'];
|
||
$data['pay_time'] = $order_product['pay_time'];
|
||
$data['refund_status'] = $order_product['refund_status'];
|
||
$data['order_no'] = $order_product['order_product_no'];
|
||
$data['escrow_trade_no'] = $order_product['escrow_trade_no'];
|
||
$data['amount_total'] = $order_product['amount_total'];
|
||
$data['coupon_amount_total'] = $order_product['coupon_amount_total'];
|
||
$data['payment_amount_total'] = $order_product['payment_amount_total'];
|
||
if ($order_inquiry['order_product_status'] == 5){
|
||
$data['cancel_status'] = 1;
|
||
}
|
||
$data['cancel_time'] = $order_product['cancel_time'];
|
||
$data['cancel_remarks'] = $order_product['cancel_remarks'];
|
||
$data['is_withdrawal'] = 3;
|
||
$order = Order::addOrder($data);
|
||
if (empty($order)) {
|
||
Db::rollBack();
|
||
$this->line("添加药品订单失败");
|
||
}
|
||
|
||
// 修改药品订单表
|
||
$data = array();
|
||
$data['order_id'] = $order['order_id'];
|
||
|
||
$params = array();
|
||
$params['order_product_no'] = $order['order_no'];
|
||
OrderProduct::edit($params,$data);
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
$this->line($e->getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 处理药品订单退款
|
||
* @return void
|
||
*/
|
||
public function handleOrderProductRefund(): void
|
||
{
|
||
$params = array();
|
||
$order_product_refunds = OrderProductRefund::getList($params);
|
||
if (empty($order_product_refunds)){
|
||
$this->line("无问诊退款订单需要执行");
|
||
return;
|
||
}
|
||
|
||
foreach ($order_product_refunds as $order_product_refund){
|
||
$params = array();
|
||
$params['order_no'] = $order_product_refund['order_product_no'];
|
||
$order_refund = OrderRefund::getOne($params);
|
||
if (!empty($order_refund)){
|
||
// 已存在订单,跳过
|
||
continue;
|
||
}
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_no'] = $order_product_refund['order_product_no'];
|
||
$order = Order::getOne($params);
|
||
if (empty($order)){
|
||
// 已存在订单,跳过
|
||
$this->line("无对应订单数据");
|
||
continue;
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 生成订单表
|
||
$data = array();
|
||
$data['order_id'] = $order['order_id'];
|
||
$data['patient_id'] = $order_product_refund['patient_id'];
|
||
$data['order_no'] = $order['order_no'];
|
||
$data['refund_no'] = $order_product_refund['order_product_no'];
|
||
$data['refund_id'] = $order_product_refund['refund_id'];
|
||
$data['refund_status'] = $order_product_refund['product_refund_status'];
|
||
$data['refund_total'] = $order_product_refund['refund_total'];
|
||
$data['refund_reason'] = $order_product_refund['refund_reason'];
|
||
$data['success_time'] = $order_product_refund['success_time'];
|
||
$order_refund = OrderRefund::addOrderRefund($data);
|
||
if (empty($order_refund)) {
|
||
Db::rollBack();
|
||
$this->line("添加药品退款订单失败");
|
||
}
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
$this->line($e->getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 处理药品订单优惠卷
|
||
* @return void
|
||
*/
|
||
public function handleOrderProductCoupon(): void
|
||
{
|
||
$params = array();
|
||
$order_product_coupons = OrderProductCoupon::getList($params);
|
||
if (empty($order_product_coupons)){
|
||
$this->line("无药品订单优惠卷需要执行");
|
||
return;
|
||
}
|
||
|
||
foreach ($order_product_coupons as $order_product_coupon){
|
||
// 获取问诊订单详情
|
||
$params = array();
|
||
$params['order_product_id'] = $order_product_coupon['order_product_id'];
|
||
$order_product = OrderProduct::getOne($params);
|
||
if (empty($order_product)){
|
||
$this->line("药品订单数据错误");
|
||
continue;
|
||
}
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_no'] = $order_product['order_product_no'];
|
||
$order = Order::getOne($params);
|
||
if (empty($order)){
|
||
$this->line("无对应订单数据");
|
||
continue;
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 生成订单表
|
||
$data = array();
|
||
$data['order_id'] = $order['order_id'];
|
||
$data['user_coupon_id'] = $order_product_coupon['user_coupon_id'];
|
||
$data['coupon_name'] = $order_product_coupon['coupon_name'];
|
||
$data['coupon_use_price'] = $order_product_coupon['coupon_use_price'];
|
||
$order_coupon = OrderCoupon::addOrderCoupon($data);
|
||
if (empty($order_coupon)) {
|
||
Db::rollBack();
|
||
$this->line("添加问诊订单优惠卷失败");
|
||
}
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
$this->line($e->getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 处理检测订单
|
||
* @return void
|
||
*/
|
||
public function handleOrderDetection(): void
|
||
{
|
||
$params = array();
|
||
$order_detections = OrderDetection::getList($params);
|
||
if (empty($order_detections)){
|
||
$this->line("无检测订单需要执行");
|
||
return;
|
||
}
|
||
|
||
foreach ($order_detections as $order_detection){
|
||
if (!empty($order_detection['order_id'])){
|
||
// 已存在订单id,跳过
|
||
continue;
|
||
}
|
||
|
||
$params = array();
|
||
$params['order_no'] = $order_detection['detection_no'];
|
||
$order = Order::getOne($params);
|
||
if (!empty($order)){
|
||
// 已存在订单,跳过
|
||
continue;
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 生成订单表
|
||
$data = array();
|
||
$data['user_id'] = $order_detection['user_id'];
|
||
$data['patient_id'] = $order_detection['patient_id'];
|
||
$data['doctor_id'] = $order_detection['doctor_id'];
|
||
$data['order_type'] = 3;
|
||
$data['is_delete'] = $order_detection['is_delete']; // 删除状态(0:否 1:是)
|
||
$data['pay_channel'] = $order_detection['detection_pay_channel'];
|
||
$data['pay_status'] = $order_detection['detection_pay_status'];
|
||
$data['pay_time'] = $order_detection['pay_time'];
|
||
$data['refund_status'] = $order_detection['detection_refund_status'];
|
||
$data['order_no'] = $order_detection['detection_no'];
|
||
$data['escrow_trade_no'] = $order_detection['escrow_trade_no'];
|
||
$data['amount_total'] = $order_detection['amount_total'];
|
||
$data['coupon_amount_total'] = $order_detection['coupon_amount_total'];
|
||
$data['payment_amount_total'] = $order_detection['payment_amount_total'];
|
||
if ($order_detection['detection_status'] == 5){
|
||
$data['cancel_status'] = 1;
|
||
}
|
||
$data['cancel_time'] = $order_detection['cancel_time'];
|
||
if (!empty($order_detection['cancel_reason'])){
|
||
$data['cancel_remarks'] = detectionCancelReasonToString($order_detection['cancel_reason']);
|
||
}
|
||
|
||
$data['is_withdrawal'] = 3;
|
||
|
||
$order = Order::addOrder($data);
|
||
if (empty($order)) {
|
||
Db::rollBack();
|
||
$this->line("添加检测订单失败");
|
||
}
|
||
|
||
// 修改检测订单表
|
||
$data = array();
|
||
$data['order_id'] = $order['order_id'];
|
||
|
||
$params = array();
|
||
$params['detection_no'] = $order['order_no'];
|
||
OrderDetection::editOrderDetection($params,$data);
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
$this->line($e->getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 处理检测订单退款
|
||
* @return void
|
||
*/
|
||
public function handleOrderDetectionRefund(): void
|
||
{
|
||
$params = array();
|
||
$order_detection_refunds = OrderDetectionRefund::getList($params);
|
||
if (empty($order_detection_refunds)){
|
||
$this->line("无检测退款订单需要执行");
|
||
return;
|
||
}
|
||
|
||
foreach ($order_detection_refunds as $order_detection_refund){
|
||
$params = array();
|
||
$params['order_no'] = $order_detection_refund['detection_no'];
|
||
$order_refund = OrderRefund::getOne($params);
|
||
if (!empty($order_refund)){
|
||
// 已存在订单,跳过
|
||
continue;
|
||
}
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_no'] = $order_detection_refund['detection_no'];
|
||
$order = Order::getOne($params);
|
||
if (empty($order)){
|
||
// 已存在订单,跳过
|
||
$this->line("无对应订单数据");
|
||
continue;
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 生成订单表
|
||
$data = array();
|
||
$data['order_id'] = $order['order_id'];
|
||
$data['patient_id'] = $order_detection_refund['patient_id'];
|
||
$data['order_no'] = $order['order_no'];
|
||
$data['refund_no'] = $order_detection_refund['detection_refund_no'];
|
||
$data['refund_id'] = $order_detection_refund['refund_id'];
|
||
$data['refund_status'] = $order_detection_refund['detection_refund_status'];
|
||
$data['refund_total'] = $order_detection_refund['refund_total'];
|
||
$data['refund_reason'] = $order_detection_refund['refund_reason'];
|
||
$data['success_time'] = $order_detection_refund['success_time'];
|
||
$order_refund = OrderRefund::addOrderRefund($data);
|
||
if (empty($order_refund)) {
|
||
Db::rollBack();
|
||
$this->line("添加检测退款订单失败");
|
||
}
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
$this->line($e->getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 修正医生提现关联订单表数据
|
||
* @return void
|
||
*/
|
||
public function handleDoctorWithdrawalOrder(): void
|
||
{
|
||
$params = array();
|
||
$doctor_withdrawal_orders = DoctorWithdrawalOrder::getList($params);
|
||
if (empty($doctor_withdrawal_orders)){
|
||
$this->line("无检测退款订单需要执行");
|
||
return;
|
||
}
|
||
|
||
foreach ($doctor_withdrawal_orders as $doctor_withdrawal_order){
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $doctor_withdrawal_order['order_inquiry_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)){
|
||
$this->line("无对应订单数据");
|
||
continue;
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
$params = array();
|
||
$params['withdrawal_order_id'] = $doctor_withdrawal_order['withdrawal_order_id'];
|
||
|
||
$data = array();
|
||
$data['order_id'] = $order_inquiry['order_id'];
|
||
DoctorWithdrawalOrder::edit($params,$data);
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
$this->line($e->getMessage());
|
||
}
|
||
}
|
||
}
|
||
}
|