AuditCompany.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <?php
  2. namespace app\admin\controller\project;
  3. use app\admin\BaseController;
  4. use app\admin\model\CostProject as CostProjectModel;
  5. use app\admin\validate\project\CostProjectValidate;
  6. use think\exception\ValidateException;
  7. use think\facade\Db;
  8. use think\facade\Session;
  9. use think\facade\View;
  10. use think\App;
  11. use app\admin\controller\field\Fieldcompany;
  12. use app\admin\controller\Pushmessage;
  13. class AuditCompany extends BaseController
  14. {
  15. public function __construct(App $app)
  16. {
  17. parent::__construct($app);
  18. $this->Field = new Fieldcompany($this->app);
  19. $this->model = new CostProjectModel();
  20. $this->uid = get_login_admin('id');
  21. $this->Pushmessage = new Pushmessage();
  22. }
  23. public function datalist()
  24. {
  25. if (request()->isAjax()) {
  26. $param = get_params();
  27. $where3 = [];
  28. if (!empty($param['keywords'])) {
  29. $keyword = $param['keywords'];
  30. $where3[] = ['project_num|project_name|entrust_unit_name', 'like', '%' . $keyword . '%'];
  31. }
  32. //财政局立项
  33. $where = [
  34. ["cp_cost_project.delete_time", "=", 0],
  35. ["project_status", "=", 3],
  36. ["review_unit", "=", get_login_admin('unit_name')]
  37. ];
  38. //业主立项
  39. $where2 = [
  40. ["cp_cost_project.delete_time", "=", 0],
  41. ["project_status", "=", 0],
  42. ["proprietor_status", "=", 2],
  43. ["review_unit", "=", get_login_admin('unit_name')]
  44. ];
  45. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  46. $order = empty($param['order']) ? 'id desc' : $param['order'];
  47. $list = $this->model->where($where3)->where(function ($query) use ($where,$where2) {
  48. // 第一组条件(entrust_maker)
  49. $query->where(function ($q1) use ($where) {
  50. $q1->where($where);
  51. });
  52. // 使用 OR 连接第二组条件(entrust_approver)
  53. $query->whereOr(function ($q2) use ($where2) {
  54. $q2->where($where2);
  55. });
  56. })
  57. ->order($order)->paginate($rows, false, ['query' => $param])
  58. ->each(function ($item) {
  59. $item->entrust_unit_name = Db::name('department')->where(['id' => $item->entrust_unit])->value('title');
  60. $entrust_head_id = Db::name('department')->where(['id' => $item->entrust_unit])->value('leader_id');
  61. if (!($item->entrust_head)) {
  62. $item->entrust_head = Db::name('admin')->where("id", $entrust_head_id)->value("nickname");
  63. }
  64. if (!($item->entrust_head_phone)) {
  65. $item->entrust_head_phone = Db::name('admin')->where("id", $entrust_head_id)->value("mobile");
  66. }
  67. //作业人
  68. $item->operate_name = Db::name("admin")->where("id", $item->operate_head)->value("nickname");
  69. $operate_team_names = null;
  70. $operate_team_names_ids = explode(",", $item->operate_team);
  71. for ($i = 0; $i < count($operate_team_names_ids); $i++) {
  72. $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
  73. if (!($i == 0)) {
  74. $name = "," . $name;
  75. }
  76. $operate_team_names = $operate_team_names . $name;
  77. }
  78. $item->operate_team_names = $operate_team_names;
  79. });
  80. return table_assign(0, '', $list);
  81. } else {
  82. return view();
  83. }
  84. }
  85. public function iframe(){
  86. return view();
  87. }
  88. /**
  89. *
  90. * 接收
  91. */
  92. public function receive()
  93. {
  94. $param = get_params();
  95. $handle = $this->Pushmessage->handleParam($param);
  96. $param = $handle['param'];
  97. $status = Db::name("cost_project")->where("id", $param["id"])->field("project_status")->select();
  98. if (0 <= $status[0]["project_status"] && $status[0]["project_status"] < 4 && $param["id"]) {
  99. $param = array_merge($param, ["project_status" => 4]);
  100. $param["project_receive_time"] = time();
  101. $entrust_maker = Db::name("cost_project")->where("id", $param["id"])->field("project_status")->value("entrust_maker");
  102. if(empty($handle['financial'])){
  103. $handle['financial'] = (array)$entrust_maker;
  104. }else{
  105. $handle['financial'] = array_merge($handle['financial'],(array)$entrust_maker);
  106. }
  107. // $this->Pushmessage->pushMessage($param["id"], $handle['financial'], $handle['company']);
  108. $this->model->editCostProject($param);
  109. add_project_log('接收项目', $param['id'], '接收项目');
  110. } else {
  111. return to_assign(0, "已审核,无法删除");
  112. }
  113. }
  114. public function project_log($project_id)
  115. {
  116. // $project_id = 24;
  117. $login_admin = get_login_admin();
  118. $where = array();
  119. if ($login_admin['user_type'] == 2) {
  120. $where = [
  121. ['project_status', '>=', 3],
  122. ['unit_name', '=', $login_admin['unit_name']],
  123. ];
  124. } else {
  125. if ($login_admin['permission'] != 1) {
  126. $where = [
  127. ['unit_name', '=', $login_admin['unit_name']],
  128. ];
  129. }
  130. }
  131. // dump($where);
  132. $project_log = Db::name('ProjectLog')->where($where)->where('project_id', $project_id)->order('create_time', 'desc')->select()->toArray();
  133. foreach ($project_log as $key => $value) {
  134. $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  135. }
  136. // dump($project_log);
  137. // View::assign('project_log', $project_log);
  138. // return View();
  139. return $project_log;
  140. }
  141. /**
  142. * 查看信息
  143. */
  144. public function read()
  145. {
  146. $param = get_params();
  147. $id = isset($param['id']) ? $param['id'] : 0;
  148. $detail = $this->model->getCostProjectById($id);
  149. $comment = Db::name("project_comment")->where("project_id", $id)->order('create_time', 'desc')->select();
  150. $file_array = Db::name('ProjectFile')
  151. ->field('mf.id,mf.topic_id,mf.admin_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.nickname as admin_name')
  152. ->alias('mf')
  153. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  154. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  155. ->order('mf.create_time desc')
  156. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  157. ->select()->toArray();
  158. $report = Db::name("project_report")->where([["project_id", "=", $id], ["r.status", "=", 1]])->alias("r")->join("admin a", "r.maker_id = a.id")->field("r.*,a.nickname")->select();
  159. // halt($comment);
  160. $project_log = self::project_log($id);
  161. View::assign('project_log', $project_log);
  162. // halt($project_log);
  163. // 根据用户id 查询其能显示的字段
  164. $field = $this->Field->get_field_rules_new($this->uid);
  165. // dump($field);
  166. if (!empty($detail)) {
  167. View::assign('project_id', $id);
  168. View::assign('comment', $comment);
  169. View::assign('field', $field);
  170. View::assign('detail', $detail);
  171. View::assign('file_array', $file_array);
  172. View::assign('report', $report);
  173. View::assign('project_five', self::getProjectFive());
  174. return view();
  175. } else {
  176. throw new \think\exception\HttpException(404, '找不到页面');
  177. }
  178. }
  179. public function getProjectFive()
  180. {
  181. $where = [
  182. ['name', '=', '作业日志-财政局'],
  183. ['name', '=', '工作记录-财政局'],
  184. ['name', '=', '项目报告-财政局'],
  185. ['name', '=', '项目人员-财政局'],
  186. ['name', '=', '项目动态-财政局'],
  187. ];
  188. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  189. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  190. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  191. $login_rules = explode(',', $login_rules);
  192. $rules_id = array();
  193. foreach ($list as $key => $value) {
  194. if ($value['name'] == "作业日志-财政局") {
  195. if (in_array($value['id'], $login_rules)) {
  196. $rules_id['project_comments'] = 1;
  197. } else {
  198. $rules_id['project_comments'] = 0;
  199. }
  200. } else if ($value['name'] == "工作记录-财政局") {
  201. if (in_array($value['id'], $login_rules)) {
  202. $rules_id['project_record'] = 1;
  203. } else {
  204. $rules_id['project_record'] = 0;
  205. }
  206. } else if ($value['name'] == "项目报告-财政局") {
  207. if (in_array($value['id'], $login_rules)) {
  208. $rules_id['project_report'] = 1;
  209. } else {
  210. $rules_id['project_report'] = 0;
  211. }
  212. } else if ($value['name'] == "项目人员-财政局") {
  213. if (in_array($value['id'], $login_rules)) {
  214. $rules_id['project_user'] = 1;
  215. } else {
  216. $rules_id['project_user'] = 0;
  217. }
  218. } else if ($value['name'] == "项目动态-财政局") {
  219. if (in_array($value['id'], $login_rules)) {
  220. $rules_id['project_log'] = 1;
  221. } else {
  222. $rules_id['project_log'] = 0;
  223. }
  224. }
  225. }
  226. return $rules_id;
  227. }
  228. }