123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace api\teahouse\controller;
- use app\teahouse\model\LockBookModel;
- use app\teahouse\model\LockModel;
- use app\teahouse\model\LockUserModel;
- use cmf\controller\RestBaseController;
- class TeahouseController extends RestBaseController
- {
- public function getTeahouseList()
- {
- $param = $this->request->param();
- $page = empty($param['page']) ? 1 : $param['page'];
- $size = empty($param['size']) ? 10 : $param['size'];
- //搜索条件
- $list = LockModel::where('is_show', 1)->page($page, $size)->select();
- //数据处理
- if (!$list->isEmpty()) {
- foreach ($list as $v) {
- $v['image'] = cmf_get_image_preview_url($v['image']);
- }
- }
- $this->success('成功', $list);
- }
- public function getTimeByDate()
- {
- $lock_id = $this->request->param('lock_id');
- $date = $this->request->param('date');
- $date = str_replace(['年', '月', '日'], ['-', '-', ''], $date);
- $date_start = strtotime($date);
- $date_end = strtotime($date . ' +1 day');
- $list = LockBookModel::where('lock_id', $lock_id)
- ->where('start_time', '>=', $date_start)
- ->where('end_time', '<=', $date_end)
- ->select();
- $res = [];
- if (!$list->isEmpty()) {
- foreach ($list as $v) {
- $res[] = date('H:i', $v['start_time']) . ' - ' . date('H:i', $v['end_time']);
- }
- }
- $this->success('成功', $res);
- }
- public function reservation()
- {
- //茶室
- $lock_id = $this->request->param('lock_id');
- if (empty($lock_id)) {
- $this->error('参数异常');
- }
- $lock = LockModel::where('id', $lock_id)->find();
- //日期
- $date = $this->request->param('date');
- if (empty($date)) {
- $this->error('请选择要预约的日期');
- }
- $date = str_replace(['年', '月', '日'], ['-', '-', ''], $date);
- //时间
- $time_list = $this->request->param('time');
- if (empty($time_list)) {
- $this->error('请选择要预约的时间');
- }
- if (count($time_list) > 3) {
- $this->error('一次最多预约3个小时');
- }
- //爽约次数
- $unuse = LockBookModel::where('user', $this->user['id'])->where('is_use',2)->count();
- if ($unuse >= 3) {
- $this->error('您爽约和预约的总时长超过3小时,无法再预约,请联系管理员');
- }
- //添加预约信息
- $user = LockUserModel::where('user_id', $this->user['id'])->find();
- $now = time();
- $relation_id = uniqid();
- foreach ($time_list as $v) {
- $add = [];
- $time = explode('-', $v);
- $add['lock_id'] = $lock_id;
- $add['user_id'] = $user['user_id'];
- $add['lock_name'] = $lock['name'];
- $add['user_name'] = $user['name'];
- $add['start_time'] = strtotime($date . ' ' . trim($time[0]) . ':00');
- $add['end_time'] = strtotime($date . ' ' . trim($time[1]) . ':00');
- $add['relation_id'] = $relation_id;
- $add['create_time'] = $now;
- LockBookModel::create($add);
- }
- $this->success('成功');
- }
- }
|