request->get(); $valid = Yii::$app->services->validate->validate($post, [ [['goods_id','min_age','max_age','gender','sort','limit', 'page','sku_id', 'store_id'], 'integer'], [['name','date','time', 'date', 'time'], 'string'], [['lat','lng'], 'string'], [['lat','lng'], 'required'], [['secondary_card_id','store_cate_id','id'], 'safe'], ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $page = $post['page'] ?? 1; $limit = $post['limit'] ?? 10; $post['mall_id'] = $this->mall_id; if(!empty($post['secondary_card_id'])){ $res = TechniciansService::searchBySecondaryCard($post,$page,$limit); }else{ $res = TechniciansService::search($post,$page,$limit); } return $this->success('成功', $res); } /** * 获取时间 * @return mixed|void */ public function actionGetTime() { $get = Yii::$app->request->get(); $valid = Yii::$app->services->validate->validate($get, [ [['goods_id','sku_id', 'store_id'], 'integer'], [['secondary_card_id','start'], 'safe'], ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $days = 7; if(!empty($get['secondary_card_id'])) { if(!MallAddons::isInstall($this->mall_id,'SecondaryCard')){ return $this->error('没有安装次卡插件' ); } $select = 'id,reservation_time_type,reservation_time,reservation_model,appointment_interval_duration,reservation_type'; $secondary_card = SecondaryCard::getOne([['id'=>$get['secondary_card_id']]],true,[],false,$select); $data = []; if($secondary_card['reservation_type']==0){ return $this->success('成功', $data); } if($secondary_card['reservation_model']==1){ //预约模式:1:预约门店;2:预约服务人 $secondary_card['reservation_time'] = isset($secondary_card['reservation_time'])?json_decode($secondary_card['reservation_time'],true):[]; if(!empty($secondary_card['reservation_time'])){ foreach ($secondary_card['reservation_time'] as $item){ $data[] = $this->getStoreTimeList($item,$secondary_card['appointment_interval_duration']); } } $times = array_column($data,'time'); array_multisort($times,SORT_ASC,$data); return $this->success('成功', $data); } $service_min = $secondary_card['appointment_interval_duration'] ?: 10; //服务分钟 $store_reserve_setting = (new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $get['store_id']]))->detail(); $range_end = $store_reserve_setting['range_end']; $range_end_arr = ReserveServiceEnum::RANGE_END_ARR_MAP; $days = $range_end_arr[$range_end] ?? 7; }else{ if (empty($get['store_id'])) { $goods_reserve = GoodsReserve::findOne(['goods_id' => $get['goods_id'], 'reserve_type' => GoodsReserve::RESERVE_TYPE_SERVICE]); if (!$goods_reserve) return $this->error('项目不存在'); $sku = GoodsReserveSku::findOne(['id' => $get['sku_id'], 'goods_id' => $get['goods_id']]); if (!$sku) return $this->error('项目不存在'); $data = BackendService::getSetting($this->mall_id); $range_end = $data['basic']['range_end'] ?? 1; $range_end_arr = ReservationServiceEnum::RANGE_END_ARR_MAP; } else { $goods_reserve = StoreGoodsReserve::findOne(['goods_id' => $get['goods_id'], 'reserve_type' => GoodsReserve::RESERVE_TYPE_SERVICE]); if (!$goods_reserve) return $this->error('项目不存在'); $sku = StoreGoodsReserveSku::findOne(['id' => $get['sku_id'], 'goods_id' => $get['goods_id']]); if (!$sku) return $this->error('项目不存在'); $store_reserve_setting = (new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $get['store_id']]))->detail(); $range_end = $store_reserve_setting['range_end']; $range_end_arr = ReserveServiceEnum::RANGE_END_ARR_MAP; } $service_min = $sku['service_min'] ?: 10; //服务分钟 $days = $range_end_arr[$range_end] ?? 7; } if (!empty($get['store_id'])) { $store = Store::findOne(['id' => $get['store_id']]); $business_time_start = $store['business_time_start']; $time1 = date('Y-m-d') . ' ' . $business_time_start . ':00'; } else { $time1 = date('Y-m-d 00:00:00'); } $time2 = date('Y-m-d 23:59:59'); $buff = []; for($i=strtotime($time1) ;$i<=strtotime($time2) ; $i=$i+60*$service_min){ $buff[]=date("H:i",$i); } $date_list = []; $time = time(); if (!empty($get['store_id'])) { $store = Store::findOne(['id' => $get['store_id']]); $business_time_start = $store['business_time_start']; $business_time_end = $store['business_time_end']; $obj = new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $get['store_id']]); $store_reserve_setting = $obj->detail(); $range_start = $store_reserve_setting['range_start']; $range_start_time = $obj->getRangeStartTime($range_start); } else { $data = BackendService::getSetting($this->mall_id); $range_start_time = TechniciansService::getRangeStartTime($data['basic']['range_start'] ?? 0); } $time += $range_start_time; //切割时间 for ($i = 0; $i < $days; $i++) { $time_list = $buff; $date = date('Y-m-d', strtotime("+ $i days")); foreach ($time_list as $key => $val) { $temp = strtotime($date . ' ' . $val . ':00'); if ($i == 0) { if ($time > $temp) { unset($time_list[$key]); continue; } if (!empty($get['store_id'])) { $start_time = strtotime($date . ' ' . $business_time_start . ':00'); $end_time = strtotime($date . ' ' . $business_time_end . ':00'); if ($temp < $start_time || $temp > $end_time) { unset($time_list[$key]); } } } else { if (!empty($get['store_id'])) { $start_time = strtotime($date . ' ' . $business_time_start . ':00'); $end_time = strtotime($date . ' ' . $business_time_end . ':00'); if ($temp < $start_time || $temp > $end_time) { unset($time_list[$key]); } } } } $time_list = array_values($time_list); $arr = ['date' => $date,'week_day' => GoodsReserveTime::getWeekDay($date),'time_list' => $time_list,'is_reserve'=>1]; $date_list[] = $arr; } if(!empty($get['start'])){ $start_time = strtotime($get['start'].' 00:00:00'); $i=0; $temp_date_list = array_column($date_list,null,'date'); $date_list = []; while (true){ if($i>=7){ break; } $time_list = $buff; if($start_time == strtotime(date('Y-m-d').' 00:00:00')){ foreach($time_list as $key => $val){ if($time > strtotime(date('Y-m-d '.$val))){ unset($time_list[$key]); } } $time_list = array_values($time_list); } $temp_time = $start_time + $i*86400; $date = date('Y-m-d',$temp_time); $is_reserve = 0; if(isset($temp_date_list[$date])){ $is_reserve = 1; } $date_list[]=['date'=>$date, 'week_day' => GoodsReserveTime::getWeekDay($date),'time_list' => $time_list,'is_reserve'=>$is_reserve]; $i++; } } return $this->success('成功', $date_list); } private function getStoreTimeList($item,$reservation_model){ $day = $item['day']; $date_arr = []; for ($i=0;$i<7;$i++){ $date = date('Y-m-d', strtotime("+ $i days")); $week = date("w", strtotime($date)); $date_arr[$week] = $date; } $date = $date_arr[$day]; $time_start = $item['time_start']; $time = time(); $today_date = date('Y-m-d',$time); $arr = []; if($date != $today_date) { $arr = [$time_start]; } $time_end = $item['time_end']; $end = strtotime($date . ' ' . $time_end . ':00'); while (true) { $temp_time = strtotime($date . ' ' . $time_start . ':00') + $reservation_model * 60; if ($temp_time > $end) break; $time_start = date('H:i', $temp_time); if($date == date('Y-m-d',$time)){ if(strtotime($date.' '.$time_start.':00')>$time){ if($date==$today_date){ if($temp_time>$time+3600){ $arr[] = $time_start; } }else{ $arr[] = $time_start; } } }else{ if($date==$today_date){ if($temp_time>$time+3600){ $arr[] = $time_start; } }else{ $arr[] = $time_start; } } } return ['time'=>strtotime($date.' 00:00:00'),'date' => $date, 'time_list' => $arr, 'week_day' => GoodsReserveTime::getWeekDay($date)]; } /** * 获取某日的时间段 * @return mixed|null * @throws \Exception */ public function actionGetTimes() { $get = Yii::$app->request->get(); $valid = Yii::$app->services->validate->validate($get, [ [['goods_id','min_age','max_age','gender','sort','limit', 'page','sku_id', 'store_id'], 'integer'], [['name','date','time', 'date', 'time'], 'string'], [['lat','lng'], 'string'], [['lat','lng'], 'required'], [['store_cate_id','tech_user_id'], 'safe'], ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $get['mall_id'] = $this->mall_id; $get['limit'] = 1000; $get['page'] = 1; $res = TechniciansService::getTimes($get); return $this->success('成功', $res); } /** * 服务人员页面-平台-可预约日期 * @return mixed|null */ public function actionGetDate() { try { $get = Yii::$app->request->get(); $get['mall_id']= $this->mall_id; $date_list = TechniciansService::getDate($get); return $this->success('成功', $date_list); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionCheckDate() { $post = Yii::$app->request->get(); $valid = Yii::$app->services->validate->validate($post, [ [['lat','lng','goods_id','sku_id','date'], 'required'], [['goods_id','sku_id'], 'integer'], [['date'], 'string'], ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $post['mall_id'] = $this->mall_id; try { $res = TechniciansService::checkDate($post,1,1); }catch (\Exception $e){ return $this->error($e->getMessage()); } return $this->success('成功', $res); } public function actionReservationDate() { try { $get = Yii::$app->request->get(); $valid = Yii::$app->services->validate->validate($get, [ [['goods_id','sku_id','tech_user_id'], 'required'], [['goods_id','sku_id','tech_user_id'], 'integer'], [['store_id','lat','lng',], 'safe'], ]); if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $get['mall_id'] = $this->mall_id; try { $res = TechniciansService::getReservationDate($get); }catch (\Exception $e){ return $this->error($e->getMessage()); } return $this->success('成功', $res); }catch (\Exception $e){ return $this->error($e->getMessage()); } } /** * -服务时间列表 * @return mixed|null */ public function actionServiceTimeList() { try { $params = \Yii::$app->request->get(); $rules = [ [['sku_id','id'], 'required'], [['start'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($params, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $list = TechniciansService::serviceTimeList($params); return $this->success('获取成功', $list); }catch (\Exception $e){ return $this->error($e->getMessage()); } } /** * h5端-预约时间列表-到店分配/技师不选项 * @return mixed|null */ public function actionReservationTimeList() { try { $params = \Yii::$app->request->get(); $rules = [ [['sku_id'], 'required'], [['date'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($params, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); if(empty($params['date'])){ $params['date'] = date('Y-m-d'); } $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $params['store_id']]))->toStoreReservationTimeList($params); return $this->success('获取成功', $list); }catch (\Exception $e){ return $this->error($e->getMessage()); } } }