yujian
2019-05-05 790515f0b126354b82fad95b5b73d7729cd9919d
品牌+奖励券推送提交
10个文件已修改
294 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushCouponController.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/BrandController.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/brand/BrandClassShopMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/push/PushCouponMapper.xml 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/push/PushCouponRecordMapper.xml 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java 89 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java 132 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/push/PushCouponService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponService.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java
@@ -22,9 +22,9 @@
 * @author Administrator
 *
 */
@Component
@Aspect
@Order(6)
//@Component
//@Aspect
//@Order(6)
public class ActiveUserAspect {
    
    @Resource(name = "taskExecutor")
@@ -73,13 +73,6 @@
                    }
                    // 加入缓存 20分钟
                    redisManager.cacheCommonString(key, uuid.toString(), 60 * 20);
                }
                // 接收券
                try {
                    userSystemCouponService.receivedCoupon(uuid);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushCouponController.java
@@ -3,6 +3,7 @@
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
@@ -45,18 +46,16 @@
     * @param out
     */
    @RequestMapping(value = "save")
    public void save(String callback, PushCoupon pushCoupon, String arrayIOS, String arrayAndroid, PrintWriter out) {
    public void save(String callback, PushCoupon pushCoupon,  PrintWriter out) {
        
        try {
            convertVersion(pushCoupon, arrayIOS, arrayAndroid);
            pushCouponService.save(pushCoupon);
            
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("发放成功"));
        } catch (PushCouponException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("发送失败"));
            e.printStackTrace();
        }
    }
@@ -175,6 +174,8 @@
                
                convertVersionList(pushCouponVO);
                
                Date createTime = pushCouponVO.getCreateTime();
                pushCouponVO.setPushTime(createTime);
                
                listVO.add(pushCouponVO);
            }
fanli/src/main/java/com/yeshi/fanli/controller/client/BrandController.java
@@ -138,6 +138,15 @@
    @RequestMapping(value = "getHistory", method = RequestMethod.POST)
    public void getHistory(AcceptData acceptData, Integer page, Long uid, Integer type, PrintWriter out) {
        try {
            if (type == null) {
                out.print(JsonUtil.loadFalseResult("类型不正确"));
                return;
            }
            if (page == null || page < 1) {
                page = 1;
            }
            int pageSize;
            if (type == 1) {
                pageSize = 4;
@@ -187,7 +196,7 @@
            }
            JSONObject data = new JSONObject();
            data.put("count", list.size());
            data.put("count", count);
            data.put("list", JsonUtil.getApiCommonGson().toJson(list));
            out.print(JsonUtil.loadTrueResult(data));
@@ -226,11 +235,17 @@
    @RequestMapping(value = "getShopInfo", method = RequestMethod.POST)
    public void getShopInfo(AcceptData acceptData, Integer page, Long sid, Long uid, PrintWriter out) {
        try {
            if (sid == null) {
                out.print(JsonUtil.loadFalseResult("缺失店铺id"));
                return;
            }
            JSONObject data = new JSONObject();
            if (page == 1) {
                TaoBaoShop taoBaoShop = taoBaoShopService.selectByPrimaryKey(sid);
                if (taoBaoShop == null) {
                    out.print(JsonUtil.loadFalseResult("店铺信息获取失败"));
                    return;
                }
                String shopLink = taoBaoShop.getShopLink();
                if (StringUtil.isNullOrEmpty(shopLink)) {
@@ -246,7 +261,7 @@
                if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
                    taoBaoShop.setShopIcon(shopIconCustom);
                }
                data.put("shop", taoBaoShop);
                data.put("shop", JsonUtil.getApiCommonGson().toJson(taoBaoShop));
                
                
                ThreadUtil.run(new Runnable() {
fanli/src/main/java/com/yeshi/fanli/mapping/brand/BrandClassShopMapper.xml
@@ -90,11 +90,11 @@
  <select id="listEffective" resultMap="BaseResultMap">
      SELECT * FROM  yeshi_ec_brand_class_shop b
    LEFT JOIN `yeshi_ec_taobao_shop_info` p ON b.`bcs_shop_id` = p.`tsi_id`
    WHERE 1=1
    WHERE b.bcs_state = 1
        <if test="cid != null and cid !=0 ">
            AND b.`bcs_cid` = #{cid}
        </if>
    ORDER BY b.`bcs_top`,b.`bcs_create_time` DESC
    ORDER BY b.`bcs_top`,bcs_orderby
  </select>
  
  <select id="countEffective" resultType="Long">
fanli/src/main/java/com/yeshi/fanli/mapping/push/PushCouponMapper.xml
@@ -80,10 +80,7 @@
        SELECT <include refid="Base_Column_List" />  FROM yeshi_ec_push_coupon
        WHERE 1=1
           <if test='key != null and key != ""'>
                  AND (pc_title like '%${key}%' or pc_content like '%${key}%')
           </if>
           <if test='state != null'>
                  AND pc_pushed = #{state}
                  AND pc_uids like '%${key}%'
           </if>
           ORDER BY pc_create_time desc 
        LIMIT ${start},${count}
@@ -93,10 +90,7 @@
        SELECT IFNULL(count(pc_id),0)  FROM yeshi_ec_push_coupon 
        WHERE 1=1
           <if test='key != null and key != ""'>
                  AND (pc_title like '%${key}%' or pc_content like '%${key}%')
           </if>
            <if test='state != null'>
                  AND pc_pushed = #{state}
                   AND pc_uids like '%${key}%'
           </if>
    </select>
    
fanli/src/main/java/com/yeshi/fanli/mapping/push/PushCouponRecordMapper.xml
fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java
@@ -1,6 +1,5 @@
package com.yeshi.fanli.service.impl.push;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -13,12 +12,15 @@
import com.yeshi.fanli.dao.mybatis.push.PushCouponMapper;
import com.yeshi.fanli.entity.push.PushCoupon;
import com.yeshi.fanli.entity.push.PushCouponRecord;
import com.yeshi.fanli.exception.PushException;
import com.yeshi.fanli.exception.push.PushCouponException;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.push.PushCouponRecordService;
import com.yeshi.fanli.service.inter.push.PushCouponService;
import com.yeshi.fanli.service.inter.push.PushService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONObject;
@@ -36,6 +38,9 @@
    
    @Resource
    private PushCouponRecordService pushCouponRecordService;
    @Resource
    private UserSystemCouponService userSystemCouponService;
    
    @Override
    public int deleteByPrimaryKey(Long id) {
@@ -80,21 +85,14 @@
    @Override
    @Transactional
    public void save(PushCoupon record) throws PushCouponException {
    public void save(PushCoupon record) throws PushCouponException,Exception {
        if (record == null) {
            throw new PushCouponException(1, "参数不正确");
        }
        String title = record.getTitle();
        String content = record.getContent();
        if (title == null || title.trim().length() == 0 || content == null || content.trim().length() == 0) {
            throw new PushCouponException(1, "标题或内容不能为空");
        }
        Date startTime = record.getStartTime();
        Date endTime = record.getEndTime();
        if (startTime == null || endTime == null) {
            throw new PushCouponException(1, "有效期时间不能为空");
        String uids = record.getUids();
        if (StringUtil.isNullOrEmpty(uids)) {
            throw new PushCouponException(1, "发放用户不能为空");
        }
        Integer amount = record.getAmount();
@@ -104,43 +102,52 @@
            throw new PushCouponException(1, "券数量范围是 1~5");
        }
        
        BigDecimal percent = record.getPercent();
        if (percent != null && (percent.compareTo(new BigDecimal(60)) > 0
                || percent.compareTo(new BigDecimal(1)) < 0)) {
            throw new PushCouponException(1, "券比例范围是1~60 的正整数");
        }
        Long id = record.getId();
        if (id == null) {
            // 新增
            record.setPushed(false);
            record.setCreateTime(new Date());
            record.setUpdateTime(new Date());
            // 插入数据
            insert(record);
            pushCouponMapper.insert(record);
            String[] uidArray = uids.split(",");
            if (uidArray != null) {
                for (int i = 0; i < uidArray.length; i++) {
                    Long uid = Long.parseLong(uidArray[i]);
                    // 插入记录
                    PushCouponRecord pushCouponRecord = new PushCouponRecord();
                    pushCouponRecord.setPushCoupon(record);
                    pushCouponRecord.setUid(uid);
                    pushCouponRecord.setCreateTime(new Date());
                    // 插入领取记录
                    pushCouponRecordService.insertSelective(pushCouponRecord);
                    // 直接发送券
                    userSystemCouponService.randomRewardCouponForPush(amount, uid);
                }
            }
        } else {
            // 修改
            PushCoupon current = selectByPrimaryKey(id);
            if (current == null) {
                throw new PushCouponException(1, "该记录已不存在");
            }
            if(current.isPushed()) {
                throw new PushCouponException(1, "已推送的信息不能修改");
            }
            current.setTitle(title);
            current.setContent(content);
            current.setAmount(amount);
            current.setStartTime(startTime);
            current.setEndTime(endTime);
            current.setUids(record.getUids());
            current.setRemark(record.getRemark());
            // 更新数据
            updateByPrimaryKey(current);
//
//            // 修改
//            PushCoupon current = selectByPrimaryKey(id);
//            if (current == null) {
//                throw new PushCouponException(1, "该记录已不存在");
//            }
//
//            if(current.isPushed()) {
//                throw new PushCouponException(1, "已推送的信息不能修改");
//            }
//            current.setAmount(amount);
//            current.setUids(record.getUids());
//            current.setRemark(record.getRemark());
//            current.setUpdateTime(new Date());
//            // 更新数据
//            updateByPrimaryKey(current);
        }
    }
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -27,8 +27,6 @@
import com.yeshi.fanli.entity.common.JumpDetailV2;
import com.yeshi.fanli.entity.money.UserMoneyDetail;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.push.PushCoupon;
import com.yeshi.fanli.entity.push.PushCouponRecord;
import com.yeshi.fanli.entity.system.SystemCoupon;
import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
@@ -282,8 +280,6 @@
        updateCounponInvalid(uid);
        // 退回券
        sendBackTimeOutCoupon(uid);
        // 活动领取券
        receivedCoupon(uid);
        
        List<UserSystemCouponVO> listVO = userSystemCouponMapper.getUserCouponVOList(start, count, uid);
        if (listVO == null || listVO.size() == 0) {
@@ -547,8 +543,6 @@
        updateCounponInvalid(uid);
        // 退回券
        sendBackTimeOutCoupon(uid);
        // 活动领取券
        receivedCoupon(uid);
        // 订单相关的券
        List<SystemCoupon> couponList = systemCouponService.getOrderCouponList();
@@ -576,9 +570,6 @@
        updateCounponInvalid(uid);
        // 退回券
        sendBackTimeOutCoupon(uid);
        // 活动领取券
        receivedCoupon(uid);
        // 商品相关的券
        List<SystemCoupon> couponList = systemCouponService.getGoodsCouponList();
@@ -1514,80 +1505,15 @@
    }
    
    @Override
    @Transactional
    public void receivedCoupon(Long uid) throws Exception {
        
        List<PushCoupon> list = pushCouponService.listQueryEffective();
        if (list == null || list.size() == 0) {
            return;
        }
        List<PushCouponRecord> listRecord = pushCouponRecordService.listByUid(uid);
        for (PushCoupon pushCoupon: list) {
            boolean receive = false;
            String uids = pushCoupon.getUids();
            if (uids == null || uids.trim().length() == 0) {
                receive = true;
            } else {
                String[] uidArray = uids.split(",");
                if (uidArray != null) {
                    for (int i = 0; i < uidArray.length; i++) {
                        String str_uid = uidArray[i];
                        if (str_uid != null && str_uid.trim().length() > 0) {
                            if(str_uid.equals(uid.toString())) {
                                receive = true;
                            }
                        }
                    }
                }
            }
            if (!receive) {
                continue;
            }
            if (listRecord != null && listRecord.size() > 0) {
                for (PushCouponRecord PushCouponRecord: listRecord) {
                     PushCoupon pushCoupon2 = PushCouponRecord.getPushCoupon();
                    if (pushCoupon.getId().equals(pushCoupon2.getId()) ) {
                        receive = false;
                        break;
                    }
                }
            }
            if (receive) {
                // 插入记录
                PushCouponRecord pushCouponRecord = new PushCouponRecord();
                pushCouponRecord.setPushCoupon(pushCoupon);
                pushCouponRecord.setUid(uid);
                pushCouponRecord.setCreateTime(new Date());
                pushCouponRecordService.insertSelective(pushCouponRecord);
                // 插入券
                randomRewardCouponForPush(pushCoupon, uid);
            }
        }
    }
    
    @Transactional
    public void randomRewardCouponForPush(PushCoupon pushCoupon, Long uid) throws Exception {
    public void randomRewardCouponForPush(Integer amount, Long uid) throws Exception {
        int coupon = 0;
        
        Integer amount = pushCoupon.getAmount();
        for (int i = 0; i < amount; i++) {
            BigDecimal percent = pushCoupon.getPercent();
            if (percent == null) {
                // 返利比-随机
                percent = new BigDecimal(randomNum());
            }
            // 系统随机
            BigDecimal percent = new BigDecimal(randomNum());
            
            // 查询奖励券
            SystemCoupon systemCoupon = systemCouponService.getCouponByTypeAndPercent(
@@ -1597,14 +1523,20 @@
                return;
            }
            
            // 结束日期
            // 今天在内  减去一天
            String endDay = DateUtil.plusDay(systemCoupon.getExpiryDay() - 1, new Date());
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date endTime = format.parse(endDay);
            UserSystemCoupon userCoupon = new UserSystemCoupon();
            userCoupon.setUid(uid);
            userCoupon.setSource(UserSystemCoupon.SOURCE_SYSTEM_PUSH);
            userCoupon.setSystemCoupon(systemCoupon);
            userCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
            userCoupon.setStateActivated(1);
            userCoupon.setStartTime(pushCoupon.getStartTime());
            userCoupon.setEndTime(pushCoupon.getEndTime());
            userCoupon.setStartTime(new Date());
            userCoupon.setEndTime(endTime);
            userCoupon.setCreateTime(new Date());
            userCoupon.setUpdateTime(new Date());
            // 插入数据库
@@ -1712,20 +1644,25 @@
        int result = 1;
        
        List<RandomProportion> list = new ArrayList<RandomProportion>();
        list.add(new RandomProportion(1,2,30));
        list.add(new RandomProportion(2,4,25));
        list.add(new RandomProportion(4,6,20));
        list.add(new RandomProportion(6,8,6));
        list.add(new RandomProportion(8,10,6));
        list.add(new RandomProportion(10,20,6));
        list.add(new RandomProportion(20,30,2));
        list.add(new RandomProportion(30,40,2));
        list.add(new RandomProportion(40,50,2));
        list.add(new RandomProportion(50,60,1));
        list.add(new RandomProportion(1, 22));
        list.add(new RandomProportion(2, 22));
        list.add(new RandomProportion(3, 22));
        list.add(new RandomProportion(4, 22));
        list.add(new RandomProportion(5, 20));
        list.add(new RandomProportion(6, 18));
        list.add(new RandomProportion(7, 16));
        list.add(new RandomProportion(8, 14));
        list.add(new RandomProportion(9, 12));
        list.add(new RandomProportion(10, 10));
        list.add(new RandomProportion(11, 8));
        list.add(new RandomProportion(12, 6));
        list.add(new RandomProportion(13, 4));
        list.add(new RandomProportion(14, 2));
        list.add(new RandomProportion(15, 1));
        int minRange = 0;
        int maxRange = 0;
        int randomNum = (int) (1 + Math.round(Math.random() * (99)));
        int randomNum = (int) (1 + Math.round(Math.random() * (199)));
        
        for (int i = 0; i < list.size(); i++) {
            
@@ -1735,11 +1672,8 @@
            maxRange = maxRange + probability;
            minRange = maxRange - probability;
            
            if (i == list.size() && randomNum > minRange && randomNum <= maxRange) {
                result = proportion.minNum + (int) (Math.random() * ((proportion.maxNum - proportion.minNum) + 1));
                break;
            } else if(randomNum > minRange && randomNum <= maxRange) {
                result = proportion.minNum + (int) (Math.random() * ((proportion.maxNum - proportion.minNum)));
            if(randomNum > minRange && randomNum <= maxRange) {
                result = proportion.num;
                break;
            }
        }
@@ -1748,15 +1682,13 @@
    }
    
    class RandomProportion {
        public int minNum;// 最小
        public int maxNum;// 最大
        public int num;//券值
        public int probability; // 概率
        
        RandomProportion () {}
        
        RandomProportion (int minNum, int maxNum, int probability) {
            this.minNum = minNum;
            this.maxNum = maxNum;
        RandomProportion (int num, int probability) {
            this.num = num;
            this.probability = probability;
        }
    }
fanli/src/main/java/com/yeshi/fanli/service/inter/push/PushCouponService.java
@@ -34,7 +34,7 @@
    public long countQuery(String key, Integer state) throws PushCouponException;
    
    public void save(PushCoupon record) throws PushCouponException;
    public void save(PushCoupon record) throws PushCouponException, Exception;
    /**
     * 执行推送
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponService.java
@@ -187,13 +187,6 @@
    public void copyLotteryPrize(Long uid, int platform, String device) throws Exception;
    
    /**
     * 领取券
     * @param uid
     * @throws Exception
     */
    public void receivedCoupon(Long uid) throws Exception;
    /**
     * 统计今日抽奖中的券数量
@@ -212,4 +205,11 @@
     */
    public void randomRewardCoupon(int num, Long uid, String source) throws Exception;
    
    /**
     * 后端直接发送券
     * @param record
     * @param uid
     */
    public void randomRewardCouponForPush(Integer amount , Long uid) throws Exception;
}