新增取消订单恢复优惠卷,新增获取订单支付数据接口
This commit is contained in:
@@ -18,6 +18,7 @@ use App\Model\PatientFamily;
|
||||
use App\Model\PatientFamilyHealth;
|
||||
use App\Model\PatientFamilyPersonal;
|
||||
use App\Model\Product;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Model\UserPatient;
|
||||
use App\Utils\Mask;
|
||||
@@ -121,8 +122,8 @@ class InquiryService extends BaseService
|
||||
|
||||
try {
|
||||
// 实际付款金额
|
||||
$coupon_price = $user_coupon['coupon']['coupon_price'] ?? 0;
|
||||
$payment_amount_total = $inquiry_price - $coupon_price;
|
||||
$coupon_amount_total = $user_coupon['coupon']['coupon_price'] ?? 0;
|
||||
$payment_amount_total = $inquiry_price - $coupon_amount_total;
|
||||
|
||||
// 生成问诊订单
|
||||
$data = array();
|
||||
@@ -136,6 +137,7 @@ class InquiryService extends BaseService
|
||||
$data['inquiry_pay_channel'] = $inquiry_pay_channel ?? 0;// 支付渠道(1:小程序支付 2:微信扫码支付)
|
||||
$data['inquiry_no'] = $generator->generate();// 订单编号
|
||||
$data['amount_total'] = $inquiry_price;// 订单金额
|
||||
$data['coupon_amount_total'] = $coupon_amount_total;// 优惠卷总金额
|
||||
$data['payment_amount_total'] = $payment_amount_total;// 实际付款金额
|
||||
$data['patient_name'] = $patient_family['card_name'];// 患者姓名-就诊人
|
||||
$data['patient_name_mask'] = $patient_family['card_name_mask'];// 患者姓名-就诊人(掩码)
|
||||
@@ -247,20 +249,17 @@ class InquiryService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
// 发起支付
|
||||
$WechatPay = new WechatPay(1);
|
||||
// 修改优惠卷使用状态
|
||||
if (!empty($user_coupon)){
|
||||
$data = array();
|
||||
$data['user_coupon_status'] = 1;
|
||||
$data['coupon_use_date'] = date('Y-m-d H:i:s',time());
|
||||
|
||||
// 获取预支付交易会话标识
|
||||
$total = $inquiry_price * 100;
|
||||
$prepay = $WechatPay->getJsapiPrepayId($order_inquiry['inquiry_no'], $total, $user_info['open_id']);
|
||||
if (empty($prepay)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
$params = array();
|
||||
$params['user_coupon_id'] = $user_coupon['user_coupon_id'];
|
||||
UserCoupon::edit($params,$data);
|
||||
}
|
||||
|
||||
// 获取小程序支付配置
|
||||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||||
|
||||
// 增加至取消订单延迟队列
|
||||
$data = array();
|
||||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
@@ -281,12 +280,8 @@ class InquiryService extends BaseService
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$result['amount_total'] = $inquiry_price; // 订单金额
|
||||
$result['inquiry_no'] = $order_inquiry['inquiry_no']; // 订单编号
|
||||
$result['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; // 订单主键id
|
||||
$result['created_at'] = date('Y-m-d H:i:s', strtotime($order_inquiry['created_at'])); // 创建时间
|
||||
$result['inquiry_type'] = $order_inquiry['inquiry_type']; // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||||
$result['pay_config'] = $pay_config; // 小程序支付配置
|
||||
|
||||
return success($result);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Model\OrderPrescription;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductItem;
|
||||
use App\Model\UserDoctor;
|
||||
use Extend\Wechat\WechatPay;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -601,4 +602,103 @@ class PatientOrderService extends BaseService
|
||||
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取患者订单支付数据
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getPatientOrderPayInfo(): array
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
|
||||
$order_type = $this->request->input('order_type');
|
||||
$order_no = $this->request->input('order_no');
|
||||
|
||||
if ($order_type == 1){
|
||||
// 问诊订单
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $order_no;
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"非法订单");
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_inquiry['inquiry_status'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单状态错误");
|
||||
}
|
||||
|
||||
// 验证订单支付状态
|
||||
if ($order_inquiry['inquiry_pay_status'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单支付状态错误");
|
||||
}
|
||||
|
||||
$order_id = $order_inquiry['order_inquiry_id'];
|
||||
$created_at = $order_inquiry['created_at'];
|
||||
$inquiry_type = $order_inquiry['inquiry_type'];
|
||||
|
||||
// 获取订单金额
|
||||
$amount_total = $order_inquiry['amount_total'];
|
||||
$payment_amount_total = $order_inquiry['payment_amount_total'];
|
||||
$coupon_amount_total = $order_inquiry['coupon_amount_total'];
|
||||
|
||||
}elseif ($order_type == 2){
|
||||
// 药品订单
|
||||
$params = array();
|
||||
$params['order_product_no'] = $order_no;
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"非法订单");
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_product['order_product_status'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单状态错误");
|
||||
}
|
||||
|
||||
// 验证订单支付状态
|
||||
if ($order_product['inquiry_pay_status'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单支付状态错误");
|
||||
}
|
||||
|
||||
$order_id = $order_product['order_product_id'];
|
||||
$created_at = $order_product['created_at'];
|
||||
$inquiry_type = 0;
|
||||
|
||||
// 获取订单金额
|
||||
$amount_total = $order_product['amount_total'];
|
||||
$payment_amount_total = $order_product['payment_amount_total'];
|
||||
$coupon_amount_total = 0;
|
||||
}else{
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 发起支付
|
||||
$WechatPay = new WechatPay(1);
|
||||
|
||||
// 获取预支付交易会话标识
|
||||
$prepay = $WechatPay->getJsapiPrepayId($order_no, $payment_amount_total * 100, $user_info['open_id']);
|
||||
if (empty($prepay)) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
// 获取小程序支付配置
|
||||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||||
|
||||
$result = array();
|
||||
$result['amount_total'] = $amount_total; // 订单金额
|
||||
$result['payment_amount_total'] = $payment_amount_total; // 实际订单金额
|
||||
$result['coupon_amount_total'] = $coupon_amount_total; // 优惠金额
|
||||
$result['order_no'] = $order_no; // 订单编号
|
||||
$result['order_id'] = $order_id; // 订单主键id(问诊订单:order_inquiry_id 药品订单:order_product_id)
|
||||
$result['created_at'] = $created_at; // 创建时间
|
||||
$result['inquiry_type'] = $inquiry_type; // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||||
$result['pay_config'] = $pay_config; // 小程序支付配置
|
||||
|
||||
return success($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user