| | |
| | | package com.yeshi.fanli.controller.client;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.PrintWriter;
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.UUID;
|
| | | import java.util.regex.Matcher;
|
| | | import java.util.regex.Pattern;
|
| | |
|
| | |
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMethod;
|
| | | import org.springframework.web.bind.annotation.RequestParam;
|
| | | import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | import org.yeshi.utils.taobao.TbImgUtil;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | import com.taobao.api.ApiException;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | |
| | | import com.yeshi.fanli.entity.taobao.SearchFilter;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | import com.yeshi.fanli.service.MaskKeyService;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.goods.RecommendDetailsService;
|
| | | import com.yeshi.fanli.service.inter.goods.RecommendReplyService;
|
| | |
| | | import com.yeshi.fanli.service.inter.user.DynamicRecommendService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.util.GsonUtil;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.Utils;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | |
| | |
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | | @Resource
|
| | | private MaskKeyService maskKeyService;
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 发布我的推荐
|
| | | * |
| | | * @param acceptData
|
| | | * @param dynamicRecommend
|
| | | * 推荐信息
|
| | | * @param files
|
| | | * 上传的图片
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "makePublic", method = RequestMethod.POST)
|
| | | public void makePublic(AcceptData acceptData, DynamicRecommend dynamicRecommend, String order,
|
| | | @RequestParam(value = "files", required = false) CommonsMultipartFile[] files, PrintWriter out) {
|
| | | if (dynamicRecommend == null) {
|
| | | out.print(JsonUtil.loadFalseResult("dynamicRecommend不能为空"));
|
| | | return;
|
| | | }
|
| | | if (dynamicRecommend.getUserInfo() == null) {
|
| | | out.print(JsonUtil.loadFalseResult("uid不能为空"));
|
| | | return;
|
| | | }
|
| | | if (dynamicRecommend.getReason() == null || "".equals(dynamicRecommend.getReason().trim())) {
|
| | | out.print(JsonUtil.loadFalseResult("推荐理由不能为空"));
|
| | | return;
|
| | | }
|
| | | if (dynamicRecommend.getUrl() == null || "".equals(dynamicRecommend.getUrl().trim())) {
|
| | | out.print(JsonUtil.loadFalseResult("url不能为空"));
|
| | | return;
|
| | | }
|
| | | if (dynamicRecommend.getAuctionId() == null) {
|
| | | out.print(JsonUtil.loadFalseResult("商品ID不能为空"));
|
| | | return;
|
| | | }
|
| | | if ((dynamicRecommend.getuPicUrl() == null || "".equals(dynamicRecommend.getuPicUrl().trim()))
|
| | | && files == null) {
|
| | | out.print(JsonUtil.loadFalseResult("请选择一张图片"));
|
| | | return;
|
| | | }
|
| | | String URL_REGEX = "(((http|https)://)|(www\\.))[a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6}(:[0-9]{1,4})?(/[a-zA-Z0-9\\&%_\\./-~-]*)?";
|
| | |
|
| | | Pattern p = Pattern.compile(URL_REGEX);
|
| | | Matcher matcher = p.matcher(dynamicRecommend.getUrl());
|
| | | if (!matcher.find()) {
|
| | | out.print(JsonUtil.loadFalseResult("暂不支持该类型!"));
|
| | | return;
|
| | | }
|
| | | String url = matcher.group();
|
| | | dynamicRecommend.setUrl(url);
|
| | | if (files != null) {
|
| | | COSManager cosManager = COSManager.getInstance();
|
| | | String paths = "";
|
| | | for (CommonsMultipartFile file : files) {
|
| | | try {
|
| | | String filename = file.getOriginalFilename();
|
| | | int index = filename.lastIndexOf(".");
|
| | | String type = filename.substring(index);
|
| | | String filePath = cosManager
|
| | | .uploadFile(file.getInputStream(), UUID.randomUUID().toString().replace("-", "") + type)
|
| | | .getUrl();
|
| | | paths += "," + filePath;
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | out.println(JsonUtil.loadFalseResult("上传图片失败"));
|
| | | return;
|
| | | }
|
| | | }
|
| | | paths = paths.replaceFirst(",", "");
|
| | | String getuPicUrl = dynamicRecommend.getuPicUrl();
|
| | | if (getuPicUrl != null) {
|
| | | getuPicUrl = getuPicUrl.replaceAll(",", "");
|
| | | }
|
| | | if (getuPicUrl == null || "".equals(getuPicUrl.trim())) {
|
| | | dynamicRecommend.setuPicUrl(paths);
|
| | | } else {
|
| | |
|
| | | // int i = getuPicUrl.lastIndexOf(",");
|
| | | String[] split = paths.split(",");
|
| | | int orderBy = 1;
|
| | | if (!StringUtil.isNullOrEmpty(order)) {
|
| | | orderBy = Integer.parseInt(order);
|
| | | }
|
| | | List<String> list = new ArrayList<String>();
|
| | | for (String pic : split) {
|
| | | if (!"".equals(pic.trim()))
|
| | | list.add(pic);
|
| | | }
|
| | | list.add(orderBy - 1, getuPicUrl);
|
| | | String pics = "";
|
| | | int ii = 0;
|
| | | for (String pic : list) {
|
| | | if (ii == 0) {
|
| | | pics = pic;
|
| | | } else {
|
| | | pics += "," + pic;
|
| | | }
|
| | | ii++;
|
| | | }
|
| | | dynamicRecommend.setuPicUrl(pics);
|
| | | // if(i==-1 || (i>0 && i==getuPicUrl.length()-1)){
|
| | | // }else{
|
| | | // dynamicRecommend.setuPicUrl(getuPicUrl+","+paths);
|
| | | // }
|
| | |
|
| | | }
|
| | | } else {
|
| | | String uPicUrl = dynamicRecommend.getuPicUrl();
|
| | | int lastIndex = uPicUrl.lastIndexOf(",");
|
| | | if (lastIndex > 0) {
|
| | | uPicUrl = uPicUrl.substring(0, lastIndex);
|
| | | dynamicRecommend.setuPicUrl(uPicUrl);
|
| | | }
|
| | | }
|
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = null;
|
| | | taoBaoGoodsBrief = TaoBaoUtil.isAlimama(dynamicRecommend.getAuctionId());
|
| | | if (taoBaoGoodsBrief == null) {
|
| | | taoBaoGoodsBrief = TaoBaoUtil.parsePhoneTmAndTb(dynamicRecommend.getAuctionId());
|
| | | dynamicRecommend.setHongbao(new BigDecimal(0));
|
| | | } else {
|
| | | SearchFilter filter = new SearchFilter();
|
| | | filter.setKey(String.format(TaoBaoUtil.TB_URL, dynamicRecommend.getAuctionId()));
|
| | | TaoBaoSearchResult search = TaoBaoUtil.search(filter);
|
| | | List<TaoBaoGoodsBrief> taoBaoGoodsBriefs = search.getTaoBaoGoodsBriefs();
|
| | | if (taoBaoGoodsBriefs.size() == 0) {
|
| | | out.println(JsonUtil.loadFalseResult("发布失败,商品已下架"));
|
| | | return;
|
| | | }
|
| | | taoBaoGoodsBrief = taoBaoGoodsBriefs.get(0);
|
| | | BigDecimal proportion = hongBaoManageService.getFanLiRate();
|
| | | |
| | | BigDecimal tkRate = taoBaoGoodsBrief.getTkRate();
|
| | | BigDecimal zkPrice = taoBaoGoodsBrief.getZkPrice();
|
| | | BigDecimal tkp = proportion.divide(BigDecimal.valueOf(100))
|
| | | .multiply(tkRate.divide(BigDecimal.valueOf(100)));
|
| | | BigDecimal hongbao = MoneyBigDecimalUtil.mul(zkPrice, tkp);
|
| | | dynamicRecommend.setHongbao(hongbao);
|
| | | }
|
| | | String title = taoBaoGoodsBrief.getTitle();
|
| | | int type = taoBaoGoodsBrief.getUserType();
|
| | | dynamicRecommend.setGname(title);
|
| | | dynamicRecommend.setZkPrice(taoBaoGoodsBrief.getZkPrice());
|
| | | dynamicRecommend.setgPicUrl(taoBaoGoodsBrief.getPictUrl());
|
| | | dynamicRecommend.setType(0);
|
| | | dynamicRecommend.setCreatetime(System.currentTimeMillis());
|
| | | if (type == 0) { // tb
|
| | | dynamicRecommend.setGoodsType(1); // tb
|
| | | } else {
|
| | | dynamicRecommend.setGoodsType(2); // 天猫
|
| | | }
|
| | | String reason = dynamicRecommend.getReason();
|
| | | reason = maskKeyService.maskAction(reason);
|
| | | dynamicRecommend.setReason(reason);
|
| | | long makePublic = dynamicRecommendService.makePublic(dynamicRecommend);
|
| | | if (makePublic > 0) {
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("auctionId", makePublic);
|
| | | out.println(JsonUtil.loadTrueResult(data));
|
| | | } else {
|
| | | out.println(JsonUtil.loadFalseResult("发布失败"));
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取推荐商品列表
|
| | | *
|
| | | * @param page
|
| | |
| | | data.put("count", count);
|
| | | data.put("recommendReplys", GsonUtil.toJsonByUserAp(recommendReplys));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 评价
|
| | | * |
| | | * @param drid
|
| | | * 推荐id
|
| | | * @param uid
|
| | | * 用户id
|
| | | * @param content
|
| | | * 评价内容
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "replys", method = RequestMethod.POST)
|
| | | public void replys(AcceptData acceptData, long drid, long uid, String content, PrintWriter out) {
|
| | |
|
| | | if (uid == 0) {
|
| | | out.print(JsonUtil.loadFalseResult("不存在该用户"));
|
| | | return;
|
| | | }
|
| | | List<UserInfo> userList = userInfoService.getUserListByUid(uid);
|
| | |
|
| | | if (userList.size() == 0) {
|
| | | out.print(JsonUtil.loadFalseResult("不存在该用户"));
|
| | | return;
|
| | | }
|
| | | UserInfo userInfo = userList.get(0);
|
| | | content = maskKeyService.maskAction(content);
|
| | | int state = recommendReplyService.replys(drid, userInfo, content);
|
| | | if (state == 0) {
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("user", JsonUtil.getApiCommonGson().toJson(userInfo));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } else if (state == 1) {
|
| | | out.print(JsonUtil.loadFalseResult("不存在该用户"));
|
| | | return;
|
| | | } else if (state == 2) {
|
| | | out.print(JsonUtil.loadFalseResult("不存在该推荐"));
|
| | | return;
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|