|
@@ -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,13 +821,17 @@ 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 {
|
|
|
// 使用优惠券
|
|
@@ -1423,11 +1429,12 @@ 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();
|
|
@@ -1989,11 +1996,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 +2373,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 +2388,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) {
|
|
@@ -2595,11 +2603,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 +2858,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 +2873,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) {
|
|
@@ -3793,27 +3802,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 +3842,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 +3890,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 +4183,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,31 +4212,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;
|
|
|
}
|
|
|
+ dump($orderIds);
|
|
|
+ }
|
|
|
+ if (!empty($orderId) || !empty($goodsName)) {
|
|
|
+ $where['order_id'] = ['in', implode(',', $orderIds)];
|
|
|
}
|
|
|
$order = $request->get('order', 'desc');
|
|
|
$field = $field ?? 'order_addtimes';
|
|
@@ -4240,7 +4302,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 +4317,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'];
|