From.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\exception\PDOException;
  6. /**
  7. * 预约表单管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class From extends Backend
  12. {
  13. /**
  14. * From模型对象
  15. * @var \app\admin\model\From
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\From;
  22. }
  23. /**
  24. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  25. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  26. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  27. */
  28. /**
  29. * 查看
  30. */
  31. public function index()
  32. {
  33. $a=$this->request->input();
  34. //设置过滤方法
  35. $this->request->filter(['strip_tags']);
  36. if ($this->request->isAjax()) {
  37. //如果发送的来源是Selectpage,则转发到Selectpage
  38. if ($this->request->request('keyField')) {
  39. return $this->selectpage();
  40. }
  41. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  42. $total = $this->model
  43. ->where($where)
  44. ->where('status',1)
  45. ->order($sort, $order)
  46. ->count();
  47. $list = $this->model
  48. ->where($where)
  49. ->where('status',1)
  50. ->with('member')
  51. ->order($sort, $order)
  52. ->limit($offset, $limit)
  53. ->select();
  54. $list = collection($list)->toArray();
  55. $result = array("total" => $total, "rows" => $list);
  56. return json($result);
  57. }
  58. return $this->view->fetch();
  59. }
  60. /**
  61. * 删除
  62. */
  63. public function del($ids = "")
  64. {
  65. if ($ids) {
  66. $pk = $this->model->getPk();
  67. $adminIds = $this->getDataLimitAdminIds();
  68. if (is_array($adminIds)) {
  69. $this->model->where($this->dataLimitField, 'in', $adminIds);
  70. }
  71. $list = $this->model->where($pk, 'in', $ids)->select();
  72. $count = 0;
  73. Db::startTrans();
  74. try {
  75. foreach ($list as $k => $v) {
  76. $count += $v->save(['status'=>'0']);
  77. }
  78. Db::commit();
  79. } catch (PDOException $e) {
  80. Db::rollback();
  81. $this->error($e->getMessage());
  82. } catch (Exception $e) {
  83. Db::rollback();
  84. $this->error($e->getMessage());
  85. }
  86. if ($count) {
  87. $this->success();
  88. } else {
  89. $this->error(__('No rows were deleted'));
  90. }
  91. }
  92. $this->error(__('Parameter %s can not be empty', 'ids'));
  93. }
  94. }