Record.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\admin\controller\project;
  4. use app\admin\BaseController;
  5. use app\admin\model\ProjectRecord;
  6. use think\exception\ValidateException;
  7. use HTMLPurifier;
  8. use HTMLPurifier_Config;
  9. use think\facade\Db;
  10. use think\facade\View;
  11. class Record extends BaseController
  12. {
  13. /**
  14. * 构造函数
  15. */
  16. public function __construct()
  17. {
  18. $this->model = new ProjectRecord();
  19. $this->uid = get_login_admin('id');
  20. }
  21. /**
  22. * 财评数据列表
  23. */
  24. public function cplist()
  25. {
  26. if (request()->isAjax()) {
  27. $param = get_params();
  28. $where = [
  29. ["cp_project_record.delete_time", "=", 0],
  30. ["project_id", "=", $param["project_id"]],
  31. ["maker_id","=",$this->uid]
  32. ];
  33. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  34. $order = empty($param['order']) ? 'a.id desc' : $param['order'];
  35. $list = $this->model->where($where)
  36. ->field('a.*,u.nickname as admin_name')
  37. ->alias('a')
  38. ->join('Admin u', 'a.maker_id = u.id', "left")
  39. ->order($order)
  40. ->paginate($rows, false, ['query' => $param])
  41. ->each(function ($item, $key) {
  42. });
  43. // halt($list);
  44. return table_assign(0, '', $list);
  45. }
  46. }
  47. /**
  48. * 公司数据列表
  49. */
  50. public function gslist()
  51. {
  52. if (request()->isAjax()) {
  53. $param = get_params();
  54. $where = [
  55. ["cp_project_record.delete_time", "=", 0],
  56. ["project_id", "=", $param["project_id"]],
  57. ];
  58. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  59. $order = empty($param['order']) ? 'a.id desc' : $param['order'];
  60. $list = $this->model->where($where)
  61. ->field('a.*,u.nickname as admin_name,u.unit_name')
  62. ->alias('a')
  63. ->join('Admin u', 'a.maker_id = u.id', "left")
  64. ->order($order)
  65. ->paginate($rows, false, ['query' => $param])
  66. ->each(function ($item, $key) {
  67. $item->type = Db::name("department")->where("id",$item->unit_name)->value("type");
  68. })->toArray();
  69. // halt($list);
  70. $list = $list["data"];
  71. for($i=0; $i<count($list); $i++){
  72. $a = $list[$i]["type"];
  73. if(!($a==2)){
  74. unset($list[$i]);
  75. }
  76. }
  77. $list = array_values($list);
  78. $list["data"] = $list;
  79. $list["total"] = count($list["data"]);
  80. // $list["data"] = $list;
  81. // halt($list);
  82. return table_assign(0, '', $list);
  83. }
  84. }
  85. /**
  86. * 业主数据列表
  87. */
  88. public function yzlist()
  89. {
  90. // if (request()->isAjax()) {
  91. $param = get_params();
  92. $where = [
  93. ["cp_project_record.delete_time", "=", 0],
  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->model->where($where)
  99. ->field('a.*,u.nickname as admin_name')
  100. ->alias('a')
  101. ->join('Admin u', 'a.maker_id = u.id', "left")
  102. ->order($order)
  103. ->paginate($rows, false, ['query' => $param])
  104. ->each(function ($item, $key) {
  105. });
  106. // halt($list);
  107. return table_assign(0, '', $list);
  108. // }
  109. }
  110. /**
  111. * 添加-财政局
  112. */
  113. public function add()
  114. {
  115. $param = get_params();
  116. if (request()->isAjax()) {
  117. if (isset($param['table-align'])) {
  118. unset($param['table-align']);
  119. }
  120. if (isset($param['content'])) {
  121. $param['md_content'] = '';
  122. }
  123. if (isset($param['docContent-html-code'])) {
  124. $param['content'] = $param['docContent-html-code'];
  125. $param['md_content'] = $param['docContent-markdown-doc'];
  126. unset($param['docContent-html-code']);
  127. unset($param['docContent-markdown-doc']);
  128. }
  129. // 创建HTMLPurifier配置对象
  130. $config = HTMLPurifier_Config::createDefault();
  131. $config->set('HTML.DefinitionID', 'html5-definitions');
  132. $config->set('HTML.DefinitionRev', 1);
  133. $config->set('HTML.ForbiddenAttributes', ['width', 'height']);
  134. //$config->set('HTML.Allowed', 'p,b,a[href],pre[class],code,blockquote,img[src],table,tr,th,td,ul,li,ol,dl,dt,dd');
  135. $config->set('HTML.ForbiddenElements', array('script'), true);//设置拒绝使用的tagname
  136. if ($def = $config->maybeGetRawHTMLDefinition()) {
  137. $def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
  138. 'src' => 'URI',
  139. 'type' => 'Text',
  140. 'poster' => 'URI',
  141. 'preload' => 'Enum#auto,metadata,none',
  142. 'controls' => 'Bool',
  143. ]);
  144. $def->addElement('source', 'Block', 'Flow', 'Common', [
  145. 'src' => 'URI',
  146. 'type' => 'Text',
  147. ]);
  148. }
  149. // 创建HTMLPurifier对象
  150. $purifier = new HTMLPurifier($config);
  151. //防止xss,过滤输入并输出结果
  152. //$param['content'] = '测试<script>alert(0);</script>';
  153. $param['content'] = $purifier->purify($param['content']);
  154. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  155. $param['project_id'] = $project_id;
  156. $param['maker_id'] = $this->uid;
  157. $content =strip_tags($param["content"]);
  158. $this->model->addRecord($param);
  159. add_project_log("新增工作记录", $project_id, $content, 3);
  160. } else {
  161. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  162. $project = Db::name("cost_project")->where("id",$project_id)->field('id,project_name')->find();
  163. //富文本类型
  164. View::assign('editor', get_system_config('other', 'editor'));
  165. //关联项目id
  166. View::assign('project', $project);
  167. View::assign('project_id', $project_id);
  168. return view();
  169. }
  170. }
  171. /**
  172. * 添加-公司
  173. */
  174. public function add_company()
  175. {
  176. $param = get_params();
  177. if (request()->isAjax()) {
  178. if (isset($param['table-align'])) {
  179. unset($param['table-align']);
  180. }
  181. if (isset($param['content'])) {
  182. $param['md_content'] = '';
  183. }
  184. if (isset($param['docContent-html-code'])) {
  185. $param['content'] = $param['docContent-html-code'];
  186. $param['md_content'] = $param['docContent-markdown-doc'];
  187. unset($param['docContent-html-code']);
  188. unset($param['docContent-markdown-doc']);
  189. }
  190. // 创建HTMLPurifier配置对象
  191. $config = HTMLPurifier_Config::createDefault();
  192. $config->set('HTML.DefinitionID', 'html5-definitions');
  193. $config->set('HTML.DefinitionRev', 1);
  194. $config->set('HTML.ForbiddenAttributes', ['width', 'height']);
  195. //$config->set('HTML.Allowed', 'p,b,a[href],pre[class],code,blockquote,img[src],table,tr,th,td,ul,li,ol,dl,dt,dd');
  196. $config->set('HTML.ForbiddenElements', array('script'), true);//设置拒绝使用的tagname
  197. if ($def = $config->maybeGetRawHTMLDefinition()) {
  198. $def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
  199. 'src' => 'URI',
  200. 'type' => 'Text',
  201. 'poster' => 'URI',
  202. 'preload' => 'Enum#auto,metadata,none',
  203. 'controls' => 'Bool',
  204. ]);
  205. $def->addElement('source', 'Block', 'Flow', 'Common', [
  206. 'src' => 'URI',
  207. 'type' => 'Text',
  208. ]);
  209. }
  210. // 创建HTMLPurifier对象
  211. $purifier = new HTMLPurifier($config);
  212. //防止xss,过滤输入并输出结果
  213. //$param['content'] = '测试<script>alert(0);</script>';
  214. $param['content'] = $purifier->purify($param['content']);
  215. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  216. $param['project_id'] = $project_id;
  217. $param['maker_id'] = $this->uid;
  218. $content =strip_tags($param["content"]);
  219. add_project_log("新增工作记录",$project_id,$content,3);
  220. $this->model->addRecord($param);
  221. } else {
  222. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  223. $project = Db::name("cost_project")->where("id",$project_id)->field('id,project_name')->find();
  224. //富文本类型
  225. View::assign('editor', get_system_config('other', 'editor'));
  226. //关联项目id
  227. View::assign('project', $project);
  228. View::assign('project_id', $project_id);
  229. return view('add_company');
  230. }
  231. }
  232. /**
  233. * 编辑-财政局
  234. */
  235. public function edit()
  236. {
  237. $param = get_params();
  238. if (request()->isAjax()) {
  239. if (isset($param['table-align'])) {
  240. unset($param['table-align']);
  241. }
  242. if (isset($param['content'])) {
  243. $param['md_content'] = '';
  244. }
  245. if (isset($param['docContent-html-code'])) {
  246. $param['content'] = $param['docContent-html-code'];
  247. $param['md_content'] = $param['docContent-markdown-doc'];
  248. unset($param['docContent-html-code']);
  249. unset($param['docContent-markdown-doc']);
  250. }
  251. // 创建HTMLPurifier配置对象
  252. $config = HTMLPurifier_Config::createDefault();
  253. $config->set('HTML.DefinitionID', 'html5-definitions');
  254. $config->set('HTML.DefinitionRev', 1);
  255. $config->set('HTML.ForbiddenAttributes', ['width', 'height']);
  256. //$config->set('HTML.Allowed', 'p,b,a[href],pre[class],code,blockquote,img[src],table,tr,th,td,ul,li,ol,dl,dt,dd');
  257. $config->set('HTML.ForbiddenElements', array('script'), true);//设置拒绝使用的tagname
  258. if ($def = $config->maybeGetRawHTMLDefinition()) {
  259. $def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
  260. 'src' => 'URI',
  261. 'type' => 'Text',
  262. 'poster' => 'URI',
  263. 'preload' => 'Enum#auto,metadata,none',
  264. 'controls' => 'Bool',
  265. ]);
  266. $def->addElement('source', 'Block', 'Flow', 'Common', [
  267. 'src' => 'URI',
  268. 'type' => 'Text',
  269. ]);
  270. }
  271. // 创建HTMLPurifier对象
  272. $purifier = new HTMLPurifier($config);
  273. //防止xss,过滤输入并输出结果
  274. //$param['content'] = '测试<script>alert(0);</script>';
  275. $param['content'] = $purifier->purify($param['content']);
  276. $this->model->editRecord($param);
  277. add_project_log('编辑工作记录', $param['project_id'], '编辑工作记录', 3);
  278. } else {
  279. $id = isset($param['id']) ? $param['id'] : 0;//记录id
  280. $project_id = $this->model->where('id',$id)->value("project_id");
  281. $project = Db::name("cost_project")->where("id",$project_id)->field('id,project_name')->find();
  282. $detail = $this->model->getRecordById($id);
  283. View::assign('editor', get_system_config('other', 'editor'));
  284. if (!empty($detail)) {
  285. if (!empty($article['md_content'])) {
  286. View::assign('editor', 1);
  287. }
  288. View::assign('id', $id);
  289. View::assign('project', $project);
  290. View::assign('detail', $detail);
  291. return view();
  292. } else {
  293. throw new \think\exception\HttpException(404, '找不到页面');
  294. }
  295. }
  296. }
  297. /**
  298. * 编辑-公司
  299. */
  300. public function edit_company()
  301. {
  302. $param = get_params();
  303. if (request()->isAjax()) {
  304. if (isset($param['table-align'])) {
  305. unset($param['table-align']);
  306. }
  307. if (isset($param['content'])) {
  308. $param['md_content'] = '';
  309. }
  310. if (isset($param['docContent-html-code'])) {
  311. $param['content'] = $param['docContent-html-code'];
  312. $param['md_content'] = $param['docContent-markdown-doc'];
  313. unset($param['docContent-html-code']);
  314. unset($param['docContent-markdown-doc']);
  315. }
  316. // 创建HTMLPurifier配置对象
  317. $config = HTMLPurifier_Config::createDefault();
  318. $config->set('HTML.DefinitionID', 'html5-definitions');
  319. $config->set('HTML.DefinitionRev', 1);
  320. $config->set('HTML.ForbiddenAttributes', ['width', 'height']);
  321. //$config->set('HTML.Allowed', 'p,b,a[href],pre[class],code,blockquote,img[src],table,tr,th,td,ul,li,ol,dl,dt,dd');
  322. $config->set('HTML.ForbiddenElements', array('script'), true);//设置拒绝使用的tagname
  323. if ($def = $config->maybeGetRawHTMLDefinition()) {
  324. $def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
  325. 'src' => 'URI',
  326. 'type' => 'Text',
  327. 'poster' => 'URI',
  328. 'preload' => 'Enum#auto,metadata,none',
  329. 'controls' => 'Bool',
  330. ]);
  331. $def->addElement('source', 'Block', 'Flow', 'Common', [
  332. 'src' => 'URI',
  333. 'type' => 'Text',
  334. ]);
  335. }
  336. // 创建HTMLPurifier对象
  337. $purifier = new HTMLPurifier($config);
  338. //防止xss,过滤输入并输出结果
  339. //$param['content'] = '测试<script>alert(0);</script>';
  340. $param['content'] = $purifier->purify($param['content']);
  341. $this->model->editRecord($param);
  342. // add_project_log('编辑工作记录', $param['project_id'], '新内容:'.$param['content']);
  343. add_project_log('编辑工作记录', $param['project_id'], '编辑工作记录', 3);
  344. } else {
  345. $id = isset($param['id']) ? $param['id'] : 0;//记录id
  346. $project_id = $this->model->where('id',$id)->value("project_id");
  347. $project = Db::name("cost_project")->where("id",$project_id)->field('id,project_name')->find();
  348. $detail = $this->model->getRecordById($id);
  349. View::assign('editor', get_system_config('other', 'editor'));
  350. if (!empty($detail)) {
  351. if (!empty($article['md_content'])) {
  352. View::assign('editor', 1);
  353. }
  354. View::assign('id', $id);
  355. View::assign('project', $project);
  356. View::assign('detail', $detail);
  357. return view();
  358. } else {
  359. throw new \think\exception\HttpException(404, '找不到页面');
  360. }
  361. }
  362. }
  363. /**
  364. * 查看信息-财政局
  365. */
  366. public function view()
  367. {
  368. $param = get_params();
  369. $id = isset($param['id']) ? $param['id'] : 0;
  370. $detail = (new ProjectRecord())->detail($id);
  371. if (empty($detail)) {
  372. if (empty($detail)) {
  373. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';exit;
  374. }
  375. } else {
  376. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  377. $detail["maker_name"] = $maker_name;
  378. View::assign('detail', $detail);
  379. return view();
  380. }
  381. }
  382. /**
  383. * 查看信息-公司
  384. */
  385. public function view_company()
  386. {
  387. $param = get_params();
  388. $id = isset($param['id']) ? $param['id'] : 0;
  389. $detail = (new ProjectRecord())->detail($id);
  390. if (empty($detail)) {
  391. if (empty($detail)) {
  392. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';exit;
  393. }
  394. } else {
  395. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  396. $detail["maker_name"] = $maker_name;
  397. View::assign('detail', $detail);
  398. return view('view');
  399. }
  400. }
  401. /**
  402. * 查看信息-业主
  403. */
  404. public function view_proprietor()
  405. {
  406. $param = get_params();
  407. $id = isset($param['id']) ? $param['id'] : 0;
  408. $detail = (new ProjectRecord())->detail($id);
  409. if (empty($detail)) {
  410. if (empty($detail)) {
  411. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';exit;
  412. }
  413. } else {
  414. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  415. $detail["maker_name"] = $maker_name;
  416. View::assign('detail', $detail);
  417. return view();
  418. }
  419. }
  420. /**
  421. * 删除-财政局
  422. */
  423. public function del()
  424. {
  425. $param = get_params();
  426. $id = isset($param['id']) ? $param['id'] : 0;
  427. $maker = $this->model->where("id",$id)->value("maker_id");
  428. if($this->uid == $maker){
  429. $type = isset($param['type']) ? $param['type'] : 0;
  430. $name = $this->model->where('id',$id)->value("content");
  431. $project_id = $this->model->where("id",$id)->value("project_id");
  432. $content = strip_tags($name);
  433. add_project_log("删除了工作记录",$project_id,$content,3);
  434. $this->model->delRecordById($id, $type);
  435. }else{
  436. return to_assign(1,"非创建人,不可删除");
  437. }
  438. }
  439. /**
  440. * 删除-公司
  441. */
  442. public function del_company()
  443. {
  444. $param = get_params();
  445. $id = isset($param['id']) ? $param['id'] : 0;
  446. $maker = $this->model->where("id",$id)->value("maker_id");
  447. if($this->uid == $maker){
  448. $type = isset($param['type']) ? $param['type'] : 0;
  449. $name = $this->model->where('id',$id)->value("content");
  450. $project_id = $this->model->where("id",$id)->value("project_id");
  451. $content = strip_tags($name);
  452. add_project_log("删除了工作记录", $project_id, $content, 3);
  453. $this->model->delRecordById($id, $type);
  454. }else{
  455. return to_assign(1,"非创建人,不可删除");
  456. }
  457. }
  458. }