admin
2019-12-13 a3e7322a0aa6b5b13a84bc76923d0c6b68b13276
订单修改
7个文件已修改
2555 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ConfigControllerV2.java 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml 2202 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java 93 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java 86 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/HongBaoV2AddManager.java 34 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeOrderApiUtil.java 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ConfigControllerV2.java
@@ -17,6 +17,7 @@
import com.yeshi.fanli.entity.bus.homemodule.FloatAD.FloatADTypeEnum;
import com.yeshi.fanli.entity.bus.msg.MsgDeviceReadState;
import com.yeshi.fanli.entity.bus.user.UserActiveLog;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.entity.common.JumpDetailV2;
import com.yeshi.fanli.entity.config.AppHomeFloatImg;
import com.yeshi.fanli.entity.taobao.ClientTBPid;
@@ -30,13 +31,16 @@
import com.yeshi.fanli.service.inter.user.TBPidService;
import com.yeshi.fanli.service.inter.user.UserActiveLogService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.util.AESUtil;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.util.jd.JDUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.homemodule.FloatImgDetailVO;
import net.sf.json.JSONObject;
@@ -80,6 +84,12 @@
    @Resource
    private UserTaoLiJinNewbiesService userTaoLiJinNewbiesService;
    @Resource
    private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
    @Resource
    private RedisManager redisManager;
    /**
     * s 首页配置信息
@@ -159,20 +169,21 @@
        // 活动弹框
        List<FloatAD> listAD = new ArrayList<FloatAD>();
        List<FloatImgDetailVO> listVO = new ArrayList<FloatImgDetailVO>();
        List<FloatAD> list = floatADService.getValidByPosition(FloatAD.POSITION_INDEX);
        if (list != null && !list.isEmpty())
            listAD.addAll(list);
        for (int i = 0; i < listAD.size(); i++) {
            FloatAD floatAD = listAD.get(i);
            FloatADTypeEnum typeEnum = floatAD.getTypeEnum();
            if (typeEnum == FloatADTypeEnum.newUserRedPack && !userTaoLiJinNewbiesService.verifyHasReward(uid, acceptData.getDevice())) {
            if (typeEnum == FloatADTypeEnum.newUserRedPack
                    && !userTaoLiJinNewbiesService.verifyHasReward(uid, acceptData.getDevice())) {
                listAD.remove(i);
                i--;
                continue;
            }
            JumpDetailV2 jumpDetail = floatAD.getJumpDetail();
            if (jumpDetail != null) {
                jumpDetail = jumpDetailV2Service.selectByPrimaryKey(jumpDetail.getId());
@@ -478,9 +489,30 @@
     */
    @RequestMapping(value = "getElemeLink")
    public void getElemeLink(AcceptData acceptData, Long uid, String callback, PrintWriter out) {
        UserExtraTaoBaoInfo userInfoExtra = userExtraTaoBaoInfoService.getByUid(uid);
        if (userInfoExtra == null || StringUtil.isNullOrEmpty(userInfoExtra.getRelationId())) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(1001, "请绑定淘宝")));
            return;
        }
        String elmeLink = redisManager.getCommonString("elme-link-" + uid);
        if (StringUtil.isNullOrEmpty(elmeLink)) {
            elmeLink = TaoKeApiUtil.officialActivityConvert(TaoBaoConstant.TAOBAO_ELEME_PID.split("_")[3],
                    "1571715733668", userInfoExtra.getRelationId());
            if (!StringUtil.isNullOrEmpty(elmeLink)) {
                redisManager.cacheCommonString("elme-link-" + uid, elmeLink, 60 * 60);// 缓存1个小时
            }
        }
        JSONObject data = new JSONObject();
        data.put("hongBao", configService.get("eleme_hongbao_link").replace("{用户ID}", uid + ""));
        data.put("goods", configService.get("eleme_goods_link").replace("{用户ID}", uid + ""));
        // data.put("hongBao",
        // configService.get("eleme_hongbao_link").replace("{用户ID}", uid + ""));
        // data.put("goods",
        // configService.get("eleme_goods_link").replace("{用户ID}", uid + ""));
        data.put("hongBao", elmeLink);
        data.put("goods", elmeLink);
        ClientTBPid clientTBPid1 = new ClientTBPid(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_ELEME_PID,
                null, TaoBaoConstant.TAOBAO_ELEME_PID.split("_")[3]);
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java
@@ -361,7 +361,8 @@
        GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertTaoBao(goods, paramsDTO);
        if (goodsDetail != null && goodsDetail.getMoneyInfo() != null && userVIPInfoService.isVIP(uid)) {
            goodsDetail.getMoneyInfo().setFanliMoney(goodsDetail.getMoneyInfo().getMaxMoney());
            goodsDetail.getMoneyInfo().setShareMoney("¥"+ TaoBaoUtil.getGoodsHongBaoMoney(goods, hongBaoManageService.getVIPShareRate()));
            goodsDetail.getMoneyInfo().setShareMoney(
                    "¥" + TaoBaoUtil.getGoodsHongBaoMoney(goods, hongBaoManageService.getVIPShareRate()));
        }
        if (TaoBaoUtil.isYUShou(goods)) {
@@ -507,20 +508,22 @@
            OtherInfo otherInfo = new OtherInfo();
            otherInfo.setReduceHongBao(newUserHongBao);
            goodsDetail.setOtherInfo(otherInfo);
            // 专属标签
            List<ClientTextStyleVO> labels = new ArrayList<ClientTextStyleVO>();
            labels.add(new ClientTextStyleVO("新人专属", "#FE0014"));
            labels.add(new ClientTextStyleVO("实付0元", "#FF9600"));
            goodsDetail.setLabels(labels);
        } else {// 普通购买
            OtherInfo otherInfo = new OtherInfo();
            RewardCouponVO rewardCoupon = new RewardCouponVO();
            rewardCoupon.setJumpDetail(jumpDetailV2Service.getByTypeCache("web"));
            JSONObject params1 = new JSONObject();
            params1.put("url", configService.get("special_guide_reward_coupon_link"));
            if (!VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion()))
                params1.put("url", configService.get("special_guide_reward_coupon_link"));
            else
                params1.put("url", configService.get("vip_link"));
            rewardCoupon
                    .setMaxMoney("¥" + TaoBaoUtil.getGoodsHongBaoMoney(goods, hongBaoManageService.getVIPFanLiRate()));
            if (VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion())) {
@@ -615,7 +618,8 @@
        GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertJDGoods(jdGoods, paramsDTO);
        if (goodsDetail != null && goodsDetail.getMoneyInfo() != null && userVIPInfoService.isVIP(uid)) {
            goodsDetail.getMoneyInfo().setFanliMoney(goodsDetail.getMoneyInfo().getMaxMoney());
            goodsDetail.getMoneyInfo().setShareMoney("¥"+ JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getVIPShareRate()));
            goodsDetail.getMoneyInfo()
                    .setShareMoney("¥" + JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getVIPShareRate()));
        }
        // 附加信息
@@ -654,7 +658,10 @@
        rewardCoupon.setMaxMoneyPlus(maxMoneyPlus);
        rewardCoupon.setJumpDetail(jumpDetailV2Service.getByTypeCache("web"));
        JSONObject params1 = new JSONObject();
        params1.put("url", configService.get("special_guide_reward_coupon_link"));
        if (!VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion()))
            params1.put("url", configService.get("special_guide_reward_coupon_link"));
        else
            params1.put("url", configService.get("vip_link"));
        rewardCoupon.setMaxMoney("¥" + JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getVIPFanLiRate()));
        if (VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion())) {
@@ -807,7 +814,8 @@
        GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertPDDGoods(pddGoods, paramsDTO);
        if (goodsDetail != null && goodsDetail.getMoneyInfo() != null && userVIPInfoService.isVIP(uid)) {
            goodsDetail.getMoneyInfo().setFanliMoney(goodsDetail.getMoneyInfo().getMaxMoney());
            goodsDetail.getMoneyInfo().setShareMoney("¥"+ PinDuoDuoUtil.getGoodsFanLiMoney(pddGoods, hongBaoManageService.getVIPShareRate()));
            goodsDetail.getMoneyInfo().setShareMoney(
                    "¥" + PinDuoDuoUtil.getGoodsFanLiMoney(pddGoods, hongBaoManageService.getVIPShareRate()));
        }
        // 附加信息
@@ -815,7 +823,10 @@
        RewardCouponVO rewardCoupon = new RewardCouponVO();
        rewardCoupon.setJumpDetail(jumpDetailV2Service.getByTypeCache("web"));
        JSONObject params1 = new JSONObject();
        params1.put("url", configService.get("special_guide_reward_coupon_link"));
        if (!VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion()))
            params1.put("url", configService.get("special_guide_reward_coupon_link"));
        else
            params1.put("url", configService.get("vip_link"));
        rewardCoupon
                .setMaxMoney("¥" + PinDuoDuoUtil.getGoodsFanLiMoney(pddGoods, hongBaoManageService.getVIPFanLiRate()));
fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml
@@ -1,1139 +1,1063 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.order.CommonOrder">
        <id column="co_id" property="id" jdbcType="BIGINT" />
        <result column="co_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="co_source_type" property="sourceType" jdbcType="INTEGER" />
        <result column="co_source_position" property="sourcePosition"
            jdbcType="VARCHAR" />
        <result column="co_count" property="count" jdbcType="INTEGER" />
        <result column="co_state" property="state" jdbcType="INTEGER" />
        <result column="co_state_whole_order" property="stateWholeOrder"
            jdbcType="INTEGER" />
        <result column="co_estimate" property="estimate" jdbcType="DECIMAL" />
        <result column="co_eIncome" property="eIncome" jdbcType="DECIMAL" />
        <result column="co_payment" property="payment" jdbcType="DECIMAL" />
        <result column="co_settlement" property="settlement" jdbcType="DECIMAL" />
        <result column="co_third_create_time" property="thirdCreateTime"
            jdbcType="TIMESTAMP" />
        <result column="co_settle_time" property="settleTime" jdbcType="TIMESTAMP" />
        <result column="co_order_by" property="orderBy" jdbcType="INTEGER" />
        <result column="co_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="co_update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <result column="co_trade_id" property="tradeId" jdbcType="VARCHAR" />
        <result column="co_state_desc" property="stateDesc" jdbcType="VARCHAR" />
        <association property="userInfo" column="co_uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="co_uid" property="id" jdbcType="BIGINT" />
        </association>
        <association property="commonOrderGoods" column="co_order_goods_id"
            javaType="com.yeshi.fanli.entity.order.CommonOrderGoods">
            <id column="co_order_goods_id" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    <resultMap id="BaseDetailResultMap" type="com.yeshi.fanli.entity.order.CommonOrder">
        <id column="co_id" property="id" jdbcType="BIGINT" />
        <result column="co_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="co_source_type" property="sourceType" jdbcType="INTEGER" />
        <result column="co_source_position" property="sourcePosition"
            jdbcType="VARCHAR" />
        <result column="co_count" property="count" jdbcType="INTEGER" />
        <result column="co_state" property="state" jdbcType="INTEGER" />
        <result column="co_state_whole_order" property="stateWholeOrder"
            jdbcType="INTEGER" />
        <result column="co_estimate" property="estimate" jdbcType="DECIMAL" />
        <result column="co_eIncome" property="eIncome" jdbcType="DECIMAL" />
        <result column="co_payment" property="payment" jdbcType="DECIMAL" />
        <result column="co_settlement" property="settlement" jdbcType="DECIMAL" />
        <result column="co_third_create_time" property="thirdCreateTime"
            jdbcType="TIMESTAMP" />
        <result column="co_settle_time" property="settleTime" jdbcType="TIMESTAMP" />
        <result column="co_order_by" property="orderBy" jdbcType="INTEGER" />
        <result column="co_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="co_update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <result column="co_trade_id" property="tradeId" jdbcType="VARCHAR" />
        <result column="co_state_desc" property="stateDesc" jdbcType="VARCHAR" />
        <association property="userInfo" column="co_uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="co_uid" property="id" jdbcType="BIGINT" />
        </association>
        <association property="commonOrderGoods"
            resultMap="com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper.BaseResultMap" />
    </resultMap>
    <resultMap id="ResultMap" type="com.yeshi.fanli.vo.order.CommonOrderVO">
        <id column="co_id" property="id" jdbcType="BIGINT" />
        <result column="co_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="co_source_type" property="sourceType" jdbcType="INTEGER" />
        <result column="co_source_position" property="sourcePosition"
            jdbcType="VARCHAR" />
        <result column="co_count" property="count" jdbcType="INTEGER" />
        <result column="co_state" property="state" jdbcType="INTEGER" />
        <result column="co_state_whole_order" property="stateWholeOrder"
            jdbcType="INTEGER" />
        <result column="co_estimate" property="estimate" jdbcType="DECIMAL" />
        <result column="co_eIncome" property="eIncome" jdbcType="DECIMAL" />
        <result column="co_payment" property="payment" jdbcType="DECIMAL" />
        <result column="co_settlement" property="settlement" jdbcType="DECIMAL" />
        <result column="co_third_create_time" property="thirdCreateTime"
            jdbcType="TIMESTAMP" />
        <result column="co_settle_time" property="settleTime" jdbcType="TIMESTAMP" />
        <result column="co_order_by" property="orderBy" jdbcType="INTEGER" />
        <result column="co_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="co_update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <result column="totalMoney" property="hongBao" jdbcType="DECIMAL" />
        <result column="couponMoney" property="couponMoney" jdbcType="DECIMAL" />
        <result column="hongBaoState" property="hongBaoState" jdbcType="INTEGER" />
        <result column="hongBaoType" property="hongBaoType" jdbcType="INTEGER" />
        <result column="accountTime" property="accountTime" jdbcType="TIMESTAMP" />
        <result column="preAccountTime" property="preAccountTime"
            jdbcType="TIMESTAMP" />
        <result column="totalCount" property="totalCount" jdbcType="INTEGER" />
        <result column="totalSettlement" property="totalSettlement"
            jdbcType="DECIMAL" />
        <result column="totalPayment" property="totalPayment" jdbcType="DECIMAL" />
        <result column="userId" property="userId" jdbcType="VARCHAR" />
        <result column="userName" property="userName" jdbcType="VARCHAR" />
        <result column="userPortrait" property="userPortrait" jdbcType="VARCHAR" />
        <result column="hb_id" property="hongbaoId" jdbcType="BIGINT" />
        <result column="co_trade_id" property="tradeId" jdbcType="VARCHAR" />
        <result column="co_state_desc" property="stateDesc" jdbcType="VARCHAR" />
        <result column="co_uid" property="userId" jdbcType="VARCHAR" />
        <association property="userInfo" column="co_uid"
            resultMap="com.yeshi.fanli.dao.mybatis.UserInfoMapper.BaseResultMap" />
        <association property="commonOrderGoods" column="co_order_goods_id"
            resultMap="com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper.BaseResultMap" />
    </resultMap>
    <resultMap id="ThreeResultMap" type="com.yeshi.fanli.vo.order.CommonOrderVO">
        <id column="co_id" property="id" jdbcType="BIGINT" />
        <result column="co_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="co_source_type" property="sourceType" jdbcType="INTEGER" />
        <result column="co_source_position" property="sourcePosition"
            jdbcType="VARCHAR" />
        <result column="co_count" property="count" jdbcType="INTEGER" />
        <result column="co_state" property="state" jdbcType="INTEGER" />
        <result column="co_state_whole_order" property="stateWholeOrder"
            jdbcType="INTEGER" />
        <result column="co_estimate" property="estimate" jdbcType="DECIMAL" />
        <result column="co_eIncome" property="eIncome" jdbcType="DECIMAL" />
        <result column="co_payment" property="payment" jdbcType="DECIMAL" />
        <result column="co_settlement" property="settlement" jdbcType="DECIMAL" />
        <result column="co_third_create_time" property="thirdCreateTime"
            jdbcType="TIMESTAMP" />
        <result column="co_settle_time" property="settleTime" jdbcType="TIMESTAMP" />
        <result column="co_order_by" property="orderBy" jdbcType="INTEGER" />
        <result column="co_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="co_update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <result column="totalMoney" property="hongBao" jdbcType="DECIMAL" />
        <result column="couponMoney" property="couponMoney" jdbcType="DECIMAL" />
        <result column="hongBaoState" property="hongBaoState" jdbcType="INTEGER" />
        <result column="hongBaoType" property="hongBaoType" jdbcType="INTEGER" />
        <result column="accountTime" property="accountTime" jdbcType="TIMESTAMP" />
        <result column="preAccountTime" property="preAccountTime"
            jdbcType="TIMESTAMP" />
        <result column="totalCount" property="totalCount" jdbcType="INTEGER" />
        <result column="totalSettlement" property="totalSettlement"
            jdbcType="DECIMAL" />
        <result column="totalPayment" property="totalPayment" jdbcType="DECIMAL" />
        <result column="userId" property="userId" jdbcType="VARCHAR" />
        <result column="userName" property="userName" jdbcType="VARCHAR" />
        <result column="userPortrait" property="userPortrait" jdbcType="VARCHAR" />
        <result column="hb_id" property="hongbaoId" jdbcType="BIGINT" />
        <result column="co_trade_id" property="tradeId" jdbcType="VARCHAR" />
        <result column="co_state_desc" property="stateDesc" jdbcType="VARCHAR" />
        <association property="userInfo" column="co_uid"
            select="com.yeshi.fanli.dao.mybatis.UserInfoMapper.selectByPrimaryKey" />
        <association property="commonOrderGoods" column="co_order_goods_id"
            select="com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper.selectByPrimaryKey" />
    </resultMap>
    <resultMap id="OrderCountMap" type="com.yeshi.fanli.vo.order.OrderCountVO" >
        <result column="self" property="self" jdbcType="BIGINT" />
        <result column="shared" property="shared" jdbcType="BIGINT" />
        <result column="invite" property="invite" jdbcType="BIGINT" />
    </resultMap>
    <sql id="Base_Column_List">co_id,co_uid,co_order_no,co_source_type,co_source_position,co_order_goods_id,co_count,co_state,co_state_whole_order,co_estimate,co_eIncome,co_payment,co_settlement,co_third_create_time,co_settle_time,co_order_by,co_create_time,co_update_time,co_trade_id,co_state_desc
    </sql>
    <sql id="Order_Column_List">co_id,co_uid,co_order_no,co_source_type,co_source_position,
        co_order_goods_id,co_count,co_state,co_state_whole_order,
        co_estimate,co_eIncome,co_payment,co_settlement, co_third_create_time,
        MAX(co_settle_time) AS co_settle_time, co_order_by, co_create_time,
        co_update_time,co_state_desc
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_common_order where co_id = #{id,jdbcType=BIGINT}
    </select>
    <select id="countByOrderNOAndOrderType" resultType="java.lang.Integer">select
        count(co_id) from yeshi_ec_common_order where co_order_no=#{orderNO}
        and co_source_type=#{orderType}
    </select>
    <select id="selectByOrderNoAndOrderTypeAndOrderBy" resultMap="BaseResultMap">select
        * from yeshi_ec_common_order where co_order_no=#{orderNo} and
        co_source_type=#{orderType} and co_order_by=#{orderBy}
    </select>
    <select id="countByUidAndOrderStateWithOrderBalanceTime"
        resultType="java.lang.Long">SELECT COUNT(*) FROM yeshi_ec_common_order co WHERE
        co.`co_state`=#{state} and co.`co_uid`=#{uid} and co.`co_settle_time`
        is not null and co.`co_settle_time`&gt;=#{minDate} and
        #{maxDate}&gt;co.`co_settle_time`</select>
    <select id="listBySourceTypeAndOrderNo" resultMap="BaseResultMap">SELECT * FROM
        yeshi_ec_common_order co WHERE co.co_source_type=#{sourceType} and
        co_order_no=#{orderNo}
    </select>
    <select id="selectBySourceTypeAndTradeId" resultMap="BaseResultMap">SELECT *
        FROM
        yeshi_ec_common_order co WHERE co.co_source_type=#{sourceType} and
        co_trade_id=#{tradeId} limit 1
    </select>
    <select id="listBySourceTypeAndTradeId" resultMap="BaseResultMap">SELECT *
        FROM
        yeshi_ec_common_order co WHERE co.co_source_type=#{sourceType} and
        co_trade_id=#{tradeId}
    </select>
    <select id="listBySourceTypeAndTradeIdList" resultMap="BaseResultMap">
        SELECT *
        FROM
        yeshi_ec_common_order co WHERE
        co.co_source_type=#{sourceType}
        <if test="tradeIdList!=null">
            <foreach collection="tradeIdList" item="tradeId" open=" and ("
                close=")" separator=" or ">
                co.co_trade_id=#{tradeId}
            </foreach>
        </if>
    </select>
    <select id="listBySourceTypeAndStateAndThirdCrateTime"
        resultMap="BaseResultMap">
        SELECT *
        FROM
        yeshi_ec_common_order co WHERE
        co.co_source_type=#{sourceType}
        <if test="state!=null">
            and co_state=#{state}
        </if>
        <if test="minTime!=null">
            and UNIX_TIMESTAMP(co_third_create_time)*1000>=#{minTime}
        </if>
        <if test="maxTime!=null">
            and #{maxTime}> UNIX_TIMESTAMP(co_third_create_time)*1000
        </if>
        order by co_id desc
        limit #{start},#{count}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_common_order where co_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.order.CommonOrder"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_common_order
        (co_id,co_uid,co_order_no,co_source_type,co_source_position,co_order_goods_id,co_count,co_state,co_estimate,co_eIncome,co_payment,co_settlement,co_third_create_time,co_settle_time,co_create_time,co_update_time,co_state_whole_order,co_order_by,co_trade_id,co_state_desc)
        values
        (#{id,jdbcType=BIGINT},#{userInfo.id,jdbcType=BIGINT},#{orderNo,jdbcType=VARCHAR},#{sourceType,jdbcType=INTEGER},#{sourcePosition,jdbcType=VARCHAR},#{commonOrderGoods.id,jdbcType=BIGINT},#{count,jdbcType=INTEGER},#{state,jdbcType=INTEGER},#{estimate,jdbcType=DECIMAL},#{eIncome,jdbcType=DECIMAL},#{payment,jdbcType=DECIMAL},#{settlement,jdbcType=DECIMAL},#{thirdCreateTime,jdbcType=TIMESTAMP},#{settleTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{stateWholeOrder,jdbcType=INTEGER},#{orderBy,jdbcType=INTEGER},#{tradeId,jdbcType=VARCHAR},#{stateDesc,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.order.CommonOrder"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_common_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">co_id,</if>
            <if test="userInfo != null">co_uid,</if>
            <if test="orderNo != null">co_order_no,</if>
            <if test="sourceType != null">co_source_type,</if>
            <if test="sourcePosition != null">co_source_position,</if>
            <if test="commonOrderGoods != null">co_order_goods_id,</if>
            <if test="count != null">co_count,</if>
            <if test="state != null">co_state,</if>
            <if test="stateWholeOrder != null">co_state_whole_order,</if>
            <if test="estimate != null">co_estimate,</if>
            <if test="eIncome != null">co_eIncome,</if>
            <if test="payment != null">co_payment,</if>
            <if test="settlement != null">co_settlement,</if>
            <if test="thirdCreateTime != null">co_third_create_time,</if>
            <if test="settleTime != null">co_settle_time,</if>
            <if test="orderBy != null">co_order_by,</if>
            <if test="createTime != null">co_create_time,</if>
            <if test="updateTime != null">co_update_time,</if>
            <if test="tradeId != null">co_trade_id,</if>
            <if test="stateDesc != null">co_state_desc,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="userInfo != null">#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="orderNo != null">#{orderNo,jdbcType=VARCHAR},</if>
            <if test="sourceType != null">#{sourceType,jdbcType=INTEGER},</if>
            <if test="sourcePosition != null">#{sourcePosition,jdbcType=VARCHAR},</if>
            <if test="commonOrderGoods != null">#{commonOrderGoods.id,jdbcType=BIGINT},</if>
            <if test="count != null">#{count,jdbcType=INTEGER},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="stateWholeOrder != null">#{stateWholeOrder,jdbcType=INTEGER},</if>
            <if test="estimate != null">#{estimate,jdbcType=DECIMAL},</if>
            <if test="eIncome != null">#{eIncome,jdbcType=DECIMAL},</if>
            <if test="payment != null">#{payment,jdbcType=DECIMAL},</if>
            <if test="settlement != null">#{settlement,jdbcType=DECIMAL},</if>
            <if test="thirdCreateTime != null">#{thirdCreateTime,jdbcType=TIMESTAMP},</if>
            <if test="settleTime != null">#{settleTime,jdbcType=TIMESTAMP},</if>
            <if test="orderBy != null">#{orderBy,jdbcType=INTEGER},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="tradeId != null">#{tradeId,jdbcType=VARCHAR},</if>
            <if test="stateDesc != null">#{stateDesc,jdbcType=VARCHAR}</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.order.CommonOrder">update
        yeshi_ec_common_order set co_uid =
        #{userInfo.id,jdbcType=BIGINT},co_order_no =
        #{orderNo,jdbcType=VARCHAR},co_source_type =
        #{sourceType,jdbcType=INTEGER},co_source_position =
        #{sourcePosition,jdbcType=VARCHAR},co_order_goods_id =
        #{commonOrderGoods.id,jdbcType=BIGINT},co_count =
        #{count,jdbcType=INTEGER},co_state =
        #{state,jdbcType=INTEGER},co_state_whole_order =
        #{stateWholeOrder,jdbcType=INTEGER},co_estimate =
        #{estimate,jdbcType=DECIMAL},co_eIncome =
        #{eIncome,jdbcType=DECIMAL},co_payment =
        #{payment,jdbcType=DECIMAL},co_settlement =
        #{settlement,jdbcType=DECIMAL},co_third_create_time =
        #{thirdCreateTime,jdbcType=TIMESTAMP},co_settle_time =
        #{settleTime,jdbcType=TIMESTAMP},co_order_by =
        #{orderBy,jdbcType=INTEGER},co_create_time =
        #{createTime,jdbcType=TIMESTAMP},co_update_time =
        #{updateTime,jdbcType=TIMESTAMP} ,co_trade_id
        =#{tradeId,jdbcType=VARCHAR},co_state_desc
        =#{stateDesc,jdbcType=VARCHAR} where co_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.order.CommonOrder">
        update yeshi_ec_common_order
        <set>
            <if test="userInfo != null">co_uid=#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="orderNo != null">co_order_no=#{orderNo,jdbcType=VARCHAR},</if>
            <if test="sourceType != null">co_source_type=#{sourceType,jdbcType=INTEGER},</if>
            <if test="sourcePosition != null">co_source_position=#{sourcePosition,jdbcType=VARCHAR},
            </if>
            <if test="commonOrderGoods != null">co_order_goods_id=#{commonOrderGoods.id,jdbcType=BIGINT},
            </if>
            <if test="count != null">co_count=#{count,jdbcType=INTEGER},</if>
            <if test="state != null">co_state=#{state,jdbcType=INTEGER},</if>
            <if test="stateWholeOrder != null">co_state_whole_order=#{stateWholeOrder,jdbcType=INTEGER},
            </if>
            <if test="estimate != null">co_estimate=#{estimate,jdbcType=DECIMAL},</if>
            <if test="eIncome != null">co_eIncome=#{eIncome,jdbcType=DECIMAL},</if>
            <if test="payment != null">co_payment=#{payment,jdbcType=DECIMAL},</if>
            <if test="settlement != null">co_settlement=#{settlement,jdbcType=DECIMAL},</if>
            <if test="thirdCreateTime != null">co_third_create_time=#{thirdCreateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="settleTime != null">co_settle_time=#{settleTime,jdbcType=TIMESTAMP},</if>
            <if test="orderBy != null">co_order_by=#{orderBy,jdbcType=INTEGER},</if>
            <if test="createTime != null">co_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">co_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="id !=null">co_id =#{id,jdbcType=BIGINT},</if>
            <if test="tradeId !=null">co_trade_id =#{tradeId,jdbcType=VARCHAR},</if>
            <if test="stateDesc !=null">co_state_desc =#{stateDesc,jdbcType=VARCHAR},</if>
        </set>
        where co_id = #{id,jdbcType=BIGINT}
    </update>
    <sql id="SELECT_PARAM_ORDER_STATE">
        <if test="orderState != null and orderState ==  1">
            <!-- 有效订单: 整个订单有效 -->
            AND <![CDATA[co.`co_state` <> 3]]>
            AND (co.co_state_whole_order = 1 or co.co_state_whole_order = 2)
        </if>
        <if test="orderState != null and orderState ==  2">
            AND co.co_state = 3
            <!-- 维权订单 -->
        </if>
        <if test="orderState != null and orderState ==  3">
            <!-- 整个订单失效 -->
            AND co.co_state_whole_order = 3
        </if>
        <if test="orderState != null and orderState ==  4">
            <!-- 已收货订单 -->
            AND co.co_state = 2
        </if>
    </sql>
    <sql id="SELECT_PARAM_ORDER_CREATE_TIME">
        <if test="startTime != null and startTime != '' ">AND <![CDATA[co.co_third_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null and endTime != '' ">AND <![CDATA[co.co_third_create_time <= #{endTime}]]>
        </if>
        <if test="day == 1">
            <!-- 今天 -->
            AND TO_DAYS(co.`co_third_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day == 2">
            <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(co.`co_third_create_time`) = 1
        </if>
        <if test="day == 3 or day == 10">
            <!-- 本月 -->
            AND DATE_FORMAT(co.`co_third_create_time`,'%Y%m') =    DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day == 4">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),    DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
        </if>
        <if test="day == 6">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),    DATE_FORMAT(co.`co_third_create_time`, '%Y%m')) = 1
        </if>
        <if test="day == 11"> <!-- 近3个月产生 -->
            AND co.`co_third_create_time` BETWEEN DATE_SUB(NOW(),INTERVAL 3 MONTH) AND NOW()
        </if>
        <if test="day == 12"> <!-- 近半年产生  -->
            AND co.`co_third_create_time` BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW()
        </if>
    </sql>
    <sql id="SELECT_PARAM_HONGBAO_TYPE">
        <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (v2.hb_type =1 or v2.hb_type =2)
        </if>
        <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND v2.`hb_type` = 20
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (v2.`hb_type` = 5 OR v2.`hb_type` = 6 OR v2.`hb_type` = 7 OR v2.`hb_type` = 21 OR v2.`hb_type` = 22)
        </if>
    </sql>
    <sql id="SELECT_PARAM_HONGBAO_STATE">
        <if test="state != null and state == 1">
            <!-- 未到账 -->
            AND (hb.hb_state = 1 or hb.hb_state = 2)
        </if>
        <if test="state != null and state == 2">
            <!-- 已到账 -->
            AND hb.hb_state = 3
        </if>
        <if test="state != null and state == 3">
            <!-- 红包已失效、整个订单失效 -->
            AND hb.hb_state =4 AND co.co_state_whole_order = 3
        </if>
    </sql>
    <sql id="Hongbao_Column_List">hb_id,hb_uid,hb_urank,hb_pid,hb_type,hb_state,hb_pre_get_time,hb_get_time,hb_version,
        IF(v2.`hb_state` = 4, 0, v2.hb_money)AS hb_money
    </sql>
    <select id="listUserOrder" resultMap="ResultMap">
        <!-- 查询用户订单 -->
        SELECT COALESCE(SUM(hb.`hb_money`),0)AS totalMoney, hb.hb_state AS
        hongBaoState, hb.`hb_type` AS hongBaoType, MAX(hb.`hb_get_time`) AS
        accountTime, MAX(hb.`hb_pre_get_time`) AS preAccountTime,
        <include refid="Order_Column_List" />
        FROM yeshi_ec_hongbao_order ho
        LEFT JOIN (SELECT
        <include refid="Hongbao_Column_List" />
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= #{uid} AND <![CDATA[v2.`hb_type`<> 10 ]]>
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <if test="type == 2 and day == 5"> <!-- 本月月将要到账分享订单 -->
            AND DATE_FORMAT(v2.`hb_pre_get_time`,'%Y%m') =    DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="type == 3 and day == 5"> <!-- 本月将要到账邀请订单 -->
            AND DATE_FORMAT(v2.`hb_pre_get_time`,'%Y%m') =    DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <!-- 红包类型 -->
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <!-- 订单时间 -->
        <include refid="SELECT_PARAM_HONGBAO_STATE" />
        <!-- 订单号查询 -->
        <if test="orderNo != null and orderNo !='' ">AND co.co_order_no = #{orderNo}</if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type` ORDER BY
        co.co_third_create_time DESC LIMIT ${start},${count}
    </select>
    <select id="countUserOrder" resultType="java.lang.Long">
        <!-- 统计用户订单数量 -->
        SELECT IFNULL(COUNT(ho_id),0) FROM (SELECT ho.ho_id FROM
        yeshi_ec_hongbao_order ho LEFT JOIN (SELECT
        <include refid="Hongbao_Column_List" />
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= #{uid} AND <![CDATA[v2.`hb_type`<> 10 ]]>
        <include refid="SELECT_PARAM_HONGBAO_TYPE" /> <!-- 红包类型 -->
        <if test="type == 2 and day == 5"> <!-- 本月月将要到账分享订单 -->
            AND DATE_FORMAT(v2.`hb_pre_get_time`,'%Y%m') =    DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="type == 3 and day == 5"> <!-- 本月将要到账邀请订单 -->
            AND DATE_FORMAT(v2.`hb_pre_get_time`,'%Y%m') =    DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <!-- 订单时间 -->
        <include refid="SELECT_PARAM_HONGBAO_STATE" />
        <!-- 订单号查询 -->
        <if test="orderNo != null and orderNo !='' ">AND co.co_order_no = #{orderNo}</if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type` )A
    </select>
    <select id="listOrderGoodsInfo" resultMap="ResultMap"
        parameterType="java.util.List">
        <!-- 查询用户订单商品信息 -->
        SELECT COALESCE(SUM(tc.`co_payment`),0)AS
        totalPayment,COALESCE(SUM(tc.`co_settlement`),0)AS totalSettlement,
        COALESCE(SUM(tc.`co_count`),0)AS
        totalCount,tc.`co_source_type`,tc.`co_order_no`,tg.*,tc.co_id FROM
        yeshi_ec_common_order_goods tg LEFT JOIN yeshi_ec_common_order tc ON
        tc.`co_order_goods_id` = tg.`cog_id` WHERE
        <foreach collection="list" item="item" separator=" OR ">(tc.`co_source_type`
            = #{item.sourceType,jdbcType=INTEGER} AND tc.`co_order_no` =
            #{item.orderNo,jdbcType=VARCHAR})
        </foreach>
        GROUP BY tc.`co_order_no`,tc.`co_order_goods_id`
    </select>
    <select id="countHistoryOrder" resultType="java.util.HashMap">
        <!-- 统计历史订单数量 -->
        SELECT SUM(A.self)AS totalSelf,SUM(A.shared)AS
        totalShared,SUM(A.invite)AS totalInvite FROM (
        <!-- 返利订单 -->
        SELECT IFNULL(COUNT(ho_id),0) AS self,0 AS shared,0 AS invite FROM
        (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT *
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= ${uid} AND
        (v2.`hb_type` = 1 OR v2.`hb_type` = 2) ) hb ON
        hb.hb_id=ho.`ho_hongbao_id`
        <!-- 自购订单 -->
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL and hb.hb_state!=4
        <if test="day != null and day == 1">
            <!-- 今天 -->
            AND TO_DAYS(co.`co_third_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">
            <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(co.co_third_create_time) = 1
        </if>
        <if test="day != null and day == 3">
            <!-- 本月 -->
            AND DATE_FORMAT(co.`co_third_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)YX
        UNION ALL
        <!-- 分享订单 -->
        SELECT 0 AS self,IFNULL(COUNT(ho_id),0) AS shared,0 AS invite FROM
        (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT *
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= ${uid} AND v2.`hb_type`
        = 20 ) hb ON hb.hb_id=ho.`ho_hongbao_id`
        <!-- 分享订单 -->
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL and hb.hb_state!=4
        <if test="day != null and day == 1">
            <!-- 今天 -->
            AND TO_DAYS(co.`co_third_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">
            <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(co.`co_third_create_time`) = 1
        </if>
        <if test="day != null and day == 3">
            <!-- 本月 -->
            AND DATE_FORMAT(co.`co_third_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)WQ
        UNION ALL
        <!-- 邀请订单 -->
        SELECT 0 AS self,0 AS shared,IFNULL(COUNT(ho_id),0) AS invite FROM
        (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT *
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= ${uid} AND
        (v2.`hb_type` = 5 OR v2.`hb_type` = 6 OR v2.`hb_type` = 7 OR
        v2.`hb_type` = 21 OR v2.`hb_type` = 22 ) ) hbp ON
        hbp.hb_pid=ho.`ho_hongbao_id` LEFT JOIN yeshi_ec_common_order co ON
        co.`co_id`=ho.`ho_order_id` WHERE hbp.hb_id IS NOT NULL and
        hbp.hb_state!=4
        <if test="day != null and day == 1">
            <!-- 今天 -->
            AND TO_DAYS(co.`co_third_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">
            <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(co.`co_third_create_time`) = 1
        </if>
        <if test="day != null and day == 3">
            <!-- 本月 -->
            AND DATE_FORMAT(co.`co_third_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)SX )A
    </select>
    <sql id="OrderCountQuery">
        WHERE co.`co_state_whole_order`<![CDATA[<>]]>3
        <if test="day == 1"> <!-- 今天 -->
            AND TO_DAYS(co.`co_third_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day == 2"> <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(co.`co_third_create_time`) = 1
        </if>
        <if test="day == 3"> <!-- 本月 -->
            AND DATE_FORMAT(co.`co_third_create_time`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day == 4"> <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
        </if>
        <!-- 订单来源 -->
        <if test="source != null and source != 0">AND co.co_source_type = #{source}</if>
    </sql>
    <select id="getOrderCount" resultMap="OrderCountMap">
        SELECT sum(self) as self,sum(shared) as shared,sum(invite) as invite from
        (
            SELECT IFNULL(COUNT(co_order_no),0)AS self,0 AS shared,0 AS invite FROM
                (SELECT co.`co_order_no` FROM (SELECT * FROM yeshi_ec_hongbao_v2 v WHERE v.`hb_uid`= ${uid} AND v.`hb_type` = 1)v2
                LEFT JOIN yeshi_ec_hongbao_order ho ON ho.`ho_hongbao_id` = IF(v2.hb_pid IS NULL,v2.hb_id,v2.hb_pid)
                LEFT JOIN yeshi_ec_common_order co ON co.`co_id` = ho.`ho_order_id`
                <include refid="OrderCountQuery"></include>
                GROUP BY co.`co_order_no`,co.`co_source_type`)A
            UNION ALL
            SELECT 0 AS self,IFNULL(COUNT(co_order_no),0)AS shared,0 AS invite FROM
                (SELECT co.`co_order_no` FROM (SELECT * FROM yeshi_ec_hongbao_v2 v WHERE v.`hb_uid`= ${uid} AND v.`hb_type` = 20)v2
                LEFT JOIN yeshi_ec_hongbao_order ho ON ho.`ho_hongbao_id` = IF(v2.hb_pid IS NULL,v2.hb_id,v2.hb_pid)
                LEFT JOIN yeshi_ec_common_order co ON co.`co_id` = ho.`ho_order_id`
                <include refid="OrderCountQuery"></include>
                GROUP BY co.`co_order_no`,co.`co_source_type`)A
            UNION ALL
            SELECT 0 AS self,0 AS shared,IFNULL(COUNT(co_order_no),0)AS invite FROM
                (SELECT co.`co_order_no` FROM (SELECT * FROM yeshi_ec_hongbao_v2 v
                     WHERE v.`hb_uid`= ${uid}
                     AND (v.`hb_type` = 5 OR v.`hb_type` = 6 OR v.`hb_type` = 7 OR v.`hb_type` = 21 OR v.`hb_type` = 22))v2
                LEFT JOIN yeshi_ec_hongbao_order ho ON ho.`ho_hongbao_id` = IF(v2.hb_pid IS NULL,v2.hb_id,v2.hb_pid)
                LEFT JOIN yeshi_ec_common_order co ON co.`co_id` = ho.`ho_order_id`
                <include refid="OrderCountQuery"></include>
                GROUP BY co.`co_order_no`,co.`co_source_type`)A
        )B
    </select>
    <select id="countUserOrderToApp" resultType="Long">
            <!-- 有效订单 -->
        SELECT IFNULL(COUNT(ho_id),0) FROM
            (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
              LEFT JOIN
               ( SELECT * FROM yeshi_ec_hongbao_v2 v2
                 WHERE v2.`hb_uid`=${uid}
                    <include refid="SELECT_PARAM_HONGBAO_TYPE" />
                    <if test="state != null and state == 1">
                        <!-- 未到账 -->
                        AND (v2.hb_state = 1 or v2.hb_state = 2)
                    </if>
                    <if test="state != null and state == 2">
                        <!-- 已到账 -->
                        AND v2.hb_state = 3
                    </if>
                    <if test="state != null and state == 3">
                        <!-- 红包已失效 -->
                        AND v2.hb_state =4
                    </if>
                ) hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
            LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
            WHERE hb.hb_id IS NOT NULL <![CDATA[AND co.`co_state` <> 3]]>
            <if test="stateOrder == 1"> <!-- 有效订单 -->
                AND (co.`co_state_whole_order` =1 OR co.`co_state_whole_order` = 2)
            </if>
            <if test="stateOrder == 2"> <!-- 维权订单 -->
                AND co.`co_state` = 3
            </if>
            <if test="stateOrder == 3"> <!-- 失效订单 -->
                AND co.`co_state_whole_order` = 3
            </if>
            <!-- 订单时间 -->
            <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
            <!-- 订单来源 -->
            <if test="source != null">AND co.co_source_type = #{source}</if>
            GROUP BY co.`co_order_no`, co.`co_source_type`
            )A
    </select>
    <!--
    <select id="countByUidAndOrderState" resultType="java.util.HashMap">
        SELECT SUM(A.valid)AS totalValid, SUM(A.proces)AS
        totalProces,SUM(A.Invalid)AS totalInvite FROM (
        有效订单
        SELECT IFNULL(COUNT(ho_id),0) AS valid,0 AS proces,0 AS Invalid FROM
        (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT *
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`=${uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        ) hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL <![CDATA[AND co.`co_state` <> 3]]>
        AND (co.`co_state_whole_order` =1 OR co.`co_state_whole_order` = 2)
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        订单来源
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)YX
        UNION ALL
        维权订单
        SELECT 0 AS valid,IFNULL(COUNT(ho_id),0) AS proces,0 AS Invalid FROM
        (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT *
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`=${uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        ) hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL AND co.`co_state` = 3
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        订单来源
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)WQ
        UNION ALL
        失效订单
        SELECT 0 AS valid,0 AS proces,IFNULL(COUNT(ho_id),0) AS Invalid FROM
        (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT *
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`=${uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        ) hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL AND co.`co_state_whole_order` = 3
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        订单来源
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)SX )A
    </select> -->
    <select id="countBonusOrderNumber" resultType="java.lang.Long">
        <!-- 奖金统计:订单数量 -->
        SELECT IFNULL(COUNT(ho_id),0) FROM (SELECT ho.`ho_id` FROM
        yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT * FROM
        yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`=${uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        ) hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type` )A
    </select>
    <select id="countBonusOrderMoney" resultType="java.math.BigDecimal">
        <!-- 奖金统计:订单总返利金额 去掉已失效 -->
        SELECT COALESCE(SUM(hb.`hb_money`),0)AS totalmoney FROM
        yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT
        <include refid="Hongbao_Column_List" />
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`=${uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        AND (v2.hb_state = 1 or v2.hb_state = 2 or v2.hb_state = 3) ) hb ON
        IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id` LEFT JOIN
        yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` WHERE hb.hb_id
        IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <if test="day != null and day == 4">
            AND co.`co_state` = 2
            <!-- 上月 :统计已收货 -->
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
    </select>
    <select id="countBonusOrderMoneyAndNumber" resultType="java.util.HashMap">
        SELECT COUNT(*) AS totalNum, CAST(SUM(moneys) AS DECIMAL(19,2)) AS
        totalmoney FROM (SELECT CAST(SUM(hb.`hb_money`) AS DECIMAL(19,2))AS
        moneys FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT
        <include refid="Hongbao_Column_List" />
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`=${uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        AND (v2.hb_state = 1 or v2.hb_state = 2 or v2.hb_state = 3) ) hb ON
        IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id` LEFT JOIN
        yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` WHERE hb.hb_id
        IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <if test="day != null and day == 4">AND co.`co_state` = 2</if> <!-- 上月 :统计已收货 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type` )A
    </select>
    <sql id="SELECT_HONGBAO_STATE">
        <if test="state != null and state == 1">
            <!-- 未到账 -->
            AND (v2.hb_state = 1 or v2.hb_state = 2)
        </if>
        <if test="state != null and state == 2">
            <!-- 已到账 -->
            AND v2.hb_state = 3
        </if>
        <if test="state != null and state == 3">
            <!-- 红包已失效 -->
            AND v2.hb_state =4
        </if>
    </sql>
    <select id="listQueryByUid" resultMap="ResultMap">
        <!-- 查询用户订单 -->
        SELECT hb.`hb_money` AS totalMoney, hb.hb_state AS hongBaoState,
        hb.`hb_type` AS hongBaoType, hb.`hb_get_time` AS accountTime,
        hb.`hb_pre_get_time` AS preAccountTime, co.*,cog.* FROM
        yeshi_ec_hongbao_order ho LEFT JOIN (SELECT * FROM yeshi_ec_hongbao_v2
        v2 WHERE v2.`hb_uid`= #{uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` LEFT
        JOIN yeshi_ec_common_order_goods cog ON cog.`cog_id`=
        co.`co_order_goods_id` WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <!-- 订单时间 -->
        <if test="orderNo != null and orderNo !='' ">AND co.co_order_no = #{orderNo}</if>
        ORDER BY co.co_third_create_time DESC LIMIT ${start},${count}
    </select>
    <select id="countQueryByUid" resultType="java.lang.Long">
        <!-- 统计用户订单数量 -->
        SELECT IFNULL(COUNT(ho_id),0) FROM (SELECT ho.ho_id FROM
        yeshi_ec_hongbao_order ho LEFT JOIN (SELECT * FROM yeshi_ec_hongbao_v2
        v2 WHERE v2.`hb_uid`= #{uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <!-- 订单时间 -->
        <if test="orderNo != null and orderNo !='' ">AND co.co_order_no = #{orderNo}</if>
        )A
    </select>
    <select id="getBuFenOrderState" resultMap="ResultMap">SELECT
        co.co_state,v2.`hb_state` AS hongBaoState FROM `yeshi_ec_common_order`
        co LEFT JOIN yeshi_ec_hongbao_order ho ON co.`co_id`=ho.`ho_order_id`
        LEFT JOIN yeshi_ec_hongbao_v2 v2 ON IF(v2.hb_pid IS
        NULL,v2.hb_id,v2.hb_pid)=ho.`ho_hongbao_id` WHERE co.`co_order_no` =
        #{orderNo} AND co.co_state<![CDATA[<>]]>
        4 AND v2.hb_uid = #{uid} ORDER BY co.`co_state` DESC LIMIT 1
    </select>
    <select id="listQuery" resultMap="ThreeResultMap">
        SELECT A.*,u.id AS userId,u.`nick_name` AS userName,u.`portrait` AS
        userPortrait FROM (SELECT hb.hb_id,hb.hb_uid,hb.`hb_money` AS
        totalMoney, hb.hb_state AS hongBaoState, hb.`hb_type` AS hongBaoType,
        hb.`hb_get_time` AS accountTime, hb.`hb_pre_get_time` AS
        preAccountTime, co.* FROM yeshi_ec_hongbao_order ho LEFT JOIN
        (SELECT *
        FROM yeshi_ec_hongbao_v2 v2 WHERE 1=1
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        <if test="listShopId != null">
            LEFT JOIN yeshi_ec_common_order_goods g  ON co.`co_order_goods_id`=g.`cog_id`
        </if>
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <if test="startTime != null and startTime != '' ">AND <![CDATA[co.co_third_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null and endTime != '' ">AND <![CDATA[co.co_third_create_time <= #{endTime}]]>
        </if>
        <if test="key != null and key != '' ">
            <if test="keyType == 1 ">AND co.co_order_no = '${key}'</if>
            <if test="keyType == 2 ">AND hb.hb_uid = ${key}</if>
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        <if test="listGoodsId != null">
            <foreach collection="listGoodsId" item="goodsId" open=" and (" separator=" or " close=")">
                co.`co_order_goods_id` =#{goodsId}
            </foreach>
        </if>
        <if test="listShopId != null">
            <foreach collection="listShopId" item="shopId" open=" and (" separator=" or " close=")">
                g.`cog_shop_id` =#{shopId}
            </foreach>
        </if>
        <if test="minTime != null"> <!-- 高风险订单 -->
            AND co.`co_third_create_time`>#{minTime} AND <![CDATA[ (co.`co_estimate`>=  ${money} OR co.`co_eIncome`> ${money})]]>
        </if>
        ORDER BY co.co_third_create_time DESC LIMIT ${start},${count} ) A LEFT
        JOIN yeshi_ec_user u ON u.id = A.hb_uid
    </select>
    <select id="listQueryWithNoChild" resultMap="ThreeResultMap">
        SELECT A.*,u.id AS userId,u.`nick_name` AS userName,u.`portrait` AS
        userPortrait FROM (SELECT hb.hb_id,hb.hb_uid,hb.`hb_money` AS
        totalMoney, hb.hb_state AS hongBaoState, hb.`hb_type` AS hongBaoType,
        hb.`hb_get_time` AS accountTime, hb.`hb_pre_get_time` AS
        preAccountTime, co.* FROM yeshi_ec_hongbao_order ho LEFT JOIN
        (SELECT *
        FROM yeshi_ec_hongbao_v2 v2 WHERE 1=1
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON hb.hb_id=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co    ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <if test="startTime != null and startTime != '' ">AND <![CDATA[co.co_third_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null and endTime != '' ">AND <![CDATA[co.co_third_create_time <= #{endTime}]]>
        </if>
        <if test="key != null and key != '' ">
            <if test="keyType == 1 ">AND co.co_order_no = '${key}'</if>
            <if test="keyType == 2 ">AND hb.hb_uid = ${key}</if>
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        ORDER BY co.co_third_create_time DESC LIMIT ${start},${count} ) A LEFT
        JOIN yeshi_ec_user u ON u.id = A.hb_uid
    </select>
    <select id="countQuery" resultType="java.lang.Long">
        SELECT count(ho.ho_id) FROM yeshi_ec_hongbao_order ho LEFT JOIN
        (SELECT * FROM yeshi_ec_hongbao_v2 v2 WHERE 1=1
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        <if test="listShopId != null">
            LEFT JOIN yeshi_ec_common_order_goods g  ON co.`co_order_goods_id`=g.`cog_id`
        </if>
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <if test="startTime != null and startTime != '' ">AND <![CDATA[co.co_third_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null and endTime != '' ">AND <![CDATA[co.co_third_create_time <= #{endTime}]]>
        </if>
        <if test="key != null and key != '' ">
            <if test="keyType == 1 ">AND co.co_order_no = '${key}'</if>
            <if test="keyType == 2 ">AND hb.hb_uid = ${key}</if>
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        <if test="listGoodsId != null">
            <foreach collection="listGoodsId" item="goodsId" open=" and (" separator=" or " close=")">
                co.`co_order_goods_id` =#{goodsId}
            </foreach>
        </if>
        <if test="listShopId != null">
            <foreach collection="listShopId" item="shopId" open=" and (" separator=" or " close=")">
                g.`cog_shop_id` =#{shopId}
            </foreach>
        </if>
        <if test="minTime != null"> <!-- 高风险订单 -->
            AND co.`co_third_create_time`>#{minTime} AND <![CDATA[ (co.`co_estimate`>=  ${money} OR co.`co_eIncome`> ${money})]]>
        </if>
    </select>
    <select id="countQueryWithNoChild" resultType="java.lang.Long">
        SELECT count(ho.ho_id) FROM yeshi_ec_hongbao_order ho LEFT JOIN
        (SELECT * FROM yeshi_ec_hongbao_v2 v2 WHERE 1=1
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON hb.hb_id=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co
        ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <if test="startTime != null and startTime != '' ">AND <![CDATA[co.co_third_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null and endTime != '' ">AND <![CDATA[co.co_third_create_time <= #{endTime}]]>
        </if>
        <if test="key != null and key != '' ">
            <if test="keyType == 1 ">AND co.co_order_no = '${key}'</if>
            <if test="keyType == 2 ">AND hb.hb_uid = ${key}</if>
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
    </select>
    <select id="getCouponHongbaoByOrderNo" resultMap="ResultMap">
        SELECT COALESCE(SUM(IF(hb.hb_type=1,hb.`hb_money`,0)),0)AS totalMoney,
        COALESCE(SUM(IF(hb.hb_type=10,hb.`hb_money`,0)),0)AS couponMoney,
        hb.`hb_type` AS hongBaoType, MAX(hb.`hb_get_time`) AS accountTime,
        MAX(hb.`hb_pre_get_time`) AS preAccountTime, hb.hb_state AS
        hongBaoState,
        <include refid="Order_Column_List" />
        FROM yeshi_ec_hongbao_order ho LEFT JOIN (SELECT * FROM
        yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= #{uid}
        <if test="hongBaoState != null">AND v2.`hb_state` = #{hongBaoState}</if>
        )hb ON hb.hb_id = ho.`ho_hongbao_id` LEFT JOIN yeshi_ec_common_order
        co ON co.`co_id`=ho.`ho_order_id` WHERE hb.hb_id IS NOT NULL AND
        co.co_order_no = #{orderNo}
    </select>
    <select id="getCommonOrderByOrderNo" resultMap="ResultMap">
        <!-- 查询用户订单 -->
        SELECT COALESCE(SUM(hb.`hb_money`),0)AS totalMoney,
        COALESCE(SUM(co.`co_payment`),0)AS totalPayment, hb.hb_state AS
        hongBaoState, hb.`hb_type` AS hongBaoType,
        <include refid="Order_Column_List" />
        FROM yeshi_ec_hongbao_order ho LEFT JOIN (SELECT
        <include refid="Hongbao_Column_List" />
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= #{uid} AND <![CDATA[v2.`hb_type`<> 10 ]]>
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL AND co.co_order_no = #{orderNo} AND
        co.`co_source_type` = #{sourceType}
        <if test="orderState != null">
            AND co.co_state = #{orderState}
            <!-- 已收货 -->
        </if>
        GROUP BY co.`co_order_no`, co.`co_source_type`
    </select>
    <select id="getByOrderNo" resultMap="BaseResultMap">
        SELECT * FROM
        yeshi_ec_common_order co
        WHERE co_uid = #{uid} AND co_order_no=#{orderNo}
    </select>
    <select id="listByUid" resultMap="BaseResultMap">
        SELECT * FROM yeshi_ec_common_order co
        WHERE co_uid = #{uid}
        <if test="stateList!=null">
            <foreach collection="stateList" separator=" or " open="and ("
                item="state" close=")">
                co_state=#{state}
            </foreach>
        </if>
        limit #{start},#{count}
    </select>
    <select id="firstValidOrderByUid"  resultMap="ResultMap">
        SELECT co.*,v2.`hb_get_time` AS accountTime FROM yeshi_ec_hongbao_order ho
        LEFT JOIN yeshi_ec_hongbao_v2 v2 ON IF(v2.hb_pid IS NULL,v2.hb_id,v2.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE v2.hb_id IS NOT NULL AND v2.`hb_uid` = #{uid} AND v2.`hb_state` = 3
            <if test="typeHB == 1"> <!-- 自购订单 -->
                AND (v2.hb_type =1 or v2.hb_type =2)
            </if>
            <if test="typeHB == 2"> <!-- 分享订单 -->
                AND v2.`hb_type` = 20
            </if>
            <if test="typeHB == 3">  <!-- 邀请订单 -->
                AND (v2.`hb_type` = 5 OR v2.`hb_type` = 6 OR v2.`hb_type` = 7 OR
                v2.`hb_type` = 21 OR v2.`hb_type` = 22)
            </if>
            <if test="typeDate == 3"> <!-- 本月 -->
                AND DATE_FORMAT(co.`co_create_time`,'%Y%m') =    DATE_FORMAT(CURDATE(),'%Y%m')
            </if>
            <if test="typeDate == 4"> <!-- 上月 -->
                AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),DATE_FORMAT(co.`co_create_time`, '%Y%m')) = 1
            </if>
        ORDER BY co.`co_id`
        LIMIT 1
    </select>
  <select id="getFirstShareOrderByUid"  resultMap="BaseResultMap">
    SELECT co.* FROM yeshi_ec_hongbao_order ho
    LEFT JOIN yeshi_ec_hongbao_v2 v2 ON v2.hb_id = ho.`ho_hongbao_id`
    LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
    WHERE v2.`hb_uid` = #{uid} AND v2.`hb_type` = 20
    ORDER BY co.`co_third_create_time`
    LIMIT 1
  </select>
  <select id="getTotalRewardMoneyByOrderNoAndSourceType" resultType="BigDecimal">
    SELECT SUM(hb_money) FROM(SELECT v2.`hb_money` FROM yeshi_ec_hongbao_order ho
        LEFT JOIN yeshi_ec_hongbao_v2 v2 ON v2.hb_id = ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE v2.`hb_type` = 20 AND v2.`hb_state` = 3
              AND co.`co_order_no` = #{orderNo} AND co.`co_source_type`= #{sourceType})A
  </select>
 <select id="count24HValidOrderByUid" resultType="Long">
     SELECT IFNULL(COUNT(A.co_order_no),0) FROM (SELECT co.`co_order_no` FROM yeshi_ec_hongbao_order ho
    LEFT JOIN yeshi_ec_hongbao_v2 v2 ON v2.hb_id = ho.`ho_hongbao_id`
    LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
    WHERE v2.`hb_type` = 1 AND co.`co_state_whole_order`<![CDATA[<>]]> 3 AND co.`co_uid` = #{uid}
         AND co.co_third_create_time <![CDATA[>]]> #{minTime}
         AND co.`co_third_create_time` <![CDATA[<=]]> DATE_SUB(NOW(), INTERVAL 1 DAY)
    GROUP BY co.`co_order_no`,co.`co_source_type`)A
 </select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.order.CommonOrder">
        <id column="co_id" property="id" jdbcType="BIGINT" />
        <result column="co_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="co_source_type" property="sourceType" jdbcType="INTEGER" />
        <result column="co_source_position" property="sourcePosition"
            jdbcType="VARCHAR" />
        <result column="co_count" property="count" jdbcType="INTEGER" />
        <result column="co_state" property="state" jdbcType="INTEGER" />
        <result column="co_state_whole_order" property="stateWholeOrder"
            jdbcType="INTEGER" />
        <result column="co_estimate" property="estimate" jdbcType="DECIMAL" />
        <result column="co_eIncome" property="eIncome" jdbcType="DECIMAL" />
        <result column="co_payment" property="payment" jdbcType="DECIMAL" />
        <result column="co_settlement" property="settlement" jdbcType="DECIMAL" />
        <result column="co_third_create_time" property="thirdCreateTime"
            jdbcType="TIMESTAMP" />
        <result column="co_settle_time" property="settleTime" jdbcType="TIMESTAMP" />
        <result column="co_order_by" property="orderBy" jdbcType="INTEGER" />
        <result column="co_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="co_update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <result column="co_trade_id" property="tradeId" jdbcType="VARCHAR" />
        <result column="co_state_desc" property="stateDesc" jdbcType="VARCHAR" />
        <result column="co_urank" property="urank" jdbcType="INTEGER" />
        <association property="userInfo" column="co_uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="co_uid" property="id" jdbcType="BIGINT" />
        </association>
        <association property="commonOrderGoods" column="co_order_goods_id"
            javaType="com.yeshi.fanli.entity.order.CommonOrderGoods">
            <id column="co_order_goods_id" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    <resultMap id="BaseDetailResultMap" type="com.yeshi.fanli.entity.order.CommonOrder">
        <id column="co_id" property="id" jdbcType="BIGINT" />
        <result column="co_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="co_source_type" property="sourceType" jdbcType="INTEGER" />
        <result column="co_source_position" property="sourcePosition"
            jdbcType="VARCHAR" />
        <result column="co_count" property="count" jdbcType="INTEGER" />
        <result column="co_state" property="state" jdbcType="INTEGER" />
        <result column="co_state_whole_order" property="stateWholeOrder"
            jdbcType="INTEGER" />
        <result column="co_estimate" property="estimate" jdbcType="DECIMAL" />
        <result column="co_eIncome" property="eIncome" jdbcType="DECIMAL" />
        <result column="co_payment" property="payment" jdbcType="DECIMAL" />
        <result column="co_settlement" property="settlement" jdbcType="DECIMAL" />
        <result column="co_third_create_time" property="thirdCreateTime"
            jdbcType="TIMESTAMP" />
        <result column="co_settle_time" property="settleTime" jdbcType="TIMESTAMP" />
        <result column="co_order_by" property="orderBy" jdbcType="INTEGER" />
        <result column="co_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="co_update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <result column="co_trade_id" property="tradeId" jdbcType="VARCHAR" />
        <result column="co_state_desc" property="stateDesc" jdbcType="VARCHAR" />
        <result column="co_urank" property="urank" jdbcType="INTEGER" />
        <association property="userInfo" column="co_uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="co_uid" property="id" jdbcType="BIGINT" />
        </association>
        <association property="commonOrderGoods"
            resultMap="com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper.BaseResultMap" />
    </resultMap>
    <resultMap id="ResultMap" type="com.yeshi.fanli.vo.order.CommonOrderVO">
        <id column="co_id" property="id" jdbcType="BIGINT" />
        <result column="co_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="co_source_type" property="sourceType" jdbcType="INTEGER" />
        <result column="co_source_position" property="sourcePosition"
            jdbcType="VARCHAR" />
        <result column="co_count" property="count" jdbcType="INTEGER" />
        <result column="co_state" property="state" jdbcType="INTEGER" />
        <result column="co_state_whole_order" property="stateWholeOrder"
            jdbcType="INTEGER" />
        <result column="co_estimate" property="estimate" jdbcType="DECIMAL" />
        <result column="co_eIncome" property="eIncome" jdbcType="DECIMAL" />
        <result column="co_payment" property="payment" jdbcType="DECIMAL" />
        <result column="co_settlement" property="settlement" jdbcType="DECIMAL" />
        <result column="co_third_create_time" property="thirdCreateTime"
            jdbcType="TIMESTAMP" />
        <result column="co_settle_time" property="settleTime" jdbcType="TIMESTAMP" />
        <result column="co_order_by" property="orderBy" jdbcType="INTEGER" />
        <result column="co_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="co_update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <result column="totalMoney" property="hongBao" jdbcType="DECIMAL" />
        <result column="couponMoney" property="couponMoney" jdbcType="DECIMAL" />
        <result column="hongBaoState" property="hongBaoState" jdbcType="INTEGER" />
        <result column="hongBaoType" property="hongBaoType" jdbcType="INTEGER" />
        <result column="accountTime" property="accountTime" jdbcType="TIMESTAMP" />
        <result column="preAccountTime" property="preAccountTime"
            jdbcType="TIMESTAMP" />
        <result column="totalCount" property="totalCount" jdbcType="INTEGER" />
        <result column="totalSettlement" property="totalSettlement"
            jdbcType="DECIMAL" />
        <result column="totalPayment" property="totalPayment" jdbcType="DECIMAL" />
        <result column="userId" property="userId" jdbcType="VARCHAR" />
        <result column="userName" property="userName" jdbcType="VARCHAR" />
        <result column="userPortrait" property="userPortrait" jdbcType="VARCHAR" />
        <result column="hb_id" property="hongbaoId" jdbcType="BIGINT" />
        <result column="co_trade_id" property="tradeId" jdbcType="VARCHAR" />
        <result column="co_state_desc" property="stateDesc" jdbcType="VARCHAR" />
        <result column="co_uid" property="userId" jdbcType="VARCHAR" />
        <result column="co_urank" property="urank" jdbcType="INTEGER" />
        <association property="userInfo" column="co_uid"
            resultMap="com.yeshi.fanli.dao.mybatis.UserInfoMapper.BaseResultMap" />
        <association property="commonOrderGoods" column="co_order_goods_id"
            resultMap="com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper.BaseResultMap" />
    </resultMap>
    <resultMap id="ThreeResultMap" type="com.yeshi.fanli.vo.order.CommonOrderVO">
        <id column="co_id" property="id" jdbcType="BIGINT" />
        <result column="co_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="co_source_type" property="sourceType" jdbcType="INTEGER" />
        <result column="co_source_position" property="sourcePosition"
            jdbcType="VARCHAR" />
        <result column="co_count" property="count" jdbcType="INTEGER" />
        <result column="co_state" property="state" jdbcType="INTEGER" />
        <result column="co_state_whole_order" property="stateWholeOrder"
            jdbcType="INTEGER" />
        <result column="co_estimate" property="estimate" jdbcType="DECIMAL" />
        <result column="co_eIncome" property="eIncome" jdbcType="DECIMAL" />
        <result column="co_payment" property="payment" jdbcType="DECIMAL" />
        <result column="co_settlement" property="settlement" jdbcType="DECIMAL" />
        <result column="co_third_create_time" property="thirdCreateTime"
            jdbcType="TIMESTAMP" />
        <result column="co_settle_time" property="settleTime" jdbcType="TIMESTAMP" />
        <result column="co_order_by" property="orderBy" jdbcType="INTEGER" />
        <result column="co_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="co_update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <result column="totalMoney" property="hongBao" jdbcType="DECIMAL" />
        <result column="couponMoney" property="couponMoney" jdbcType="DECIMAL" />
        <result column="hongBaoState" property="hongBaoState" jdbcType="INTEGER" />
        <result column="hongBaoType" property="hongBaoType" jdbcType="INTEGER" />
        <result column="accountTime" property="accountTime" jdbcType="TIMESTAMP" />
        <result column="preAccountTime" property="preAccountTime"
            jdbcType="TIMESTAMP" />
        <result column="totalCount" property="totalCount" jdbcType="INTEGER" />
        <result column="totalSettlement" property="totalSettlement"
            jdbcType="DECIMAL" />
        <result column="totalPayment" property="totalPayment" jdbcType="DECIMAL" />
        <result column="userId" property="userId" jdbcType="VARCHAR" />
        <result column="userName" property="userName" jdbcType="VARCHAR" />
        <result column="userPortrait" property="userPortrait" jdbcType="VARCHAR" />
        <result column="hb_id" property="hongbaoId" jdbcType="BIGINT" />
        <result column="co_trade_id" property="tradeId" jdbcType="VARCHAR" />
        <result column="co_state_desc" property="stateDesc" jdbcType="VARCHAR" />
        <result column="co_urank" property="urank" jdbcType="INTEGER" />
        <association property="userInfo" column="co_uid"
            select="com.yeshi.fanli.dao.mybatis.UserInfoMapper.selectByPrimaryKey" />
        <association property="commonOrderGoods" column="co_order_goods_id"
            select="com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper.selectByPrimaryKey" />
    </resultMap>
    <resultMap id="OrderCountMap" type="com.yeshi.fanli.vo.order.OrderCountVO">
        <result column="self" property="self" jdbcType="BIGINT" />
        <result column="shared" property="shared" jdbcType="BIGINT" />
        <result column="invite" property="invite" jdbcType="BIGINT" />
    </resultMap>
    <sql id="Base_Column_List">co_id,co_uid,co_order_no,co_source_type,co_source_position,co_order_goods_id,co_count,co_state,co_state_whole_order,co_estimate,co_eIncome,co_payment,co_settlement,co_third_create_time,co_settle_time,co_order_by,co_create_time,co_update_time,co_trade_id,co_state_desc,co_urank
    </sql>
    <sql id="Order_Column_List">co_id,co_uid,co_order_no,co_source_type,co_source_position,
        co_order_goods_id,co_count,co_state,co_state_whole_order,
        co_estimate,co_eIncome,co_payment,co_settlement, co_third_create_time,
        MAX(co_settle_time) AS co_settle_time, co_order_by, co_create_time,
        co_update_time,co_state_desc
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_common_order where co_id = #{id,jdbcType=BIGINT}
    </select>
    <select id="countByOrderNOAndOrderType" resultType="java.lang.Integer">select
        count(co_id) from yeshi_ec_common_order where co_order_no=#{orderNO}
        and co_source_type=#{orderType}
    </select>
    <select id="selectByOrderNoAndOrderTypeAndOrderBy" resultMap="BaseResultMap">select
        * from yeshi_ec_common_order where co_order_no=#{orderNo} and
        co_source_type=#{orderType} and co_order_by=#{orderBy}
    </select>
    <select id="countByUidAndOrderStateWithOrderBalanceTime"
        resultType="java.lang.Long">SELECT COUNT(*) FROM yeshi_ec_common_order co WHERE
        co.`co_state`=#{state} and co.`co_uid`=#{uid} and co.`co_settle_time`
        is not null and co.`co_settle_time`&gt;=#{minDate} and
        #{maxDate}&gt;co.`co_settle_time`</select>
    <select id="listBySourceTypeAndOrderNo" resultMap="BaseResultMap">SELECT * FROM
        yeshi_ec_common_order co WHERE co.co_source_type=#{sourceType} and
        co_order_no=#{orderNo}
    </select>
    <select id="selectBySourceTypeAndTradeId" resultMap="BaseResultMap">SELECT *
        FROM yeshi_ec_common_order co WHERE co.co_source_type=#{sourceType}
        and co_trade_id=#{tradeId} limit 1
    </select>
    <select id="listBySourceTypeAndTradeId" resultMap="BaseResultMap">SELECT * FROM
        yeshi_ec_common_order co WHERE co.co_source_type=#{sourceType} and
        co_trade_id=#{tradeId}
    </select>
    <select id="listBySourceTypeAndTradeIdList" resultMap="BaseResultMap">
        SELECT * FROM yeshi_ec_common_order co WHERE
        co.co_source_type=#{sourceType}
        <if test="tradeIdList!=null">
            <foreach collection="tradeIdList" item="tradeId" open=" and ("
                close=")" separator=" or ">co.co_trade_id=#{tradeId}</foreach>
        </if>
    </select>
    <select id="listBySourceTypeAndStateAndThirdCrateTime"
        resultMap="BaseResultMap">
        SELECT * FROM yeshi_ec_common_order co WHERE
        co.co_source_type=#{sourceType}
        <if test="state!=null">and co_state=#{state}</if>
        <if test="minTime!=null">and
            UNIX_TIMESTAMP(co_third_create_time)*1000&gt;=#{minTime}</if>
        <if test="maxTime!=null">and #{maxTime}&gt;
            UNIX_TIMESTAMP(co_third_create_time)*1000
        </if>
        order by co_id desc limit #{start},#{count}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_common_order where co_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.order.CommonOrder"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_common_order
        (co_id,co_uid,co_order_no,co_source_type,co_source_position,co_order_goods_id,co_count,co_state,co_estimate,co_eIncome,co_payment,co_settlement,co_third_create_time,co_settle_time,co_create_time,co_update_time,co_state_whole_order,co_order_by,co_trade_id,co_state_desc,co_urank)
        values
        (#{id,jdbcType=BIGINT},#{userInfo.id,jdbcType=BIGINT},#{orderNo,jdbcType=VARCHAR},#{sourceType,jdbcType=INTEGER},#{sourcePosition,jdbcType=VARCHAR},#{commonOrderGoods.id,jdbcType=BIGINT},#{count,jdbcType=INTEGER},#{state,jdbcType=INTEGER},#{estimate,jdbcType=DECIMAL},#{eIncome,jdbcType=DECIMAL},#{payment,jdbcType=DECIMAL},#{settlement,jdbcType=DECIMAL},#{thirdCreateTime,jdbcType=TIMESTAMP},#{settleTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{stateWholeOrder,jdbcType=INTEGER},#{orderBy,jdbcType=INTEGER},#{tradeId,jdbcType=VARCHAR},#{stateDesc,jdbcType=VARCHAR},#{urank,jdbcType=INTEGER})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.order.CommonOrder"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_common_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">co_id,</if>
            <if test="userInfo != null">co_uid,</if>
            <if test="orderNo != null">co_order_no,</if>
            <if test="sourceType != null">co_source_type,</if>
            <if test="sourcePosition != null">co_source_position,</if>
            <if test="commonOrderGoods != null">co_order_goods_id,</if>
            <if test="count != null">co_count,</if>
            <if test="state != null">co_state,</if>
            <if test="stateWholeOrder != null">co_state_whole_order,</if>
            <if test="estimate != null">co_estimate,</if>
            <if test="eIncome != null">co_eIncome,</if>
            <if test="payment != null">co_payment,</if>
            <if test="settlement != null">co_settlement,</if>
            <if test="thirdCreateTime != null">co_third_create_time,</if>
            <if test="settleTime != null">co_settle_time,</if>
            <if test="orderBy != null">co_order_by,</if>
            <if test="createTime != null">co_create_time,</if>
            <if test="updateTime != null">co_update_time,</if>
            <if test="tradeId != null">co_trade_id,</if>
            <if test="stateDesc != null">co_state_desc,</if>
            <if test="urank != null">co_urank,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="userInfo != null">#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="orderNo != null">#{orderNo,jdbcType=VARCHAR},</if>
            <if test="sourceType != null">#{sourceType,jdbcType=INTEGER},</if>
            <if test="sourcePosition != null">#{sourcePosition,jdbcType=VARCHAR},</if>
            <if test="commonOrderGoods != null">#{commonOrderGoods.id,jdbcType=BIGINT},</if>
            <if test="count != null">#{count,jdbcType=INTEGER},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="stateWholeOrder != null">#{stateWholeOrder,jdbcType=INTEGER},</if>
            <if test="estimate != null">#{estimate,jdbcType=DECIMAL},</if>
            <if test="eIncome != null">#{eIncome,jdbcType=DECIMAL},</if>
            <if test="payment != null">#{payment,jdbcType=DECIMAL},</if>
            <if test="settlement != null">#{settlement,jdbcType=DECIMAL},</if>
            <if test="thirdCreateTime != null">#{thirdCreateTime,jdbcType=TIMESTAMP},</if>
            <if test="settleTime != null">#{settleTime,jdbcType=TIMESTAMP},</if>
            <if test="orderBy != null">#{orderBy,jdbcType=INTEGER},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="tradeId != null">#{tradeId,jdbcType=VARCHAR},</if>
            <if test="stateDesc != null">#{stateDesc,jdbcType=VARCHAR},</if>
            <if test="urank != null">#{urank,jdbcType=INTEGER}</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.order.CommonOrder">update
        yeshi_ec_common_order set co_uid =
        #{userInfo.id,jdbcType=BIGINT},co_order_no =
        #{orderNo,jdbcType=VARCHAR},co_source_type =
        #{sourceType,jdbcType=INTEGER},co_source_position =
        #{sourcePosition,jdbcType=VARCHAR},co_order_goods_id =
        #{commonOrderGoods.id,jdbcType=BIGINT},co_count =
        #{count,jdbcType=INTEGER},co_state =
        #{state,jdbcType=INTEGER},co_state_whole_order =
        #{stateWholeOrder,jdbcType=INTEGER},co_estimate =
        #{estimate,jdbcType=DECIMAL},co_eIncome =
        #{eIncome,jdbcType=DECIMAL},co_payment =
        #{payment,jdbcType=DECIMAL},co_settlement =
        #{settlement,jdbcType=DECIMAL},co_third_create_time =
        #{thirdCreateTime,jdbcType=TIMESTAMP},co_settle_time =
        #{settleTime,jdbcType=TIMESTAMP},co_order_by =
        #{orderBy,jdbcType=INTEGER},co_create_time =
        #{createTime,jdbcType=TIMESTAMP},co_update_time =
        #{updateTime,jdbcType=TIMESTAMP} ,co_trade_id
        =#{tradeId,jdbcType=VARCHAR},co_state_desc
        =#{stateDesc,jdbcType=VARCHAR} ,co_urank =#{urank,jdbcType=INTEGER}
        where co_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.order.CommonOrder">
        update yeshi_ec_common_order
        <set>
            <if test="userInfo != null">co_uid=#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="orderNo != null">co_order_no=#{orderNo,jdbcType=VARCHAR},</if>
            <if test="sourceType != null">co_source_type=#{sourceType,jdbcType=INTEGER},</if>
            <if test="sourcePosition != null">co_source_position=#{sourcePosition,jdbcType=VARCHAR},
            </if>
            <if test="commonOrderGoods != null">co_order_goods_id=#{commonOrderGoods.id,jdbcType=BIGINT},
            </if>
            <if test="count != null">co_count=#{count,jdbcType=INTEGER},</if>
            <if test="state != null">co_state=#{state,jdbcType=INTEGER},</if>
            <if test="stateWholeOrder != null">co_state_whole_order=#{stateWholeOrder,jdbcType=INTEGER},
            </if>
            <if test="estimate != null">co_estimate=#{estimate,jdbcType=DECIMAL},</if>
            <if test="eIncome != null">co_eIncome=#{eIncome,jdbcType=DECIMAL},</if>
            <if test="payment != null">co_payment=#{payment,jdbcType=DECIMAL},</if>
            <if test="settlement != null">co_settlement=#{settlement,jdbcType=DECIMAL},</if>
            <if test="thirdCreateTime != null">co_third_create_time=#{thirdCreateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="settleTime != null">co_settle_time=#{settleTime,jdbcType=TIMESTAMP},</if>
            <if test="orderBy != null">co_order_by=#{orderBy,jdbcType=INTEGER},</if>
            <if test="createTime != null">co_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">co_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="id !=null">co_id =#{id,jdbcType=BIGINT},</if>
            <if test="tradeId !=null">co_trade_id =#{tradeId,jdbcType=VARCHAR},</if>
            <if test="stateDesc !=null">co_state_desc =#{stateDesc,jdbcType=VARCHAR},</if>
            <if test="urank !=null">co_urank =#{urank,jdbcType=INTEGER},</if>
        </set>
        where co_id = #{id,jdbcType=BIGINT}
    </update>
    <sql id="SELECT_PARAM_ORDER_STATE">
        <if test="orderState != null and orderState ==  1">
            <!-- 有效订单: 整个订单有效 -->
            AND <![CDATA[co.`co_state` <> 3]]>
            AND (co.co_state_whole_order = 1 or co.co_state_whole_order = 2)
        </if>
        <if test="orderState != null and orderState ==  2">
            AND co.co_state = 3
            <!-- 维权订单 -->
        </if>
        <if test="orderState != null and orderState ==  3">
            <!-- 整个订单失效 -->
            AND co.co_state_whole_order = 3
        </if>
        <if test="orderState != null and orderState ==  4">
            <!-- 已收货订单 -->
            AND co.co_state = 2
        </if>
    </sql>
    <sql id="SELECT_PARAM_ORDER_CREATE_TIME">
        <if test="startTime != null and startTime != '' ">AND <![CDATA[co.co_third_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null and endTime != '' ">AND <![CDATA[co.co_third_create_time <= #{endTime}]]>
        </if>
        <if test="day == 1">
            <!-- 今天 -->
            AND TO_DAYS(co.`co_third_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day == 2">
            <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(co.`co_third_create_time`) = 1
        </if>
        <if test="day == 3 or day == 10">
            <!-- 本月 -->
            AND DATE_FORMAT(co.`co_third_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day == 4">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
        </if>
        <if test="day == 6">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(co.`co_third_create_time`, '%Y%m')) = 1
        </if>
        <if test="day == 11">
            <!-- 近3个月产生 -->
            AND co.`co_third_create_time` BETWEEN DATE_SUB(NOW(),INTERVAL 3
            MONTH) AND NOW()
        </if>
        <if test="day == 12">
            <!-- 近半年产生 -->
            AND co.`co_third_create_time` BETWEEN DATE_SUB(NOW(),INTERVAL 6
            MONTH) AND NOW()
        </if>
    </sql>
    <sql id="SELECT_PARAM_HONGBAO_TYPE">
        <if test="type != null and type == 1">
            <!-- 自购订单 -->
            AND (v2.hb_type =1 or v2.hb_type =2)
        </if>
        <if test="type != null and type == 2">
            <!-- 分享订单 -->
            AND v2.`hb_type` = 20
        </if>
        <if test="type != null and type == 3">
            <!-- 邀请订单 -->
            AND (v2.`hb_type` = 5 OR v2.`hb_type` = 6 OR v2.`hb_type` = 7 OR
            v2.`hb_type` = 21 OR v2.`hb_type` = 22)
        </if>
    </sql>
    <sql id="SELECT_PARAM_HONGBAO_STATE">
        <if test="state != null and state == 1">
            <!-- 未到账 -->
            AND (hb.hb_state = 1 or hb.hb_state = 2)
        </if>
        <if test="state != null and state == 2">
            <!-- 已到账 -->
            AND hb.hb_state = 3
        </if>
        <if test="state != null and state == 3">
            <!-- 红包已失效、整个订单失效 -->
            AND hb.hb_state =4 AND co.co_state_whole_order = 3
        </if>
    </sql>
    <sql id="Hongbao_Column_List">hb_id,hb_uid,hb_urank,hb_pid,hb_type,hb_state,hb_pre_get_time,hb_get_time,hb_version,
        IF(v2.`hb_state` = 4, 0, v2.hb_money)AS hb_money
    </sql>
    <select id="listUserOrder" resultMap="ResultMap">
        <!-- 查询用户订单 -->
        SELECT COALESCE(SUM(hb.`hb_money`),0)AS totalMoney, hb.hb_state AS
        hongBaoState, hb.`hb_type` AS hongBaoType, MAX(hb.`hb_get_time`) AS
        accountTime, MAX(hb.`hb_pre_get_time`) AS preAccountTime,
        <include refid="Order_Column_List" />
        FROM yeshi_ec_hongbao_order ho LEFT JOIN (SELECT
        <include refid="Hongbao_Column_List" />
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= #{uid} AND <![CDATA[v2.`hb_type`<> 10 ]]>
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <if test="type == 2 and day == 5">
            <!-- 本月月将要到账分享订单 -->
            AND DATE_FORMAT(v2.`hb_pre_get_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="type == 3 and day == 5">
            <!-- 本月将要到账邀请订单 -->
            AND DATE_FORMAT(v2.`hb_pre_get_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <!-- 红包类型 -->
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <!-- 订单时间 -->
        <include refid="SELECT_PARAM_HONGBAO_STATE" />
        <!-- 订单号查询 -->
        <if test="orderNo != null and orderNo !='' ">AND co.co_order_no = #{orderNo}</if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type` ORDER BY
        co.co_third_create_time DESC LIMIT ${start},${count}
    </select>
    <select id="countUserOrder" resultType="java.lang.Long">
        <!-- 统计用户订单数量 -->
        SELECT IFNULL(COUNT(ho_id),0) FROM (SELECT ho.ho_id FROM
        yeshi_ec_hongbao_order ho LEFT JOIN (SELECT
        <include refid="Hongbao_Column_List" />
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= #{uid} AND <![CDATA[v2.`hb_type`<> 10 ]]>
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <if test="type == 2 and day == 5">
            <!-- 本月月将要到账分享订单 -->
            AND DATE_FORMAT(v2.`hb_pre_get_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="type == 3 and day == 5">
            <!-- 本月将要到账邀请订单 -->
            AND DATE_FORMAT(v2.`hb_pre_get_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <!-- 订单时间 -->
        <include refid="SELECT_PARAM_HONGBAO_STATE" />
        <!-- 订单号查询 -->
        <if test="orderNo != null and orderNo !='' ">AND co.co_order_no = #{orderNo}</if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type` )A
    </select>
    <select id="listOrderGoodsInfo" resultMap="ResultMap"
        parameterType="java.util.List">
        <!-- 查询用户订单商品信息 -->
        SELECT COALESCE(SUM(tc.`co_payment`),0)AS
        totalPayment,COALESCE(SUM(tc.`co_settlement`),0)AS totalSettlement,
        COALESCE(SUM(tc.`co_count`),0)AS
        totalCount,tc.`co_source_type`,tc.`co_order_no`,tg.*,tc.co_id FROM
        yeshi_ec_common_order_goods tg LEFT JOIN yeshi_ec_common_order tc ON
        tc.`co_order_goods_id` = tg.`cog_id` WHERE
        <foreach collection="list" item="item" separator=" OR ">(tc.`co_source_type`
            = #{item.sourceType,jdbcType=INTEGER} AND tc.`co_order_no` =
            #{item.orderNo,jdbcType=VARCHAR})
        </foreach>
        GROUP BY tc.`co_order_no`,tc.`co_order_goods_id`
    </select>
    <select id="countHistoryOrder" resultType="java.util.HashMap">
        <!-- 统计历史订单数量 -->
        SELECT SUM(A.self)AS totalSelf,SUM(A.shared)AS
        totalShared,SUM(A.invite)AS totalInvite FROM (
        <!-- 返利订单 -->
        SELECT IFNULL(COUNT(ho_id),0) AS self,0 AS shared,0 AS invite FROM
        (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT *
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= ${uid} AND
        (v2.`hb_type` = 1 OR v2.`hb_type` = 2) ) hb ON
        hb.hb_id=ho.`ho_hongbao_id`
        <!-- 自购订单 -->
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL and hb.hb_state!=4
        <if test="day != null and day == 1">
            <!-- 今天 -->
            AND TO_DAYS(co.`co_third_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">
            <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(co.co_third_create_time) = 1
        </if>
        <if test="day != null and day == 3">
            <!-- 本月 -->
            AND DATE_FORMAT(co.`co_third_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)YX UNION ALL
        <!-- 分享订单 -->
        SELECT 0 AS self,IFNULL(COUNT(ho_id),0) AS shared,0 AS invite FROM
        (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT *
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= ${uid} AND v2.`hb_type`
        = 20 ) hb ON hb.hb_id=ho.`ho_hongbao_id`
        <!-- 分享订单 -->
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL and hb.hb_state!=4
        <if test="day != null and day == 1">
            <!-- 今天 -->
            AND TO_DAYS(co.`co_third_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">
            <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(co.`co_third_create_time`) = 1
        </if>
        <if test="day != null and day == 3">
            <!-- 本月 -->
            AND DATE_FORMAT(co.`co_third_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)WQ UNION ALL
        <!-- 邀请订单 -->
        SELECT 0 AS self,0 AS shared,IFNULL(COUNT(ho_id),0) AS invite FROM
        (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT *
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= ${uid} AND
        (v2.`hb_type` = 5 OR v2.`hb_type` = 6 OR v2.`hb_type` = 7 OR
        v2.`hb_type` = 21 OR v2.`hb_type` = 22 ) ) hbp ON
        hbp.hb_pid=ho.`ho_hongbao_id` LEFT JOIN yeshi_ec_common_order co ON
        co.`co_id`=ho.`ho_order_id` WHERE hbp.hb_id IS NOT NULL and
        hbp.hb_state!=4
        <if test="day != null and day == 1">
            <!-- 今天 -->
            AND TO_DAYS(co.`co_third_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">
            <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(co.`co_third_create_time`) = 1
        </if>
        <if test="day != null and day == 3">
            <!-- 本月 -->
            AND DATE_FORMAT(co.`co_third_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)SX )A
    </select>
    <sql id="OrderCountQuery">WHERE
        co.`co_state_whole_order`<![CDATA[<>]]>3
        <if test="day == 1">
            <!-- 今天 -->
            AND TO_DAYS(co.`co_third_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day == 2">
            <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(co.`co_third_create_time`) = 1
        </if>
        <if test="day == 3">
            <!-- 本月 -->
            AND DATE_FORMAT(co.`co_third_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day == 4">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(),
            '%Y%m'),DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
        </if>
        <!-- 订单来源 -->
        <if test="source != null and source != 0">AND co.co_source_type = #{source}</if>
    </sql>
    <select id="getOrderCount" resultMap="OrderCountMap">
        SELECT sum(self) as self,sum(shared) as shared,sum(invite) as invite
        from ( SELECT IFNULL(COUNT(co_order_no),0)AS self,0 AS shared,0 AS
        invite FROM (SELECT co.`co_order_no` FROM (SELECT * FROM
        yeshi_ec_hongbao_v2 v WHERE v.`hb_uid`= ${uid} AND v.`hb_type` = 1)v2
        LEFT JOIN yeshi_ec_hongbao_order ho ON ho.`ho_hongbao_id` =
        IF(v2.hb_pid IS NULL,v2.hb_id,v2.hb_pid) LEFT JOIN
        yeshi_ec_common_order co ON co.`co_id` = ho.`ho_order_id`
        <include refid="OrderCountQuery" />
        GROUP BY co.`co_order_no`,co.`co_source_type`)A UNION ALL SELECT 0 AS
        self,IFNULL(COUNT(co_order_no),0)AS shared,0 AS invite FROM (SELECT
        co.`co_order_no` FROM (SELECT * FROM yeshi_ec_hongbao_v2 v WHERE
        v.`hb_uid`= ${uid} AND v.`hb_type` = 20)v2 LEFT JOIN
        yeshi_ec_hongbao_order ho ON ho.`ho_hongbao_id` = IF(v2.hb_pid IS
        NULL,v2.hb_id,v2.hb_pid) LEFT JOIN yeshi_ec_common_order co ON
        co.`co_id` = ho.`ho_order_id`
        <include refid="OrderCountQuery" />
        GROUP BY co.`co_order_no`,co.`co_source_type`)A UNION ALL SELECT 0 AS
        self,0 AS shared,IFNULL(COUNT(co_order_no),0)AS invite FROM (SELECT
        co.`co_order_no` FROM (SELECT * FROM yeshi_ec_hongbao_v2 v WHERE
        v.`hb_uid`= ${uid} AND (v.`hb_type` = 5 OR v.`hb_type` = 6 OR
        v.`hb_type` = 7 OR v.`hb_type` = 21 OR v.`hb_type` = 22))v2 LEFT JOIN
        yeshi_ec_hongbao_order ho ON ho.`ho_hongbao_id` = IF(v2.hb_pid IS
        NULL,v2.hb_id,v2.hb_pid) LEFT JOIN yeshi_ec_common_order co ON
        co.`co_id` = ho.`ho_order_id`
        <include refid="OrderCountQuery" />
        GROUP BY co.`co_order_no`,co.`co_source_type`)A )B
    </select>
    <select id="countUserOrderToApp" resultType="Long">
        <!-- 有效订单 -->
        SELECT IFNULL(COUNT(ho_id),0) FROM (SELECT ho.`ho_id` FROM
        yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT * FROM
        yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`=${uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <if test="state != null and state == 1">
            <!-- 未到账 -->
            AND (v2.hb_state = 1 or v2.hb_state = 2)
        </if>
        <if test="state != null and state == 2">
            <!-- 已到账 -->
            AND v2.hb_state = 3
        </if>
        <if test="state != null and state == 3">
            <!-- 红包已失效 -->
            AND v2.hb_state =4
        </if>
        ) hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL<![CDATA[AND co.`co_state` <> 3]]>
        <if test="stateOrder == 1">
            <!-- 有效订单 -->
            AND (co.`co_state_whole_order` =1 OR co.`co_state_whole_order` = 2)
        </if>
        <if test="stateOrder == 2">
            <!-- 维权订单 -->
            AND co.`co_state` = 3
        </if>
        <if test="stateOrder == 3">
            <!-- 失效订单 -->
            AND co.`co_state_whole_order` = 3
        </if>
        <!-- 订单时间 -->
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type` )A
    </select>
    <!-- <select id="countByUidAndOrderState" resultType="java.util.HashMap">
        SELECT SUM(A.valid)AS totalValid, SUM(A.proces)AS totalProces,SUM(A.Invalid)AS
        totalInvite FROM ( 有效订单 SELECT IFNULL(COUNT(ho_id),0) AS valid,0 AS proces,0
        AS Invalid FROM (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho LEFT JOIN
        ( SELECT * FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`=${uid} <include
        refid="SELECT_PARAM_HONGBAO_TYPE" /> ) hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` WHERE hb.hb_id
        IS NOT NULL <![CDATA[AND co.`co_state` <> 3]]> AND (co.`co_state_whole_order`
        =1 OR co.`co_state_whole_order` = 2) <include refid="SELECT_PARAM_ORDER_CREATE_TIME"
        /> 订单来源 <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)YX UNION ALL 维权订单 SELECT 0
        AS valid,IFNULL(COUNT(ho_id),0) AS proces,0 AS Invalid FROM (SELECT ho.`ho_id`
        FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT * FROM yeshi_ec_hongbao_v2
        v2 WHERE v2.`hb_uid`=${uid} <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        ) hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id` LEFT
        JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` WHERE hb.hb_id
        IS NOT NULL AND co.`co_state` = 3 <include refid="SELECT_PARAM_ORDER_CREATE_TIME"
        /> 订单来源 <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)WQ UNION ALL 失效订单 SELECT 0
        AS valid,0 AS proces,IFNULL(COUNT(ho_id),0) AS Invalid FROM (SELECT ho.`ho_id`
        FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT * FROM yeshi_ec_hongbao_v2
        v2 WHERE v2.`hb_uid`=${uid} <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        ) hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id` LEFT
        JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` WHERE hb.hb_id
        IS NOT NULL AND co.`co_state_whole_order` = 3 <include refid="SELECT_PARAM_ORDER_CREATE_TIME"
        /> 订单来源 <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type`)SX )A </select> -->
    <select id="countBonusOrderNumber" resultType="java.lang.Long">
        <!-- 奖金统计:订单数量 -->
        SELECT IFNULL(COUNT(ho_id),0) FROM (SELECT ho.`ho_id` FROM
        yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT * FROM
        yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`=${uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        ) hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type` )A
    </select>
    <select id="countBonusOrderMoney" resultType="java.math.BigDecimal">
        <!-- 奖金统计:订单总返利金额 去掉已失效 -->
        SELECT COALESCE(SUM(hb.`hb_money`),0)AS totalmoney FROM
        yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT
        <include refid="Hongbao_Column_List" />
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`=${uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        AND (v2.hb_state = 1 or v2.hb_state = 2 or v2.hb_state = 3) ) hb ON
        IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id` LEFT JOIN
        yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` WHERE hb.hb_id
        IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <if test="day != null and day == 4">
            AND co.`co_state` = 2
            <!-- 上月 :统计已收货 -->
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
    </select>
    <select id="countBonusOrderMoneyAndNumber" resultType="java.util.HashMap">
        SELECT COUNT(*) AS totalNum, CAST(SUM(moneys) AS DECIMAL(19,2)) AS
        totalmoney FROM (SELECT CAST(SUM(hb.`hb_money`) AS DECIMAL(19,2))AS
        moneys FROM yeshi_ec_hongbao_order ho LEFT JOIN ( SELECT
        <include refid="Hongbao_Column_List" />
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`=${uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        AND (v2.hb_state = 1 or v2.hb_state = 2 or v2.hb_state = 3) ) hb ON
        IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id` LEFT JOIN
        yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` WHERE hb.hb_id
        IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <if test="day != null and day == 4">AND co.`co_state` = 2</if>
        <!-- 上月 :统计已收货 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        GROUP BY co.`co_order_no`, co.`co_source_type` )A
    </select>
    <sql id="SELECT_HONGBAO_STATE">
        <if test="state != null and state == 1">
            <!-- 未到账 -->
            AND (v2.hb_state = 1 or v2.hb_state = 2)
        </if>
        <if test="state != null and state == 2">
            <!-- 已到账 -->
            AND v2.hb_state = 3
        </if>
        <if test="state != null and state == 3">
            <!-- 红包已失效 -->
            AND v2.hb_state =4
        </if>
    </sql>
    <select id="listQueryByUid" resultMap="ResultMap">
        <!-- 查询用户订单 -->
        SELECT hb.`hb_money` AS totalMoney, hb.hb_state AS hongBaoState,
        hb.`hb_type` AS hongBaoType, hb.`hb_get_time` AS accountTime,
        hb.`hb_pre_get_time` AS preAccountTime, co.*,cog.* FROM
        yeshi_ec_hongbao_order ho LEFT JOIN (SELECT * FROM yeshi_ec_hongbao_v2
        v2 WHERE v2.`hb_uid`= #{uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` LEFT
        JOIN yeshi_ec_common_order_goods cog ON cog.`cog_id`=
        co.`co_order_goods_id` WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <!-- 订单时间 -->
        <if test="orderNo != null and orderNo !='' ">AND co.co_order_no = #{orderNo}</if>
        ORDER BY co.co_third_create_time DESC LIMIT ${start},${count}
    </select>
    <select id="countQueryByUid" resultType="java.lang.Long">
        <!-- 统计用户订单数量 -->
        SELECT IFNULL(COUNT(ho_id),0) FROM (SELECT ho.ho_id FROM
        yeshi_ec_hongbao_order ho LEFT JOIN (SELECT * FROM yeshi_ec_hongbao_v2
        v2 WHERE v2.`hb_uid`= #{uid}
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
        <!-- 订单时间 -->
        <if test="orderNo != null and orderNo !='' ">AND co.co_order_no = #{orderNo}</if>
        )A
    </select>
    <select id="getBuFenOrderState" resultMap="ResultMap">SELECT
        co.co_state,v2.`hb_state` AS hongBaoState FROM `yeshi_ec_common_order`
        co LEFT JOIN yeshi_ec_hongbao_order ho ON co.`co_id`=ho.`ho_order_id`
        LEFT JOIN yeshi_ec_hongbao_v2 v2 ON IF(v2.hb_pid IS
        NULL,v2.hb_id,v2.hb_pid)=ho.`ho_hongbao_id` WHERE co.`co_order_no` =
        #{orderNo} AND co.co_state<![CDATA[<>]]>
        4 AND v2.hb_uid = #{uid} ORDER BY co.`co_state` DESC LIMIT 1
    </select>
    <select id="listQuery" resultMap="ThreeResultMap">
        SELECT A.*,u.id AS userId,u.`nick_name` AS userName,u.`portrait` AS
        userPortrait FROM (SELECT hb.hb_id,hb.hb_uid,hb.`hb_money` AS
        totalMoney, hb.hb_state AS hongBaoState, hb.`hb_type` AS hongBaoType,
        hb.`hb_get_time` AS accountTime, hb.`hb_pre_get_time` AS
        preAccountTime, co.* FROM yeshi_ec_hongbao_order ho LEFT JOIN (SELECT
        * FROM yeshi_ec_hongbao_v2 v2 WHERE 1=1
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        <if test="listShopId != null">LEFT JOIN yeshi_ec_common_order_goods g ON
            co.`co_order_goods_id`=g.`cog_id`
        </if>
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <if test="startTime != null and startTime != '' ">AND <![CDATA[co.co_third_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null and endTime != '' ">AND <![CDATA[co.co_third_create_time <= #{endTime}]]>
        </if>
        <if test="key != null and key != '' ">
            <if test="keyType == 1 ">AND co.co_order_no = '${key}'</if>
            <if test="keyType == 2 ">AND hb.hb_uid = ${key}</if>
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        <if test="listGoodsId != null">
            <foreach collection="listGoodsId" item="goodsId" open=" and ("
                separator=" or " close=")">co.`co_order_goods_id` =#{goodsId}</foreach>
        </if>
        <if test="listShopId != null">
            <foreach collection="listShopId" item="shopId" open=" and ("
                separator=" or " close=")">g.`cog_shop_id` =#{shopId}</foreach>
        </if>
        <if test="minTime != null">
            <!-- 高风险订单 -->
            AND co.`co_third_create_time`&gt;#{minTime} AND<![CDATA[ (co.`co_estimate`>=  ${money} OR co.`co_eIncome`> ${money})]]>
        </if>
        ORDER BY co.co_third_create_time DESC LIMIT ${start},${count} ) A LEFT
        JOIN yeshi_ec_user u ON u.id = A.hb_uid
    </select>
    <select id="listQueryWithNoChild" resultMap="ThreeResultMap">
        SELECT A.*,u.id AS userId,u.`nick_name` AS userName,u.`portrait` AS
        userPortrait FROM (SELECT hb.hb_id,hb.hb_uid,hb.`hb_money` AS
        totalMoney, hb.hb_state AS hongBaoState, hb.`hb_type` AS hongBaoType,
        hb.`hb_get_time` AS accountTime, hb.`hb_pre_get_time` AS
        preAccountTime, co.* FROM yeshi_ec_hongbao_order ho LEFT JOIN (SELECT
        * FROM yeshi_ec_hongbao_v2 v2 WHERE 1=1
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON hb.hb_id=ho.`ho_hongbao_id` LEFT JOIN yeshi_ec_common_order co
        ON co.`co_id`=ho.`ho_order_id` WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <if test="startTime != null and startTime != '' ">AND <![CDATA[co.co_third_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null and endTime != '' ">AND <![CDATA[co.co_third_create_time <= #{endTime}]]>
        </if>
        <if test="key != null and key != '' ">
            <if test="keyType == 1 ">AND co.co_order_no = '${key}'</if>
            <if test="keyType == 2 ">AND hb.hb_uid = ${key}</if>
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        ORDER BY co.co_third_create_time DESC LIMIT ${start},${count} ) A LEFT
        JOIN yeshi_ec_user u ON u.id = A.hb_uid
    </select>
    <select id="countQuery" resultType="java.lang.Long">
        SELECT count(ho.ho_id) FROM yeshi_ec_hongbao_order ho LEFT JOIN
        (SELECT * FROM yeshi_ec_hongbao_v2 v2 WHERE 1=1
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        <if test="listShopId != null">LEFT JOIN yeshi_ec_common_order_goods g ON
            co.`co_order_goods_id`=g.`cog_id`
        </if>
        WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <if test="startTime != null and startTime != '' ">AND <![CDATA[co.co_third_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null and endTime != '' ">AND <![CDATA[co.co_third_create_time <= #{endTime}]]>
        </if>
        <if test="key != null and key != '' ">
            <if test="keyType == 1 ">AND co.co_order_no = '${key}'</if>
            <if test="keyType == 2 ">AND hb.hb_uid = ${key}</if>
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
        <if test="listGoodsId != null">
            <foreach collection="listGoodsId" item="goodsId" open=" and ("
                separator=" or " close=")">co.`co_order_goods_id` =#{goodsId}</foreach>
        </if>
        <if test="listShopId != null">
            <foreach collection="listShopId" item="shopId" open=" and ("
                separator=" or " close=")">g.`cog_shop_id` =#{shopId}</foreach>
        </if>
        <if test="minTime != null">
            <!-- 高风险订单 -->
            AND co.`co_third_create_time`&gt;#{minTime} AND<![CDATA[ (co.`co_estimate`>=  ${money} OR co.`co_eIncome`> ${money})]]>
        </if>
    </select>
    <select id="countQueryWithNoChild" resultType="java.lang.Long">
        SELECT count(ho.ho_id) FROM yeshi_ec_hongbao_order ho LEFT JOIN
        (SELECT * FROM yeshi_ec_hongbao_v2 v2 WHERE 1=1
        <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        <!-- 红包类型 -->
        <include refid="SELECT_HONGBAO_STATE" />
        <!-- 红包状态 -->
        )hb ON hb.hb_id=ho.`ho_hongbao_id` LEFT JOIN yeshi_ec_common_order co
        ON co.`co_id`=ho.`ho_order_id` WHERE hb.hb_id IS NOT NULL
        <include refid="SELECT_PARAM_ORDER_STATE" />
        <!-- 订单状态 -->
        <if test="startTime != null and startTime != '' ">AND <![CDATA[co.co_third_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null and endTime != '' ">AND <![CDATA[co.co_third_create_time <= #{endTime}]]>
        </if>
        <if test="key != null and key != '' ">
            <if test="keyType == 1 ">AND co.co_order_no = '${key}'</if>
            <if test="keyType == 2 ">AND hb.hb_uid = ${key}</if>
        </if>
        <!-- 订单来源 -->
        <if test="source != null">AND co.co_source_type = #{source}</if>
    </select>
    <select id="getCouponHongbaoByOrderNo" resultMap="ResultMap">
        SELECT COALESCE(SUM(IF(hb.hb_type=1,hb.`hb_money`,0)),0)AS totalMoney,
        COALESCE(SUM(IF(hb.hb_type=10,hb.`hb_money`,0)),0)AS couponMoney,
        hb.`hb_type` AS hongBaoType, MAX(hb.`hb_get_time`) AS accountTime,
        MAX(hb.`hb_pre_get_time`) AS preAccountTime, hb.hb_state AS
        hongBaoState,
        <include refid="Order_Column_List" />
        FROM yeshi_ec_hongbao_order ho LEFT JOIN (SELECT * FROM
        yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= #{uid}
        <if test="hongBaoState != null">AND v2.`hb_state` = #{hongBaoState}</if>
        )hb ON hb.hb_id = ho.`ho_hongbao_id` LEFT JOIN yeshi_ec_common_order
        co ON co.`co_id`=ho.`ho_order_id` WHERE hb.hb_id IS NOT NULL AND
        co.co_order_no = #{orderNo}
    </select>
    <select id="getCommonOrderByOrderNo" resultMap="ResultMap">
        <!-- 查询用户订单 -->
        SELECT COALESCE(SUM(hb.`hb_money`),0)AS totalMoney,
        COALESCE(SUM(co.`co_payment`),0)AS totalPayment, hb.hb_state AS
        hongBaoState, hb.`hb_type` AS hongBaoType,
        <include refid="Order_Column_List" />
        FROM yeshi_ec_hongbao_order ho LEFT JOIN (SELECT
        <include refid="Hongbao_Column_List" />
        FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= #{uid} AND <![CDATA[v2.`hb_type`<> 10 ]]>
        )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL AND co.co_order_no = #{orderNo} AND
        co.`co_source_type` = #{sourceType}
        <if test="orderState != null">
            AND co.co_state = #{orderState}
            <!-- 已收货 -->
        </if>
        GROUP BY co.`co_order_no`, co.`co_source_type`
    </select>
    <select id="getByOrderNo" resultMap="BaseResultMap">SELECT * FROM
        yeshi_ec_common_order co WHERE co_uid = #{uid} AND
        co_order_no=#{orderNo}
    </select>
    <select id="listByUid" resultMap="BaseResultMap">
        SELECT * FROM yeshi_ec_common_order co WHERE co_uid = #{uid}
        <if test="stateList!=null">
            <foreach collection="stateList" separator=" or " open="and ("
                item="state" close=")">co_state=#{state}</foreach>
        </if>
        limit #{start},#{count}
    </select>
    <select id="firstValidOrderByUid" resultMap="ResultMap">
        SELECT co.*,v2.`hb_get_time` AS accountTime FROM
        yeshi_ec_hongbao_order ho LEFT JOIN yeshi_ec_hongbao_v2 v2 ON
        IF(v2.hb_pid IS NULL,v2.hb_id,v2.hb_pid)=ho.`ho_hongbao_id` LEFT JOIN
        yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` WHERE v2.hb_id
        IS NOT NULL AND v2.`hb_uid` = #{uid} AND v2.`hb_state` = 3
        <if test="typeHB == 1">
            <!-- 自购订单 -->
            AND (v2.hb_type =1 or v2.hb_type =2)
        </if>
        <if test="typeHB == 2">
            <!-- 分享订单 -->
            AND v2.`hb_type` = 20
        </if>
        <if test="typeHB == 3">
            <!-- 邀请订单 -->
            AND (v2.`hb_type` = 5 OR v2.`hb_type` = 6 OR v2.`hb_type` = 7 OR
            v2.`hb_type` = 21 OR v2.`hb_type` = 22)
        </if>
        <if test="typeDate == 3">
            <!-- 本月 -->
            AND DATE_FORMAT(co.`co_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="typeDate == 4">
            <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(),
            '%Y%m'),DATE_FORMAT(co.`co_create_time`, '%Y%m')) = 1
        </if>
        ORDER BY co.`co_id` LIMIT 1
    </select>
    <select id="getFirstShareOrderByUid" resultMap="BaseResultMap">SELECT co.* FROM
        yeshi_ec_hongbao_order ho LEFT JOIN yeshi_ec_hongbao_v2 v2 ON v2.hb_id
        = ho.`ho_hongbao_id` LEFT JOIN yeshi_ec_common_order co ON
        co.`co_id`=ho.`ho_order_id` WHERE v2.`hb_uid` = #{uid} AND
        v2.`hb_type` = 20 ORDER BY co.`co_third_create_time` LIMIT 1
    </select>
    <select id="getTotalRewardMoneyByOrderNoAndSourceType"
        resultType="BigDecimal">SELECT SUM(hb_money) FROM(SELECT v2.`hb_money` FROM
        yeshi_ec_hongbao_order ho LEFT JOIN yeshi_ec_hongbao_v2 v2 ON v2.hb_id
        = ho.`ho_hongbao_id` LEFT JOIN yeshi_ec_common_order co ON
        co.`co_id`=ho.`ho_order_id` WHERE v2.`hb_type` = 20 AND v2.`hb_state`
        = 3 AND co.`co_order_no` = #{orderNo} AND co.`co_source_type`=
        #{sourceType})A
    </select>
    <select id="count24HValidOrderByUid" resultType="Long">SELECT
        IFNULL(COUNT(A.co_order_no),0) FROM (SELECT co.`co_order_no` FROM
        yeshi_ec_hongbao_order ho LEFT JOIN yeshi_ec_hongbao_v2 v2 ON v2.hb_id
        = ho.`ho_hongbao_id` LEFT JOIN yeshi_ec_common_order co ON
        co.`co_id`=ho.`ho_order_id` WHERE v2.`hb_type` = 1 AND
        co.`co_state_whole_order`<![CDATA[<>]]>
        3 AND co.`co_uid` = #{uid} AND co.co_third_create_time <![CDATA[>]]>
        #{minTime} AND co.`co_third_create_time` <![CDATA[<=]]>
        DATE_SUB(NOW(), INTERVAL 1 DAY) GROUP BY
        co.`co_order_no`,co.`co_source_type`)A
    </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
@@ -52,6 +52,7 @@
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
import com.yeshi.fanli.service.inter.order.InviteOrderSubsidyService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
@@ -121,6 +122,9 @@
    @Resource
    private UserVIPInfoService userVIPInfoService;
    @Resource
    private UserInfoService userInfoService;
    // 奖励订单图片
    public final static String PIC_REWARD = "http://img.flqapp.com/resource/order/order_state_reward.png";
@@ -200,10 +204,9 @@
        // 数据加工重新组织
        orderVOFactory(acceptData, listOrder, listGoods, uid);
        return listOrder;
    }
    /**
     * 订单信息加工
@@ -269,11 +272,11 @@
                    order.setVipOrder(false);
            } else
                order.setVipOrder(false);
            if(order.isVipOrder())
            if (order.isVipOrder())
                order.setVipOrderDesc("订单来源:由超级会员的粉丝产生");
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
        SimpleDateFormat formatday = new SimpleDateFormat("yyyy.MM.dd");
        // 2019.8.1开始返回维权信息
@@ -489,7 +492,7 @@
                }
            }
            order.setSignList(signList);
            String hongBaoDate = null;
            String hongBaoState_Str = "";
            String hongbaoInfoFontColor = "#E5005C";
@@ -549,21 +552,21 @@
            hongBaoMap.put("content", hongbaoInfo + " ¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN).toString());
            hongBaoMap.put("fontColor", hongbaoInfoFontColor);
            order.setHongBaoInfo(hongBaoMap);
            // 显示返利、免单详情
            if (HongBaoV2.TYPE_ZIGOU == hongBaoType) {
                // 奖励订单、免单 使用记录
                if (sourceType == null) {
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, null, uid, vip, acceptData);
                } else if (sourceType == Constant.SOURCE_TYPE_TAOBAO) {
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType,
                            listRecordTB, uid, vip, acceptData);
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, listRecordTB, uid, vip,
                            acceptData);
                } else if (sourceType == Constant.SOURCE_TYPE_JD) {
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType,
                            listRecordJD, uid, vip, acceptData);
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, listRecordJD, uid, vip,
                            acceptData);
                } else if (sourceType == Constant.SOURCE_TYPE_PDD) {
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType,
                            listRecordPDD, uid, vip, acceptData);
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, listRecordPDD, uid, vip,
                            acceptData);
                }
            }
@@ -575,8 +578,7 @@
            }
        }
    }
    /**
     * 订单: 免单标识 奖励标识
     * 
@@ -586,21 +588,21 @@
     * @param list
     * @param signList
     */
    private void couponFactory(CommonOrderVO order, boolean hasRewardCoupon,    Integer hongBaoState,
            Integer hongBaoType, List<UserSystemCouponRecord> list, Long uid, boolean vip, AcceptData acceptData) throws Exception{
    private void couponFactory(CommonOrderVO order, boolean hasRewardCoupon, Integer hongBaoState, Integer hongBaoType,
            List<UserSystemCouponRecord> list, Long uid, boolean vip, AcceptData acceptData) throws Exception {
        // 是否免单商品
        boolean freeOrder = false;
        // 是否奖励成功
        boolean rewardSuccess = false;
        boolean version2_1 = VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion());
        if (list != null && list.size() > 0) {
            for (UserSystemCouponRecord couponRecord : list) {
                int goodSource = couponRecord.getGoodSource();
                if (goodSource == 0)
                    goodSource = 1;
                if (order.getOrderNo().equals(couponRecord.getOrderNo()) && goodSource == order.getSourceType()) {
                    Integer state = couponRecord.getState();
                    String systemCouponType = couponRecord.getCouponType();
@@ -634,7 +636,7 @@
                }
            }
        }
        // 免单详情
        if (freeOrder) {
            ClientTextStyleVO rewardStyleVO = new ClientTextStyleVO();
@@ -658,19 +660,19 @@
            rewardMap.put("jump", jump);
            order.setRewardDetail(rewardMap);
        }
        // 已使用奖励券
        if (rewardSuccess) {
            ClientTextStyleVO rewardStyleVO = new ClientTextStyleVO();
            rewardStyleVO.setColor("#E5005C");
            rewardStyleVO.setBottomColor("#FFDCEA");
            if (version2_1) {
                rewardStyleVO.setContent("已使用奖励券 >");
            } else {
                rewardStyleVO.setContent("返利奖励 >");
            }
            Map<String, Object> rewardMap = new HashMap<String, Object>();
            rewardMap.put("text", rewardStyleVO);
            Map<String, Object> jumpLink = new HashMap<String, Object>();
@@ -678,15 +680,15 @@
            jumpLink.put("goodsType", order.getSourceType() + "");
            Map<String, Object> jump = new HashMap<String, Object>();
            jump.put("type", 1); // 1 常规跳转页面
            jump.put("type", 1); // 1 常规跳转页面
            jump.put("params", jumpLink);
            jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("rewardCouponDetail"));
            rewardMap.put("jump", jump);
            order.setRewardDetail(rewardMap);
        }
        // 是否可使用奖励券
        if (!rewardSuccess && !freeOrder && HongBaoV2.TYPE_ZIGOU == hongBaoType
        if (!rewardSuccess && !freeOrder && HongBaoV2.TYPE_ZIGOU == hongBaoType
                && HongBaoV2.STATE_YILINGQU == hongBaoState && !vip && CommonOrder.STATE_WQ != order.getState()) {
            // 下单时间
            Date thirdCreateTime = order.getThirdCreateTime();
@@ -694,11 +696,11 @@
            Date accountTime = order.getAccountTime();
            if (thirdCreateTime == null || accountTime == null)
                return;
            // 下单日期是否是符合上线日期
            long downOrderTime = thirdCreateTime.getTime();
            long limitDate = TimeUtil.parse(Constant.COUPON_REWARD_TIME).getTime();
            if (downOrderTime > limitDate)  {
            if (downOrderTime > limitDate) {
                // 2.1 开始新版
                rewardCounponLimitTime(order, accountTime);
            } else if (hasRewardCoupon) {
@@ -707,16 +709,16 @@
                rewardStyleVO.setColor("#E5005C");
                rewardStyleVO.setBottomColor("#FFDCEA");
                rewardStyleVO.setContent("返利奖励 >");
                Map<String, Object> jumpLink = new HashMap<String, Object>();
                jumpLink.put("orderNo", order.getOrderNo());
                jumpLink.put("goodsType", order.getSourceType() + "");
                Map<String, Object> jump = new HashMap<String, Object>();
                jump.put("type", 2); // 弹框
                jump.put("params", jumpLink);
                jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("rewardCouponDetail"));
                Map<String, Object> rewardMap = new HashMap<String, Object>();
                rewardMap.put("text", rewardStyleVO);
                rewardMap.put("jump", jump);
@@ -725,13 +727,13 @@
        }
    }
    private void rewardCounponLimitTime(CommonOrderVO order,Date accountTime) throws Exception {
    private void rewardCounponLimitTime(CommonOrderVO order, Date accountTime) throws Exception {
        // 倒计时验证
        Date endDay = DateUtil.plusDayDate(Constant.COUPON_REWARD_LIMIT_DAY, accountTime);
        long currentTime = java.lang.System.currentTimeMillis();
        if (endDay.getTime() <= currentTime)
            return;
        String num = null;
        String unit = null;
        boolean canUse = false;
@@ -762,16 +764,16 @@
        }
        // 已经超时
        if (!canUse)
        if (!canUse)
            return;
        Map<String, Object> rewardMap = new HashMap<String, Object>();
        ClientTextStyleVO rewardStyleVO = new ClientTextStyleVO();
        rewardStyleVO.setColor("#E5005C");
        rewardStyleVO.setBottomColor("#FFDCEA");
        rewardStyleVO.setContent("使用奖励券");
        rewardMap.put("text", rewardStyleVO);
        ClientTextStyleVO txt1 = new ClientTextStyleVO();
        txt1.setContent("剩");
        txt1.setColor("#666666");
@@ -804,13 +806,12 @@
        rewardMap.put("jump", jump);
        order.setRewardDetail(rewardMap);
    }
    @Override
    public Map<String, BigDecimal> countHistoryOrder(Long uid, Integer day, Integer source) {
        return commonOrderMapper.countHistoryOrder(uid, day, source);
    }
    @Override
    public OrderCountVO getOrderCount(Long uid, Integer day, Integer source) {
        return commonOrderMapper.getOrderCount(uid, day, source);
@@ -1093,6 +1094,16 @@
        if (oldCommonOrder == null)// 新增
        {
            commonOrder.setCreateTime(new Date());
            // 查询是否为vip
            boolean isVIP = userVIPInfoService.isVIP(commonOrder.getUserInfo().getId());
            if (isVIP)
                commonOrder.setUrank(100);// VIP订单
            else {
                UserInfo user = userInfoService.selectAvailableByPrimaryKey(commonOrder.getUserInfo().getId());
                if (user != null)
                    commonOrder.setUrank(user.getRank());
            }
            commonOrderMapper.insertSelective(commonOrder);
            // 插入映射,保证交易ID的完整性
            commonOrderTradeIdMapMapper.insertSelective(new CommonOrderTradeIdMap(commonOrder.getId(),
@@ -1527,8 +1538,8 @@
        JSONObject map = new JSONObject();
        // 订单标识
        List<String> signList = new ArrayList<String>();
        //signList.add(CommonOrder.TYPE_FANLI);
        //signList.add(PIC_REWARD); // 加入奖励成功图片
        // signList.add(CommonOrder.TYPE_FANLI);
        // signList.add(PIC_REWARD); // 加入奖励成功图片
        map.put("signList", signList);
        ClientTextStyleVO rewardStyleVO = new ClientTextStyleVO();
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
@@ -24,6 +24,8 @@
import com.aliyun.openservices.ons.api.transaction.TransactionProducer;
import com.aliyun.openservices.ons.api.transaction.TransactionStatus;
import com.google.gson.Gson;
import com.opensymphony.xwork2.util.Element;
import com.sun.org.apache.xml.internal.serializer.ElemDesc;
import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
import com.yeshi.fanli.dao.mybatis.money.UserMoneyDetailMapper;
@@ -51,6 +53,7 @@
import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanDrawBack;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
import com.yeshi.fanli.exception.elme.ElmeOrderException;
import com.yeshi.fanli.exception.money.OrderMoneySettleException;
import com.yeshi.fanli.exception.money.UserMoneyDetailException;
import com.yeshi.fanli.exception.order.CommonOrderException;
@@ -202,6 +205,7 @@
        Iterator<String> its = orders.keySet().iterator();
        Map<String, List<TaoBaoOrder>> fanliOrderMap = new HashMap<>();
        Map<String, List<TaoBaoOrder>> shareOrderMap = new HashMap<>();
        Map<String, List<TaoBaoOrder>> elmeOrderMap = new HashMap<>();
        while (its.hasNext()) {
            String orderId = its.next();
@@ -209,26 +213,32 @@
                List<TaoBaoOrder> list = orders.get(orderId);
                String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(),
                        list.get(0).getSourceMediaId(), list.get(0).getAdPositionId());
                if ("饿了么".equalsIgnoreCase(list.get(0).getOrderType())) {
                    // 处理饿了么订单
                    elmeOrderMap.put(orderId, list);
                }
                if (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId())
                        || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)) {// 设置渠道ID当做会员运营ID的位置ID
                    fanliOrderMap.put(orderId, list);
                } else if (!StringUtil.isNullOrEmpty(list.get(0).getRelationId())) {
                    shareOrderMap.put(orderId, list);
                } else {
                    // 通过红包查询
                    CommonOrder commonOrder = commonOrderService
                            .selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, list.get(0).getTradeId());
                else {
                    if (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId())
                            || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)) {// 设置渠道ID当做会员运营ID的位置ID
                        fanliOrderMap.put(orderId, list);
                    } else if (!StringUtil.isNullOrEmpty(list.get(0).getRelationId())) {
                        shareOrderMap.put(orderId, list);
                    } else {
                        // 通过红包查询
                        CommonOrder commonOrder = commonOrderService
                                .selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, list.get(0).getTradeId());
                    if (commonOrder != null) {
                        HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
                        if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null
                                && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) {
                            shareOrderMap.put(orderId, list);
                            continue;
                        if (commonOrder != null) {
                            HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
                            if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null
                                    && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) {
                                shareOrderMap.put(orderId, list);
                                continue;
                            }
                        }
                        fanliOrderMap.put(orderId, list);
                    }
                    fanliOrderMap.put(orderId, list);
                }
            }
        }
@@ -237,6 +247,46 @@
        processShopingFanliOrder(fanliOrderMap);
        // 处理分享赚订单
        processShareGoodsOrder(shareOrderMap);
        // 处理饿了么订单
        processElemeOrder(elmeOrderMap);
    }
    private ElmeOrder createElmeOrder(TaoBaoOrder taoBaoOrder) {
        ElmeOrder elmeOrder = new ElmeOrder();
        elmeOrder.setChannelId("");
        elmeOrder.setCreateTime(new Date());
        elmeOrder
                .setOrderDate(new Date(TimeUtil.convertToTimeTemp(taoBaoOrder.getCreateTime(), "yyyy-MM-dd HH:mm:ss")));
        elmeOrder.setOrderId(taoBaoOrder.getOrderId());
        elmeOrder.setPayMoney(taoBaoOrder.getPayment());
        elmeOrder.setRid(taoBaoOrder.getRelationId());
        if (taoBaoOrder.getOrderState().equalsIgnoreCase("订单结算"))
            elmeOrder.setIsSettle(true);
        else
            elmeOrder.setIsSettle(false);
        elmeOrder.setTrackPid(
                String.format("mm_124933865_%s_%s", taoBaoOrder.getSourceMediaId(), taoBaoOrder.getAdPositionId()));
        if (!StringUtil.isNullOrEmpty(taoBaoOrder.getRelationId())) {
            UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByRelationId(taoBaoOrder.getRelationId());
            if (extraInfo != null)
                elmeOrder.setUid(extraInfo.getUser().getId());
        }
        return elmeOrder;
    }
    private void processElemeOrder(Map<String, List<TaoBaoOrder>> orders) {
        for (Iterator<String> its = orders.keySet().iterator(); its.hasNext();) {
            String orderId = its.next();
            List<TaoBaoOrder> orderList = orders.get(orderId);
            for (TaoBaoOrder taoBaoOrder : orderList) {
                ElmeOrder elmeOrder = createElmeOrder(taoBaoOrder);
                try {
                    elmeOrderService.addOrder(elmeOrder);
                } catch (ElmeOrderException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    @Override
@@ -525,7 +575,7 @@
    }
    @Override
    @Transactional(rollbackFor=Exception.class)
    @Transactional(rollbackFor = Exception.class)
    public void fanliInvaiteAndShare(Long uid) throws TaoBaoWeiQuanException {
        // 邀请赚到账
        try {
@@ -533,7 +583,7 @@
        } catch (OrderMoneySettleException e) {
            e.printStackTrace();
        }
        if(1>0)
        if (1 > 0)
            return;
        //
        try {
fanli/src/main/java/com/yeshi/fanli/service/manger/HongBaoV2AddManager.java
@@ -28,7 +28,6 @@
import com.yeshi.fanli.entity.order.HongBaoOrder;
import com.yeshi.fanli.exception.order.HongBaoException;
import com.yeshi.fanli.exception.user.UserAccountException;
import com.yeshi.fanli.exception.user.UserInfoException;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.order.msg.UserOrderMsgNotificationService;
@@ -78,32 +77,6 @@
    @Resource
    private UserVIPInfoService userVIPInfoService;
    // 保存红包
    public void saveHongBao1(CommonOrder commonOrder, int commonOrderType) throws HongBaoException, UserInfoException {
        // 查询上2级的信息
        long uid = commonOrder.getUserInfo().getId();
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
        if (user == null)
            throw new UserInfoException(1, "用户不存在");
        UserInfo lastUser = threeSaleSerivce.getBoss(uid);
        UserInfo superLastUser = null;
        if (lastUser != null) {
            lastUser = userInfoService.selectAvailableByPrimaryKey(lastUser.getId());
            if (lastUser != null)
                superLastUser = threeSaleSerivce.getBoss(lastUser.getId());
            if (superLastUser != null)
                superLastUser = userInfoService.selectAvailableByPrimaryKey(superLastUser.getId());
        }
        if (commonOrderType == CommonOrder.ORDER_TYPE_ZIGOU) {
            // 保存红包信息
        } else if (commonOrderType == CommonOrder.ORDER_TYPE_SHARE) {
        }
    }
    /**
     * 添加红包信息
     * 
@@ -123,7 +96,6 @@
            boolean hasAdd = false;
            boolean hasUpdate = false;
            Set<Integer> stateSet = new HashSet<>();// 订单状态Set
            boolean isVIP = userVIPInfoService.isVIP(commonOrderList.get(0).getUserInfo().getId());
            for (CommonOrder commonOrder : commonOrderList) {
                stateSet.add(commonOrder.getState());
                goodsCount += commonOrder.getCount();
@@ -131,7 +103,7 @@
                    throw new HongBaoException(1, "订单信息不完整");
                HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
                if (hongBaoOrder == null) {
                    saveHongBao(commonOrder, type, isVIP, notificationMap);
                    saveHongBao(commonOrder, type, notificationMap);
                    hasAdd = true;
                } else {
                    boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap);
@@ -458,8 +430,10 @@
    }
    @Transactional(rollbackFor = Exception.class)
    private void saveHongBao(CommonOrder commonOrder, int type, boolean vip, Map<Integer, HongBaoOrder> notificationMap)
    private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
            throws HongBaoException, UserAccountException {
        boolean vip = commonOrder.getUrank() != null && commonOrder.getUrank() == 100;
        if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
            BigDecimal fanliRate = hongBaoManageService
                    .getRate(new OrderHongBaoRateParams(0, type, false, vip, commonOrder.getThirdCreateTime()));
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeOrderApiUtil.java
@@ -31,7 +31,6 @@
    public static int TK_STATUS_SUCCESS = 14;
    public static int TK_STATUS_INVALID = 13;
    private static TaoBaoPunishOrder parsePunishOrder(JSONObject data) {
        TaoBaoPunishOrder order = new TaoBaoPunishOrder();
        order.setPunishStatus(data.optString("punish_status"));
@@ -202,16 +201,15 @@
    private static TaoBaoOrderResultDTO parseTaoBaoOrderNew(String response) {
        TaoBaoOrderResultDTO dto=new TaoBaoOrderResultDTO(false, false, null, new ArrayList<>());
        TaoBaoOrderResultDTO dto = new TaoBaoOrderResultDTO(false, false, null, new ArrayList<>());
        List<TaoBaoOrder> orderList = new ArrayList<>();
        JSONArray array = null;
        JSONObject data = JSONObject.fromObject(response);
        try {
            JSONObject rootData=data.optJSONObject("tbk_order_details_get_response").optJSONObject("data");
            array =rootData .optJSONObject("results")
                    .optJSONArray("publisher_order_dto");
            dto.setHasPre(    rootData.optBoolean("has_pre"));
            JSONObject rootData = data.optJSONObject("tbk_order_details_get_response").optJSONObject("data");
            array = rootData.optJSONObject("results").optJSONArray("publisher_order_dto");
            dto.setHasPre(rootData.optBoolean("has_pre"));
            dto.setPositionIndex(rootData.optString("position_index"));
            dto.setHasNext(rootData.optBoolean("has_next"));
        } catch (Exception e) {
@@ -260,11 +258,14 @@
                        taoBaoOrder.setPayment(new BigDecimal(item.optString("alipay_total_price")));
                    else
                        taoBaoOrder.setPayment(new BigDecimal(0));
                    taoBaoOrder.setPrice(new BigDecimal(item.optString("item_price")));
                    if (StringUtil.isNullOrEmpty(item.optString("item_price")))
                        taoBaoOrder.setPrice(new BigDecimal(0));
                    else
                        taoBaoOrder.setPrice(new BigDecimal(item.optString("item_price")));
                    if (!StringUtil.isNullOrEmpty(item.optString("pay_price")))
                        taoBaoOrder.setSettlement(new BigDecimal(item.optString("pay_price")));
                    else
                        taoBaoOrder.setSettlement(new BigDecimal(0));
                        taoBaoOrder.setSettlement(taoBaoOrder.getPayment());
                    taoBaoOrder.setSettlementTime(item.optString("tk_earning_time"));
                    taoBaoOrder.setShop(item.optString("seller_shop_title"));
                    taoBaoOrder.setSourceMediaId(item.optString("site_id"));
@@ -396,7 +397,7 @@
        return finalResult;
    }
    /**
     * 新版本淘宝订单
     */
@@ -412,21 +413,28 @@
        return getTaoBaoOrderList(startTime, endTime, queryType, 3);
    }
    /**
     * 淘宝渠道订单
     *
     * @param startTime
     * @param endTime
     * @param queryType
     * @return
     */
    public static List<TaoBaoOrder> getTaoBaoRelationOrderList(long startTime, long endTime, int queryType) {
        return getTaoBaoOrderList(startTime, endTime, queryType, 2);
    }
    public static List<TaoBaoOrder> getTaoBaoCommonOrderList(long startTime, long endTime, int queryType) {
        return getTaoBaoOrderList(startTime, endTime, queryType, 1);
    }
    public static List<TaoBaoOrder> getTaoBaoOrderList(long startTime, long endTime, int queryType,int orderScene) {
    public static List<TaoBaoOrder> getTaoBaoOrderList(long startTime, long endTime, int queryType, int orderScene) {
        List<TaoBaoOrder> orderList = new ArrayList<>();
        // 跨度20分钟
        long span=(1000 * 60 * 20L);
        long span = (1000 * 60 * 20L);
        long jianGe = endTime - startTime;
        long page = jianGe %span==0?jianGe/span:jianGe /span+1 ;
        long page = jianGe % span == 0 ? jianGe / span : jianGe / span + 1;
        if (page == 0)
            page = 1;
        for (int i = 1; i <= page; i++) {
@@ -435,22 +443,33 @@
            if (end > endTime)
                end = endTime;
            TaoBaoOrderResultDTO dto = queryNewOrder(TimeUtil.getGernalTime(start, "yyyy-MM-dd HH:mm:ss"),
                    TimeUtil.getGernalTime(end, "yyyy-MM-dd HH:mm:ss"),null, queryType, orderScene);
                    TimeUtil.getGernalTime(end, "yyyy-MM-dd HH:mm:ss"), null, queryType, orderScene);
            if (dto != null)
                orderList.addAll(dto.getOrderList());
            while(dto.isHasNext())
            {
                dto=queryNewOrder(TimeUtil.getGernalTime(start, "yyyy-MM-dd HH:mm:ss"),
                        TimeUtil.getGernalTime(end, "yyyy-MM-dd HH:mm:ss"),dto.getPositionIndex(), queryType, orderScene);
            while (dto.isHasNext()) {
                dto = queryNewOrder(TimeUtil.getGernalTime(start, "yyyy-MM-dd HH:mm:ss"),
                        TimeUtil.getGernalTime(end, "yyyy-MM-dd HH:mm:ss"), dto.getPositionIndex(), queryType,
                        orderScene);
                if (dto != null)
                    orderList.addAll(dto.getOrderList());
            }
        }
        return orderList;
    }
    private static TaoBaoOrderResultDTO queryNewOrder(String startTime, String endTime,String positionIndex, int queryType, int orderScene) {
    /**
     * 淘宝订单查询
     *
     * @param startTime
     * @param endTime
     * @param positionIndex
     * @param queryType
     *            1:按照订单淘客创建时间查询,2:按照订单淘客付款时间查询,3:按照订单淘客结算时间查询
     * @param orderScene
     * @return
     */
    private static TaoBaoOrderResultDTO queryNewOrder(String startTime, String endTime, String positionIndex,
            int queryType, int orderScene) {
        Map<String, String> params = new HashMap<>();
        params.put("query_type", queryType + "");
        params.put("page_size", "100");
@@ -458,7 +477,7 @@
        params.put("end_time", endTime);
        params.put("page_no", "1");
        params.put("order_scene", orderScene + "");
        if(!StringUtil.isNullOrEmpty(positionIndex))
        if (!StringUtil.isNullOrEmpty(positionIndex))
            params.put("position_index", positionIndex + "");
        params.put("method", "taobao.tbk.order.details.get");
        TaoKeAppInfo app = new TaoKeAppInfo();