IndexServer.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <?php
  2. namespace app\admin\server\index;
  3. use app\admin\model\SystemAdmin;
  4. use app\admin\model\SystemBusiness;
  5. use app\admin\model\SystemRole;
  6. use app\admin\model\IntelligenceLog;
  7. use app\admin\model\IntelligenceUser;
  8. use app\admin\model\SystemPage;
  9. use think\contract\Jsonable;
  10. class IndexServer
  11. {
  12. /**
  13. * Notes:管理员列表
  14. * @param string $keywords
  15. * @return bool
  16. * @throws \Exception
  17. * User: ZQ
  18. * Date: 2022/9/16
  19. */
  20. public static function getAdminList(string $keywords, int $page, int $limit, $status)
  21. {
  22. [$list, $count] = SystemAdmin::adminList($keywords, $page, $limit, $status);
  23. if (!empty($list)){
  24. foreach ($list as $k => $v){
  25. if ($v['admin_status'] == 1){
  26. $list[$k]['admin_status'] = true;
  27. }else{
  28. $list[$k]['admin_status'] = false;
  29. }
  30. if (!empty($v['admin_roles'])){
  31. $admin_roles = explode(',',$v['admin_roles']);
  32. $mation = SystemRole::roleMation($admin_roles);
  33. $name = [];
  34. for ($i=0;$i<count($mation);$i++){
  35. $name[$i] = $mation[$i]['role_name'];
  36. }
  37. $list[$k]['admin_roles'] = implode(',',$name);
  38. }
  39. }
  40. }
  41. return compact('list', 'page', 'limit', 'count');
  42. }
  43. /**
  44. * Notes:修改管理员
  45. * @param string $role_name
  46. * @param int $role_id
  47. * @param int $role_rules
  48. * @return int
  49. * User: ZQ
  50. * Date: 2022/9/3
  51. */
  52. public static function updateAdmin($admin_id, $admin_real_name, $admin_pwd, $admin_roles, $admin_status)
  53. {
  54. SystemAdmin::affairBegin();
  55. try {
  56. $data = [];
  57. $data['admin_real_name'] = $admin_real_name;
  58. if (!empty($admin_roles)){
  59. $data['admin_roles'] = implode(',',$admin_roles);
  60. }
  61. if (!empty($admin_status)){
  62. $data['admin_status'] = $admin_status;
  63. }
  64. if (!empty($admin_pwd)){
  65. $data['admin_pwd'] = md5(sha1($admin_pwd));
  66. }
  67. $result = SystemAdmin::updateInfo($admin_id, $data);
  68. if ($result !== false){
  69. SystemAdmin::affairCommit();
  70. return true;
  71. }
  72. throw new \Exception('修改管理员失败!');
  73. }catch (\Exception $exception){
  74. SystemAdmin::affairRollback();
  75. throw new \Exception($exception->getMessage(), 500);
  76. }
  77. }
  78. /**
  79. * Notes:查询管理员账号
  80. * @param string $role_name
  81. * @param int $role_id
  82. * @param int $role_rules
  83. * @return int
  84. * User: ZQ
  85. * Date: 2022/9/3
  86. */
  87. public static function adminCheck($admin_account){
  88. $where = [];
  89. $where['admin_account'] = $admin_account;
  90. $result = SystemAdmin::where($where)->first();
  91. return $result;
  92. }
  93. /**
  94. * Notes:添加管理员
  95. * @param string $admin_account
  96. * @param string $admin_real_name
  97. * @param string $admin_pwd
  98. * @param string $admin_roles
  99. * @param string $admin_status
  100. * @return int
  101. * User: ZQ
  102. * Date: 2022/9/3
  103. */
  104. public static function insertAdmin($admin_account, $admin_real_name, $admin_pwd, $admin_roles, $admin_status)
  105. {
  106. SystemAdmin::affairBegin();
  107. try {
  108. $data = [];
  109. $data['admin_account'] = $admin_account;
  110. $data['admin_real_name'] = $admin_real_name;
  111. $data['admin_roles'] = implode(',',$admin_roles);
  112. $data['admin_status'] = $admin_status;
  113. $data['admin_pwd'] = md5(sha1($admin_pwd));
  114. $result = SystemAdmin::insertGetId($data);
  115. if (!empty($result)){
  116. SystemAdmin::affairCommit();
  117. return $result;
  118. }
  119. throw new \Exception('添加管理员失败!');
  120. }catch (\Exception $exception){
  121. SystemAdmin::affairRollback();
  122. throw new \Exception($exception->getMessage(), 500);
  123. }
  124. }
  125. /**
  126. * Notes:删除管理员
  127. * @param int $admin_id
  128. * @return boolean
  129. * User: ZQ
  130. * Date: 2022/9/16
  131. */
  132. public static function delAdmin(int $admin_id)
  133. {
  134. SystemAdmin::affairBegin();
  135. try {
  136. $where = [];
  137. $where['admin_id'] = $admin_id;
  138. $data['admin_is_del'] = 1;
  139. $result = SystemAdmin::where($where)->update($data);
  140. if (!empty($result)){
  141. SystemAdmin::affairCommit();
  142. return true;
  143. }else{
  144. return false;
  145. }
  146. }catch (\Exception $exception){
  147. SystemAdmin::affairRollback();
  148. throw new \Exception($exception->getMessage(), 500);
  149. }
  150. }
  151. /**
  152. * Notes:查询管理员
  153. * @param int $admin_id
  154. * @return int
  155. * User: ZQ
  156. * Date: 2022/9/13
  157. */
  158. public static function adminInfo($admin_id)
  159. {
  160. $where = [];
  161. $where['admin_id'] = $admin_id;
  162. $result = SystemAdmin::where($where)->first();
  163. if (!empty($result)){
  164. $result['admin_roles'] = explode(',',$result['admin_roles']);
  165. }
  166. return $result;
  167. }
  168. /**
  169. * Notes:更新管理员状态
  170. * @param int $admin_id
  171. * @return boolean
  172. * User: ZQ
  173. * Date: 2022/9/16
  174. */
  175. public static function updateStatus(int $admin_id, $admin_status)
  176. {
  177. SystemAdmin::affairBegin();
  178. try {
  179. $data['admin_status'] = $admin_status;
  180. $result = SystemAdmin::updateInfo($admin_id,$data);
  181. if (!empty($result)){
  182. SystemAdmin::affairCommit();
  183. return true;
  184. }else{
  185. return false;
  186. }
  187. }catch (\Exception $exception){
  188. SystemAdmin::affairRollback();
  189. throw new \Exception($exception->getMessage(), 500);
  190. }
  191. }
  192. /**
  193. * Notes:会员设备消息推送信息插入
  194. * @param int $log_equipment_id
  195. * @param Jsonable $log_content
  196. * @param int $log_type
  197. * @param string $log_msg_type
  198. * @return boolean
  199. * User: ZQ
  200. * Date: 2022/9/20
  201. */
  202. public static function equipmentLog($equipment_only, $log_content, $log_type, $log_msg_type)
  203. {
  204. //查询设备是否已存在,存在则获取id,不存在插入数据库
  205. $where = [];
  206. $where['equipment_only'] = $equipment_only;
  207. $info = IntelligenceUser::equipmentCheck($where);
  208. if (!empty($info)){
  209. $log_equipment_id = $info['equipment_id'];
  210. }else{
  211. return false;
  212. // $mation = [];
  213. // $json = json_decode($log_content,true);
  214. // $type = $json['payload']['serviceData']['devicetype'];
  215. // if ($type == 'HW'){
  216. // $mation['equipment_name'] = 'NB-IoT智能红外探测报警器';
  217. // }elseif ($type == 'YG'){
  218. // $mation['equipment_name'] = 'NB-IoT烟雾报警器';
  219. // }elseif ($type == 'SO'){
  220. // $mation['equipment_name'] = 'NB-IoT智能紧急求救报警器';
  221. // }elseif ($type == 'LS'){
  222. // $mation['equipment_name'] = 'NB-IoT智能水浸报警器';
  223. // }elseif ($type == 'MC'){
  224. // $mation['equipment_name'] = 'NB-IoT磁开关入侵探测器';
  225. // }else{
  226. // $mation['equipment_name'] = '手环';
  227. // }
  228. // $mation['equipment_only'] = $equipment_only;
  229. // $mation['equipment_type'] = 0;
  230. // $log_equipment_id = IntelligenceUser::insertGetId($mation);
  231. }
  232. $data = [];
  233. $data['log_equipment_id'] = $log_equipment_id;
  234. $data['log_content'] = $log_content;
  235. $data['log_type'] = $log_type;
  236. $data['log_msg_type'] = $log_msg_type;
  237. $data['log_create_time'] = time();
  238. return IntelligenceLog::logInsert($data);
  239. }
  240. /**
  241. * Notes:会员设备消息推送信息查询
  242. * @param int $log_equipment_id
  243. * @param Jsonable $log_content
  244. * @param int $log_type
  245. * @param string $log_msg_type
  246. * @return boolean
  247. * User: ZQ
  248. * Date: 2022/9/20
  249. */
  250. public static function logCheck($log_equipment_id)
  251. {
  252. $where = [];
  253. $where['log_equipment_id'] = $log_equipment_id;
  254. return IntelligenceLog::where($where)->first();
  255. }
  256. /**
  257. * Notes:管理员密码更新
  258. * @param int $admin_id
  259. * @param string $old_pwd
  260. * @param string $new_pwd
  261. * @param string $confirm_pwd
  262. * @return bool
  263. * @throws \Exception
  264. * User: yym
  265. * Date: 2022/8/3
  266. */
  267. public static function updatePwd(int $admin_id, string $old_pwd, string $new_pwd, string $confirm_pwd)
  268. {
  269. try {
  270. if($new_pwd !== $confirm_pwd)
  271. {
  272. throw new \Exception('新密码和确认密码不一致~');
  273. }
  274. $info = SystemAdmin::getAdminInfo($admin_id);
  275. if(empty($info))
  276. {
  277. throw new \Exception('管理员信息不存在');
  278. }
  279. if($info['admin_pwd'] != md5(sha1($old_pwd)))
  280. {
  281. throw new \Exception('旧密码不正确~');
  282. }
  283. if($info['admin_pwd'] == md5(sha1($new_pwd)))
  284. {
  285. throw new \Exception('新密码与旧密码一致!');
  286. }
  287. $result = SystemAdmin::updateInfo($admin_id, array('admin_pwd' => md5(sha1($new_pwd))));
  288. if($result !== false)
  289. {
  290. return true;
  291. }
  292. throw new \Exception('更新失败~');
  293. }catch (\Exception $exception){
  294. throw new \Exception($exception->getMessage(), 500);
  295. }
  296. }
  297. /**
  298. * Notes:获取小程序页面地址
  299. * @return array
  300. * User: yym
  301. * Date: 2022/10/25
  302. */
  303. public static function getPageList()
  304. {
  305. return SystemPage::getPageList();
  306. }
  307. /**
  308. * Notes:业务控制器列表
  309. * @param string $keywords
  310. * @return bool
  311. * @throws \Exception
  312. * User: ZQ
  313. * Date: 2022/11/14
  314. */
  315. public static function getBusinessList(string $keywords, int $page, int $limit)
  316. {
  317. [$list, $count] = SystemBusiness::businessList($keywords, $page, $limit);
  318. return compact('list', 'page', 'limit', 'count');
  319. }
  320. /**
  321. * Notes:更新业务控制器
  322. * @return bool
  323. * @throws \Exception
  324. * User: ZQ
  325. * Date: 2022/11/14
  326. */
  327. public static function updateBusiness($business,$business_message)
  328. {
  329. SystemBusiness::affairBegin();
  330. try {
  331. foreach ($business as $k => $v){
  332. if (!empty($v['business_id'])){
  333. $business[$k]['business_message'] = $business_message;
  334. $result[] = SystemBusiness::where(['business_id'=>$v['business_id']])->update($business[$k]);
  335. }else{
  336. SystemBusiness::affairRollback();
  337. throw new \Exception('更新失败~');
  338. }
  339. }
  340. if (!empty($result)){
  341. SystemBusiness::affairCommit();
  342. return true;
  343. }else{
  344. return false;
  345. }
  346. }catch (\Exception $exception){
  347. SystemBusiness::affairRollback();
  348. throw new \Exception($exception->getMessage(), 500);
  349. }
  350. }
  351. /**
  352. * Notes:添加业务控制器
  353. * @param string $keywords
  354. * @return bool
  355. * @throws \Exception
  356. * User: ZQ
  357. * Date: 2022/11/14
  358. */
  359. public static function insertBusiness($business_name,$business_status,$business_message)
  360. {
  361. SystemBusiness::affairBegin();
  362. try {
  363. $data = [];
  364. $data['business_name'] = $business_name;
  365. $data['business_status'] = $business_status;
  366. $data['business_message'] = $business_message;
  367. $result = SystemBusiness::insertGetId($data);
  368. if (!empty($result)){
  369. SystemBusiness::affairCommit();
  370. return $result;
  371. }else{
  372. return $result;
  373. }
  374. }catch (\Exception $exception){
  375. SystemBusiness::affairRollback();
  376. throw new \Exception($exception->getMessage(), 500);
  377. }
  378. }
  379. }