| | |
| | | package com.yeshi.fanli.controller.apph5;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | |
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
|
| | | import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.yeshi.fanli.dto.jd.JDFilter;
|
| | | import com.yeshi.fanli.dto.jd.JDSearchResult;
|
| | | import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
|
| | | import com.yeshi.fanli.dto.pdd.PDDGoodsResult;
|
| | | import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
|
| | | import com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup;
|
| | | import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.jd.JDGoods;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
|
| | | import com.yeshi.fanli.util.jd.JDApiUtil;
|
| | | import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | | import com.yeshi.fanli.vo.goods.GoodsDetailVO;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Controller
|
| | | @RequestMapping("api/apph5/v1/share")
|
| | | public class AppH5ShareController {
|
| | |
|
| | | |
| | | @Resource
|
| | | private UserShareGoodsGroupService userShareGoodsGroupService;
|
| | | |
| | | private UserShareGoodsRecordService userShareGoodsRecordService;
|
| | |
|
| | | @Resource
|
| | | private HongBaoManageService hongBaoManageService;
|
| | |
|
| | | /**
|
| | | * 分享商品
|
| | | * 分享商品详情
|
| | | * |
| | | * @param callback
|
| | | * @param shareId 分享id
|
| | | * @param source 来源
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getDetail")
|
| | | public void getDetail(String callback, Long shareId, String source, PrintWriter out) {
|
| | | |
| | | public void getDetail(String callback, Long shareId, String source, String fingerprint, PrintWriter out) {
|
| | |
|
| | | try {
|
| | | |
| | |
|
| | | if (shareId == null) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("传递参数不正确")));
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不正确"));
|
| | | return;
|
| | | }
|
| | | |
| | | userShareGoodsGroupService.updateBrowseRecord(shareId, 1);
|
| | | |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("更新成功")));
|
| | | } catch (UserShareGoodsRecordException e) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMsg())));
|
| | |
|
| | | // 获取商品信息
|
| | | JSONObject data = userShareGoodsRecordService.getGoodsGroupDetail(shareId);
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
| | |
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("更新失败")));
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("获取失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * 分享商品
|
| | | * 分享商品列表
|
| | | * |
| | | * @param callback
|
| | | * @param shareId 分享id
|
| | | * @param source 来源
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "record")
|
| | | public void query(String callback, Long shareId, String source, PrintWriter out) {
|
| | | |
| | | @RequestMapping(value = "getList")
|
| | | public void getList(String callback, Long shareId, PrintWriter out) {
|
| | | try {
|
| | | |
| | | if (shareId == null) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("传递参数不正确")));
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不正确"));
|
| | | return;
|
| | | }
|
| | | |
| | | userShareGoodsGroupService.updateBrowseRecord(shareId, 1);
|
| | | |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("更新成功")));
|
| | | } catch (UserShareGoodsRecordException e) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMsg())));
|
| | |
|
| | | JSONArray array = new JSONArray();
|
| | |
|
| | | List<UserShareGoodsGroup> list = userShareGoodsRecordService.listByRecordId(shareId);
|
| | | if (list != null && list.size() > 0) {
|
| | | List<Long> listIdTB = new ArrayList<Long>();
|
| | | List<Long> listIdJD = new ArrayList<Long>();
|
| | | List<Long> listIdPDD = new ArrayList<Long>();
|
| | | |
| | | for (int i = 0; i < list.size(); i++) {
|
| | | CommonGoods commonGoods = list.get(i).getCommonGoods();
|
| | | if (commonGoods == null) {
|
| | | continue;
|
| | | }
|
| | | |
| | | Integer goodsType = commonGoods.getGoodsType();
|
| | | if (goodsType == null) {
|
| | | continue;
|
| | | }
|
| | | |
| | | if (Constant.SOURCE_TYPE_TAOBAO == goodsType) {
|
| | | listIdTB.add(commonGoods.getGoodsId());
|
| | | } else if (Constant.SOURCE_TYPE_JD == goodsType) {
|
| | | listIdJD.add(commonGoods.getGoodsId());
|
| | | } else if (Constant.SOURCE_TYPE_PDD == goodsType) {
|
| | | listIdPDD.add(commonGoods.getGoodsId());
|
| | | }
|
| | | }
|
| | | |
| | | // 淘宝验证是否在售
|
| | | List<TaoBaoGoodsBrief> listTB = null;
|
| | | if (listIdTB.size() > 0) {
|
| | | try {
|
| | | listTB = TaoKeApiUtil.getBatchGoodsInfo(listIdTB);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | // 京东验证是否在售
|
| | | List<JDGoods> listJD = null;
|
| | | if (listIdJD.size() > 0) {
|
| | | try {
|
| | | JDFilter filter = new JDFilter();
|
| | | filter.setListId(listIdJD);
|
| | | filter.setPageIndex(1);
|
| | | filter.setPageSize(100);
|
| | | JDSearchResult result = JDApiUtil.queryByKey(filter);
|
| | | if (result != null) {
|
| | | listJD = result.getGoodsList();
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | // 拼多多验证是否在售
|
| | | List<PDDGoodsDetail> listPDD = null;
|
| | | if (listIdPDD.size() > 0) {
|
| | | try {
|
| | | Long[] ids = new Long[list.size()];
|
| | | PDDSearchFilter sf = new PDDSearchFilter();
|
| | | sf.setPage(1);
|
| | | sf.setPageSize(100);
|
| | | sf.setGoodsIdList(listIdPDD.toArray(ids));
|
| | | PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(sf);
|
| | | if (result != null) {
|
| | | listPDD = result.getGoodsList();
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
| | | .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
| | | BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
|
| | | BigDecimal shareRate = hongBaoManageService.getShareRate();
|
| | | |
| | | for (UserShareGoodsGroup goodsGroup : list) {
|
| | | CommonGoods commonGoods = goodsGroup.getCommonGoods();
|
| | | if (commonGoods == null) {
|
| | | continue;
|
| | | }
|
| | | Integer goodsType = commonGoods.getGoodsType();
|
| | | if (goodsType == null) {
|
| | | goodsType = Constant.SOURCE_TYPE_TAOBAO;
|
| | | }
|
| | | Long commonGid = commonGoods.getGoodsId();
|
| | | |
| | | if (goodsType == Constant.SOURCE_TYPE_TAOBAO && listTB != null && listTB.size() > 0) {
|
| | | int state = 1; // 默认停售
|
| | | for (TaoBaoGoodsBrief goodsDetail : listTB) {
|
| | | Long goodsId =goodsDetail.getAuctionId();
|
| | | if (goodsId == commonGid || goodsId.equals(commonGid)) {
|
| | | state = 0; // 在售
|
| | | break;
|
| | | }
|
| | | }
|
| | | commonGoods.setState(state);
|
| | | }
|
| | | |
| | | if (goodsType == Constant.SOURCE_TYPE_JD && listJD != null && listJD.size() > 0) {
|
| | | int state = 1; // 默认停售
|
| | | for (JDGoods goodsDetail : listJD) {
|
| | | Long goodsId =goodsDetail.getSkuId();
|
| | | if (goodsId == commonGid || goodsId.equals(commonGid)) {
|
| | | state = 0; // 在售
|
| | | break;
|
| | | }
|
| | | }
|
| | | commonGoods.setState(state);
|
| | | }
|
| | | |
| | | |
| | | if (goodsType == Constant.SOURCE_TYPE_PDD && listPDD != null && listPDD.size() > 0) {
|
| | | int state = 1; // 默认停售
|
| | | for (PDDGoodsDetail goodsDetail : listPDD) {
|
| | | Long goodsId =goodsDetail.getGoodsId();
|
| | | if (goodsId == commonGid || goodsId.equals(commonGid)) {
|
| | | state = 0; // 在售
|
| | | break;
|
| | | }
|
| | | }
|
| | | commonGoods.setState(state);
|
| | | }
|
| | | |
| | | GoodsDetailVO detailVO = GoodsDetailVOFactory.convertCommonGoods(commonGoods, null, fanLiRate, shareRate);
|
| | | if (!detailVO.isHasCoupon()) {
|
| | | detailVO.setState(1);; // 已抢光
|
| | | }
|
| | | array.add(gson.toJson(detailVO));
|
| | | }
|
| | | }
|
| | |
|
| | | String title = "";
|
| | | UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordService.selectByPrimaryKey(shareId);
|
| | | if (userShareGoodsRecord != null) {
|
| | | title = userShareGoodsRecord.getTitle();
|
| | | }
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("title", title);
|
| | | data.put("count", list.size());
|
| | | data.put("result_list", array);
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("更新失败")));
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("获取失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | }
|