alias('oc')->where(['oc.store_id' => $this->store_id, 'oc.is_delete' => OrderComment::IS_DELETE_FALSE, 'oc.mch_id' => 0]); $query ->leftJoin(['u' => User::tableName()], 'oc.user_id=u.id') ->leftJoin(['g' => Goods::tableName()], 'oc.goods_id=g.id') ->select('oc.created_at, oc.user_id as uid,oc.is_virtual,oc.virtual_user,oc.id,u.nickname,u.platform,u.avatar_url, oc.score,oc.content,oc.pic_list,g.name goods_name,g.cover_pic,oc.is_hide,oc.reply_content') ->orderBy('oc.created_at DESC'); $pagination = pagination_make($query); $list = $pagination['list']; foreach ($list as $key => &$value) { if ($value['is_virtual'] == 1) { $list[$key]['nickname'] = '(' . $value['virtual_user'] . ')'; } $value['score'] = intval($value['score']); $value['pic_list'] = json_decode($value['pic_list'], true); $value['created_at'] = date('m-d H:i', $value['created_at']); // TODO: 其他数据 } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list, 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'] ], ]; } /** * 回复消息 * @return array */ public function reply() { $query = OrderComment::find()->where(['id' => $this->id])->one(); if (!$query || empty($this->reply_content)) { return [ 'code' => 1, 'msg' => '参数错误', ]; } $query->reply_content = $this->reply_content; if ($query->save()) { return [ 'code' => 0, 'msg' => '回复成功', ]; } else { return [ 'code' => 1, 'msg' => '回复失败', ]; } } /** * 隐藏评论 * @return array */ public function hideStatus() { $order_comment = OrderComment::findOne([ 'store_id' => $this->store_id, 'id' => $this->id, ]); if ($order_comment) { $order_comment->is_hide = $this->status; $order_comment->save(); } return [ 'code' => 0, 'msg' => '操作成功', ]; } /** * 删除评论 * @return array */ public function deleteStatus() { $order_comment = OrderComment::findOne([ 'store_id' => $this->store_id, 'id' => $this->id, ]); if ($order_comment) { $order_comment->is_delete = $this->status; $order_comment->save(); } return [ 'code' => 0, 'msg' => '操作成功', ]; } }