|
@@ -4,7 +4,14 @@ namespace app\admin\service\order;
|
|
|
|
|
|
use app\model\Appointment;
|
|
|
use app\model\Goods;
|
|
|
+use app\model\Member;
|
|
|
+use app\model\MemberAccount;
|
|
|
use app\model\MemberBenefit;
|
|
|
+use app\model\MemberCert;
|
|
|
+use app\model\MemberInfo;
|
|
|
+use app\model\Order;
|
|
|
+use app\model\OrderSheet;
|
|
|
+use app\model\PayDetail;
|
|
|
use app\model\SysSerial;
|
|
|
use support\Db;
|
|
|
use support\Request;
|
|
@@ -20,7 +27,6 @@ class AppointmentService
|
|
|
$mobile = $request->get('mobile', '');
|
|
|
$status = $request->get('status', '');
|
|
|
|
|
|
-
|
|
|
$rows = Db::table('appointment')
|
|
|
->leftJoin('member', 'member.member_id', '=', 'appointment.join_appointment_member_id')
|
|
|
->leftJoin('member_cert', 'member_cert.join_cert_member_id', '=', 'appointment.join_appointment_member_id')
|
|
@@ -57,12 +63,16 @@ class AppointmentService
|
|
|
$row->goods_sku_specs_json = !empty($row->goods_sku_specs_json) ? json_decode($row->goods_sku_specs_json, true) : [];
|
|
|
$row->order_addtimes = date('Y-m-d H:i:s', $row->order_addtimes);
|
|
|
$row->appointment_addtimes = date('Y-m-d H:i:s', $row->appointment_addtimes);
|
|
|
- $row->appointment_apply_json = !empty($row->appointment_apply_json) ? json_decode($row->appointment_apply_json) : [];
|
|
|
+// $row->appointment_apply_json = !empty($row->appointment_apply_json) ? json_decode($row->appointment_apply_json) : [];
|
|
|
if ($row->appointment_category == 'NOFEE') {
|
|
|
$row->member_benefit_name = "后付费预约";
|
|
|
}
|
|
|
+ if (!empty($row->appointment_apply_json)) {
|
|
|
+ $applyJson = json_decode($row->appointment_apply_json, true);
|
|
|
+ $row->person = $applyJson['person'] ?? '';
|
|
|
+ $row->appointment_times = $applyJson['times'] ?? '';
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
return json_success('', compact('rows', 'page', 'pageSize', 'total'));
|
|
|
}
|
|
|
|
|
@@ -89,12 +99,81 @@ class AppointmentService
|
|
|
$params = $request->post();
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
+ // 先检查选择的时段是否可预约
|
|
|
+ $goods = Goods::where('goods_id', $params['join_appointment_goods_id'])->first();
|
|
|
+ $appointments = Appointment::where('appointment_datetime', $params['appointment_datetime'])->get()->toArray();
|
|
|
+ if ($goods->is_support_appointment == 'Y' && !empty($goods->goods_extend_json)) {
|
|
|
+ // {"times": [{"person": 2, "appointmentTimeEnd": "07:00", "appointmentTimeStart": "06:30"}, {"person": 3, "appointmentTimeEnd": "07:30", "appointmentTimeStart": "07:00"}]}
|
|
|
+ $extendJson = json_decode($goods->goods_extend_json, true);
|
|
|
+ foreach ($extendJson['times'] as $key => $time) {
|
|
|
+ $timesStr = $time['appointmentTimeStart'] . '~' . $time['appointmentTimeEnd'];
|
|
|
+ if ($timesStr == $params['appointment_times']) {
|
|
|
+ foreach ($appointments as $appointment) {
|
|
|
+ $applyJson = json_decode($appointment['appointment_apply_json'], true);
|
|
|
+ $applyJsonTimes = $applyJson['times'] ?? '';
|
|
|
+
|
|
|
+ if ($timesStr == $applyJsonTimes) {
|
|
|
+ $extendJson['times'][$key]['person'] -= $applyJson['person'];
|
|
|
+ if ($extendJson['times'][$key]['person'] < $params['person']) {
|
|
|
+ return json_fail('当前时段已满员,请选择其他时段');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果没有,新建
|
|
|
+ if (empty($params['join_appointment_member_id']) && !empty($params['username']) && !empty($params['mobile'])) {
|
|
|
+ $memberId = "ME" . str_pad(SysSerial::getSerial(), 16, "0", STR_PAD_LEFT) . random_string(6, 'up');
|
|
|
+ $params['join_appointment_member_id'] = $memberId;
|
|
|
+
|
|
|
+ // 主表
|
|
|
+ $memberData = [
|
|
|
+ 'member_id' => $memberId,
|
|
|
+ 'member_is_owner' => 'N',
|
|
|
+ 'member_classify' => 'MEMBER',
|
|
|
+ 'member_status' => 'ACTIVED',
|
|
|
+ 'member_mobile' => $params['mobile'],
|
|
|
+ 'member_from' => 'backstage',
|
|
|
+ 'member_addtimes' => time()
|
|
|
+ ];
|
|
|
+ Member::insert($memberData);
|
|
|
+ // 账户表
|
|
|
+ $accountData = [
|
|
|
+ 'join_account_member_id' => $memberId,
|
|
|
+ 'member_account_classify' => 'POINTS',
|
|
|
+ 'member_account_status' => 'ACTIVED',
|
|
|
+ 'member_account_category' => 'NORMAL',
|
|
|
+ 'member_account_nbr' => $memberId . '-POINTS',
|
|
|
+ 'member_account_name' => '积分账户',
|
|
|
+ 'member_account_addtimes' => time()
|
|
|
+ ];
|
|
|
+ // 积分账户
|
|
|
+ MemberAccount::insert($accountData);
|
|
|
+ $accountData['member_account_classify'] = 'CASH';
|
|
|
+ $accountData['member_account_nbr'] = $memberId . '-CASH';
|
|
|
+ $accountData['member_account_name'] = '余额账户';
|
|
|
+ // 现金/余额账户
|
|
|
+ MemberAccount::insert($accountData);
|
|
|
+ // cert
|
|
|
+ $certData = [
|
|
|
+ 'join_cert_member_id' => $memberId,
|
|
|
+ 'member_cert_name' => $params['username']
|
|
|
+ ];
|
|
|
+ MemberCert::insert($certData);
|
|
|
+ // info
|
|
|
+ $infoData = [
|
|
|
+ 'join_info_member_id' => $memberId,
|
|
|
+ 'member_info_nickname' => $params['username']
|
|
|
+ ];
|
|
|
+ MemberInfo::insert($infoData);
|
|
|
+ }
|
|
|
$data = [
|
|
|
'appointment_id' => "AP" . str_pad(SysSerial::getSerial(), 16, '0') . random_string(6, 'up'),
|
|
|
'join_appointment_member_id' => $params['join_appointment_member_id'] ?? '',
|
|
|
'join_appointment_goods_id' => $params['join_appointment_goods_id'] ?? '',
|
|
|
'appointment_status' => $params['appointment_status'] ?? '',
|
|
|
- 'appointment_datetime' => isset($params['appointment_datetime']) ? date('Y-m-d H:i:s', strtotime($params['appointment_datetime'])) : '',
|
|
|
+ 'appointment_datetime' => isset($params['appointment_datetime']) ? date('Y-m-d', strtotime($params['appointment_datetime'])) : '',
|
|
|
'appointment_apply_datetime' => isset($params['appointment_apply_datetime']) ? date('Y-m-d H:i:s', strtotime($params['appointment_apply_datetime'])) : '',
|
|
|
'appointment_doing_datetime' => isset($params['appointment_doing_datetime']) ? date('Y-m-d H:i:s', strtotime($params['appointment_doing_datetime'])) : '',
|
|
|
'appointment_done_datetime' => isset($params['appointment_done_datetime']) ? date('Y-m-d H:i:s', strtotime($params['appointment_done_datetime'])) : '',
|
|
@@ -102,10 +181,103 @@ class AppointmentService
|
|
|
'appointment_remark' => $params['appointment_remark'] ?? '',
|
|
|
'appointment_category' => 'NOFEE',
|
|
|
'appointment_addtimes' => time(),
|
|
|
+ 'appointment_mode' => $params['appointment_mode'] ?? '',
|
|
|
+ 'settlement_mode' => $params['settlement_mode'] ?? '',
|
|
|
];
|
|
|
|
|
|
+ if (!empty($params['join_appointment_member_id'])) {
|
|
|
+ $member = Member::with([
|
|
|
+ 'cert' => function ($query) {
|
|
|
+ $query->select('join_cert_member_id', 'member_cert_name');
|
|
|
+ }
|
|
|
+ ])->where('member_id', $params['join_appointment_member_id'])
|
|
|
+ ->first()
|
|
|
+ ->toArray();
|
|
|
+ $data['appointment_apply_json'] = json_encode([
|
|
|
+ 'name' => !empty($member['cert']['member_cert_name']) ? $member['cert']['member_cert_name'] : $member['member_mobile'],
|
|
|
+ 'mobile' => $member['member_mobile'],
|
|
|
+ 'person' => $params['person'],
|
|
|
+ 'remark' => $data['appointment_remark'],
|
|
|
+ 'premises' => $params['premises'],
|
|
|
+ 'times' => $params['appointment_times']
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
Appointment::insert($data);
|
|
|
|
|
|
+ // 如果预约成功,生成订单
|
|
|
+ if ($params['appointment_status'] == 'PENDING') {
|
|
|
+ $orderId = 'OD' . date('YmdHis') . random_string(6, 'up');
|
|
|
+ $order = [
|
|
|
+ 'order_id' => $orderId,
|
|
|
+ 'join_order_member_id' => $params['join_appointment_member_id'],
|
|
|
+ 'order_name' => "预约-" . $goods->goods_name,
|
|
|
+ 'order_amount_total' => $goods->goods_sales_price * $params['person'],
|
|
|
+ 'order_amount_pay' => $goods->goods_sales_price * $params['person'],
|
|
|
+ 'order_is_complete' => 'N',
|
|
|
+ 'order_category' => 'OTHER',
|
|
|
+ 'order_status_system' => 'PAYING',
|
|
|
+ 'order_status_payment' => 'PENDING',
|
|
|
+ 'order_status_storage' => 'PENDING',
|
|
|
+ 'order_addtimes' => time()
|
|
|
+ ];
|
|
|
+ Order::insert($order);
|
|
|
+ // 订单详情
|
|
|
+ $sheet = [
|
|
|
+ 'join_sheet_member_id' => $params['join_appointment_member_id'],
|
|
|
+ 'join_sheet_order_id' => $orderId,
|
|
|
+ 'join_sheet_goods_id' => $params['join_appointment_goods_id'],
|
|
|
+ 'order_sheet_status' => 'PAYING',
|
|
|
+ 'order_sheet_category' => 'APPOINTMENT',
|
|
|
+ 'order_sheet_unit' => '套',
|
|
|
+ 'order_sheet_num' => $params['person'],
|
|
|
+ 'order_sheet_price' => $goods->goods_sales_price,
|
|
|
+ 'order_sheet_amount' => $goods->goods_sales_price * $params['person'],
|
|
|
+ 'order_sheet_pay' => $goods->goods_sales_price * $params['person'],
|
|
|
+ 'order_sheet_task_status' => 'NONE',
|
|
|
+ 'order_sheet_addtimes' => time()
|
|
|
+ ];
|
|
|
+ OrderSheet::insert($sheet);
|
|
|
+ // 订单号更新到预约
|
|
|
+ Appointment::where('appointment_id', $data['appointment_id'])->update(['join_appointment_order_id' => $orderId]);
|
|
|
+ // 支付数据
|
|
|
+ $pay = [
|
|
|
+ 'join_pay_member_id' => $params['join_appointment_member_id'],
|
|
|
+ 'join_pay_order_id' => $orderId,
|
|
|
+ 'pay_amount' => $sheet['order_sheet_pay'],
|
|
|
+ 'pay_remark' => '预约单',
|
|
|
+ 'pay_addtimes' => time()
|
|
|
+ ];
|
|
|
+ // 现金余额结算
|
|
|
+ if ($params['settlement_mode'] == 'CASH') {
|
|
|
+ $account = MemberAccount::where('join_account_member_id', $params['join_appointment_member_id'])
|
|
|
+ ->where('member_account_classify', 'CASH')
|
|
|
+ ->where('member_account_status', 'ACTIVED')
|
|
|
+ ->first();
|
|
|
+ if (!$account) {
|
|
|
+ Db::rollBack();
|
|
|
+ return json_fail('当前账户不存在或已过期');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($account->member_account_surplus < $sheet['order_sheet_pay']) {
|
|
|
+ $pay['pay_status'] = 'PENDING';
|
|
|
+ } else {
|
|
|
+ MemberAccount::where('member_account_id', $account->member_account_id)->update([
|
|
|
+ 'member_account_expend' => $account->member_account_expend + $sheet['order_sheet_pay'],
|
|
|
+ 'member_account_surplus' => $account->member_account_surplus - $sheet['order_sheet_pay']
|
|
|
+ ]);
|
|
|
+ $pay['pay_status'] = 'SUCCESS';
|
|
|
+ $pay['join_pay_object_json'] = json_encode(['payment' => ['member_account_id' => $account->member_account_id]]);
|
|
|
+ }
|
|
|
+ $pay['pay_category'] = 'CASH';
|
|
|
+ PayDetail::insert($pay);
|
|
|
+ }elseif ($params['settlement_mode'] == 'QRCODE'){
|
|
|
+ $pay['pay_category'] = 'QRCODE';
|
|
|
+ $pay['pay_status'] = 'SUCCESS';
|
|
|
+ PayDetail::insert($pay);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Db::commit();
|
|
|
return json_success("添加预约成功");
|
|
|
} catch (\Exception $e) {
|
|
@@ -126,21 +298,144 @@ class AppointmentService
|
|
|
$params = $request->post();
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
+ // 先检查选择的时段是否可预约
|
|
|
+ $goods = Goods::where('goods_id', $params['join_appointment_goods_id'])->first();
|
|
|
+ $appointments = Appointment::where('appointment_datetime', $params['appointment_datetime'])
|
|
|
+ ->where('appointment_id', '<>', $params['appointment_id'])
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ if ($goods->is_support_appointment == 'Y' && !empty($goods->goods_extend_json)) {
|
|
|
+ // {"times": [{"person": 2, "appointmentTimeEnd": "07:00", "appointmentTimeStart": "06:30"}, {"person": 3, "appointmentTimeEnd": "07:30", "appointmentTimeStart": "07:00"}]}
|
|
|
+ $extendJson = json_decode($goods->goods_extend_json, true);
|
|
|
+ foreach ($extendJson['times'] as $key => $time) {
|
|
|
+ $timesStr = $time['appointmentTimeStart'] . '~' . $time['appointmentTimeEnd'];
|
|
|
+ if ($timesStr == $params['appointment_times']) {
|
|
|
+ foreach ($appointments as $appointment) {
|
|
|
+ $applyJson = json_decode($appointment['appointment_apply_json'], true);
|
|
|
+ $applyJsonTimes = $applyJson['times'] ?? '';
|
|
|
+// dump($timesStr.'=='.$applyJsonTimes);
|
|
|
+ if ($timesStr == $applyJsonTimes) {
|
|
|
+ $extendJson['times'][$key]['person'] -= $applyJson['person'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($extendJson['times'][$key]['person'] < $params['person']) {
|
|
|
+ return json_fail('当前时段已满员,请选择其他时段');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
$data = [
|
|
|
'appointment_status' => $params['appointment_status'],
|
|
|
- 'appointment_datetime' => $params['appointment_datetime'] ? date('Y-m-d H:i:s', strtotime($params['appointment_datetime'])) : null,
|
|
|
+ 'appointment_datetime' => $params['appointment_datetime'] ? date('Y-m-d', strtotime($params['appointment_datetime'])) : null,
|
|
|
'appointment_apply_datetime' => $params['appointment_apply_datetime'] ? date('Y-m-d H:i:s', strtotime($params['appointment_apply_datetime'])) : null,
|
|
|
'appointment_doing_datetime' => $params['appointment_doing_datetime'] ? date('Y-m-d H:i:s', strtotime($params['appointment_doing_datetime'])) : null,
|
|
|
'appointment_done_datetime' => $params['appointment_done_datetime'] ? date('Y-m-d H:i:s', strtotime($params['appointment_done_datetime'])) : null,
|
|
|
'appointment_cancel_datetime' => $params['appointment_cancel_datetime'] ? date('Y-m-d H:i:s', strtotime($params['appointment_cancel_datetime'])) : null,
|
|
|
'appointment_remark' => $params['appointment_remark'] ?? '',
|
|
|
+ 'appointment_mode' => $params['appointment_mode'] ?? '',
|
|
|
+ 'settlement_mode' => $params['settlement_mode'] ?? '',
|
|
|
];
|
|
|
-
|
|
|
- Appointment::where('appointment_id', $appointmentId)->update($data);
|
|
|
// 如果是完成状态
|
|
|
if ($params['appointment_status'] == 'DONE' && $appointment->appointment_status != 'DONE') {
|
|
|
+ if (empty($params['appointment_done_datetime'])) {
|
|
|
+ $data['appointment_done_datetime'] = date('Y-m-d H:i:s');
|
|
|
+ }
|
|
|
MemberBenefit::where('member_benefit_id', $appointment->join_appointment_member_benefit_id)->increment('member_benefit_used_count');
|
|
|
}
|
|
|
+ if (!empty($params['join_appointment_member_id'])) {
|
|
|
+ $member = Member::with([
|
|
|
+ 'cert' => function ($query) {
|
|
|
+ $query->select('join_cert_member_id', 'member_cert_name');
|
|
|
+ }
|
|
|
+ ])->where('member_id', $params['join_appointment_member_id'])
|
|
|
+ ->first()
|
|
|
+ ->toArray();
|
|
|
+ $data['appointment_apply_json'] = json_encode([
|
|
|
+ 'name' => !empty($member['cert']['member_cert_name']) ? $member['cert']['member_cert_name'] : $member['member_mobile'],
|
|
|
+ 'mobile' => $member['member_mobile'],
|
|
|
+ 'person' => $params['person'],
|
|
|
+ 'remark' => $data['appointment_remark'],
|
|
|
+ 'premises' => $params['premises'],
|
|
|
+ 'times' => $params['appointment_times']
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ Appointment::where('appointment_id', $appointmentId)->update($data);
|
|
|
+
|
|
|
+ // 如果预约成功,没有生成过订单,生成订单
|
|
|
+ if ($params['appointment_status'] == 'PENDING' && empty($appointment->join_appointment_order_id)) {
|
|
|
+ $orderId = 'OD' . date('YmdHis') . random_string(6, 'up');
|
|
|
+ $order = [
|
|
|
+ 'order_id' => $orderId,
|
|
|
+ 'join_order_member_id' => $params['join_appointment_member_id'],
|
|
|
+ 'order_name' => "预约-" . $goods->goods_name,
|
|
|
+ 'order_amount_total' => $goods->goods_sales_price * $params['person'],
|
|
|
+ 'order_amount_pay' => $goods->goods_sales_price * $params['person'],
|
|
|
+ 'order_is_complete' => 'N',
|
|
|
+ 'order_category' => 'OTHER',
|
|
|
+ 'order_status_system' => 'PAYING',
|
|
|
+ 'order_status_payment' => 'PENDING',
|
|
|
+ 'order_status_storage' => 'PENDING',
|
|
|
+ 'order_addtimes' => time()
|
|
|
+ ];
|
|
|
+ Order::insert($order);
|
|
|
+ // 订单详情
|
|
|
+ $sheet = [
|
|
|
+ 'join_sheet_member_id' => $params['join_appointment_member_id'],
|
|
|
+ 'join_sheet_order_id' => $orderId,
|
|
|
+ 'join_sheet_goods_id' => $params['join_appointment_goods_id'],
|
|
|
+ 'order_sheet_status' => 'PAYING',
|
|
|
+ 'order_sheet_category' => 'APPOINTMENT',
|
|
|
+ 'order_sheet_unit' => '套',
|
|
|
+ 'order_sheet_num' => $params['person'],
|
|
|
+ 'order_sheet_price' => $goods->goods_sales_price,
|
|
|
+ 'order_sheet_amount' => $goods->goods_sales_price * $params['person'],
|
|
|
+ 'order_sheet_pay' => $goods->goods_sales_price * $params['person'],
|
|
|
+ 'order_sheet_task_status' => 'NONE',
|
|
|
+ 'order_sheet_addtimes' => time()
|
|
|
+ ];
|
|
|
+ OrderSheet::insert($sheet);
|
|
|
+ // 订单号更新到预约
|
|
|
+ Appointment::where('appointment_id', $data['appointment_id'])->update(['join_appointment_order_id' => $orderId]);
|
|
|
+
|
|
|
+ // 支付数据
|
|
|
+ $pay = [
|
|
|
+ 'join_pay_member_id' => $params['join_appointment_member_id'],
|
|
|
+ 'join_pay_order_id' => $orderId,
|
|
|
+ 'pay_amount' => $sheet['order_sheet_pay'],
|
|
|
+ 'pay_remark' => '预约单',
|
|
|
+ 'pay_addtimes' => time()
|
|
|
+ ];
|
|
|
+ // 现金余额结算
|
|
|
+ if ($params['settlement_mode'] == 'CASH') {
|
|
|
+ $account = MemberAccount::where('join_account_member_id', $params['join_appointment_member_id'])
|
|
|
+ ->where('member_account_classify', 'CASH')
|
|
|
+ ->where('member_account_status', 'ACTIVED')
|
|
|
+ ->first();
|
|
|
+ if (!$account) {
|
|
|
+ Db::rollBack();
|
|
|
+ return json_fail('当前账户不存在或已过期');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($account->member_account_surplus < $sheet['order_sheet_pay']) {
|
|
|
+ $pay['pay_status'] = 'PENDING';
|
|
|
+ } else {
|
|
|
+ MemberAccount::where('member_account_id', $account->member_account_id)->update([
|
|
|
+ 'member_account_expend' => $account->member_account_expend + $sheet['order_sheet_pay'],
|
|
|
+ 'member_account_surplus' => $account->member_account_surplus - $sheet['order_sheet_pay']
|
|
|
+ ]);
|
|
|
+ $pay['pay_status'] = 'SUCCESS';
|
|
|
+ $pay['join_pay_object_json'] = json_encode(['payment' => ['member_account_id' => $account->member_account_id]]);
|
|
|
+ }
|
|
|
+ $pay['pay_category'] = 'CASH';
|
|
|
+ PayDetail::insert($pay);
|
|
|
+ }elseif ($params['settlement_mode'] == 'QRCODE'){
|
|
|
+ $pay['pay_category'] = 'QRCODE';
|
|
|
+ $pay['pay_status'] = 'SUCCESS';
|
|
|
+ PayDetail::insert($pay);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
Db::commit();
|
|
|
return json_success("数据更新成功");
|
|
@@ -150,4 +445,47 @@ class AppointmentService
|
|
|
return json_fail("数据更新失败");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static function getTimes(Request $request)
|
|
|
+ {
|
|
|
+ $goodsId = $request->get('goods_id', '');
|
|
|
+ $date = $request->get('date', '');
|
|
|
+ $memberId = $request->get('member_id', '');
|
|
|
+ if (!$goodsId || !$date) {
|
|
|
+ return json_fail("查询时间段失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ $goods = Goods::where('goods_id', $goodsId)->first();
|
|
|
+ if (!$goods) {
|
|
|
+ return json_fail('数据不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当前服务已预约出去的
|
|
|
+ $appointments = Appointment::where('join_appointment_goods_id', $goodsId)
|
|
|
+ ->where('appointment_datetime', $date)
|
|
|
+ ->where('join_appointment_member_id', '<>', $memberId)
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ if ($goods->is_support_appointment == 'Y' && !empty($goods->goods_extend_json)) {
|
|
|
+ $extendJson = json_decode($goods->goods_extend_json, true);
|
|
|
+ $times = $extendJson['times'];
|
|
|
+ foreach ($times as $key => $time) {
|
|
|
+ $timesStr = $time['appointmentTimeStart'] . '~' . $time['appointmentTimeEnd'];
|
|
|
+ $times[$key]['timesStr'] = $timesStr;
|
|
|
+ foreach ($appointments as $appointment) {
|
|
|
+ if (!empty($appointment['appointment_apply_json'])) {
|
|
|
+ $applyJson = json_decode($appointment['appointment_apply_json'], true);
|
|
|
+ $applyJsonTimes = $applyJson['times'] ?? '';
|
|
|
+ if ($timesStr == $applyJsonTimes) {
|
|
|
+ $times[$key]['person'] -= $applyJson['person'];
|
|
|
+ if ($times[$key]['person'] < 1) {
|
|
|
+ unset($times[$key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return json_success('', $times);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|