ソースを参照

feat[litemall-admin-api, litemall-admin]: 管理后台支持评价回复。

Junling Bu 7 年 前
コミット
f5b1a2df06

+ 47 - 4
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminOrderController.java

@@ -9,10 +9,7 @@ import org.linlinjava.litemall.core.util.JacksonUtil;
 import org.linlinjava.litemall.core.validator.Order;
 import org.linlinjava.litemall.core.validator.Sort;
 import org.linlinjava.litemall.db.domain.*;
-import org.linlinjava.litemall.db.service.LitemallOrderGoodsService;
-import org.linlinjava.litemall.db.service.LitemallOrderService;
-import org.linlinjava.litemall.db.service.LitemallGoodsProductService;
-import org.linlinjava.litemall.db.service.LitemallUserService;
+import org.linlinjava.litemall.db.service.*;
 import org.linlinjava.litemall.db.util.OrderUtil;
 import org.linlinjava.litemall.core.util.ResponseUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,12 +18,14 @@ import org.springframework.transaction.PlatformTransactionManager;
 import org.springframework.transaction.TransactionDefinition;
 import org.springframework.transaction.TransactionStatus;
 import org.springframework.transaction.support.DefaultTransactionDefinition;
+import org.springframework.util.StringUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.constraints.NotNull;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -48,6 +47,8 @@ public class AdminOrderController {
     private LitemallGoodsProductService productService;
     @Autowired
     private LitemallUserService userService;
+    @Autowired
+    private LitemallCommentService commentService;
 
     @Autowired
     private NotifyService notifyService;
@@ -220,6 +221,48 @@ public class AdminOrderController {
         return ResponseUtil.ok();
     }
 
+
+    /**
+     * 回复订单商品
+     *
+     * @param adminId 管理员ID
+     * @param body   订单信息,{ orderId:xxx }
+     * @return 订单操作结果
+     * 成功则 { errno: 0, errmsg: '成功' }
+     * 失败则 { errno: XXX, errmsg: XXX }
+     */
+    @PostMapping("reply")
+    public Object reply(@LoginAdmin Integer adminId, @RequestBody String body) {
+        if (adminId == null) {
+            return ResponseUtil.unlogin();
+        }
+
+        Integer commentId = JacksonUtil.parseInteger(body, "commentId");
+        if(commentId == null || commentId == 0){
+            return ResponseUtil.badArgument();
+        }
+        // 目前只支持回复一次
+        if(commentService.findById(commentId) != null){
+            return ResponseUtil.fail(404, "订单商品已回复!");
+        }
+        String content = JacksonUtil.parseString(body, "content");
+        if(StringUtils.isEmpty(content)){
+            return ResponseUtil.badArgument();
+        }
+        // 创建评价回复
+        LitemallComment comment = new LitemallComment();
+        comment.setType((byte)2);
+        comment.setValueId(commentId);
+        comment.setContent(content);
+        comment.setUserId(0);                 // 评价回复没有用
+        comment.setStar((short)0);           // 评价回复没有用
+        comment.setHasPicture(false);        // 评价回复没有用
+        comment.setPicUrls(new String[]{});  // 评价回复没有用
+        commentService.save(comment);
+
+        return ResponseUtil.ok();
+    }
+
     /**
      * 自动取消订单
      * <p>

+ 8 - 0
litemall-admin/src/api/order.js

@@ -35,3 +35,11 @@ export function refundOrder(data) {
     data
   })
 }
+
+export function replyComment(data) {
+  return request({
+    url: '/order/reply',
+    method: 'post',
+    data
+  })
+}

+ 38 - 5
litemall-admin/src/views/goods/comment.vue

@@ -20,6 +20,9 @@
       <el-table-column align="center" label="商品ID" prop="valueId">
       </el-table-column>
 
+      <el-table-column align="center" label="打分" prop="star">
+      </el-table-column>
+
       <el-table-column align="center" label="评论内容" prop="content">
       </el-table-column>
 
@@ -47,12 +50,25 @@
       </el-pagination>
     </div>
 
+    <!-- 评论回复 -->
+    <el-dialog title="回复" :visible.sync="replyFormVisible">
+      <el-form ref="replyForm" :model="replyForm" status-icon label-position="left" label-width="100px" style='width: 400px; margin-left:50px;'>
+        <el-form-item label="回复内容" prop="content">
+          <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 8}" v-model="replyForm.content"></el-input>
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button @click="replyFormVisible = false">取消</el-button>
+        <el-button type="primary" @click="reply">确定</el-button>
+      </div>
+    </el-dialog>
+
   </div>
 </template>
 
 <script>
 import { listComment, deleteComment } from '@/api/comment'
-import { MessageBox } from 'element-ui'
+import { replyComment } from '@/api/order'
 
 export default {
   name: 'Comment',
@@ -69,7 +85,12 @@ export default {
         sort: 'add_time',
         order: 'desc'
       },
-      downloadLoading: false
+      downloadLoading: false,
+      replyForm: {
+        commentId: 0,
+        content: ''
+      },
+      replyFormVisible: false
     }
   },
   created() {
@@ -101,9 +122,21 @@ export default {
       this.getList()
     },
     handleReply(row) {
-      MessageBox.alert('商品评论回复目前不支持', '失败', {
-        confirmButtonText: '确定',
-        type: 'error'
+      this.replyForm = { commentId: row.id, content: '' }
+      this.replyFormVisible = true
+    },
+    reply() {
+      replyComment(this.replyForm).then(response => {
+        this.replyFormVisible = false
+        this.$notify.success({
+          title: '成功',
+          message: '回复成功'
+        })
+      }).catch(response => {
+        this.$notify.error({
+          title: '失败',
+          message: response.data.errmsg
+        })
       })
     },
     handleDelete(row) {