yujian
2020-06-03 80e39e3a40283521fc732c930aa51d9bece7c146
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/UserCloudControllerV2.java
@@ -34,6 +34,7 @@
import com.yeshi.fanli.entity.bus.user.cloud.UserCloudOrder;
import com.yeshi.fanli.entity.dynamic.GoodsEvaluate;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
@@ -41,6 +42,7 @@
import com.yeshi.fanli.exception.user.cloud.UserCloudGoodsException;
import com.yeshi.fanli.exception.user.cloud.UserCloudGroupException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.dynamic.GoodsEvaluateService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
@@ -55,6 +57,7 @@
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.aitaoker.AitaokerApiUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.util.suning.SuningUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import com.yeshi.fanli.vo.user.cloud.UserCloudInfoVO;
@@ -93,7 +96,8 @@
   @Resource
   private GoodsEvaluateService goodsEvaluateService;
   
   @Resource
   private ConfigService configService;
   /**
    * 查询开通记录
@@ -575,7 +579,7 @@
    * @param out
    */
   @RequestMapping(value = "accordGoods")
   public void accordGoods(String callback, AcceptData acceptData, Long uid, Long goodsId, Integer goodsType,
   public void accordGoods(String callback, AcceptData acceptData, Long uid, String goodsId, Integer goodsType,
         PrintWriter out) {
      if (uid == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户未登录"));
@@ -589,11 +593,17 @@
      try {
         boolean state = false;
         UserCloudGoods cloudGoods = userCloudGoodsService.getByUidAndGoods(uid, goodsId, goodsType);
         String queryGoodsId = goodsId;
         if (goodsType == Constant.SOURCE_TYPE_SUNING) { // 苏宁
            String[] ids = SuningUtil.getGoodsIdDetail(goodsId);
            queryGoodsId = ids[1];
         }
         UserCloudGoods cloudGoods = userCloudGoodsService.getByUidAndGoods(uid, Long.parseLong(queryGoodsId), goodsType);
         if (cloudGoods != null) { // 取消加入选品库
            userCloudGoodsService.deleteByPrimaryKeyAndUid(cloudGoods.getId(), uid);
         } else { // 加入选品库
            Set<Long> set = new HashSet<Long>();
            Set<String> set = new HashSet<String>();
            set.add(goodsId);
            userCloudGoodsService.addGoods(uid, set, goodsType);
            state = true;
@@ -742,7 +752,14 @@
         userCloudService.sendByDynamic(uid, id);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("一键发单成功"));
      } catch (UserCloudException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getCode(),e.getMsg()));
         if (e.getCode() > 1000) {
            JSONObject data = new JSONObject();
            data.put("msg", e.getMsg());
            data.put("link",  configService.get(ConfigKeyEnum.robotCloudLink.getKey()));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(1000, data));
         } else {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getCode(),e.getMsg()));
         }
      }
   }
   
@@ -757,22 +774,39 @@
    * @param out
    */
   @RequestMapping(value = "sendGoods")
   public void sendGoods(String callback, AcceptData acceptData, Long uid, Long goodsId, Integer goodsType, PrintWriter out) {
   public void sendGoods(String callback, AcceptData acceptData, Long uid, String goodsId, Integer goodsType, PrintWriter out) {
      if (uid == null || goodsId == null || goodsType == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("参数不能为空"));
         return;
      }
      
      try {
         GoodsEvaluate evaluate = goodsEvaluateService.queryExistSingle(goodsId +"", goodsType);
         GoodsEvaluate evaluate = goodsEvaluateService.queryExistSingle(goodsId, goodsType);
         if (evaluate != null) {
            userCloudService.sendByDynamic(uid, evaluate.getId());
         } else {
            userCloudService.sendCustomGoods(uid, goodsId, goodsType);
            Long gid = null;
            Long sellerId = null;
            if (goodsType == Constant.SOURCE_TYPE_SUNING) { // 苏宁
               String[] ids = SuningUtil.getGoodsIdDetail(goodsId);
               gid = Long.parseLong(ids[1]);
               sellerId = Long.parseLong(ids[0]);
            } else {
               gid = Long.parseLong(goodsId);
            }
            userCloudService.sendCustomGoods(uid, gid, goodsType, sellerId);
         }
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("一键发单成功"));
      } catch (UserCloudException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getCode(),e.getMsg()));
         if (e.getCode() > 1000 && e.getCode() < 1100) {
            JSONObject data = new JSONObject();
            data.put("link",  configService.get(ConfigKeyEnum.robotCloudLink.getKey()));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrue(e.getCode(), data, e.getMsg()).toString());
         } else {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getCode(),e.getMsg()));
         }
      }
   }
}