Zhengce.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\company\controller;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. /**
  6. * 政策
  7. */
  8. class Zhengce extends Apic
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['info'];
  12. protected $table = 'zhengce';
  13. public function index(){
  14. $list = Db::name($this->table)->field('content',true)->where('company_id',$this->auth->company_id)->order('id desc')->paginate();
  15. $total = $list->total();
  16. $list = $list->items();
  17. $list = list_domain_image($list,['image']);
  18. $rs = [
  19. 'list' => $list,
  20. 'total'=> $total,
  21. ];
  22. $this->success(1,$rs);
  23. }
  24. public function add(){
  25. $data = [
  26. 'title' => input('title',''),
  27. 'image' => input('image',''),
  28. 'content' => input('content','','htmlspecialchars_decode'),
  29. 'company_id' => $this->auth->company_id,
  30. 'createtime' => time(),
  31. 'updatetime' => time(),
  32. ];
  33. Db::name($this->table)->insertGetId($data);
  34. $this->success();
  35. }
  36. public function info(){
  37. $id = input('id',0);
  38. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  39. $info = info_domain_image($info,['image']);
  40. $this->success(1,$info);
  41. }
  42. public function edit(){
  43. $id = input('id',0);
  44. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  45. if(empty($info)){
  46. $this->error('没找到该信息,请刷新重试');
  47. }
  48. $data = [
  49. 'title' => input('title',''),
  50. 'image' => input('image',''),
  51. 'content' => input('content','','htmlspecialchars_decode'),
  52. 'updatetime' => time(),
  53. ];
  54. Db::name($this->table)->where('id',$id)->update($data);
  55. $this->success();
  56. }
  57. public function del(){
  58. $ids = input('ids','');
  59. $ids = explode(',',$ids);
  60. if (empty($ids)) {
  61. $this->error();
  62. }
  63. Db::name($this->table)->where('id','IN',$ids)->where('company_id',$this->auth->company_id)->delete();
  64. $this->success();
  65. }
  66. }