|
@@ -206,6 +206,7 @@ class PartnerController extends Curd
|
|
// 判断餐品是否连带着服务或实体
|
|
// 判断餐品是否连带着服务或实体
|
|
$goodsClassifys = array_unique(array_column($params['goodsContentList'], 'goods_classify'));
|
|
$goodsClassifys = array_unique(array_column($params['goodsContentList'], 'goods_classify'));
|
|
$params['goods_classify'] = $goodsClassifys[0];
|
|
$params['goods_classify'] = $goodsClassifys[0];
|
|
|
|
+ $orderExtendJson = [];
|
|
Db::beginTransaction();
|
|
Db::beginTransaction();
|
|
try {
|
|
try {
|
|
// 验证线下付款密码
|
|
// 验证线下付款密码
|
|
@@ -215,6 +216,14 @@ class PartnerController extends Curd
|
|
throw new BusinessException('密码错误,请重新输入');
|
|
throw new BusinessException('密码错误,请重新输入');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if (!empty($params['dept_id'])) {
|
|
|
|
+ $dept = SysDept::where('dept_id', $params['dept_id'])->first();
|
|
|
|
+ if (!$dept) {
|
|
|
|
+ throw new BusinessException("入伙场所不存在");
|
|
|
|
+ }
|
|
|
|
+ $params['dept_name'] = $dept->dept_name;
|
|
|
|
+ $orderExtendJson = ['dept_id' => $params['dept_id'], 'dept_name' => $params['dept_name']];
|
|
|
|
+ }
|
|
// 下单账户
|
|
// 下单账户
|
|
if (empty($params['join_order_member_id']) && !empty($params['mobile'])) {
|
|
if (empty($params['join_order_member_id']) && !empty($params['mobile'])) {
|
|
if (Member::where('member_mobile', $params['mobile'])->exists()) {
|
|
if (Member::where('member_mobile', $params['mobile'])->exists()) {
|
|
@@ -230,7 +239,6 @@ class PartnerController extends Curd
|
|
throw new BusinessException('检查下单账户');
|
|
throw new BusinessException('检查下单账户');
|
|
}
|
|
}
|
|
|
|
|
|
- $qrcodePayAmount = 0;
|
|
|
|
$params['orderId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
|
|
$params['orderId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
|
|
$params['orderGroupId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
|
|
$params['orderGroupId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
|
|
// 查询是否有未完全支付订单
|
|
// 查询是否有未完全支付订单
|
|
@@ -291,6 +299,7 @@ class PartnerController extends Curd
|
|
}
|
|
}
|
|
|
|
|
|
if (empty($paidOrder)) {
|
|
if (empty($paidOrder)) {
|
|
|
|
+ $params['order_extend_json'] = $orderExtendJson;
|
|
// 写入主订单
|
|
// 写入主订单
|
|
$this->insertMain($params);
|
|
$this->insertMain($params);
|
|
// 订单详情
|
|
// 订单详情
|
|
@@ -383,7 +392,21 @@ class PartnerController extends Curd
|
|
}
|
|
}
|
|
$goods = $goods->toArray();
|
|
$goods = $goods->toArray();
|
|
$params['goods_classify'] = $goods['goods_classify'] ?? '';
|
|
$params['goods_classify'] = $goods['goods_classify'] ?? '';
|
|
-
|
|
|
|
|
|
+ // 入伙场所
|
|
|
|
+ if (!empty($params['dept_id'])) {
|
|
|
|
+ $orderExtendJson = [];
|
|
|
|
+ if (!empty($order->order_extend_json)) {
|
|
|
|
+ $orderExtendJson = json_decode($order->order_extend_json, true);
|
|
|
|
+ }
|
|
|
|
+ $dept = SysDept::where('dept_id', $params['dept_id'])->first();
|
|
|
|
+ if (!$dept) {
|
|
|
|
+ throw new BusinessException("入伙场所不存在");
|
|
|
|
+ }
|
|
|
|
+ $params['dept_name'] = $dept->dept_name;
|
|
|
|
+ $orderExtendJson['dept_id'] = $params['dept_id'];
|
|
|
|
+ $orderExtendJson['dept_name'] = $params['dept_name'];
|
|
|
|
+ $order->order_extend_json = json_encode($orderExtendJson);
|
|
|
|
+ }
|
|
// 立即结算
|
|
// 立即结算
|
|
if ($params['goods_classify'] == 'PARTNER') {
|
|
if ($params['goods_classify'] == 'PARTNER') {
|
|
$order->order_is_complete = 'Y';
|
|
$order->order_is_complete = 'Y';
|
|
@@ -976,6 +999,9 @@ class PartnerController extends Curd
|
|
if (isset($orderExtendJson['free_remark'])) {
|
|
if (isset($orderExtendJson['free_remark'])) {
|
|
$order->free_remark = $orderExtendJson['free_remark'];
|
|
$order->free_remark = $orderExtendJson['free_remark'];
|
|
}
|
|
}
|
|
|
|
+ if (isset($orderExtendJson['dept_id'])) {
|
|
|
|
+ $order->dept_id = $orderExtendJson['dept_id'];
|
|
|
|
+ }
|
|
}
|
|
}
|
|
$discount = ['coupon_name' => '', 'classify' => '', 'value' => 0];
|
|
$discount = ['coupon_name' => '', 'classify' => '', 'value' => 0];
|
|
if (!empty($order->order_discount_json)) {
|
|
if (!empty($order->order_discount_json)) {
|
|
@@ -1050,7 +1076,7 @@ class PartnerController extends Curd
|
|
$order = Order::where('join_order_member_id', $memberId)
|
|
$order = Order::where('join_order_member_id', $memberId)
|
|
->where('order_category', 'PARTNER')
|
|
->where('order_category', 'PARTNER')
|
|
->where('order_status_system', 'PAYING')
|
|
->where('order_status_system', 'PAYING')
|
|
- ->select('order_id', 'order_amount_total', 'order_amount_paid', 'order_amount_pay')
|
|
|
|
|
|
+ ->select('order_id', 'order_amount_total', 'order_amount_paid', 'order_amount_pay', 'order_extend_json')
|
|
->first();
|
|
->first();
|
|
|
|
|
|
return json_success('', $order);
|
|
return json_success('', $order);
|
|
@@ -1092,6 +1118,7 @@ class PartnerController extends Curd
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @Desc 查询订单状态
|
|
* @Desc 查询订单状态
|
|
* @Author Gorden
|
|
* @Author Gorden
|
|
@@ -1102,106 +1129,98 @@ class PartnerController extends Curd
|
|
*/
|
|
*/
|
|
public function getOrderPayStatus(Request $request)
|
|
public function getOrderPayStatus(Request $request)
|
|
{
|
|
{
|
|
- $orderId = $request->get('order_id', '');
|
|
|
|
- if (!$orderId) {
|
|
|
|
- return json_fail('订单不存在');
|
|
|
|
|
|
+ $groupId = $request->get('group_id');
|
|
|
|
+ if (!$groupId) {
|
|
|
|
+ return json_fail('参数异常');
|
|
}
|
|
}
|
|
|
|
|
|
- $order = Order::where('order_id', $orderId)->first();
|
|
|
|
- if (!$order) {
|
|
|
|
|
|
+ $order = Order::where('order_groupby', $groupId)->first();
|
|
|
|
+ if (empty($order)) {
|
|
return json_fail('订单不存在');
|
|
return json_fail('订单不存在');
|
|
}
|
|
}
|
|
-
|
|
|
|
- $discountJson = [];
|
|
|
|
- if (!empty($order->order_discount_json)) {
|
|
|
|
- $discountJson = json_decode($order->order_discount_json, true);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ($order->order_status_payment == 'SUCCESS') {
|
|
|
|
- return json_success('success');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $payDetailType = PayDetail::where('join_pay_order_id', $order->order_groupby)->pluck('pay_prepayid')->toArray();
|
|
|
|
|
|
+ $order = $order->toArray();
|
|
|
|
+ $sheet = OrderSheet::where('join_sheet_order_id', $order['order_id'])
|
|
|
|
+ ->select('order_sheet_id', 'join_sheet_goods_id', 'join_sheet_goods_sku_id')
|
|
|
|
+ ->first();
|
|
|
|
+ $payDetailType = PayDetail::where('join_pay_order_id', $groupId)->pluck('pay_prepayid')->toArray();
|
|
try {
|
|
try {
|
|
Db::beginTransaction();
|
|
Db::beginTransaction();
|
|
|
|
+ $payStatus = 'N';
|
|
|
|
+ $payAmount = 0;
|
|
if (in_array('WXPAY', $payDetailType)) {
|
|
if (in_array('WXPAY', $payDetailType)) {
|
|
- $result = Pay::wechat(config('payment.wxpay'))->find($order->order_groupby, 'pos');
|
|
|
|
- $result = json_decode(json_encode($result), true);
|
|
|
|
-// $result = '{"return_code":"SUCCESS","return_msg":"OK","result_code":"SUCCESS","mch_id":"1680393367","appid":"wxc6274da7198e3eb4","openid":"o3JAn6Ii_bAlxS-jbNEC4WnPhdwM","is_subscribe":"N","trade_type":"MICROPAY","trade_state":"SUCCESS","bank_type":"OTHERS","total_fee":"1000","fee_type":"CNY","cash_fee":"1000","cash_fee_type":"CNY","transaction_id":"4200067718202409250802875650","out_trade_no":"OD24092518408RV7","attach":[],"time_end":"20240925184009","trade_state_desc":"支付成功","nonce_str":"OeGOkjch4eaV5qIt","sign":"6DCB3BFC594EBC018A2BEE2C3DFEA4E3"}';
|
|
|
|
-// $result = json_decode($result, true);
|
|
|
|
|
|
+// $result = Pay::wechat(config('payment.wxpay'))->find($groupId, 'pos');
|
|
|
|
+// $result = json_decode(json_encode($result), true);
|
|
|
|
+ $result = '{"return_code":"SUCCESS","return_msg":"OK","result_code":"SUCCESS","mch_id":"1680393367","appid":"wxc6274da7198e3eb4","openid":"o3JAn6Ii_bAlxS-jbNEC4WnPhdwM","is_subscribe":"N","trade_type":"MICROPAY","trade_state":"SUCCESS","bank_type":"OTHERS","total_fee":"50","fee_type":"CNY","cash_fee":"1000","cash_fee_type":"CNY","transaction_id":"4200067718202409250802875650","out_trade_no":"OD24092518408RV7","attach":[],"time_end":"20240925184009","trade_state_desc":"支付成功","nonce_str":"OeGOkjch4eaV5qIt","sign":"6DCB3BFC594EBC018A2BEE2C3DFEA4E3"}';
|
|
|
|
+ $result = json_decode($result, true);
|
|
if (!empty($result['return_code']) && $result['return_code'] == 'SUCCESS' && !empty($result['result_code']) && $result['result_code'] == 'SUCCESS' && !empty($result['trade_state']) && $result['trade_state'] == 'SUCCESS') {
|
|
if (!empty($result['return_code']) && $result['return_code'] == 'SUCCESS' && !empty($result['result_code']) && $result['result_code'] == 'SUCCESS' && !empty($result['trade_state']) && $result['trade_state'] == 'SUCCESS') {
|
|
- $order->order_status_payment = 'SUCCESS';
|
|
|
|
- if (in_array($order->order_category, ['SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE'])) {
|
|
|
|
- $order->order_status_system = 'WAITING';
|
|
|
|
- } else if (in_array($order->order_category, ['DISHES', 'MEALS'])) {
|
|
|
|
- $order->order_is_complete = 'Y';
|
|
|
|
- $order->order_status_system = 'DONE';
|
|
|
|
- } else if (in_array($order->order_category, ['VIP', 'PARTNER'])) {
|
|
|
|
- $order->order_status_payment = 'PENDING';
|
|
|
|
- $totalFee = $result['total_fee'] / 100;
|
|
|
|
- if ($order->order_amount_paid + $totalFee >= $order->order_amount_total) {
|
|
|
|
- $order->order_amount_paid = $order->order_amount_paid + $totalFee;
|
|
|
|
- $order->order_status_payment = 'SUCCESS';
|
|
|
|
- $order->order_status_system = 'DONE';
|
|
|
|
- $order->order_is_complete = 'Y';
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- $order->order_status_system = 'SENDING';
|
|
|
|
|
|
+ $payStatus = 'Y';
|
|
|
|
+ $payAmount = ($result['total_fee'] / 100);
|
|
|
|
+ $orderUpdateData['order_status_payment'] = 'PENDING';
|
|
|
|
+ $orderUpdateData['order_amount_paid'] = $order['order_amount_paid'] + $payAmount;
|
|
|
|
+ $orderUpdateData['order_amount_pay'] = $order['order_amount_pay'] + $payAmount;
|
|
|
|
+ if ($order['order_amount_paid'] + $payAmount >= $order['order_amount_total']) {
|
|
|
|
+ $orderUpdateData['order_status_payment'] = 'SUCCESS';
|
|
|
|
+ $orderUpdateData['order_status_system'] = 'DONE';
|
|
|
|
+ $orderUpdateData['order_is_complete'] = 'Y';
|
|
}
|
|
}
|
|
- $order->save();
|
|
|
|
|
|
+ // 主订单
|
|
|
|
+ Order::where('order_groupby', $groupId)->update($orderUpdateData);
|
|
// Sheet
|
|
// Sheet
|
|
- if ($order->order_status_payment == 'SUCCESS') {
|
|
|
|
- OrderSheet::where('join_sheet_order_id', $orderId)->where('order_sheet_status', 'PAYING')->update(['order_sheet_status' => 'DONE']);
|
|
|
|
- }
|
|
|
|
- // 支付记录
|
|
|
|
- PayDetail::where('join_pay_order_id', $order->order_groupby)->where('pay_prepayid', 'WXPAY')->update(['pay_status' => 'SUCCESS']);
|
|
|
|
-
|
|
|
|
- // 优惠券标记使用
|
|
|
|
- $this->changeOrderCouponStatus($discountJson, 'USED');
|
|
|
|
|
|
+ OrderSheet::where('join_sheet_order_id', $order['order_id'])->where('order_sheet_status', 'PAYING')->update(['order_sheet_status' => 'DONE']);
|
|
|
|
|
|
- Db::commit();
|
|
|
|
- return json_success('success');
|
|
|
|
|
|
+ // 支付记录
|
|
|
|
+ PayDetail::where('join_pay_order_id', $order['order_groupby'])->where('pay_prepayid', 'WXPAY')->update(['pay_status' => 'SUCCESS']);
|
|
}
|
|
}
|
|
} else if (in_array('ALIPAY', $payDetailType)) {
|
|
} else if (in_array('ALIPAY', $payDetailType)) {
|
|
- $result = Pay::alipay(config('payment.alipay'))->find($order->order_groupby);
|
|
|
|
|
|
+ $result = Pay::alipay(config('payment.alipay'))->find($groupId);
|
|
$result = json_decode(json_encode($result), true);
|
|
$result = json_decode(json_encode($result), true);
|
|
-// $result = '{"code":"10000","msg":"Success","buyer_logon_id":"138******93","buyer_pay_amount":"5.87","fund_bill_list":[{"amount":"5.69","fund_channel":"ALIPAYACCOUNT"},{"amount":"0.18","fund_channel":"COUPON"},{"amount":"0.13","fund_channel":"DISCOUNT"}],"invoice_amount":"5.69","out_trade_no":"OD2409251550Q07A","point_amount":"0.00","receipt_amount":"6.00","send_pay_date":"2024-09-25 15:50:22","total_amount":"6.00","trade_no":"2024092523001439431419750998","trade_status":"TRADE_SUCCESS","buyer_open_id":"04309N2aVhSZz4cKwN_DN2DQa7ekM3z5n8kscQHsmIZOJsf"}';
|
|
|
|
|
|
+// $result = '{"code":"10000","msg":"Success","buyer_logon_id":"138******93","buyer_pay_amount":"5.87","fund_bill_list":[{"amount":"5.69","fund_channel":"ALIPAYACCOUNT"},{"amount":"0.18","fund_channel":"COUPON"},{"amount":"0.13","fund_channel":"DISCOUNT"}],"invoice_amount":"5.69","out_trade_no":"OD2409251550Q07A","point_amount":"0.00","receipt_amount":"0.01","send_pay_date":"2024-09-25 15:50:22","total_amount":"0.01","trade_no":"2024092523001439431419750998","trade_status":"TRADE_SUCCESS","buyer_open_id":"04309N2aVhSZz4cKwN_DN2DQa7ekM3z5n8kscQHsmIZOJsf"}';
|
|
// $result = json_decode($result, true);
|
|
// $result = json_decode($result, true);
|
|
if (!empty($result['code']) && $result['code'] == '10000' && !empty($result['trade_status']) && $result['trade_status'] == 'TRADE_SUCCESS') {
|
|
if (!empty($result['code']) && $result['code'] == '10000' && !empty($result['trade_status']) && $result['trade_status'] == 'TRADE_SUCCESS') {
|
|
- $order->order_status_payment = 'SUCCESS';
|
|
|
|
- if (in_array($order->order_category, ['SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE'])) {
|
|
|
|
- $order->order_status_system = 'WAITING';
|
|
|
|
- } elseif (in_array($order->order_category, ['DISHES', 'MEALS'])) {
|
|
|
|
- $order->order_is_complete = 'Y';
|
|
|
|
- $order->order_status_system = 'DONE';
|
|
|
|
- } else if (in_array($order->order_category, ['VIP', 'PARTNER'])) {
|
|
|
|
- $order->order_status_payment = 'PENDING';
|
|
|
|
- if ($order->order_amount_paid + $result['total_amount'] >= $order->order_amount_total) {
|
|
|
|
- $order->order_amount_paid = $order->order_amount_paid + $result['total_amount'];
|
|
|
|
- $order->order_status_system = 'DONE';
|
|
|
|
- $order->order_status_payment = 'SUCCESS';
|
|
|
|
- $order->order_is_complete = 'Y';
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- $order->order_status_system = 'SENDING';
|
|
|
|
|
|
+ $payStatus = 'Y';
|
|
|
|
+ $payAmount = $result['total_amount'];
|
|
|
|
+ $orderUpdateData['order_status_payment'] = 'PENDING';
|
|
|
|
+ $orderUpdateData['order_amount_paid'] = $order['order_amount_paid'] + $payAmount;
|
|
|
|
+ $orderUpdateData['order_amount_pay'] = $order['order_amount_pay'] + $payAmount;
|
|
|
|
+ if ($order['order_amount_paid'] + $payAmount >= $order['order_amount_total']) {
|
|
|
|
+ $orderUpdateData['order_status_payment'] = 'SUCCESS';
|
|
|
|
+ $orderUpdateData['order_status_system'] = 'DONE';
|
|
|
|
+ $orderUpdateData['order_is_complete'] = 'Y';
|
|
}
|
|
}
|
|
- $order->save();
|
|
|
|
|
|
+ // 主订单
|
|
|
|
+ Order::where('order_groupby', $groupId)->update($orderUpdateData);
|
|
// Sheet
|
|
// Sheet
|
|
- if ($order->order_status_payment == 'SUCCESS') {
|
|
|
|
- OrderSheet::where('join_sheet_order_id', $orderId)->where('order_sheet_status', 'PAYING')->update(['order_sheet_status' => 'DONE']);
|
|
|
|
- }
|
|
|
|
|
|
+ OrderSheet::where('join_sheet_order_id', $order['order_id'])->where('order_sheet_status', 'PAYING')->update(['order_sheet_status' => 'DONE']);
|
|
// 支付记录
|
|
// 支付记录
|
|
- PayDetail::where('join_pay_order_id', $order->order_groupby)->where('pay_prepayid', 'ALIPAY')->update(['pay_status' => 'SUCCESS']);
|
|
|
|
- // 其他支付方式 扣
|
|
|
|
-// $this->deductAccount($order->order_groupby, 'ALIPAY');
|
|
|
|
- // 优惠券标记使用
|
|
|
|
- $this->changeOrderCouponStatus($discountJson, 'USED');
|
|
|
|
- Db::commit();
|
|
|
|
- return json_success('success');
|
|
|
|
|
|
+ PayDetail::where('join_pay_order_id', $order['order_groupby'])->where('pay_prepayid', 'ALIPAY')->update(['pay_status' => 'SUCCESS']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if ($payStatus == 'Y') {
|
|
|
|
+ if ($order['order_amount_paid'] + $payAmount >= $order['order_amount_total']) {
|
|
|
|
+ $params['member_id'] = $order['join_order_member_id'];
|
|
|
|
+ $params['orderId'] = $order['order_id'];
|
|
|
|
+ $params['order_amount_pay'] = $payAmount;
|
|
|
|
+ $params['order_amount_total'] = $order['order_amount_total'];
|
|
|
|
+ $params['join_sheet_goods_id'] = $sheet->join_sheet_goods_id;
|
|
|
|
+ if (!empty($order['order_extend_json'])) {
|
|
|
|
+ $orderExtendJson = json_decode($order['order_extend_json'], true);
|
|
|
|
+ $params['dept_id'] = $orderExtendJson['dept_id'] ?? '';
|
|
|
|
+ $params['dept_name'] = $orderExtendJson['dept_name'] ?? '';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Event::dispatch('order.partner.grant', $params);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Db::commit();
|
|
|
|
+ return json_success('success');
|
|
|
|
+ }
|
|
|
|
+
|
|
Db::rollBack();
|
|
Db::rollBack();
|
|
return json_fail('没有查询到记录');
|
|
return json_fail('没有查询到记录');
|
|
|
|
+ } catch (BusinessException $e) {
|
|
|
|
+ Db::rollBack();
|
|
|
|
+ _syslog("支付轮询", '订单支付异常:' . $e->getMessage());
|
|
|
|
+ return json_fail($e->getMessage());
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
dump($e->getMessage());
|
|
dump($e->getMessage());
|
|
Db::rollBack();
|
|
Db::rollBack();
|