Report.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  240. $ids = Db::name('CostProject')->where("id", $project_id)->field("entrust_maker,review_head,operate_head,operate_team")->find();
  241. // halt($ids);
  242. $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"];
  243. $idarr = explode(",", $idarr);
  244. $people = Db::name("admin")->whereIn('id', $idarr)->field('id,nickname')->select();
  245. //富文本类型
  246. View::assign('editor', get_system_config('other', 'editor'));
  247. //关联项目id
  248. View::assign('project_id', $project_id);
  249. View::assign('people', $people);
  250. return view('add');
  251. }
  252. }
  253. /**
  254. * 查看信息-财政局
  255. */
  256. public function view()
  257. {
  258. $param = get_params();
  259. $id = isset($param['id']) ? $param['id'] : 0;
  260. $detail = (new ProjectReport())->detail($id);
  261. if (empty($detail)) {
  262. if (empty($detail)) {
  263. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';
  264. exit;
  265. }
  266. } else {
  267. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  268. $detail["maker_name"] = $maker_name;
  269. $file_array = Db::name('ProjectReport')
  270. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  271. ->alias('r')
  272. ->join('File f', 'r.file = f.id')
  273. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  274. ->order('r.create_time desc')
  275. ->where(array('r.id' => $id))
  276. ->select()->toArray();
  277. View::assign('file_array', $file_array);
  278. View::assign('detail', $detail);
  279. return view();
  280. }
  281. }
  282. /**
  283. * 查看信息-公司
  284. */
  285. public function view_company()
  286. {
  287. $param = get_params();
  288. $id = isset($param['id']) ? $param['id'] : 0;
  289. $detail = (new ProjectReport())->detail($id);
  290. if (empty($detail)) {
  291. if (empty($detail)) {
  292. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';
  293. exit;
  294. }
  295. } else {
  296. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  297. $detail["maker_name"] = $maker_name;
  298. $file_array = Db::name('ProjectReport')
  299. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  300. ->alias('r')
  301. ->join('File f', 'r.file = f.id')
  302. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  303. ->order('r.create_time desc')
  304. ->where(array('r.id' => $id))
  305. ->select()->toArray();
  306. View::assign('file_array', $file_array);
  307. View::assign('detail', $detail);
  308. return view();
  309. }
  310. }
  311. /**
  312. * 查看信息-业主
  313. */
  314. public function view_proprietor()
  315. {
  316. $param = get_params();
  317. $id = isset($param['id']) ? $param['id'] : 0;
  318. $detail = (new ProjectReport())->detail($id);
  319. if (empty($detail)) {
  320. if (empty($detail)) {
  321. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';
  322. exit;
  323. }
  324. } else {
  325. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  326. $detail["maker_name"] = $maker_name;
  327. $file_array = Db::name('ProjectReport')
  328. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  329. ->alias('r')
  330. ->join('File f', 'r.file = f.id')
  331. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  332. ->order('r.create_time desc')
  333. ->where(array('r.id' => $id))
  334. ->select()->toArray();
  335. View::assign('file_array', $file_array);
  336. View::assign('detail', $detail);
  337. return view();
  338. }
  339. }
  340. /**
  341. * 删除-公司
  342. * 跟财评申请删除
  343. */
  344. public function delete_company()
  345. {
  346. $param = get_params();
  347. $handle = $this->Pushmessage->handleParam($param);
  348. $param = $handle['param'];
  349. $id = isset($param['id']) ? $param['id'] : 0;
  350. $detail = $this->model->where("id", $id)->find();
  351. $approver = Db::name("cost_project")->where("id", $detail["project_id"])->value("entrust_maker");
  352. $details = Db::name("cost_project")->where("id", $detail["project_id"])->field("project_name,project_status,entrust_maker,entrust_maker_name")->find();
  353. $auditData = [
  354. "project_id" => $detail["project_id"],
  355. "project_name" => $details["project_name"],
  356. "project_type" => "造价项目",
  357. "audit_name" => "删除报告申请",
  358. "audit_type" => 2,
  359. "else_id" => $id,
  360. "sponsor" => get_login_admin("nickname"),
  361. "sponsor_id" => $this->uid,
  362. "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"),
  363. "approver" => $details["entrust_maker"],
  364. "approver_name" => $details["entrust_maker_name"],
  365. "remark" => $param["remark"],
  366. "create_time" => time()
  367. ];
  368. ProjectAudit::create($auditData);
  369. if (empty($handle['financial'])) {
  370. $handle['financial'] = (array)$details["entrust_maker"];
  371. } else {
  372. $handle['financial'] = array_merge($details["entrust_maker"], $handle['financial']);
  373. }
  374. $this->Pushmessage->pushMessage($detail["project_id"], $handle['financial'], $handle['company']);
  375. $this->model->where("id", $id)->update(["status" => 3]);
  376. add_project_log("发起删除项目报告审批", $detail["project_id"], $detail["title"]);
  377. return to_assign(0, "操作成功");
  378. }
  379. /**
  380. * 财评
  381. * 同意-报告
  382. */
  383. public function agree_report()
  384. {
  385. $param = get_params();
  386. $handle = $this->Pushmessage->handleParam($param);
  387. $param = $handle['param'];
  388. $type = isset($param['type']) ? $param['type'] : 0;
  389. dump($type);
  390. if (!isset($param["type"])) {
  391. $id = isset($param['id']) ? $param['id'] : 0;
  392. $this->model->where("id", $id)->update(["status" => 1]);//已通过
  393. $detail = $this->model->where("id", $id)->find();
  394. $num = $this->model->where([
  395. ["project_id", "=", $detail["project_id"],
  396. ["type", ">", $detail["type"]]],
  397. ["status", ">", 1],//已通过
  398. ["status", "<>", 2],//不等于
  399. ["status", "<", 4]//小于删除通过
  400. ])->count();//找到删除待审核的
  401. //type,0初审,1对数,2审定
  402. $report_status = $detail["type"] + 1;
  403. if ($num == 0) {
  404. $data = ['report_time' => time(), "report_status" => $report_status];
  405. } else {
  406. $data = ['report_time' => time()];
  407. }
  408. try {
  409. Db::name("cost_project")->where("id", $detail["project_id"])->update($data);
  410. } catch (DbException $e) {
  411. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  412. }
  413. try {
  414. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 2, "audit_time" => time()]);
  415. } catch (DbException $e) {
  416. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  417. }
  418. $people = $this->model->where('id', $id)->value("maker_id");
  419. if (empty($handle['company'])) {
  420. $handle['company'] = (array)$people;
  421. } else {
  422. $handle['company'] = array_merge($handle['company'], (array)$people);
  423. }
  424. $this->Pushmessage->pushMessage($detail["project_id"], $handle['financial'], $handle['company']);
  425. } else {
  426. $param['audit_time'] = time();
  427. $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]);
  428. add_log('edit', $param['id'], $param);
  429. $id = $param['id'];
  430. unset($param["id"]);
  431. $detail = ProjectReport::where("id", $param["else_id"])->find();
  432. $num = $this->model->where([
  433. ["project_id", "=", $detail["project_id"],
  434. ["type", ">", $detail["type"]]],
  435. ["status", ">", 1],
  436. ["status", "<>", 2],
  437. ["status", "<", 4]
  438. ])->count();
  439. //type,0初审,1对数,2审定
  440. $report_status = $detail["type"] + 1;
  441. if ($num == 0) {
  442. $data = ['report_time' => time(), "report_status" => $report_status];
  443. } else {
  444. $data = ['report_time' => time()];
  445. }
  446. $type_status = $detail["status"];
  447. if ($type_status == 0) {
  448. ProjectReport::where("id", $param["else_id"])->update(["status" => 1, "update_time" => time()]);
  449. $this->CostModel->where('id', $param['project_id'])->strict(false)->update($data);
  450. } elseif ($type_status == 3) {
  451. ProjectReport::where("id", $param["else_id"])->update(["status" => 4, "update_time" => time()]);
  452. }
  453. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  454. if (empty($handle['company'])) {
  455. $handle['company'] = (array)$people;
  456. } else {
  457. $handle['company'] = array_merge($handle['company'], (array)$people);
  458. }
  459. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  460. add_project_log('审批通过', $param['project_id'], "报告审批通过");
  461. }
  462. return to_assign(0, "操作成功");
  463. }
  464. /**
  465. * 业主
  466. * 同意-报告 (未修改)
  467. */
  468. public function proprietor_agree_report()
  469. {
  470. $param = get_params();
  471. $handle = $this->Pushmessage->handleParam($param);
  472. $param = $handle['param'];
  473. $type = isset($param['type']) ? $param['type'] : 0;
  474. if (!isset($param["type"])) {
  475. $id = isset($param['id']) ? $param['id'] : 0;
  476. $this->model->where("id", $id)->update(["status" => 1]);
  477. $detail = $this->model->where("id", $id)->find();
  478. $num = $this->model->where([
  479. ["project_id", "=", $detail["project_id"],
  480. ["type", ">", $detail["type"]]],
  481. ["status", ">", 1],
  482. ["status", "<>", 2],
  483. ["status", "<", 4]
  484. ])->count();
  485. //type,0初审,1对数,2审定
  486. $report_status = $detail["type"] + 1;
  487. if ($num == 0) {
  488. $data = ['report_time' => time(), "report_status" => $report_status];
  489. } else {
  490. $data = ['report_time' => time()];
  491. }
  492. try {
  493. Db::name("cost_project")->where("id", $detail["project_id"])->update($data);
  494. } catch (DbException $e) {
  495. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  496. }
  497. try {
  498. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 2, "audit_time" => time()]);
  499. } catch (DbException $e) {
  500. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  501. }
  502. $people = $this->model->where('id', $id)->value("maker_id");
  503. if (empty($handle['company'])) {
  504. $handle['company'] = (array)$people;
  505. } else {
  506. $handle['company'] = array_merge($handle['company'], (array)$people);
  507. }
  508. $this->Pushmessage->pushMessage($detail["project_id"], $handle['financial'], $handle['company']);
  509. } else {
  510. $param['audit_time'] = time();
  511. $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]);
  512. add_log('edit', $param['id'], $param);
  513. $id = $param['id'];
  514. unset($param["id"]);
  515. $detail = ProjectReport::where("id", $param["else_id"])->find();
  516. $num = $this->model->where([
  517. ["project_id", "=", $detail["project_id"],
  518. ["type", ">", $detail["type"]]],
  519. ["status", ">", 1],
  520. ["status", "<>", 2],
  521. ["status", "<", 4]
  522. ])->count();
  523. //type,0初审,1对数,2审定
  524. $report_status = $detail["type"] + 1;
  525. if ($num == 0) {
  526. $data = ['report_time' => time(), "report_status" => $report_status];
  527. } else {
  528. $data = ['report_time' => time()];
  529. }
  530. $type_status = $detail["status"];
  531. if ($type_status == 0) {
  532. ProjectReport::where("id", $param["else_id"])->update(["status" => 1, "update_time" => time()]);
  533. $this->CostModel->where('id', $param['project_id'])->strict(false)->update($data);
  534. } elseif ($type_status == 3) {
  535. ProjectReport::where("id", $param["else_id"])->update(["status" => 4, "update_time" => time()]);
  536. }
  537. $people = $this->Auditmodel->where('id', $id)->value("sponsor_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($param['project_id'], $handle['financial'], $handle['company']);
  544. add_project_log('审批通过', $param['project_id'], "报告审批通过");
  545. }
  546. return to_assign(0, "操作成功");
  547. }
  548. /**
  549. * 财评
  550. * 不同意-报告
  551. */
  552. public function un_report()
  553. {
  554. $param = get_params();
  555. $handle = $this->Pushmessage->handleParam($param);
  556. $param = $handle['param'];
  557. if (!isset($param["type"])) {
  558. $id = isset($param['id']) ? $param['id'] : 0;
  559. $this->model->where("id", $id)->update(["status" => 2]);
  560. try {
  561. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"]]);
  562. } catch (DbException $e) {
  563. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  564. }
  565. $people = $this->model->where('id', $id)->value("maker_id");
  566. if (empty($handle['company'])) {
  567. $handle['company'] = (array)$people;
  568. } else {
  569. $handle['company'] = array_merge($handle['company'], (array)$people);
  570. }
  571. $project_id = $this->model->where("id", $id)->value("project_id");
  572. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  573. } else {
  574. $param = get_params();
  575. $handle = $this->Pushmessage->handleParam($param);
  576. $param = $handle['param'];
  577. try {
  578. $param['audit_time'] = time();
  579. $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  580. $id = $param['id'];
  581. unset($param["id"]);
  582. $type_status = Db::name("contact")->where("id", $param["else_id"])->value("status");
  583. if ($type_status == 0) {
  584. //新建
  585. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 2, "update_time" => time()]);
  586. } elseif ($type_status == 3) {
  587. //删除
  588. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 5, "update_time" => time()]);
  589. }
  590. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  591. if (empty($handle['company'])) {
  592. $handle['company'] = (array)$people;
  593. } else {
  594. $handle['company'] = array_merge($handle['company'], (array)$people);
  595. }
  596. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  597. } catch (\Exception $e) {
  598. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  599. }
  600. }
  601. return to_assign(0, "操作成功");
  602. }
  603. /**
  604. * 业主 (未修改)
  605. * 不同意-报告
  606. */
  607. public function proprietor_un_report()
  608. {
  609. $param = get_params();
  610. $handle = $this->Pushmessage->handleParam($param);
  611. $param = $handle['param'];
  612. if (!isset($param["type"])) {
  613. $id = isset($param['id']) ? $param['id'] : 0;
  614. $this->model->where("id", $id)->update(["status" => 2]);
  615. try {
  616. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"]]);
  617. } catch (DbException $e) {
  618. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  619. }
  620. $people = $this->model->where('id', $id)->value("maker_id");
  621. if (empty($handle['company'])) {
  622. $handle['company'] = (array)$people;
  623. } else {
  624. $handle['company'] = array_merge($handle['company'], (array)$people);
  625. }
  626. $project_id = $this->model->where("id", $id)->value("project_id");
  627. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  628. } else {
  629. $param = get_params();
  630. $handle = $this->Pushmessage->handleParam($param);
  631. $param = $handle['param'];
  632. try {
  633. $param['audit_time'] = time();
  634. $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  635. $id = $param['id'];
  636. unset($param["id"]);
  637. $type_status = Db::name("contact")->where("id", $param["else_id"])->value("status");
  638. if ($type_status == 0) {
  639. //新建
  640. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 2, "update_time" => time()]);
  641. } elseif ($type_status == 3) {
  642. //删除
  643. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 5, "update_time" => time()]);
  644. }
  645. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  646. if (empty($handle['company'])) {
  647. $handle['company'] = (array)$people;
  648. } else {
  649. $handle['company'] = array_merge($handle['company'], (array)$people);
  650. }
  651. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  652. } catch (\Exception $e) {
  653. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  654. }
  655. }
  656. return to_assign(0, "操作成功");
  657. }
  658. /**
  659. * 财评
  660. * 同意-删除
  661. */
  662. public function agree_delete()
  663. {
  664. $param = get_params();
  665. $handle = $this->Pushmessage->handleParam($param);
  666. $param = $handle['param'];
  667. if (!isset($param["type"])) {
  668. $id = isset($param['id']) ? $param['id'] : 0;
  669. $this->model->where("id", $id)->update(["status" => 4]);
  670. $detail = $this->model->where("id", $id)->find();
  671. //type,0初审,1对数,2审定
  672. $num = $this->model->where([
  673. ["project_id", "=", $detail["project_id"],
  674. ["type", ">=", $detail["type"]]],
  675. ["status", ">", 1],
  676. ["status", "<>", 2],
  677. ["status", "<", 4]
  678. ])->count();
  679. //type,0初审,1对数,2审定
  680. $report_status = $detail["type"];
  681. if ($num == 0) {
  682. $data = ['report_time' => time(), "report_status" => $report_status];
  683. } else {
  684. $data = ['report_time' => time()];
  685. }
  686. try {
  687. Db::name("cost_project")->where("id", $detail["project_id"])->update($data);
  688. } catch (DbException $e) {
  689. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  690. }
  691. try {
  692. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 2]);
  693. } catch (DbException $e) {
  694. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  695. }
  696. $people = $this->model->where('id', $id)->value("maker_id");
  697. if (empty($handle['company'])) {
  698. $handle['company'] = (array)$people;
  699. } else {
  700. $handle['company'] = array_merge($handle['company'], (array)$people);
  701. }
  702. $project_id = $this->model->where("id", $id)->value("project_id");
  703. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  704. } else {
  705. $param['audit_time'] = time();
  706. $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]);
  707. $id = $param['id'];
  708. unset($param["id"]);
  709. $detail = ProjectReport::where("id", $param["else_id"])->find();
  710. $num = $this->model->where([
  711. ["project_id", "=", $detail["project_id"],
  712. ["type", ">=", $detail["type"]]],
  713. ["status", ">", 1],
  714. ["status", "<>", 2],
  715. ["status", "<", 4]
  716. ])->count();
  717. //type,0初审,1对数,2审定
  718. $report_status = $detail["type"];
  719. if ($num == 0) {
  720. $data = ['report_time' => time(), "report_status" => $report_status];
  721. } else {
  722. $data = ['report_time' => time()];
  723. }
  724. $type_status = $detail["status"];
  725. if ($type_status == 0) {
  726. ProjectReport::where("id", $param["else_id"])->update(["status" => 1, "update_time" => time()]);
  727. $this->CostModel->where('id', $param['project_id'])->strict(false)->update($data);
  728. } elseif ($type_status == 3) {
  729. ProjectReport::where("id", $param["else_id"])->update(["status" => 4, "update_time" => time()]);
  730. Db::name("cost_project")->where("id", $detail["project_id"])->update(["report_status" => $report_status]);
  731. }
  732. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  733. if (empty($handle['company'])) {
  734. $handle['company'] = (array)$people;
  735. } else {
  736. $handle['company'] = array_merge($handle['company'], (array)$people);
  737. }
  738. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  739. add_project_log('审批通过', $param['project_id'], "报告删除审批通过");
  740. }
  741. return to_assign(0, "操作成功");
  742. }
  743. /**
  744. * 业主 (未修改)
  745. * 同意-删除
  746. */
  747. public function proprietor_agree_delete()
  748. {
  749. $param = get_params();
  750. $handle = $this->Pushmessage->handleParam($param);
  751. $param = $handle['param'];
  752. if (!isset($param["type"])) {
  753. $id = isset($param['id']) ? $param['id'] : 0;
  754. $this->model->where("id", $id)->update(["status" => 4]);
  755. $detail = $this->model->where("id", $id)->find();
  756. //type,0初审,1对数,2审定
  757. $num = $this->model->where([
  758. ["project_id", "=", $detail["project_id"],
  759. ["type", ">=", $detail["type"]]],
  760. ["status", ">", 1],
  761. ["status", "<>", 2],
  762. ["status", "<", 4]
  763. ])->count();
  764. //type,0初审,1对数,2审定
  765. $report_status = $detail["type"];
  766. if ($num == 0) {
  767. $data = ['report_time' => time(), "report_status" => $report_status];
  768. } else {
  769. $data = ['report_time' => time()];
  770. }
  771. try {
  772. Db::name("cost_project")->where("id", $detail["project_id"])->update($data);
  773. } catch (DbException $e) {
  774. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  775. }
  776. try {
  777. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 2]);
  778. } catch (DbException $e) {
  779. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  780. }
  781. $people = $this->model->where('id', $id)->value("maker_id");
  782. if (empty($handle['company'])) {
  783. $handle['company'] = (array)$people;
  784. } else {
  785. $handle['company'] = array_merge($handle['company'], (array)$people);
  786. }
  787. $project_id = $this->model->where("id", $id)->value("project_id");
  788. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  789. } else {
  790. $param['audit_time'] = time();
  791. $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]);
  792. $id = $param['id'];
  793. unset($param["id"]);
  794. $detail = ProjectReport::where("id", $param["else_id"])->find();
  795. $num = $this->model->where([
  796. ["project_id", "=", $detail["project_id"],
  797. ["type", ">=", $detail["type"]]],
  798. ["status", ">", 1],
  799. ["status", "<>", 2],
  800. ["status", "<", 4]
  801. ])->count();
  802. //type,0初审,1对数,2审定
  803. $report_status = $detail["type"];
  804. if ($num == 0) {
  805. $data = ['report_time' => time(), "report_status" => $report_status];
  806. } else {
  807. $data = ['report_time' => time()];
  808. }
  809. $type_status = $detail["status"];
  810. if ($type_status == 0) {
  811. ProjectReport::where("id", $param["else_id"])->update(["status" => 1, "update_time" => time()]);
  812. $this->CostModel->where('id', $param['project_id'])->strict(false)->update($data);
  813. } elseif ($type_status == 3) {
  814. ProjectReport::where("id", $param["else_id"])->update(["status" => 4, "update_time" => time()]);
  815. Db::name("cost_project")->where("id", $detail["project_id"])->update(["report_status" => $report_status]);
  816. }
  817. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  818. if (empty($handle['company'])) {
  819. $handle['company'] = (array)$people;
  820. } else {
  821. $handle['company'] = array_merge($handle['company'], (array)$people);
  822. }
  823. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  824. add_project_log('审批通过', $param['project_id'], "报告删除审批通过");
  825. }
  826. return to_assign(0, "操作成功");
  827. }
  828. /**
  829. * 财评
  830. * 不同意-删除
  831. */
  832. public function un_delete()
  833. {
  834. $param = get_params();
  835. $handle = $this->Pushmessage->handleParam($param);
  836. $param = $handle['param'];
  837. if (!isset($param["type"])) {
  838. $id = isset($param['id']) ? $param['id'] : 0;
  839. $this->model->where("id", $id)->update(["status" => 5]);
  840. try {
  841. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"]]);
  842. } catch (DbException $e) {
  843. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  844. }
  845. $people = $this->model->where('id', $id)->value("maker_id");
  846. if (empty($handle['company'])) {
  847. $handle['company'] = (array)$people;
  848. } else {
  849. $handle['company'] = array_merge($handle['company'], (array)$people);
  850. }
  851. $project_id = $this->model->where("id", $id)->value("project_id");
  852. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  853. } else {
  854. $param = get_params();
  855. $handle = $this->Pushmessage->handleParam($param);
  856. $param = $handle['param'];
  857. try {
  858. $param['audit_time'] = time();
  859. $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  860. $id = $param['id'];
  861. unset($param["id"]);
  862. $type_status = Db::name("contact")->where("id", $param["else_id"])->value("status");
  863. if ($type_status == 0) {
  864. //新建
  865. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 2, "update_time" => time()]);
  866. } elseif ($type_status == 3) {
  867. //删除
  868. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 5, "update_time" => time()]);
  869. }
  870. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  871. if (empty($handle['company'])) {
  872. $handle['company'] = (array)$people;
  873. } else {
  874. $handle['company'] = array_merge($handle['company'], (array)$people);
  875. }
  876. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  877. } catch (\Exception $e) {
  878. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  879. }
  880. }
  881. return to_assign(0, "操作成功");
  882. }
  883. /**
  884. * 业主 (未修改)
  885. * 不同意-删除
  886. */
  887. public function proprietor_un_delete()
  888. {
  889. $param = get_params();
  890. $handle = $this->Pushmessage->handleParam($param);
  891. $param = $handle['param'];
  892. if (!isset($param["type"])) {
  893. $id = isset($param['id']) ? $param['id'] : 0;
  894. $this->model->where("id", $id)->update(["status" => 5]);
  895. try {
  896. Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"]]);
  897. } catch (DbException $e) {
  898. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  899. }
  900. $people = $this->model->where('id', $id)->value("maker_id");
  901. if (empty($handle['company'])) {
  902. $handle['company'] = (array)$people;
  903. } else {
  904. $handle['company'] = array_merge($handle['company'], (array)$people);
  905. }
  906. $project_id = $this->model->where("id", $id)->value("project_id");
  907. $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']);
  908. } else {
  909. $param = get_params();
  910. $handle = $this->Pushmessage->handleParam($param);
  911. $param = $handle['param'];
  912. try {
  913. $param['audit_time'] = time();
  914. $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]);
  915. $id = $param['id'];
  916. unset($param["id"]);
  917. $type_status = Db::name("contact")->where("id", $param["else_id"])->value("status");
  918. if ($type_status == 0) {
  919. //新建
  920. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 2, "update_time" => time()]);
  921. } elseif ($type_status == 3) {
  922. //删除
  923. Db::name("contact")->where("id", $param["else_id"])->update(["status" => 5, "update_time" => time()]);
  924. }
  925. $people = $this->Auditmodel->where('id', $id)->value("sponsor_id");
  926. if (empty($handle['company'])) {
  927. $handle['company'] = (array)$people;
  928. } else {
  929. $handle['company'] = array_merge($handle['company'], (array)$people);
  930. }
  931. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']);
  932. } catch (\Exception $e) {
  933. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  934. }
  935. }
  936. return to_assign(0, "操作成功");
  937. }
  938. /**
  939. * 报告附件上传
  940. */
  941. public function add_file_company()
  942. {
  943. $param = get_params();
  944. // $param['create_time'] = time();
  945. $param['maker_id'] = $this->uid;
  946. $file_array = Db::name('file')
  947. ->field("f.id,f.name,f.filesize,f.filepath,f.fileext,f.admin_id,f.create_time,a.nickname as admin_name")
  948. ->alias("f")
  949. // ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  950. ->join('Admin a', 'f.admin_id = a.id', 'LEFT')
  951. ->order('f.create_time desc')
  952. ->where(array('f.id' => $param["file"]))
  953. ->select()->toArray();
  954. // ->find();
  955. View::assign("file_array", $file_array);
  956. return json($file_array);
  957. }
  958. /**
  959. * 查看审批进度
  960. */
  961. public function progress()
  962. {
  963. $param = get_params();
  964. $id = isset($param['id']) ? $param['id'] : 0;
  965. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  966. $order = empty($param['order']) ? 'id desc' : $param['order'];
  967. $list = $this->Auditmodel->alias('a')->join("cost_project c", "a.project_id=c.id", 'left')
  968. ->field("a.*,c.project_status,c.sent_review_amount,c.engineering_type,c.review_unit_name")->where('else_id', $id)->order('create_time', "sec")
  969. ->select()
  970. ->each(function ($item) {
  971. switch ($item["audit_type"]) {
  972. case 4:
  973. $item->else_name = "报告一级审核";
  974. break;
  975. case 5:
  976. $item->else_name = "报告二级审核";
  977. break;
  978. case 6:
  979. $item->else_name = "报告三级审核";
  980. break;
  981. }
  982. });
  983. View::assign('list', $list);
  984. return view();
  985. }
  986. }