Report.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  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. ];
  90. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  91. $order = empty($param['order']) ? 'a.id desc' : $param['order'];
  92. $list = $this->model->where($where)
  93. ->field('a.*,u.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id')
  94. ->alias('a')
  95. ->join('file f', "a.file = f.id", "left")
  96. ->join('Admin u', 'a.maker_id = u.id', "left")
  97. ->order($order)
  98. ->paginate($rows, false, ['query' => $param])
  99. ->each(function ($item, $key) {
  100. });
  101. return table_assign(0, '', $list);
  102. }
  103. /**
  104. * 添加-公司
  105. */
  106. public function add_company()
  107. {
  108. $param = get_params();
  109. $handle = $this->Pushmessage->handleParam($param);
  110. $param = $handle['param'];
  111. if (request()->isAjax()) {
  112. if (isset($param['table-align'])) {
  113. unset($param['table-align']);
  114. }
  115. if (isset($param['content'])) {
  116. $param['md_content'] = '';
  117. }
  118. if (isset($param['docContent-html-code'])) {
  119. $param['content'] = $param['docContent-html-code'];
  120. $param['md_content'] = $param['docContent-markdown-doc'];
  121. unset($param['docContent-html-code']);
  122. unset($param['docContent-markdown-doc']);
  123. }
  124. // 创建HTMLPurifier配置对象
  125. $config = HTMLPurifier_Config::createDefault();
  126. $config->set('HTML.DefinitionID', 'html5-definitions');
  127. $config->set('HTML.DefinitionRev', 1);
  128. $config->set('HTML.ForbiddenAttributes', ['width', 'height']);
  129. //$config->set('HTML.Allowed', 'p,b,a[href],pre[class],code,blockquote,img[src],table,tr,th,td,ul,li,ol,dl,dt,dd');
  130. $config->set('HTML.ForbiddenElements', array('script'), true);//设置拒绝使用的tagname
  131. if ($def = $config->maybeGetRawHTMLDefinition()) {
  132. $def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
  133. 'src' => 'URI',
  134. 'type' => 'Text',
  135. 'poster' => 'URI',
  136. 'preload' => 'Enum#auto,metadata,none',
  137. 'controls' => 'Bool',
  138. ]);
  139. $def->addElement('source', 'Block', 'Flow', 'Common', [
  140. 'src' => 'URI',
  141. 'type' => 'Text',
  142. ]);
  143. }
  144. // 创建HTMLPurifier对象
  145. $purifier = new HTMLPurifier($config);
  146. //防止xss,过滤输入并输出结果
  147. //$param['content'] = '测试<script>alert(0);</script>';
  148. $param['content'] = $purifier->purify($param['content']);
  149. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  150. $param['status'] = 6;
  151. $param['project_id'] = $project_id;
  152. $param['maker_id'] = $this->uid;
  153. $param['admin_name'] = get_login_admin('nickname');
  154. try {
  155. $param['create_time'] = time();
  156. $insertId = $this->model->strict(false)->field(true)->insertGetId($param);
  157. $log = $param;
  158. unset($log['content']);
  159. add_log('add', $insertId, $log);
  160. } catch (\Exception $e) {
  161. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  162. }
  163. $detail = Db::name("cost_project")->where("id", $project_id)->field("project_name,project_status,entrust_maker,entrust_maker_name")->find();
  164. $auditDataArr = [];
  165. $auditData = [
  166. "project_id" => $project_id,
  167. "project_name" => $detail["project_name"],
  168. "project_type" => "造价项目",
  169. "audit_name" => "报告一审",
  170. "audit_type" => 4,
  171. "else_id" => $insertId,
  172. "sponsor" => get_login_admin("nickname"),
  173. "sponsor_id" => $this->uid,
  174. "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"),
  175. "approver" => $param["first"],
  176. "approver_name" => get_admin($param["first"])["nickname"],
  177. "create_time" => time()
  178. ];
  179. //1项目,2报告,3公司一级审核,4公司二级审核,5公司三级审核
  180. if (!empty($param["first"])) {
  181. $auditData["audit_name"] = "报告一审";
  182. $auditData["audit_type"] = 4;
  183. $auditData["approver"] = $param["first"];
  184. $auditData["approver_name"] = get_admin($param["first"])["nickname"];
  185. $auditDataArr[] = $auditData;
  186. if (empty($handle['financial'])) {
  187. $handle['company'] = (array)$param["first"];
  188. } else {
  189. $handle['company'] = array_merge($param["first"], $handle['financial']);
  190. }
  191. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  192. } else {
  193. return to_assign(1, "请选择审批人");
  194. }
  195. if (!empty($param["second"])) {
  196. $auditData["audit_name"] = "报告二审";
  197. $auditData["audit_type"] = 5;
  198. $auditData["audit_status"] = 5;
  199. $auditData["approver"] = $param["second"];
  200. $auditData["approver_name"] = get_admin($param["second"])["nickname"];
  201. $auditDataArr[] = $auditData;
  202. }
  203. if (!empty($param["third"])) {
  204. $auditData["audit_name"] = "报告三审";
  205. $auditData["audit_type"] = 6;
  206. $auditData["audit_status"] = 5;
  207. $auditData["approver"] = $param["third"];
  208. $auditData["approver_name"] = get_admin($param["third"])["nickname"];
  209. $auditDataArr[] = $auditData;
  210. }
  211. if (!empty($param["fourth"])) {
  212. $auditData["audit_name"] = "报告四审";
  213. $auditData["audit_type"] = 14;
  214. $auditData["audit_status"] = 5;
  215. $auditData["approver"] = $param["fourth"];
  216. $auditData["approver_name"] = get_admin($param["fourth"])["nickname"];
  217. $auditDataArr[] = $auditData;
  218. }
  219. if (!empty($param["fifth"])) {
  220. $auditData["audit_name"] = "报告五审";
  221. $auditData["audit_type"] = 15;
  222. $auditData["audit_status"] = 5;
  223. $auditData["approver"] = $param["fifth"];
  224. $auditData["approver_name"] = get_admin($param["fifth"])["nickname"];
  225. $auditDataArr[] = $auditData;
  226. }
  227. // halt($auditDataArr);
  228. if (!empty($auditDataArr)) {
  229. $ProjectAudit = new ProjectAudit();
  230. try {
  231. $ProjectAudit->saveAll($auditDataArr);
  232. } catch (\Exception $e) {
  233. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  234. }
  235. }
  236. return to_assign(0, '操作成功');
  237. } else {
  238. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  239. $ids = Db::name('CostProject')->where("id", $project_id)->field("entrust_maker,review_head,operate_head,operate_team")->find();
  240. // halt($ids);
  241. $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"];
  242. $idarr = explode(",", $idarr);
  243. $people = Db::name("admin")->whereIn('id', $idarr)->field('id,nickname')->select();
  244. //富文本类型
  245. View::assign('editor', get_system_config('other', 'editor'));
  246. //关联项目id
  247. View::assign('project_id', $project_id);
  248. View::assign('people', $people);
  249. return view('add');
  250. }
  251. }
  252. /**
  253. * 查看信息-财政局
  254. */
  255. public function view()
  256. {
  257. $param = get_params();
  258. $id = isset($param['id']) ? $param['id'] : 0;
  259. $detail = (new ProjectReport())->detail($id);
  260. if (empty($detail)) {
  261. if (empty($detail)) {
  262. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';
  263. exit;
  264. }
  265. } else {
  266. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  267. $detail["maker_name"] = $maker_name;
  268. $file_array = Db::name('ProjectReport')
  269. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  270. ->alias('r')
  271. ->join('File f', 'r.file = f.id')
  272. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  273. ->order('r.create_time desc')
  274. ->where(array('r.id' => $id))
  275. ->select()->toArray();
  276. View::assign('file_array', $file_array);
  277. View::assign('detail', $detail);
  278. return view();
  279. }
  280. }
  281. /**
  282. * 查看信息-公司
  283. */
  284. public function view_company()
  285. {
  286. $param = get_params();
  287. $id = isset($param['id']) ? $param['id'] : 0;
  288. $detail = (new ProjectReport())->detail($id);
  289. if (empty($detail)) {
  290. if (empty($detail)) {
  291. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';
  292. exit;
  293. }
  294. } else {
  295. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  296. $detail["maker_name"] = $maker_name;
  297. $file_array = Db::name('ProjectReport')
  298. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  299. ->alias('r')
  300. ->join('File f', 'r.file = f.id')
  301. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  302. ->order('r.create_time desc')
  303. ->where(array('r.id' => $id))
  304. ->select()->toArray();
  305. View::assign('file_array', $file_array);
  306. View::assign('detail', $detail);
  307. return view();
  308. }
  309. }
  310. /**
  311. * 查看信息-业主
  312. */
  313. public function view_proprietor()
  314. {
  315. $param = get_params();
  316. $id = isset($param['id']) ? $param['id'] : 0;
  317. $detail = (new ProjectReport())->detail($id);
  318. if (empty($detail)) {
  319. if (empty($detail)) {
  320. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';
  321. exit;
  322. }
  323. } else {
  324. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  325. $detail["maker_name"] = $maker_name;
  326. $file_array = Db::name('ProjectReport')
  327. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  328. ->alias('r')
  329. ->join('File f', 'r.file = f.id')
  330. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  331. ->order('r.create_time desc')
  332. ->where(array('r.id' => $id))
  333. ->select()->toArray();
  334. View::assign('file_array', $file_array);
  335. View::assign('detail', $detail);
  336. return view();
  337. }
  338. }
  339. /**
  340. * 删除-公司
  341. * 跟财评申请删除
  342. */
  343. public function delete_company()
  344. {
  345. $param = get_params();
  346. $handle = $this->Pushmessage->handleParam($param);
  347. $param = $handle['param'];
  348. $id = isset($param['id']) ? $param['id'] : 0;
  349. $detail = $this->model->where("id", $id)->find();
  350. $approver = Db::name("cost_project")->where("id", $detail["project_id"])->value("entrust_maker");
  351. $details = Db::name("cost_project")->where("id", $detail["project_id"])->field("project_name,project_status,entrust_maker,entrust_maker_name")->find();
  352. $auditData = [
  353. "project_id" => $detail["project_id"],
  354. "project_name" => $details["project_name"],
  355. "project_type" => "造价项目",
  356. "audit_name" => "删除报告申请",
  357. "audit_type" => 2,
  358. "else_id" => $id,
  359. "sponsor" => get_login_admin("nickname"),
  360. "sponsor_id" => $this->uid,
  361. "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"),
  362. "approver" => $details["entrust_maker"],
  363. "approver_name" => $details["entrust_maker_name"],
  364. "remark" => $param["remark"],
  365. "create_time" => time()
  366. ];
  367. ProjectAudit::create($auditData);
  368. if (empty($handle['financial'])) {
  369. $handle['financial'] = (array)$details["entrust_maker"];
  370. } else {
  371. $handle['financial'] = array_merge($details["entrust_maker"], $handle['financial']);
  372. }
  373. $this->Pushmessage->pushMessage($detail["project_id"], $handle['financial'], $handle['company']);
  374. $this->model->where("id", $id)->update(["status" => 3]);
  375. add_project_log("发起删除项目报告审批", $detail["project_id"], $detail["title"]);
  376. return to_assign(0, "操作成功");
  377. }
  378. /**
  379. * 财评
  380. * 同意-报告
  381. */
  382. public function agree_report()
  383. {
  384. $param = get_params();
  385. $handle = $this->Pushmessage->handleParam($param);
  386. $param = $handle['param'];
  387. $type = isset($param['type']) ? $param['type'] : 0;
  388. if (!isset($param["type"])) {
  389. $id = isset($param['id']) ? $param['id'] : 0;
  390. $this->model->where("id", $id)->update(["status" => 1]);
  391. $detail = $this->model->where("id", $id)->find();
  392. $num = $this->model->where([
  393. ["project_id", "=", $detail["project_id"],
  394. ["type", ">", $detail["type"]]],
  395. ["status", ">", 1],
  396. ["status", "<>", 2],
  397. ["status", "<", 4]
  398. ])->count();
  399. //type,0初审,1对数,2审定
  400. $report_status = $detail["type"] + 1;
  401. if ($num == 0) {
  402. $data = ['report_time' => time(), "report_status" => $report_status];
  403. } else {
  404. $data = ['report_time' => time()];
  405. }
  406. try {
  407. Db::name("cost_project")->where("id", $detail["project_id"])->update($data);
  408. } catch (DbException $e) {
  409. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  410. }
  411. try {
  412. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 2, "audit_time" => time()]);
  413. } catch (DbException $e) {
  414. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  415. }
  416. $people = $this->model->where('id', $id)->value("maker_id");
  417. if (empty($handle['company'])) {
  418. $handle['company'] = (array)$people;
  419. } else {
  420. $handle['company'] = array_merge($handle['company'], (array)$people);
  421. }
  422. $this->Pushmessage->pushMessage($detail["project_id"], $handle['financial'], $handle['company']);
  423. } else {
  424. $param['audit_time'] = time();
  425. $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]);
  426. add_log('edit', $param['id'], $param);
  427. $id = $param['id'];
  428. unset($param["id"]);
  429. $detail = ProjectReport::where("id", $param["else_id"])->find();
  430. $num = $this->model->where([
  431. ["project_id", "=", $detail["project_id"],
  432. ["type", ">", $detail["type"]]],
  433. ["status", ">", 1],
  434. ["status", "<>", 2],
  435. ["status", "<", 4]
  436. ])->count();
  437. //type,0初审,1对数,2审定
  438. $report_status = $detail["type"] + 1;
  439. if ($num == 0) {
  440. $data = ['report_time' => time(), "report_status" => $report_status];
  441. } else {
  442. $data = ['report_time' => time()];
  443. }
  444. $type_status = $detail["status"];
  445. if ($type_status == 0) {
  446. ProjectReport::where("id", $param["else_id"])->update(["status" => 1, "update_time" => time()]);
  447. $this->CostModel->where('id', $param['project_id'])->strict(false)->update($data);
  448. } elseif ($type_status == 3) {
  449. ProjectReport::where("id", $param["else_id"])->update(["status" => 4, "update_time" => time()]);
  450. }
  451. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  452. if (empty($handle['company'])) {
  453. $handle['company'] = (array)$people;
  454. } else {
  455. $handle['company'] = array_merge($handle['company'], (array)$people);
  456. }
  457. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  458. add_project_log('审批通过', $param['project_id'], "报告审批通过");
  459. }
  460. return to_assign(0, "操作成功");
  461. }
  462. /**
  463. * 财评
  464. * 不同意-报告
  465. */
  466. public function un_report()
  467. {
  468. $param = get_params();
  469. $handle = $this->Pushmessage->handleParam($param);
  470. $param = $handle['param'];
  471. if (!isset($param["type"])) {
  472. $id = isset($param['id']) ? $param['id'] : 0;
  473. $this->model->where("id", $id)->update(["status" => 2]);
  474. try {
  475. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"]]);
  476. } catch (DbException $e) {
  477. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  478. }
  479. $people = $this->model->where('id', $id)->value("maker_id");
  480. if (empty($handle['company'])) {
  481. $handle['company'] = (array)$people;
  482. } else {
  483. $handle['company'] = array_merge($handle['company'], (array)$people);
  484. }
  485. $project_id = $this->model->where("id", $id)->value("project_id");
  486. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  487. } else {
  488. $param = get_params();
  489. $handle = $this->Pushmessage->handleParam($param);
  490. $param = $handle['param'];
  491. try {
  492. $param['audit_time'] = time();
  493. $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  494. $id = $param['id'];
  495. unset($param["id"]);
  496. $type_status = Db::name("contact")->where("id", $param["else_id"])->value("status");
  497. if ($type_status == 0) {
  498. //新建
  499. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 2, "update_time" => time()]);
  500. } elseif ($type_status == 3) {
  501. //删除
  502. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 5, "update_time" => time()]);
  503. }
  504. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  505. if (empty($handle['company'])) {
  506. $handle['company'] = (array)$people;
  507. } else {
  508. $handle['company'] = array_merge($handle['company'], (array)$people);
  509. }
  510. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  511. } catch (\Exception $e) {
  512. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  513. }
  514. }
  515. return to_assign(0, "操作成功");
  516. }
  517. /**
  518. * 财评
  519. * 同意-删除
  520. */
  521. public function agree_delete()
  522. {
  523. $param = get_params();
  524. $handle = $this->Pushmessage->handleParam($param);
  525. $param = $handle['param'];
  526. if (!isset($param["type"])) {
  527. $id = isset($param['id']) ? $param['id'] : 0;
  528. $this->model->where("id", $id)->update(["status" => 4]);
  529. $detail = $this->model->where("id", $id)->find();
  530. //type,0初审,1对数,2审定
  531. $num = $this->model->where([
  532. ["project_id", "=", $detail["project_id"],
  533. ["type", ">=", $detail["type"]]],
  534. ["status", ">", 1],
  535. ["status", "<>", 2],
  536. ["status", "<", 4]
  537. ])->count();
  538. //type,0初审,1对数,2审定
  539. $report_status = $detail["type"];
  540. if ($num == 0) {
  541. $data = ['report_time' => time(), "report_status" => $report_status];
  542. } else {
  543. $data = ['report_time' => time()];
  544. }
  545. try {
  546. Db::name("cost_project")->where("id", $detail["project_id"])->update($data);
  547. } catch (DbException $e) {
  548. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  549. }
  550. try {
  551. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 2]);
  552. } catch (DbException $e) {
  553. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  554. }
  555. $people = $this->model->where('id', $id)->value("maker_id");
  556. if (empty($handle['company'])) {
  557. $handle['company'] = (array)$people;
  558. } else {
  559. $handle['company'] = array_merge($handle['company'], (array)$people);
  560. }
  561. $project_id = $this->model->where("id", $id)->value("project_id");
  562. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  563. } else {
  564. $param['audit_time'] = time();
  565. $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]);
  566. $id = $param['id'];
  567. unset($param["id"]);
  568. $detail = ProjectReport::where("id", $param["else_id"])->find();
  569. $num = $this->model->where([
  570. ["project_id", "=", $detail["project_id"],
  571. ["type", ">=", $detail["type"]]],
  572. ["status", ">", 1],
  573. ["status", "<>", 2],
  574. ["status", "<", 4]
  575. ])->count();
  576. //type,0初审,1对数,2审定
  577. $report_status = $detail["type"];
  578. if ($num == 0) {
  579. $data = ['report_time' => time(), "report_status" => $report_status];
  580. } else {
  581. $data = ['report_time' => time()];
  582. }
  583. $type_status = $detail["status"];
  584. if ($type_status == 0) {
  585. ProjectReport::where("id", $param["else_id"])->update(["status" => 1, "update_time" => time()]);
  586. $this->CostModel->where('id', $param['project_id'])->strict(false)->update($data);
  587. } elseif ($type_status == 3) {
  588. ProjectReport::where("id", $param["else_id"])->update(["status" => 4, "update_time" => time()]);
  589. Db::name("cost_project")->where("id", $detail["project_id"])->update(["report_status" => $report_status]);
  590. }
  591. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  592. if (empty($handle['company'])) {
  593. $handle['company'] = (array)$people;
  594. } else {
  595. $handle['company'] = array_merge($handle['company'], (array)$people);
  596. }
  597. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  598. add_project_log('审批通过', $param['project_id'], "报告删除审批通过");
  599. }
  600. return to_assign(0, "操作成功");
  601. }
  602. /**
  603. * 财评
  604. * 不同意-删除
  605. */
  606. public function un_delete()
  607. {
  608. $param = get_params();
  609. $handle = $this->Pushmessage->handleParam($param);
  610. $param = $handle['param'];
  611. if (!isset($param["type"])) {
  612. $id = isset($param['id']) ? $param['id'] : 0;
  613. $this->model->where("id", $id)->update(["status" => 5]);
  614. try {
  615. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"]]);
  616. } catch (DbException $e) {
  617. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  618. }
  619. $people = $this->model->where('id', $id)->value("maker_id");
  620. if (empty($handle['company'])) {
  621. $handle['company'] = (array)$people;
  622. } else {
  623. $handle['company'] = array_merge($handle['company'], (array)$people);
  624. }
  625. $project_id = $this->model->where("id", $id)->value("project_id");
  626. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  627. } else {
  628. $param = get_params();
  629. $handle = $this->Pushmessage->handleParam($param);
  630. $param = $handle['param'];
  631. try {
  632. $param['audit_time'] = time();
  633. $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  634. $id = $param['id'];
  635. unset($param["id"]);
  636. $type_status = Db::name("contact")->where("id", $param["else_id"])->value("status");
  637. if ($type_status == 0) {
  638. //新建
  639. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 2, "update_time" => time()]);
  640. } elseif ($type_status == 3) {
  641. //删除
  642. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 5, "update_time" => time()]);
  643. }
  644. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  645. if (empty($handle['company'])) {
  646. $handle['company'] = (array)$people;
  647. } else {
  648. $handle['company'] = array_merge($handle['company'], (array)$people);
  649. }
  650. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  651. } catch (\Exception $e) {
  652. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  653. }
  654. }
  655. return to_assign(0, "操作成功");
  656. }
  657. /**
  658. * 报告附件上传
  659. */
  660. public function add_file_company()
  661. {
  662. $param = get_params();
  663. // $param['create_time'] = time();
  664. $param['maker_id'] = $this->uid;
  665. $file_array = Db::name('file')
  666. ->field("f.id,f.name,f.filesize,f.filepath,f.fileext,f.admin_id,f.create_time,a.nickname as admin_name")
  667. ->alias("f")
  668. // ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  669. ->join('Admin a', 'f.admin_id = a.id', 'LEFT')
  670. ->order('f.create_time desc')
  671. ->where(array('f.id' => $param["file"]))
  672. ->select()->toArray();
  673. // ->find();
  674. View::assign("file_array", $file_array);
  675. return json($file_array);
  676. }
  677. /**
  678. * 查看审批进度
  679. */
  680. public function progress()
  681. {
  682. $param = get_params();
  683. $id = isset($param['id']) ? $param['id'] : 0;
  684. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  685. $order = empty($param['order']) ? 'id desc' : $param['order'];
  686. $list = $this->Auditmodel->alias('a')->join("cost_project c", "a.project_id=c.id", 'left')
  687. ->field("a.*,c.project_status,c.sent_review_amount,c.engineering_type,c.review_unit_name")->where('else_id', $id)->order('create_time', "sec")
  688. ->select()
  689. ->each(function ($item) {
  690. switch ($item["audit_type"]) {
  691. case 4:
  692. $item->else_name = "报告一级审核";
  693. break;
  694. case 5:
  695. $item->else_name = "报告二级审核";
  696. break;
  697. case 6:
  698. $item->else_name = "报告三级审核";
  699. break;
  700. }
  701. });
  702. View::assign('list', $list);
  703. return view();
  704. }
  705. }