Remind.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\admin\controller\qingdong\general;
  3. use addons\qingdong\model\Staff;
  4. use app\admin\controller\qingdong\Base;
  5. use addons\qingdong\model\Field;
  6. use think\Db;
  7. use think\Exception;
  8. /**
  9. * 提醒人管理
  10. */
  11. class Remind extends Base {
  12. protected $relationSearch = true;
  13. /**
  14. * @var \addons\qingdong\model\Remind
  15. */
  16. protected $model = null;
  17. public function _initialize() {
  18. parent::_initialize();
  19. $this->model =new \addons\qingdong\model\Remind();
  20. }
  21. /**
  22. * 查看
  23. */
  24. public function index() {
  25. //设置过滤方法
  26. $this->request->filter(['strip_tags', 'trim']);
  27. if ($this->request->isAjax()) {
  28. $reminds = $this->model->where([])->select();
  29. $reminds = collection($reminds)->toArray();
  30. $result = array("total" => count($reminds), "rows" => $reminds);
  31. return json($result);
  32. }
  33. return $this->view->fetch();
  34. }
  35. /**
  36. * 添加
  37. */
  38. public function add() {
  39. if ($this->request->isAjax()) {
  40. $data = $this->request->post('row/a');
  41. $reminds = $this->model->where(array('type'=>$data['type']))->find();
  42. if($reminds){
  43. $this->error('此类型已经存在,请前去修改');
  44. }
  45. $result = $this->model->save($data);
  46. if (!$result) {
  47. $this->error('提交失败');
  48. }
  49. $this->success('提交成功');
  50. }
  51. return $this->view->fetch();
  52. }
  53. /**
  54. * 修改
  55. */
  56. public function edit($ids = null) {
  57. $map['id'] = $ids;
  58. if ($this->request->isAjax()) {
  59. $data = $this->request->post('row/a');
  60. $reminds = $this->model->where(array('type'=>$data['type'],'id'=>array('neq',$ids)))->find();
  61. if($reminds){
  62. $this->error('此类型已经存在,请前去修改');
  63. }
  64. $result = $this->model->save($data, $map);
  65. if (!$result) {
  66. $this->error('修改失败');
  67. }
  68. $this->success('修改成功');
  69. }
  70. $data = $this->model->where($map)->find();
  71. $this->view->assign("row", $data);
  72. return $this->view->fetch();
  73. }
  74. /**
  75. * 获取客户列表
  76. */
  77. public function getstaff()
  78. {
  79. $pageSize = input('pageSize');
  80. $pageNumber = input('pageNumber');
  81. $where = [];
  82. if ($keyValue = $this->request->request("keyValue")) {
  83. $where['id'] = ['in',explode(',',$keyValue)];
  84. }
  85. $name = input('name');
  86. if (!empty($name)) {
  87. $where['name'] = ['like', '%' . $name . '%'];
  88. }
  89. $customer = Staff::where($where)->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]);
  90. return json(['list' => $customer->items(), 'total' => $customer->total()]);
  91. }
  92. }