Admin.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. namespace app\admin\controller\index;
  3. use app\admin\controller\BaseController;
  4. use app\admin\model\SystemAdmin;
  5. use app\admin\server\index\IndexServer;
  6. class Admin extends BaseController
  7. {
  8. /**
  9. * Notes:获取菜单列表
  10. * @return \support\Response
  11. * User: ZQ
  12. * Date: 2022/9/16
  13. */
  14. public function getAdminList()
  15. {
  16. $keywords = $this->request->get('keywords');
  17. $status = $this->request->get('status');
  18. [$page, $limit] = $this->getPage();
  19. $result = IndexServer::getAdminList($keywords,$page,$limit,$status);
  20. $result['keywords'] = $keywords;
  21. $result['status'] = $status;
  22. return json_success($result, '成功');
  23. }
  24. /**
  25. * Notes:修改管理员
  26. * @return \support\Response
  27. * User: ZQ
  28. * Date: 2022/9/16
  29. */
  30. public function updateAdmin()
  31. {
  32. $admin_id = $this->request->post('admin_id');
  33. $admin_real_name = $this->request->post('admin_real_name','');
  34. $admin_pwd = $this->request->post('admin_pwd','');
  35. $agin_admin_pwd = $this->request->post('agin_admin_pwd','');
  36. $admin_roles = $this->request->post('admin_roles');
  37. $admin_status = $this->request->post('admin_status');
  38. if (!empty($admin_pwd) && !empty($agin_admin_pwd)){
  39. if ($admin_pwd != $agin_admin_pwd){
  40. throw new \Exception('两次密码输入不一致!');
  41. }
  42. }
  43. $this->validateCheck('index\IndexValidate', ['admin_id' => $admin_id], 'update');
  44. $result = IndexServer::updateAdmin($admin_id, $admin_real_name, $admin_pwd, $admin_roles, $admin_status);
  45. return json_success($result, '修改成功');
  46. }
  47. /**
  48. * Notes:添加管理员
  49. * @return \support\Response
  50. * User: ZQ
  51. * Date: 2022/9/16
  52. */
  53. public function insertAdmin()
  54. {
  55. $admin_real_name = $this->request->post('admin_real_name','');
  56. $admin_pwd = $this->request->post('admin_pwd','');
  57. $admin_account = $this->request->post('admin_account');
  58. $agin_admin_pwd = $this->request->post('agin_admin_pwd','');
  59. $admin_roles = $this->request->post('admin_roles');
  60. $admin_status = $this->request->post('admin_status');
  61. if (!empty($admin_pwd) && !empty($agin_admin_pwd)){
  62. if ($admin_pwd != $agin_admin_pwd){
  63. throw new \Exception('两次密码输入不一致!');
  64. }
  65. }
  66. $this->validateCheck('index\IndexValidate', ['admin_real_name' => $admin_real_name, 'admin_pwd' => $admin_pwd, 'admin_account' => $admin_account, 'agin_admin_pwd' => $agin_admin_pwd, 'admin_roles' => $admin_roles, 'admin_status' => $admin_status], 'create');
  67. //查询账号是否重复
  68. $status = IndexServer::adminCheck($admin_account);
  69. if (!empty($status)){
  70. throw new \Exception('账号已存在,请更换其他账号!');
  71. }
  72. $result = IndexServer::insertAdmin($admin_account, $admin_real_name, $admin_pwd, $admin_roles, $admin_status);
  73. return json_success($result, '修改成功');
  74. }
  75. /**
  76. * Notes:删除管理员
  77. * @return \support\Response
  78. * User: ZQ
  79. * Date: 2022/9/16
  80. */
  81. public function delAdmin()
  82. {
  83. $admin_id = $this->request->get('admin_id');
  84. $this->validateCheck('index\IndexValidate', ['admin_id' => $admin_id], 'info');
  85. $result = IndexServer::delAdmin($admin_id);
  86. if ($result){
  87. return json_success($result, '删除成功');
  88. }else{
  89. throw new \Exception('删除失败!');
  90. }
  91. }
  92. /**
  93. * Notes:查询管理员详情
  94. * @return \support\Response
  95. * User: ZQ
  96. * Date: 2022/9/13
  97. */
  98. public function adminInfo()
  99. {
  100. $admin_id = $this->request->get('admin_id');
  101. $this->validateCheck('index\IndexValidate', ['admin_id' => $admin_id], 'info');
  102. $result = IndexServer::adminInfo($admin_id);
  103. return json_success($result, '成功');
  104. }
  105. /**
  106. * Notes:管理员启用禁用
  107. * @return \support\Response
  108. * User: ZQ
  109. * Date: 2022/9/13
  110. */
  111. public function updateStatus()
  112. {
  113. $admin_id = $this->request->get('admin_id');
  114. $admin_status = $this->request->get('admin_status');
  115. $this->validateCheck('index\IndexValidate', ['admin_id' => $admin_id], 'info');
  116. $result = IndexServer::updateStatus($admin_id, $admin_status);
  117. return json_success($result, '修改成功');
  118. }
  119. /**
  120. * Notes:存储设备推送信息(健康驿站)
  121. * @return \support\Response
  122. * User: ZQ
  123. * Date: 2022/9/20
  124. */
  125. public function equipmentInsert()
  126. {
  127. $mation = $this->request->post('mation');
  128. $info = json_decode($mation,true);
  129. $log_equipment_id = $info['deviceId'];
  130. $log_content = $info['topic'];
  131. $log_type = $this->request->post('log_type');
  132. $log_msg_type = $this->request->post('log_msg_type');
  133. $result = IndexServer::equipmentLog($log_equipment_id, $log_content, $log_type, $log_msg_type);
  134. return json_success($result, '成功');
  135. }
  136. /**
  137. * Notes:存储设备推送信息(正式版)
  138. * @return \support\Response
  139. * User: ZQ
  140. * Date: 2022/9/20
  141. */
  142. public function logInsert()
  143. {
  144. $mation = $this->request->post('mation');
  145. $info = json_decode($mation,true);
  146. $log_equipment_id = $info['deviceId'];
  147. $log_content = $mation;
  148. $log_type = $this->request->post('log_type');
  149. $log_msg_type = $this->request->post('log_msg_type');
  150. $result = IndexServer::equipmentLog($log_equipment_id, $log_content, $log_type, $log_msg_type);
  151. return json_success($result, '成功');
  152. }
  153. /**
  154. * Notes:接收设备信息并发送
  155. * @return \support\Response
  156. * User: ZQ
  157. * Date: 2022/9/20
  158. */
  159. public function receiveMation()
  160. {
  161. $mation = file_get_contents("php://input");
  162. $url = 'http://192.168.0.139:90/v1/equipment/log';
  163. $urls = 'http://192.168.0.139:84/v1/equipment/log';
  164. $method = 'POST';
  165. $headers = [];
  166. $body = [];
  167. $body['mation'] = $mation;
  168. $body['log_type'] = 0;
  169. $body['log_msg_type'] = '设备数据变化';
  170. if (!empty($mation)){
  171. //正式版后台
  172. $curl = curl_init();
  173. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  174. curl_setopt($curl, CURLOPT_URL, $url);
  175. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  176. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  177. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  178. curl_setopt($curl, CURLOPT_HEADER, true);
  179. if (1 == strpos("$".$url, "https://")){
  180. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  181. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  182. }
  183. curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
  184. $result = curl_exec($curl);
  185. $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
  186. $rheader = substr($result, 0, $header_size);
  187. $rbody = substr($result, $header_size);
  188. $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE);
  189. //健康驿站
  190. $curl = curl_init();
  191. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  192. curl_setopt($curl, CURLOPT_URL, $urls);
  193. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  194. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  195. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  196. curl_setopt($curl, CURLOPT_HEADER, true);
  197. if (1 == strpos("$".$url, "https://")){
  198. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  199. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  200. }
  201. curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
  202. $result = curl_exec($curl);
  203. $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
  204. $rheader = substr($result, 0, $header_size);
  205. $rbody = substr($result, $header_size);
  206. $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE);
  207. }
  208. }
  209. //APP设备消息查询
  210. public function logQuery()
  211. {
  212. $log_equipment_id = $this->request->get('log_equipment_id');
  213. $result = IndexServer::logCheck($log_equipment_id);
  214. if (!empty($result)){
  215. $data = true;
  216. }else{
  217. $data = false;
  218. }
  219. return json_success($data, '成功');
  220. }
  221. /**
  222. * Notes:emqx数据测试
  223. * Type: StayTooLong 久滞事件;FallDown 跌倒事件;OptInOut 进出事件;BreathHeartRate 呼吸心率信息
  224. * PeopleEvent 活动信息;RoomEnv 环境信息;PeopleGesture 手势信息;PeopleCount 人数信息
  225. * HeartBeat 心跳信息
  226. * @return \support\Response
  227. * User: ZQ
  228. * Date: 2022/10/19
  229. */
  230. public function emqxLog()
  231. {
  232. $mation = file_get_contents("php://input");
  233. file_put_contents('MQTTFileGet.txt',$mation);
  234. $info = json_decode($mation,true);
  235. $type = ['StayTooLong'=>'久滞事件','FallDown'=>'跌倒事件','OptInOut'=>'进出事件','BreathHeartRate'=>'呼吸心率信息',
  236. 'PeopleEvent'=>'活动信息','RoomEnv'=>'环境信息','PeopleGesture'=>'手势信息','PeopleCount'=>'人数信息','HeartBeat'=>'心跳信息',];
  237. if (!empty($info)){
  238. $mdid = $info['mdid'];
  239. $user = IndexServer::logCheck($mdid);//根据设备编号查询会员绑定信息
  240. $data = [];
  241. $data['log_user_id'] = $user['equipment_user_id'];
  242. $data['log_equipment_id'] = $user['equipment_id'];
  243. $data['log_type'] = 0;
  244. $data['log_msg_type'] = $type[$info['type']];
  245. $data['log_content'] = $mation;
  246. $data['log_create_time'] = time();
  247. $rusult = IndexServer::logInsert($data);
  248. }
  249. }
  250. /**
  251. * Notes:获取业务控制器列表
  252. * @return \support\Response
  253. * User: ZQ
  254. * Date: 2022/11/17
  255. */
  256. public function businessList()
  257. {
  258. $keywords = $this->request->get('keywords');
  259. [$page, $limit] = $this->getPage();
  260. $result = IndexServer::getBusinessList($keywords,$page,$limit);
  261. $result['keywords'] = $keywords;
  262. return json_success($result, '成功');
  263. }
  264. /**
  265. * Notes:更新业务控制器
  266. * @return \support\Response
  267. * User: ZQ
  268. * Date: 2022/11/17
  269. */
  270. public function businessUpdate()
  271. {
  272. $business = $this->request->post('business');
  273. $business_message = $this->request->post('business_message');
  274. $result = IndexServer::updateBusiness($business,$business_message);
  275. if ($result){
  276. return json_success($result, '更新成功');
  277. }else{
  278. throw new \Exception('更新失败~');
  279. }
  280. }
  281. /**
  282. * Notes:添加业务控制器
  283. * @return \support\Response
  284. * User: ZQ
  285. * Date: 2022/11/17
  286. */
  287. public function businessInsert()
  288. {
  289. $business_name = $this->request->post('business_name');
  290. $business_status = $this->request->post('business_status');
  291. $business_message = $this->request->post('business_message','');
  292. $result = IndexServer::insertBusiness($business_name,$business_status,$business_message);
  293. if ($result){
  294. return json_success($result, '添加成功');
  295. }else{
  296. throw new \Exception('添加失败~');
  297. }
  298. }
  299. }