Report.php 48 KB

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