| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\models\v1\admin;
- use app\models\Goods;
- use app\models\OrderComment;
- use app\models\User;
- use yii\base\Model;
- class OrderCommentForm extends Model
- {
- public $store_id;
- public $id;
- public $status;
- public $reply_content;
- public $pic_list;
- public $mch_id;
- /**
- * 获取评论列表
- * @return array
- */
- public function getComment() {
- $query = OrderComment::find()->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' => '操作成功',
- ];
- }
- }
|