|
@@ -44,7 +44,6 @@ use support\Response;
|
|
|
use Tinywan\Jwt\JwtToken;
|
|
|
use Webman\Event\Event;
|
|
|
use Yansongda\Pay\Pay;
|
|
|
-use function Qiniu\Http\Middleware\compose;
|
|
|
|
|
|
class WholeController extends Curd
|
|
|
{
|
|
@@ -71,6 +70,11 @@ class WholeController extends Curd
|
|
|
$where['order_addtimes'][0] = strtotime($where['order_addtimes'][0]);
|
|
|
$where['order_addtimes'][1] = strtotime($where['order_addtimes'][1]);
|
|
|
}
|
|
|
+ if ($request->get('goods_classify') && $request->get('goods_classify') == 'SERVICE') {
|
|
|
+ $where['order_classify'] = ['in', 'SERVICE,CHNMED,CHNNCD'];
|
|
|
+ } else if ($request->get('goods_classify')) {
|
|
|
+ $where['order_classify'] = $request->get('goods_classify');
|
|
|
+ }
|
|
|
|
|
|
$order = $request->get('order', 'desc');
|
|
|
$type = $request->get('type', '');
|
|
@@ -132,14 +136,12 @@ class WholeController extends Curd
|
|
|
}
|
|
|
if ($request->get('goods_classify') || $request->get('goods_name')) {
|
|
|
$orderGoodsIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
|
|
|
-// if ($orderGoodsIds) {
|
|
|
if (!empty($where['order_id'])) {
|
|
|
$orderIds = array_intersect($orderIds, $orderGoodsIds);
|
|
|
$where['order_id'] = ['in', implode(',', $orderIds)];
|
|
|
} else {
|
|
|
$where['order_id'] = ['in', implode(',', $orderGoodsIds)];
|
|
|
}
|
|
|
-// }
|
|
|
} elseif (!empty($orderIds)) {
|
|
|
$where['order_id'] = ['in', implode(',', $orderIds)];
|
|
|
}
|
|
@@ -819,17 +821,25 @@ class WholeController extends Curd
|
|
|
|
|
|
$systemStatus = 'SENDING'; // 待发货
|
|
|
// 立即结算
|
|
|
- if (in_array($params['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'MEALS', 'VIP'])) {
|
|
|
+ if (in_array($params['goods_classify'], ['MEALS', 'VIP'])) {
|
|
|
$order->order_is_complete = 'Y';
|
|
|
$systemStatus = 'DONE';
|
|
|
}
|
|
|
- if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') {
|
|
|
+ if (in_array($params['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE']) && $params['delivery'] == 'ARRIVAL') {
|
|
|
+ $params['order_is_complete'] = 'N';
|
|
|
$systemStatus = "WAITING";
|
|
|
}
|
|
|
+// if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') {
|
|
|
+// $systemStatus = "WAITING";
|
|
|
+// }
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
// 使用优惠券
|
|
|
$couponUseJson = [];
|
|
|
+ if (!empty($order->order_discount_json)) {
|
|
|
+ // 释放下单时选的优惠券
|
|
|
+ $order->order_discount_json = $this->releaseCoupon(json_decode($order->order_discount_json, true));
|
|
|
+ }
|
|
|
if (!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']) {
|
|
@@ -838,12 +848,12 @@ class WholeController 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)));
|
|
|
- }
|
|
|
- }
|
|
|
+// 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)));
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
}
|
|
|
// 存储优惠信息
|
|
@@ -1302,6 +1312,9 @@ class WholeController extends Curd
|
|
|
|
|
|
if ($order->order_status_payment != 'SUCCESS') {
|
|
|
_syslog("订单", "支付异常,检查是否有轮询");
|
|
|
+ // 恢复优惠券到已占用
|
|
|
+ $this->changeOrderCouponStatus(json_decode($couponUseJson, true), 'WAITING');
|
|
|
+
|
|
|
return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
|
|
|
}
|
|
|
_syslog("订单", "订单支付成功");
|
|
@@ -1423,17 +1436,22 @@ class WholeController extends Curd
|
|
|
|
|
|
$systemStatus = 'SENDING'; // 待发货
|
|
|
// 立即结算
|
|
|
- if (in_array($params['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'MEALS', 'VIP'])) {
|
|
|
+ if (in_array($params['goods_classify'], ['MEALS', 'VIP'])) {
|
|
|
$order->order_is_complete = 'Y';
|
|
|
$systemStatus = 'DONE';
|
|
|
}
|
|
|
- if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') {
|
|
|
+ if (in_array($params['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE']) && $params['delivery'] == 'ARRIVAL') {
|
|
|
+ $params['order_is_complete'] = 'N';
|
|
|
$systemStatus = "WAITING";
|
|
|
}
|
|
|
$payDetail = PayDetail::where('join_pay_order_id', $order->order_groupby)->first();
|
|
|
Db::beginTransaction();
|
|
|
try {// 使用优惠券
|
|
|
$couponUseJson = [];
|
|
|
+ if (!empty($order->order_discount_json)) {
|
|
|
+ // 释放下单时选的优惠券
|
|
|
+ $order->order_discount_json = $this->releaseCoupon(json_decode($order->order_discount_json, true));
|
|
|
+ }
|
|
|
if (!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']) {
|
|
@@ -1442,12 +1460,12 @@ class WholeController 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)));
|
|
|
- }
|
|
|
- }
|
|
|
+// 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)));
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
}
|
|
|
// 存储优惠信息
|
|
@@ -1744,6 +1762,8 @@ class WholeController extends Curd
|
|
|
}
|
|
|
if ($order->order_status_payment != 'SUCCESS') {
|
|
|
_syslog("订单", "支付异常,检查是否有轮询");
|
|
|
+ // 恢复优惠券到已占用
|
|
|
+ $this->changeOrderCouponStatus(json_decode($couponUseJson, true), 'WAITING');
|
|
|
return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
|
|
|
}
|
|
|
_syslog("订单", "订单支付成功");
|
|
@@ -1989,11 +2009,12 @@ class WholeController extends Curd
|
|
|
$systemStatus = 'SENDING'; // 待发货
|
|
|
// 立即结算
|
|
|
if ($params['settlement_now'] == 'Y') {
|
|
|
- if (in_array($params['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'MEALS', 'VIP'])) {
|
|
|
+ if (in_array($params['goods_classify'], ['MEALS', 'VIP'])) {
|
|
|
$params['order_is_complete'] = 'Y';
|
|
|
$systemStatus = 'DONE';
|
|
|
}
|
|
|
- if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') {
|
|
|
+ if (in_array($params['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE']) && $params['delivery'] == 'ARRIVAL') {
|
|
|
+ $params['order_is_complete'] = 'N';
|
|
|
$systemStatus = "WAITING";
|
|
|
}
|
|
|
}
|
|
@@ -2365,7 +2386,7 @@ class WholeController extends Curd
|
|
|
if ($params['order_status_payment'] == 'SUCCESS') {
|
|
|
foreach ($params['goodsContentList'] as $goods) {
|
|
|
$params['join_sheet_goods_id'] = $goods['goods_id'];
|
|
|
- if (isset($goods['goods_classify']) && in_array($goods['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD'])) {
|
|
|
+ if (isset($goods['goods_classify']) && in_array($goods['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD']) && $params['delivery'] == 'ARRIVAL') {
|
|
|
$params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
|
|
|
$params['join_sheet_goods_sku_id'] = $goods['sku_id'];
|
|
|
$params['goods_id'] = $goods['goods_id'];
|
|
@@ -2380,7 +2401,7 @@ class WholeController extends Curd
|
|
|
$goods['category'] = $goods['goods_classify'];
|
|
|
// 权益表
|
|
|
$this->insertMemberBenefit($params, $goods);
|
|
|
- } elseif (isset($goods['goods_classify']) && $goods['goods_classify'] == 'PACKAGE') { // 一个套餐买多个
|
|
|
+ } elseif (isset($goods['goods_classify']) && $goods['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') { // 一个套餐买多个
|
|
|
$params['packageId'] = $goods['goods_id'];
|
|
|
$components = GoodsComponent::with([
|
|
|
'goods' => function ($query) {
|
|
@@ -2481,6 +2502,9 @@ class WholeController extends Curd
|
|
|
|
|
|
if ($params['settlement_now'] == 'Y' && $params['order_status_payment'] != 'SUCCESS') {
|
|
|
_syslog("订单", "支付异常,检查是否有轮询");
|
|
|
+ // 恢复优惠券到已占用
|
|
|
+ $this->changeOrderCouponStatus(json_decode($couponUseJson, true), 'WAITING');
|
|
|
+
|
|
|
return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
|
|
|
}
|
|
|
_syslog("订单", "创建订单成功");
|
|
@@ -2500,6 +2524,68 @@ class WholeController extends Curd
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Desc 修改优惠券状态
|
|
|
+ * @Author Gorden
|
|
|
+ * @Date 2024/9/19 9:03
|
|
|
+ *
|
|
|
+ * @param $coupon
|
|
|
+ * @param $status
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private function changeOrderCouponStatus($coupon, $status)
|
|
|
+ {
|
|
|
+ if (!empty($coupon) && is_array($coupon)) {
|
|
|
+ $updateData['coupon_detail_status'] = $status;
|
|
|
+ if ($status == 'ACTIVED' || $status == 'WAITING') {
|
|
|
+ $updateData['coupon_detail_used_datetime'] = '';
|
|
|
+ } elseif ($status == 'USED') {
|
|
|
+ $updateData['coupon_detail_used_datetime'] = date('Y-m-d H:i:s');
|
|
|
+ }
|
|
|
+ foreach ($coupon as $item) {
|
|
|
+ if (!empty($item['coupon_id']) && !empty($item['coupon_detail_id'])) {
|
|
|
+ foreach ($item['coupon_detail_id'] as $detailId) {
|
|
|
+ CouponDetail::where('join_detail_coupon_id', $item['coupon_id'])
|
|
|
+ ->where('coupon_detail_id', $detailId)->update($updateData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 组合支付下单
|
|
|
*/
|
|
@@ -2595,11 +2681,12 @@ class WholeController extends Curd
|
|
|
$systemStatus = 'SENDING'; // 待发货
|
|
|
// 立即结算
|
|
|
if ($params['settlement_now'] == 'Y') {
|
|
|
- if (in_array($params['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'MEALS', 'VIP'])) {
|
|
|
+ if (in_array($params['goods_classify'], ['MEALS', 'VIP'])) {
|
|
|
$params['order_is_complete'] = 'Y';
|
|
|
$systemStatus = 'DONE';
|
|
|
}
|
|
|
- if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') {
|
|
|
+ if (in_array($params['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE']) && $params['delivery'] == 'ARRIVAL') {
|
|
|
+ $params['order_is_complete'] = 'N';
|
|
|
$systemStatus = "WAITING";
|
|
|
}
|
|
|
}
|
|
@@ -2849,7 +2936,7 @@ class WholeController extends Curd
|
|
|
if ($params['order_status_payment'] == 'SUCCESS') {
|
|
|
foreach ($params['goodsContentList'] as $goods) {
|
|
|
$params['join_sheet_goods_id'] = $goods['goods_id'];
|
|
|
- if (isset($goods['goods_classify']) && in_array($goods['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD'])) {
|
|
|
+ if (isset($goods['goods_classify']) && in_array($goods['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD']) && $params['delivery'] == 'ARRIVAL') {
|
|
|
$params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
|
|
|
$params['join_sheet_goods_sku_id'] = $goods['sku_id'];
|
|
|
$params['goods_id'] = $goods['goods_id'];
|
|
@@ -2864,7 +2951,7 @@ class WholeController extends Curd
|
|
|
$goods['category'] = $goods['goods_classify'];
|
|
|
// 权益表
|
|
|
$this->insertMemberBenefit($params, $goods);
|
|
|
- } elseif (isset($goods['goods_classify']) && $goods['goods_classify'] == 'PACKAGE') { // 一个套餐买多个
|
|
|
+ } elseif (isset($goods['goods_classify']) && $goods['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') { // 一个套餐买多个
|
|
|
$params['packageId'] = $goods['goods_id'];
|
|
|
$components = GoodsComponent::with([
|
|
|
'goods' => function ($query) {
|
|
@@ -2964,6 +3051,9 @@ class WholeController extends Curd
|
|
|
|
|
|
if ($params['settlement_now'] == 'Y' && $params['order_status_payment'] != 'SUCCESS') {
|
|
|
_syslog("订单", "支付异常,检查是否有轮询");
|
|
|
+ // 恢复优惠券到已占用
|
|
|
+ $this->changeOrderCouponStatus(json_decode($couponUseJson, true), 'WAITING');
|
|
|
+
|
|
|
return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
|
|
|
}
|
|
|
_syslog("订单", "创建订单成功");
|
|
@@ -3793,27 +3883,34 @@ class WholeController extends Curd
|
|
|
'dept_premises_id' => $request->post('dept_premises_id'),
|
|
|
'order_remark' => $request->post('remark'),
|
|
|
'write_off_member_id' => $request->post('write_off_member_id'),
|
|
|
- 'join_order_member_id' => $memberId
|
|
|
+ 'join_order_member_id' => $memberId,
|
|
|
+ 'charge_waiter' => $request->post('charge_waiter'),
|
|
|
];
|
|
|
$writeOffData = OrderService::generateWriteOffData($params);
|
|
|
|
|
|
// 开始减额度
|
|
|
+ $benefitUsed = [];
|
|
|
+ $appointmentIds = [];
|
|
|
foreach ($benefits as $benefit) {
|
|
|
foreach ($benefitList as $list) {
|
|
|
if ($list['member_benefit_id'] == $benefit['member_benefit_id']) {
|
|
|
$usedCount = $benefit['member_benefit_used_count'] + intval($list['nbr']);
|
|
|
+ $benefitUpdateData = ['member_benefit_used_count' => $usedCount];
|
|
|
// 用完了
|
|
|
if ($benefit['member_benefit_limit_count'] <= $usedCount && !empty($benefit['join_benefit_order_id'])) {
|
|
|
- Order::where('order_id', $benefit['join_benefit_order_id'])->update(['order_status_system' => 'DONE']);
|
|
|
+ $benefitUpdateData['member_benefit_status'] = 'DONE';
|
|
|
+ $benefitUsed[$benefit['join_benefit_order_id']][] = $benefit['member_benefit_id'];
|
|
|
+// Order::where('order_id', $benefit['join_benefit_order_id'])->update(['order_status_system' => 'DONE']);
|
|
|
}
|
|
|
// 更新benefit 表
|
|
|
- MemberBenefit::where('member_benefit_id', $benefit['member_benefit_id'])->update(['member_benefit_used_count' => $usedCount]);
|
|
|
+ MemberBenefit::where('member_benefit_id', $benefit['member_benefit_id'])->update($benefitUpdateData);
|
|
|
// 更新Appointment 表
|
|
|
$appointments = Appointment::where('join_appointment_member_benefit_id', $benefit['member_benefit_id'])
|
|
|
->where('appointment_status', 'INIT')
|
|
|
->limit(intval($list['nbr']))
|
|
|
->get();
|
|
|
foreach ($appointments as $appointment) {
|
|
|
+ $appointmentIds[] = $appointment->appointment_id;
|
|
|
Appointment::where('appointment_id', $appointment->appointment_id)->update([
|
|
|
'appointment_status' => 'DONE',
|
|
|
'appointment_datetime' => $times,
|
|
@@ -3826,6 +3923,46 @@ class WholeController extends Curd
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // 订单服务是否用完了
|
|
|
+ foreach ($benefitUsed as $key => $item) {
|
|
|
+ $orderUsedComplete = 'Y';
|
|
|
+ $orderBenefits = MemberBenefit::where('join_benefit_order_id', $key)->get()->toArray();
|
|
|
+ foreach ($orderBenefits as $orderBenefit) {
|
|
|
+ if ($orderBenefit['member_benefit_used_count'] >= $orderBenefit['member_benefit_limit_count']) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!in_array($orderBenefit['member_benefit_id'], $item)) {
|
|
|
+ $orderUsedComplete = 'N';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($orderUsedComplete == 'Y') {
|
|
|
+ Order::where('order_id', $key)->update(['order_is_complete' => 'Y', 'order_status_system' => 'DONE']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 核销服务回写process
|
|
|
+ foreach ($benefits as $benefit) {
|
|
|
+ foreach ($benefitList as $list) {
|
|
|
+ if ($list['member_benefit_id'] == $benefit['member_benefit_id'] && (!empty($benefit['join_benefit_goods_id']) || !empty($benefit['join_benefit_package_id'])) && !empty($benefit['join_benefit_order_id'])) {
|
|
|
+ $dept = [];
|
|
|
+ if (!empty($params['dept_premises_id'])) {
|
|
|
+ $dept = SysDept::where('dept_id', $params['dept_premises_id'])
|
|
|
+ ->orWhere('dept_name', $params['dept_premises_id'])
|
|
|
+ ->select('dept_id', 'dept_name', 'dept_status', 'dept_category', 'dept_super_id', 'dept_super_path')
|
|
|
+ ->first();
|
|
|
+ }
|
|
|
+ $params['charge_amount'] = $list['nbr'];
|
|
|
+ $params['goods_id'] = !empty($benefit['join_benefit_goods_id']) ? $benefit['join_benefit_goods_id'] : (!empty($benefit['join_benefit_package_id']) ? $benefit['join_benefit_package_id'] : '');
|
|
|
+ $params['goods_sku_id'] = $benefit['join_benefit_goods_sku_id'];
|
|
|
+ $params['order_id'] = $benefit['join_benefit_order_id'];
|
|
|
+ $params['appointment_ids'] = $appointmentIds;
|
|
|
+ $params['dept'] = $dept;
|
|
|
+ $params['write_off_data'] = OrderService::generateWriteOffDataByOrderProcess($params);
|
|
|
+ // 触发事件
|
|
|
+ Event::dispatch('order.write_off', $params);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
Redis::del($key);
|
|
|
|
|
@@ -3834,7 +3971,7 @@ class WholeController extends Curd
|
|
|
_syslog("订单", "核销成功");
|
|
|
return json_success('核销成功');
|
|
|
} catch (\Exception $e) {
|
|
|
- dump($e->getMessage());
|
|
|
+ dump($e->getMessage() . $e->getLine());
|
|
|
Db::rollBack();
|
|
|
_syslog("订单", "核销失败");
|
|
|
return json_fail('核销失败');
|
|
@@ -4127,6 +4264,13 @@ class WholeController extends Curd
|
|
|
{
|
|
|
$type = $request->get('type', '');
|
|
|
[$where, $format, $limit, $field, $order] = $this->selectInput($request);
|
|
|
+
|
|
|
+ if ($request->get('goods_classify') && $request->get('goods_classify') == 'SERVICE') {
|
|
|
+ $where['order_classify'] = ['in', 'SERVICE,CHNMED,CHNNCD'];
|
|
|
+ } else if ($request->get('goods_classify')) {
|
|
|
+ $where['order_classify'] = $request->get('goods_classify');
|
|
|
+ }
|
|
|
+
|
|
|
$where['order_category'] = ['<>', 'RECHARGE'];
|
|
|
if (!empty($request->get('order_ids'))) {
|
|
|
$where['order_id'] = ['in', $request->get('order_ids')];
|
|
@@ -4149,32 +4293,30 @@ class WholeController extends Curd
|
|
|
->toArray();
|
|
|
$where['order_groupby'] = ['in', $groupIds];
|
|
|
}
|
|
|
- if ($request->get('goods_classify') || $request->get('goods_name')) {
|
|
|
- $where['order_id'] = '';
|
|
|
- $goodsClassify = $request->get('goods_classify', '');
|
|
|
- $goodsName = $request->get('goods_name', '');
|
|
|
- if (!empty($goodsName) && empty($goodsClassify)) {
|
|
|
- $goodsIds = Goods::where('goods_name', 'like', '%' . $request->get('goods_name') . '%')->pluck('goods_id')->toArray();
|
|
|
- } else if (!empty($goodsClassify)) {
|
|
|
- if ($goodsClassify == 'SERVICE') {
|
|
|
- $goodsModel = Goods::whereIn('goods_classify', ['SERVICE', 'CHNMED', 'CHNNCD']);
|
|
|
- } else {
|
|
|
- $goodsModel = Goods::where('goods_classify', $goodsClassify);
|
|
|
- }
|
|
|
-
|
|
|
- if (!empty($goodsName)) {
|
|
|
- $goodsModel->where('goods_name', 'like', '%' . $goodsName . '%');
|
|
|
- }
|
|
|
-
|
|
|
- $goodsIds = $goodsModel->pluck('goods_id')->toArray();
|
|
|
- }
|
|
|
- if ($goodsIds) {
|
|
|
- $orderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
|
|
|
- if ($orderIds) {
|
|
|
- $where['order_id'] = ['in', implode(',', $orderIds)];
|
|
|
- }
|
|
|
+ $orderId = trim($request->get('order_id', ''));
|
|
|
+ $orderIds = [];
|
|
|
+ if (!empty($orderId)) {
|
|
|
+ $orderIds = Order::where('order_id', 'like', '%' . $orderId . '%')
|
|
|
+ ->whereIn('order_classify', ['SERVICE', 'CHNMED', 'CHNNCD'])
|
|
|
+ ->pluck('order_id')
|
|
|
+ ->toArray();
|
|
|
+ }
|
|
|
+ $goodsName = trim($request->get('goods_name', ''));
|
|
|
+ if (!empty($goodsName)) {
|
|
|
+ $goodsIds = Goods::whereIn('goods_classify', ['SERVICE', 'CHNMED', 'CHNNCD'])
|
|
|
+ ->where('goods_name', 'like', '%' . $goodsName . '%')
|
|
|
+ ->pluck('goods_id')
|
|
|
+ ->toArray();
|
|
|
+ $goodsOrderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
|
|
|
+ if (!empty($where['order_id'])) {
|
|
|
+ $orderIds = array_intersect($orderIds, $goodsOrderIds);
|
|
|
+ } else {
|
|
|
+ $orderIds = $goodsOrderIds;
|
|
|
}
|
|
|
}
|
|
|
+ if (!empty($orderId) || !empty($goodsName)) {
|
|
|
+ $where['order_id'] = ['in', implode(',', $orderIds)];
|
|
|
+ }
|
|
|
$order = $request->get('order', 'desc');
|
|
|
$field = $field ?? 'order_addtimes';
|
|
|
|
|
@@ -4240,7 +4382,7 @@ class WholeController extends Curd
|
|
|
])
|
|
|
->select('order_id', 'join_order_member_id', 'order_is_complete', 'order_status_system')
|
|
|
->where("order_is_complete", 'N')
|
|
|
- ->whereIn("order_category", ['NORMAL', 'SYSTEM'])
|
|
|
+// ->whereIn("order_category", ['NORMAL', 'SYSTEM'])
|
|
|
->orderBy('order_addtimes', 'DESC')
|
|
|
->get()
|
|
|
->toArray();
|
|
@@ -4255,6 +4397,9 @@ class WholeController extends Curd
|
|
|
foreach ($order['benefit'] as $benefit) {
|
|
|
$benefit['member_benefit_limit_count'] = intval($benefit['member_benefit_limit_count']);
|
|
|
$benefit['member_benefit_used_count'] = intval($benefit['member_benefit_used_count']);
|
|
|
+ if ($benefit['member_benefit_used_count'] >= $benefit['member_benefit_limit_count']) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
$benefit['unused'] = $benefit['member_benefit_limit_count'] - $benefit['member_benefit_used_count'];
|
|
|
$orderOne['benefit'] = $benefit;
|
|
|
$orderOne['member_benefit_id'] = $benefit['member_benefit_id'];
|
|
@@ -4442,6 +4587,11 @@ class WholeController extends Curd
|
|
|
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');
|
|
|
}
|
|
@@ -4453,10 +4603,10 @@ class WholeController extends Curd
|
|
|
$result = Pay::wechat(config('payment.wxpay'))->find($order->order_groupby, 'pos');
|
|
|
$result = json_decode(json_encode($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') {
|
|
|
+ $order->order_status_payment = 'SUCCESS';
|
|
|
if (in_array($order->order_category, ['SERVICE', 'CHNMED', 'CHNNCD', 'DISHES', 'MEALS', 'VIP'])) {
|
|
|
$order->order_is_complete = 'Y';
|
|
|
$order->order_status_system = 'DONE';
|
|
|
- $order->order_status_payment = 'SUCCESS';
|
|
|
} else {
|
|
|
$order->order_status_system = 'SENDING';
|
|
|
}
|
|
@@ -4465,6 +4615,8 @@ class WholeController extends Curd
|
|
|
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');
|
|
|
|
|
|
Db::commit();
|
|
|
return json_success('success');
|
|
@@ -4485,7 +4637,8 @@ class WholeController extends Curd
|
|
|
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', 'ALIPAY')->update(['pay_status' => 'SUCCESS']);
|
|
|
-
|
|
|
+ // 优惠券标记使用
|
|
|
+ $this->changeOrderCouponStatus($discountJson, 'USED');
|
|
|
Db::commit();
|
|
|
return json_success('success');
|
|
|
}
|