1000], [['virtual_user'], 'string', 'max' => 255], [['created_at'], 'integer', 'max' => 2000000000], [['mch', 'mch_id'], 'safe'], ]; } /** * 获取评论列表 * @return array */ public function getComment() { $query = OrderComment::find()->alias('oc')->where(['oc.store_id' => $this->store_id, 'oc.is_delete' => OrderComment::IS_DELETE_FALSE]); $query ->leftJoin(['u' => User::tableName()], 'oc.user_id=u.id') ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding') ->leftJoin(['od' => OrderDetail::tableName()], 'oc.order_detail_id=od.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,od.goods_name,oc.is_hide,oc.reply_content, od.pic goods_pic, oc.goods_id, , oc.order_detail_id, oc.user_type, oc.user_name, oc.user_avatar ') ->orderBy('oc.created_at DESC')->groupBy('oc.id'); if (isset($this->mch) && $this->mch == 1) { if ($this->mch_id > 0) { $query->andWhere(['oc.mch_id' => $this->mch_id]); }else{ $query->andWhere(['>', 'oc.mch_id', 0]); } }else{ $query->andWhere(['oc.mch_id' => 0]); } $pagination = pagination_make($query); $list = $pagination['list']; foreach ($list as $key => &$value) { if (!$value['order_detail_id']) { $goods = Goods::findOne($value['goods_id']); $value['goods_name'] = $goods->name; $value['goods_pic'] = $goods->cover_pic; } $value['user_type'] = intval($value['user_type']); if ($value['user_type'] === OrderComment::USER_TYPE_CUSTOM) { $value['nickname'] = $value['user_name']; $value['avatar_url'] = $value['user_avatar']; } 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('Y-m-d H:i:s', $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' => '操作成功', ]; } /** * 增加评论 * @return array */ public function save() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $orderComment = new OrderComment(); $orderComment->store_id = $this->store_id; $orderComment->user_id = 0; $orderComment->order_id = 0; $orderComment->order_detail_id = 0; $orderComment->user_id = 0; $orderComment->is_delete = 0; $orderComment->created_at = $this->created_at; $orderComment->is_virtual = 1; $orderComment->pic_list = $this->pic_list; $orderComment->score = $this->score; $orderComment->created_at = $this->created_at; $orderComment->mch_id = $this->mch_id; $orderComment->goods_id = $this->goods_id; $orderComment->is_hide = $this->is_hide; $orderComment->content = $this->content; $orderComment->virtual_user = $this->virtual_user; $orderComment->virtual_avatar = $this->virtual_avatar; if ($orderComment->save()) { return [ 'code' => 0, 'msg' => '保存成功', ]; } else { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } } /** * 增加评论后台添加 * @return array */ public function commentSave() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $saas_user = SaasUser::findOne($this->saas_user_id); if ($saas_user) { $user = User::findOne(['binding' => $saas_user->mobile]); } if (intval($this->user_type) === OrderComment::USER_TYPE_USER) { if (empty($user)) { return [ 'code' => 1, 'msg' => '用户信息不存在', ]; } } if (intval($this->user_type) === OrderComment::USER_TYPE_CUSTOM) { if (empty($this->user_name) || empty($this->user_avatar)) { return [ 'code' => 1, 'msg' => '用户信息错误', ]; } } $orderComment = new OrderComment(); $orderComment->store_id = $this->store_id; $orderComment->user_id = $user->id ?? 0; $orderComment->saas_id = $this->saas_user_id; $orderComment->order_id = 0; $orderComment->order_detail_id = 0; $orderComment->is_delete = 0; $orderComment->created_at = $this->created_at; $orderComment->is_virtual = 0; $orderComment->pic_list = $this->pic_list; $orderComment->score = $this->score; $orderComment->created_at = $this->created_at; $orderComment->mch_id = 0; $orderComment->goods_id = $this->goods_id; $orderComment->is_hide = $this->is_hide; $orderComment->content = $this->content; $orderComment->virtual_user = $this->virtual_user; $orderComment->virtual_avatar = $this->virtual_avatar; $orderComment->user_type = $this->user_type; $orderComment->user_name = $this->user_name; $orderComment->user_avatar = $this->user_avatar; if ($orderComment->save()) { return [ 'code' => 0, 'msg' => '保存成功', ]; } else { return [ 'code' => 1, 'msg' => implode(';', array_values($orderComment->firstErrors)), ]; } } }