修改支付中心数据,增加优惠卷不可使用原因
This commit is contained in:
parent
d7a4d9ab4a
commit
2336d96915
@ -86,7 +86,7 @@ class CancelUnpayOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
Db::commit();
|
||||
Log::getInstance("queue-CancelUnpayOrders")->info("取消未支付订单 队列执行成功");
|
||||
return Result::ACK;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-CancelUnpayOrders")->error("取消未支付订单执行失败:" . $e->getMessage());
|
||||
return Result::ACK; // 重回队列
|
||||
|
||||
@ -26,6 +26,7 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
||||
* @property int $is_delete 删除状态(0:否 1:是)
|
||||
* @property int $cancel_reason 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时 4:客服取消)
|
||||
* @property string $amount_total 订单金额
|
||||
* @property string $coupon_amount_total 优惠卷总金额
|
||||
* @property string $payment_amount_total 实际付款金额
|
||||
* @property string $logistics_fee 运费金额
|
||||
* @property string $logistics_no 物流编号
|
||||
@ -37,7 +38,7 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
||||
* @property int $refund_status 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
* @property string $cancel_time 订单取消时间
|
||||
* @property string $cancel_remarks 订单取消备注(自动添加)
|
||||
* @property int $report_pre_status 上报处方平台状态(0:未上报 1:已上报 2:上报失败))
|
||||
* @property int $report_pre_status 上报处方平台状态(0:未上报 1:已上报 2:上报失败 3:上报取消)
|
||||
* @property string $report_pre_time 上报处方平台时间
|
||||
* @property string $report_pre_fail_reason 上报失败原因
|
||||
* @property int $province_id 省份id
|
||||
@ -54,10 +55,10 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
||||
* @property string $consignee_tel_mask 收货人电话(掩码)
|
||||
* @property \Carbon\Carbon $created_at 创建时间
|
||||
* @property \Carbon\Carbon $updated_at 修改时间
|
||||
* @property-read OrderPrescription $OrderPrescription
|
||||
* @property-read \Hyperf\Database\Model\Collection|OrderPrescriptionIcd[] $OrderPrescriptionIcd
|
||||
* @property-read \Hyperf\Database\Model\Collection|OrderProductItem[] $OrderProductItem
|
||||
* @property-read PatientFamily $PatientFamily
|
||||
* @property-read OrderPrescription|null $OrderPrescription
|
||||
* @property-read \Hyperf\Database\Model\Collection|OrderPrescriptionIcd[]|null $OrderPrescriptionIcd
|
||||
* @property-read \Hyperf\Database\Model\Collection|OrderProductItem[]|null $OrderProductItem
|
||||
* @property-read PatientFamily|null $PatientFamily
|
||||
*/
|
||||
class OrderProduct extends Model
|
||||
{
|
||||
@ -71,7 +72,7 @@ class OrderProduct extends Model
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'doctor_id', 'patient_id', 'family_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'is_delete', 'cancel_reason', 'amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'logistics_company_code', 'sub_logistics_status', 'delivery_time', 'pay_time', 'remarks', 'refund_status', 'cancel_time', 'cancel_remarks', 'report_pre_status', 'report_pre_time', 'report_pre_fail_reason', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at'];
|
||||
protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'doctor_id', 'patient_id', 'family_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'is_delete', 'cancel_reason', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'logistics_company_code', 'sub_logistics_status', 'delivery_time', 'pay_time', 'remarks', 'refund_status', 'cancel_time', 'cancel_remarks', 'report_pre_status', 'report_pre_time', 'report_pre_fail_reason', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "order_product_id";
|
||||
|
||||
|
||||
67
app/Model/OrderProductCoupon.php
Normal file
67
app/Model/OrderProductCoupon.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $order_coupon_id 主键id
|
||||
* @property int $order_product_id 订单-商品id
|
||||
* @property int $user_coupon_id 用户优惠卷表id
|
||||
* @property string $coupon_name 优惠卷名称
|
||||
* @property string $coupon_use_price 优惠卷使用金额
|
||||
* @property \Carbon\Carbon $created_at 创建时间
|
||||
* @property \Carbon\Carbon $updated_at 修改时间
|
||||
*/
|
||||
class OrderProductCoupon extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'order_product_coupon';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['order_coupon_id', 'order_product_id', 'user_coupon_id', 'coupon_name', 'coupon_use_price', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "order_coupon_id";
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息-多条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getList(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param array $data
|
||||
* @return OrderProductCoupon|\Hyperf\Database\Model\Model
|
||||
*/
|
||||
public static function addOrderProductCoupon(array $data): \Hyperf\Database\Model\Model|OrderProductCoupon
|
||||
{
|
||||
return self::create($data);
|
||||
}
|
||||
}
|
||||
@ -122,4 +122,34 @@ class UserCoupon extends Model
|
||||
->where($params)
|
||||
->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取患者购药可用的优惠卷
|
||||
* @param string|int $user_id 用户id
|
||||
* @param array $coupon_product_datas
|
||||
* @param array $fields 字段
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getUserProductUsableCoupon(string|int $user_id,array $coupon_product_datas,array $fields = ['*']): Collection|array
|
||||
{
|
||||
$params = array();
|
||||
$params[] = ['user_id', '=', $user_id];
|
||||
$params[] = ['user_coupon_status', '=', 0];// 状态(0:未使用 1:已使用 3:已过期)
|
||||
$params[] = ['valid_start_time', '<', date('Y-m-d H:i:s', time())]; // 有效使用时间
|
||||
$params[] = ['valid_end_time', '>', date('Y-m-d H:i:s', time())]; // 过期使用时间
|
||||
|
||||
return self::with(['Coupon'=> function($query) use($coupon_product_datas){
|
||||
$query->where("coupon_client",1)
|
||||
->where("coupon_status",1)
|
||||
->where("application_scope",2)
|
||||
->whereIn("application_scope",[1,3,4,5])
|
||||
->where(function ($query) use ($coupon_product_datas) {
|
||||
foreach ($coupon_product_datas as $coupon_product_data){
|
||||
$query->orwhere("product_id","like",'%' . $coupon_product_data['product_id'] . '%');
|
||||
}
|
||||
});
|
||||
}])
|
||||
->where($params)
|
||||
->get($fields);
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,14 +156,13 @@ class InquiryService extends BaseService
|
||||
// 获取问诊价格
|
||||
$DoctorInquiryService = new DoctorInquiryService();
|
||||
$inquiry_price = $DoctorInquiryService->getDoctorInquiryPrice($request_params['inquiry_type'], $request_params['inquiry_mode'], $request_params['doctor_id'] ?: "");
|
||||
|
||||
if ($inquiry_price > 0) {
|
||||
// 获取患者问诊可用的优惠卷
|
||||
$userCouponService = new UserCouponService();
|
||||
$user_coupon = $userCouponService->getUserInquiryUsableCoupon($user_info['user_id'], $request_params['inquiry_type']);
|
||||
$user_coupons = $userCouponService->getUserInquiryUsableCoupon($user_info['user_id'], $request_params['inquiry_type']);
|
||||
|
||||
// 获取可用优惠卷总金额
|
||||
$coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupon);
|
||||
$coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupons);
|
||||
}
|
||||
|
||||
// 确定支付渠道
|
||||
@ -266,17 +265,29 @@ class InquiryService extends BaseService
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
}
|
||||
|
||||
// 增加问诊优惠卷表
|
||||
if (!empty($user_coupon)) {
|
||||
$data = array();
|
||||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_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_inquiry_coupon = OrderInquiryCoupon::addOrderInquiryCoupon($data);
|
||||
if (empty($order_inquiry_coupon)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
// 处理优惠卷数据
|
||||
if (!empty($user_coupons)) {
|
||||
foreach ($user_coupons as $user_coupon){
|
||||
// 增加问诊优惠卷表
|
||||
$data = array();
|
||||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_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_inquiry_coupon = OrderInquiryCoupon::addOrderInquiryCoupon($data);
|
||||
if (empty($order_inquiry_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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -313,17 +324,6 @@ class InquiryService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
// 修改优惠卷使用状态
|
||||
if (!empty($user_coupon)) {
|
||||
$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'] = $order_inquiry['inquiry_no'];
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Model\Product;
|
||||
use App\Model\UserCoupon;
|
||||
|
||||
/**
|
||||
@ -70,7 +71,11 @@ class UserCouponService extends BaseService
|
||||
return $selected_coupons;
|
||||
}
|
||||
|
||||
// 获取可用优惠卷总金额
|
||||
/**
|
||||
* 获取可用优惠卷总金额
|
||||
* @param array $coupons 优惠卷数据
|
||||
* @return int
|
||||
*/
|
||||
public function getCouponTotalPrice(array $coupons): int
|
||||
{
|
||||
$coupon_total_price = 0;
|
||||
@ -81,4 +86,127 @@ class UserCouponService extends BaseService
|
||||
|
||||
return $coupon_total_price;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取患者购药可用的优惠卷
|
||||
* @param string|int $user_id
|
||||
* @param array $coupon_product_datas
|
||||
* @return array
|
||||
*/
|
||||
public function getUserProductUsableCoupon(string|int $user_id, array $coupon_product_datas): array
|
||||
{
|
||||
$user_coupons = UserCoupon::getUserProductUsableCoupon($user_id,$coupon_product_datas);
|
||||
if (empty($user_coupons)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// 选中的优惠卷
|
||||
$selected_coupons = array();
|
||||
|
||||
// 优惠卷最高金额
|
||||
$coupon_high_price = 0;
|
||||
|
||||
// 是否存在互斥卷
|
||||
$is_mutex = 0;
|
||||
|
||||
// 新增字段
|
||||
foreach ($user_coupons as $key => $coupon) {
|
||||
$user_coupons[$key]['is_can_use'] = 1;// 是否可使用
|
||||
$user_coupons[$key]['cannot_use_coupon_reason'] = ""; // 不可使用原因
|
||||
}
|
||||
|
||||
foreach ($user_coupons as $key => $coupon) {
|
||||
// 处理优惠卷数量限制问题
|
||||
if ($coupon['coupon_type'] == 3 && !empty($coupon['product_id'])){
|
||||
// 数量是否足够标识字段
|
||||
$quantity_quantity = 0;
|
||||
|
||||
foreach ($coupon_product_datas as $coupon_product_data){
|
||||
// 如该优惠卷不包含此商品,跳过
|
||||
if (!str_contains($coupon['product_id'], $coupon_product_data['product_id'])){
|
||||
continue;
|
||||
}
|
||||
|
||||
// 判断商品数量是否满足
|
||||
if($coupon['min_usable_number'] > $coupon_product_data['product_num']){
|
||||
continue;
|
||||
}
|
||||
|
||||
// 标记为数量足够
|
||||
$quantity_quantity = 1;
|
||||
}
|
||||
|
||||
if ($quantity_quantity == 0){
|
||||
// 此优惠卷无商品能达到规定最小数量
|
||||
$user_coupons[$key]['is_can_use'] = 0;
|
||||
$user_coupons[$key]['cannot_use_coupon_reason'] = "商品不足" . $coupon['min_usable_number'] . "盒,不满足使用优惠卷条件";
|
||||
}
|
||||
}
|
||||
|
||||
// 处理满减金额问题
|
||||
if ($coupon['coupon_type'] == 2 && !empty($coupon['product_id'])){
|
||||
// 可共用一个优惠卷的商品金额问题
|
||||
$product_price = 0;
|
||||
|
||||
foreach ($coupon_product_datas as $coupon_product_data) {
|
||||
// 如该优惠卷不包含此商品,跳过
|
||||
if (!str_contains($coupon['product_id'], $coupon_product_data['product_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$product_price = bcadd($product_price,$coupon_product_data['product_price'],2);
|
||||
}
|
||||
|
||||
if ($coupon['with_amount'] > $product_price){
|
||||
// 此优惠卷因商品金额不足,无法使用
|
||||
$user_coupons[$key]['is_can_use'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 判断品牌是否符合-暂无品牌
|
||||
}
|
||||
|
||||
// 可选择优惠卷中是否存在互斥卷
|
||||
foreach ($user_coupons as $coupon) {
|
||||
if ($coupon['is_can_use'] == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($coupon['is_mutex'] == 1) {
|
||||
$is_mutex = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理存在互斥卷情况
|
||||
foreach ($user_coupons as $coupon) {
|
||||
if (empty($selected_coupon)) {
|
||||
$selected_coupons[] = $coupon; // 选中的优惠卷数据
|
||||
|
||||
$coupon_high_price = $coupon['coupon_price'];
|
||||
continue;
|
||||
}
|
||||
|
||||
// 处理存在互斥卷情况
|
||||
if ($is_mutex == 1) {
|
||||
// 选择金额最高的为选中
|
||||
if ($coupon['coupon_price'] < $coupon_high_price){
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($coupon['coupon_price'] > $coupon_high_price) {
|
||||
$coupon_high_price = $coupon['coupon_price'];
|
||||
|
||||
// 选中的优惠卷数据置空
|
||||
$selected_coupons = array();
|
||||
$selected_coupons[] = $coupon;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$selected_coupons[] = $coupon; // 选中的优惠卷数据
|
||||
}
|
||||
|
||||
return $selected_coupons;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user