Shouhuanlogic.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. namespace app\api\logic;
  3. use app\common\model\SettingModel;
  4. use app\common\server\ShouhuanCommand;
  5. /**
  6. * 手环处理
  7. * 低电报警开关 跌倒报警开关 睡眠时间段设置 立即定位 设置翻滚时间 设置sos电话 设置电话本
  8. * 发送间隔 设备初始化
  9. *
  10. * @author wj
  11. * @date 2023-08-29
  12. */
  13. class Shouhuanlogic
  14. {
  15. /**
  16. * 设备初始化
  17. *
  18. * @return void
  19. * @author wj
  20. * @date 2023-08-29
  21. */
  22. public function facilityinit($facility_id, $device_id_code, $sys_user_id)
  23. {
  24. $m_s = new SettingModel();
  25. $s_sc = new ShouhuanCommand();
  26. $zone = $m_s->getvalue('shouhuan_zone'); //时区
  27. $upload_interval = $m_s->getvalue('shouhuan_local_space'); //定位间隔
  28. $fd_is_open = $m_s->getvalue('shouhuan_fall_call'); //定位间隔
  29. $pedo_is_open = $m_s->getvalue('shouhuan_step_status'); //计步开关
  30. $remove_is_open = $m_s->getvalue('shouhuan_wear_call'); //佩戴开关
  31. $param = [
  32. 'zone' => $zone,
  33. 'upload_interval' => $upload_interval,
  34. 'fd_is_open' => $fd_is_open,
  35. 'lowbat_is_open' => 1,
  36. 'pedo_is_open' => $pedo_is_open,
  37. 'remove_is_open' => $remove_is_open,
  38. ];
  39. $s_sc->facilityinit($facility_id, $device_id_code, $param, $sys_user_id);
  40. return backarr(1, "操作成功");
  41. }
  42. /**
  43. * 低电报警开关
  44. *
  45. * @param [type] $arr
  46. * @return void
  47. * @author wj
  48. * @date 2023-08-29
  49. */
  50. public function createlowbatcommand($facility_id, $device_id_code, $param, $sys_user_id)
  51. {
  52. if (!isset($param['is_open'])) {
  53. throw new \Exception("参数错误");
  54. }
  55. $is_open = empty($param['is_open']) ? 0 : 1;
  56. $s_sc = new ShouhuanCommand();
  57. $s_sc->createlowbatcommand($facility_id, $device_id_code, $is_open, $sys_user_id);
  58. return backarr(1, "操作成功");
  59. }
  60. /**
  61. * 设置 跌倒报警开关
  62. *
  63. * @param [type] $arr
  64. * @return void
  65. * @author wj
  66. * @date 2023-08-29
  67. * lsset_type 灵敏度类型 1高 2中 3低
  68. */
  69. public function createfalldowncommand($facility_id, $device_id_code, $param, $sys_user_id)
  70. {
  71. if (!isset($param['is_open']) || !isset($param['lsset_type'])) {
  72. throw new \Exception("参数错误");
  73. }
  74. $lsset_type = [1, 2, 3];
  75. if (!in_array($param['lsset_type'], $lsset_type)) {
  76. $param['lsset_type'] = 1;
  77. }
  78. $param['is_open'] = empty($param['is_open']) ? 0 : 1;
  79. $s_sc = new ShouhuanCommand();
  80. $s_sc->createfalldowncommand($facility_id, $device_id_code, $param, $sys_user_id);
  81. return backarr(1, "操作成功");
  82. }
  83. //['starttime'=>'21:00','endtime'=>'6:00'];
  84. /**
  85. * 设置睡眠/翻滚时间段
  86. *
  87. * @param [type] $arr
  88. * @return void
  89. * @author wj
  90. * @date 2023-08-29
  91. * 参数格式 ['starttime'=>'21:00','endtime'=>'6:00'];
  92. */
  93. public function createsleeptimecommand($facility_id, $device_id_code, $data, $sys_user_id)
  94. {
  95. $param = ['starttime' => $data['starttime'], 'endtime' => $data['endtime']];
  96. $s_sc = new ShouhuanCommand();
  97. $s_sc->createsleeptimecommand($facility_id, $device_id_code, $param, $sys_user_id);
  98. return backarr(1, "操作成功");
  99. }
  100. //立即定位
  101. public function createcrcommand($facility_id, $device_id_code, $sys_user_id)
  102. {
  103. $s_sc = new ShouhuanCommand();
  104. $s_sc->createcrcommand($facility_id, $device_id_code, $sys_user_id);
  105. return backarr(1, "操作成功");
  106. }
  107. //设置sos 电话
  108. /**
  109. * 设置sos 电话
  110. * tels 一维数组 未验证是否为手机号
  111. * @param [type] $arr
  112. * @return void
  113. * @author wj
  114. * @date 2023-08-29
  115. */
  116. public function createsoscommand($facility_id, $device_id_code, $data, $sys_user_id)
  117. {
  118. if (!isset($data['tels'])) {
  119. throw new \Exception("参数错误");
  120. }
  121. $param = $data['tels'];
  122. $s_sc = new ShouhuanCommand();
  123. $s_sc->createsoscommand($facility_id, $device_id_code, $param, $sys_user_id);
  124. return backarr(1, "操作成功");
  125. }
  126. //设置电话本
  127. /**
  128. * 设置电话本
  129. * 参数格式
  130. * $phldata = [
  131. * ['telno' => '12344', 'name' => '测试2'],
  132. * ['telno' => '123', 'name' => '测试'],
  133. * ];
  134. * @param [type] $arr
  135. * @return void
  136. * @author wj
  137. * @date 2023-08-29
  138. */
  139. public function createphlcommand($facility_id, $device_id_code, $data, $sys_user_id)
  140. {
  141. $param = $data;
  142. $s_sc = new ShouhuanCommand();
  143. $s_sc->createphlcommand($facility_id, $device_id_code, $param, $sys_user_id);
  144. return backarr(1, "操作成功");
  145. }
  146. /**
  147. * 数据间隔设置
  148. *
  149. * @param [type] $facility_id
  150. * @param [type] $device_id_code
  151. * @param [type] $data
  152. * @param [type] $sys_user_id
  153. * @return void
  154. * @author wj
  155. * @date 2023-09-05
  156. */
  157. public function ctreateintervalcommand($facility_id, $device_id_code, $data, $sys_user_id)
  158. {
  159. $m_s = new SettingModel();
  160. $s_sc = new ShouhuanCommand();
  161. $usedata = [];
  162. //定位
  163. if (!isset($data['cr_interval']) || empty($data['cr_interval'])) {
  164. $cr_interval = $m_s->getvalue('shouhuan_local_space'); //分钟
  165. } else {
  166. $cr_interval = $data['cr_interval'];
  167. }
  168. $usedata['cr_interval'] = bcmul((int) $cr_interval, 60);
  169. //心率
  170. if (!isset($data['hrt_interval']) || empty($data['hrt_interval'])) {
  171. $hrt_interval = $m_s->getvalue('shouhuan_heart_space'); //分钟
  172. } else {
  173. $hrt_interval = $data['hrt_interval'];
  174. }
  175. $usedata['hrt_interval'] = bcmul((int) $hrt_interval, 60);
  176. //体温
  177. if (!isset($data['wd_interval']) || empty($data['wd_interval'])) {
  178. $wd_interval = $m_s->getvalue('shouhuan_body_space'); //分钟
  179. } else {
  180. $wd_interval = $data['wd_interval'];
  181. }
  182. $usedata['wd_interval'] = bcmul((int) $wd_interval, 60);
  183. //血压
  184. if (!isset($data['bld_interval']) || empty($data['bld_interval'])) {
  185. $bld_interval = $m_s->getvalue('shouhuan_blood_space'); //分钟
  186. } else {
  187. $bld_interval = $data['bld_interval'];
  188. }
  189. $usedata['bld_interval'] = bcmul((int) $bld_interval, 60);
  190. //血氧
  191. if (!isset($data['ox_interval']) || empty($data['ox_interval'])) {
  192. $ox_interval = $m_s->getvalue('shouhuan_oxygen_space'); //分钟
  193. } else {
  194. $ox_interval = $data['ox_interval'];
  195. }
  196. $usedata['ox_interval'] = bcmul((int) $ox_interval, 60);
  197. $s_sc->setdatainterval($facility_id, $device_id_code, $usedata, $sys_user_id);
  198. return backarr(1, "操作成功");
  199. }
  200. /**
  201. * 关机
  202. *
  203. * @param [type] $facility_id
  204. * @param [type] $device_id_code
  205. * @param [type] $sys_user_id
  206. * @return void
  207. * @author wj
  208. * @date 2023-09-05
  209. */
  210. public function createpoweroffcommand($facility_id, $device_id_code, $sys_user_id)
  211. {
  212. $s_sc = new ShouhuanCommand();
  213. $s_sc->createpoweroffcommand($facility_id, $device_id_code, $sys_user_id);
  214. return backarr(1, "操作成功");
  215. }
  216. /**
  217. * 静默时间
  218. *
  219. * @param [type] $facility_id
  220. * @param [type] $device_id_code
  221. * @param [type] $param
  222. * @param [type] $sys_user_id
  223. * @return void
  224. * @author wj
  225. * @date 2023-09-05
  226. */
  227. public function createsilencetime2command($facility_id, $device_id_code, $param, $sys_user_id)
  228. {
  229. $s_sc = new ShouhuanCommand();
  230. $s_sc->createsilencetime2command($facility_id, $device_id_code, $param, $sys_user_id);
  231. return backarr(1, "操作成功");
  232. }
  233. /**
  234. * 开关机时间
  235. *
  236. * @return void
  237. * @author wj
  238. * @date 2023-09-05
  239. */
  240. public function createbootoffcommand($facility_id, $device_id_code, $param, $sys_user_id)
  241. {
  242. $s_sc = new ShouhuanCommand();
  243. $s_sc->createbootoffcommand($facility_id, $device_id_code, $param, $sys_user_id);
  244. return backarr(1, "操作成功");
  245. }
  246. /**
  247. * 佩戴提醒
  248. *
  249. * @param [type] $facility_id
  250. * @param [type] $device_id_code
  251. * @param [type] $param
  252. * @param [type] $sys_user_id
  253. * @return void
  254. * @author wj
  255. * @date 2023-09-05
  256. */
  257. public function createremovecommand($facility_id, $device_id_code, $param, $sys_user_id)
  258. {
  259. if (!isset($param['is_open'])) {
  260. throw new \Exception("参数错误");
  261. }
  262. $is_open = empty($param['is_open']) ? 0 : 1;
  263. $s_sc = new ShouhuanCommand();
  264. $s_sc->createremovecommand($facility_id, $device_id_code, $is_open, $sys_user_id);
  265. return backarr(1, "操作成功");
  266. }
  267. /**
  268. * 闹钟
  269. *
  270. * @param [type] $facility_id
  271. * @param [type] $device_id_code
  272. * @param [type] $param
  273. * @param [type] $sys_user_id
  274. * @return void
  275. * @author wj
  276. * @date 2023-09-05
  277. */
  278. public function createremindcommand($facility_id, $device_id_code, $param, $sys_user_id)
  279. {
  280. $s_sc = new ShouhuanCommand();
  281. $s_sc->createremindcommand($facility_id, $device_id_code, $param, $sys_user_id);
  282. return backarr(1, "操作成功");
  283. }
  284. /**
  285. * 计步开关
  286. *
  287. * @return void
  288. * @author wj
  289. * @date 2023-09-05
  290. */
  291. public function createpedocommand($facility_id, $device_id_code, $param, $sys_user_id)
  292. {
  293. if (!isset($param['is_open'])) {
  294. throw new \Exception("参数错误");
  295. }
  296. $is_open = empty($param['is_open']) ? 0 : 1;
  297. $s_sc = new ShouhuanCommand();
  298. $s_sc->createpedocommand($facility_id, $device_id_code, $is_open, $sys_user_id);
  299. return backarr(1, "操作成功");
  300. }
  301. /**
  302. * 拨打电话
  303. *
  304. * @param [type] $facility_id
  305. * @param [type] $device_id_code
  306. * @param [type] $param
  307. * @param [type] $sys_user_id
  308. * @return void
  309. * @author wj
  310. * @date 2023-09-15
  311. */
  312. public function createcallcommand($facility_id, $device_id_code, $param, $sys_user_id)
  313. {
  314. if (!isset($param['telno']) || empty($param['telno'])) {
  315. throw new \Exception("参数错误");
  316. }
  317. $telno = $param['telno'];
  318. $s_sc = new ShouhuanCommand();
  319. $s_sc->createcallcommand($facility_id, $device_id_code, $telno, $sys_user_id);
  320. return backarr(1, "操作成功");
  321. }
  322. /**
  323. * 拨号开关
  324. *
  325. * @param [type] $facility_id
  326. * @param [type] $device_id_code
  327. * @param [type] $param
  328. * @param [type] $sys_user_id
  329. * @return void
  330. * @author wj
  331. * @date 2023-09-18
  332. */
  333. public function createkeybrdcommand($facility_id, $device_id_code, $param, $sys_user_id)
  334. {
  335. if (!isset($param['is_open'])) {
  336. throw new \Exception("参数错误");
  337. }
  338. $is_open = empty($param['is_open']) ? 0 : 1;
  339. $s_sc = new ShouhuanCommand();
  340. $s_sc->createkeybrdcommand($facility_id, $device_id_code, $is_open, $sys_user_id);
  341. return backarr(1, "操作成功");
  342. }
  343. }