喻健
2018-12-13 376731d640612a4ea22bb3fb5ec8fc2c7075002b
分享商品优化
1个文件已删除
5个文件已修改
231 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/apph5/AppH5ShareController.java 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/h5/H5RecommendController.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/share/UserShareGoodsGroupMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsGroupServiceImpl.java 100 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsRecordServiceImpl.java 35 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserShareGoodsGroupService.java 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/apph5/AppH5ShareController.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/controller/h5/H5RecommendController.java
@@ -8,6 +8,9 @@
import javax.annotation.Resource;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -42,6 +45,7 @@
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.user.ScanHistoryService;
import com.yeshi.fanli.service.inter.user.TBPidService;
import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
import com.yeshi.fanli.util.AESUtil;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.RedisManager;
@@ -49,9 +53,6 @@
import com.yeshi.fanli.util.Utils;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("api/h5/v1/webRecommend")
@@ -99,6 +100,9 @@
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
    @Resource
    private UserShareGoodsGroupService userShareGoodsGroupService;
    /**
     * 
     * 方法说明: 推荐轮播商品信息
@@ -279,6 +283,9 @@
                } catch (Exception e) {
                }
                userShareGoodsGroupService.updateBrowseRecord(Long.parseLong(uid), Long.parseLong(id), 1);
            } catch (Exception e) {
fanli/src/main/java/com/yeshi/fanli/mapping/share/UserShareGoodsGroupMapper.xml
@@ -151,11 +151,11 @@
   </select>
   
   <select id="getNewestRecord" resultMap="BaseResultMap">
    SELECT * FROM yeshi_ec_share_goods_group tg
    SELECT tg.* FROM yeshi_ec_share_goods_group tg
    RIGHT JOIN `yeshi_ec_share_goods_record` r ON tg.`gu_record_id` = r.`sgr_id`
    LEFT JOIN  `yeshi_ec_common_goods` cg ON tg.`gu_common_goods_id` = cg.`cg_id`
    WHERE r.`sgr_uid` = #{uid} AND cg.`cg_goods_id` = #{auctionId}  AND r.sgr_share_state = 1
    ORDER BY gu_updatetime desc LIMIT 1
    ORDER BY tg.gu_updatetime desc LIMIT 1
   </select>
   
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsGroupServiceImpl.java
@@ -1,7 +1,6 @@
package com.yeshi.fanli.service.impl.user;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -12,13 +11,12 @@
import com.yeshi.fanli.dao.mybatis.share.UserShareGoodsGroupMapper;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.bus.user.HongBao;
import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
@Service
public class UserShareGoodsGroupServiceImpl implements UserShareGoodsGroupService {
@@ -79,43 +77,52 @@
    
    /**
     * 更新浏览记录数据
     * @param shareId 分享id
     * @param count 浏览次数
     * 更新订单记录数据
     * @param uid
     * @param auctionId
     */
    @Override
    public void updateBrowseRecord (Long shareId, int count) throws UserShareGoodsRecordException{
        if (shareId == null) {
            throw new UserShareGoodsRecordException(1, "分享id为空");
    public void updateOrderRecord (HongBao hongBao) throws UserShareGoodsRecordException{
        if (hongBao == null) {
            throw new UserShareGoodsRecordException(1, "hongBao不能为空");
        }
        
        List<UserShareGoodsGroup> list = listByRecordId(shareId);
        if (list == null || list.size() == 0) {
            throw new UserShareGoodsRecordException(1, "分享商品已不存在");
        if (hongBao.getUserInfo() == null) {
            throw new UserShareGoodsRecordException(1, "用户信息不能为空");
        }
        
        List<UserShareGoodsGroup> listUpdate = new ArrayList<UserShareGoodsGroup>();
        Long uid = hongBao.getUserInfo().getId();
        if (uid == null) {
            throw new UserShareGoodsRecordException(1, "用户ID不能为空");
        }
        
        for (UserShareGoodsGroup group: list) {
            // 注意: 修改记录数据、但不可修改更新设置
            UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(group.getId());
        if (hongBao.getAuctionId() == null) {
            throw new UserShareGoodsRecordException(1, "商品ID不能为空");
        }
        UserShareGoodsGroup newestRecord = getNewestRecord(uid, hongBao.getAuctionId());
        if (newestRecord != null) {
            // 更新订单数量
            UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(newestRecord.getId());
            Integer totalOrder = newestRecord.getTotalOrder();
            
            shareGoodsGroup.setTotalBrowse(group.getTotalBrowse() + count);
            Date browseTime = group.getBrowseTime();
            if (DateUtil.isSameDay(browseTime, new Date())) {
                shareGoodsGroup.setTodayBrowse(group.getTodayBrowse() + count);
            } else {
                shareGoodsGroup.setTodayBrowse(count);
                shareGoodsGroup.setBrowseTime(new Date());
            if (totalOrder == null) {
                totalOrder = 0;
            }
            shareGoodsGroup.setTotalOrder(totalOrder + 1);
            
            listUpdate.add(shareGoodsGroup);
            // 更新预计收益
            BigDecimal totalMoney = shareGoodsGroup.getTotalMoney();
            if (totalMoney == null) {
                totalMoney = new BigDecimal(0);
            }
            BigDecimal resultMoney = MoneyBigDecimalUtil.mul(totalMoney, hongBao.getMoney());
            shareGoodsGroup.setTotalMoney(resultMoney);
            updateByPrimaryKeySelective(shareGoodsGroup);
        }
        userShareGoodsGroupMapper.updateBatchSelective(listUpdate);
    }
    
    
@@ -125,33 +132,34 @@
     * @param auctionId
     */
    @Override
    public void updateOrderRecord (Long uid, TaoBaoGoodsBrief taoBaoGoodsBrief, int count)
    public void updateBrowseRecord (Long uid, Long auctionId, int count)
            throws UserShareGoodsRecordException{
        
        if (uid == null) {
            throw new UserShareGoodsRecordException(1, "用户ID不能为空");
        }
        
        if (taoBaoGoodsBrief == null) {
            throw new UserShareGoodsRecordException(1, "商品不能为空");
        if (auctionId == null) {
            throw new UserShareGoodsRecordException(1, "商品Id不能为空");
        }
        
        UserShareGoodsGroup newestRecord = getNewestRecord(uid, taoBaoGoodsBrief.getAuctionId());
        UserShareGoodsGroup group = getNewestRecord(uid, auctionId);
        
        if (newestRecord != null) {
            // 注意: 修改记录数据、但不可修改更新设置
            UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(newestRecord.getId());
            shareGoodsGroup.setTotalOrder(newestRecord.getTotalOrder() + count);
        if (group != null) {
            UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(group.getId());
            // 累计浏览
            shareGoodsGroup.setTotalBrowse(group.getTotalBrowse() + count);
            
            // 单个商品预计金额
            String rateStr = hongBaoManageService.get("hongbao_goods_proportion");
            BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(taoBaoGoodsBrief, new BigDecimal(rateStr));
            // 更新预计收益
            BigDecimal resultMoney = MoneyBigDecimalUtil.mul(new BigDecimal(shareGoodsGroup.getTotalOrder()), money);
            shareGoodsGroup.setTotalMoney(resultMoney);
            updateByPrimaryKeySelective(shareGoodsGroup);
            // 今日浏览
            Date date = new Date();
            Date browseTime = group.getBrowseTime();
            if (DateUtil.isSameDay(browseTime, date)) {
                shareGoodsGroup.setTodayBrowse(group.getTodayBrowse() + count);
            } else {
                shareGoodsGroup.setTodayBrowse(count);
            }
            shareGoodsGroup.setBrowseTime(date);
            userShareGoodsGroupMapper.updateByPrimaryKeySelective(shareGoodsGroup);
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsRecordServiceImpl.java
@@ -143,6 +143,14 @@
                userShareGoodsRecord.setCreateTime(null);
                userShareGoodsRecord.setUpdateTime(null);
                listId.add(userShareGoodsRecord.getId());
                // 改变图片尺寸
                String pictUrl = userShareGoodsRecord.getPicture();
                if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
                    userShareGoodsRecord.setPicture(TbImgUtil.getTBSize320Img(pictUrl));
                }
            }
            
            // 今日浏览统计
@@ -328,17 +336,12 @@
                userShareGoodsRecord.setUpdateTime(new Date());
                userShareGoodsRecordMapper.updateByPrimaryKey(userShareGoodsRecord);
                
                Integer totalOrder = shareGoodsGroup.getTotalOrder();
                if (totalOrder == null ||totalOrder == 0 || totalOrder.equals(0)) {
                    // 预计金额
                    String rateStr = hongBaoManageService.get("hongbao_goods_proportion");
                    shareGoodsGroup.setUpdateTime(new Date());
                    BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(taoBaoGoodsBrief, new BigDecimal(rateStr));
                    shareGoodsGroup.setTotalMoney(money);
                    userShareGoodsGroupService.updateByPrimaryKeySelective(shareGoodsGroup);
                }
            } else {
                // 最新商品
                shareGoodsGroup.setUpdateTime(new Date());
                userShareGoodsGroupService.updateByPrimaryKeySelective(shareGoodsGroup);
            } else
            {
                // 单个商品第一次分享
                Date date = new Date();
                userShareGoodsRecord.setPicture(taoBaoGoodsBrief.getPictUrl());
@@ -350,15 +353,12 @@
                shareGoodsGroup.setTotalOrder(0);
                shareGoodsGroup.setTotalBrowse(0);
                shareGoodsGroup.setTodayBrowse(0);
                shareGoodsGroup.setTotalMoney(new BigDecimal(0));
                shareGoodsGroup.setCreateTime(date);
                shareGoodsGroup.setUpdateTime(date);
                shareGoodsGroup.setCommonGoods(resultCommonGoods);
                shareGoodsGroup.setRecordId(userShareGoodsRecord.getId());
                
                // 预计金额
                String rateStr = hongBaoManageService.get("hongbao_goods_proportion");
                BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(taoBaoGoodsBrief, new BigDecimal(rateStr));
                shareGoodsGroup.setTotalMoney(money);
                
                userShareGoodsGroupService.insertSelective(shareGoodsGroup);
            }
@@ -380,7 +380,6 @@
        
        // 分享记录
        Date date = new Date();
        String rateStr = hongBaoManageService.get("hongbao_goods_proportion");
        
        List<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>();
        List<UserShareGoodsGroup> listGroup = new ArrayList<UserShareGoodsGroup>();
@@ -400,14 +399,12 @@
                shareGoodsGroup.setTotalOrder(0);
                shareGoodsGroup.setTotalBrowse(0);
                shareGoodsGroup.setTodayBrowse(0);
                shareGoodsGroup.setTotalMoney(new BigDecimal(0));
                shareGoodsGroup.setCreateTime(date);
                shareGoodsGroup.setUpdateTime(date);
                shareGoodsGroup.setCommonGoods(resultCommonGoods);
                shareGoodsGroup.setRecordId(userShareGoodsRecord.getId());
                
                // 预计金额
                BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(taoBaoGoodsBrief, new BigDecimal(rateStr));
                shareGoodsGroup.setTotalMoney(money);
                
                listGroup.add(shareGoodsGroup);
                
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserShareGoodsGroupService.java
@@ -3,7 +3,7 @@
import java.util.List;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.bus.user.HongBao;
import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
public interface UserShareGoodsGroupService {
@@ -47,22 +47,22 @@
     */
    public UserShareGoodsGroup getNewestRecord(Long uid, Long auctionId);
    /**
     * 更新浏览数据
     * @param uid 用户id
     * @param auctionId 商品id
     * @param count 数量
     * @throws UserShareGoodsRecordException
     */
    public void updateBrowseRecord(Long shareId, int count) throws UserShareGoodsRecordException;
    /**
     * 更新订单数量及收益
     * @param uid 用户id 
     * @param taoBaoGoodsBrief 商品
     * @param auctionId 商品id
     * @param count 订单数量
     * @throws UserShareGoodsRecordException
     */
    public void updateOrderRecord(Long uid, TaoBaoGoodsBrief taoBaoGoodsBrief, int count) throws UserShareGoodsRecordException;
    public void updateOrderRecord(HongBao hongBao) throws UserShareGoodsRecordException;
    /**
     * 单个商品分享浏览记录
     * @param uid
     * @param auctionId
     * @param count
     * @throws UserShareGoodsRecordException
     */
    public void updateBrowseRecord(Long uid, Long auctionId, int count) throws UserShareGoodsRecordException;
}