|
@@ -0,0 +1,202 @@
|
|
|
+<?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="status", in="query", description="1正常 2禁用", @OA\Schema(type="integer",default="1")),
|
|
|
+ * @OA\Parameter(name="name", in="query", description="名字或code", @OA\Schema(type="integer",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'])) {
|
|
|
+ $where[] = ['r.status', '=', (int)$input['status']];
|
|
|
+ }
|
|
|
+ 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'],
|
|
|
+ 'room_id' => $input['id']
|
|
|
+ ];
|
|
|
+ $model = new OrderRoomModel();
|
|
|
+ $rs = $model::where($data)->find();
|
|
|
+ if (empty($rs)) {
|
|
|
+ $model->insert($data);
|
|
|
+ }else {
|
|
|
+ $model::where(['order_id' => $input['orderId']])->update(['room_id' => $input['id']]);
|
|
|
+ }
|
|
|
+ Until::output();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|