| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace app\admin\controller\massager;
- use app\api\model\system\Message;
- use app\common\controller\Backend;
- /**
- * 助教评论
- *
- * @icon fa fa-circle-o
- */
- class Comment extends Backend
- {
- /**
- * Comment模型对象
- * @var \app\admin\model\massager\Comment
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\massager\Comment;
- $this->view->assign("statusList", $this->model->getStatusList());
- $this->view->assign("allegedlyStatusList", $this->model->getAllegedlyStatusList());
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
- * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- protected $noNeedRight = ["check"];
- private function fetchWhere()
- {
- $admin = $this->auth->getUserInfo();
- if (!$admin)
- $this->error("error");
- $p_where = [];
- if (\E_ADMIN_TYPE::Store === $admin["type"]) {
- array_push($p_where, ["massager.store_id", "=", $admin["store_id"]]);
- } else if (\E_ADMIN_TYPE::Agency === $admin["type"]) {
- array_push($p_where, ["massager.city_code", "in", is_null($admin["city_codes"]) ? [] : explode(",", $admin["city_codes"])]);
- }
- return $p_where;
- }
- /**
- * 查看
- */
- public function index()
- {
- //当前是否为关联查询
- $this->relationSearch = true;
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- $c_where = $this->fetchWhere();
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->c_selectpage($c_where);
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $query = $this->model
- ->with(['massager', 'user'])
- ->where($where);
- foreach ($c_where as $item) {
- $query->where($item[0], $item[1], $item[2]);
- }
- $list = $query
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $row) {
- $row->visible(['id', 'is_anonymity', 'tags', 'star', 'content', 'status', 'negative', 'allegedly', 'allegedly_status', 'allegedly_text', 'updatetime']);
- $row->visible(['massager']);
- $row->getRelation('massager')->visible(['name']);
- $row->visible(['user']);
- $row->getRelation('user')->visible(['nickname']);
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
- public function check($id = null, $check = null)
- {
- if (!$id || !$check)
- $this->error("参数错误!");
- $comment = $this->model->where([
- "id" => $id,
- "allegedly" => 1,
- "allegedly_status" => \E_BASE_STATUS::Default,
- ])->find();
- if (!$comment)
- $this->error("申诉记录不存在!");
- $is_pass = $check === "pass";
- $this->model->update([
- "updatetime" => time(),
- "negative" => (int)$is_pass,
- "allegedly_status" => $check
- ], ["id" => $id]);
- if ($is_pass) {
- (new \app\api\model\massager\Massager())->where("id", $comment["massager_id"])->setDec("negative_count");
- }
- $total_count = $this->model->where([
- 'massager_id' => $comment["massager_id"],
- "status" => \E_BASE_STATUS::Normal
- ])->count();
- $gte_3_count = $this->model
- ->where([
- 'massager_id' => $comment["massager_id"],
- "negative" => 1,
- "status" => \E_BASE_STATUS::Normal
- ])
- ->count();
- $praise_rate = 100;
- if ($total_count > 0 && $gte_3_count > 0)
- $praise_rate = fixed2Float((($gte_3_count / $total_count)) * 100);
- (new \app\admin\model\Massager())->update([
- "updatetime" => time(),
- "praise_rate" => $praise_rate,
- ], ["id" => $id]);
- Message::sendSystemMessage(
- \E_IDENTITY_TYPE::Massager,
- ["to_massager_id" => $id],
- "助教审核",
- "您的异地签证申请已被管理员" . ($is_pass ? "通过!" : "拒绝!")
- );
- $this->success($is_pass ? "审核通过!" : "审核驳回!");
- }
- }
|