Contact.php 41 KB

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