You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Evaluate.php 3.6 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\admin\controller\unishop;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\Exception;
  6. use think\exception\PDOException;
  7. /**
  8. * 商品评价管理
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Evaluate extends Backend
  13. {
  14. /**
  15. * Multi方法可批量修改的字段
  16. */
  17. protected $multiFields = 'toptime';
  18. /**
  19. * Evaluate模型对象
  20. * @var \app\admin\model\unishop\Evaluate
  21. */
  22. protected $model = null;
  23. public function _initialize()
  24. {
  25. parent::_initialize();
  26. $this->model = new \app\admin\model\unishop\Evaluate;
  27. $this->view->assign("rateList", $this->model->getRateList());
  28. $this->view->assign("anonymousList", $this->model->getAnonymousList());
  29. }
  30. /**
  31. * 查看
  32. */
  33. public function index()
  34. {
  35. //设置过滤方法
  36. $this->request->filter(['strip_tags']);
  37. if ($this->request->isAjax()) {
  38. //如果发送的来源是Selectpage,则转发到Selectpage
  39. if ($this->request->request('keyField')) {
  40. return $this->selectpage();
  41. }
  42. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  43. $total = $this->model
  44. ->where($where)
  45. ->count();
  46. $list = $this->model
  47. ->with(['product'])
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->limit($offset, $limit)
  51. ->select();
  52. $list = collection($list)->toArray();
  53. $result = array("total" => $total, "rows" => $list);
  54. return json($result);
  55. }
  56. return $this->view->fetch();
  57. }
  58. /**
  59. * 批量更新
  60. */
  61. public function multi($ids = "")
  62. {
  63. $ids = $ids ? $ids : $this->request->param("ids");
  64. if ($ids) {
  65. if ($this->request->has('params')) {
  66. parse_str($this->request->post("params"), $values);
  67. $values = array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
  68. if ($values || $this->auth->isSuperAdmin()) {
  69. $adminIds = $this->getDataLimitAdminIds();
  70. if (is_array($adminIds)) {
  71. $this->model->where($this->dataLimitField, 'in', $adminIds);
  72. }
  73. $count = 0;
  74. Db::startTrans();
  75. try {
  76. $list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
  77. foreach ($list as $index => $item) {
  78. if ($values['toptime'] > 0) {
  79. $values['toptime'] = time();
  80. }
  81. $count += $item->allowField(true)->isUpdate(true)->save($values);
  82. }
  83. Db::commit();
  84. } catch (PDOException $e) {
  85. Db::rollback();
  86. $this->error($e->getMessage());
  87. } catch (Exception $e) {
  88. Db::rollback();
  89. $this->error($e->getMessage());
  90. }
  91. if ($count) {
  92. $this->success();
  93. } else {
  94. $this->error(__('No rows were updated'));
  95. }
  96. } else {
  97. $this->error(__('You have no permission'));
  98. }
  99. }
  100. }
  101. $this->error(__('Parameter %s can not be empty', 'ids'));
  102. }
  103. }