Comment.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace app\admin\controller\massager;
  3. use app\api\model\system\Message;
  4. use app\common\controller\Backend;
  5. /**
  6. * 助教评论
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Comment extends Backend
  11. {
  12. /**
  13. * Comment模型对象
  14. * @var \app\admin\model\massager\Comment
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\massager\Comment;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. $this->view->assign("allegedlyStatusList", $this->model->getAllegedlyStatusList());
  23. }
  24. /**
  25. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  26. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  27. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  28. */
  29. protected $noNeedRight = ["check"];
  30. private function fetchWhere()
  31. {
  32. $admin = $this->auth->getUserInfo();
  33. if (!$admin)
  34. $this->error("error");
  35. $p_where = [];
  36. if (\E_ADMIN_TYPE::Store === $admin["type"]) {
  37. array_push($p_where, ["massager.store_id", "=", $admin["store_id"]]);
  38. } else if (\E_ADMIN_TYPE::Agency === $admin["type"]) {
  39. array_push($p_where, ["massager.city_code", "in", is_null($admin["city_codes"]) ? [] : explode(",", $admin["city_codes"])]);
  40. }
  41. return $p_where;
  42. }
  43. /**
  44. * 查看
  45. */
  46. public function index()
  47. {
  48. //当前是否为关联查询
  49. $this->relationSearch = true;
  50. //设置过滤方法
  51. $this->request->filter(['strip_tags', 'trim']);
  52. $c_where = $this->fetchWhere();
  53. if ($this->request->isAjax()) {
  54. //如果发送的来源是Selectpage,则转发到Selectpage
  55. if ($this->request->request('keyField')) {
  56. return $this->c_selectpage($c_where);
  57. }
  58. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  59. $query = $this->model
  60. ->with(['massager', 'user'])
  61. ->where($where);
  62. foreach ($c_where as $item) {
  63. $query->where($item[0], $item[1], $item[2]);
  64. }
  65. $list = $query
  66. ->order($sort, $order)
  67. ->paginate($limit);
  68. foreach ($list as $row) {
  69. $row->visible(['id', 'is_anonymity', 'tags', 'star', 'content', 'status', 'negative', 'allegedly', 'allegedly_status', 'allegedly_text', 'updatetime']);
  70. $row->visible(['massager']);
  71. $row->getRelation('massager')->visible(['name']);
  72. $row->visible(['user']);
  73. $row->getRelation('user')->visible(['nickname']);
  74. }
  75. $result = array("total" => $list->total(), "rows" => $list->items());
  76. return json($result);
  77. }
  78. return $this->view->fetch();
  79. }
  80. public function check($id = null, $check = null)
  81. {
  82. if (!$id || !$check)
  83. $this->error("参数错误!");
  84. $comment = $this->model->where([
  85. "id" => $id,
  86. "allegedly" => 1,
  87. "allegedly_status" => \E_BASE_STATUS::Default,
  88. ])->find();
  89. if (!$comment)
  90. $this->error("申诉记录不存在!");
  91. $is_pass = $check === "pass";
  92. $this->model->update([
  93. "updatetime" => time(),
  94. "negative" => (int)$is_pass,
  95. "allegedly_status" => $check
  96. ], ["id" => $id]);
  97. if ($is_pass) {
  98. (new \app\api\model\massager\Massager())->where("id", $comment["massager_id"])->setDec("negative_count");
  99. }
  100. $total_count = $this->model->where([
  101. 'massager_id' => $comment["massager_id"],
  102. "status" => \E_BASE_STATUS::Normal
  103. ])->count();
  104. $gte_3_count = $this->model
  105. ->where([
  106. 'massager_id' => $comment["massager_id"],
  107. "negative" => 1,
  108. "status" => \E_BASE_STATUS::Normal
  109. ])
  110. ->count();
  111. $praise_rate = 100;
  112. if ($total_count > 0 && $gte_3_count > 0)
  113. $praise_rate = fixed2Float((($gte_3_count / $total_count)) * 100);
  114. (new \app\admin\model\Massager())->update([
  115. "updatetime" => time(),
  116. "praise_rate" => $praise_rate,
  117. ], ["id" => $id]);
  118. Message::sendSystemMessage(
  119. \E_IDENTITY_TYPE::Massager,
  120. ["to_massager_id" => $id],
  121. "助教审核",
  122. "您的异地签证申请已被管理员" . ($is_pass ? "通过!" : "拒绝!")
  123. );
  124. $this->success($is_pass ? "审核通过!" : "审核驳回!");
  125. }
  126. }