|
@@ -174,12 +174,26 @@ class ServicesController extends Curd
|
|
|
'order_return_remark' => $item['order_return_remark']
|
|
|
];
|
|
|
}
|
|
|
+ $item['have_success_paydetail'] = 'N';
|
|
|
+ if (PayDetail::where('join_pay_order_id', $item['order_groupby'])
|
|
|
+ ->whereJsonContains('join_pay_object_json->order_id', $item['order_id'])
|
|
|
+ ->where('pay_status', 'SUCCESS')
|
|
|
+ ->exists()) {
|
|
|
+ $item['have_success_paydetail'] = 'Y';
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return $items;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * @Desc 下单+支付
|
|
|
+ * @Author Gorden
|
|
|
+ * @Date 2024/9/23 16:15
|
|
|
+ *
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
public function insert(Request $request): Response
|
|
|
{
|
|
|
$params = $request->post();
|
|
@@ -498,9 +512,9 @@ class ServicesController extends Curd
|
|
|
|
|
|
$orderConfigJson = [];
|
|
|
// 优惠
|
|
|
-// if (!empty($params['preferential'])) {
|
|
|
-// $orderConfigJson['preferential'] = $params['preferential'];
|
|
|
-// }
|
|
|
+ if (!empty($params['preferential'])) {
|
|
|
+ $orderConfigJson['preferential'] = $params['preferential'];
|
|
|
+ }
|
|
|
|
|
|
// 配送方式
|
|
|
if (isset($params['delivery']) && ($params['delivery'] == 'PICKUP' || $params['delivery'] == 'ARRIVAL')) { // 自提/ 到店
|
|
@@ -510,45 +524,14 @@ class ServicesController extends Curd
|
|
|
if (isset($params['delivery']) && in_array($params['delivery'], ['PICKUP', 'ARRIVAL']) && !empty($params['dept_premises_id'])) {
|
|
|
$params['submit_premises_id'] = $premises->dept_id;
|
|
|
}
|
|
|
-// if (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS' && !empty($params['dept_premises_id'])) {
|
|
|
-// $table = '';
|
|
|
-// if (!empty($params['dept_table_id'])) {
|
|
|
-// $table = SysDept::where('dept_id', $params['dept_table_id'])->where('dept_category', '桌台')->first();
|
|
|
-// }
|
|
|
-// $orderConfigJson['premises'] = $params['dept_premises_id'];
|
|
|
-// $orderConfigJson['dept'] = $premises->dept_id ?? 0;
|
|
|
-// $orderConfigJson['reach'] = "00:00";
|
|
|
-// $orderConfigJson['table'] = !empty($table) ? $table->dept_name : null;
|
|
|
-// $orderConfigJson['express'] = "到店吃";
|
|
|
-// $orderConfigJson['tableid'] = $params['dept_table_id'] ?? null;
|
|
|
-// if (!empty($params['eat'])) {
|
|
|
-// $orderConfigJson['eat'] = $params['eat'] ?? null;
|
|
|
-// }
|
|
|
-//
|
|
|
-// if ($params['settlement_now'] == 'N' && !empty($params['dept_table_id'])) {
|
|
|
-// // 桌台设为使用中
|
|
|
-// SysDept::where('dept_id', $params['dept_table_id'])->where('dept_category', '桌台')->update(['dept_status' => 'USING']);
|
|
|
-// }
|
|
|
-// }
|
|
|
|
|
|
$params['order_config_json'] = json_encode($orderConfigJson);
|
|
|
- // 写入主订单
|
|
|
+ // 写入订单
|
|
|
$this->insertMain($params);
|
|
|
- // 订单详情
|
|
|
-// $sheetId = $this->insertSheet($params);
|
|
|
- // 支付记录
|
|
|
-// $params['order_amount_pay'] = $params['order_amount_pay'] - $qrcodePayAmount;
|
|
|
-// $this->insertPayDetail($params);
|
|
|
-
|
|
|
|
|
|
// 买的单个服务
|
|
|
$writeOffDate = [];
|
|
|
$applyData = [];
|
|
|
- // 服务已完成,生成核销数据
|
|
|
-// if ($params['order_status_payment'] == 'SUCCESS' && in_array($goods['goods_classify'], ['SERVICE','CHNMED','CHNNCD', 'PACKAGE'])) {
|
|
|
-// $writeOffDate = OrderService::generateWriteOffData($params);
|
|
|
-// $applyData = OrderService::generateAppointmentApplyData($params);
|
|
|
-// }
|
|
|
if ($params['order_status_payment'] == 'SUCCESS') {
|
|
|
foreach ($params['goodsContentList'] as $goods) {
|
|
|
$params['join_sheet_goods_id'] = $goods['goods_id'];
|
|
@@ -598,12 +581,6 @@ class ServicesController extends Curd
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 2.4W 康养城
|
|
|
- if ($params['goods_classify'] == 'VIP' && $params['order_status_payment'] == 'SUCCESS') {
|
|
|
- $params['member_id'] = $params['join_order_member_id'];
|
|
|
- Event::dispatch('order.kangyangCityVIP.grant', $params);
|
|
|
- }
|
|
|
-
|
|
|
Db::commit();
|
|
|
|
|
|
// 会员升级
|
|
@@ -612,6 +589,26 @@ class ServicesController extends Curd
|
|
|
Event::dispatch('order_pay.member_level.up', $params['join_order_member_id']);
|
|
|
}
|
|
|
|
|
|
+ // 打小票
|
|
|
+ if ($params['order_status_payment'] == 'SUCCESS') {
|
|
|
+ if (!empty($premises) && !empty($premises->dept_id)) {
|
|
|
+ $voteData = [
|
|
|
+ 'func' => 'procActionToPrinter',
|
|
|
+ 'sign' => '',
|
|
|
+ 'data' => [
|
|
|
+ 'printer_premises' => $premises->dept_id,
|
|
|
+ 'printer_device' => ["收银"],
|
|
|
+ 'printer_action' => 'ExecPrintOrder',
|
|
|
+ 'printer_data' => [
|
|
|
+ 'order_id' => $params['orderId'],
|
|
|
+ 'order_batch' => ''
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+// dump("小票参数", $voteData);
|
|
|
+ http_post_json(getenv('VOTE_MENU_URL'), $voteData);
|
|
|
+ }
|
|
|
+ }
|
|
|
if ($params['settlement_now'] == 'Y' && $params['order_status_payment'] != 'SUCCESS') {
|
|
|
_syslog("订单", "支付异常,检查是否有轮询");
|
|
|
// 恢复优惠券到已占用
|
|
@@ -647,15 +644,6 @@ class ServicesController extends Curd
|
|
|
$params = $request->post();
|
|
|
// 判断餐品是否连带着服务或实体
|
|
|
$goodsClassifys = array_unique(array_column($params['goodsContentList'], 'goods_classify'));
|
|
|
- if (in_array('MEALS', $goodsClassifys) && count($goodsClassifys) > 1) {
|
|
|
- return json_fail('餐饮餐品不支持和其他类型的产品一起下单');
|
|
|
- }
|
|
|
- if (in_array('MEALS', $goodsClassifys)) {
|
|
|
- $params['submit_goods_classify'] = 'MEALS';
|
|
|
- }
|
|
|
- if (in_array('PACKAGE', $goodsClassifys)) {
|
|
|
- $params['submit_goods_classify'] = 'PACKAGE';
|
|
|
- }
|
|
|
if (!empty($params['dept_premises_id'])) {
|
|
|
$premises = SysDept::where('dept_name', $params['dept_premises_id'])->first();
|
|
|
}
|
|
@@ -690,7 +678,13 @@ class ServicesController extends Curd
|
|
|
// 验证库存
|
|
|
OrderService::checkGoodsStorage($params);
|
|
|
// 余额、福利、储值卡 验证短信
|
|
|
- if (!empty($params['pay_category_constitute']) && !in_array('OFFLINE', $params['pay_category_constitute']) && !in_array('MONEY', $params['pay_category_constitute']) && !in_array('QRCODE', $params['pay_category_constitute']) && (in_array('CASH', $params['pay_category_constitute']) || in_array('CARD', $params['pay_category_constitute']) || in_array('WELFARE', $params['pay_category_constitute']))) {
|
|
|
+ if (!empty($params['pay_category_constitute'])
|
|
|
+ && !in_array('OFFLINE', $params['pay_category_constitute'])
|
|
|
+ && !in_array('MONEY', $params['pay_category_constitute'])
|
|
|
+ && !in_array('QRCODE', $params['pay_category_constitute'])
|
|
|
+ && (in_array('CASH', $params['pay_category_constitute'])
|
|
|
+ || in_array('CARD', $params['pay_category_constitute'])
|
|
|
+ || in_array('WELFARE', $params['pay_category_constitute']))) {
|
|
|
$code = $params['sms_code'];
|
|
|
if (!$code) {
|
|
|
throw new BusinessException("验证码错误,请重新输入");
|
|
@@ -705,7 +699,9 @@ class ServicesController extends Curd
|
|
|
Redis::del($key);
|
|
|
}
|
|
|
// 验证线下付款密码
|
|
|
- if (!empty($params['pay_category_constitute']) && in_array('OFFLINE', $params['pay_category_constitute']) || in_array('MONEY', $params['pay_category_constitute'])) {
|
|
|
+ if (!empty($params['pay_category_constitute'])
|
|
|
+ && in_array('OFFLINE', $params['pay_category_constitute'])
|
|
|
+ || (in_array('MONEY', $params['pay_category_constitute']) && !in_array('QRCODE', $params['pay_category_constitute']))) {
|
|
|
$password = $params['offline_password'];
|
|
|
if ($password != '666888') {
|
|
|
throw new BusinessException("密码错误,请重新输入");
|
|
@@ -726,7 +722,6 @@ class ServicesController extends Curd
|
|
|
throw new BusinessException("检查下单账户");
|
|
|
}
|
|
|
|
|
|
- $qrcodePayAmount = 0;
|
|
|
$params['orderId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
|
|
|
$params['orderGroupId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
|
|
|
$params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
|
|
@@ -743,6 +738,7 @@ class ServicesController extends Curd
|
|
|
$systemStatus = "WAITING";
|
|
|
}
|
|
|
}
|
|
|
+ $params['pay_detail_item'] = [];
|
|
|
if (!empty($params['pay_category_constitute']) && in_array('OFFLINE', $params['pay_category_constitute'])) { // 线下支付
|
|
|
$params['order_status_system'] = $systemStatus;
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
@@ -752,7 +748,8 @@ class ServicesController extends Curd
|
|
|
if (isset($constituteList['OFFLINE'])) {
|
|
|
$params['order_amount_pay'] = $constituteList['OFFLINE'];
|
|
|
// 生成支付记录
|
|
|
- OrderService::createPayDetail($params);
|
|
|
+ $params['pay_detail_item'][] = $params;
|
|
|
+// OrderService::createPayDetail($params);
|
|
|
}
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
}
|
|
@@ -765,7 +762,8 @@ class ServicesController extends Curd
|
|
|
if (isset($constituteList['MONEY'])) {
|
|
|
$params['order_amount_pay'] = $constituteList['MONEY'];
|
|
|
// 生成支付记录
|
|
|
- OrderService::createPayDetail($params);
|
|
|
+ $params['pay_detail_item'][] = $params;
|
|
|
+// OrderService::createPayDetail($params);
|
|
|
}
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
}
|
|
@@ -804,7 +802,8 @@ class ServicesController extends Curd
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
|
|
|
// 生成支付记录
|
|
|
- OrderService::createPayDetail($params);
|
|
|
+// OrderService::createPayDetail($params);
|
|
|
+ $params['pay_detail_item'][] = $params;
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
|
|
|
}
|
|
@@ -849,7 +848,8 @@ class ServicesController extends Curd
|
|
|
$params['order_status_system'] = $systemStatus;
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
// 生成支付记录
|
|
|
- OrderService::createPayDetail($params);
|
|
|
+ $params['pay_detail_item'][] = $params;
|
|
|
+// OrderService::createPayDetail($params);
|
|
|
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
}
|
|
@@ -896,7 +896,8 @@ class ServicesController extends Curd
|
|
|
}
|
|
|
|
|
|
// 生成支付记录
|
|
|
- OrderService::createPayDetail($params);
|
|
|
+ $params['pay_detail_item'][] = $params;
|
|
|
+// OrderService::createPayDetail($params);
|
|
|
// 账户支付的金额
|
|
|
$params['order_amount_pay'] = $orderAmountPay;
|
|
|
}
|
|
@@ -907,85 +908,13 @@ class ServicesController extends Curd
|
|
|
if (!empty($params['preferential'])) {
|
|
|
$orderConfigJson['preferential'] = $params['preferential'];
|
|
|
}
|
|
|
-
|
|
|
- // 配送方式
|
|
|
- if (isset($params['delivery']) && ($params['delivery'] == 'PICKUP' || $params['delivery'] == 'ARRIVAL')) { // 自提/ 到店
|
|
|
- $orderConfigJson['premises'] = $params['dept_premises_id'];
|
|
|
- } else if (isset($params['delivery']) && $params['delivery'] == 'LOGISTICS') {
|
|
|
- // $params['order_express_json'] = json_encode([
|
|
|
- // 'express' => 'Y',
|
|
|
- // ]);
|
|
|
- }
|
|
|
- $params['order_amount_pay'] = $params['order_amount_pay'] + $qrcodePayAmount;
|
|
|
-
|
|
|
- if (isset($params['delivery']) && in_array($params['delivery'], ['PICKUP', 'ARRIVAL']) && !empty($params['dept_premises_id'])) {
|
|
|
- // $premises = SysDept::where('dept_name',$params['dept_premises_id'])->where('dept_category','营业场所')->first();
|
|
|
- if (!$premises) {
|
|
|
- throw new BusinessException("门店不存在,请重新选择");
|
|
|
- }
|
|
|
- $params['submit_premises_id'] = $premises->dept_id;
|
|
|
- }
|
|
|
- if (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS' && !empty($params['dept_table_id'])) {
|
|
|
- $table = SysDept::where('dept_id', $params['dept_table_id'])->where('dept_category', '桌台')->first();
|
|
|
- $orderConfigJson['premises'] = $params['dept_premises_id'];
|
|
|
- $orderConfigJson['dept'] = $premises->dept_id;
|
|
|
- $orderConfigJson['reach'] = "00:00";
|
|
|
- $orderConfigJson['table'] = !empty($table) ? $table->dept_name : null;
|
|
|
- $orderConfigJson['express'] = "堂食";
|
|
|
- $orderConfigJson['tableid'] = $params['dept_table_id'] ?? null;
|
|
|
- if (!empty($params['eat'])) {
|
|
|
- $orderConfigJson['eat'] = $params['eat'] ?? null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
$params['order_config_json'] = json_encode($orderConfigJson);
|
|
|
- // 写入主订单
|
|
|
+ // 写入订单
|
|
|
$this->insertMain($params);
|
|
|
- // 订单详情
|
|
|
- $sheetId = $this->insertSheet($params);
|
|
|
-
|
|
|
- $params['order_express_goods'] = json_encode(['sheet' => $sheetId]);
|
|
|
- if (isset($params['delivery']) && $params['delivery'] == 'LOGISTICS') {
|
|
|
- $params['order_express_type'] = '配送';
|
|
|
- // 入配送
|
|
|
- $this->saveExpress($params);
|
|
|
- } else if (isset($params['delivery']) && $params['delivery'] == 'PICKUP') {
|
|
|
- $params['order_express_type'] = '自提';
|
|
|
- if (!$premises) {
|
|
|
- throw new BusinessException('自提门店不存在');
|
|
|
- }
|
|
|
-
|
|
|
- $params['order_express_city'] = $premises->dept_city;
|
|
|
- $params['order_express_address'] = $premises->dept_address;
|
|
|
- $params['order_express_telephone'] = $premises->dept_telephone;
|
|
|
- $params['order_express_extend_json'] = json_encode(['pick_code' => random_string(4, 'number')]);
|
|
|
-
|
|
|
- $this->saveExpress($params);
|
|
|
- } else if ($params['delivery'] == 'ARRIVAL') {
|
|
|
- $premises = SysDept::where('dept_name', $params['dept_premises_id'])->first();
|
|
|
- $params['order_express_type'] = '到店';
|
|
|
- if (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS') {
|
|
|
- $params['order_express_type'] = '堂食';
|
|
|
- }
|
|
|
- if (!$premises) {
|
|
|
- throw new BusinessException('门店不存在');
|
|
|
- }
|
|
|
-
|
|
|
- $params['order_express_city'] = $premises->dept_city;
|
|
|
- $params['order_express_address'] = $premises->dept_address;
|
|
|
- $params['order_express_telephone'] = $premises->dept_telephone;
|
|
|
-
|
|
|
- $this->saveExpress($params);
|
|
|
- }
|
|
|
|
|
|
// 买的单个服务
|
|
|
$writeOffDate = [];
|
|
|
$applyData = [];
|
|
|
- // 服务已完成,生成核销数据
|
|
|
-// if ($params['order_status_payment'] == 'SUCCESS' && in_array($goods['goods_classify'], ['SERVICE','CHNMED','CHNNCD', 'PACKAGE'])) {
|
|
|
-// $writeOffDate = OrderService::generateWriteOffData($params);
|
|
|
-// $applyData = OrderService::generateAppointmentApplyData($params);
|
|
|
-// }
|
|
|
if ($params['order_status_payment'] == 'SUCCESS') {
|
|
|
foreach ($params['goodsContentList'] as $goods) {
|
|
|
$params['join_sheet_goods_id'] = $goods['goods_id'];
|
|
@@ -1034,13 +963,6 @@ class ServicesController extends Curd
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 2.4W 康养城
|
|
|
- if ($params['goods_classify'] == 'VIP' && intval($params['order_amount_pay']) == 24000 && $params['order_status_payment'] == 'SUCCESS') {
|
|
|
- $params['member_id'] = $params['join_order_member_id'];
|
|
|
- Event::dispatch('order.kangyangCityVIP.grant', $params);
|
|
|
- }
|
|
|
-
|
|
|
Db::commit();
|
|
|
|
|
|
// 会员升级
|
|
@@ -1050,55 +972,23 @@ class ServicesController extends Curd
|
|
|
}
|
|
|
|
|
|
// 打小票
|
|
|
- if (!empty($premises) && isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS') {
|
|
|
-// if (!empty($premises)){
|
|
|
- if ($premises->dept_category != '餐厅') {
|
|
|
- $restaurant = SysDept::where('dept_super_id', $premises->dept_id)->where('dept_category', '餐厅')->first();
|
|
|
- } else {
|
|
|
- $restaurant = $premises;
|
|
|
- }
|
|
|
- if (!empty($restaurant->dept_extend_json)) {
|
|
|
- $deptExtendJson = json_decode($restaurant->dept_extend_json, true);
|
|
|
- if (isset($deptExtendJson['printer'])) {
|
|
|
- foreach ($deptExtendJson['printer'] as $key => $item) {
|
|
|
- if (strpos($key, '结算') !== false && $params['order_status_payment'] == 'SUCCESS') {
|
|
|
- $voteData = [
|
|
|
- 'func' => 'procActionToPrinter',
|
|
|
- 'sign' => '',
|
|
|
- 'data' => [
|
|
|
- 'printer_premises' => $restaurant->dept_id,
|
|
|
- 'printer_device' => [
|
|
|
- $key
|
|
|
- ],
|
|
|
- 'printer_action' => 'ExecPrintOrder',
|
|
|
- 'printer_data' => [
|
|
|
- 'order_id' => $params['orderId'],
|
|
|
- 'order_batch' => ''
|
|
|
- ]
|
|
|
- ]
|
|
|
- ];
|
|
|
- http_post_json(getenv('VOTE_MENU_URL'), $voteData);
|
|
|
- }
|
|
|
- if ((strpos($key, '前台') !== false || strpos($key, '后厨') !== false)) {
|
|
|
- $voteData = [
|
|
|
- 'func' => 'procActionToPrinter',
|
|
|
- 'sign' => '',
|
|
|
- 'data' => [
|
|
|
- 'printer_premises' => $restaurant->dept_id,
|
|
|
- 'printer_device' => [
|
|
|
- $key
|
|
|
- ],
|
|
|
- 'printer_action' => 'ExecPrintOrder',
|
|
|
- 'printer_data' => [
|
|
|
- 'order_id' => $params['orderId'],
|
|
|
- 'order_batch' => ''
|
|
|
- ]
|
|
|
- ]
|
|
|
- ];
|
|
|
- http_post_json(getenv('VOTE_MENU_URL'), $voteData);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if ($params['order_status_payment'] == 'SUCCESS') {
|
|
|
+ if (!empty($premises) && !empty($premises->dept_id)) {
|
|
|
+ $voteData = [
|
|
|
+ 'func' => 'procActionToPrinter',
|
|
|
+ 'sign' => '',
|
|
|
+ 'data' => [
|
|
|
+ 'printer_premises' => $premises->dept_id,
|
|
|
+ 'printer_device' => ["收银"],
|
|
|
+ 'printer_action' => 'ExecPrintOrder',
|
|
|
+ 'printer_data' => [
|
|
|
+ 'order_id' => $params['orderId'],
|
|
|
+ 'order_batch' => ''
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+// dump("小票参数", $voteData);
|
|
|
+ http_post_json(getenv('VOTE_MENU_URL'), $voteData);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1201,11 +1091,18 @@ class ServicesController extends Curd
|
|
|
try {
|
|
|
// 使用优惠券
|
|
|
$couponUseJson = [];
|
|
|
+ $discountJson = [];
|
|
|
if (!empty($order->order_discount_json)) {
|
|
|
+ $discountJson = json_decode($order->order_discount_json, true);
|
|
|
+ foreach ($discountJson as $item) {
|
|
|
+ if (isset($item['coupon_value']) && sprintf('%.2f', (floatval($order->order_amount_total) - floatval($params['order_amount_pay']))) != sprintf('%.2f', $item['coupon_value'])) {
|
|
|
+ throw new BusinessException("计算优惠后,实付金额错误!");
|
|
|
+ }
|
|
|
+ }
|
|
|
// 释放下单时选的优惠券
|
|
|
- $order->order_discount_json = $this->releaseCoupon(json_decode($order->order_discount_json, true));
|
|
|
+ $order->order_discount_json = $this->releaseCoupon($discountJson);
|
|
|
}
|
|
|
- if (!empty($params['join_order_member_id']) && !empty($params['preferential'])) {
|
|
|
+ if (empty($discountJson) && !empty($params['join_order_member_id']) && !empty($params['preferential'])) {
|
|
|
$couponResult = OrderService::payUseCoupon('pay', 'Y', $params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
|
|
|
if (!empty($couponResult['pay_amount']) && $couponResult['pay_amount'] != $params['order_amount_pay']) {
|
|
|
throw new BusinessException("计算优惠后,实付金额错误!");
|
|
@@ -1213,16 +1110,12 @@ class ServicesController extends Curd
|
|
|
// 组装优惠券使用数据,存主表优惠里
|
|
|
if (!empty($couponResult['use_coupon_json'])) {
|
|
|
$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($couponUseJson, $params));
|
|
|
+ if (empty($discountJson)) {
|
|
|
+ $order->order_discount_json = json_encode($this->discountRecord($couponUseJson, $params));
|
|
|
+ }
|
|
|
// 组合支付时,付款码应收金额
|
|
|
$qrcodePayAmount = 0;
|
|
|
if ($params['pay_category'] == 'OFFLINE' || $params['pay_category'] == 'MONEY') {
|
|
@@ -1459,29 +1352,6 @@ class ServicesController extends Curd
|
|
|
} else {
|
|
|
throw new BusinessException('付款码无效');
|
|
|
}
|
|
|
-
|
|
|
- // 组合支付,追加加一条支付记录 pay_detail
|
|
|
- if ($params['pay_constitute'] == 'Y' && $qrcodePayAmount > 0) {
|
|
|
- $insertPayDetailData = [
|
|
|
- 'join_pay_member_id' => $params['join_order_member_id'],
|
|
|
- 'join_pay_order_id' => $params['orderGroupId'],
|
|
|
- 'pay_status' => 'SUCCESS',
|
|
|
- 'pay_category' => $params['goods_classify'],
|
|
|
- 'pay_amount' => $params['order_amount_pay'],
|
|
|
- 'pay_paytimes' => date('Y-m-d H:i:s'),
|
|
|
- 'pay_prepayid' => $params['pay_category'],
|
|
|
- 'pay_json_request' => json_encode($params),
|
|
|
- 'pay_json_response' => $params['pay_json_response'],
|
|
|
- 'join_pay_object_json' => !empty($params['orderId']) ? json_encode(['order_id' => $params['orderId']]) : '[]',
|
|
|
- 'pay_addtimes' => time()
|
|
|
- ];
|
|
|
-
|
|
|
- PayDetail::insert($insertPayDetailData);
|
|
|
-
|
|
|
- // 组合支付,还原提交的支付分类
|
|
|
- $params['pay_category'] = $submitPayCategory;
|
|
|
- }
|
|
|
-
|
|
|
// 账户支付的金额
|
|
|
$params['order_amount_pay'] = $accountAmount;
|
|
|
}
|
|
@@ -1490,15 +1360,8 @@ class ServicesController 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;
|
|
|
- // 康养城订单,支付完就结束了
|
|
|
- if ($order->order_status_payment == 'SUCCESS' && $params['goods_classify'] == 'VIP') {
|
|
|
- $order->order_is_complete = 'Y';
|
|
|
- }
|
|
|
// 主订单
|
|
|
$order->save();
|
|
|
|
|
@@ -1509,6 +1372,10 @@ class ServicesController extends Curd
|
|
|
]);
|
|
|
}
|
|
|
// payDetail
|
|
|
+ // 不组合支付,那就只有一条支付记录 先删,再加
|
|
|
+ PayDetail::where('join_pay_order_id', $order->order_groupby)
|
|
|
+ ->whereJsonContains('join_pay_object_json->order_id', $params['orderId'])
|
|
|
+ ->delete();
|
|
|
$payData = [
|
|
|
'pay_amount' => $params['order_amount_pay']
|
|
|
];
|
|
@@ -1536,31 +1403,18 @@ class ServicesController extends Curd
|
|
|
} else if ($params['pay_category'] == 'MONEY') {
|
|
|
$payData['pay_prepayid'] = 'MONEY';
|
|
|
}
|
|
|
- // 如果 是APP 过来的菜订单,可能没有paydetail
|
|
|
- if (!PayDetail::where('join_pay_order_id', $order->order_groupby)->where('pay_category', '<>', 'WXPAY')->where('pay_category', '<>', 'ALIPAY')->exists()) {
|
|
|
- $payData['join_pay_member_id'] = $params['join_order_member_id'];
|
|
|
- $payData['join_pay_order_id'] = $order->order_groupby;
|
|
|
- $payData['pay_status'] = $payData['pay_status'] == 'SUCCESS' ? $payData['pay_status'] : 'WAITING';
|
|
|
- $payData['pay_category'] = $params['goods_classify'] ?? '';
|
|
|
- $payData['pay_json_request'] = json_encode($params); // {"pay-result": "支付成功", "result-datetime": "2024-07-29 18:38:21"}
|
|
|
- $payData['pay_json_response'] = $payData['pay_status'] == 'SUCCESS' ? json_encode([
|
|
|
- 'pay-result' => '支付成功', 'result-datetime' => date('Y-m-d H:i:s')
|
|
|
- ]) : '[]';
|
|
|
- $payData['join_pay_object_json'] = !empty($params['orderId']) ? json_encode(['order_id' => $params['orderId']]) : '[]';
|
|
|
- $payData['pay_addtimes'] = time();
|
|
|
-
|
|
|
- PayDetail::insert($payData);
|
|
|
- } else {
|
|
|
- // 更新非微信支付宝的支付记录
|
|
|
- PayDetail::where('join_pay_order_id', $order->order_groupby)->where('pay_category', '<>', 'WXPAY')->where('pay_category', '<>', 'ALIPAY')->update($payData);
|
|
|
- }
|
|
|
+ $payData['join_pay_member_id'] = $params['join_order_member_id'];
|
|
|
+ $payData['join_pay_order_id'] = $order->order_groupby;
|
|
|
+ $payData['pay_status'] = $payData['pay_status'] == 'SUCCESS' ? $payData['pay_status'] : 'WAITING';
|
|
|
+ $payData['pay_category'] = $params['goods_classify'] ?? '';
|
|
|
+ $payData['pay_json_request'] = json_encode($params); // {"pay-result": "支付成功", "result-datetime": "2024-07-29 18:38:21"}
|
|
|
+ $payData['pay_json_response'] = $payData['pay_status'] == 'SUCCESS' ? (!empty($params['pay_json_response']) ? $params['pay_json_response'] : json_encode(['pay-result' => '支付成功', 'result-datetime' => date('Y-m-d H:i:s')])) : '[]';
|
|
|
+ $payData['join_pay_object_json'] = !empty($params['orderId']) ? json_encode(['order_id' => $params['orderId']]) : '[]';
|
|
|
+ $payData['pay_addtimes'] = time();
|
|
|
+ PayDetail::insert($payData);
|
|
|
+
|
|
|
$writeOffDate = [];
|
|
|
$applyData = [];
|
|
|
- // 服务已完成,生成核销数据
|
|
|
- // if ($order->order_status_payment == 'SUCCESS' && in_array($goods['goods_classify'], ['SERVICE','CHNMED','CHNNCD', 'PACKAGE'])) {
|
|
|
- // $writeOffDate = OrderService::generateWriteOffData($params);
|
|
|
- // $applyData = OrderService::generateAppointmentApplyData($params);
|
|
|
- // }
|
|
|
// 有预约单,状态已完成
|
|
|
$appointment = Appointment::where('join_appointment_order_id', $params['order_id'])->first();
|
|
|
if ($order->order_status_payment == 'SUCCESS' && $appointment) {
|
|
@@ -1631,12 +1485,6 @@ class ServicesController extends Curd
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 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);
|
|
|
- }
|
|
|
-
|
|
|
Db::commit();
|
|
|
|
|
|
// 会员升级
|
|
@@ -1646,32 +1494,23 @@ class ServicesController extends Curd
|
|
|
}
|
|
|
|
|
|
// 打小票
|
|
|
- if (!empty($premises) && $params['goods_classify'] == 'MEALS') {
|
|
|
- dump("pay 打小票");
|
|
|
- $restaurant = SysDept::where('dept_super_id', $premises->dept_id)->where('dept_category', '餐厅')->first();
|
|
|
- if (!empty($restaurant->dept_extend_json)) {
|
|
|
- $deptExtendJson = json_decode($restaurant->dept_extend_json, true);
|
|
|
- if (isset($deptExtendJson['printer'])) {
|
|
|
- foreach ($deptExtendJson['printer'] as $key => $item) {
|
|
|
- if (strpos($key, '结算') !== false && $order->order_status_payment == 'SUCCESS') {
|
|
|
- $voteData = [
|
|
|
- 'func' => 'procActionToPrinter',
|
|
|
- 'sign' => '',
|
|
|
- 'data' => [
|
|
|
- 'printer_premises' => $restaurant->dept_id,
|
|
|
- 'printer_device' => [
|
|
|
- $key
|
|
|
- ],
|
|
|
- 'printer_action' => 'ExecPrintOrder',
|
|
|
- 'printer_data' => [
|
|
|
- 'order_id' => $params['order_id']
|
|
|
- ]
|
|
|
- ]
|
|
|
- ];
|
|
|
- http_post_json(getenv('VOTE_MENU_URL'), $voteData);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if ($order->order_status_payment == 'SUCCESS') {
|
|
|
+ if (!empty($premises) && !empty($premises->dept_id)) {
|
|
|
+ $voteData = [
|
|
|
+ 'func' => 'procActionToPrinter',
|
|
|
+ 'sign' => '',
|
|
|
+ 'data' => [
|
|
|
+ 'printer_premises' => $premises->dept_id,
|
|
|
+ 'printer_device' => ["收银"],
|
|
|
+ 'printer_action' => 'ExecPrintOrder',
|
|
|
+ 'printer_data' => [
|
|
|
+ 'order_id' => $params['orderId'],
|
|
|
+ 'order_batch' => ''
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+// dump("小票参数", $voteData);
|
|
|
+ http_post_json(getenv('VOTE_MENU_URL'), $voteData);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1681,7 +1520,10 @@ class ServicesController extends Curd
|
|
|
if (!is_array($couponUseJson)) {
|
|
|
$couponUseJson = json_decode($couponUseJson, true);
|
|
|
}
|
|
|
- $this->changeOrderCouponStatus($couponUseJson, 'WAITING');
|
|
|
+ // 如果下单时就填了,不用恢复
|
|
|
+ if (empty($discountJson)) {
|
|
|
+ $this->changeOrderCouponStatus($couponUseJson, 'WAITING');
|
|
|
+ }
|
|
|
|
|
|
return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
|
|
|
}
|
|
@@ -1772,11 +1614,18 @@ class ServicesController extends Curd
|
|
|
Db::beginTransaction();
|
|
|
try {// 使用优惠券
|
|
|
$couponUseJson = [];
|
|
|
+ $discountJson = [];
|
|
|
if (!empty($order->order_discount_json)) {
|
|
|
+ $discountJson = json_decode($order->order_discount_json, true);
|
|
|
+ foreach ($discountJson as $item) {
|
|
|
+ if (isset($item['coupon_value']) && sprintf('%.2f', (floatval($order->order_amount_total) - floatval($params['order_amount_pay']))) != sprintf('%.2f', $item['coupon_value'])) {
|
|
|
+ throw new BusinessException("计算优惠后,实付金额错误!");
|
|
|
+ }
|
|
|
+ }
|
|
|
// 释放下单时选的优惠券
|
|
|
- $order->order_discount_json = $this->releaseCoupon(json_decode($order->order_discount_json, true));
|
|
|
+ $order->order_discount_json = $this->releaseCoupon($discountJson);
|
|
|
}
|
|
|
- if (!empty($params['join_order_member_id']) && !empty($params['preferential'])) {
|
|
|
+ if (empty($discountJson) && !empty($params['join_order_member_id']) && !empty($params['preferential'])) {
|
|
|
$couponResult = OrderService::payUseCoupon('pay', 'Y', $params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
|
|
|
if (!empty($couponResult['pay_amount']) && $couponResult['pay_amount'] != $params['order_amount_pay']) {
|
|
|
throw new BusinessException("计算优惠后,实付金额错误!");
|
|
@@ -1784,12 +1633,6 @@ class ServicesController extends Curd
|
|
|
// 组装优惠券使用数据,存主表优惠里
|
|
|
if (!empty($couponResult['use_coupon_json'])) {
|
|
|
$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)));
|
|
|
-// }
|
|
|
-// }
|
|
|
}
|
|
|
}
|
|
|
// 存储优惠信息
|
|
@@ -1970,7 +1813,10 @@ class ServicesController extends Curd
|
|
|
]);
|
|
|
}
|
|
|
// 清除paydetail 中的未支付记录
|
|
|
- PayDetail::where('join_pay_order_id', $params['orderGroupId'])->where('pay_status', '<>', 'SUCCESS')->delete();
|
|
|
+ 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 = [];
|
|
@@ -2056,32 +1902,23 @@ class ServicesController extends Curd
|
|
|
}
|
|
|
|
|
|
// 打小票
|
|
|
- if (!empty($premises) && $params['goods_classify'] == "MEALS") {
|
|
|
- dump('payCons 打小票');
|
|
|
- $restaurant = SysDept::where('dept_super_id', $premises->dept_id)->where('dept_category', '餐厅')->first();
|
|
|
- if (!empty($restaurant->dept_extend_json)) {
|
|
|
- $deptExtendJson = json_decode($restaurant->dept_extend_json, true);
|
|
|
- if (isset($deptExtendJson['printer'])) {
|
|
|
- foreach ($deptExtendJson['printer'] as $key => $item) {
|
|
|
- if (strpos($key, '结算') !== false && $order->order_status_payment == 'SUCCESS') {
|
|
|
- $voteData = [
|
|
|
- 'func' => 'procActionToPrinter',
|
|
|
- 'sign' => '',
|
|
|
- 'data' => [
|
|
|
- 'printer_premises' => $restaurant->dept_id,
|
|
|
- 'printer_device' => [
|
|
|
- $key
|
|
|
- ],
|
|
|
- 'printer_action' => 'ExecPrintOrder',
|
|
|
- 'printer_data' => [
|
|
|
- 'order_id' => $params['order_id']
|
|
|
- ]
|
|
|
- ]
|
|
|
- ];
|
|
|
- http_post_json(getenv('VOTE_MENU_URL'), $voteData);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if ($order->order_status_payment == 'SUCCESS') {
|
|
|
+ if (!empty($premises) && !empty($premises->dept_id)) {
|
|
|
+ $voteData = [
|
|
|
+ 'func' => 'procActionToPrinter',
|
|
|
+ 'sign' => '',
|
|
|
+ 'data' => [
|
|
|
+ 'printer_premises' => $premises->dept_id,
|
|
|
+ 'printer_device' => ["收银"],
|
|
|
+ 'printer_action' => 'ExecPrintOrder',
|
|
|
+ 'printer_data' => [
|
|
|
+ 'order_id' => $params['orderId'],
|
|
|
+ 'order_batch' => ''
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+// dump("小票参数", $voteData);
|
|
|
+ http_post_json(getenv('VOTE_MENU_URL'), $voteData);
|
|
|
}
|
|
|
}
|
|
|
if ($order->order_status_payment != 'SUCCESS') {
|
|
@@ -2090,7 +1927,10 @@ class ServicesController extends Curd
|
|
|
if (!is_array($couponUseJson)) {
|
|
|
$couponUseJson = json_decode($couponUseJson, true);
|
|
|
}
|
|
|
- $this->changeOrderCouponStatus($couponUseJson, 'WAITING');
|
|
|
+ // 如果下单时就填了,不用恢复
|
|
|
+ if (empty($discountJson)) {
|
|
|
+ $this->changeOrderCouponStatus($couponUseJson, 'WAITING');
|
|
|
+ }
|
|
|
return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
|
|
|
}
|
|
|
_syslog("订单", "订单支付成功");
|
|
@@ -2125,8 +1965,17 @@ class ServicesController extends Curd
|
|
|
// 推荐人
|
|
|
$params['order_extend_json']['referee'] = $params['referee'] ?? '';
|
|
|
foreach ($params['goodsContentList'] as $goods) {
|
|
|
+ $discountJson = [];
|
|
|
+ if (!empty($params['order_discount_json'])) {
|
|
|
+ $discountJson = json_decode($params['order_discount_json'], true);
|
|
|
+ foreach ($discountJson as &$item) {
|
|
|
+ if (!empty($item['coupon_value'])) {
|
|
|
+ $item['coupon_value'] = round((floatval($goods['goods_sales_price']) * $goods['nbr'] / $params['order_amount_total']) * $item['coupon_value'], 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
$orderId = 'OD' . date('ymdHi') . random_string(4, 'up');
|
|
|
- $amountPay = (floatval($goods['goods_sales_price']) * $goods['nbr'] / $params['order_amount_total']) * $params['order_amount_pay'];
|
|
|
+ $amountPay = round((floatval($goods['goods_sales_price']) * $goods['nbr'] / $params['order_amount_total']) * $params['order_amount_pay'], 2);
|
|
|
// $amountPay = round(floatval($goods['goods_sales_price']) * $goods['nbr'] * $params['order_ratio'], 2);
|
|
|
$data = [
|
|
|
'order_id' => $orderId,
|
|
@@ -2143,7 +1992,7 @@ class ServicesController extends Curd
|
|
|
'order_status_storage' => $params['order_status_storage'],
|
|
|
'order_platform' => $params['order_platform'],
|
|
|
'order_remark' => $params['order_remark'] ?? '',
|
|
|
- 'order_discount_json' => $params['order_discount_json'],
|
|
|
+ 'order_discount_json' => json_encode($discountJson),
|
|
|
'order_config_json' => $params['order_config_json'] ?? '[]',
|
|
|
'order_express_json' => $params['order_express_json'] ?? '[]',
|
|
|
'order_extend_json' => $params['order_extend_json'] ? json_encode($params['order_extend_json']) : '[]',
|
|
@@ -2152,13 +2001,13 @@ class ServicesController extends Curd
|
|
|
|
|
|
Order::insert($data);
|
|
|
|
|
|
- $sheetIds = $this->insertSheetOne($params, $goods, $orderId);
|
|
|
+ $sheetIds = $this->insertSheetOne($params, $goods, $orderId, $amountPay);
|
|
|
|
|
|
- $this->insertPayDetailOne($params, $orderId, $amountPay,$goods);
|
|
|
+ $this->insertPayDetailOne($params, $orderId, $amountPay, $goods);
|
|
|
|
|
|
$params['order_express_goods'] = json_encode(['sheet' => $sheetIds]);
|
|
|
|
|
|
- $this->insertExpressOne($params);
|
|
|
+ $this->insertExpressOne($params, $orderId);
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
dump($e->getMessage());
|
|
@@ -2252,7 +2101,7 @@ class ServicesController extends Curd
|
|
|
* @return array
|
|
|
* @throws BusinessException
|
|
|
*/
|
|
|
- public function insertSheetOne($params, $goods, $orderId)
|
|
|
+ public function insertSheetOne($params, $goods, $orderId, $amountPay)
|
|
|
{
|
|
|
try {
|
|
|
$orderSheetIds = [];
|
|
@@ -2275,9 +2124,9 @@ class ServicesController extends Curd
|
|
|
'order_sheet_category' => (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS') ? 'DISHES' : 'NORMAL',
|
|
|
'order_sheet_num' => $goods['nbr'],
|
|
|
'order_sheet_price' => $goods['goods_sales_price'],
|
|
|
- 'order_sheet_price_pay' => round($goods['goods_sales_price'] * $params['order_ratio']),
|
|
|
+ 'order_sheet_price_pay' => round($amountPay / $goods['nbr'], 2),
|
|
|
'order_sheet_amount' => $price * $goods['nbr'],
|
|
|
- 'order_sheet_pay' => round($price * $goods['nbr'] * $params['order_ratio'], 2),
|
|
|
+ 'order_sheet_pay' => $amountPay,
|
|
|
'order_sheet_task_status' => 'NONE',
|
|
|
'order_sheet_remark' => $params['order_remark'] ?? '',
|
|
|
'order_sheet_addtimes' => time(),
|
|
@@ -2377,38 +2226,58 @@ class ServicesController extends Curd
|
|
|
* @return void
|
|
|
* @throws BusinessException
|
|
|
*/
|
|
|
- public function insertPayDetailOne($params, $orderId, $amountPay,$goods)
|
|
|
+ public function insertPayDetailOne($params, $orderId, $amountPay, $goods)
|
|
|
{
|
|
|
try {
|
|
|
- if (in_array($params['pay_category'], ['WXPAY', 'ALIPAY'])) {
|
|
|
- $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';
|
|
|
+ if (!empty($params['pay_detail_item'])) {
|
|
|
+ foreach ($params['pay_detail_item'] as $item) {
|
|
|
+ $data = [
|
|
|
+ 'join_pay_member_id' => $item['join_order_member_id'],
|
|
|
+ 'join_pay_order_id' => $item['orderGroupId'],
|
|
|
+ 'pay_status' => $item['settlement_now'] == 'Y' && $item['order_status_payment'] == 'SUCCESS' ? 'SUCCESS' : 'WAITING',
|
|
|
+ 'pay_category' => $goods['goods_classify'],
|
|
|
+ 'pay_amount' => round(($amountPay / $params['order_amount_pay']) * $item['order_amount_pay'], 2),
|
|
|
+ 'pay_prepayid' => $item['pay_category'],
|
|
|
+ 'pay_paytimes' => date('Y-m-d H:i:s'),
|
|
|
+ 'join_pay_object_json' => !empty($item['orderId']) ? json_encode(['order_id' => $orderId]) : '[]',
|
|
|
+ 'pay_json_request' => json_encode($item),
|
|
|
+ 'pay_json_response' => $item['pay_json_response'] ?? '[]',
|
|
|
+ 'pay_remark' => $item['order_remark'] ?? '',
|
|
|
+ 'pay_addtimes' => time(),
|
|
|
+ ];
|
|
|
+ PayDetail::insert($data);
|
|
|
+ }
|
|
|
} else {
|
|
|
- $payPrepayid = $params['join_order_member_id'] . '-' . $params['pay_category'];
|
|
|
- }
|
|
|
- $data = [
|
|
|
- 'join_pay_member_id' => $params['join_order_member_id'],
|
|
|
- 'join_pay_order_id' => $params['orderGroupId'],
|
|
|
- 'pay_status' => $params['settlement_now'] == 'Y' && $params['order_status_payment'] == 'SUCCESS' ? 'SUCCESS' : 'WAITING',
|
|
|
- 'pay_category' => $goods['goods_classify'],
|
|
|
- 'pay_amount' => $amountPay,
|
|
|
- 'pay_prepayid' => $payPrepayid,
|
|
|
- 'pay_paytimes' => date('Y-m-d H:i:s'),
|
|
|
- 'join_pay_object_json' => !empty($params['orderId']) ? json_encode(['order_id' => $orderId]) : '[]',
|
|
|
- 'pay_json_request' => json_encode($params),
|
|
|
- 'pay_json_response' => $params['pay_json_response'] ?? '[]',
|
|
|
- 'pay_remark' => $params['order_remark'] ?? '',
|
|
|
- 'pay_addtimes' => time(),
|
|
|
- ];
|
|
|
+ if (in_array($params['pay_category'], ['WXPAY', 'ALIPAY'])) {
|
|
|
+ $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 {
|
|
|
+ $payPrepayid = $params['join_order_member_id'] . '-' . $params['pay_category'];
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'join_pay_member_id' => $params['join_order_member_id'],
|
|
|
+ 'join_pay_order_id' => $params['orderGroupId'],
|
|
|
+ 'pay_status' => $params['settlement_now'] == 'Y' && $params['order_status_payment'] == 'SUCCESS' ? 'SUCCESS' : 'WAITING',
|
|
|
+ 'pay_category' => $goods['goods_classify'],
|
|
|
+ 'pay_amount' => $amountPay,
|
|
|
+ 'pay_prepayid' => $payPrepayid,
|
|
|
+ 'pay_paytimes' => date('Y-m-d H:i:s'),
|
|
|
+ 'join_pay_object_json' => !empty($params['orderId']) ? json_encode(['order_id' => $orderId]) : '[]',
|
|
|
+ 'pay_json_request' => json_encode($params),
|
|
|
+ 'pay_json_response' => $params['pay_json_response'] ?? '[]',
|
|
|
+ 'pay_remark' => $params['order_remark'] ?? '',
|
|
|
+ 'pay_addtimes' => time(),
|
|
|
+ ];
|
|
|
|
|
|
- PayDetail::insert($data);
|
|
|
+ PayDetail::insert($data);
|
|
|
+ }
|
|
|
} catch (\Exception $e) {
|
|
|
dump($e->getMessage());
|
|
|
throw new BusinessException('创建支付记录失败');
|
|
@@ -2489,12 +2358,12 @@ class ServicesController extends Curd
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function saveExpress($params)
|
|
|
+ public function saveExpress($params, $orderId)
|
|
|
{
|
|
|
try {
|
|
|
$express = new OrderExpress();
|
|
|
$express->order_express_type = $params['order_express_type'];
|
|
|
- $express->join_express_order_id = $params['orderId'];
|
|
|
+ $express->join_express_order_id = $orderId;
|
|
|
$express->join_express_dept_id = $params['submit_premises_id'] ?? 0;
|
|
|
$express->order_express_goods = $params['order_express_goods'];
|
|
|
$express->order_express_city = $params['order_express_city'];
|
|
@@ -2595,12 +2464,12 @@ class ServicesController extends Curd
|
|
|
* @return void
|
|
|
* @throws BusinessException
|
|
|
*/
|
|
|
- public function insertExpressOne($params)
|
|
|
+ public function insertExpressOne($params, $orderId)
|
|
|
{
|
|
|
if (isset($params['delivery']) && $params['delivery'] == 'LOGISTICS') {
|
|
|
$params['order_express_type'] = '配送';
|
|
|
// 入配送
|
|
|
- $this->saveExpress($params);
|
|
|
+ $this->saveExpress($params, $orderId);
|
|
|
} else if (isset($params['delivery']) && $params['delivery'] == 'PICKUP') {
|
|
|
$params['order_express_type'] = '自提';
|
|
|
$premises = SysDept::where('dept_name', $params['dept_premises_id'])->first();
|
|
@@ -2613,7 +2482,7 @@ class ServicesController extends Curd
|
|
|
$params['order_express_telephone'] = $premises->dept_telephone;
|
|
|
$params['order_express_extend_json'] = json_encode(['pick_code' => random_string(4, 'number')]);
|
|
|
|
|
|
- $this->saveExpress($params);
|
|
|
+ $this->saveExpress($params, $orderId);
|
|
|
} else if (isset($params['delivery']) && $params['delivery'] == 'ARRIVAL') {
|
|
|
$premises = SysDept::where('dept_name', $params['dept_premises_id'])->first();
|
|
|
$params['order_express_type'] = '到店';
|
|
@@ -2628,7 +2497,40 @@ class ServicesController extends Curd
|
|
|
$params['order_express_address'] = $premises->dept_address;
|
|
|
$params['order_express_telephone'] = $premises->dept_telephone;
|
|
|
|
|
|
- $this->saveExpress($params);
|
|
|
+ $this->saveExpress($params, $orderId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Desc 释放下单时选的优惠券
|
|
|
+ * @Author Gorden
|
|
|
+ * @Date 2024/9/19 9:56
|
|
|
+ *
|
|
|
+ * @param $coupon
|
|
|
+ * @return false|string
|
|
|
+ */
|
|
|
+ private function releaseCoupon($coupon)
|
|
|
+ {
|
|
|
+ if (!empty($coupon) && is_array($coupon)) {
|
|
|
+ $updateData = [
|
|
|
+ 'coupon_detail_status' => 'ACTIVED',
|
|
|
+ 'coupon_detail_used_datetime' => ''
|
|
|
+ ];
|
|
|
+ foreach ($coupon as $key => $item) {
|
|
|
+ if (!empty($item['coupon_id']) && !empty($item['coupon_detail_id'])) {
|
|
|
+ foreach ($item['coupon_detail_id'] as $detailId) {
|
|
|
+ if (substr($detailId, 0, 4) == 'CUDT') {
|
|
|
+ CouponDetail::where('join_detail_coupon_id', $item['coupon_id'])
|
|
|
+ ->where('coupon_detail_id', $detailId)
|
|
|
+ ->where('coupon_detail_status', 'WAITING')
|
|
|
+ ->update($updateData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ unset($coupon[$key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ return json_encode($coupon);
|
|
|
}
|
|
|
}
|