|
@@ -546,7 +546,7 @@ class GoodsController extends Curd
|
|
|
|
|
|
$params['order_config_json'] = json_encode($orderConfigJson);
|
|
|
// 写入订单
|
|
|
- $this->insertMain($params,$premises);
|
|
|
+ $this->insertMain($params);
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
@@ -589,7 +589,6 @@ class GoodsController extends Curd
|
|
|
public function insertConstitute(Request $request): Response
|
|
|
{
|
|
|
$params = $request->post();
|
|
|
- // 判断餐品是否连带着服务或实体
|
|
|
$goodsClassifys = array_unique(array_column($params['goodsContentList'], 'goods_classify'));
|
|
|
$premises = [];
|
|
|
if (!empty($params['dept_premises_id'])) {
|
|
@@ -614,7 +613,7 @@ class GoodsController extends Curd
|
|
|
$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');
|
|
|
-
|
|
|
+ // 验证金额
|
|
|
$constituteAmount = 0;
|
|
|
foreach ($params['pay_category_constitute_list'] as $item) {
|
|
|
$constituteAmount = sprintf("%.2f", $constituteAmount) + sprintf("%.2f", $item['amount']);
|
|
@@ -677,16 +676,14 @@ class GoodsController extends Curd
|
|
|
$systemStatus = 'SENDING'; // 待发货
|
|
|
// 立即结算
|
|
|
if ($params['settlement_now'] == 'Y') {
|
|
|
- if (in_array($params['goods_classify'], ['MEALS', 'VIP'])) {
|
|
|
- $params['order_is_complete'] = 'Y';
|
|
|
- $systemStatus = 'DONE';
|
|
|
- }
|
|
|
if (in_array($params['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE']) && $params['delivery'] == 'ARRIVAL') {
|
|
|
$params['order_is_complete'] = 'N';
|
|
|
$systemStatus = "WAITING";
|
|
|
}
|
|
|
}
|
|
|
$params['pay_detail_item'] = [];
|
|
|
+ $waitToPayAccount = [];
|
|
|
+ $wxAndAliPayStatus = 'Y';
|
|
|
if (!empty($params['pay_category_constitute']) && in_array('OFFLINE', $params['pay_category_constitute'])) { // 线下支付
|
|
|
$params['order_status_system'] = $systemStatus;
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
@@ -732,25 +729,31 @@ class GoodsController extends Curd
|
|
|
if ($params['pay_constitute'] == 'N' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
throw new BusinessException("账户余额不足");
|
|
|
}
|
|
|
- if ($params['pay_constitute'] == 'Y' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
- $qrcodePayAmount = $params['order_amount_pay'] - $amount;
|
|
|
- $params['order_amount_pay'] = $amount;
|
|
|
- }
|
|
|
- if ($params['order_amount_pay'] > $account->member_account_surplus) {
|
|
|
- $cut = $account->member_account_added - ($params['order_amount_pay'] - $account->member_account_surplus);
|
|
|
- $account->member_account_surplus = 0;
|
|
|
- $account->member_account_added = $cut;
|
|
|
- } else {
|
|
|
- $account->member_account_surplus = $account->member_account_surplus - $params['order_amount_pay'];
|
|
|
- }
|
|
|
- $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
|
|
|
- $account->save();
|
|
|
+// if ($params['pay_constitute'] == 'Y' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
+// $qrcodePayAmount = $params['order_amount_pay'] - $amount;
|
|
|
+// $params['order_amount_pay'] = $amount;
|
|
|
+// }
|
|
|
+// if ($params['order_amount_pay'] > $account->member_account_surplus) {
|
|
|
+// $cut = $account->member_account_added - ($params['order_amount_pay'] - $account->member_account_surplus);
|
|
|
+// $account->member_account_surplus = 0;
|
|
|
+// $account->member_account_added = $cut;
|
|
|
+// } else {
|
|
|
+// $account->member_account_surplus = $account->member_account_surplus - $params['order_amount_pay'];
|
|
|
+// }
|
|
|
+// $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
|
|
|
+// $account->save();
|
|
|
+ // 余额账户扣款数据
|
|
|
+ $params['waitToPayAccount']['cash'] = [
|
|
|
+ 'group_id' => $params['orderGroupId'],
|
|
|
+ 'member_id' => $params['join_order_member_id'],
|
|
|
+ 'amount' => $constituteList['CASH'],
|
|
|
+ 'nbr' => $params['join_order_member_id'] . '-CASH'
|
|
|
+ ];
|
|
|
|
|
|
$params['order_status_system'] = $systemStatus;
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
|
|
|
// 生成支付记录
|
|
|
-// OrderService::createPayDetail($params);
|
|
|
$params['pay_detail_item'][] = $params;
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
|
|
@@ -777,27 +780,32 @@ class GoodsController extends Curd
|
|
|
if ($params['pay_constitute'] == 'N' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
throw new BusinessException("储值卡账户余额不足");
|
|
|
}
|
|
|
- if ($params['pay_constitute'] == 'Y' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
- $qrcodePayAmount = $params['order_amount_pay'] - $amount;
|
|
|
- $params['order_amount_pay'] = $amount;
|
|
|
- }
|
|
|
-
|
|
|
- if ($params['order_amount_pay'] > $account->member_account_surplus) {
|
|
|
- $cut = $account->member_account_added - ($params['order_amount_pay'] - $account->member_account_surplus);
|
|
|
- $account->member_account_surplus = 0;
|
|
|
- $account->member_account_added = $cut;
|
|
|
- } else {
|
|
|
- $account->member_account_surplus = $account->member_account_surplus - $params['order_amount_pay'];
|
|
|
- }
|
|
|
- $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
|
|
|
- $account->save();
|
|
|
-
|
|
|
+// if ($params['pay_constitute'] == 'Y' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
+// $qrcodePayAmount = $params['order_amount_pay'] - $amount;
|
|
|
+// $params['order_amount_pay'] = $amount;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if ($params['order_amount_pay'] > $account->member_account_surplus) {
|
|
|
+// $cut = $account->member_account_added - ($params['order_amount_pay'] - $account->member_account_surplus);
|
|
|
+// $account->member_account_surplus = 0;
|
|
|
+// $account->member_account_added = $cut;
|
|
|
+// } else {
|
|
|
+// $account->member_account_surplus = $account->member_account_surplus - $params['order_amount_pay'];
|
|
|
+// }
|
|
|
+// $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
|
|
|
+// $account->save();
|
|
|
+ // 储值卡账户扣款数据
|
|
|
+ $params['waitToPayAccount']['card'] = [
|
|
|
+ 'group_id' => $params['orderGroupId'],
|
|
|
+ 'member_id' => $params['join_order_member_id'],
|
|
|
+ 'amount' => $constituteList['CARD'],
|
|
|
+ 'nbr' => $params['join_order_member_id'] . '-CARD'
|
|
|
+ ];
|
|
|
|
|
|
$params['order_status_system'] = $systemStatus;
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
// 生成支付记录
|
|
|
$params['pay_detail_item'][] = $params;
|
|
|
-// OrderService::createPayDetail($params);
|
|
|
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
}
|
|
@@ -818,6 +826,8 @@ class GoodsController extends Curd
|
|
|
if (in_array($prefix, [10, 11, 12, 13, 14, 15])) {
|
|
|
$params['pay_category'] = 'WXPAY';
|
|
|
if ((!isset($result['return_code']) || $result['return_code'] != 'SUCCESS') || (!isset($result['result_code']) || $result['result_code'] != 'SUCCESS') || (empty($result['trade_state']) || $result['trade_state'] != 'SUCCESS')) {
|
|
|
+ // 标记支付状态
|
|
|
+ $wxAndAliPayStatus = 'N';
|
|
|
$params['order_status_system'] = 'PAYING';
|
|
|
$params['order_status_payment'] = 'PENDING';
|
|
|
$params['order_is_complete'] = 'N';
|
|
@@ -830,6 +840,8 @@ class GoodsController extends Curd
|
|
|
} else if (in_array($prefix, [25, 26, 27, 28, 29, 30])) {
|
|
|
$params['pay_category'] = 'ALIPAY';
|
|
|
if ((!isset($result['code']) || $result['code'] != '10000') || (empty($result['trade_status']) || $result['trade_status'] != 'TRADE_SUCCESS')) {
|
|
|
+ // 标记支付状态
|
|
|
+ $wxAndAliPayStatus = 'N';
|
|
|
$params['order_status_system'] = 'PAYING';
|
|
|
$params['order_status_payment'] = 'PENDING';
|
|
|
$params['order_is_complete'] = 'N';
|
|
@@ -862,7 +874,7 @@ class GoodsController extends Curd
|
|
|
}
|
|
|
$params['order_config_json'] = json_encode($orderConfigJson);
|
|
|
// 写入订单
|
|
|
- $this->insertMain($params, $premises);
|
|
|
+ $this->insertMain($params, $wxAndAliPayStatus);
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
@@ -880,20 +892,18 @@ class GoodsController extends Curd
|
|
|
}
|
|
|
$this->changeOrderCouponStatus($couponUseJson, 'WAITING');
|
|
|
|
|
|
- return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
|
|
|
+ return json_throw(2001, '支付异常', ['order_id' => $params['orderId'], 'group_id' => $params['orderGroupId']]);
|
|
|
}
|
|
|
_syslog("订单", "创建订单成功");
|
|
|
return json_success('创建订单成功');
|
|
|
} catch (BusinessException $e) {
|
|
|
Db::rollBack();
|
|
|
dump($e->getMessage());
|
|
|
- dump($e->getTrace());
|
|
|
_syslog("订单", $e->getMessage());
|
|
|
return json_fail($e->getMessage());
|
|
|
} catch (\Exception $e) {
|
|
|
Db::rollBack();
|
|
|
dump($e->getMessage());
|
|
|
- dump($e->getTrace());
|
|
|
_syslog("订单", "创建订单失败");
|
|
|
return json_fail('创建订单失败');
|
|
|
}
|
|
@@ -1243,9 +1253,6 @@ class GoodsController extends Curd
|
|
|
$orderConfigJson = json_decode($order->order_config_json, true);
|
|
|
}
|
|
|
$orderConfigJson['preferential'] = $params['preferential'] ?? '';
|
|
|
- if (isset($orderConfigJson['tableid']) && !empty($orderConfigJson['tableid'])) {
|
|
|
- SysDept::where('dept_id', $orderConfigJson['tableid'])->where('dept_category', '桌台')->update(['dept_status' => 'ACTIVED']);
|
|
|
- }
|
|
|
$order->order_config_json = json_encode($orderConfigJson);
|
|
|
$order->order_amount_pay = $params['order_amount_pay'] + $qrcodePayAmount;
|
|
|
// 主订单
|
|
@@ -1302,27 +1309,6 @@ class GoodsController extends Curd
|
|
|
|
|
|
$writeOffDate = [];
|
|
|
$applyData = [];
|
|
|
- // 有预约单,状态已完成
|
|
|
- $appointment = Appointment::where('join_appointment_order_id', $params['order_id'])->first();
|
|
|
- if ($order->order_status_payment == 'SUCCESS' && $appointment) {
|
|
|
- $writeOffDate = OrderService::generateWriteOffData($params);
|
|
|
- $applyData = OrderService::generateAppointmentApplyData($params);
|
|
|
-
|
|
|
- $appointment->appointment_status = 'DONE';
|
|
|
- $appointment->appointment_done_datetime = date('Y-m-d H:i:s');
|
|
|
- $appointment->appointment_done_json = json_encode($writeOffDate);
|
|
|
- if (empty($appointment->appointment_apply_datetime)) {
|
|
|
- $appointment->appointment_apply_datetime = date('Y-m-d H:i:s');
|
|
|
- }
|
|
|
- if (empty($appointment->appointment_apply_json)) {
|
|
|
- $appointment->appointment_apply_json = json_encode($applyData);
|
|
|
- }
|
|
|
- if (empty($appointment->appointment_datetime)) {
|
|
|
- $appointment->appointment_datetime = date('Y-m-d');
|
|
|
- }
|
|
|
-
|
|
|
- $appointment->save();
|
|
|
- }
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
@@ -1333,9 +1319,9 @@ class GoodsController extends Curd
|
|
|
// 会员升级
|
|
|
Event::dispatch('order_pay.member_level.up', $params['join_order_member_id']);
|
|
|
}
|
|
|
- if($order->order_status_payment == 'SUCCESS'){
|
|
|
+ if ($order->order_status_payment == 'SUCCESS') {
|
|
|
// 上级提成
|
|
|
- Event::dispatch('commission.order',$params);
|
|
|
+ Event::dispatch('commission.order', $params);
|
|
|
}
|
|
|
|
|
|
// 打小票
|
|
@@ -1370,7 +1356,7 @@ class GoodsController extends Curd
|
|
|
$this->changeOrderCouponStatus($couponUseJson, 'WAITING');
|
|
|
}
|
|
|
|
|
|
- return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
|
|
|
+ return json_throw(2001, '支付异常', ['order_id' => $params['orderId'], 'group_id' => $params['orderGroupId']]);
|
|
|
}
|
|
|
_syslog("订单", "订单支付成功");
|
|
|
return json_success('支付成功');
|
|
@@ -1496,7 +1482,11 @@ class GoodsController extends Curd
|
|
|
if (sprintf("%.2f", $params['order_amount_pay']) != sprintf("%.2f", $constituteAmount)) {
|
|
|
throw new BusinessException('组合支付金额与应付金额不一致');
|
|
|
}
|
|
|
- $params['pay_detail_item'] = [];
|
|
|
+
|
|
|
+ $wxAndAliPayStatus = 'Y';
|
|
|
+ $waitToPayAccount = [];
|
|
|
+ // 清除订单的支付记录,重建
|
|
|
+ PayDetail::whereJsonContains('join_pay_object_json->order_id', $params['orderId'])->delete();
|
|
|
if (!empty($params['pay_category_constitute']) && in_array('OFFLINE', $params['pay_category_constitute'])) { //线下付款
|
|
|
$order->order_status_system = $systemStatus;
|
|
|
$order->order_status_payment = 'SUCCESS';
|
|
@@ -1506,9 +1496,9 @@ class GoodsController extends Curd
|
|
|
if (isset($constituteList['OFFLINE'])) {
|
|
|
$params['order_amount_pay'] = $constituteList['OFFLINE'];
|
|
|
// 生成支付记录
|
|
|
- OrderService::createPayConstituteDetail($params, $payDetail);
|
|
|
+ $params['order_status_payment'] = 'PENDING';
|
|
|
+ OrderService::createProductPayConstituteDetail($params);
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
- $params['pay_detail_item'][] = $params;
|
|
|
}
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
}
|
|
@@ -1521,9 +1511,9 @@ class GoodsController extends Curd
|
|
|
if (isset($constituteList['MONEY'])) {
|
|
|
$params['order_amount_pay'] = $constituteList['MONEY'];
|
|
|
// 生成支付记录
|
|
|
- OrderService::createPayConstituteDetail($params, $payDetail);
|
|
|
+ $params['order_status_payment'] = 'PENDING';
|
|
|
+ OrderService::createProductPayConstituteDetail($params);
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
- $params['pay_detail_item'][] = $params;
|
|
|
}
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
}
|
|
@@ -1543,23 +1533,17 @@ class GoodsController extends Curd
|
|
|
if ($params['pay_constitute'] == 'N' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
throw new BusinessException('账户余额不足');
|
|
|
}
|
|
|
- if ($params['pay_constitute'] == 'Y' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
- $qrcodePayAmount = $params['order_amount_pay'] - $amount;
|
|
|
- $params['order_amount_pay'] = $amount;
|
|
|
- }
|
|
|
- if ($params['order_amount_pay'] > $account->member_account_surplus) {
|
|
|
- $cut = $account->member_account_added - ($params['order_amount_pay'] - $account->member_account_surplus);
|
|
|
- $account->member_account_surplus = 0;
|
|
|
- $account->member_account_added = $cut;
|
|
|
- } else {
|
|
|
- $account->member_account_surplus = $account->member_account_surplus - $params['order_amount_pay'];
|
|
|
- }
|
|
|
- $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
|
|
|
- $account->save();
|
|
|
+ // 余额账户扣款数据
|
|
|
+ $waitToPayAccount['cash'] = [
|
|
|
+ 'group_id' => $params['orderGroupId'],
|
|
|
+ 'member_id' => $params['join_order_member_id'],
|
|
|
+ 'amount' => $constituteList['CASH'],
|
|
|
+ 'nbr' => $params['join_order_member_id'] . '-CASH'
|
|
|
+ ];
|
|
|
// 生成支付记录
|
|
|
- OrderService::createPayConstituteDetail($params, $payDetail);
|
|
|
+ $params['order_status_payment'] = 'PENDING';
|
|
|
+ OrderService::createProductPayConstituteDetail($params);
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
- $params['pay_detail_item'][] = $params;
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
$order->order_status_system = $systemStatus;
|
|
|
$order->order_status_payment = 'SUCCESS';
|
|
@@ -1586,23 +1570,17 @@ class GoodsController extends Curd
|
|
|
if ($params['pay_constitute'] == 'N' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
throw new BusinessException('账户余额不足');
|
|
|
}
|
|
|
- if ($params['pay_constitute'] == 'Y' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
- $qrcodePayAmount = $params['order_amount_pay'] - $amount;
|
|
|
- $params['order_amount_pay'] = $amount;
|
|
|
- }
|
|
|
- if ($params['order_amount_pay'] > $account->member_account_surplus) {
|
|
|
- $cut = $account->member_account_added - ($params['order_amount_pay'] - $account->member_account_surplus);
|
|
|
- $account->member_account_surplus = 0;
|
|
|
- $account->member_account_added = $cut;
|
|
|
- } else {
|
|
|
- $account->member_account_surplus = $account->member_account_surplus - $params['order_amount_pay'];
|
|
|
- }
|
|
|
- $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
|
|
|
- $account->save();
|
|
|
+ // 储值卡账户扣款数据
|
|
|
+ $waitToPayAccount['card'] = [
|
|
|
+ 'group_id' => $params['orderGroupId'],
|
|
|
+ 'member_id' => $params['join_order_member_id'],
|
|
|
+ 'amount' => $constituteList['CARD'],
|
|
|
+ 'nbr' => $params['join_order_member_id'] . '-CARD'
|
|
|
+ ];
|
|
|
// 生成支付记录
|
|
|
- OrderService::createPayConstituteDetail($params, $payDetail);
|
|
|
+ $params['order_status_payment'] = 'PENDING';
|
|
|
+ OrderService::createProductPayConstituteDetail($params);
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
- $params['pay_detail_item'][] = $params;
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
$order->order_status_system = $systemStatus;
|
|
|
$order->order_status_payment = 'SUCCESS';
|
|
@@ -1621,26 +1599,30 @@ class GoodsController extends Curd
|
|
|
if (in_array($prefix, [10, 11, 12, 13, 14, 15])) {
|
|
|
$params['pay_category'] = 'WXPAY';
|
|
|
if ((!isset($result['return_code']) || $result['return_code'] != 'SUCCESS') || (!isset($result['result_code']) || $result['result_code'] != 'SUCCESS') || (empty($result['trade_state']) || $result['trade_state'] != 'SUCCESS')) {
|
|
|
+ // 标记支付状态
|
|
|
+ $wxAndAliPayStatus = 'N';
|
|
|
$order->order_status_system = 'PAYING';
|
|
|
$order->order_status_payment = 'PENDING';
|
|
|
$order->order_is_complete = 'N';
|
|
|
-// Db::rollBack();
|
|
|
-// return json_fail('支付失败');
|
|
|
+ $params['order_status_payment'] = 'PAYING';
|
|
|
} else {
|
|
|
$order->order_status_system = $systemStatus;
|
|
|
$order->order_status_payment = 'SUCCESS';
|
|
|
+ $params['order_status_payment'] = 'SUCCESS';
|
|
|
}
|
|
|
} else if (in_array($prefix, [25, 26, 27, 28, 29, 30])) {
|
|
|
$params['pay_category'] = 'ALIPAY';
|
|
|
if ((!isset($result['code']) || $result['code'] != '10000') || (empty($result['trade_status']) || $result['trade_status'] != 'TRADE_SUCCESS')) {
|
|
|
+ // 标记支付状态
|
|
|
+ $wxAndAliPayStatus = 'N';
|
|
|
$order->order_status_system = 'PAYING';
|
|
|
$order->order_status_payment = 'PENDING';
|
|
|
$order->order_is_complete = 'N';
|
|
|
-// Db::rollBack();
|
|
|
-// return json_fail('支付失败');
|
|
|
+ $params['order_status_payment'] = 'PAYING';
|
|
|
} else {
|
|
|
$order->order_status_system = $systemStatus;
|
|
|
$order->order_status_payment = 'SUCCESS';
|
|
|
+ $params['order_status_payment'] = 'SUCCESS';
|
|
|
}
|
|
|
} else {
|
|
|
throw new BusinessException('付款码无效');
|
|
@@ -1648,7 +1630,7 @@ class GoodsController extends Curd
|
|
|
}
|
|
|
|
|
|
// 生成支付记录
|
|
|
- OrderService::createPayConstituteDetail($params, $payDetail);
|
|
|
+ OrderService::createProductPayConstituteDetail($params);
|
|
|
// 账户支付的金额
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
}
|
|
@@ -1657,9 +1639,6 @@ class GoodsController extends Curd
|
|
|
$orderConfigJson = json_decode($order->order_config_json, true);
|
|
|
}
|
|
|
$orderConfigJson['preferential'] = $params['preferential'] ?? '';
|
|
|
- if (isset($orderConfigJson['tableid']) && !empty($orderConfigJson['tableid'])) {
|
|
|
- SysDept::where('dept_id', $orderConfigJson['tableid'])->where('dept_category', '桌台')->update(['dept_status' => 'ACTIVED']);
|
|
|
- }
|
|
|
$order->order_config_json = json_encode($orderConfigJson);
|
|
|
$order->order_amount_pay = $params['order_amount_pay'];
|
|
|
|
|
@@ -1671,35 +1650,27 @@ class GoodsController extends Curd
|
|
|
'order_sheet_status' => $systemStatus,
|
|
|
]);
|
|
|
}
|
|
|
- // 清除paydetail 中的未支付记录
|
|
|
- PayDetail::where('join_pay_order_id', $params['orderGroupId'])
|
|
|
- ->whereJsonContains('join_pay_object_json->order_id', $params['order_id'])
|
|
|
- ->where('pay_status', '<>', 'SUCCESS')
|
|
|
- ->delete();
|
|
|
-
|
|
|
- $writeOffDate = [];
|
|
|
- $applyData = [];
|
|
|
- // 有预约单,状态已完成
|
|
|
- $appointment = Appointment::where('join_appointment_order_id', $params['order_id'])->first();
|
|
|
- if ($order->order_status_payment == 'SUCCESS' && $appointment) {
|
|
|
- $writeOffDate = OrderService::generateWriteOffData($params);
|
|
|
- $applyData = OrderService::generateAppointmentApplyData($params);
|
|
|
|
|
|
- $appointment->appointment_status = 'DONE';
|
|
|
- $appointment->appointment_done_datetime = date('Y-m-d H:i:s');
|
|
|
- $appointment->appointment_done_json = json_encode($writeOffDate);
|
|
|
- if (empty($appointment->appointment_apply_datetime)) {
|
|
|
- $appointment->appointment_apply_datetime = date('Y-m-d H:i:s');
|
|
|
- }
|
|
|
- if (empty($appointment->appointment_apply_json)) {
|
|
|
- $appointment->appointment_apply_json = json_encode($applyData);
|
|
|
- }
|
|
|
- if (empty($appointment->appointment_datetime)) {
|
|
|
- $appointment->appointment_datetime = date('Y-m-d');
|
|
|
+ if ($wxAndAliPayStatus == 'Y') {
|
|
|
+ PayDetail::whereJsonContains('join_pay_object_json->order_id', $params['orderId'])->update([
|
|
|
+ 'pay_status' => 'SUCCESS',
|
|
|
+ 'pay_paytimes' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+ // 扣款
|
|
|
+ foreach ($waitToPayAccount as $item) {
|
|
|
+ $accountNbr = $item['nbr'];
|
|
|
+ $account = MemberAccount::where('member_account_nbr', $accountNbr)->first();
|
|
|
+ $account->member_account_expend = $account->member_account_expend + $amount;
|
|
|
+ if ($account->member_account_surplus < $amount && strpos($accountNbr, 'CASH') !== false) {
|
|
|
+ $account->member_account_added = $account->member_account_added - ($amount - $account->member_account_surplus);
|
|
|
+ $account->member_account_surplus = 0;
|
|
|
+ } else {
|
|
|
+ $account->member_account_surplus = $account->member_account_surplus - $amount;
|
|
|
+ }
|
|
|
+ $account->save();
|
|
|
}
|
|
|
-
|
|
|
- $appointment->save();
|
|
|
}
|
|
|
+
|
|
|
Db::commit();
|
|
|
// 触发事件
|
|
|
if ($order->order_is_complete == 'Y' && $order->order_status_payment == 'SUCCESS') {
|
|
@@ -1708,9 +1679,9 @@ class GoodsController extends Curd
|
|
|
// 会员升级
|
|
|
Event::dispatch('order_pay.member_level.up', $params['join_order_member_id']);
|
|
|
}
|
|
|
- if($order->order_status_payment == 'SUCCESS'){
|
|
|
+ if ($order->order_status_payment == 'SUCCESS') {
|
|
|
// 上级提成
|
|
|
- Event::dispatch('commission.order',$params);
|
|
|
+ Event::dispatch('commission.order', $params);
|
|
|
}
|
|
|
|
|
|
// 打小票
|
|
@@ -1746,7 +1717,7 @@ class GoodsController extends Curd
|
|
|
// 清除支付记录,恢复账户金额
|
|
|
// $this->restoreAccount($params['pay_detail_item']);
|
|
|
|
|
|
- return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
|
|
|
+ return json_throw(2001, '支付异常', ['order_id' => $params['orderId'], 'group_id' => $params['orderGroupId']]);
|
|
|
}
|
|
|
_syslog("订单", "订单支付成功");
|
|
|
return json_success('支付成功');
|
|
@@ -1758,31 +1729,6 @@ class GoodsController extends Curd
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function restoreAccount($payDetailItem)
|
|
|
- {
|
|
|
- foreach ($payDetailItem as $item) {
|
|
|
- $prepayId = '';
|
|
|
- if ($item['order_status_payment'] == 'SUCCESS') {
|
|
|
- if (in_array($item['pay_category'], ['MONEY', 'OFFLINE', 'OFFLINE_ALIPAY', 'OFFLINE_WXPAY'])) {
|
|
|
- $prepayId = $item['pay_category'];
|
|
|
- }
|
|
|
- if (strpos($item['pay_category'],'CASH') !== false || strpos($item['pay_category'],'CARD') !== false || strpos($item['pay_category'],'WELFARE') !== false || strpos($item['pay_category'],'VIP') !== false){
|
|
|
- $prepayId = $item['pay_category'];
|
|
|
- $account = MemberAccount::where('member_account_nbr', $prepayId)->first();
|
|
|
- $account->member_account_expend = $account->member_account_expend - $item['order_amount_pay'];
|
|
|
- $account->member_account_surplus = $account->member_account_surplus + $item['order_amount_pay'];
|
|
|
- $account->save();
|
|
|
- }
|
|
|
- }
|
|
|
- if (!empty($prepayId)) {
|
|
|
- PayDetail::where('pay_prepayid', $prepayId)
|
|
|
- ->where('join_pay_order_id', $item['orderGroupId'])
|
|
|
- ->whereJsonContains('join_pay_object_json->order_id',$item['orderId'])
|
|
|
- ->update(['pay_status' => 'WAITING']);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @Desc
|
|
|
* @Author Gorden
|
|
@@ -1792,7 +1738,7 @@ class GoodsController extends Curd
|
|
|
* @return void
|
|
|
* @throws BusinessException
|
|
|
*/
|
|
|
- public function insertMain($params,$premises)
|
|
|
+ public function insertMain($params, $wxAndAliPayStatus = 'Y')
|
|
|
{
|
|
|
try {
|
|
|
if (empty($params['order_extend_json'])) {
|
|
@@ -1802,6 +1748,12 @@ class GoodsController extends Curd
|
|
|
$params['order_extend_json'] = json_decode($params['order_extend_json'], true);
|
|
|
}
|
|
|
}
|
|
|
+ // 账户扣款
|
|
|
+ if ($wxAndAliPayStatus == 'Y' && !empty($params['waitToPayAccount'])) {
|
|
|
+ foreach ($params['waitToPayAccount'] as $account) {
|
|
|
+ $this->deductAmount($account['nbr'], $account['amount']);
|
|
|
+ }
|
|
|
+ }
|
|
|
// 推荐人
|
|
|
$params['order_extend_json']['referee'] = $params['referee'] ?? '';
|
|
|
foreach ($params['goodsContentList'] as $goods) {
|
|
@@ -1848,8 +1800,6 @@ class GoodsController extends Curd
|
|
|
$params['order_express_goods'] = json_encode(['sheet' => $sheetIds]);
|
|
|
|
|
|
$this->insertExpressOne($params, $orderId);
|
|
|
- // 打小票
|
|
|
-// $this->printerTicket($params, $premises, $orderId);
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
dump($e->getMessage());
|
|
@@ -1857,6 +1807,35 @@ class GoodsController extends Curd
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @Desc 扣除账户金额
|
|
|
+ * @Author Gorden
|
|
|
+ * @Date 2024/9/26 14:16
|
|
|
+ *
|
|
|
+ * @param $accountNbr
|
|
|
+ * @param $amount
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function deductAmount($accountNbr, $amount)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $account = MemberAccount::where('member_account_nbr', $accountNbr)->first();
|
|
|
+ $account->member_account_expend = $account->member_account_expend + $amount;
|
|
|
+ if ($account->member_account_surplus < $amount && strpos($accountNbr, 'CASH') !== false) {
|
|
|
+ $account->member_account_added = $account->member_account_added - ($amount - $account->member_account_surplus);
|
|
|
+ $account->member_account_surplus = 0;
|
|
|
+ } else {
|
|
|
+ $account->member_account_surplus = $account->member_account_surplus - $amount;
|
|
|
+ }
|
|
|
+
|
|
|
+ $account->save();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ _syslog("下单扣款", "扣款失败");
|
|
|
+
|
|
|
+ throw new BusinessException("账户扣款失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @Desc 打小票
|
|
|
* @Author Gorden
|
|
@@ -1889,6 +1868,7 @@ class GoodsController extends Curd
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* @Desc
|
|
|
* @Author Gorden
|