Feedback.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\admin\controller\shopro;
  3. use think\Db;
  4. use app\admin\model\shopro\Feedback as FeedbackModel;
  5. class Feedback extends Common
  6. {
  7. protected $model = null;
  8. public function _initialize()
  9. {
  10. parent::_initialize();
  11. $this->model = new FeedbackModel();
  12. }
  13. /**
  14. * 查看
  15. *
  16. * @return Response
  17. */
  18. public function index()
  19. {
  20. if (!$this->request->isAjax()) {
  21. return $this->view->fetch();
  22. }
  23. $feedbacks = $this->model->sheepFilter()->with('user')->paginate($this->request->param('list_rows', 10));
  24. $this->success('获取成功', null, $feedbacks);
  25. }
  26. /**
  27. * 详情
  28. *
  29. * @param $id
  30. * @return \think\Response
  31. */
  32. public function detail($id)
  33. {
  34. if (!$this->request->isAjax()) {
  35. return $this->view->fetch();
  36. }
  37. $detail = $this->model->with('user')->where('id', $id)->find();
  38. if (!$detail) {
  39. $this->error(__('No Results were found'));
  40. }
  41. $this->success('获取成功', null, $detail);
  42. }
  43. /**
  44. * 编辑(支持批量)
  45. */
  46. public function edit($id = null)
  47. {
  48. $params = $this->request->only(['status', 'remark']);
  49. $list = $this->model->where('id', 'in', $id)->select();
  50. $result = Db::transaction(function () use ($list, $params) {
  51. $count = 0;
  52. foreach ($list as $item) {
  53. $count += $item->save($params);
  54. }
  55. return $count;
  56. });
  57. if ($result) {
  58. $this->success('更新成功', null, $result);
  59. } else {
  60. $this->error('更新失败,未改变任何记录');
  61. }
  62. }
  63. /**
  64. * 删除优惠券
  65. *
  66. * @param string $id 要删除的意见反馈
  67. * @return void
  68. */
  69. public function delete($id)
  70. {
  71. if (empty($id)) {
  72. $this->error(__('Parameter %s can not be empty', 'id'));
  73. }
  74. $id = explode(',', $id);
  75. $list = $this->model->where('id', 'in', $id)->select();
  76. $result = Db::transaction(function () use ($list) {
  77. $count = 0;
  78. foreach ($list as $item) {
  79. $count += $item->delete();
  80. }
  81. return $count;
  82. });
  83. if ($result) {
  84. $this->success('删除成功', null, $result);
  85. } else {
  86. $this->error(__('No rows were deleted'));
  87. }
  88. }
  89. }