HousekeeperServer.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace app\admin\server\housekeeper;
  3. use app\admin\model\Housekeeper;
  4. class HousekeeperServer
  5. {
  6. /**
  7. * Notes:管家列表
  8. * @param string $keywords
  9. * @param int $page
  10. * @param int $limit
  11. * @return array
  12. * User: yym
  13. * Date: 2022/10/28
  14. */
  15. public static function getHousekeeperList(string $keywords, int $page, int $limit)
  16. {
  17. [$list, $count] = Housekeeper::getHousekeeperList($keywords, $page, $limit);
  18. if(!empty($list))
  19. {
  20. foreach ($list as &$item)
  21. {
  22. $item['housekeeper_create_time'] = date("Y-m-d H:i:s", $item['housekeeper_create_time']);
  23. $item['housekeeper_update_time'] = date("Y-m-d H:i:s", $item['housekeeper_update_time']);
  24. }
  25. unset($item);
  26. }
  27. return compact('list', 'count');
  28. }
  29. /**
  30. * Notes:添加管家
  31. * @param $admin_id
  32. * @param $housekeeper_name
  33. * @param $housekeeper_pwd
  34. * @param $housekeeper_real_name
  35. * @param $housekeeper_head
  36. * @param $housekeeper_phone
  37. * @param $housekeeper_position
  38. * @return bool
  39. * @throws \Exception
  40. * User: yym
  41. * Date: 2022/10/28
  42. */
  43. public static function addHousekeeper($admin_id, $housekeeper_name, $housekeeper_pwd, $housekeeper_real_name, $housekeeper_head, $housekeeper_phone, $housekeeper_position)
  44. {
  45. Housekeeper::affairBegin();
  46. try {
  47. //检测管家账号是否存在
  48. if(Housekeeper::checkAccount($housekeeper_name))
  49. {
  50. throw new \Exception('该账号已存在!');
  51. }
  52. $salf = getRandomString(6);
  53. $insert = array(
  54. 'housekeeper_name' => $housekeeper_name,
  55. 'housekeeper_pwd' => md5(sha1($housekeeper_pwd) . $salf),
  56. 'housekeeper_salf' => $salf,
  57. 'housekeeper_real_name' => $housekeeper_real_name,
  58. 'housekeeper_head' => $housekeeper_head,
  59. 'housekeeper_phone' => $housekeeper_phone,
  60. 'housekeeper_position' => $housekeeper_position,
  61. 'housekeeper_create_time' => time()
  62. );
  63. $message = '管理员:' . $admin_id . '在' . date("Y-m-d H:i:s", time()) . '添加管家:' . $housekeeper_name;
  64. $result = Housekeeper::insertData($insert);
  65. if($result)
  66. {
  67. plog('housekeeper-add', '管家-添加管家', $message);
  68. Housekeeper::affairCommit();
  69. return true;
  70. }
  71. throw new \Exception('添加失败!');
  72. }catch (\Exception $exception){
  73. Housekeeper::affairRollback();
  74. throw new \Exception($exception->getMessage(), 500);
  75. }
  76. }
  77. /**
  78. * Notes:管家编辑
  79. * @param $admin_id
  80. * @param $housekeeper_id
  81. * @param $housekeeper_name
  82. * @param $housekeeper_pwd
  83. * @param $housekeeper_real_name
  84. * @param $housekeeper_head
  85. * @param $housekeeper_phone
  86. * @param $housekeeper_position
  87. * @return bool
  88. * @throws \Exception
  89. * User: yym
  90. * Date: 2022/10/28
  91. */
  92. public static function updateHousekeeper($admin_id, $housekeeper_id, $housekeeper_name, $housekeeper_pwd, $housekeeper_real_name, $housekeeper_head, $housekeeper_phone, $housekeeper_position)
  93. {
  94. Housekeeper::affairBegin();
  95. try {
  96. //检测管家账号是否存在
  97. if(Housekeeper::checkAccountNo($housekeeper_name, $housekeeper_id))
  98. {
  99. throw new \Exception('该账号已存在!');
  100. }
  101. $update = array(
  102. 'housekeeper_name' => $housekeeper_name,
  103. 'housekeeper_real_name' => $housekeeper_real_name,
  104. 'housekeeper_head' => $housekeeper_head,
  105. 'housekeeper_phone' => $housekeeper_phone,
  106. 'housekeeper_position' => $housekeeper_position
  107. );
  108. if(!empty($housekeeper_pwd))
  109. {
  110. $salf = getRandomString(6);
  111. $update['housekeeper_pwd'] = md5(sha1($housekeeper_pwd) . $salf);
  112. $update['housekeeper_salf'] = $salf;
  113. }
  114. $message = '管理员:' . $admin_id . '在' . date("Y-m-d H:i:s", time()) . '编辑管家:' . $housekeeper_id;
  115. $result = Housekeeper::updateData($update, $housekeeper_id);
  116. if($result)
  117. {
  118. plog('housekeeper-update', '管家-编辑管家', $message);
  119. Housekeeper::affairCommit();
  120. return true;
  121. }
  122. throw new \Exception('编辑失败!');
  123. }catch (\Exception $exception){
  124. Housekeeper::affairRollback();
  125. throw new \Exception($exception->getMessage(), 500);
  126. }
  127. }
  128. /**
  129. * Notes:获取管家详情
  130. * @param int $housekeeper_id
  131. * @return array
  132. * @throws \Exception
  133. * User: yym
  134. * Date: 2022/10/28
  135. */
  136. public static function getInfo(int $housekeeper_id)
  137. {
  138. try {
  139. $info = Housekeeper::getInfo($housekeeper_id);
  140. if(empty($info))
  141. {
  142. throw new \Exception('管家账号不存在或已删除!');
  143. }
  144. $info = $info->toArray();
  145. $info['housekeeper_pwd'] = '';
  146. return $info;
  147. }catch (\Exception $exception){
  148. throw new \Exception($exception->getMessage(), '500');
  149. }
  150. }
  151. /**
  152. * Notes:删除管家
  153. * @param int $admin_id
  154. * @param int $housekeeper_id
  155. * @return bool
  156. * @throws \Exception
  157. * User: yym
  158. * Date: 2022/10/28
  159. */
  160. public static function delHousekeeper(int $admin_id, int $housekeeper_id)
  161. {
  162. Housekeeper::affairBegin();
  163. try {
  164. $info = Housekeeper::getInfo($housekeeper_id);
  165. if(empty($info))
  166. {
  167. throw new \Exception('管家账号不存在或已删除!');
  168. }
  169. $update = array(
  170. 'housekeeper_del' => Housekeeper::DEL_YES
  171. );
  172. $message = '管理员:' . $admin_id . '在' . date("Y-m-d H:i:s", time()) . '删除管家:' . $housekeeper_id;
  173. $result = Housekeeper::updateData($update, $housekeeper_id);
  174. if($result)
  175. {
  176. plog('housekeeper-delete', '管家-删除管家', $message);
  177. Housekeeper::affairCommit();
  178. return true;
  179. }
  180. throw new \Exception('删除失败!');
  181. }catch (\Exception $exception){
  182. Housekeeper::affairRollback();
  183. throw new \Exception($exception->getMessage(), 500);
  184. }
  185. }
  186. }