Contact.php 43 KB

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