| <?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.matrix.system.hive.dao.SysOrderItemDao"> | 
|   | 
|     <resultMap type="SysOrderItem" id="SysOrderItemMap"> | 
|         <id property="id" column="ID"/> | 
|         <result property="orderId" column="ORDER_ID"/> | 
|         <!-- <result property="projId" column="PROJ_ID" /> | 
|         <result property="skuId" column="SKU_ID" /> --> | 
|         <result property="count" column="COUNT"/> | 
|         <!-- <result property="taocanId" column="TAOCAN_ID" /> --> | 
|         <result property="isFree" column="IS_FREE"/> | 
|         <result property="type" column="TYPE"/> | 
|         <result property="price" column="PRICE"/> | 
|         <result property="zkPrice" column="ZK_PRICE"/> | 
|         <result property="goodsId" column="GOODS_ID"/> | 
|         <result property="assembleId" column="ASSEMBLE_ID"/> | 
|   | 
|   | 
|         <result property="status" column="status"/> | 
|         <result property="cardPay" column="card_pay"/> | 
|         <result property="cashPay" column="cash_pay"/> | 
|         <result property="arrears" column="arrears"/> | 
|         <result property="payMethod" column="pay_method"/> | 
|         <result property="payMethodDetail" column="pay_method_detail"/> | 
|         <!-- 扩展字段 --> | 
|         <result property="orderNo" column="ORDER_NO"/> | 
|         <result property="orderTime" column="ORDER_TIME"/> | 
|   | 
|         <association property="shoppingGoods" | 
|                      resultMap="com.matrix.system.hive.dao.ShoppingGoodsDao.ShoppingGoodsSimpleMap"></association> | 
|   | 
|   | 
|     </resultMap> | 
|   | 
|     <!-- 查询会员待处理的订单商品 --> | 
|     <select id="selectDclItem" resultMap="SysOrderItemMap"> | 
|         SELECT | 
|         a.ACTIVITY, | 
|         a.ACTUAL_PAY, | 
|         a.IS_ARREARS, | 
|         a.IS_CROSS, | 
|         a.ORDER_NO, | 
|         a.ORDER_TIME, | 
|         a.REMARK, | 
|         a.TOTAL, | 
|         a.SKU_ID, | 
|         b.COUNT, | 
|         b.ID, | 
|         b.IS_FREE, | 
|         b.ORDER_ID, | 
|         b.ASSEMBLE_ID | 
|         a.ZK_PRICE, | 
|         a.PRICE, | 
|         a.GOODS_ID, | 
|         a.ASSEMBLE_ID, | 
|         a.status, | 
|         a.cardPay, | 
|         a.cashPay, | 
|         a.arrears | 
|         FROM | 
|         sys_order a | 
|         LEFT JOIN | 
|         sys_order_item b ON a.id = b.ORDER_ID | 
|         WHERE | 
|         a.VIP_ID =#{vipId} | 
|         AND b.ASSEMBLE_ID IS NOT NULL | 
|     </select> | 
|   | 
|     <!-- 查询会员待处理的订单商品总数 --> | 
|     <select id="selectDclItemTotal" resultType="java.lang.Integer"> | 
|         SELECT | 
|         count(*) | 
|         FROM | 
|         sys_order a | 
|         LEFT JOIN sys_order_item b ON a.id = b.ORDER_ID | 
|         WHERE | 
|         a.VIP_ID = #{vipId} | 
|         AND b.ASSEMBLE_ID IS NOT NULL | 
|     </select> | 
|   | 
|     <!-- 插入方法 --> | 
|     <insert id="insert" parameterType="SysOrderItem" | 
|             useGeneratedKeys="true" keyProperty="id"> | 
|         INSERT INTO sys_order_item ( | 
|         ID, | 
|         ORDER_ID, | 
|         COUNT, | 
|         TYPE, | 
|         IS_FREE, | 
|         PRICE, | 
|         ZK_PRICE, | 
|         GOODS_ID, | 
|         ASSEMBLE_ID, | 
|         status, | 
|         card_Pay, | 
|         cash_Pay, | 
|         arrears, | 
|         pay_method, | 
|         pay_method_detail | 
|         ) | 
|         VALUES ( | 
|         #{id}, | 
|         #{orderId}, | 
|         #{count}, | 
|         #{type}, | 
|         #{isFree}, | 
|         #{price}, | 
|         #{zkPrice}, | 
|         #{goodsId}, | 
|         #{assembleId}, | 
|         #{status}, | 
|         #{cardPay}, | 
|         #{cashPay}, | 
|         #{arrears}, | 
|         #{payMethod}, | 
|         #{payMethodDetail} | 
|         ) | 
|     </insert> | 
|   | 
|   | 
|     <!-- 根据id更新 部分更新 --> | 
|     <update id="update"> | 
|         UPDATE sys_order_item | 
|         <set> | 
|             <if test="orderId != null and orderId !='' "> | 
|                 ORDER_ID = #{orderId}, | 
|             </if> | 
|             <if test="count != null and count !='' "> | 
|                 COUNT = #{count}, | 
|             </if> | 
|             <if test="isFree != null and isFree !='' "> | 
|                 IS_FREE = #{isFree}, | 
|             </if> | 
|             <if test="type != null and type !='' "> | 
|                 TYPE = #{type}, | 
|             </if> | 
|             <if test="price != null "> | 
|                 PRICE = #{price}, | 
|             </if> | 
|             <if test="zkPrice != null "> | 
|                 ZK_PRICE = #{zkPrice}, | 
|             </if> | 
|             <if test="goodsId != null and goodsId !='' "> | 
|                 GOODS_ID = #{goodsId}, | 
|             </if> | 
|             <if test="assembleId != null and assembleId !='' "> | 
|                 ASSEMBLE_ID = #{assembleId}, | 
|             </if> | 
|             <if test="status != null and status !='' "> | 
|                 status = #{status}, | 
|             </if> | 
|             <if test="cardPay != null and cardPay !='' "> | 
|                 card_Pay = #{cardPay}, | 
|             </if> | 
|             <if test="cashPay != null and cashPay !='' "> | 
|                 cash_Pay = #{cashPay}, | 
|             </if> | 
|             <if test="arrears == 0 or arrears != null and arrears !='' "> | 
|                 arrears = #{arrears}, | 
|             </if> | 
|             <if test="payMethod != null and payMethod !='' "> | 
|                 pay_method = #{payMethod}, | 
|             </if> | 
|             <if test="payMethodDetail != null and payMethodDetail !='' "> | 
|                 pay_method_detail = #{payMethodDetail}, | 
|             </if> | 
|   | 
|   | 
|         </set> | 
|         WHERE ID=#{id} | 
|     </update> | 
|   | 
|   | 
|     <!-- 批量删除 --> | 
|     <delete id="deleteByIds" parameterType="java.util.List"> | 
|         delete from sys_order_item where ID in | 
|         <foreach collection="list" index="index" item="item" open="(" | 
|                  separator="," close=")"> | 
|             #{item} | 
|         </foreach> | 
|     </delete> | 
|   | 
|     <!-- 根据id删除 --> | 
|     <delete id="deleteById"> | 
|         DELETE FROM sys_order_item | 
|         where ID=#{id} | 
|     </delete> | 
|     <delete id="deleteByOrderId"> | 
|             DELETE FROM sys_order_item where order_id=#{id} | 
|     </delete> | 
|   | 
|   | 
|     <!-- 分页查询 --> | 
|     <select id="selectInPage" resultMap="SysOrderItemMap"> | 
|         <include refid="select"></include> | 
|         <include refid="from"></include> | 
|         <include refid="where"></include> | 
|         <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> | 
|             <if test="pageVo.sort !=null  and pageVo.order !=null"> | 
|                 order by | 
|                 ${pageVo.sort} ${pageVo.order} | 
|             </if> | 
|             <if test="pageVo.offset >=0  and pageVo.limit >0"> | 
|                 limit | 
|                 #{pageVo.offset},#{pageVo.limit} | 
|             </if> | 
|         </if> | 
|     </select> | 
|   | 
|     <!-- 查询总条数 --> | 
|     <select id="selectTotalRecord" resultType="java.lang.Integer"> | 
|         select count(*) | 
|         <include refid="from"></include> | 
|         <include refid="where"></include> | 
|     </select> | 
|   | 
|     <!-- 根据id查询 --> | 
|     <select id="selectById" resultMap="SysOrderItemMap"> | 
|         <include refid="select"></include> | 
|         <include refid="from"></include> | 
|         where | 
|         ID=#{id} | 
|     </select> | 
|   | 
|   | 
|     <select id="selectByOrderId" resultMap="SysOrderItemMap"> | 
|         select | 
|         i.ID, | 
|         i.ORDER_ID, | 
|         i.COUNT, | 
|         i.TYPE, | 
|         i.IS_FREE, | 
|         i.PRICE, | 
|         i.ZK_PRICE, | 
|         i.GOODS_ID, | 
|         i.ASSEMBLE_ID, | 
|         i.status, | 
|         i.card_Pay, | 
|         i.cash_Pay, | 
|         i.arrears, | 
|         i.pay_method, | 
|         i.pay_method_detail, | 
|   | 
|         g.id as sp_id, | 
|         g.name, | 
|         g.seal_pice, | 
|         g.is_course, | 
|         g.car_use_count, | 
|         g.good_type, | 
|         g.code | 
|   | 
|   | 
|         from sys_order_item i | 
|         left  join shopping_goods g on i.goods_id=g.id | 
|         where ORDER_ID =#{orderId} | 
|     </select> | 
|   | 
|     <!-- 根据对象查询 --> | 
|     <select id="selectByModel" resultMap="SysOrderItemMap"> | 
|         <include refid="select"></include> | 
|         <include refid="from"></include> | 
|         <include refid="where"></include> | 
|     </select> | 
|     <!-- 根据商品id查询改商品下单次数总和--> | 
|     <select id="selectByGoodsId" resultType="java.lang.Integer"> | 
|         select sum(COUNT) from sys_order_item a | 
|         left join  sys_order b on b.ID=a.ORDER_ID | 
|         where a.GOODS_ID = #{goodsId}  | 
|         and b.STATU !='已取消' | 
|     </select> | 
|   | 
|   | 
|     <select id="selectItemByTime" resultMap="SysOrderItemMap"> | 
|         select a.* | 
| from sys_order_item a | 
|          left join sys_order b on a.ORDER_ID=b.ID | 
| where | 
| b.SHOP_ID=#{shopId} | 
| and to_days(b.pay_time) = to_days(#{time}); | 
|   | 
|     </select> | 
|   | 
|     <sql id="select"> | 
|     select | 
|         ID, | 
|         ORDER_ID, | 
|         COUNT, | 
|         TYPE, | 
|         IS_FREE, | 
|         PRICE, | 
|         ZK_PRICE, | 
|         GOODS_ID, | 
|         ASSEMBLE_ID, | 
|         status, | 
|         card_Pay, | 
|         cash_Pay, | 
|         arrears, | 
|         pay_method, | 
|         pay_method_detail | 
|     </sql> | 
|     <sql id="from"> | 
|     from sys_order_item | 
|     </sql> | 
|     <sql id="where"> | 
|         where 1=1 | 
|         <if test="record!=null"> | 
|             <if test="record.id != null and record.id !='' "> | 
|                 and ID = #{record.id} | 
|             </if> | 
|             <if test="record.orderId != null and record.orderId !='' "> | 
|                 and ORDER_ID = #{record.orderId} | 
|             </if> | 
|             <if test="record.type != null and record.type !='' "> | 
|                 and TYPE LIKE CONCAT('%',#{record.type},'%') | 
|             </if> | 
|             <if test="record.goodsId != null and record.goodsId !='' "> | 
|                 and GOODS_ID = #{record.goodsId} | 
|             </if> | 
|             <if test="record.assembleId != null and record.assembleId !='' "> | 
|                 and ASSEMBLE_ID = #{record.assembleId} | 
|             </if> | 
|             <if test="record.status != null and record.status !='' "> | 
|                 and status = #{record.status} | 
|             </if> | 
|         </if> | 
|     </sql> | 
|   | 
|   | 
|     <!-- 销售明细 --> | 
|     <select id="selectItemDetail" resultType="java.util.HashMap" parameterType="java.util.HashMap"> | 
|         select | 
|         f.SHOP_NAME, | 
|         b.pay_time, | 
|         b.ORDER_NO, | 
|         d.su_name, | 
|         e.VIP_NAME, | 
|         c.name as goodsName, | 
|         g.name as cateName, | 
|         a.COUNT, | 
|         a.ZK_PRICE, | 
|         a.IS_FREE, | 
|         a.pay_method, | 
|         a.status | 
|         from sys_order_item a | 
|         left join sys_order b on a.ORDER_ID=b.ID | 
|         left join shopping_goods c on a.goods_id=c.id | 
|         left join sys_users d on b.STAFF_ID=d.su_id | 
|         left join sys_vip_info e on e.ID=b.VIP_ID | 
|         left join sys_shop_info f on f.ID=b.SHOP_ID | 
|         left join shopping_goods_category g on c.cate_id=g.id | 
|         <where> | 
|             <if test="shopId != null and  shopId != ''"> | 
|                 and b.SHOP_ID =#{shopId} | 
|             </if> | 
|             <if test="beginTime != null and beginTime != ''  "> | 
|                 and b.pay_time  <![CDATA[>=]]> #{beginTime} | 
|             </if> | 
|             <if test="endTime != null and endTime != ''  "> | 
|                 and b.pay_time <![CDATA[<=]]> #{endTime} | 
|             </if> | 
|   | 
|             <if test="vipQueryKey != null and vipQueryKey != ''  "> | 
|                 and e.VIP_NAME like concat('%',#{vipQueryKey},'%') | 
|                 or (e.VIP_NO like concat('%',#{vipQueryKey},'%') | 
|                 or e.PHONE like concat('%',#{vipQueryKey},'%') | 
|                 ) | 
|             </if> | 
|   | 
|             <if test="goodsName != null and goodsName != ''  "> | 
|               and  c.name like concat('%',#{goodsName},'%') | 
|             </if> | 
|   | 
|             <if test="shopId != null and shopId != ''  "> | 
|                 and f.id=#{shopId} | 
|             </if> | 
|   | 
|             <if test="cateId != null and cateId != ''  "> | 
|                 and  c.cate_id=#{cateId} | 
|             </if> | 
|             <if test="guwenId != null and guwenId != ''  "> | 
|                 and  b.STAFF_ID=#{guwenId} | 
|             </if> | 
|             <if test="status != null and status != ''  "> | 
|                 and  a.status=#{status} | 
|             </if> | 
|   | 
|         </where> | 
|   | 
|         <if test="sort !=null and sort!=''"> order by ${sort} ${order}</if> | 
|         <if test="(offset !=null and offset!='') or offset==0 "> | 
|             limit ${offset},${limit} | 
|         </if> | 
|     </select> | 
|     <select id="selectItemDetailTotal" resultType="java.lang.Integer"> | 
|         select count(a.id) | 
|         from sys_order_item a | 
|         left join sys_order b on a.ORDER_ID=b.ID | 
|         left join shopping_goods c on a.goods_id=c.id | 
|         left join sys_users d on b.STAFF_ID=d.su_id | 
|         left join sys_vip_info e on e.ID=b.VIP_ID | 
|         left join sys_shop_info f on f.ID=b.SHOP_ID | 
|         left join shopping_goods_category g on c.cate_id=g.id | 
|         <where> | 
|             <if test="shopId != null and  shopId != ''"> | 
|                 and b.SHOP_ID =#{shopId} | 
|             </if> | 
|             <if test="beginTime != null and beginTime != ''  "> | 
|                 and b.pay_time  <![CDATA[>=]]> #{beginTime} | 
|             </if> | 
|             <if test="endTime != null   and endTime != ''  "> | 
|                 and b.pay_time <![CDATA[<=]]> #{endTime} | 
|             </if> | 
|   | 
|             <if test="vipQueryKey != null and vipQueryKey != ''  "> | 
|                 and e.VIP_NAME like concat('%',#{vipQueryKey},'%') | 
|                 or (e.VIP_NO like concat('%',#{vipQueryKey},'%') | 
|                 or e.PHONE like concat('%',#{vipQueryKey},'%') | 
|                 ) | 
|             </if> | 
|   | 
|             <if test="goodsName != null and goodsName != ''  "> | 
|                 and  c.name like concat('%',#{goodsName},'%') | 
|             </if> | 
|   | 
|             <if test="shopId != null and shopId != ''  "> | 
|                 and f.id=#{shopId} | 
|             </if> | 
|   | 
|             <if test="cateId != null and cateId != ''  "> | 
|                 and  c.cate_id=#{cateId} | 
|             </if> | 
|             <if test="guwenId != null and guwenId != ''  "> | 
|                 and  b.STAFF_ID=#{guwenId} | 
|             </if> | 
|             <if test="status != null and status != ''  "> | 
|                 and  a.status=#{status} | 
|             </if> | 
|         </where> | 
|     </select> | 
|   | 
|   | 
|     <!-- 销售明细统计 --> | 
|     <select id="summaryItemDetail" resultType="java.util.HashMap" parameterType="java.util.HashMap"> | 
|         select | 
|         f.SHOP_NAME, | 
|         c.name as goodsName, | 
|         c.id, | 
|         g.name as cateName , | 
|         SUM(a.COUNT) as COUNT, | 
|         ROUND(SUM(a.ZK_PRICE * a.COUNT),2) as ZK_PRICE | 
|         from sys_order_item a | 
|         left join sys_order b on a.ORDER_ID = b.ID | 
|         left join shopping_goods c on a.goods_id = c.id | 
|         left join sys_shop_info f on f.ID=b.SHOP_ID | 
|         left join shopping_goods_category g on c.cate_id = g.id | 
|         <where> | 
|             <if test="shopId != null and  shopId != ''"> | 
|                 and b.SHOP_ID =#{shopId} | 
|             </if> | 
|             <if test="beginTime != null   and beginTime != ''  "> | 
|                 and b.pay_time  <![CDATA[>=]]> #{beginTime} | 
|             </if> | 
|             <if test="endTime != null  and endTime != ''  "> | 
|                 and b.pay_time <![CDATA[<=]]> #{endTime} | 
|             </if> | 
|             <if test="goodsName != null and goodsName != ''  "> | 
|                and c.name like concat('%',#{goodsName},'%') | 
|             </if> | 
|             <if test="shopId != null and shopId != ''  "> | 
|                 and f.id=#{shopId} | 
|             </if> | 
|             <if test="cateId != null and cateId != ''  "> | 
|                 and   c.cate_id=#{cateId} | 
|             </if> | 
|             <if test="status != null and status != ''  "> | 
|                 and  a.status=#{status} | 
|             </if> | 
|         </where> | 
|         group by c.id ,f.id | 
|         <if test="sort !=null and sort!=''"> order by ${sort} ${order}</if> | 
|         <if test="(offset !=null and offset!='') or offset==0 "> | 
|             limit ${offset},${limit} | 
|         </if> | 
|     </select> | 
|   | 
|     <select id="summaryItemDetailTotal" resultType="java.lang.Integer"> | 
|         select count(1) from (  select count(1) | 
|         from sys_order_item a | 
|         left join sys_order b on a.ORDER_ID = b.ID | 
|         left join shopping_goods c on a.goods_id = c.id | 
|         left join sys_shop_info f on f.ID=b.SHOP_ID | 
|         left join shopping_goods_category g on c.cate_id = g.id | 
|         <where> | 
|             <if test="shopId != null and  shopId != ''"> | 
|                 and b.SHOP_ID =#{shopId} | 
|             </if> | 
|             <if test="beginTime != null  and beginTime != ''  "> | 
|                 and b.pay_time  <![CDATA[>=]]> #{beginTime} | 
|             </if> | 
|             <if test="endTime != null  and endTime != ''   "> | 
|                 and b.pay_time <![CDATA[<=]]> #{endTime} | 
|             </if> | 
|             <if test="goodsName != null and goodsName != ''  "> | 
|               and  c.name like concat('%',#{goodsName},'%') | 
|             </if> | 
|             <if test="shopId != null and shopId != ''  "> | 
|                and f.id=#{shopId} | 
|             </if> | 
|             <if test="cateId != null and cateId != ''  "> | 
|                and c.cate_id=#{cateId} | 
|             </if> | 
|             <if test="status != null and status != ''  "> | 
|                 and  a.status=#{status} | 
|             </if> | 
|         </where> | 
|         group by c.id ,f.id) t | 
|     </select> | 
|   | 
|     <select id="selectApiOrderDetailItemsByOrderId" resultType="com.matrix.system.app.vo.OrderDetailItemVo"> | 
|         select | 
|                a.id id, | 
|                b.name goodsName, | 
|                a.COUNT count, | 
|                a.cash_Pay cashPay, | 
|                a.card_Pay cardPay, | 
|                a.PRICE price, | 
|                a.ZK_PRICE zkPrice, | 
|                a.status status | 
|         from sys_order_item a | 
|         inner join shopping_goods b on a.goods_id=b.id | 
|         where a.ORDER_ID=#{orderId}; | 
|     </select> | 
|   | 
| </mapper> |