Shouhuan.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\logic\Shouhuanlogic;
  4. //use app\common\server\ShouhuanCommand;
  5. use think\Controller;
  6. /**
  7. * 套餐配送
  8. *
  9. * @author wj
  10. * @date 2022-12-03
  11. */
  12. class Shouhuan extends Controller
  13. {
  14. protected $middleware = [\app\common\middleware\checkfacility::class];
  15. /**
  16. * 创建命令
  17. *
  18. * @return void
  19. * @author wj
  20. * @date 2023-09-02
  21. */
  22. public function createcommand()
  23. {
  24. $commandlist = [
  25. 'init', //初始化
  26. 'cr', //定位
  27. 'poweroff', //关机
  28. 'sos', //sos
  29. 'interval', //间隔
  30. 'falldown', //跌倒
  31. 'pedo', //计步开关
  32. 'phl', //电话本
  33. 'remind', //闹钟
  34. 'silencetime2', //静默时间
  35. 'remove', //佩戴提醒
  36. 'bootoff', //开关机时间
  37. 'call', //拨打电话
  38. 'keybrd', //拨号开关
  39. ];
  40. $data = request()->post();
  41. $command = $data['command'];
  42. if (in_array($command, $commandlist)) {
  43. $functionname = 'ctreate' . ucwords($command) . "Command";
  44. if (method_exists($this, $functionname)) {
  45. try {
  46. $facility_id = $data['facility_id'];
  47. $device_id_code = $data['device_id_code'];
  48. $param = !isset($data['param']) || empty($data['param']) ? [] : $data['param'];
  49. if (is_string($param)) {
  50. $param = json_decode($param, true);
  51. }
  52. $userinfo = request()->suinfo;
  53. $sys_user_id = $userinfo['user_id'];
  54. $result = $this->$functionname($facility_id, $device_id_code, $param, $sys_user_id);
  55. return $this->successjson($result['msg']);
  56. } catch (\Exception $e) {
  57. return $this->errorjson($e->getMessage());
  58. }
  59. }
  60. }
  61. $this->errorjson("命令错误");
  62. }
  63. private function ctreateInitCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  64. {
  65. $l_s = new Shouhuanlogic();
  66. $result = $l_s->facilityinit($facility_id, $device_id_code, $param, $sys_user_id);
  67. return $result;
  68. }
  69. private function ctreateCrCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  70. {
  71. $l_s = new Shouhuanlogic();
  72. $result = $l_s->createcrcommand($facility_id, $device_id_code, $param, $sys_user_id);
  73. return $result;
  74. }
  75. private function ctreatePoweroffCommand($facility_id, $device_id_code, $param, $sys_user_id)
  76. {
  77. $l_s = new Shouhuanlogic();
  78. $result = $l_s->createpoweroffcommand($facility_id, $device_id_code, $param, $sys_user_id);
  79. return $result;
  80. }
  81. private function ctreateSosCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  82. {
  83. $l_s = new Shouhuanlogic();
  84. $result = $l_s->createsoscommand($facility_id, $device_id_code, $param, $sys_user_id);
  85. return $result;
  86. }
  87. private function ctreateIntervalCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  88. {
  89. $l_s = new Shouhuanlogic();
  90. $result = $l_s->ctreateintervalcommand($facility_id, $device_id_code, $param, $sys_user_id);
  91. return $result;
  92. }
  93. private function ctreateFalldownCommand($facility_id, $device_id_code, $param, $sys_user_id)
  94. {
  95. $l_s = new Shouhuanlogic();
  96. $result = $l_s->createfalldowncommand($facility_id, $device_id_code, $param, $sys_user_id);
  97. return $result;
  98. }
  99. private function ctreatePedoCommand($facility_id, $device_id_code, $param, $sys_user_id)
  100. {
  101. $l_s = new Shouhuanlogic();
  102. $result = $l_s->createpedocommand($facility_id, $device_id_code, $param, $sys_user_id);
  103. return $result;
  104. }
  105. private function ctreatePhlCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  106. {
  107. $l_s = new Shouhuanlogic();
  108. $result = $l_s->createphlcommand($facility_id, $device_id_code, $param, $sys_user_id);
  109. return $result;
  110. }
  111. private function ctreateRemindCommand($facility_id, $device_id_code, $param, $sys_user_id)
  112. {
  113. $l_s = new Shouhuanlogic();
  114. $result = $l_s->createremindcommand($facility_id, $device_id_code, $param, $sys_user_id);
  115. return $result;
  116. }
  117. private function ctreateSilencetime2Command($facility_id, $device_id_code, $param, $sys_user_id)
  118. {
  119. $l_s = new Shouhuanlogic();
  120. $result = $l_s->createsilencetime2command($facility_id, $device_id_code, $param, $sys_user_id);
  121. return $result;
  122. }
  123. private function ctreateRemoveCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  124. {
  125. $l_s = new Shouhuanlogic();
  126. $result = $l_s->createremovecommand($facility_id, $device_id_code, $param, $sys_user_id);
  127. return $result;
  128. }
  129. private function ctreateBootoffCommand($facility_id, $device_id_code, $param, $sys_user_id)
  130. {
  131. $l_s = new Shouhuanlogic();
  132. $result = $l_s->createbootoffcommand($facility_id, $device_id_code, $param, $sys_user_id);
  133. return $result;
  134. }
  135. private function ctreateCallCommand($facility_id, $device_id_code, $param, $sys_user_id)
  136. {
  137. $l_s = new Shouhuanlogic();
  138. $result = $l_s->createcallcommand($facility_id, $device_id_code, $param, $sys_user_id);
  139. return $result;
  140. }
  141. private function ctreateKeybrdCommand($facility_id, $device_id_code, $param, $sys_user_id)
  142. {
  143. $l_s = new Shouhuanlogic();
  144. $result = $l_s->createkeybrdcommand($facility_id, $device_id_code, $param, $sys_user_id);
  145. return $result;
  146. }
  147. /**
  148. * 返回正确信息
  149. *
  150. * @return void
  151. * @author wj
  152. * @date 2023-09-02
  153. */
  154. private function successjson($msg, $data = [])
  155. {
  156. return backjson2(200, $msg, $data);
  157. }
  158. /**
  159. * 返回错误信息
  160. *
  161. * @return void
  162. * @author wj
  163. * @date 2023-09-02
  164. */
  165. private function errorjson($msg)
  166. {
  167. return backjson2(500, $msg);
  168. }
  169. }