Report.php 47 KB

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