| package com.matrix.system.shopXcx.api.action; | 
|   | 
| import com.matrix.component.redis.RedisUserLoginUtils; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.system.common.bean.BusParameterSettings; | 
| import com.matrix.system.common.constance.AppConstance; | 
| import com.matrix.system.common.dao.BusParameterSettingsDao; | 
| import com.matrix.system.hive.bean.SysVipInfo; | 
| import com.matrix.system.score.constant.ScoreSettingConstant; | 
| import com.matrix.system.score.entity.ScoreVipDetail; | 
| import com.matrix.system.score.service.ScoreVipDetailService; | 
| import com.matrix.system.shopXcx.bean.ShopOrder; | 
| import com.matrix.system.shopXcx.bean.ShopProductComment; | 
| import com.matrix.system.shopXcx.dao.ShopOrderDao; | 
| import com.matrix.system.shopXcx.dao.ShopProductCommentDao; | 
| import org.apache.commons.collections.CollectionUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import java.util.HashMap; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * @description 产品评价接口 | 
|  * @author jiangyouyao | 
|  * @date 2019-06-14 11:15 | 
|  */ | 
| @CrossOrigin(origins = "*", maxAge = 3600) | 
| @Controller | 
| @RequestMapping(value = "wxapi/ProductComment") | 
| public class WxProductCommentAction { | 
|     @Autowired | 
|     private ShopProductCommentDao productCommentDao; | 
|     @Autowired | 
|     private RedisUserLoginUtils redisUserLoginUtils; | 
|     @Autowired | 
|     private ShopOrderDao shopOrderDao; | 
|   | 
|     @Autowired | 
|     ScoreVipDetailService scoreVipDetailService; | 
|   | 
|     @Autowired | 
|     private BusParameterSettingsDao busParameterSettingsDao; | 
|     /** | 
|      * 根据ID逻辑删除产品评价 | 
|      * @param | 
|      * @return | 
|      */ | 
|     @PostMapping("/deleteByComId/{comId}") | 
|     @ResponseBody | 
|     public AjaxResult deleteByComId(@PathVariable("comId") Integer comId){ | 
|         Map<String, Object> modifyMap = new HashMap<>(); | 
|         modifyMap.put("delFlag", AppConstance.DATA_DISABLE); | 
|         modifyMap.put("comId", comId); | 
|         int i = productCommentDao.updateByMap(modifyMap); | 
|         if (i == 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "删除失败"); | 
|         } | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "删除成功"); | 
|     } | 
|   | 
|     /** | 
|      * 接收保存产品评价数据 | 
|      */ | 
|     @PostMapping(value = "/saveProductComment") | 
|     public @ResponseBody | 
|     AjaxResult saveProductComment(@RequestBody List<ShopProductComment> commentList) { | 
|         SysVipInfo loginUser = redisUserLoginUtils.getLoginUser(SysVipInfo.class); | 
|         int flag = 0; | 
|         if(CollectionUtils.isNotEmpty(commentList)){ | 
|             for(ShopProductComment productComment : commentList){ | 
|                 productComment.setCreateBy(loginUser.getOpenId()); | 
|                 productComment.setUpdateBy(loginUser.getOpenId()); | 
|                 productComment.setUserId(loginUser.getOpenId()); | 
|                 productComment.setComAuditStatus(AppConstance.NOT_AUDITED); | 
|                 productComment.setDelFlag(AppConstance.DATA_USEABLE); | 
|                 productComment.setCompanyId(loginUser.getCompanyId()); | 
|             } | 
|             flag = productCommentDao.batchInsert(commentList); | 
|         } | 
|   | 
|         if (flag == 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "保存失败"); | 
|         } | 
|         //将订单状态改为已评价 | 
|         Integer orderId = commentList.get(0).getOrderId(); | 
|         Map<String, Object> modifyMap = new HashMap<>(); | 
|         modifyMap.put("id", orderId); | 
|         modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_ALREADY_REMARK); | 
|         shopOrderDao.updateByMap(modifyMap); | 
|   | 
|         //添加用户积分 | 
|         BusParameterSettings parameterSetting = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.EVALUATUIN_ORDER_SHOP_NAME, loginUser.getCompanyId()); | 
|         scoreVipDetailService.addScoreByParamSetting(loginUser.getId(), null,null, commentList.get(0).getComId(), | 
|                 ScoreVipDetail.SCORE_VIP_TYPE_JOIN_ACTIVE,"评价送积分", parameterSetting); | 
|   | 
|   | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "保存成功"); | 
|     } | 
|   | 
|     /** | 
|      * 根据用户ID查询产品评价 | 
|      * @param | 
|      * @return | 
|      */ | 
|     @PostMapping("/findProductComment") | 
|     @ResponseBody | 
|     public AjaxResult getProductCommentByUserId(@RequestBody ShopProductComment productComment) { | 
|         SysVipInfo loginUser = redisUserLoginUtils.getLoginUser(SysVipInfo.class); | 
|         String userId = loginUser.getOpenId(); | 
|         productComment.setUserId(userId); | 
|         List<ShopProductComment> list = productCommentDao.selectByUserId(productComment); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, list); | 
|         return result; | 
|     } | 
|   | 
|     /** | 
|      * 根据产品ID查询产品评价 | 
|      * @param | 
|      * @return | 
|      */ | 
|     @PostMapping("/findByProductId") | 
|     @ResponseBody | 
|     public AjaxResult findByProductId(@RequestBody ShopProductComment productComment) { | 
|         List<ShopProductComment> list = productCommentDao.selectByProductId(productComment); | 
|         int total = productCommentDao.selectByProductTotal(productComment); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, list,total); | 
|         return result; | 
|     } | 
| } |