10、问诊订单退款
11、药品订单退款 12、问诊订单模拟退款 13、药品订单模拟退款
This commit is contained in:
@@ -4,14 +4,17 @@ namespace App\Services;
|
||||
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\OrderInquiryCoupon;
|
||||
use App\Model\OrderInquiryRefund;
|
||||
use App\Model\OrderPrescription;
|
||||
use App\Model\OrderPrescriptionProduct;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductCoupon;
|
||||
use App\Model\OrderProductItem;
|
||||
use App\Model\OrderProductRefund;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
use App\Model\UserPatient;
|
||||
use Extend\Wechat\WechatPay;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Snowflake\IdGeneratorInterface;
|
||||
@@ -41,6 +44,8 @@ class OrderProductService extends BaseService
|
||||
* @param string|int $cancel_reason 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时
|
||||
* @param string $cancel_remarks 订单取消原因
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function cancelUnpayProductOrder(string|int $order_no,string|int $cancel_reason,string $cancel_remarks): array
|
||||
{
|
||||
@@ -87,6 +92,16 @@ class OrderProductService extends BaseService
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 获取患者数据
|
||||
$params = array();
|
||||
$params['patient_id'] = $order_product['patient_id'];
|
||||
$user_patient = UserPatient::getOne($params);
|
||||
if (empty($user_patient)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应用户数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 取消药品订单
|
||||
$data = array();
|
||||
$data['order_product_status'] = 5;
|
||||
@@ -134,7 +149,6 @@ class OrderProductService extends BaseService
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
// 库存+订单商品数量
|
||||
$params = array();
|
||||
$params['amount_id'] = $product_platform_amount['amount_id'];
|
||||
@@ -181,6 +195,25 @@ class OrderProductService extends BaseService
|
||||
OrderPrescriptionProduct::edit($params, $data);
|
||||
}
|
||||
|
||||
// 处理订单优惠卷
|
||||
if (!empty($order_product['coupon_amount_total']) && $order_product['coupon_amount_total'] > 0) {
|
||||
// 获取该订单全部优惠卷数据
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
$order_product_coupons = OrderProductCoupon::getList($params);
|
||||
if (!empty($order_product_coupons)){
|
||||
$userCouponService = new UserCouponService();
|
||||
foreach ($order_product_coupons as $order_product_coupon){
|
||||
// 退还优惠卷
|
||||
$userCouponService->returnUserCoupon($order_product_coupon['user_coupon_id']);
|
||||
|
||||
// 发送站内消息-优惠卷退还
|
||||
$MessagePush = new MessagePush($user_patient['user_id']);
|
||||
$MessagePush->patientRefundCoupon($order_product_coupon['coupon_name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -233,6 +266,14 @@ class OrderProductService extends BaseService
|
||||
throw new BusinessException("订单支付状态错误,无法退款");
|
||||
}
|
||||
|
||||
// 获取患者数据
|
||||
$params = array();
|
||||
$params['patient_id'] = $order_product['patient_id'];
|
||||
$user_patient = UserPatient::getOne($params);
|
||||
if (empty($user_patient)){
|
||||
throw new BusinessException("未查询到对应用户数据");
|
||||
}
|
||||
|
||||
// 系统退款编号
|
||||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||||
$product_refund_no = $generator->generate();
|
||||
@@ -281,6 +322,25 @@ class OrderProductService extends BaseService
|
||||
$refund_status = 3;
|
||||
$refund_id = "模拟退款:" . $generator->generate();
|
||||
$success_time = date("Y-m-d H:i:s", time());
|
||||
|
||||
// 模拟退款时手动退还优惠卷
|
||||
if (!empty($order_product['coupon_amount_total']) && $order_product['coupon_amount_total'] > 0) {
|
||||
// 获取该订单全部优惠卷数据
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
$order_product_coupons = OrderProductCoupon::getList($params);
|
||||
if (!empty($order_product_coupons)){
|
||||
$userCouponService = new UserCouponService();
|
||||
foreach ($order_product_coupons as $order_product_coupon){
|
||||
// 退还优惠卷
|
||||
$userCouponService->returnUserCoupon($order_product_coupon['user_coupon_id']);
|
||||
|
||||
// 发送站内消息-优惠卷退还
|
||||
$MessagePush = new MessagePush($user_patient['user_id']);
|
||||
$MessagePush->patientRefundCoupon($order_product_coupon['coupon_name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 新增退款表
|
||||
|
||||
Reference in New Issue
Block a user