|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace app\admin\controller\order;
|
|
|
|
|
|
+use app\admin\service\coupon\CouponService;
|
|
|
use app\admin\service\member\MemberService;
|
|
|
use app\admin\service\order\OrderService;
|
|
|
use app\admin\validate\coupon\CouponValidate;
|
|
@@ -207,7 +208,7 @@ class WholeController extends Curd
|
|
|
$item['sheet'] = $item['sheets'][0] ?? [];
|
|
|
if (!empty($item['sheet'])) {
|
|
|
$goods = Goods::where('goods_id', $item['sheet']['join_sheet_goods_id'])->first();
|
|
|
- if (count($item['sheets']) > 1 && $goods->goods_classify == 'MEALS') {
|
|
|
+ if (count($item['sheets']) > 1 && !empty($goods) && $goods->goods_classify == 'MEALS') {
|
|
|
$sheetDeng = ' 等餐品';
|
|
|
}
|
|
|
$item['sheet']['goods_name'] = ($goods && $goods->goods_name) ? $goods->goods_name . $sheetDeng : '';
|
|
@@ -245,7 +246,7 @@ class WholeController extends Curd
|
|
|
} else {
|
|
|
$item['payWay'] = null;
|
|
|
}
|
|
|
- if (isset($item['payWay']) && $item['order_status_payment'] == 'SUCCESS') {
|
|
|
+ if (!empty($item['payWay']) && $item['order_status_payment'] == 'SUCCESS') {
|
|
|
$payWay = explode('-', $item['payWay']);
|
|
|
if (!empty($payWay[1]) && $payWay[1] == 'CASH') {
|
|
|
$item['payWay'] = '账户余额';
|
|
@@ -255,6 +256,10 @@ class WholeController extends Curd
|
|
|
$item['payWay'] = '付款码';
|
|
|
} else if (!empty($payWay[0]) && $payWay[0] == 'OFFLINE') {
|
|
|
$item['payWay'] = '线下支付';
|
|
|
+ } else if (!empty($payWay[0]) && $payWay[0] == 'OFFLINE_ALIPAY') {
|
|
|
+ $item['payWay'] = '线下支付-支付宝';
|
|
|
+ } else if (!empty($payWay[0]) && $payWay[0] == 'OFFLINE_WXPAY') {
|
|
|
+ $item['payWay'] = '线下支付-微信';
|
|
|
} else if (!empty($payWay[0]) && $payWay[0] == 'WXPAY') {
|
|
|
$item['payWay'] = '微信支付';
|
|
|
} else if (!empty($payWay[0]) && $payWay[0] == 'ALIPAY') {
|
|
@@ -311,13 +316,6 @@ class WholeController extends Curd
|
|
|
if ($express && $express->order_express_type == '自提') {
|
|
|
$premises = $express->order_express_company;
|
|
|
}
|
|
|
- // if (!empty($express->order_express_code)){
|
|
|
- // $expressCode = explode(':',$express->order_express_code);
|
|
|
- // if(count($expressCode) == 2){
|
|
|
- // $express->order_express_company = $expressCode[0];
|
|
|
- // $express->order_express_code = $expressCode[1];
|
|
|
- // }
|
|
|
- // }
|
|
|
$sheetAmount = 0;
|
|
|
foreach ($orderSheet as &$item) {
|
|
|
$sheetAmount += $item['order_sheet_amount'];
|
|
@@ -417,42 +415,6 @@ class WholeController extends Curd
|
|
|
'appointment_status' => $appontment['appointment_status'],
|
|
|
];
|
|
|
}
|
|
|
- // $benifits = MemberBenefit::where('join_benefit_member_id', $item['join_sheet_member_id'])
|
|
|
- // ->where('join_benefit_order_id', $orderId)
|
|
|
- // ->get();
|
|
|
- // if (!empty($benifits)) {
|
|
|
- // $item['appontment'] = [];
|
|
|
- // foreach($benifits as $benifit){
|
|
|
- // $item['benefit'] = [
|
|
|
- // 'total' => intval($benifit->member_benefit_limit_count),
|
|
|
- // 'used' => intval($benifit->member_benefit_used_count),
|
|
|
- // 'cut' => $benifit->member_benefit_limit_count - $benifit->member_benefit_used_count,
|
|
|
- // ];
|
|
|
- // $appontments = Appointment::where('join_appointment_member_benefit_id', $benifit->member_benefit_id)
|
|
|
- // ->where('appointment_status', 'DONE')
|
|
|
- // ->select('appointment_id', 'appointment_done_datetime', 'appointment_done_json')
|
|
|
- // ->get()
|
|
|
- // ->toArray();
|
|
|
- // foreach ($appontments as $appontment) {
|
|
|
- // $doneJson = [];
|
|
|
- // $username = '';
|
|
|
- // if (!empty($appontment['appointment_done_json'])) {
|
|
|
- // $doneJson = json_decode($appontment['appointment_done_json'], true);
|
|
|
- // if (isset($doneJson['charge'])) {
|
|
|
- // $username = SysUser::where('user_id', $doneJson['charge']['charge_user_id'])->value('user_name');
|
|
|
- // }
|
|
|
- // }
|
|
|
- // $item['appontment'][] = [
|
|
|
- // 'member' => ($item['cert'] ? $item['cert']['member_cert_name'] . '-' : '') . ($item['member'] ? $item['member']['member_mobile'] : ''),
|
|
|
- // 'goods_name' => $item['goods']['goods_name'].'-'.$benifit->member_benefit_name,
|
|
|
- // 'premisses' => isset($doneJson['charge']) ? $doneJson['charge']['charge_premises'] : '',
|
|
|
- // 'username' => $username,
|
|
|
- // 'nbr' => 1,
|
|
|
- // 'done_time' => $appontment['appointment_done_datetime']
|
|
|
- // ];
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
}
|
|
|
if (!empty($item['order_sheet_extend_json']) && !$express) {
|
|
|
$extendJson = json_decode($item['order_sheet_extend_json'], true);
|
|
@@ -488,27 +450,16 @@ class WholeController extends Curd
|
|
|
$payDetail = !empty($payDetails) && count($payDetails) > 0 ? $payDetails[0] : [];
|
|
|
if (!empty($payDetail) && !empty($payDetail->pay_extend_json)) {
|
|
|
$payExtendJson = json_decode($payDetail->pay_extend_json, true);
|
|
|
- $payDetail->cancel_times = $payExtendJson['cancel_times'] ?? '';
|
|
|
+ $order->cancel_times = $payExtendJson['cancel_times'] ?? '';
|
|
|
+// $payDetail->cancel_times = $payExtendJson['cancel_times'] ?? '';
|
|
|
}
|
|
|
if (!empty($payDetail) && !empty($payDetail->pay_prepayid)) {
|
|
|
$categoryArray = explode('-', $payDetail->pay_prepayid);
|
|
|
if (isset($categoryArray[1])) {
|
|
|
$payDetail->pay_category = $categoryArray[1];
|
|
|
- } else if (in_array($categoryArray[0], ['WXPAY', 'ALIPAY'])) {
|
|
|
- $payDetail->pay_category = $categoryArray[0];
|
|
|
- } else if ($categoryArray[0] == 'OFFLINE') {
|
|
|
+ } else if (in_array($categoryArray[0], ['WXPAY', 'ALIPAY', 'OFFLINE', 'OFFLINE_ALIPAY', 'OFFLINE_WXPAY', 'MONEY'])) {
|
|
|
$payDetail->pay_category = $categoryArray[0];
|
|
|
- } else if ($categoryArray[0] == 'MONEY') {
|
|
|
- $payDetail->pay_category = $categoryArray[0];
|
|
|
- } else {
|
|
|
- if (MemberAccount::where('member_account_nbr', $categoryArray[0])->where('member_account_classify', 'CARD')->exists()) {
|
|
|
- $payDetail->pay_category = 'CARD';
|
|
|
- } else {
|
|
|
- $payDetail->pay_category = 'CASH';
|
|
|
- }
|
|
|
}
|
|
|
- } else if (!empty($payDetail)) {
|
|
|
- $payDetail->pay_category = 'CASH';
|
|
|
}
|
|
|
$refund = OrderReturn::where('join_return_order_id', $orderId)
|
|
|
->select('order_return_status', 'order_return_apply_datetime', 'order_return_apply_json', 'order_return_accept_datetime', 'order_return_refund_json', 'order_return_extend_json')
|
|
@@ -547,7 +498,39 @@ class WholeController extends Curd
|
|
|
if (!empty($order->order_extend_json)) {
|
|
|
$orderExtendJson = json_decode($order->order_extend_json, true);
|
|
|
$order->referee = $orderExtendJson['referee'] ?? '';
|
|
|
+ if (isset($orderExtendJson['cancel_times'])){
|
|
|
+ $order->cancel_times = $orderExtendJson['cancel_times'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $discount = ['coupon_name' => '', 'classify' => '', 'value' => 0];
|
|
|
+ if (!empty($order->order_discount_json)) {
|
|
|
+ $orderDiscountJson = json_decode($order->order_discount_json, true);
|
|
|
+ foreach ($orderDiscountJson as $discountItem) {
|
|
|
+ if (!empty($discountItem['coupon_id'])) {
|
|
|
+ $coupon = Coupon::where('coupon_id', $discountItem['coupon_id'])
|
|
|
+ ->select('coupon_name', 'coupon_classify', 'coupon_category', 'coupon_value', 'coupon_minimum_limit')
|
|
|
+ ->first();
|
|
|
+ if (!$coupon) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $classify = CouponService::couponClassifyInfo($coupon->coupon_classify, $coupon->coupon_category, $coupon->coupon_value, $coupon->coupon_minimum_limit);
|
|
|
+ $discount['coupon_name'] .= $coupon->coupon_classify . ':' . $coupon->coupon_name . '(优惠¥' . $discountItem['coupon_value'] . '), ';
|
|
|
+ }
|
|
|
+ if (empty($discountItem['coupon_id']) && !empty($discountItem['coupon_classify'])) {
|
|
|
+ $discount['classify'] .= $discountItem['coupon_classify'] . '(¥' . round($discountItem['coupon_value'], 2) . '), ';
|
|
|
+ }
|
|
|
+ if (!empty($discountItem['coupon_value'])) {
|
|
|
+ $discount['value'] += $discountItem['coupon_value'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($discount['coupon_name'])) {
|
|
|
+ $discount['coupon_name'] = rtrim($discount['coupon_name'], ', ');
|
|
|
+ }
|
|
|
+ if (!empty($discount['classify'])) {
|
|
|
+ $discount['classify'] = rtrim($discount['classify'], ', ');
|
|
|
+ }
|
|
|
}
|
|
|
+ $order->discount = $discount;
|
|
|
|
|
|
$order->premises = $order->premises ?? $premises;
|
|
|
$data = [
|
|
@@ -776,6 +759,9 @@ class WholeController extends Curd
|
|
|
$orderConfigJson = json_decode($order->order_config_json, true);
|
|
|
if (isset($orderConfigJson['premises'])) {
|
|
|
$premises = SysDept::where('dept_name', $orderConfigJson['premises'])->first();
|
|
|
+ if (!empty($premises)) {
|
|
|
+ $params['submit_premises_id'] = $premises->dept_id;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
$params['orderId'] = $params['order_id'];
|
|
@@ -799,14 +785,32 @@ class WholeController extends Curd
|
|
|
}
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
+ // 使用优惠券
|
|
|
+ $couponUseJson = [];
|
|
|
+ if (!empty($params['join_order_member_id']) && !empty($params['preferential'])) {
|
|
|
+ $couponResult = OrderService::payUseCoupon($params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
|
|
|
+ if ($couponResult['pay_amount'] != $params['order_amount_pay']) {
|
|
|
+ throw new BusinessException("计算优惠后,实付金额错误!");
|
|
|
+ }
|
|
|
+ // 组装优惠券使用数据,存主表优惠里
|
|
|
+ $couponUseJson = $couponResult['use_coupon_json'];
|
|
|
+ if (!empty($order->order_discount_json)) {
|
|
|
+ $orderDiscountJson = json_decode($order->order_discount_json, true);
|
|
|
+ if (!empty($orderDiscountJson)) {
|
|
|
+ $couponUseJson = json_encode(array_merge($orderDiscountJson, json_decode($couponUseJson, true)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
// 存储优惠信息
|
|
|
- $order->order_discount_json = json_encode($this->discountRecord($order->order_discount_json, $params));
|
|
|
-
|
|
|
+ $order->order_discount_json = json_encode($this->discountRecord($couponUseJson, $params));
|
|
|
// 组合支付时,付款码应收金额
|
|
|
$qrcodePayAmount = 0;
|
|
|
if ($params['pay_category'] == 'OFFLINE' || $params['pay_category'] == 'MONEY') {
|
|
|
$order->order_status_system = $systemStatus;
|
|
|
$order->order_status_payment = 'SUCCESS';
|
|
|
+ if ($params['pay_category'] == 'OFFLINE' && !empty($params['pay_category_sub'])) {
|
|
|
+ $params['pay_category'] = $params['pay_category_sub'];
|
|
|
+ }
|
|
|
} else if ($params['pay_category'] == 'CASH') { // 余额支付
|
|
|
$account = MemberAccount::where('join_account_member_id', $params['join_order_member_id'])
|
|
|
->where('member_account_classify', 'CASH')
|
|
@@ -1083,6 +1087,10 @@ class WholeController extends Curd
|
|
|
$payData['pay_prepayid'] = $params['card_nbr'];
|
|
|
} else if ($params['pay_category'] == 'OFFLINE') {
|
|
|
$payData['pay_prepayid'] = 'OFFLINE';
|
|
|
+ } else if ($params['pay_category'] == 'OFFLINE_ALIPAY') {
|
|
|
+ $payData['pay_prepayid'] = 'OFFLINE_ALIPAY';
|
|
|
+ } else if ($params['pay_category'] == 'OFFLINE_WXPAY') {
|
|
|
+ $payData['pay_prepayid'] = 'OFFLINE_WXPAY';
|
|
|
} else if ($params['pay_category'] == 'MONEY') {
|
|
|
$payData['pay_prepayid'] = 'MONEY';
|
|
|
}
|
|
@@ -1166,6 +1174,10 @@ class WholeController extends Curd
|
|
|
Event::dispatch('order.kangyangCityVIP.grant', $params);
|
|
|
}
|
|
|
|
|
|
+ if ($order->order_is_complete == 'Y') {
|
|
|
+ Event::dispatch('order.complete', $params);
|
|
|
+ }
|
|
|
+
|
|
|
Db::commit();
|
|
|
|
|
|
// 打小票
|
|
@@ -1224,18 +1236,18 @@ class WholeController extends Curd
|
|
|
$json = json_decode($orderDiscountJson, true);
|
|
|
}
|
|
|
try {
|
|
|
- if (!empty($params['preferential']) && $params['preferential'] == 'wipe') {
|
|
|
+ if (!empty($params['preferential']) && in_array('wipe', $params['preferential'])) {
|
|
|
if (intval($params['order_amount_total'] / 10) * 10 != $params['order_amount_pay']) {
|
|
|
throw new BusinessException("抹零后实际支付金额错误");
|
|
|
}
|
|
|
$params['order_discount_amount'] = $params['order_amount_total'] - $params['order_amount_pay'];
|
|
|
$couponClassifyDesc = $couponClassify = '抹零';
|
|
|
- } else if (!empty($params['preferential']) && $params['preferential'] == 'custom') {
|
|
|
+ } elseif (!empty($params['preferential']) && in_array('custom', $params['preferential'])) {
|
|
|
if (sprintf("%.2f", $params['order_amount_total'] - $params['order_discount_amount']) != sprintf("%.2f", $params['order_amount_pay'])) {
|
|
|
throw new BusinessException("餐厅前台优惠后实际支付金额错误");
|
|
|
}
|
|
|
$couponClassifyDesc = $couponClassify = '餐厅前台优惠';
|
|
|
- } else if (!empty($params['preferential']) && intval($params['preferential']) < 100 && intval($params['preferential']) >= 50) {
|
|
|
+ } else if (!empty($params['preferential']) && intval($params['preferential'][0]) < 100 && intval($params['preferential'][0]) >= 50) {
|
|
|
if (($params['order_amount_total'] * intval($params['preferential'])) / 100 !== $params['order_amount_pay']) {
|
|
|
throw new BusinessException("折扣后实际支付金额错误");
|
|
|
}
|
|
@@ -1302,6 +1314,9 @@ class WholeController extends Curd
|
|
|
$orderConfigJson = json_decode($order->order_config_json, true);
|
|
|
if (isset($orderConfigJson['premises'])) {
|
|
|
$premises = SysDept::where('dept_name', $orderConfigJson['premises'])->first();
|
|
|
+ if (!empty($premises)) {
|
|
|
+ $params['submit_premises_id'] = $premises->dept_id;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
$params['orderId'] = $params['order_id'];
|
|
@@ -1325,9 +1340,24 @@ class WholeController extends Curd
|
|
|
}
|
|
|
$payDetail = PayDetail::where('join_pay_order_id', $order->order_groupby)->first();
|
|
|
Db::beginTransaction();
|
|
|
- try {
|
|
|
+ try {// 使用优惠券
|
|
|
+ $couponUseJson = [];
|
|
|
+ if (!empty($params['join_order_member_id']) && !empty($params['preferential'])) {
|
|
|
+ $couponResult = OrderService::payUseCoupon($params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
|
|
|
+ if ($couponResult['pay_amount'] != $params['order_amount_pay']) {
|
|
|
+ throw new BusinessException("计算优惠后,实付金额错误!");
|
|
|
+ }
|
|
|
+ // 组装优惠券使用数据,存主表优惠里
|
|
|
+ $couponUseJson = $couponResult['use_coupon_json'];
|
|
|
+ if (!empty($order->order_discount_json)) {
|
|
|
+ $orderDiscountJson = json_decode($order->order_discount_json, true);
|
|
|
+ if (!empty($orderDiscountJson)) {
|
|
|
+ $couponUseJson = json_encode(array_merge($orderDiscountJson, json_decode($couponUseJson, true)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
// 存储优惠信息
|
|
|
- $order->order_discount_json = json_encode($this->discountRecord($order->order_discount_json, $params));
|
|
|
+ $order->order_discount_json = json_encode($this->discountRecord($couponUseJson, $params));
|
|
|
$orderAmountPay = $params['order_amount_pay'];
|
|
|
$constituteList = array_column($params['pay_category_constitute_list'], 'amount', 'category');// 验证金额
|
|
|
$constituteAmount = 0;
|
|
@@ -1340,7 +1370,7 @@ class WholeController extends Curd
|
|
|
if (!empty($params['pay_category_constitute']) && in_array('OFFLINE', $params['pay_category_constitute'])) { //线下付款
|
|
|
$order->order_status_system = $systemStatus;
|
|
|
$order->order_status_payment = 'SUCCESS';
|
|
|
- $params['pay_category'] = 'OFFLINE';
|
|
|
+ $params['pay_category'] = $params['pay_category_sub'] ?? 'OFFLINE';
|
|
|
|
|
|
// 线下支付金额
|
|
|
if (isset($constituteList['OFFLINE'])) {
|
|
@@ -1350,7 +1380,7 @@ class WholeController extends Curd
|
|
|
}
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
}
|
|
|
- if (!empty($params['pay_category_constitute']) && in_array('MONEY', $params['pay_category_constitute'])) { //线下付款
|
|
|
+ if (!empty($params['pay_category_constitute']) && in_array('MONEY', $params['pay_category_constitute'])) { //现金付款
|
|
|
$order->order_status_system = $systemStatus;
|
|
|
$order->order_status_payment = 'SUCCESS';
|
|
|
$params['pay_category'] = 'MONEY';
|
|
@@ -1534,6 +1564,17 @@ class WholeController extends Curd
|
|
|
|
|
|
$appointment->save();
|
|
|
}
|
|
|
+
|
|
|
+ // 2.4W 康养城
|
|
|
+ if ($params['goods_classify'] == 'VIP' && $order->order_status_payment == 'SUCCESS') {
|
|
|
+ $params['member_id'] = $params['join_order_member_id'];
|
|
|
+ Event::dispatch('order.kangyangCityVIP.grant', $params);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($order->order_is_complete == 'Y') {
|
|
|
+ Event::dispatch('order.complete', $params);
|
|
|
+ }
|
|
|
+
|
|
|
Db::commit();
|
|
|
|
|
|
// 打小票
|
|
@@ -1676,6 +1717,13 @@ class WholeController extends Curd
|
|
|
SysDept::where('dept_id', $orderConfigJson['tableid'])->update(['dept_status' => 'ACTIVED']);
|
|
|
}
|
|
|
}
|
|
|
+ // 主表存取消时间吧
|
|
|
+ $orderExtendJson = [];
|
|
|
+ if (!empty($order->order_extend_json)) {
|
|
|
+ $orderExtendJson = json_decode($order->order_extend_json, true);
|
|
|
+ }
|
|
|
+ $orderExtendJson['cancel_times'] = date('Y-m-d H:i:s');
|
|
|
+ $order->order_extend_json = json_encode($orderExtendJson, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
|
$order->order_is_complete = 'Y';
|
|
|
$order->order_status_system = 'CANCEL';
|
|
@@ -1710,8 +1758,18 @@ class WholeController extends Curd
|
|
|
$params['goods_classify'] = $goodsClassifys[0];
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
+ // 使用优惠券
|
|
|
+ $couponUseJson = [];
|
|
|
+ if (!empty($params['join_order_member_id']) && !empty($params['preferential'])) {
|
|
|
+ $couponResult = OrderService::payUseCoupon($params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
|
|
|
+ if ($couponResult['pay_amount'] != $params['order_amount_pay']) {
|
|
|
+ throw new BusinessException("计算优惠后,实付金额错误!");
|
|
|
+ }
|
|
|
+ // 组装优惠券使用数据,存主表优惠里
|
|
|
+ $couponUseJson = $couponResult['use_coupon_json'];
|
|
|
+ }
|
|
|
// 存储优惠信息
|
|
|
- $params['order_discount_json'] = json_encode($this->discountRecord([], $params));
|
|
|
+ $params['order_discount_json'] = json_encode($this->discountRecord($couponUseJson, $params));
|
|
|
// 验证库存
|
|
|
foreach ($params['goodsContentList'] as $goods) {
|
|
|
// 减库存,规格和总库存
|
|
@@ -1780,13 +1838,16 @@ class WholeController extends Curd
|
|
|
$systemStatus = 'SENDING'; // 待发货
|
|
|
// 立即结算
|
|
|
if ($params['settlement_now'] == 'Y') {
|
|
|
- $params['order_is_complete'] = 'Y';
|
|
|
if (in_array($params['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'MEALS', 'VIP'])) {
|
|
|
+ $params['order_is_complete'] = 'Y';
|
|
|
$systemStatus = 'DONE';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if ($params['settlement_now'] == 'Y' && ($params['pay_category'] == 'OFFLINE' || $params['pay_category'] == 'MONEY')) {
|
|
|
+ if ($params['pay_category'] == 'OFFLINE' && !empty($params['pay_category_sub'])) {
|
|
|
+ $params['pay_category'] = $params['pay_category_sub'];
|
|
|
+ }
|
|
|
$params['order_status_system'] = $systemStatus;
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
} else if ($params['settlement_now'] == 'Y' && $params['pay_category'] == 'CASH') { // 余额支付
|
|
@@ -2176,6 +2237,9 @@ class WholeController extends Curd
|
|
|
$params['member_id'] = $params['join_order_member_id'];
|
|
|
Event::dispatch('order.kangyangCityVIP.grant', $params);
|
|
|
}
|
|
|
+ if (!empty($params['order_is_complete']) && $params['order_is_complete'] == 'Y') {
|
|
|
+ Event::dispatch('order.complete', $params);
|
|
|
+ }
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
@@ -2274,8 +2338,18 @@ class WholeController extends Curd
|
|
|
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
+ // 使用优惠券
|
|
|
+ $couponUseJson = [];
|
|
|
+ if (!empty($params['join_order_member_id']) && !empty($params['preferential'])) {
|
|
|
+ $couponResult = OrderService::payUseCoupon($params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
|
|
|
+ if ($couponResult['pay_amount'] != $params['order_amount_pay']) {
|
|
|
+ throw new BusinessException("计算优惠后,实付金额错误!");
|
|
|
+ }
|
|
|
+ // 组装优惠券使用数据,存主表优惠里
|
|
|
+ $couponUseJson = $couponResult['use_coupon_json'];
|
|
|
+ }
|
|
|
// 存储优惠信息
|
|
|
- $params['order_discount_json'] = json_encode($this->discountRecord([], $params));
|
|
|
+ $params['order_discount_json'] = json_encode($this->discountRecord($couponUseJson, $params));
|
|
|
$orderAmountPay = $params['order_amount_pay'];
|
|
|
$constituteList = array_column($params['pay_category_constitute_list'], 'amount', 'category');
|
|
|
// 验证金额
|
|
@@ -2344,7 +2418,7 @@ class WholeController extends Curd
|
|
|
if (!empty($params['pay_category_constitute']) && in_array('OFFLINE', $params['pay_category_constitute'])) { // 线下支付
|
|
|
$params['order_status_system'] = $systemStatus;
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
- $params['pay_category'] = 'OFFLINE';
|
|
|
+ $params['pay_category'] = $params['pay_category_sub'] ?? 'OFFLINE';
|
|
|
|
|
|
// 线下支付金额
|
|
|
if (isset($constituteList['OFFLINE'])) {
|
|
@@ -2668,6 +2742,10 @@ class WholeController extends Curd
|
|
|
Event::dispatch('order.kangyangCityVIP.grant', $params);
|
|
|
}
|
|
|
|
|
|
+ if (!empty($params['order_is_complete']) && $params['order_is_complete'] == 'Y') {
|
|
|
+ Event::dispatch('order.complete', $params);
|
|
|
+ }
|
|
|
+
|
|
|
Db::commit();
|
|
|
|
|
|
// 打小票
|
|
@@ -2895,6 +2973,10 @@ class WholeController extends Curd
|
|
|
$payPrepayid = $params['pay_category'];
|
|
|
} else if ($params['pay_category'] == 'OFFLINE') {
|
|
|
$payPrepayid = 'OFFLINE';
|
|
|
+ } else if ($params['pay_category'] == 'OFFLINE_ALIPAY') {
|
|
|
+ $payPrepayid = 'OFFLINE_ALIPAY';
|
|
|
+ } else if ($params['pay_category'] == 'OFFLINE_WXPAY') {
|
|
|
+ $payPrepayid = 'OFFLINE_WXPAY';
|
|
|
} else if ($params['pay_category'] == 'MONEY') {
|
|
|
$payPrepayid = 'MONEY';
|
|
|
} else {
|
|
@@ -4091,7 +4173,7 @@ class WholeController extends Curd
|
|
|
} elseif ($item['order_is_complete'] == 'R') {
|
|
|
$systemStatus = '售后已完成';
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if ($item['order_is_complete'] != 'R' && !empty($item['order_return_status']) && $item['order_return_status'] == 'PENDING') {
|
|
|
$systemStatus = '待处理';
|
|
|
} elseif ($item['order_is_complete'] != 'R' && !empty($item['order_return_status']) && $item['order_return_status'] == 'DOING') {
|
|
@@ -4101,16 +4183,20 @@ class WholeController extends Curd
|
|
|
} elseif ($item['order_is_complete'] != 'R' && !empty($item['order_return_status']) && $item['order_return_status'] == 'DISAGREE') {
|
|
|
$systemStatus = '不同意退款';
|
|
|
}
|
|
|
+
|
|
|
$payDetails = PayDetail::where('join_pay_order_id', $item['order_groupby'])
|
|
|
->where('pay_status', 'SUCCESS')
|
|
|
- ->where('pay_category','<>','REFUND')
|
|
|
+ ->where('pay_category', '<>', 'REFUND')
|
|
|
->get()
|
|
|
->toArray();
|
|
|
if (count($payDetails) > 1) {
|
|
|
$payWay = '组合支付';
|
|
|
} elseif (count($payDetails) == 1) {
|
|
|
$payWayEn = OrderService::getPayWayByPrepayId($payDetails[0]['pay_prepayid']);
|
|
|
- $payWay = OrderService::$payWay[$payWayEn];
|
|
|
+ $payWay = '';
|
|
|
+ if (!empty($payWayEn)) {
|
|
|
+ $payWay = OrderService::$payWay[$payWayEn];
|
|
|
+ }
|
|
|
}
|
|
|
if ($item['member']['member_mobile'] == '0000') {
|
|
|
$memberName = '散客';
|
|
@@ -4250,7 +4336,39 @@ class WholeController extends Curd
|
|
|
Db::rollBack();
|
|
|
return json_fail('修改订单状态失败');
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ public function useCoupon(Request $request)
|
|
|
+ {
|
|
|
+ $goods = $request->post('goods', []);
|
|
|
+ $coupon = $request->post('coupon', []);
|
|
|
+ $payAmount = $request->post('pay_amount', 0);
|
|
|
+ $memberId = $request->post('member_id', '');
|
|
|
+ if (empty($goods) || empty($coupon) || empty($memberId)) {
|
|
|
+ return json_fail("参数异常");
|
|
|
+ }
|
|
|
+ foreach ($coupon as $item) {
|
|
|
+ if (!in_array(substr($item, 0, 2), ['CU', 'CO'])) {
|
|
|
+ return json_fail("参数异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $amountBalance = [
|
|
|
+ 'pay_amount' => $payAmount,
|
|
|
+ 'welfare_balance' => 0,
|
|
|
+ 'cut_balance' => 0,
|
|
|
+ ];
|
|
|
+ foreach ($goods as $good) {
|
|
|
+ $result = OrderService::chooseCoupon($memberId, $goods, $good, $coupon, $amountBalance);
|
|
|
+ $amountBalance = [
|
|
|
+ 'pay_amount' => $result['pay_amount'],
|
|
|
+ 'welfare_balance' => $result['welfare_balance'],
|
|
|
+ 'cut_balance' => $result['cut_balance'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ Redis::del("ORDER:USE:COUPON:" . $memberId);
|
|
|
|
|
|
+ return json_success("success", ['pay_amount' => $amountBalance['pay_amount']]);
|
|
|
}
|
|
|
|
|
|
public static $goodsClassify = [
|