DailyRuleLogic.php 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. /**
  3. * 日志规则逻辑类
  4. *
  5. * @author qifan
  6. * @date 2020-12-03
  7. */
  8. namespace app\admin\logic;
  9. use think\Db;
  10. class DailyRuleLogic
  11. {
  12. /**
  13. * 获取日志欢迎语
  14. *
  15. * @return array|mixed
  16. */
  17. public function welcome()
  18. {
  19. $mark = Db::name('admin_oalog_rule')->where('type', 4)->value('mark');
  20. return !empty($mark) ? unserialize($mark) : [];
  21. }
  22. /**
  23. * 保存欢迎语
  24. *
  25. * @param $data
  26. * @return int|string
  27. * @throws \think\Exception
  28. * @throws \think\exception\PDOException
  29. */
  30. public function setWelcome($data)
  31. {
  32. $result = [];
  33. foreach ($data as $key => $value) {
  34. if (!empty($value)) $result[] = $value;
  35. }
  36. $result = serialize($result);
  37. if (Db::name('admin_oalog_rule')->where('type', 4)->value('id')) {
  38. return Db::name('admin_oalog_rule')->where('type', 4)->update(['mark' => $result]);
  39. }
  40. return Db::name('admin_oalog_rule')->insert([
  41. 'type' => 4,
  42. 'status' => 1,
  43. 'mark' => $result
  44. ]);
  45. }
  46. /**
  47. * 获取日志规则
  48. *
  49. * @return mixed
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @throws \think\exception\DbException
  53. */
  54. public function workLogRule()
  55. {
  56. $result[] = $this->getDayLogRule();
  57. $result[] = $this->getWeekLogRule();
  58. $result[] = $this->getMonthLogRule();
  59. return $result;
  60. }
  61. /**
  62. * 设置日志规则
  63. *
  64. * @param $param
  65. * @throws \think\Exception
  66. * @throws \think\exception\PDOException
  67. */
  68. public function setWorkLogRule($param)
  69. {
  70. if (!empty($param[0])) $this->setDayLogRule($param[0]);
  71. if (!empty($param[1])) $this->setWeekLogRule($param[1]);
  72. if (!empty($param[2])) $this->setMonthLogRule($param[2]);
  73. }
  74. /**
  75. * 设置日规则
  76. *
  77. * @param $param
  78. * @return int|string
  79. * @throws \think\Exception
  80. * @throws \think\exception\PDOException
  81. */
  82. private function setDayLogRule($param)
  83. {
  84. $data = [
  85. 'type' => 1,
  86. 'userIds' => $param['userIds'],
  87. 'effective_day' => $param['effective_day'],
  88. 'start_time' => $param['start_time'],
  89. 'end_time' => $param['end_time'],
  90. 'status' => $param['status']
  91. ];
  92. if (Db::name('admin_oalog_rule')->where('type', 1)->value('id')) {
  93. return Db::name('admin_oalog_rule')->where('type', 1)->update($data);
  94. }
  95. return Db::name('admin_oalog_rule')->insert($data);
  96. }
  97. /**
  98. * 设置周规则
  99. *
  100. * @param $param
  101. * @return int|string
  102. * @throws \think\Exception
  103. * @throws \think\exception\PDOException
  104. */
  105. private function setWeekLogRule($param)
  106. {
  107. $data = [
  108. 'type' => 2,
  109. 'userIds' => $param['userIds'],
  110. 'start_time' => $param['start_time'],
  111. 'end_time' => $param['end_time'],
  112. 'status' => $param['status']
  113. ];
  114. if (Db::name('admin_oalog_rule')->where('type', 2)->value('id')) {
  115. return Db::name('admin_oalog_rule')->where('type', 2)->update($data);
  116. }
  117. return Db::name('admin_oalog_rule')->insert($data);
  118. }
  119. /**
  120. * 设置月规则
  121. *
  122. * @param $param
  123. * @return int|string
  124. * @throws \think\Exception
  125. * @throws \think\exception\PDOException
  126. */
  127. private function setMonthLogRule($param)
  128. {
  129. $data = [
  130. 'type' => 3,
  131. 'userIds' => $param['userIds'],
  132. 'start_time' => $param['start_time'],
  133. 'end_time' => $param['end_time'],
  134. 'status' => $param['status']
  135. ];
  136. if (Db::name('admin_oalog_rule')->where('type', 3)->value('id')) {
  137. return Db::name('admin_oalog_rule')->where('type', 3)->update($data);
  138. }
  139. return Db::name('admin_oalog_rule')->insert($data);
  140. }
  141. /**
  142. * 获取日规则
  143. *
  144. * @return array
  145. * @throws \think\db\exception\DataNotFoundException
  146. * @throws \think\db\exception\ModelNotFoundException
  147. * @throws \think\exception\DbException
  148. */
  149. private function getDayLogRule()
  150. {
  151. $day = Db::name('admin_oalog_rule')->where('type', 1)->find();
  152. return [
  153. 'type' => $day['type'],
  154. 'status' => $day['status'],
  155. 'userIds' => $day['userIds'],
  156. 'user' => $this->getUsers($day['userIds']),
  157. 'effective_day' => $day['effective_day'],
  158. 'start_time' => $day['start_time'],
  159. 'end_time' => $day['end_time']
  160. ];
  161. }
  162. /**
  163. * 获取周规则
  164. *
  165. * @return array
  166. * @throws \think\db\exception\DataNotFoundException
  167. * @throws \think\db\exception\ModelNotFoundException
  168. * @throws \think\exception\DbException
  169. */
  170. private function getWeekLogRule()
  171. {
  172. $week = Db::name('admin_oalog_rule')->where('type', 2)->find();
  173. return [
  174. 'type' => $week['type'],
  175. 'status' => $week['status'],
  176. 'userIds' => $week['userIds'],
  177. 'user' => $this->getUsers($week['userIds']),
  178. 'effective_day' => $week['effective_day'],
  179. 'start_time' => $week['start_time'],
  180. 'end_time' => $week['end_time']
  181. ];
  182. }
  183. /**
  184. * 获取月规则
  185. *
  186. * @return array
  187. * @throws \think\db\exception\DataNotFoundException
  188. * @throws \think\db\exception\ModelNotFoundException
  189. * @throws \think\exception\DbException
  190. */
  191. private function getMonthLogRule()
  192. {
  193. $month = Db::name('admin_oalog_rule')->where('type', 3)->find();
  194. return [
  195. 'type' => $month['type'],
  196. 'status' => $month['status'],
  197. 'userIds' => $month['userIds'],
  198. 'user' => $this->getUsers($month['userIds']),
  199. 'effective_day' => $month['effective_day'],
  200. 'start_time' => $month['start_time'],
  201. 'end_time' => $month['end_time']
  202. ];
  203. }
  204. /**
  205. * 获取用户列表
  206. *
  207. * @param $ids
  208. * @return bool|\PDOStatement|string|\think\Collection
  209. * @throws \think\db\exception\DataNotFoundException
  210. * @throws \think\db\exception\ModelNotFoundException
  211. * @throws \think\exception\DbException
  212. */
  213. private function getUsers($ids)
  214. {
  215. return Db::name('admin_user')->field(['id', 'realname'])->whereIn('id', $ids)->select();
  216. }
  217. /**
  218. * 自定义日程类型列表
  219. * @return array
  220. * @throws \think\db\exception\DataNotFoundException
  221. * @throws \think\db\exception\ModelNotFoundException
  222. * @throws \think\exception\DbException
  223. */
  224. public function schedule()
  225. {
  226. $list = Db::name('admin_oa_schedule')->where('type', 2)->field(['name,color,schedule_id as id'])->select();
  227. $data = [];
  228. $data['list'] = $list;
  229. return $data;
  230. }
  231. /**
  232. * 设置日程自定义规则
  233. * @param $param
  234. * @return int|string
  235. * @throws \think\Exception
  236. * @throws \think\exception\PDOException
  237. */
  238. public function setSchedule($param)
  239. {
  240. if (Db::name('admin_oa_schedule')->where('schedule_id', $param['id'])->value('schedule_id')) {
  241. $data = [
  242. 'name' => $param['name'],
  243. 'update_time' => time(),
  244. 'color' => $param['color'],
  245. ];
  246. return Db::name('admin_oa_schedule')->where( 'schedule_id', $param['id'])->update($data);
  247. }
  248. }
  249. /**
  250. * 添加自定义日程规则
  251. * @param $param
  252. * @return int|string
  253. */
  254. public function addSchedule($param)
  255. {
  256. $data = [
  257. 'name' => $param['name'],
  258. 'create_time' => time(),
  259. 'color' => $param['color'],
  260. ];
  261. return Db::name('admin_oa_schedule')->insert($data);
  262. }
  263. /**
  264. * 删除日程自定义规则
  265. * @param $param
  266. * @return int
  267. * @throws \think\Exception
  268. * @throws \think\exception\PDOException
  269. */
  270. public function delSchedule($param)
  271. {
  272. if (Db::name('admin_oa_schedule')->where('schedule_id', $param)->value('schedule_id')) {
  273. return Db::name('AdminOaSchedule')->where('schedule_id', $param)->delete();
  274. }
  275. }
  276. }