Shouhuan.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. ];
  39. $data = request()->post();
  40. $command = $data['command'];
  41. if (in_array($command, $commandlist)) {
  42. $functionname = 'ctreate' . ucwords($command) . "Command";
  43. if (method_exists($this, $functionname)) {
  44. try {
  45. $facility_id = $data['facility_id'];
  46. $device_id_code = $data['device_id_code'];
  47. $param = !isset($data['param']) || empty($data['param']) ? [] : $data['param'];
  48. if (is_string($param)) {
  49. $param = json_decode($param, true);
  50. }
  51. $userinfo = request()->suinfo;
  52. $sys_user_id = $userinfo['user_id'];
  53. $result = $this->$functionname($facility_id, $device_id_code, $param, $sys_user_id);
  54. return $this->successjson($result['msg']);
  55. } catch (\Exception $e) {
  56. return $this->errorjson($e->getMessage());
  57. }
  58. }
  59. }
  60. $this->errorjson("命令错误");
  61. }
  62. private function ctreateInitCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  63. {
  64. $l_s = new Shouhuanlogic();
  65. $result = $l_s->facilityinit($facility_id, $device_id_code, $param, $sys_user_id);
  66. return $result;
  67. }
  68. private function ctreateCrCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  69. {
  70. $l_s = new Shouhuanlogic();
  71. $result = $l_s->createcrcommand($facility_id, $device_id_code, $param, $sys_user_id);
  72. return $result;
  73. }
  74. private function ctreatePoweroffCommand($facility_id, $device_id_code, $param, $sys_user_id)
  75. {
  76. $l_s = new Shouhuanlogic();
  77. $result = $l_s->createpoweroffcommand($facility_id, $device_id_code, $param, $sys_user_id);
  78. return $result;
  79. }
  80. private function ctreateSosCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  81. {
  82. $l_s = new Shouhuanlogic();
  83. $result = $l_s->createsoscommand($facility_id, $device_id_code, $param, $sys_user_id);
  84. return $result;
  85. }
  86. private function ctreateIntervalCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  87. {
  88. $l_s = new Shouhuanlogic();
  89. $result = $l_s->ctreateintervalcommand($facility_id, $device_id_code, $param, $sys_user_id);
  90. return $result;
  91. }
  92. private function ctreateFalldownCommand($facility_id, $device_id_code, $param, $sys_user_id)
  93. {
  94. $l_s = new Shouhuanlogic();
  95. $result = $l_s->createfalldowncommand($facility_id, $device_id_code, $param, $sys_user_id);
  96. return $result;
  97. }
  98. private function ctreatePedoCommand($facility_id, $device_id_code, $param, $sys_user_id)
  99. {
  100. $l_s = new Shouhuanlogic();
  101. $result = $l_s->createpedocommand($facility_id, $device_id_code, $param, $sys_user_id);
  102. return $result;
  103. }
  104. private function ctreatePhlCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  105. {
  106. $l_s = new Shouhuanlogic();
  107. $result = $l_s->createphlcommand($facility_id, $device_id_code, $param, $sys_user_id);
  108. return $result;
  109. }
  110. private function ctreateRemindCommand($facility_id, $device_id_code, $param, $sys_user_id)
  111. {
  112. $l_s = new Shouhuanlogic();
  113. $result = $l_s->createremindcommand($facility_id, $device_id_code, $param, $sys_user_id);
  114. return $result;
  115. }
  116. private function ctreateSilencetime2Command($facility_id, $device_id_code, $param, $sys_user_id)
  117. {
  118. $l_s = new Shouhuanlogic();
  119. $result = $l_s->createsilencetime2command($facility_id, $device_id_code, $param, $sys_user_id);
  120. return $result;
  121. }
  122. private function ctreateRemoveCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
  123. {
  124. $l_s = new Shouhuanlogic();
  125. $result = $l_s->createremovecommand($facility_id, $device_id_code, $param, $sys_user_id);
  126. return $result;
  127. }
  128. private function ctreateBootoffCommand($facility_id, $device_id_code, $param, $sys_user_id)
  129. {
  130. $l_s = new Shouhuanlogic();
  131. $result = $l_s->createbootoffcommand($facility_id, $device_id_code, $param, $sys_user_id);
  132. return $result;
  133. }
  134. private function ctreateCallCommand($facility_id, $device_id_code, $param, $sys_user_id)
  135. {
  136. $l_s = new Shouhuanlogic();
  137. $result = $l_s->createcallcommand($facility_id, $device_id_code, $param, $sys_user_id);
  138. return $result;
  139. }
  140. /**
  141. * 返回正确信息
  142. *
  143. * @return void
  144. * @author wj
  145. * @date 2023-09-02
  146. */
  147. private function successjson($msg, $data = [])
  148. {
  149. return backjson2(200, $msg, $data);
  150. }
  151. /**
  152. * 返回错误信息
  153. *
  154. * @return void
  155. * @author wj
  156. * @date 2023-09-02
  157. */
  158. private function errorjson($msg)
  159. {
  160. return backjson2(500, $msg);
  161. }
  162. }