Shouhuan.php 5.5 KB

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