123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- <?php
- /**
- * Author: luzheng.liu
- * Time: 2020/12/16 23:06
- */
- namespace app\api\controller;
- use app\api\BaseController;
- use app\api\exception\ApiException;
- use app\api\model\DiscussModel;
- use app\api\model\GroupModel;
- use app\api\model\OrderRoomModel;
- use app\api\model\RoomModel;
- use app\common\until\Until;
- use think\Model;
- class Room extends BaseController {
- /**
- * @OA\Get(path="/api/Room/index",
- * tags={"房间管理"},
- * summary="房间列表",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="ineger",default="1")),
- * @OA\Parameter(name="pageSize", in="query", description="页尺寸", @OA\Schema(type="integer",default="10")),
- * @OA\Parameter(name="storeId", in="query", description="门店id", @OA\Schema(type="integer",default="1")),
- * @OA\Parameter(name="date", in="query", description="服务开始时间", @OA\Schema(type="string",default="2021-04-09")),
- * @OA\Parameter(name="status", in="query", description="1正常(待使用) 2使用中 3空闲 999禁用", @OA\Schema(type="integer",default="1")),
- * @OA\Parameter(name="name", in="query", description="名字或code", @OA\Schema(type="string",default="666")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function index() {
- $input = Until::getInput();
- $model = new RoomModel();
- $model->setPage($input['page'] ?? 1);
- $model->setPageSize($input['pageSize'] ?? 10);
- $where = [];
- if (!empty($input['storeId'])) {
- $where[] = ['r.store_id', '=', (int)$input['storeId']];
- }
- if (!empty($input['status'])) {
- if ($input['status'] != 999) {
- $where[] = ['r.status', '=', 1];
- $where[] = ['r.room_server_status', '=', (int)$input['status']];
- }else{
- $where[] = ['r.status', '=', 2];
- }
- }
- if (!empty($input['name'])) {
- $where[] = ['r.room_name|r.room_code', 'like', "%{$input['name']}%"];
- }
- if ($this->isAdmin()) {
- $where[] = ['sr.admin_id', '=', $this->adminId];
- }
- $model->setWhere($where);
- $data = $model->getRoomList();
- Until::output($data);
- }
- /**
- * @OA\Post(path="/api/room/save",
- * tags={"房间管理"},
- * summary="保存房间信息",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * @OA\MediaType(
- * mediaType="multipart/form-data",
- * @OA\Schema(
- * @OA\Property(description="房间名称", property="roomName", type="integer", default="1"),
- * @OA\Property(description="房间代号", property="roomCode", type="integer", default="1"),
- * @OA\Property(description="门店id", property="storeId", type="integer", default="1"),
- * @OA\Property(description="状态", property="status", type="integer", default="1"),
- * @OA\Property(description="房间id", property="id", type="integer", default="1"),
- * required={"roomName","roomCode","storeId","status"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function save() {
- $input = Until::getInput();
- $rule = [
- 'roomName|房间名称' => 'require',
- 'roomCode|房间代号' => 'require',
- 'storeId|门店id' => 'require',
- 'status|状态' => 'require',
- // 'id|房间id' => 'require',
- ];
- Until::check($rule, $input);
- $model = new RoomModel();
- if (!empty($input['id'])) {
- $id = (int)$input['id'];
- $rs = $model::where([['store_id', '=', $input['storeId']], ['room_name', '=', $input['roomName']], ['id', '<>', $id]])->find();
- if ($rs !== null) {
- throw new ApiException('名称不能重复');
- }
- $rs = $model::where([['store_id', '=', $input['storeId']], ['room_code', '=', $input['roomCode']], ['id', '<>', $id]])->find();
- if ($rs !== null) {
- throw new ApiException('code不能重复');
- }
- $model::where(['id' => $id])->update([
- 'room_name' => $input['roomName'],
- 'store_id' => $input['storeId'],
- 'room_code' => $input['roomCode'],
- 'status' => $input['status'] ?? 1,
- ]);
- } else {
- $rs = $model::where([['store_id', '=', $input['storeId']], ['room_name', '=', $input['roomName']]])->find();
- if ($rs !== null) {
- throw new ApiException('名称不能重复');
- }
- $rs = $model::where([['store_id', '=', $input['storeId']], ['room_code', '=', $input['roomCode']]])->find();
- if ($rs !== null) {
- throw new ApiException('code不能重复');
- }
- $id = $model->insertGetId([
- 'room_name' => $input['roomName'],
- 'store_id' => $input['storeId'],
- 'room_code' => $input['roomCode'],
- 'status' => $input['status'] ?? 1,
- ]);
- }
- $where[] = ['r.id', '=', (int)$id];
- $model->setWhere($where);
- $info = $model->getRoomInfo();
- Until::output(['info' => $info]);
- }
- /**
- * @OA\Post(path="/api/room/updateStatus",
- * tags={"房间管理"},
- * summary="修改房间状态",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * @OA\MediaType(
- * mediaType="multipart/form-data",
- * @OA\Schema(
- * @OA\Property(description="房间id", property="id", type="integer", default="1"),
- * @OA\Property(description="状态", property="status", type="integer", default="1"),
- * required={"id","status"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function updateStatus() {
- $input = Until::getInput();
- $rule = [
- 'id|房间id' => 'require',
- 'status|状态' => 'require',
- ];
- Until::check($rule, $input);
- $model = new RoomModel();
- $model::where(['id' => $input['id']])->update(['status' => $input['status']]);
- Until::output();
- }
- /**
- * @OA\Post(path="/api/room/allocateRoom",
- * tags={"房间管理"},
- * summary="分配房间",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * @OA\MediaType(
- * mediaType="multipart/form-data",
- * @OA\Schema(
- * @OA\Property(description="房间id", property="id", type="integer", default="1"),
- * @OA\Property(description="订单id", property="orderId", type="integer", default="1"),
- * required={"id","orderId"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function allocateRoom() {
- $input = Until::getInput();
- $rule = [
- 'id|房间id' => 'require',
- 'orderId|订单id' => 'require',
- ];
- Until::check($rule, $input);
- $data = [
- 'order_id' => $input['orderId'],
- ];
- $model = new OrderRoomModel();
- $rs = $model::where($data)->find();
- if (empty($rs)) {
- $data['room_id'] = $input['id'];
- $model->insert($data);
- } else {
- $model::where(['order_id' => $input['orderId']])->update(['room_id' => $input['id']]);
- }
- (new RoomModel())::where(['id' => $input['id']])->update(['room_server_status' => 1]);
- Until::output();
- }
- /**
- * @OA\Post(path="/api/room/serverRoom",
- * tags={"房间管理"},
- * summary="房间报表",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * @OA\MediaType(
- * mediaType="multipart/form-data",
- * @OA\Schema(
- * @OA\Property(description="门店id", property="storeId", type="integer", default="1"),
- * @OA\Property(description="日期(默认今天)", property="date", type="string", default="2021-04-29"),
- * @OA\Property(description="状态 1未开始 2服务中 3已完成(多个逗号分隔)", property="status", type="integer", default="1"),
- * required={"storeId","status"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function serverRoom() {
- $input = Until::getInput();
- $rule = [
- 'storeId|门店id' => 'require',
- //'date|日期' => 'require',
- 'status|状态' => 'require',
- ];
- Until::check($rule, $input);
- $where = [];
- if (!empty($input['status'])) {
- $statusArr = explode(',', $input['status']);
- $where[] = ['as.status', 'in', $statusArr];
- }
- if (empty($input['date'])) {
- $input['date'] = date('Y-m-d');
- }
- $where[] = ['as.server_start_time', 'between', [$input['date'], date('Y-m-d', strtotime('+1 day', strtotime($input['date'])))]];
- $model = new OrderRoomModel();
- $model->setWhere($where);
- $rs = $model->getRoomList();
- if (empty($rs)) {
- Until::output([]);
- }
- $list = [];
- foreach ($rs as $v) {
- if ($v['asStatus'] == 2){
- $allocateOrderStatus = 3; //服务中
- }elseif ($v['asStatus'] == 3) {
- $allocateOrderStatus = 4; // 服务结束
- }else {
- $allocateOrderStatus = 2; //未开始
- }
- $productInfo = json_decode($v['product_snap'], true);
- if (empty($v['server_end_time'])) {
- $endTime = strtotime($v['server_start_time']) + $productInfo['time'];
- $time = $productInfo['time'];
- } else {
- $endTime = strtotime($v['server_end_time']);
- $time = (int)(($endTime - strtotime($v['server_start_time'])) / 60);
- }
- $list[$v['room_id']][] = [
- 'productName' => $productInfo['product_name'],
- 'start' => (int)((strtotime($v['server_start_time']) - strtotime($input['date'] . ' 08:00:00')) / 60),
- 'time' => $time,
- 'allocateOrderStatus' => $allocateOrderStatus,
- 'startTime' => date('H:i', strtotime($v['server_start_time'])),
- 'endTime' => date('H:i', $endTime),
- 'staffName' => $v['staff_name'],
- 'orderId' => $v['order_id'],
- 'name' => $v['name'],
- 'realName' => $v['real_name'],
- 'orderType' => $v['order_type'],
- ];
- }
- Until::output($list);
- }
- /**
- * @OA\Post(path="/api/room/freeRoom",
- * tags={"房间管理"},
- * summary="还未分配房间",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * @OA\MediaType(
- * mediaType="multipart/form-data",
- * @OA\Schema(
- * @OA\Property(description="门店id", property="storeId", type="integer", default="1"),
- * @OA\Property(description="日期(默认今天)", property="date", type="string", default="2021-04-29"),
- * required={"storeId"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function freeRoom() {
- $input = Until::getInput();
- $rule = [
- 'storeId|门店id' => 'require',
- //'date|日期' => 'require',
- ];
- Until::check($rule, $input);
- $where = [];
- if (empty($input['date'])) {
- $input['date'] = date('Y-m-d');
- }
- $where[] = ['o.status', '=', 2];
- $where[] = ['or.id', '=', null];
- $where[] = ['o.appointment_time', 'between', [$input['date'], date('Y-m-d', strtotime('+1 day', strtotime($input['date'])))]];
- $model = new OrderRoomModel();
- $model->setWhere($where);
- $rs = $model->getfreeRoomList();
- if (empty($rs)) {
- Until::output([]);
- }
- $list = $rs;
- $count = count($rs);
- Until::output(['count' => $count, 'list' => $list]);
- }
- }
|