ServerService.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2021/6/23 15:11
  5. */
  6. namespace app\common\service;
  7. use app\api\exception\ApiException;
  8. use app\api\model\AllocateModel;
  9. use app\api\model\OrderModel;
  10. use app\api\model\OrderRoomModel;
  11. use app\api\model\RoomModel;
  12. use app\api\model\StaffModel;
  13. use app\common\until\Until;
  14. use think\Model;
  15. class ServerService {
  16. public function startService(int $orderId) {
  17. $allocateModel = new AllocateModel();
  18. $model = new OrderModel();
  19. $roomOrder = new OrderRoomModel();
  20. $order = $model::where(['id' =>$orderId])->find();
  21. if (empty($order)) {
  22. throw new ApiException('无此订单');
  23. }
  24. if ($order['status'] != 2) {
  25. throw new ApiException('订单必须是支付状态');
  26. }
  27. $rs = $allocateModel::where(['order_id' => $orderId])->find();
  28. if (empty($rs)) {
  29. throw new ApiException('该服务还没分配职员');
  30. } else {
  31. if ($rs['status'] == 3) {
  32. throw new ApiException('该服务已完成');
  33. }
  34. if ($rs['status'] == 2) {
  35. throw new ApiException('该服务正在进行');
  36. }
  37. }
  38. $orderRoomRs = $roomOrder::where(['order_id' =>$orderId])->find();
  39. if ($orderRoomRs === null) {
  40. throw new ApiException('请分配房间');
  41. }
  42. if (!empty($this->adminId)) {
  43. $opId = $this->adminId;
  44. $opType = 'admin';
  45. } else {
  46. $opId = Until::$userId;
  47. $opType = 'xcx';
  48. }
  49. (new RoomModel())::where(['id' => $orderRoomRs['room_id']])->update(['room_server_status' => 2]);
  50. $allocateModel::where(['id' => $rs['id']])->update(['status' => 2, 'start_id' => $opId, 'op_type' => $opType, 'server_start_time' => date('Y-m-d H:i:s')]);
  51. (new StaffModel())::where(['id' => $rs['staff_id']])->update(['server_status' => 3]);
  52. }
  53. public static function getStaffByCode(string $braceletCode) {
  54. $staffModel = new Staffmodel();
  55. $staffInfo = $staffModel::where(['bracelet_code' => $braceletCode,'status' => Staffmodel::NORMAL])->find();
  56. $staffInfo = Until::modelToArray($staffInfo);
  57. if (empty($staffInfo)) {
  58. throw new apiexception('无此职员');
  59. }
  60. return $staffInfo;
  61. }
  62. public static function getRoomByCode(string $roomCode) {
  63. $model = new RoomModel();
  64. $roomInfo = $model::where(['clock_code' => $roomCode,'status' => StaffModel::NORMAL])->find();
  65. $roomInfo = Until::modelToArray($roomInfo);
  66. if (empty($roomInfo) || empty($roomInfo['store_id'])) {
  67. throw new ApiException('无此门店');
  68. }
  69. return $roomInfo;
  70. }
  71. }