ProjectLog.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2022 勾股工作室
  4. * @license https://opensource.org/licenses/GPL-3.0
  5. * @link https://www.gougucms.com
  6. */
  7. declare (strict_types = 1);
  8. namespace app\admin\model;
  9. use think\facade\Db;
  10. use think\Model;
  11. class ProjectLog extends Model
  12. {
  13. public static $Sourse = [
  14. 'project' => [
  15. 'status' => ['','未开始', '进行中', '已完成', '已关闭'],
  16. 'field_array' => [
  17. 'director_uid' => array('icon' => 'icon-xueshengzhuce', 'title' => '负责人'),
  18. 'start_time' => array('icon' => 'icon-kaoshijihua', 'title' => '预计开始时间'),
  19. 'end_time' => array('icon' => 'icon-kaoshijihua', 'title' => '预计结束时间'),
  20. 'name' => array('icon' => 'icon-wodedianping', 'title' => '标题'),
  21. 'status' => array('icon' => 'icon-wodedianping', 'title' => '状态'),
  22. 'content' => array('icon' => 'icon-wodedianping', 'title' => '描述'),
  23. 'file' => array('icon' => 'icon-sucaiziyuan', 'title' => '文件'),
  24. 'contract_id' => array('icon' => 'icon-hetongguanli', 'title' => '合同'),
  25. 'customer_id' => array('icon' => 'icon-jiaoshiguanli', 'title' => '客户'),
  26. 'link' => array('icon' => 'icon-sucaiziyuan', 'title' => '链接'),
  27. 'user' => array('icon' => 'icon-xueshengzhuce', 'title' => '成员'),
  28. 'new' => array('icon' => 'icon-zidingyishezhi', 'title' => '项目'),
  29. 'delete' => array('icon' => 'icon-shanchu', 'title' => '项目'),
  30. ]],
  31. 'task' => [
  32. 'priority' => ['', '低', '中', '高', '紧急'],
  33. 'flow_status' => ['', '未开始', '进行中', '已完成', '已拒绝', '已关闭'],
  34. 'type' => ['', '需求', '设计', '研发', '缺陷'],
  35. 'field_array' => [
  36. 'director_uid' => array('icon' => 'icon-xueshengzhuce', 'title' => '负责人'),
  37. 'assist_admin_ids' => array('icon' => 'icon-xueshengbaoming', 'title' => '协作人'),
  38. 'end_time' => array('icon' => 'icon-kaoshijihua', 'title' => '预计结束时间'),
  39. 'title' => array('icon' => 'icon-wodedianping', 'title' => '标题'),
  40. 'flow_status' => array('icon' => 'icon-wodedianping', 'title' => '任务状态'),
  41. 'plan_hours' => array('icon' => 'icon-wodedianping', 'title' => '工时'),
  42. 'priority' => array('icon' => 'icon-wodedianping', 'title' => '等级'),
  43. 'type' => array('icon' => 'icon-wodedianping', 'title' => '任务类型'),
  44. 'cate' => array('icon' => 'icon-wodedianping', 'title' => '任务类别'),
  45. 'done_ratio' => array('icon' => 'icon-wodedianping', 'title' => '完成进度'),
  46. 'project_id' => array('icon' => 'icon-wodedianping', 'title' => '关联项目'),
  47. 'content' => array('icon' => 'icon-wodedianping', 'title' => '描述'),
  48. 'file' => array('icon' => 'icon-sucaiziyuan', 'title' => '文件'),
  49. 'new' => array('icon' => 'icon-zidingyishezhi', 'title' => '任务'),
  50. 'delete' => array('icon' => 'icon-shanchu', 'title' => '任务'),
  51. ]],
  52. 'document' => [
  53. 'field_array' => [
  54. 'title' => array('icon' => 'icon-wodedianping', 'title' => '标题'),
  55. 'project_id' => array('icon' => 'icon-wodedianping', 'title' => '关联项目'),
  56. 'content' => array('icon' => 'icon-wodedianping', 'title' => '描述'),
  57. 'new' => array('icon' => 'icon-zidingyishezhi', 'title' => '任务'),
  58. 'delete' => array('icon' => 'icon-shanchu', 'title' => '任务'),
  59. ]]
  60. ];
  61. public function get_list($param = [])
  62. {
  63. $where = array();
  64. $where['a.module'] = $param['m'];
  65. $where['a.' . $param['m'] . '_id'] = $param['tid'];
  66. $content = Db::name('ProjectLog')
  67. ->field('a.*,u.name')
  68. ->alias('a')
  69. ->join('Admin u', 'u.id = a.admin_id')
  70. ->order('a.create_time desc')
  71. ->where($where)
  72. ->select()->toArray();
  73. $sourse = self::$Sourse[$param['m']];
  74. $action = get_config('log.type_action');
  75. $field_array = $sourse['field_array'];
  76. $data = [];
  77. foreach ($content as $k => $v) {
  78. if (isset($sourse[$v['field']])) {
  79. $v['old_content'] = $sourse[$v['field']][$v['old_content']];
  80. $v['new_content'] = $sourse[$v['field']][$v['new_content']];
  81. }
  82. if (strpos($v['field'], '_time') !== false) {
  83. if ($v['old_content'] == '') {
  84. $v['old_content'] = '未设置';
  85. }
  86. $v['new_content'] = date('Y-m-d', (int) $v['new_content']);
  87. }
  88. if (strpos($v['field'], '_uid') !== false) {
  89. $v['old_content'] = Db::name('Admin')->where(['id' => $v['old_content']])->value('name');
  90. $v['new_content'] = Db::name('Admin')->where(['id' => $v['new_content']])->value('name');
  91. }
  92. if ($v['field'] == 'user') {
  93. $v['new_content'] = Db::name('Admin')->where(['id' => $v['new_content']])->value('name');
  94. }
  95. if ($v['field'] == 'project_id') {
  96. $v['old_content'] = Db::name('Project')->where(['id' => $v['old_content']])->value('name');
  97. $v['new_content'] = Db::name('Project')->where(['id' => $v['new_content']])->value('name');
  98. }
  99. if ($v['field'] == 'cate') {
  100. $v['old_content'] = Db::name('WorkCate')->where(['id' => $v['old_content']])->value('title');
  101. $v['new_content'] = Db::name('WorkCate')->where(['id' => $v['new_content']])->value('title');
  102. }
  103. if ($v['field'] == 'done_ratio') {
  104. $v['old_content'] = $v['old_content'] . '%';
  105. $v['new_content'] = $v['new_content'] . '%';
  106. }
  107. if (strpos($v['field'], '_ids') !== false) {
  108. $old_ids = Db::name('Admin')->where('id', 'in', $v['old_content'])->column('name');
  109. $v['old_content'] = implode(',', $old_ids);
  110. $new_ids = Db::name('Admin')->where('id', 'in', $v['new_content'])->column('name');
  111. $v['new_content'] = implode(',', $new_ids);
  112. }
  113. if ($v['old_content'] == '' || $v['old_content'] == null) {
  114. $v['old_content'] = '未设置';
  115. }
  116. if ($v['new_content'] == '' || $v['new_content'] == null) {
  117. $v['new_content'] = '未设置';
  118. }
  119. $v['action'] = $action[$v['action']];
  120. $v['icon'] = $field_array[$v['field']]['icon'];
  121. $v['title'] = $field_array[$v['field']]['title'];
  122. $v['times'] = time_trans($v['create_time']);
  123. $v['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
  124. $data[] = $v;
  125. }
  126. return $data;
  127. }
  128. public function project_log($param = [])
  129. {
  130. $task_ids = Db::name('ProjectTask')->where(['project_id' => $param['topic_id'], 'delete_time' => 0])->column('id');
  131. $document_ids = Db::name('ProjectDocument')->where(['project_id' => $param['topic_id'], 'delete_time' => 0])->column('id');
  132. $where1 = [];
  133. $where2 = [];
  134. $where3 = [];
  135. $where1[] = ['a.module', '=', 'project'];
  136. $where1[] = ['a.project_id', '=', $param['topic_id']];
  137. $where2[] = ['a.module', '=', 'task'];
  138. $where2[] = ['a.task_id', 'in', $task_ids];
  139. $where3[] = ['a.module', '=', 'document'];
  140. $where3[] = ['a.document_id', 'in', $document_ids];
  141. $page = intval($param['page']);
  142. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  143. $content = Db::name('ProjectLog')
  144. ->field('a.*,u.name,u.thumb')
  145. ->alias('a')
  146. ->join('Admin u', 'u.id = a.admin_id')
  147. ->order('a.create_time desc')
  148. ->whereOr([$where1, $where2, $where3])
  149. ->page($page, $rows)
  150. ->select()->toArray();
  151. $module = [
  152. 'project' => '',
  153. 'task' => '任务',
  154. 'document' => '文档',
  155. ];
  156. $action = get_config('log.type_action');
  157. $data = [];
  158. foreach ($content as $k => $v) {
  159. $sourse = self::$Sourse[$v['module']];
  160. $field_array = $sourse['field_array'];
  161. if (isset($sourse[$v['field']])) {
  162. $v['old_content'] = $sourse[$v['field']][$v['old_content']];
  163. $v['new_content'] = $sourse[$v['field']][$v['new_content']];
  164. }
  165. if (strpos($v['field'], '_time') !== false) {
  166. if ($v['old_content'] == '') {
  167. $v['old_content'] = '未设置';
  168. }
  169. else{
  170. $v['old_content'] = date('Y-m-d', (int) $v['old_content']);
  171. }
  172. $v['new_content'] = date('Y-m-d', (int) $v['new_content']);
  173. }
  174. if (strpos($v['field'], '_uid') !== false) {
  175. $v['old_content'] = Db::name('Admin')->where(['id' => $v['old_content']])->value('name');
  176. $v['new_content'] = Db::name('Admin')->where(['id' => $v['new_content']])->value('name');
  177. }
  178. if ($v['field'] == 'user') {
  179. $v['new_content'] = Db::name('Admin')->where(['id' => $v['new_content']])->value('name');
  180. }
  181. if ($v['field'] == 'project_id') {
  182. $v['old_content'] = Db::name('Project')->where(['id' => $v['old_content']])->value('name');
  183. $v['new_content'] = Db::name('Project')->where(['id' => $v['new_content']])->value('name');
  184. }
  185. if ($v['field'] == 'cate') {
  186. $v['old_content'] = Db::name('WorkCate')->where(['id' => $v['old_content']])->value('title');
  187. $v['new_content'] = Db::name('WorkCate')->where(['id' => $v['new_content']])->value('title');
  188. }
  189. if ($v['field'] == 'contract_id') {
  190. $v['old_content'] = Db::name('Contract')->where(['id' => $v['old_content']])->value('name');
  191. $v['new_content'] = Db::name('Contract')->where(['id' => $v['new_content']])->value('name');
  192. }
  193. if ($v['field'] == 'customer_id') {
  194. $v['old_content'] = Db::name('Customer')->where(['id' => $v['old_content']])->value('name');
  195. $v['new_content'] = Db::name('Customer')->where(['id' => $v['new_content']])->value('name');
  196. }
  197. if ($v['field'] == 'done_ratio') {
  198. $v['old_content'] = $v['old_content'] . '%';
  199. $v['new_content'] = $v['new_content'] . '%';
  200. }
  201. if (strpos($v['field'], '_ids') !== false) {
  202. $old_ids = Db::name('Admin')->where('id', 'in', $v['old_content'])->column('name');
  203. $v['old_content'] = implode(',', $old_ids);
  204. $new_ids = Db::name('Admin')->where('id', 'in', $v['new_content'])->column('name');
  205. $v['new_content'] = implode(',', $new_ids);
  206. }
  207. if ($v['old_content'] == '' || $v['old_content'] == null) {
  208. $v['old_content'] = '未设置';
  209. }
  210. if ($v['new_content'] == '' || $v['new_content'] == null) {
  211. $v['new_content'] = '未设置';
  212. }
  213. $v['module_name'] = $module[$v['module']];
  214. $v['topic'] = '';
  215. $v['topic_title'] = '';
  216. $v['url'] = '';
  217. if ($v['module'] == 'task') {
  218. $v['topic'] = 'T' . $v['task_id'];
  219. $v['topic_title'] = Db::name('ProjectTask')->where('id', $v['task_id'])->value('title');
  220. $v['url'] = '/project/task/view/id/' . $v['task_id'];
  221. }
  222. $v['action'] = $action[$v['action']];
  223. $v['icon'] = $field_array[$v['field']]['icon'];
  224. $v['title'] = $field_array[$v['field']]['title'];
  225. $v['times'] = time_trans($v['create_time']);
  226. $v['create_time'] = date('Y-m-d', $v['create_time']);
  227. $data[] = $v;
  228. }
  229. return $data;
  230. }
  231. }