ReservationServiceOrderService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. <?php
  2. namespace addons\ReservationService\common\services;
  3. use addons\ReservationService\common\enums\ReservationServiceEnum;
  4. use addons\ReservationService\common\models\ReservationServiceGoods;
  5. use addons\ReservationService\common\models\ReservationServiceGoodsSetting;
  6. use addons\ReservationService\common\models\ReservationServiceLevel;
  7. use addons\ReservationService\common\models\ReservationServiceOccupy;
  8. use addons\ReservationService\common\models\ReservationServiceOrder;
  9. use addons\ReservationService\common\models\ReservationServiceStoreSecondaryCard;
  10. use addons\ReservationService\common\models\ReservationServiceUser;
  11. use addons\SecondaryCard\common\models\SecondaryCard;
  12. use common\enums\ClerkEnum;
  13. use common\enums\GoodsTypeEnum;
  14. use common\enums\OrderSourceEnum;
  15. use common\enums\StatusEnum;
  16. use common\models\goods\Goods;
  17. use common\models\goods\GoodsReserveSku;
  18. use common\models\mall\Mall;
  19. use common\models\order\Order;
  20. use common\models\order\OrderReserve;
  21. use common\models\user\User;
  22. use services\common\UserWalletService;
  23. use Yii;
  24. use yii\console\ExitCode;
  25. class ReservationServiceOrderService
  26. {
  27. public static function orderProcess(string $action, string $config_key, array $order_wheres = null) : int
  28. {
  29. $action_info_map = [
  30. 'complete' => [
  31. 'task_name' => '自动验收',
  32. 'time_radix' => 86400, // 时间节点计算的基数,订单自动自动过售后的时间单位是天,转换为秒的基数是86400
  33. 'method' => 'complete',
  34. 'time_field' => 'service_end_at',
  35. 'default' => 7, // 自动过售后默认时间 7 天
  36. ],
  37. ];
  38. try {
  39. $mall_list = Mall::getEnableMallList(true);
  40. $mall_ids = array_column($mall_list, 'id');
  41. if (empty($mall_ids)) {
  42. echo '没有可用商城,不做处理 ... ' . PHP_EOL;
  43. return ExitCode::UNSPECIFIED_ERROR;
  44. }
  45. foreach ($mall_ids as $mall_id) {
  46. // 订单自动处理时间
  47. $order_auto_handle_time = \Yii::$app->services->setting->mall->get($mall_id, $config_key);
  48. // 如果自动处理时间没有配置,则取默认值
  49. if (empty($order_auto_handle_time)) $order_auto_handle_time = $action_info_map[$action]['default'];
  50. // 订单自动处理时间节点,延后两分钟处理,避免支付回调尚未回来订单已经被取消s
  51. $time_node = time() - $order_auto_handle_time * $action_info_map[$action]['time_radix'] - 120;
  52. $time_field = $action_info_map[$action]['time_field'];
  53. $where = [
  54. 'and',
  55. ['mall_id' => $mall_id],
  56. ['<', $time_field, $time_node]
  57. ];
  58. if (!empty($order_wheres)) {
  59. foreach ($order_wheres as $order_where) {
  60. array_push($where, $order_where);
  61. }
  62. }
  63. foreach (ReservationServiceOrder::find()->where($where)->each(500) as $order) {
  64. var_dump($order['order_id']);
  65. $data = [];
  66. $data['id'] = $order['order_id'];
  67. $data['mall_id'] = $order['mall_id'];
  68. $data['user_id'] = $order['user_id'];
  69. $data['operator_id'] = 0;
  70. $data['operator_name'] = '';
  71. $data['from'] = OrderSourceEnum::SOURCE_RESERVE;
  72. Order::complete($data);
  73. }
  74. }
  75. return ExitCode::OK;
  76. } catch (\Exception $e) {
  77. echo ' 订单' . $action_info_map[$action]['task_name'] . ' 任务处理出错:' . $e->getMessage() . PHP_EOL;
  78. return ExitCode::UNSPECIFIED_ERROR;
  79. }
  80. }
  81. public static function getSkuList(int $mall_id)
  82. {
  83. $goods_list = Goods::lists([
  84. 'where' => [
  85. ['mall_id' => $mall_id],
  86. ['status' => StatusEnum::ENABLED],
  87. ['check_status' => StatusEnum::ENABLED],
  88. ['is_on_sale' => StatusEnum::ENABLED],
  89. ['goods_type' => GoodsTypeEnum::GoodsTypeReserved],
  90. ],
  91. 'select' => 'id,goods_name',
  92. 'index' => 'id'
  93. ]);
  94. $goods_ids = array_column($goods_list, 'id');
  95. $sku_list = GoodsReserveSku::lists([
  96. 'where' => [
  97. ['goods_id' => $goods_ids],
  98. ],
  99. 'select' => 'id,goods_id,service_min,name',
  100. ]);
  101. foreach ($sku_list as &$sku) {
  102. $sku['goods_name'] = $goods_list[$sku['goods_id']]['goods_name'] . ':' . $sku['name'];
  103. }
  104. return $sku_list;
  105. }
  106. public static function getReserveDay(int $mall_id)
  107. {
  108. $config = BackendService::getSetting($mall_id);
  109. $range_end = $config['range_end'];
  110. $range_end_arr = ReservationServiceEnum::RANGE_END_ARR_MAP;
  111. $days = $range_end_arr[$range_end] ?? 7;
  112. $day_arr = [];
  113. $time = strtotime(date('Y-m-d'));
  114. $end_time = $time + $days * 24 * 3600;
  115. for ($i = $time; $i < $end_time; $i += 24 * 60 * 60) {
  116. $day_arr[] = $i * 1000;;
  117. }
  118. return ['day_arr' => $day_arr];
  119. }
  120. /**
  121. * 后台添加预约/预约看板添加预约,获取可以预约的时间段
  122. * @param $params
  123. * @return array
  124. */
  125. public function getReserveTimes($params)
  126. {
  127. $date_time = strtotime($params['date']);
  128. $staff_user_id = $params['staff_user_id'] ?? 0;
  129. if (!empty($params['staff_user_id'])) {
  130. $scheduling = ReserveTechnicianScheduling::getOne([
  131. ['user_id' => $staff_user_id],
  132. ['date_time' => $date_time],
  133. ['status' => StatusEnum::ENABLED]
  134. ], true, ['schedulingTime']);
  135. if (empty($scheduling)) {
  136. return [];
  137. }
  138. }
  139. $buff = [];
  140. $sku = StoreGoodsReserveSku::findOne(['id' => $params['sku_id']]);
  141. $date_day = date('Y-m-d', strtotime($params['date']));
  142. $time = time();
  143. $service_min = $sku['service_min'];
  144. $obj = new StoreReserveSettingService(['mall_id' => $mall_id, 'store_id' => $this->store_id]);
  145. $store_reserve_setting = $obj->detail();
  146. if (strtotime(date('Y-m-d')) == $date_time) {
  147. $range_start_time = $obj->getRangeStartTime($store_reserve_setting['range_start']);
  148. $time += $range_start_time;
  149. }
  150. $reservation_service_order_list = ReservationServiceOrder::lists([
  151. 'where' => [
  152. ['mall_id' => $mall_id],
  153. ['store_id' => $this->store_id],
  154. ['staff_user_id' => $staff_user_id],
  155. ['>=', 'service_start_at', strtotime($date_day . ' 00:00:00')],
  156. ['<=', 'service_end_at', strtotime($date_day . ' 23:59:59')],
  157. ['!=', 'server_status', ReservationServiceEnum::CANCELED]
  158. ]
  159. ]);//已预约
  160. $reservation_service_order_arr = [];
  161. foreach ($reservation_service_order_list as $value) {
  162. $reservation_service_order_arr[$value['service_start_at']] = $value;
  163. }
  164. $occupy_list = ReservationServiceOccupy::lists([
  165. 'where' => [
  166. ['mall_id' => $mall_id],
  167. ['store_id' => $this->store_id],
  168. ['staff_user_id' => $staff_user_id],
  169. ['status' => StatusEnum::ENABLED]
  170. ]
  171. ]
  172. );//已占用时间
  173. if (!empty($staff_user_id)) {
  174. if (!empty($scheduling['is_all_day'])) {
  175. //全天
  176. $store = Store::findOne(['id' => $this->store_id]);
  177. $time1 = $date_day . " " . $store['business_time_start'] . ":00";
  178. $time2 = $date_day . " " . $store['business_time_end'] . ":59";
  179. $start = strtotime($time1);
  180. $end = strtotime($time2);
  181. $this->getBuff($start, $end, $service_min, $reservation_service_order_arr, $occupy_list, $time, $buff);
  182. } else {
  183. if (!empty($scheduling['schedulingTime'])) {
  184. foreach ($scheduling['schedulingTime'] as $val) {
  185. $start = $val['start_time'];
  186. $end = $val['end_time'];
  187. $this->getBuff($start, $end, $service_min, $reservation_service_order_arr, $occupy_list, $time, $buff);
  188. }
  189. }
  190. }
  191. } else {
  192. $store = Store::findOne(['id' => $this->store_id]);
  193. $time1 = $date_day . " " . $store['business_time_start'] . ":00";
  194. $time2 = $date_day . " " . $store['business_time_end'] . ":59";
  195. $start = strtotime($time1);
  196. $end = strtotime($time2);
  197. $this->getBuff($start, $end, $service_min, $reservation_service_order_arr, $occupy_list, $time, $buff);
  198. }
  199. return $buff;
  200. }
  201. public static function getReserveTime(int $mall_id)
  202. {
  203. $step = '00:01';
  204. $picker_options_time = [
  205. 'start' => "00:00",
  206. 'end' => "23:59",
  207. 'step' => $step,
  208. ];
  209. return ['picker_options_time' => $picker_options_time];
  210. }
  211. public static function getStaffUserList(int $mall_id, $params)
  212. {
  213. if (empty($params['goods_id'])) {
  214. $sku = GoodsReserveSku::findOne(['id' => $params['sku_id']]);
  215. if ($sku === null) throw new \Exception('商品不存在.');
  216. $goods_id = $sku['goods_id'];
  217. } else {
  218. $goods_id = $params['goods_id'];
  219. }
  220. $reservation_ervice_store_goods_list = ReservationServiceGoods::lists(['where' => [
  221. ['goods_id' => $goods_id],
  222. ['status' => StatusEnum::ENABLED],
  223. ['mall_id' => $mall_id]
  224. ]]);
  225. $user_ids = array_column($reservation_ervice_store_goods_list, 'user_id');
  226. $list = ReservationServiceUser::lists([
  227. 'where' => [
  228. ['mall_id' => $mall_id],
  229. ['user_id' => $user_ids],
  230. ['status' => StatusEnum::ENABLED]
  231. ],
  232. 'select' => 'user_id,name'
  233. ]);
  234. return $list;
  235. }
  236. public static function getUser(int $mall_id, $params)
  237. {
  238. $user = User::findOne(['mall_id' => $mall_id, 'mobile' => $params['mobile'], 'status' => [StatusEnum::ENABLED]]);
  239. $name = '';
  240. if ($user !== null) {
  241. if (!empty($user['nickname'])) {
  242. $name = $user['nickname'];
  243. } else {
  244. $name = $user['mobile'];
  245. }
  246. }
  247. return $name;
  248. }
  249. public static function getEditData(int $mall_id, $params)
  250. {
  251. $goods_list = Goods::lists([
  252. 'where' => [
  253. ['mall_id' => $mall_id],
  254. ['status' => StatusEnum::ENABLED],
  255. ['check_status' => StatusEnum::ENABLED],
  256. ['is_on_sale' => StatusEnum::ENABLED],
  257. ['goods_type' => GoodsTypeEnum::GoodsTypeReserved],
  258. ],
  259. 'select' => 'id,goods_name',
  260. 'with' => ['reserve' => function ($q) {
  261. $q->select('id,goods_id,service_min');
  262. }],
  263. ]);
  264. $config = BackendService::getSetting($mall_id);
  265. $ret['goods_list'] = $goods_list;
  266. $ret['range_start'] = $config['range_start'] ?? 1;
  267. $ret['range_end'] = $config['range_end'] ?? 1;
  268. $order = [];
  269. $goods_name = '';
  270. $service_type_arr = [];
  271. if (!empty($params['id'])) {
  272. $order = ReservationServiceOrder::getOne([
  273. ['id' => $params['id'], 'mall_id' => $mall_id]
  274. ],
  275. true
  276. );
  277. $user = User::findOne(['id' => $order['user_id']]);
  278. if ($user === null) throw new \Exception('用户不存在');
  279. $order['mobile'] = $user['mobile'];
  280. $order['nickname'] = !empty($user['nickname']) ? $user['nickname'] : $user['mobile'];
  281. $order['at_date'] = date('Y-m-d', $order['service_start_at']);
  282. $order['at_time'] = date('H:i', $order['service_start_at']);
  283. $params['goods_id'] = $order['goods_id'];
  284. $params['sku_id'] = $order['goods_reserve_sku_id'];
  285. $order['sku_id'] = $order['goods_reserve_sku_id'];
  286. if (empty($order['staff_user_id'])) {
  287. $order['staff_user_id'] = '';
  288. }
  289. if (empty($order['secondary_card_id'])) {
  290. $sku = GoodsReserveSku::findOne(['id' => $order['sku_id']]);
  291. if ($sku === null) throw new \Exception('商品不存在');
  292. if (empty($sku['name'])) {
  293. $store_goods = Goods::findOne(['id' => $order['goods_id']]);
  294. if ($store_goods === null) throw new \Exception('商品不存在!');
  295. $goods_name = $store_goods['goods_name'];
  296. } else {
  297. $goods_name = $sku['name'];
  298. }
  299. $ret['staff_user_list'] = self::getStaffUserList($mall_id, $params);
  300. $order['master'] = [
  301. ['sku_id' => $order['sku_id'], 'staff_user_id' => $order['staff_user_id'], 'service_min' => $sku['service_min'] ?? 0]
  302. ];
  303. } else {
  304. $params['secondary_card_id'] = $order['secondary_card_id'];
  305. $secondary_card = SecondaryCard::getOne([['id' => $order['secondary_card_id']]]);
  306. $goods_name = $secondary_card['name'] ?? '';
  307. $ret['staff_user_list'] = self::getStaffUserListBySecondaryCard($mall_id, $params);
  308. $order['master'] = [
  309. ['sku_id' => $order['secondary_card_id'], 'staff_user_id' => $order['staff_user_id'], 'service_min' => $secondary_card['appointment_interval_duration'] ?? 0]
  310. ];
  311. switch ($secondary_card['reservation_service_type']) {
  312. case 1:
  313. $service_type_arr[] = ['value' => 1, 'label' => '上门服务'];
  314. break;
  315. case 2:
  316. $service_type_arr[] = ['value' => 2, 'label' => '到店服务'];
  317. break;
  318. case 3:
  319. $service_type_arr[] = ['value' => 1, 'label' => '上门服务'];
  320. $service_type_arr[] = ['value' => 2, 'label' => '到店服务'];
  321. break;
  322. }
  323. }
  324. }
  325. $ret['service_type_arr'] = $service_type_arr;
  326. $ret['reserve_order'] = $order;
  327. $ret['goods_name'] = $goods_name;
  328. $store = $params['store'];
  329. $business_time_start = strtotime(date('Y-m-d') . ' ' . $store['business_time_start'] . ':00');
  330. $business_time_end = strtotime(date('Y-m-d') . ' ' . $store['business_time_end'] . ':00');
  331. $H = date('H', $business_time_start);
  332. $start_time = $H * 60;
  333. $H = date('H', $business_time_end);
  334. $minute = date('i', $business_time_end);
  335. $end_time = $H * 60 + $minute;
  336. $ret['start_time'] = $start_time;
  337. $ret['end_time'] = $end_time;
  338. return $ret;
  339. }
  340. public static function getStaffUserListBySecondaryCard(int $mall_id, $params)
  341. {
  342. $reservation_service_store_secondary_card_list = ReservationServiceStoreSecondaryCard::lists(['where' => [
  343. ['secondary_card_id' => $params['secondary_card_id']],
  344. ['status' => StatusEnum::ENABLED],
  345. ['mall_id' => $mall_id]
  346. ]]);
  347. $user_ids = array_column($reservation_service_store_secondary_card_list, 'user_id');
  348. return ReservationServiceUser::lists([
  349. 'where' => [
  350. ['mall_id' => $mall_id],
  351. ['user_id' => $user_ids],
  352. ['status' => StatusEnum::ENABLED]
  353. ],
  354. 'select' => 'user_id,name'
  355. ]);
  356. }
  357. /**
  358. * 后台添加预约
  359. * @param $params
  360. * @return array
  361. * @throws \yii\base\Exception
  362. * @throws \yii\db\Exception
  363. */
  364. public static function setEditData(int $mall_id, $params)
  365. {
  366. $t = Yii::$app->db->beginTransaction();
  367. try {
  368. $user = User::findOne(['mobile' => $params['mobile'], 'mall_id' => $mall_id]);
  369. if (!empty($user)) {
  370. if ($user['status'] != StatusEnum::ENABLED) {
  371. throw new \Exception('用户状态异常');
  372. } else {
  373. $params['user_id'] = $user['id'];
  374. }
  375. } else {
  376. //注册用户
  377. $user = self::setUser($mall_id, $params);
  378. $params['user_id'] = $user['id'];
  379. }
  380. $service_start_at = strtotime(date('Y-m-d', strtotime($params['at_date'])) . ' ' . $params['at_time'] . ':00');
  381. $config = BackendService::getSetting($mall_id);
  382. if (!empty($params['id'])) {
  383. $model = ReservationServiceOrder::findOne(['id' => $params['id'], 'mall_id' => $mall_id]);
  384. if ($model === null) {
  385. throw new \Exception('数据不存在');
  386. }
  387. $params['secondary_card_id'] = $model['secondary_card_id'];
  388. }
  389. $params['staff_user_id'] = !empty($params['master'][0]['staff_user_id']) ? $params['master'][0]['staff_user_id'] : 0;
  390. if (empty($params['secondary_card_id'])) {
  391. $params['sku_id'] = $params['master'][0]['sku_id'];;
  392. $store_goods_reserve_sku = GoodsReserveSku::findOne(['id' => $params['sku_id']]);
  393. if (empty($store_goods_reserve_sku)) {
  394. throw new \Exception('预约商品规格不存在');
  395. }
  396. $service_min = TechniciansService::getServiceMin(1, $store_goods_reserve_sku['service_min'] ?? 0);
  397. $goods_id = $store_goods_reserve_sku['goods_id'];
  398. } else {
  399. $secondary_card = SecondaryCard::getOne([['id' => $params['secondary_card_id']]]);
  400. $service_min = TechniciansService::getServiceMin(1, $secondary_card['appointment_interval_duration'] ?? 0);
  401. $goods_id = 0;
  402. $params['sku_id'] = 0;
  403. }
  404. $service_end_at = $service_start_at + $service_min * 60;
  405. self::checkEdit($params['staff_user_id'], $service_start_at, $service_end_at);
  406. if (!empty($params['create_type'])) {
  407. $update['create_type'] = $params['create_type'];
  408. }
  409. if (!empty($params['id'])) {
  410. if ($params['staff_user_id'] != $model['staff_user_id']) {
  411. $staff = ReservationServiceUser::findOne(['user_id' => $params['staff_user_id'], 'status' => StatusEnum::ENABLED]);
  412. }
  413. } else {
  414. throw new \Exception('预约订单不存在');
  415. }
  416. $model->user_id = $params['user_id'];
  417. $model->staff_user_id = $params['staff_user_id'];
  418. $model->goods_id = $goods_id;
  419. $model->service_start_at = $service_start_at;
  420. $model->service_end_at = $service_end_at;
  421. $model->reservation_model = $params['reservation_model'];
  422. $model->goods_reserve_sku_id = $params['sku_id'];
  423. $model->commission = self::calcCommission($mall_id, $params['staff_user_id'], $goods_id, $store_goods_reserve_sku['price'] ?? 0);
  424. $model->service_status = ReservationServiceEnum::RESERVE_ORDER_STATUS_NORMAL;
  425. if (!empty($params['create_type'])) {
  426. $model->create_type = $params['create_type'];
  427. }
  428. if (!empty($params['service_type'])) {
  429. $model->service_type = $params['service_type'];
  430. }
  431. $res = $model->save();
  432. $reserve_date_time = date('Y-m-d H:i', $model->service_start_at) . ',' . date('Y-m-d H:i', $model->service_end_at);
  433. $update['reserve_date_time'] = $reserve_date_time;
  434. $update['service_start_at'] = $model->service_start_at;
  435. $update['service_end_at'] = $model->service_end_at;
  436. $update['service_type'] = $model->service_type;
  437. $update['reservation_service_order_id'] = $model['id'];
  438. $update['reserve_code'] = OrderReserve::getClerkCode($mall_id, ClerkEnum::RESERVATION_SERVICE_CLERK_CODE_PRE);
  439. if (isset($staff)) {
  440. $update['tech_id'] = $staff['id'];
  441. }
  442. unset($update['create_type']);
  443. OrderReserve::updateAll($update, ['order_id' => $model['order_id']]);
  444. // 核销码
  445. Order::updateAll(['clerk_code' => $update['reserve_code']], ['id' => $model->order_id]);
  446. if ($res == false) {
  447. throw new \Exception($model->getErrorMessage());
  448. }
  449. $t->commit();
  450. return ['id' => $model['id']];
  451. } catch (\Exception $e) {
  452. $t->rollBack();
  453. throw new \Exception($e->getMessage());
  454. }
  455. }
  456. public static function calcCommission(int $mall_id, $tech_id, $goods_id, $goods_price)
  457. {
  458. $staff = ReservationServiceUser::findOne(['mall_id' => $mall_id, 'user_id' => $tech_id,
  459. 'status' => StatusEnum::ENABLED, 'check_status' => ReservationServiceEnum::CHECK_ADOPT]);
  460. if ($staff === null) throw new \Exception('技师不存在');
  461. /**
  462. * @var $level ReservationServiceLevel
  463. */
  464. $level = $staff->getLevel()->andWhere(['mall_id' => $mall_id])->one();
  465. $commission = $level->item_commission;
  466. if (empty($level->item_commission_type)) {
  467. $commission = bcmul(bcmul($commission, $goods_price, 2), 0.01, 2);
  468. }
  469. /**
  470. * @var $goodsSetting ReservationServiceGoodsSetting
  471. */
  472. $goodsSetting = ReservationServiceGoodsSetting::getOne([
  473. ['mall_id' => $mall_id],
  474. ['status' => StatusEnum::ENABLED],
  475. ['item_id' => $goods_id],
  476. ['item_type' => 'goods'],
  477. ['is_enable' => StatusEnum::ENABLED],
  478. ['commission_type' => UserWalletService::WALLET_TYPE_COMMISSION]
  479. ]);
  480. if (!empty($goodsSetting)) {
  481. $commission = $goodsSetting->commission;
  482. if (!empty($goodsSetting->is_percent)) {
  483. $commission = bcmul(bcmul($commission, $goods_price, 2), 0.01, 2);
  484. }
  485. }
  486. if ($commission < 0) $commission = 0;
  487. return $commission;
  488. }
  489. /**
  490. * 注册用户
  491. * @param $params
  492. * @return bool|User
  493. * @throws \yii\base\Exception
  494. * @throws \yii\db\Exception
  495. */
  496. protected static function setUser(int $mall_id, $params)
  497. {
  498. $password = substr($params['mobile'], -6, 6);
  499. $params['mall_id'] = $mall_id;
  500. if (empty($params['username'])) {
  501. $params['username'] = $params['mobile'];
  502. }
  503. $params['parent_id'] = 0;
  504. $params['level'] = 0;
  505. $params['source'] = User::SOURCE_ADD_PLATFORM;
  506. $params['platform'] = User::TYPE_MANUAL;
  507. $params['password'] = Yii::$app->getSecurity()->generatePasswordHash($password);
  508. return User::setData($params);
  509. }
  510. /**
  511. * 检查该时间段是否被预约或者被占用
  512. * @param $staff_user_id
  513. * @param $service_start_at
  514. * @param $service_end_at
  515. * @param $reservation_service_order_id
  516. * @return void
  517. * @throws \Exception
  518. */
  519. protected static function checkEdit($staff_user_id, $service_start_at, $service_end_at, $reservation_service_order_id = null, $create_type = 2)
  520. {
  521. $list = ReservationServiceOccupy::lists([
  522. 'where' => [
  523. ['staff_user_id' => $staff_user_id],
  524. ['status' => StatusEnum::ENABLED],
  525. ]
  526. ]);
  527. foreach ($list as $item) {
  528. if ($service_start_at >= $item['start_at'] && $service_start_at < $item['end_at']) {
  529. throw new \Exception('该时间段已被占用');
  530. }
  531. if ($service_end_at >= $item['start_at'] && $service_end_at < $item['end_at']) {
  532. throw new \Exception('该时间段已被占用');
  533. }
  534. }
  535. }
  536. }