Report.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\admin\controller\project;
  4. use app\admin\BaseController;
  5. use app\admin\controller\Pushmessage;
  6. use app\admin\model\CostProject;
  7. use app\admin\model\ProjectAudit;
  8. use app\admin\model\ProjectAudit as AuditModel;
  9. use app\admin\model\ProjectMsg;
  10. use app\admin\model\ProjectReport;
  11. use app\wechat\controller\Officialaccount;
  12. use think\db\exception\DbException;
  13. use think\exception\ValidateException;
  14. use HTMLPurifier;
  15. use HTMLPurifier_Config;
  16. use think\facade\Db;
  17. use think\facade\View;
  18. class Report extends BaseController
  19. {
  20. /**
  21. * 构造函数
  22. */
  23. public function __construct()
  24. {
  25. $this->model = new ProjectReport();
  26. $this->CostModel = new CostProject();
  27. $this->uid = get_login_admin('id');
  28. $this->ProjectMsg = new ProjectMsg();
  29. $this->Auditmodel = new AuditModel();
  30. $this->Officialaccount = new Officialaccount();
  31. $this->Pushmessage = new Pushmessage();
  32. }
  33. /**
  34. * 数据列表-财政局
  35. */
  36. public function datalist()
  37. {
  38. $param = get_params();
  39. // halt($param);
  40. $where = [
  41. ["cp_project_report.delete_time", "=", 0],
  42. ["project_id", "=", $param["project_id"]],
  43. ["a.status","<>",6],//公司待审批之前
  44. ["a.status","<>",7]//公司待审批之前
  45. ];
  46. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  47. $order = empty($param['order']) ? 'a.id desc' : $param['order'];
  48. $list = $this->model->where($where)
  49. ->field('a.*,f.name,f.filesize,f.filepath,f.fileext,f.admin_id')
  50. ->alias('a')
  51. ->join('file f', "a.file = f.id", "left")
  52. ->order($order)
  53. ->paginate($rows, false, ['query' => $param])
  54. ->each(function ($item, $key) {
  55. });
  56. return table_assign(0, '', $list);
  57. }
  58. /**
  59. * 数据列表-公司
  60. */
  61. public function datalist_company()
  62. {
  63. $param = get_params();
  64. $where = [
  65. ["cp_project_report.delete_time", "=", 0],
  66. ["project_id", "=", $param["project_id"]],
  67. ];
  68. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  69. $order = empty($param['order']) ? 'a.id desc' : $param['order'];
  70. $list = $this->model->where($where)
  71. ->field('a.*,f.name,f.filesize,f.filepath,f.fileext,f.admin_id')
  72. ->alias('a')
  73. ->join('file f', "a.file = f.id", "left")
  74. ->order($order)
  75. ->paginate($rows, false, ['query' => $param])
  76. ->each(function ($item, $key) {
  77. });
  78. // halt($list);
  79. return table_assign(0, '', $list);
  80. }
  81. /**
  82. * 数据列表-业主
  83. */
  84. public function datalist_proprietor()
  85. {
  86. $param = get_params();
  87. $where = [
  88. ["cp_project_report.delete_time", "=", 0],
  89. ["project_id", "=", $param["project_id"]],
  90. // ["a.status",">",7],//财评审完后才到业主
  91. ["a.status","<>",2]//财评拒绝后,业主端不显示
  92. ];
  93. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  94. $order = empty($param['order']) ? 'a.id desc' : $param['order'];
  95. $list = $this->model->where($where)
  96. ->field('a.*,u.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id')
  97. ->alias('a')
  98. ->join('file f', "a.file = f.id", "left")
  99. ->join('Admin u', 'a.maker_id = u.id', "left")
  100. ->order($order)
  101. ->paginate($rows, false, ['query' => $param])
  102. ->each(function ($item, $key) {
  103. });
  104. return table_assign(0, '', $list);
  105. }
  106. /**
  107. * 添加报告-公司
  108. */
  109. public function add_company()
  110. {
  111. $param = get_params();
  112. $handle = $this->Pushmessage->handleParam($param);
  113. $param = $handle['param'];
  114. if (request()->isAjax()) {
  115. if (isset($param['table-align'])) {
  116. unset($param['table-align']);
  117. }
  118. if (isset($param['content'])) {
  119. $param['md_content'] = '';
  120. }
  121. if (isset($param['docContent-html-code'])) {
  122. $param['content'] = $param['docContent-html-code'];
  123. $param['md_content'] = $param['docContent-markdown-doc'];
  124. unset($param['docContent-html-code']);
  125. unset($param['docContent-markdown-doc']);
  126. }
  127. // 创建HTMLPurifier配置对象
  128. $config = HTMLPurifier_Config::createDefault();
  129. $config->set('HTML.DefinitionID', 'html5-definitions');
  130. $config->set('HTML.DefinitionRev', 1);
  131. $config->set('HTML.ForbiddenAttributes', ['width', 'height']);
  132. //$config->set('HTML.Allowed', 'p,b,a[href],pre[class],code,blockquote,img[src],table,tr,th,td,ul,li,ol,dl,dt,dd');
  133. $config->set('HTML.ForbiddenElements', array('script'), true);//设置拒绝使用的tagname
  134. if ($def = $config->maybeGetRawHTMLDefinition()) {
  135. $def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
  136. 'src' => 'URI',
  137. 'type' => 'Text',
  138. 'poster' => 'URI',
  139. 'preload' => 'Enum#auto,metadata,none',
  140. 'controls' => 'Bool',
  141. ]);
  142. $def->addElement('source', 'Block', 'Flow', 'Common', [
  143. 'src' => 'URI',
  144. 'type' => 'Text',
  145. ]);
  146. }
  147. // 创建HTMLPurifier对象
  148. $purifier = new HTMLPurifier($config);
  149. //防止xss,过滤输入并输出结果
  150. //$param['content'] = '测试<script>alert(0);</script>';
  151. $param['content'] = $purifier->purify($param['content']);
  152. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  153. $param['status'] = 6;
  154. $param['project_id'] = $project_id;
  155. $param['maker_id'] = $this->uid;
  156. $param['admin_name'] = get_login_admin('nickname');
  157. try {
  158. $param['create_time'] = time();
  159. $insertId = $this->model->strict(false)->field(true)->insertGetId($param);
  160. $log = $param;
  161. unset($log['content']);
  162. add_log('add', $insertId, $log);
  163. } catch (\Exception $e) {
  164. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  165. }
  166. $detail = Db::name("cost_project")->where("id", $project_id)->field("project_name,project_status,entrust_maker,entrust_maker_name")->find();
  167. $auditDataArr = [];
  168. $auditData = [
  169. "project_id" => $project_id,
  170. "project_name" => $detail["project_name"],
  171. "project_type" => "造价项目",
  172. "audit_name" => "报告一审",
  173. "audit_type" => 4,
  174. "else_id" => $insertId,
  175. "sponsor" => get_login_admin("nickname"),
  176. "sponsor_id" => $this->uid,
  177. "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"),
  178. "approver" => $param["first"],
  179. "approver_name" => get_admin($param["first"])["nickname"],
  180. "create_time" => time()
  181. ];
  182. //1项目,2报告,3公司一级审核,4公司二级审核,5公司三级审核
  183. if (!empty($param["first"])) {
  184. $auditData["audit_name"] = "报告一审";
  185. $auditData["audit_type"] = 4;
  186. $auditData["approver"] = $param["first"];
  187. $auditData["approver_name"] = get_admin($param["first"])["nickname"];
  188. $auditDataArr[] = $auditData;
  189. if (empty($handle['financial'])) {
  190. $handle['company'] = (array)$param["first"];
  191. } else {
  192. $handle['company'] = array_merge($param["first"], $handle['financial']);
  193. }
  194. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  195. } else {
  196. return to_assign(1, "请选择审批人");
  197. }
  198. if (!empty($param["second"])) {
  199. $auditData["audit_name"] = "报告二审";
  200. $auditData["audit_type"] = 5;
  201. $auditData["audit_status"] = 5;
  202. $auditData["approver"] = $param["second"];
  203. $auditData["approver_name"] = get_admin($param["second"])["nickname"];
  204. $auditDataArr[] = $auditData;
  205. }
  206. if (!empty($param["third"])) {
  207. $auditData["audit_name"] = "报告三审";
  208. $auditData["audit_type"] = 6;
  209. $auditData["audit_status"] = 5;
  210. $auditData["approver"] = $param["third"];
  211. $auditData["approver_name"] = get_admin($param["third"])["nickname"];
  212. $auditDataArr[] = $auditData;
  213. }
  214. if (!empty($param["fourth"])) {
  215. $auditData["audit_name"] = "报告四审";
  216. $auditData["audit_type"] = 14;
  217. $auditData["audit_status"] = 5;
  218. $auditData["approver"] = $param["fourth"];
  219. $auditData["approver_name"] = get_admin($param["fourth"])["nickname"];
  220. $auditDataArr[] = $auditData;
  221. }
  222. if (!empty($param["fifth"])) {
  223. $auditData["audit_name"] = "报告五审";
  224. $auditData["audit_type"] = 15;
  225. $auditData["audit_status"] = 5;
  226. $auditData["approver"] = $param["fifth"];
  227. $auditData["approver_name"] = get_admin($param["fifth"])["nickname"];
  228. $auditDataArr[] = $auditData;
  229. }
  230. // halt($auditDataArr);
  231. if (!empty($auditDataArr)) {
  232. $ProjectAudit = new ProjectAudit();
  233. try {
  234. $ProjectAudit->saveAll($auditDataArr);
  235. } catch (\Exception $e) {
  236. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  237. }
  238. }
  239. return to_assign(0, '操作成功');
  240. } else {
  241. //dump($param);=>project_id
  242. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  243. //委托单位的id(财政局),评审单位id(公司),操作负责人id(作业部长),操作成员id(工人)
  244. $ids = Db::name('CostProject')->where("id", $project_id)->field("entrust_maker,review_head,operate_head,operate_team")->find();
  245. //halt($ids);
  246. $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"];
  247. $idarr = explode(",", $idarr);
  248. $people = Db::name("admin")->whereIn('id', $idarr)->field('id,nickname')->select();
  249. //dump($people);
  250. //富文本类型
  251. View::assign('editor', get_system_config('other', 'editor'));
  252. //关联项目id
  253. View::assign('project_id', $project_id);
  254. View::assign('people', $people);
  255. return view('add');
  256. }
  257. }
  258. /**
  259. * 查看信息-财政局
  260. */
  261. public function view()
  262. {
  263. $param = get_params();
  264. $id = isset($param['id']) ? $param['id'] : 0;
  265. $detail = (new ProjectReport())->detail($id);
  266. if (empty($detail)) {
  267. if (empty($detail)) {
  268. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';
  269. exit;
  270. }
  271. } else {
  272. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  273. $detail["maker_name"] = $maker_name;
  274. $file_array = Db::name('ProjectReport')
  275. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  276. ->alias('r')
  277. ->join('File f', 'r.file = f.id')
  278. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  279. ->order('r.create_time desc')
  280. ->where(array('r.id' => $id))
  281. ->select()->toArray();
  282. View::assign('file_array', $file_array);
  283. View::assign('detail', $detail);
  284. return view();
  285. }
  286. }
  287. /**
  288. * 查看信息-公司
  289. */
  290. public function view_company()
  291. {
  292. $param = get_params();
  293. $id = isset($param['id']) ? $param['id'] : 0;
  294. $detail = (new ProjectReport())->detail($id);
  295. if (empty($detail)) {
  296. if (empty($detail)) {
  297. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';
  298. exit;
  299. }
  300. } else {
  301. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  302. $detail["maker_name"] = $maker_name;
  303. $file_array = Db::name('ProjectReport')
  304. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  305. ->alias('r')
  306. ->join('File f', 'r.file = f.id')
  307. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  308. ->order('r.create_time desc')
  309. ->where(array('r.id' => $id))
  310. ->select()->toArray();
  311. View::assign('file_array', $file_array);
  312. View::assign('detail', $detail);
  313. return view();
  314. }
  315. }
  316. /**
  317. * 查看信息-业主
  318. */
  319. public function view_proprietor()
  320. {
  321. $param = get_params();
  322. $id = isset($param['id']) ? $param['id'] : 0;
  323. $detail = (new ProjectReport())->detail($id);
  324. if (empty($detail)) {
  325. if (empty($detail)) {
  326. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';
  327. exit;
  328. }
  329. } else {
  330. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  331. $detail["maker_name"] = $maker_name;
  332. $file_array = Db::name('ProjectReport')
  333. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  334. ->alias('r')
  335. ->join('File f', 'r.file = f.id')
  336. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  337. ->order('r.create_time desc')
  338. ->where(array('r.id' => $id))
  339. ->select()->toArray();
  340. View::assign('file_array', $file_array);
  341. View::assign('detail', $detail);
  342. return view();
  343. }
  344. }
  345. /**
  346. * 删除-公司
  347. * 跟财评申请删除
  348. */
  349. public function delete_company()
  350. {
  351. $param = get_params();
  352. $handle = $this->Pushmessage->handleParam($param);
  353. $param = $handle['param'];
  354. $id = isset($param['id']) ? $param['id'] : 0;
  355. $detail = $this->model->where("id", $id)->find();
  356. $approver = Db::name("cost_project")->where("id", $detail["project_id"])->value("entrust_maker");
  357. $details = Db::name("cost_project")->where("id", $detail["project_id"])->field("project_name,project_status,entrust_maker,entrust_maker_name")->find();
  358. $auditData = [
  359. "project_id" => $detail["project_id"],
  360. "project_name" => $details["project_name"],
  361. "project_type" => "造价项目",
  362. "audit_name" => "财评删除报告审核",
  363. "audit_type" => 2,
  364. "else_id" => $id,
  365. "sponsor" => get_login_admin("nickname"),
  366. "sponsor_id" => $this->uid,
  367. "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"),
  368. "approver" => $details["entrust_maker"],
  369. "approver_name" => $details["entrust_maker_name"],
  370. "remark" => $param["remark"],
  371. "create_time" => time()
  372. ];
  373. ProjectAudit::create($auditData);
  374. if (empty($handle['financial'])) {
  375. $handle['financial'] = (array)$details["entrust_maker"];
  376. } else {
  377. $handle['financial'] = array_merge($details["entrust_maker"], $handle['financial']);
  378. }
  379. $this->Pushmessage->pushMessage($detail["project_id"], $handle['financial'], $handle['company']);
  380. $this->model->where("id", $id)->update(["status" => 3]);
  381. add_project_log("发起删除项目报告审批", $detail["project_id"], $detail["title"]);
  382. return to_assign(0, "操作成功");
  383. }
  384. /**
  385. * 财评
  386. * 同意-报告
  387. */
  388. public function agree_report()
  389. {
  390. $param = get_params();
  391. $handle = $this->Pushmessage->handleParam($param);
  392. $param = $handle['param'];
  393. if (!isset($param["type"])) {//在项目列表通过
  394. $id = isset($param['id']) ? $param['id'] : 0;
  395. $detail = $this->model->where("id", $id)->find();//在Project_report里
  396. $project_id = $this->model->where("id", $id)->value("project_id");//在Project_report里
  397. try {
  398. Db::name("project_audit")->where([["else_id", "=", $id]])->where("audit_name","财评报告审核")->update(["audit_status" => 2, "audit_time" => time()]);//更新审批通过
  399. $this->model->where("id", $id)->update(["status" => 1]);//财评已通过
  400. } catch (DbException $e) {
  401. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  402. }
  403. //给业主新增报告审核
  404. $where = [
  405. ["project_id", "=", $project_id],
  406. ["else_id", "=", $id],//项目报告id
  407. ["audit_type", "=", 2]
  408. ];
  409. $de = Db::name("costProject")->where("id", $detail["project_id"])->field("sent_review_head,sent_review_head_name")->find();
  410. if (isset($de)) {
  411. $auditData = $this->Auditmodel->where($where)->find()->toArray();
  412. $auditData["audit_name"] = "业主报告审核";
  413. $auditData["audit_status"] = 1;
  414. $auditData["audit_type"] = 2;
  415. $auditData["approver"] = $de["sent_review_head"];
  416. $auditData["approver_name"] = $de["sent_review_head_name"];
  417. $auditData["create_time"] = time();
  418. $auditData["audit_time"] = null;
  419. $auditData["remark"] = null;
  420. $auditData["audit_remark"] = null;
  421. unset($auditData["id"]);
  422. try {
  423. $this->Auditmodel->save($auditData);
  424. } catch (\Exception $e) {
  425. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  426. }
  427. }
  428. //发给公司
  429. $people = $this->model->where('id', $id)->value("maker_id");
  430. $proprietor =Db::name("costProject")->where("id", $project_id)->value("sent_review_head");
  431. if (empty($handle['company'])) {
  432. $handle['company'] = (array)$people;
  433. } else {
  434. $handle['company'] = array_merge($handle['company'], (array)$people);
  435. }
  436. if (empty($handle['proprietor'])) {
  437. $handle['proprietor'] = (array)$proprietor;
  438. } else {
  439. $handle['proprietor'] = array_merge($handle['proprietor'], (array)$proprietor);
  440. }
  441. $this->Pushmessage->pushMessage( $project_id, $handle['financial'], $handle['company'],$handle["proprietor"]);
  442. add_project_log('财政局审批通过', $project_id, "报告审批通过");
  443. } else {//在审核列表里同意
  444. //$param['audit_time'] = time();
  445. $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]);
  446. add_log('edit', $param['id'], $param);
  447. $id = $param['id'];
  448. $this->model->where("id", $id)->update(["status" => 1]);//财评已通过
  449. unset($param["id"]);
  450. $detail = ProjectReport::where("id", $param["else_id"])->find();
  451. $type_status = $detail["status"];
  452. if ($type_status == 0) {//通过
  453. ProjectReport::where("id", $param["else_id"])->update(["status" => 1, "update_time" => time()]);
  454. }
  455. //给业主新增报告审核
  456. $where = [
  457. ["project_id", "=", $param["project_id"]],
  458. ["else_id", "=", $param["else_id"]],//项目报告id
  459. ["audit_type", "=", 2]
  460. ];
  461. $de = Db::name("cost_project")->where("id", $param["project_id"])->field("sent_review_head,sent_review_head_name")->find();
  462. if (isset($de)) {
  463. $auditData = $this->Auditmodel->where($where)->find()->toArray();
  464. $auditData["audit_name"] = "业主报告审核";
  465. $auditData["audit_status"] = 1;
  466. //$auditData["audit_type"] = 2;
  467. $auditData["approver"] = $de["sent_review_head"];
  468. $auditData["approver_name"] = $de["sent_review_head_name"];
  469. $auditData["create_time"] = time();
  470. $auditData["audit_time"] = null;
  471. $auditData["remark"] = null;
  472. $auditData["audit_remark"] = null;
  473. unset($auditData["id"]);
  474. try {
  475. $this->Auditmodel->save($auditData);
  476. } catch (\Exception $e) {
  477. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  478. }
  479. }
  480. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  481. $proprietor =Db::name("costProject")->where("id",$detail["project_id"])->value("sent_review_head");
  482. if (empty($handle['proprietor'])) {
  483. $handle['proprietor'] = (array)$proprietor;
  484. } else {
  485. $handle['proprietor'] = array_merge($handle['proprietor'], (array)$proprietor);
  486. }
  487. if (empty($handle['company'])) {
  488. $handle['company'] = (array)$people;
  489. } else {
  490. $handle['company'] = array_merge($handle['company'], (array)$people);
  491. }
  492. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company'],$handle['proprietor']);
  493. add_project_log('财政局审批通过', $param['project_id'], "报告审批通过");
  494. }
  495. return to_assign(0, "操作成功");
  496. }
  497. /**
  498. * 业主
  499. * 同意-报告 (已修改)
  500. */
  501. public function proprietor_agree_report()
  502. {
  503. $param = get_params();
  504. $handle = $this->Pushmessage->handleParam($param);
  505. $param = $handle['param'];
  506. //$type = isset($param['type']) ? $param['type'] : 0;
  507. if (!isset($param["type"])) {//在审核列表通过
  508. $id = isset($param['id']) ? $param['id'] : 0;
  509. $this->model->where("id", $id)->update(["status" => 8]);
  510. $detail = $this->model->where("id", $id)->find();
  511. //type,0初审,1对数,2审定
  512. $report_status = $detail["type"] + 1;
  513. $data = ['report_time' => time(), "report_status" => $report_status];
  514. try {
  515. Db::name("cost_project")->where("id", $detail["project_id"])->update($data);
  516. } catch (DbException $e) {
  517. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  518. }
  519. try {
  520. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 2, "audit_time" => time()]);
  521. } catch (DbException $e) {
  522. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  523. }
  524. $people = $this->model->where('id', $id)->value("maker_id");
  525. if (empty($handle['company'])) {
  526. $handle['company'] = (array)$people;
  527. } else {
  528. $handle['company'] = array_merge($handle['company'], (array)$people);
  529. }
  530. $this->Pushmessage->pushMessage( $detail["project_id"], $handle['financial'], $handle['company']);
  531. //add_project_log('业主审批通过', $detail["project_id"], "报告审批通过");
  532. } else {//在项目报告里通过
  533. $param['audit_time'] = time();
  534. $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]);
  535. add_log('edit', $param['id'], $param);
  536. $id = $param['id'];
  537. unset($param["id"]);
  538. $detail = ProjectReport::where("id", $param["else_id"])->find();
  539. //type,0初审,1对数,2审定
  540. $report_status = $detail["type"] + 1;
  541. $data = ['report_time' => time(), "report_status" => $report_status];
  542. $type_status = $detail["status"];
  543. if ($type_status == 1) {//财政局已通过
  544. ProjectReport::where("id", $param["else_id"])->update(["status" => 8, "update_time" => time()]);
  545. $this->CostModel->where('id', $param['project_id'])->strict(false)->update($data);
  546. }
  547. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  548. if (empty($handle['company'])) {
  549. $handle['company'] = (array)$people;
  550. } else {
  551. $handle['company'] = array_merge($handle['company'], (array)$people);
  552. }
  553. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  554. add_project_log('审批通过', $param['project_id'], "报告审批通过");
  555. }
  556. return to_assign(0, "操作成功");
  557. }
  558. /**
  559. * 财评(已修改)
  560. * 不同意-报告
  561. */
  562. public function un_report()
  563. {
  564. $param = get_params();
  565. $handle = $this->Pushmessage->handleParam($param);
  566. $param = $handle['param'];
  567. if (!isset($param["type"])) {//审核列表拒绝
  568. $id = isset($param['id']) ? $param['id'] : 0;
  569. $this->model->where("id", $id)->update(["status" => 2]);
  570. try {
  571. //全部的都变成已拒绝,修改为仅改变财评的状态
  572. Db::name("project_audit")->where([["else_id", "=", $id]])->where("audit_name","财评报告审核")->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"]]);
  573. } catch (DbException $e) {
  574. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  575. }
  576. $people = $this->model->where('id', $id)->value("maker_id");
  577. if (empty($handle['company'])) {
  578. $handle['company'] = (array)$people;
  579. } else {
  580. $handle['company'] = array_merge($handle['company'], (array)$people);
  581. }
  582. $project_id = $this->model->where("id", $id)->value("project_id");
  583. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  584. add_project_log('审批未通过', $project_id, "报告审批未通过");
  585. } else {//项目报告列表拒绝
  586. $param = get_params();
  587. $handle = $this->Pushmessage->handleParam($param);
  588. $param = $handle['param'];
  589. try {
  590. $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  591. $id = $param['id'];
  592. unset($param["id"]);
  593. $type_status = Db::name("project_report")->where("id", $param["else_id"])->value("status");
  594. if ($type_status == 0) {
  595. //新建
  596. Db::name("project_report")->where("id", $param["else_id"])->update(["status" => 2, "update_time" => time()]);
  597. } elseif ($type_status == 3) {
  598. //删除
  599. Db::name("project_report")->where("id", $param["else_id"])->update(["status" => 5, "update_time" => time()]);
  600. }
  601. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  602. if (empty($handle['company'])) {
  603. $handle['company'] = (array)$people;
  604. } else {
  605. $handle['company'] = array_merge($handle['company'], (array)$people);
  606. }
  607. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  608. add_project_log('审批未通过', $param['project_id'], "报告审批未通过");
  609. } catch (\Exception $e) {
  610. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  611. }
  612. }
  613. return to_assign(0, "操作成功");
  614. }
  615. /**
  616. * 业主 (已修改)
  617. * 不同意-报告
  618. */
  619. public function proprietor_un_report()
  620. {
  621. $param = get_params();
  622. $handle = $this->Pushmessage->handleParam($param);
  623. $param = $handle['param'];
  624. if (!isset($param["type"])) {//项目报告列表
  625. $id = isset($param['id']) ? $param['id'] : 0;
  626. $this->model->where("id", $id)->update(["status" => 9]);
  627. try {
  628. //一开始将所有的都改成了拒绝,改成了只改变业主的审批状态
  629. Db::name("project_audit")->where([["else_id", "=", $id]])->where("audit_name","业主报告审核")->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"],"audit_time" => time()]);
  630. } catch (DbException $e) {
  631. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  632. }
  633. $people = $this->model->where('id', $id)->value("maker_id");
  634. if (empty($handle['company'])) {
  635. $handle['company'] = (array)$people;
  636. } else {
  637. $handle['company'] = array_merge($handle['company'], (array)$people);
  638. }
  639. $project_id = $this->model->where("id", $id)->value("project_id");
  640. $this->Pushmessage->pushMessage($project_id, [], $handle['company']);
  641. //add_project_log('审批未通过', $project_id, "报告审批未通过");
  642. } else {//项目报告列表
  643. $param = get_params();
  644. $handle = $this->Pushmessage->handleParam($param);
  645. $param = $handle['param'];
  646. try {
  647. //$param['audit_time'] = time();
  648. $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  649. $id = $param['id'];
  650. unset($param["id"]);
  651. $type_status = Db::name("project_report")->where("id", $param["else_id"])->value("status");
  652. if ($type_status == 1) {
  653. //新建
  654. Db::name("project_report")->where("id", $param["else_id"])->update(["status" => 9, "update_time" => time()]);
  655. } elseif ($type_status == 4) {
  656. //删除
  657. Db::name("project_report")->where("id", $param["else_id"])->update(["status" => 11, "update_time" => time()]);
  658. }
  659. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  660. if (empty($handle['company'])) {
  661. $handle['company'] = (array)$people;
  662. } else {
  663. $handle['company'] = array_merge($handle['company'], (array)$people);
  664. }
  665. $this->Pushmessage->pushMessage($param['project_id'], [], $handle['company']);
  666. //add_project_log('审批未通过', $param['project_id'], "报告审批未通过");
  667. } catch (\Exception $e) {
  668. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  669. }
  670. }
  671. return to_assign(0, "操作成功");
  672. }
  673. /**
  674. * 财评(已修改)
  675. * 同意-删除
  676. */
  677. public function agree_delete()
  678. {
  679. $param = get_params();
  680. $handle = $this->Pushmessage->handleParam($param);
  681. $param = $handle['param'];
  682. if (!isset($param["type"])) {//在
  683. $id = isset($param['id']) ? $param['id'] : 0;
  684. $this->model->where("id", $id)->update(["status" => 4]);
  685. $detail = $this->model->where("id", $id)->find();
  686. $project_id = $this->model->where("id", $id)->value("project_id");//在Project_report里
  687. Db::name("project_audit")->where([["else_id", "=", $id]])->where("audit_name","财评删除报告审核")->update(["audit_status" => 2]);
  688. //给业主新增报告删除审核
  689. $where = [
  690. ["project_id", "=",$project_id],
  691. ["else_id", "=", $id],//项目报告id
  692. ["audit_type", "=", 2],
  693. ["audit_name","=","财评删除报告审核"]
  694. ];
  695. $de = Db::name("cost_project")->where("id", $project_id)->field("sent_review_head,sent_review_head_name")->find();
  696. if (isset($de)) {
  697. $auditData = $this->Auditmodel->where($where)->find()->toArray();//
  698. $auditData["audit_name"] = "业主删除报告审核";
  699. $auditData["audit_status"] = 1;
  700. $auditData["approver"] = $de["sent_review_head"];
  701. $auditData["approver_name"] = $de["sent_review_head_name"];
  702. $auditData["create_time"] = time();
  703. $auditData["audit_time"] = null;
  704. //$auditData["remark"] = null;
  705. $auditData["audit_remark"] = null;
  706. unset($auditData["id"]);
  707. try {
  708. $this->Auditmodel->save($auditData);
  709. } catch (\Exception $e) {
  710. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  711. }
  712. }
  713. $people = $this->model->where('id', $id)->value("maker_id");
  714. $proprietor =Db::name("costProject")->where("id",$project_id)->value("sent_review_head");
  715. if (empty($handle['proprietor'])) {
  716. $handle['proprietor'] = (array)$proprietor;
  717. } else {
  718. $handle['proprietor'] = array_merge($handle['proprietor'], (array)$proprietor);
  719. }
  720. if (empty($handle['company'])) {
  721. $handle['company'] = (array)$people;
  722. } else {
  723. $handle['company'] = array_merge($handle['company'], (array)$people);
  724. }
  725. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company'],$handle["proprietor"]);
  726. add_project_log('审批通过', $project_id, "报告删除审批通过");
  727. } else {//审核项目里
  728. $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]);
  729. $id = $param['id'];
  730. unset($param["id"]);
  731. //$param{else_id是项目报告id
  732. $detail = ProjectReport::where("id", $param["else_id"])->find();
  733. $type_status = $detail["status"];
  734. if ($type_status == 3) {
  735. ProjectReport::where("id", $param["else_id"])->update(["status" => 4, "update_time" => time()]);
  736. }
  737. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  738. $proprietor =Db::name("costProject")->where("id",$detail["project_id"])->value("sent_review_head");
  739. if (empty($handle['proprietor'])) {
  740. $handle['proprietor'] = (array)$proprietor;
  741. } else {
  742. $handle['proprietor'] = array_merge($handle['proprietor'], (array)$proprietor);
  743. }
  744. if (empty($handle['company'])) {
  745. $handle['company'] = (array)$people;
  746. } else {
  747. $handle['company'] = array_merge($handle['company'], (array)$people);
  748. }
  749. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company'],$handle["proprietor"]);
  750. add_project_log('审批通过', $param['project_id'], "报告删除审批通过");
  751. //给业主新增报告删除审核
  752. $where = [
  753. ["project_id", "=", $param["project_id"]],
  754. ["else_id", "=", $param["else_id"]],//项目报告id
  755. ["audit_type", "=", 2],
  756. ["audit_name","=","财评删除报告审核"]
  757. ];
  758. $de = Db::name("cost_project")->where("id", $param["project_id"])->field("sent_review_head,sent_review_head_name")->find();
  759. if (isset($de)) {
  760. $auditData = $this->Auditmodel->where($where)->find()->toArray();
  761. $auditData["audit_name"] = "业主删除报告审核";
  762. $auditData["audit_status"] = 1;
  763. $auditData["approver"] = $de["sent_review_head"];
  764. $auditData["approver_name"] = $de["sent_review_head_name"];
  765. $auditData["create_time"] = time();
  766. $auditData["audit_time"] = null;
  767. //$auditData["remark"] = null;
  768. $auditData["audit_remark"] = null;
  769. unset($auditData["id"]);
  770. try {
  771. $this->Auditmodel->save($auditData);
  772. } catch (\Exception $e) {
  773. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  774. }
  775. }
  776. }
  777. return to_assign(0, "操作成功");
  778. }
  779. /**
  780. * 业主 (已修改)
  781. * 同意-删除
  782. */
  783. public function proprietor_agree_delete()
  784. {
  785. $param = get_params();
  786. $handle = $this->Pushmessage->handleParam($param);
  787. $param = $handle['param'];
  788. if (!isset($param["type"])) {
  789. $id = isset($param['id']) ? $param['id'] : 0;
  790. $this->model->where("id", $id)->update(["status" => 10]);
  791. $detail = $this->model->where("id", $id)->find();
  792. try {
  793. Db::name("cost_project")->where("id", $detail["project_id"])->update(['report_time' => time()]);
  794. } catch (DbException $e) {
  795. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  796. }
  797. try {
  798. Db::name("project_audit")->where([["else_id", "=", $id]])->where("audit_name","业主删除报告审核")->update(["audit_status" => 2]);
  799. } catch (DbException $e) {
  800. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  801. }
  802. $people = $this->model->where('id', $id)->value("maker_id");
  803. if (empty($handle['company'])) {
  804. $handle['company'] = (array)$people;
  805. } else {
  806. $handle['company'] = array_merge($handle['company'], (array)$people);
  807. }
  808. $project_id = $this->model->where("id", $id)->value("project_id");
  809. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  810. add_project_log('业主审批通过', $project_id, "报告删除审批通过");
  811. } else {//在项目报告里
  812. $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]);
  813. $id = $param['id'];
  814. unset($param["id"]);
  815. $detail = ProjectReport::where("id", $param["else_id"])->find();
  816. $type_status = $detail["status"];
  817. if ($type_status == 4) {
  818. ProjectReport::where("id", $param["else_id"])->update(["status" => 10, "update_time" => time()]);
  819. Db::name("cost_project")->where("id", $detail["project_id"])->update(['report_time' => time()]);
  820. }
  821. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  822. if (empty($handle['company'])) {
  823. $handle['company'] = (array)$people;
  824. } else {
  825. $handle['company'] = array_merge($handle['company'], (array)$people);
  826. }
  827. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  828. add_project_log('业主审批通过', $param['project_id'], "报告删除审批通过");
  829. }
  830. return to_assign(0, "操作成功");
  831. }
  832. /**
  833. * 财评(已修改)
  834. * 不同意-删除
  835. */
  836. public function un_delete()
  837. {
  838. $param = get_params();
  839. $handle = $this->Pushmessage->handleParam($param);
  840. $param = $handle['param'];
  841. if (!isset($param["type"])) {
  842. $id = isset($param['id']) ? $param['id'] : 0;
  843. $this->model->where("id", $id)->update(["status" => 5]);
  844. try {
  845. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  846. } catch (DbException $e) {
  847. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  848. }
  849. $people = $this->model->where('id', $id)->value("maker_id");
  850. if (empty($handle['company'])) {
  851. $handle['company'] = (array)$people;
  852. } else {
  853. $handle['company'] = array_merge($handle['company'], (array)$people);
  854. }
  855. $project_id = $this->model->where("id", $id)->value("project_id");
  856. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  857. add_project_log('财政局审批未通过', $project_id, "报告删除审批未通过");
  858. } else {
  859. $param = get_params();
  860. $handle = $this->Pushmessage->handleParam($param);
  861. $param = $handle['param'];
  862. try {
  863. $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  864. $id = $param['id'];
  865. unset($param["id"]);
  866. $type_status = Db::name("project_report")->where("id", $param["else_id"])->value("status");
  867. if ($type_status == 3) {
  868. //删除
  869. Db::name("project_report")->where("id", $param["else_id"])->update(["status" => 5, "update_time" => time()]);
  870. }
  871. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  872. if (empty($handle['company'])) {
  873. $handle['company'] = (array)$people;
  874. } else {
  875. $handle['company'] = array_merge($handle['company'], (array)$people);
  876. }
  877. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  878. add_project_log('财政局审批未通过', $param['project_id'], "报告删除审批未通过");
  879. } catch (\Exception $e) {
  880. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  881. }
  882. }
  883. return to_assign(0, "操作成功");
  884. }
  885. /**
  886. * 业主 (已修改)
  887. * 不同意-删除
  888. */
  889. public function proprietor_un_delete()
  890. {
  891. $param = get_params();
  892. $handle = $this->Pushmessage->handleParam($param);
  893. $param = $handle['param'];
  894. if (!isset($param["type"])) {
  895. $id = isset($param['id']) ? $param['id'] : 0;
  896. $this->model->where("id", $id)->update(["status" => 11]);
  897. try {
  898. Db::name("project_audit")->where([["else_id", "=", $id]])->where("audit_name","业主删除报告审核")->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  899. } catch (DbException $e) {
  900. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  901. }
  902. $people = $this->model->where('id', $id)->value("maker_id");
  903. if (empty($handle['company'])) {
  904. $handle['company'] = (array)$people;
  905. } else {
  906. $handle['company'] = array_merge($handle['company'], (array)$people);
  907. }
  908. $project_id = $this->model->where("id", $id)->value("project_id");
  909. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  910. add_project_log('业主审批未通过', $project_id, "报告删除审批未通过");
  911. } else {
  912. $param = get_params();
  913. $handle = $this->Pushmessage->handleParam($param);
  914. $param = $handle['param'];
  915. try {
  916. $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  917. $id = $param['id'];
  918. unset($param["id"]);
  919. $type_status = Db::name("project_report")->where("id", $param["else_id"])->value("status");
  920. if ($type_status == 4) {
  921. //删除
  922. Db::name("project_report")->where("id", $param["else_id"])->update(["status" => 11, "update_time" => time()]);
  923. }
  924. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  925. if (empty($handle['company'])) {
  926. $handle['company'] = (array)$people;
  927. } else {
  928. $handle['company'] = array_merge($handle['company'], (array)$people);
  929. }
  930. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  931. add_project_log('业主审批未通过', $param['project_id'], "报告删除审批未通过");
  932. } catch (\Exception $e) {
  933. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  934. }
  935. }
  936. return to_assign(0, "操作成功");
  937. }
  938. /**
  939. * 报告附件上传
  940. */
  941. public function add_file_company()
  942. {
  943. $param = get_params();
  944. // $param['create_time'] = time();
  945. $param['maker_id'] = $this->uid;
  946. $file_array = Db::name('file')
  947. ->field("f.id,f.name,f.filesize,f.filepath,f.fileext,f.admin_id,f.create_time,a.nickname as admin_name")
  948. ->alias("f")
  949. // ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  950. ->join('Admin a', 'f.admin_id = a.id', 'LEFT')
  951. ->order('f.create_time desc')
  952. ->where(array('f.id' => $param["file"]))
  953. ->select()->toArray();
  954. // ->find();
  955. View::assign("file_array", $file_array);
  956. return json($file_array);
  957. }
  958. /**
  959. * 查看审批进度
  960. */
  961. public function progress()
  962. {
  963. $param = get_params();
  964. $id = isset($param['id']) ? $param['id'] : 0;
  965. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  966. $order = empty($param['order']) ? 'id desc' : $param['order'];
  967. $list = $this->Auditmodel->alias('a')->join("cost_project c", "a.project_id=c.id", 'left')
  968. ->field("a.*,c.project_status,c.sent_review_amount,c.engineering_type,c.review_unit_name")->where('else_id', $id)->order('create_time', "sec")
  969. ->select()
  970. ->each(function ($item) {
  971. switch ($item["audit_type"]) {
  972. case 4:
  973. $item->else_name = "报告一级审核";
  974. break;
  975. case 5:
  976. $item->else_name = "报告二级审核";
  977. break;
  978. case 6:
  979. $item->else_name = "报告三级审核";
  980. break;
  981. }
  982. });
  983. View::assign('list', $list);
  984. return view();
  985. }
  986. }