修改支付中心数据,增加优惠卷不可使用原因
This commit is contained in:
@@ -19,11 +19,13 @@ use App\Model\OrderPrescription;
|
||||
use App\Model\OrderPrescriptionFile;
|
||||
use App\Model\OrderPrescriptionProduct;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductCoupon;
|
||||
use App\Model\OrderProductItem;
|
||||
use App\Model\OrderProductLogistic;
|
||||
use App\Model\PatientFollow;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Model\UserDoctorInfo;
|
||||
use App\Model\UserPharmacistInfo;
|
||||
@@ -199,7 +201,7 @@ class PatientOrderService extends BaseService
|
||||
$order_inquiry_case = OrderInquiryCase::getOne($params, $fields);
|
||||
if (empty($order_inquiry_case)) {
|
||||
$order_inquiry['case'] = [];
|
||||
}else{
|
||||
} else {
|
||||
$order_inquiry['case'] = $order_inquiry_case->toArray();
|
||||
}
|
||||
|
||||
@@ -262,8 +264,8 @@ class PatientOrderService extends BaseService
|
||||
$params['inquiry_type'] = 4;
|
||||
$params['inquiry_mode'] = 1;
|
||||
$doctor_inquiry_config = DoctorInquiryConfig::getOne($params);
|
||||
if (!empty($doctor_inquiry_config)){
|
||||
if ($doctor_inquiry_config['is_enable'] == 1){
|
||||
if (!empty($doctor_inquiry_config)) {
|
||||
if ($doctor_inquiry_config['is_enable'] == 1) {
|
||||
$user_doctor['multi_point_enable'] = 1;
|
||||
}
|
||||
}
|
||||
@@ -592,8 +594,8 @@ class PatientOrderService extends BaseService
|
||||
$params['inquiry_type'] = 4;
|
||||
$params['inquiry_mode'] = 1;
|
||||
$doctor_inquiry_config = DoctorInquiryConfig::getOne($params);
|
||||
if (!empty($doctor_inquiry_config)){
|
||||
if ($doctor_inquiry_config['is_enable'] == 1){
|
||||
if (!empty($doctor_inquiry_config)) {
|
||||
if ($doctor_inquiry_config['is_enable'] == 1) {
|
||||
$user_doctor['multi_point_enable'] = 1;
|
||||
}
|
||||
}
|
||||
@@ -715,6 +717,7 @@ class PatientOrderService extends BaseService
|
||||
$result['created_at'] = ""; // 创建时间
|
||||
$result['inquiry_type'] = 0; // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测)
|
||||
$result['pay_config'] = []; // 小程序支付配置
|
||||
$result['cannot_use_coupon_reason'] = ""; // 不可使用优惠卷原因
|
||||
|
||||
if ($order_type == 1) {
|
||||
// 问诊订单
|
||||
@@ -827,7 +830,53 @@ class PatientOrderService extends BaseService
|
||||
// 获取订单金额
|
||||
$result['amount_total'] = $order_product['amount_total']; // 订单金额
|
||||
$result['payment_amount_total'] = $order_product['payment_amount_total']; // 实际订单金额
|
||||
$result['coupon_amount_total'] = 0; // 优惠金额
|
||||
$result['coupon_amount_total'] = $order_product['coupon_amount_total']; // 优惠金额
|
||||
|
||||
// 获取优惠卷不可用原因。存在优惠卷,但是未使用
|
||||
if ($order_product['coupon_amount_total'] == 0){
|
||||
// 优惠卷商品数据
|
||||
$coupon_product_datas = array();
|
||||
|
||||
// 获取药品订单关联处方商品数据
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_product['order_prescription_id'];
|
||||
$order_prescription_products = OrderPrescriptionProduct::getList($params);
|
||||
if (empty($order_prescription_products)) {
|
||||
$return_result['message'] = "优惠卷数据错误";
|
||||
$return_result['data'] = $result;
|
||||
$return_result['data']['order_product_id'] = $order_product['order_product_id'];
|
||||
$return_result['data']['order_product_status'] = $order_product['order_product_status'];
|
||||
$return_result['data']['order_pay_status'] = $order_product['pay_status'];
|
||||
return success($return_result);
|
||||
}
|
||||
|
||||
foreach ($order_prescription_products as $order_prescription_product){
|
||||
$params = array();
|
||||
$params['product_id'] = $order_prescription_product['product_id'];
|
||||
$product = Product::getWithAmountOne($params);
|
||||
if (empty($product)) {
|
||||
$return_result['message'] = "优惠卷数据错误";
|
||||
$return_result['data'] = $result;
|
||||
$return_result['data']['order_product_id'] = $order_product['order_product_id'];
|
||||
$return_result['data']['order_product_status'] = $order_product['order_product_status'];
|
||||
$return_result['data']['order_pay_status'] = $order_product['pay_status'];
|
||||
return success($return_result);
|
||||
}
|
||||
|
||||
// 优惠卷商品数据
|
||||
$coupon_product_data = array();
|
||||
$product['product_num'] = $order_prescription_product['prescription_product_num'];
|
||||
$coupon_product_data[] = $product;
|
||||
$coupon_product_datas[] = $coupon_product_data;
|
||||
}
|
||||
|
||||
$user_coupons = UserCoupon::getUserProductUsableCoupon($user_info['user_id'],$coupon_product_datas);
|
||||
if (!empty($user_coupons)) {
|
||||
foreach ($user_coupons as $user_coupon){
|
||||
$result['cannot_use_coupon_reason'] = "商品不足" . $user_coupon['min_usable_number'] . "盒,不满足使用优惠卷条件";; // 不可使用优惠卷原因
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($order_product['payment_amount_total'] > 0) {
|
||||
// 发起支付
|
||||
@@ -947,7 +996,7 @@ class PatientOrderService extends BaseService
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$order_inquiry_case = OrderInquiryCase::getOne($params);
|
||||
if (empty($order_inquiry_case)){
|
||||
if (empty($order_inquiry_case)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "患者病例错误");
|
||||
}
|
||||
@@ -1095,19 +1144,22 @@ class PatientOrderService extends BaseService
|
||||
|
||||
$not_enough_product_ids = [];
|
||||
$amount_total = 0;
|
||||
foreach ($product_ids as $value) {
|
||||
|
||||
// 优惠卷商品数据
|
||||
$coupon_product_datas = array();
|
||||
|
||||
foreach ($product_ids as $product_id) {
|
||||
// 检测药品是否存在于处方中
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
$params['product_id'] = $value;
|
||||
$params['product_id'] = $product_id;
|
||||
$order_prescription_product = OrderPrescriptionProduct::getOne($params);
|
||||
if (empty($order_prescription_product)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "创建订单失败");
|
||||
}
|
||||
|
||||
|
||||
$params = array();
|
||||
$params['product_id'] = $value;
|
||||
$params['product_id'] = $product_id;
|
||||
$product = Product::getWithAmountOne($params);
|
||||
if (empty($product)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方存在未知药品");
|
||||
@@ -1117,19 +1169,38 @@ class PatientOrderService extends BaseService
|
||||
if (!empty($product['ProductPlatformAmount'])) {
|
||||
if ($order_prescription_product['prescription_product_num'] > $product['ProductPlatformAmount']['stock']) {
|
||||
// 库存不足
|
||||
$not_enough_product_ids[] = $value;
|
||||
$not_enough_product_ids[] = $product_id;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单金额
|
||||
$amount_total += $product['product_price'] * $order_prescription_product['prescription_product_num'];
|
||||
$amount_total = bcadd($amount_total, ($product['product_price'] * $order_prescription_product['prescription_product_num']), 2);
|
||||
|
||||
// 优惠卷商品数据
|
||||
$coupon_product_data = array();
|
||||
$product['product_num'] = $order_prescription_product['prescription_product_num'];
|
||||
$coupon_product_data[] = $product;
|
||||
$coupon_product_datas[] = $coupon_product_data;
|
||||
}
|
||||
|
||||
if (!empty($not_enough_product_ids)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "存在库存不足商品", $not_enough_product_ids);
|
||||
}
|
||||
|
||||
// 定义优惠卷金额默认值
|
||||
$coupon_amount_total = 0;
|
||||
|
||||
if (!empty($coupon_product_datas)) {
|
||||
// 获取患者购药可用的优惠卷
|
||||
$userCouponService = new UserCouponService();
|
||||
$user_coupons = $userCouponService->getUserProductUsableCoupon($user_info['user_id'], $coupon_product_datas);
|
||||
|
||||
// 获取可用优惠卷总金额
|
||||
$coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupons);
|
||||
}
|
||||
|
||||
// 处理运费数据
|
||||
$app_env = config('app_env', 'prod');
|
||||
if ($app_env != "dev") {
|
||||
// 获取运费金额
|
||||
@@ -1141,16 +1212,20 @@ class PatientOrderService extends BaseService
|
||||
} else {
|
||||
$logistics_fee = $result['freight'];
|
||||
}
|
||||
|
||||
// 实际支付金额
|
||||
$payment_amount_total = $amount_total + $logistics_fee;
|
||||
} else {
|
||||
$logistics_fee = 0;
|
||||
}
|
||||
|
||||
// 实际支付金额=商品总金额-优惠卷金额+运费金额
|
||||
$payment_amount_total = bcadd(bcsub($amount_total , $coupon_amount_total,2), $logistics_fee, 2);
|
||||
if ($app_env == "dev") {
|
||||
$logistics_fee = 0;
|
||||
$payment_amount_total = 0.01;
|
||||
}
|
||||
|
||||
if ($payment_amount_total < 0) {
|
||||
$payment_amount_total = 0;
|
||||
}
|
||||
|
||||
// 确定支付渠道
|
||||
// 支付渠道(1:小程序支付 2:微信扫码支付)
|
||||
if ($client_type == 1) {
|
||||
@@ -1175,6 +1250,7 @@ class PatientOrderService extends BaseService
|
||||
$data['order_product_status'] = 1; // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$data['pay_channel'] = $pay_channel; // 支付渠道(1:小程序支付 2:微信扫码支付)
|
||||
$data['amount_total'] = $amount_total; // 订单金额
|
||||
$data['coupon_amount_total'] = $coupon_amount_total; // 优惠卷总金额
|
||||
$data['payment_amount_total'] = $payment_amount_total; // 实际付款金额
|
||||
$data['logistics_fee'] = $logistics_fee; // 运费金额
|
||||
$data['province_id'] = $user_ship_address['province_id'];
|
||||
@@ -1263,6 +1339,32 @@ class PatientOrderService extends BaseService
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
OrderPrescription::edit($params, $data);
|
||||
|
||||
// 处理优惠卷数据
|
||||
if (!empty($user_coupons)) {
|
||||
foreach ($user_coupons as $user_coupon){
|
||||
// 增加问诊优惠卷表
|
||||
$data = array();
|
||||
$data['order_product_id'] = $order_product['order_product_id'];// 订单-商品id
|
||||
$data['user_coupon_id'] = $user_coupon['user_coupon_id'];
|
||||
$data['coupon_name'] = $user_coupon['coupon']['coupon_name'];
|
||||
$data['coupon_use_price'] = $user_coupon['coupon']['coupon_price'];
|
||||
$order_product_coupon = OrderProductCoupon::addOrderProductCoupon($data);
|
||||
if (empty($order_product_coupon)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
}
|
||||
|
||||
// 修改优惠卷使用状态
|
||||
$data = array();
|
||||
$data['user_coupon_status'] = 1;
|
||||
$data['coupon_use_date'] = date('Y-m-d H:i:s', time());
|
||||
|
||||
$params = array();
|
||||
$params['user_coupon_id'] = $user_coupon['user_coupon_id'];
|
||||
UserCoupon::edit($params, $data);
|
||||
}
|
||||
}
|
||||
|
||||
// 增加至取消订单延迟队列
|
||||
$data = array();
|
||||
$data['order_no'] = (string)$order_product['order_product_no'];
|
||||
@@ -1782,8 +1884,8 @@ class PatientOrderService extends BaseService
|
||||
$params['inquiry_type'] = 4;
|
||||
$params['inquiry_mode'] = 1;
|
||||
$doctor_inquiry_config = DoctorInquiryConfig::getOne($params);
|
||||
if (!empty($doctor_inquiry_config)){
|
||||
if ($doctor_inquiry_config['is_enable'] == 1){
|
||||
if (!empty($doctor_inquiry_config)) {
|
||||
if ($doctor_inquiry_config['is_enable'] == 1) {
|
||||
$user_doctor['multi_point_enable'] = 1;
|
||||
}
|
||||
}
|
||||
@@ -1795,7 +1897,7 @@ class PatientOrderService extends BaseService
|
||||
}
|
||||
|
||||
// 检测管图片
|
||||
if (!empty($order_detection['detection_pic'])){
|
||||
if (!empty($order_detection['detection_pic'])) {
|
||||
$detection_pic = explode(',', $order_detection['detection_pic']);
|
||||
foreach ($detection_pic as &$value) {
|
||||
$value = addAliyunOssWebsite($value);
|
||||
@@ -1807,7 +1909,7 @@ class PatientOrderService extends BaseService
|
||||
$params = array();
|
||||
$params['detection_project_id'] = $order_detection['detection_project_id'];
|
||||
$detection_project = DetectionProject::getOne($params);
|
||||
if (empty($detection_project)){
|
||||
if (empty($detection_project)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
@@ -1815,7 +1917,7 @@ class PatientOrderService extends BaseService
|
||||
$order_detection['detection_result_pdf'] = addAliyunOssWebsite($order_detection['detection_result_pdf']);
|
||||
|
||||
// 检测成功时间
|
||||
$detection_success_time = date('Y-m-d',time() + 60 * 60 * $detection_project['detection_time']);
|
||||
$detection_success_time = date('Y-m-d', time() + 60 * 60 * $detection_project['detection_time']);
|
||||
$order_detection['detection_success_time'] = $detection_success_time;
|
||||
|
||||
return success($order_detection);
|
||||
|
||||
Reference in New Issue
Block a user