Office.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\BuildingModel;
  5. use app\common\model\BusinessModel;
  6. use app\common\model\OfficeModel;
  7. use app\common\model\OfficeOrderModel;
  8. use app\common\model\Park;
  9. use think\Db;
  10. /**
  11. * 租赁管理
  12. */
  13. class Office extends Api
  14. {
  15. protected $noNeedLogin = ['lists', 'parkLists', 'listInfo', 'qustion', 'qustionInfo', 'buildInfo', 'protable', 'cityLists', 'NoticeInfo', 'GgInfo'];
  16. protected $noNeedRight = ['*'];
  17. /**
  18. * 园区列表
  19. */
  20. public function parkLists()
  21. {
  22. $parkModel = Park::where('switch', 1)->order('sort desc')->select();
  23. if ($parkModel) {
  24. return $this->success('', $parkModel);
  25. } else {
  26. return $this->success('暂无园区', []);
  27. }
  28. }
  29. /**
  30. * 搜索数据
  31. */
  32. public function cityLists()
  33. {
  34. $data['area'] = Db::name('city')->order('eng asc')->select();
  35. $data['num'] = [
  36. ['label' => "全部", 'value' => 1],
  37. ['label' => "0-10座", 'value' => 2],
  38. ['label' => "10-30座", 'value' => 3],
  39. ['label' => "30-50座", 'value' => 4],
  40. ['label' => "20-100座", 'value' => 5],
  41. ['label' => "100-200座", 'value' => 6],
  42. ['label' => "200-300座", 'value' => 7],
  43. ['label' => "300座以上", 'value' => 8],
  44. ];
  45. $data['money'] = [
  46. ['label' => "全部", 'value' => 1],
  47. ['label' => "0-100/60分钟", 'value' => 2],
  48. ['label' => "100-200/60分钟", 'value' => 3],
  49. ['label' => "200-500/60分钟", 'value' => 4],
  50. ['label' => "500-1000/60分钟", 'value' => 5],
  51. ['label' => "1000+/60分钟", 'value' => 6],
  52. ];
  53. return $this->success('', $data);
  54. }
  55. /**
  56. * 办公室列表
  57. * @param string $page 页数
  58. * @param string $limit 条数
  59. * @param string $area_name 条数
  60. * @param string $area_id 地区id
  61. * @param string $num 座位
  62. * @param string $money 租金
  63. */
  64. public function lists()
  65. {
  66. $page = $this->request->get('page');
  67. $limit = $this->request->get('limit');
  68. $area_name = $this->request->get('area_name');
  69. $area_id = $this->request->get('area_id');
  70. $num = $this->request->get('num');
  71. $money = $this->request->get('money');
  72. $mp = [];
  73. if (isset($area_id) && !empty($area_id)) $mp['c_id'] = $area_id;
  74. if (isset($area_name) && !empty($area_name)) {
  75. $name = Park::where('name','like','%'.$area_name.'%')->column('id');
  76. $idStr = implode(',',$name);
  77. if (!empty($idStr)) {
  78. $mp['p_id'] = ['in',$idStr];
  79. } else {
  80. $mp['p_id'] = 0;
  81. }
  82. };
  83. if (isset($num) && !empty($num)) {
  84. if ($num == 2) {
  85. $mp['num'] = ['between', '0,10'];
  86. } else if ($num == 3) {
  87. $mp['num'] = ['between', '10,30'];
  88. } else if ($num == 4) {
  89. $mp['num'] = ['between', '30,50'];
  90. } else if ($num == 5) {
  91. $mp['num'] = ['between', '50,100'];
  92. } else if ($num == 6) {
  93. $mp['num'] = ['between', '100,200'];
  94. } else if ($num == 7) {
  95. $mp['num'] = ['between', '200,300'];
  96. } else if ($num == 8) {
  97. $mp['num'] = ['>', '300'];
  98. }
  99. }
  100. if (isset($money) && !empty($money)) {
  101. if ($money == 2) {
  102. $mp['money_num'] = ['between', '0,100'];
  103. } else if ($money == 3) {
  104. $mp['money_num'] = ['between', '100,200'];
  105. } else if ($num == 4) {
  106. $mp['money_num'] = ['between', '200,500'];
  107. } else if ($money == 5) {
  108. $mp['money_num'] = ['between', '500,1000'];
  109. } else if ($money == 6) {
  110. $mp['money_num'] = ['>', '1000'];
  111. }
  112. }
  113. if (empty($area_name)) {
  114. $user = $this->auth->getUser();
  115. if ($user && $user['p_id'] != 0) $mp['p_id'] = $user['p_id'];
  116. };
  117. $mp['switch'] = 1;
  118. if (!$page) {
  119. $pages = '0,10';
  120. } else {
  121. $page = $page - 1;
  122. if ($page < 0) $page = 0;
  123. $pages = $page . ',' . $limit;
  124. }
  125. $officeModel = new OfficeModel();
  126. $field = 'id,image,title,money,wuye,mianji,address,num';
  127. $data = $officeModel->where($mp)->limit($pages)->field($field)->order('sort desc')->select();
  128. if ($data) {
  129. return $this->success('', $data);
  130. } else {
  131. return $this->success('暂无数据');
  132. }
  133. }
  134. /**
  135. * 办公室详情
  136. * @param string $id id
  137. *
  138. */
  139. public function listInfo()
  140. {
  141. $id = $this->request->get('id');
  142. if (!isset($id) || empty($id)) return $this->error('缺少参数');
  143. $officeModel = new OfficeModel();
  144. $data = $officeModel->where('switch', 1)
  145. ->where('id', $id)
  146. ->order('sort desc')
  147. ->find();
  148. if ($data) {
  149. return $this->success('', $data);
  150. } else {
  151. return $this->success('暂无数据');
  152. }
  153. }
  154. /**
  155. * 租办公室
  156. * @param string $oid 办公室id
  157. * @param string $name 用户
  158. * @param string $phone 手机号
  159. */
  160. public function order()
  161. {
  162. $oid = $this->request->get('oid');
  163. $name = $this->request->get('name');
  164. $phone = $this->request->get('phone');
  165. if (!isset($oid) || empty($oid)) return $this->error('参数错误');
  166. if (!isset($name) || empty($name)) return $this->error('参数错误');
  167. if (!isset($phone) || empty($phone)) return $this->error('参数错误');
  168. $user = $this->auth->getUser();
  169. $year = date('Y', time());
  170. $month = date('m', time());
  171. $day = date('d', time());
  172. $data = [
  173. 'uid' => $user['id'],
  174. 'oid' => $oid,
  175. 'name' => $name,
  176. 'phone' => $phone,
  177. 'create_time' => date('Y-m-d H:i:s', time()),
  178. 'number' => $year . $month . $day . 'N' . rand(0, 10000),
  179. ];
  180. $model = new OfficeOrderModel();
  181. $ins = $model->save($data);
  182. if ($ins) {
  183. $id = $model->getLastInsID();
  184. return $this->success('申请成功', ['id' => $id]);
  185. } else {
  186. return $this->error('申请失败哦!', ['id' => 0]);
  187. }
  188. }
  189. /**
  190. * 成功返回数据
  191. * @param string $id 订单id
  192. */
  193. public function orderInfo()
  194. {
  195. $id = $this->request->get('id');
  196. if (!isset($id) || empty($id)) return $this->error('参数错误');
  197. $model = new OfficeOrderModel();
  198. $data = $model
  199. ->with(['office'])
  200. ->where('id', $id)
  201. ->select();
  202. return $this->success('', $data);
  203. }
  204. }