| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | |
| | | import org.yeshi.utils.DateUtil;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.share.UserShareGoodsGroupMapper;
|
| | | import com.yeshi.fanli.dto.HongBao;
|
| | | import com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord.ShareSourceTypeEnum;
|
| | | 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.order.config.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | |
|
| | | @Service
|
| | | public class UserShareGoodsGroupServiceImpl implements UserShareGoodsGroupService {
|
| | |
| | |
|
| | | @Override
|
| | | public UserShareGoodsGroup getSingleGoods(Long cid, Long uid) {
|
| | | return userShareGoodsGroupMapper.getSingleGoods(cid, uid);
|
| | | return userShareGoodsGroupMapper.getSingleGoods(ShareSourceTypeEnum.goodsDetail,cid, uid );
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public UserShareGoodsGroup getNewestRecord(Long uid, Long auctionId) {
|
| | | return userShareGoodsGroupMapper.getNewestRecord(uid, auctionId);
|
| | | public UserShareGoodsGroup getNewestRecord(Long uid, Long auctionId, Integer goodsType) {
|
| | | return userShareGoodsGroupMapper.getNewestRecord(uid, auctionId, goodsType);
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 更新浏览记录数据
|
| | | * @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, int goodsType) 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(), goodsType);
|
| | | |
| | | 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 = newestRecord.getTotalMoney();
|
| | | if (totalMoney == null) {
|
| | | totalMoney = new BigDecimal(0);
|
| | | }
|
| | | BigDecimal resultMoney = MoneyBigDecimalUtil.add(totalMoney, hongBao.getMoney());
|
| | | shareGoodsGroup.setTotalMoney(resultMoney);
|
| | | |
| | | updateByPrimaryKeySelective(shareGoodsGroup);
|
| | | }
|
| | | |
| | | userShareGoodsGroupMapper.updateBatchSelective(listUpdate);
|
| | | |
| | | }
|
| | |
|
| | |
|
| | |
| | | * @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, Constant.SOURCE_TYPE_TAOBAO);
|
| | |
|
| | | if (newestRecord != null) {
|
| | | // 注意: 修改记录数据、但不可修改更新设置
|
| | | UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(newestRecord.getId());
|
| | | shareGoodsGroup.setTotalOrder(newestRecord.getTotalOrder() + count);
|
| | | if (group != null) {
|
| | | UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(group.getId());
|
| | | // 累计浏览
|
| | | Integer totalBrowse = group.getTotalBrowse();
|
| | | if (totalBrowse == null) {
|
| | | totalBrowse = 0;
|
| | | }
|
| | | shareGoodsGroup.setTotalBrowse(totalBrowse + count);
|
| | |
|
| | | // 单个商品预计金额
|
| | | String rateStr = hongBaoManageService.get("hongbao_goods_proportion");
|
| | | BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(taoBaoGoodsBrief, new BigDecimal(rateStr));
|
| | | // 今日浏览
|
| | | 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);
|
| | |
|
| | | // 更新预计收益 |
| | | BigDecimal resultMoney = MoneyBigDecimalUtil.mul(new BigDecimal(shareGoodsGroup.getTotalOrder()), money);
|
| | | shareGoodsGroup.setTotalMoney(resultMoney);
|
| | | userShareGoodsGroupMapper.updateByPrimaryKeySelective(shareGoodsGroup);
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | |
| | | @Override
|
| | | public void updateBrowseNum(Long uid, Long id, int goodsType) throws UserShareGoodsRecordException{
|
| | | |
| | | if (uid == null) {
|
| | | throw new UserShareGoodsRecordException(1, "用户ID不能为空");
|
| | | }
|
| | | |
| | | if (id == null) {
|
| | | throw new UserShareGoodsRecordException(1, "商品Id不能为空");
|
| | | }
|
| | | |
| | | UserShareGoodsGroup group = getNewestRecord(uid, id, goodsType);
|
| | | if (group != null) {
|
| | | UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(group.getId());
|
| | | // 累计浏览
|
| | | Integer totalBrowse = group.getTotalBrowse();
|
| | | if (totalBrowse == null) {
|
| | | totalBrowse = 0;
|
| | | }
|
| | | shareGoodsGroup.setTotalBrowse(totalBrowse + 1);
|
| | |
|
| | | updateByPrimaryKeySelective(shareGoodsGroup);
|
| | | // 今日浏览
|
| | | Date date = new Date();
|
| | | Date browseTime = group.getBrowseTime();
|
| | | if (DateUtil.isSameDay(browseTime, date)) {
|
| | | shareGoodsGroup.setTodayBrowse(group.getTodayBrowse() + 1);
|
| | | } else {
|
| | | shareGoodsGroup.setTodayBrowse(1);
|
| | | }
|
| | | shareGoodsGroup.setBrowseTime(date);
|
| | | userShareGoodsGroupMapper.updateByPrimaryKeySelective(shareGoodsGroup);
|
| | | }
|
| | | }
|
| | | }
|