DinnerWechat.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\User;
  4. use think\App;
  5. use think\Db;
  6. class DinnerWechat extends Auth
  7. {
  8. public function __construct(App $app = null) {
  9. parent::__construct($app);
  10. $this->model= new \app\common\model\DinnerWechat();
  11. $this->table= $this->model->table;
  12. }
  13. public function index(){
  14. if(request()->isAjax()){
  15. //分页参数
  16. $length = input('rows',10,'intval'); //每页条数
  17. $page = input('page',1,'intval'); //第几页
  18. $start = ($page - 1) * $length; //分页开始位置
  19. //排序
  20. $sortRow = input('sidx','id','trim'); //排序列
  21. $sort = input('sord','desc','trim'); //排序方式
  22. $order = 'a.id desc';
  23. $title = input('title','','trim');
  24. if($title){
  25. $map[] = ['o.name','like','%'.$title.'%'];
  26. }
  27. $map= empty($map) ? true: $map;
  28. //数据查询
  29. $lists = Db::name('dinner_wechat')
  30. ->alias('a')
  31. ->join('org o','a.org_id = o.id')
  32. ->field('a.*,o.name')
  33. ->where($map)
  34. ->limit($start,$length)
  35. ->order($order)
  36. ->select();
  37. //数据返回
  38. $totalCount = Db::name('dinner_wechat')
  39. ->alias('a')
  40. ->join('org o','a.org_id = o.id')
  41. ->where($map)->count();
  42. $totalPage = ceil($totalCount/$length);
  43. $result['page'] = $page;
  44. $result['total'] = $totalPage;
  45. $result['records'] = $totalCount;
  46. $result['rows'] = $lists;
  47. return json($result);
  48. }else{
  49. return $this->fetch();
  50. }
  51. }
  52. public function index2(){
  53. $map[] = ['org_id','=',$this->orgId];
  54. $info = Db::name('dinner_wechat')
  55. ->where($map)
  56. ->find();
  57. $this->assign('info',$info);
  58. return $this->fetch();
  59. }
  60. /**
  61. * 新增/编辑
  62. */
  63. // public function add($id=0){
  64. // if(request()->isPost()){
  65. // $res = $this->model->updates();
  66. // if($res){
  67. // $this->success('操作成功',url('index'));
  68. // }else{
  69. // $this->error($this->model->getError());
  70. // }
  71. // }
  72. // }
  73. public function add($id=0){
  74. if(request()->isPost()){
  75. $res = $this->model->updates();
  76. if($res){
  77. $this->success('操作成功',url('index'));
  78. }else{
  79. $this->error($this->model->getError());
  80. }
  81. }else{
  82. $meta_title = '新增配置';
  83. if($id){
  84. $info = Db::name('dinner_wechat')->where('id',$id)->find();
  85. $this->assign('info',$info);
  86. $meta_title = '编辑配置';
  87. }
  88. $this->assign('meta_title',$meta_title);
  89. $orgs = Db::name('org')->where('del',0)->where('type',2)->field('id,name as title')->select();
  90. $this->assign('orgs',$orgs);
  91. return $this->fetch();
  92. }
  93. }
  94. /**
  95. * 删除记录
  96. * @param int $id
  97. */
  98. public function del($id=0){
  99. $info = Db::name('dinner_wechat')->where('id',$id)->find();
  100. if(!$info){
  101. $this->error('该记录不存在');
  102. }
  103. $res = Db::name('dinner_wechat')->delete($id);
  104. if($res){
  105. $this->success('删除成功');
  106. }else{
  107. $this->error('删除失败');
  108. }
  109. }
  110. }