Index.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\project\controller;
  15. use app\base\BaseController;
  16. use app\project\model\Project as ProjectModel;
  17. use app\project\validate\IndexValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Index extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new ProjectModel();
  31. }
  32. /**
  33. * 数据列表
  34. */
  35. public function datalist()
  36. {
  37. $param = get_params();
  38. $uid = $this->uid;
  39. $auth = isAuth($uid,'project_admin','conf_1');
  40. $tab = isset($param['tab']) ? $param['tab'] : 0;
  41. if (request()->isAjax()) {
  42. $where = array();
  43. $whereOr = array();
  44. $where[] = ['delete_time', '=', 0];
  45. if (!empty($param['status'])) {
  46. $where[] = ['status', '=', $param['status']];
  47. }
  48. if (!empty($param['cate_id'])) {
  49. $where[] = ['cate_id', '=', $param['cate_id']];
  50. }
  51. if (!empty($param['keywords'])) {
  52. $where[] = ['name|content', 'like', '%' . $param['keywords'] . '%'];
  53. }
  54. if (!empty($param['director_uid'])) {
  55. $where[] = ['director_uid', 'in', $param['director_uid']];
  56. }
  57. else{
  58. if($auth == 0){
  59. $whereOr[] = ['director_uid', '=', $uid];
  60. $project_ids = Db::name('ProjectUser')->where(['uid' => $uid, 'delete_time' => 0])->column('project_id');
  61. $whereOr[] = ['id', 'in', $project_ids];
  62. $dids_a = get_leader_departments($uid);
  63. $dids_b = get_role_departments($uid);
  64. $dids = array_merge($dids_a, $dids_b);
  65. if(!empty($dids)){
  66. $whereOr[] = ['did','in',$dids];
  67. }
  68. }
  69. }
  70. if($tab == 0){
  71. }
  72. if($tab == 1){
  73. $where[] = ['status', '=', 2];
  74. }
  75. if($tab == 2){
  76. $time = time();
  77. $dalay_time = time()+7*86400;
  78. $where[] = ['status', '<', 3];
  79. $where[] = ['end_time', 'between', [$time,$dalay_time]];
  80. }
  81. if($tab == 3){
  82. $where[] = ['status', '<', 3];
  83. $where[] = ['end_time', '<', time()];
  84. }
  85. $list = $this->model->datalist($param,$where,$whereOr);
  86. return table_assign(0, '', $list);
  87. }
  88. else{
  89. View::assign('auth', $auth);
  90. return view();
  91. }
  92. }
  93. /**
  94. * 添加/编辑
  95. */
  96. public function add()
  97. {
  98. $param = get_params();
  99. if (request()->isAjax()) {
  100. if (isset($param['range_time'])) {
  101. $range_time = explode('到',$param['range_time']);
  102. $param['start_time'] = strtotime(urldecode(trim($range_time[0])));
  103. $param['end_time'] = strtotime(urldecode(trim($range_time[1])));
  104. }
  105. else{
  106. $param['start_time'] = strtotime(urldecode(trim($param['start_time'])));
  107. $param['end_time'] = strtotime(urldecode(trim($param['end_time'])));
  108. }
  109. $step_title_data = isset($param['step_title']) ? $param['step_title'] : '';
  110. $step_director_uid_data = isset($param['step_director_uid']) ? $param['step_director_uid'] : '';
  111. $step_uids_data = isset($param['step_uids']) ? $param['step_uids'] : '';
  112. $step_start_time_data = isset($param['step_start_time']) ? $param['step_start_time'] : '';
  113. $step_end_time_data = isset($param['step_end_time']) ? $param['step_end_time'] : '';
  114. $step_cycle_time_data = isset($param['step_cycle_time']) ? $param['step_cycle_time'] : '';
  115. $step_remark_data = isset($param['step_remark']) ? $param['step_remark'] : '';
  116. $step_id_data = isset($param['step_id']) ? $param['step_id'] : 0;
  117. $step = [];
  118. $time_1 = $param['start_time'];
  119. $time_2 = $param['end_time'];
  120. if(!empty($step_title_data)){
  121. foreach ($step_title_data as $key => $value) {
  122. if (!$value) {
  123. continue;
  124. }
  125. if(!empty($step_cycle_time_data)){
  126. $step_cycle_time = explode('到',$step_cycle_time_data[$key]);
  127. $start_time = strtotime(urldecode(trim($step_cycle_time[0])));
  128. $end_time = strtotime(urldecode(trim($step_cycle_time[1])));
  129. }
  130. else{
  131. $start_time = strtotime(urldecode(trim($step_start_time_data[$key])));
  132. $end_time = strtotime(urldecode(trim($step_end_time_data[$key])));
  133. }
  134. if($start_time<$time_1){
  135. return to_assign(1, '第'.($key+1).'阶段的开始时间不能小于项目计划周期的开始时间');
  136. break;
  137. }
  138. if($end_time>$time_2){
  139. return to_assign(1, '第'.($key+1).'阶段的结束时间不能大于项目计划周期的结束时间');
  140. break;
  141. }
  142. $item = [];
  143. $item['title'] = $value;
  144. $item['director_uid'] = $step_director_uid_data[$key];
  145. $item['uids'] = $step_uids_data[$key];
  146. $item['sort'] = $key;
  147. $item['start_time'] = $start_time;
  148. $item['end_time'] = $end_time;
  149. $item['remark'] = $step_remark_data[$key];
  150. $item['id'] = $step_id_data[$key];
  151. $item['create_time'] = time();
  152. $step[]=$item;
  153. }
  154. }
  155. if (!empty($param['id']) && $param['id'] > 0) {
  156. try {
  157. validate(IndexValidate::class)->scene('edit')->check($param);
  158. } catch (ValidateException $e) {
  159. // 验证失败 输出错误信息
  160. return to_assign(1, $e->getError());
  161. }
  162. $this->model->edit($param,$step);
  163. } else {
  164. try {
  165. validate(IndexValidate::class)->scene('add')->check($param);
  166. } catch (ValidateException $e) {
  167. // 验证失败 输出错误信息
  168. return to_assign(1, $e->getError());
  169. }
  170. $param['status'] = 2;
  171. $param['step_sort'] = 0;
  172. $param['admin_id'] = $this->uid;
  173. $this->model->add($param,$step);
  174. }
  175. }else{
  176. $id = isset($param['id']) ? $param['id'] : 0;
  177. if ($id>0) {
  178. $detail = $this->model->getById($id);
  179. $detail['current_step'] = Db::name('ProjectStep')->where(['project_id' => $id, 'is_current' => 1,'delete_time'=>0])->value('sort');
  180. View::assign('detail', $detail);
  181. if(is_mobile()){
  182. return view('qiye@/project/project_edit');
  183. }
  184. return view('edit');
  185. }
  186. if(is_mobile()){
  187. return view('qiye@/project/project_add');
  188. }
  189. return view();
  190. }
  191. }
  192. /**
  193. * 查看
  194. */
  195. public function view($id)
  196. {
  197. $detail = $this->model->getById($id);
  198. if (!empty($detail)) {
  199. $detail['status_name'] = status_name($detail['status']);
  200. $detail['cate'] = Db::name('ProjectCate')->where([['id', '=', $detail['cate_id']]])->value('title');
  201. $team_admin_ids = Db::name('ProjectUser')->where(['delete_time' => 0,'project_id'=>$id])->column('uid');
  202. $team_admin_names = Db::name('Admin')->where('id', 'in', $team_admin_ids)->column('name');
  203. $detail['team_admin_names'] = implode(',', $team_admin_names);
  204. $tids = Db::name('ProjectTask')->where([['project_id', '=', $detail['id']], ['delete_time', '=', 0]])->column('id');
  205. $detail['schedules'] = Db::name('Schedule')->where([['tid', 'in', $tids], ['delete_time', '=', 0]])->count();
  206. $detail['hours'] = Db::name('Schedule')->where([['tid', 'in', $tids], ['delete_time', '=', 0]])->sum('labor_time');
  207. $detail['plan_hours'] = Db::name('ProjectTask')->where([['project_id', '=', $detail['id']], ['delete_time', '=', 0]])->sum('plan_hours');
  208. $detail['tasks'] = Db::name('ProjectTask')->where([['project_id', '=', $detail['id']],['delete_time', '=', 0]])->count();
  209. $detail['tasks_finish'] = Db::name('ProjectTask')->where([['project_id', '=', $detail['id']],['status', '>', 2], ['delete_time', '=', 0]])->count();
  210. $detail['tasks_unfinish'] = $detail['tasks'] - $detail['tasks_finish'];
  211. $task_map = [];
  212. $task_map[] = ['project_id', '=', $detail['id']];
  213. $task_map[] = ['delete_time', '=', 0];
  214. //判断是否是创建者或者负责人
  215. $role = 0;
  216. if ($detail['admin_id'] == $this->uid) {
  217. $role = 1; //创建人
  218. }
  219. if ($detail['director_uid'] == $this->uid) {
  220. $role = 2; //负责人
  221. }
  222. $auth = isAuth($this->uid,'project_admin','conf_1');
  223. if ($auth == 1) {
  224. $role = 3; //项目管理员
  225. }
  226. //相关附件
  227. $file_array = Db::name('ProjectFile')
  228. ->field('mf.id,mf.topic_id,mf.admin_id,f.id as file_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.name as admin_name')
  229. ->alias('mf')
  230. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  231. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  232. ->order('mf.create_time desc')
  233. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  234. ->select()->toArray();
  235. //阶段操作记录
  236. $step_record = Db::name('ProjectStepRecord')
  237. ->field('s.*,a.name as check_name,p.title')
  238. ->alias('s')
  239. ->join('Admin a', 'a.id = s.check_uid', 'LEFT')
  240. ->join('ProjectStep p', 'p.id = s.step_id', 'LEFT')
  241. ->order('s.check_time asc')
  242. ->where(array('s.project_id' => $id))
  243. ->select()->toArray();
  244. foreach ($step_record as $kk => &$vv) {
  245. $vv['check_time_str'] = date('Y-m-d H:i', $vv['check_time']);
  246. $vv['status_str'] = '提交';
  247. if($vv['status'] == 1){
  248. $vv['status_str'] = '确认完成';
  249. }
  250. else if($vv['status'] == 2){
  251. $vv['status_str'] = '回退';
  252. }
  253. if($vv['status'] == 3){
  254. $vv['status_str'] = '撤销';
  255. }
  256. if($vv['content'] == ''){
  257. $vv['content'] = '无';
  258. }
  259. }
  260. //当前项目阶段
  261. $step = Db::name('ProjectStep')->where(array('project_id' => $id, 'is_current' => 1,'delete_time'=>0))->find();
  262. if(!empty($step)){
  263. $step['director_name'] = Db::name('Admin')->where(['id' => $step['director_uid']])->value('name');
  264. $unames = Db::name('Admin')->where([['id','in',$step['uids']]])->column('name');
  265. $step['unames'] = implode(',',$unames);
  266. }
  267. View::assign('role', $role);
  268. View::assign('file_array', $file_array);
  269. View::assign('step', $step);
  270. View::assign('step_record', $step_record);
  271. View::assign('detail', $detail);
  272. if(is_mobile()){
  273. return view('qiye@/project/view');
  274. }
  275. return view();
  276. }
  277. else{
  278. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  279. }
  280. }
  281. /**
  282. * 删除
  283. */
  284. public function del()
  285. {
  286. $param = get_params();
  287. $id = isset($param['id']) ? $param['id'] : 0;
  288. if (request()->isDelete()) {
  289. $this->model->delById($id);
  290. } else {
  291. return to_assign(1, "错误的请求");
  292. }
  293. }
  294. }