SalesDetailMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.kmall.schedule.dao.SalesDetailMapper">
  4. <!-- 抓取订单销售明细数据-->
  5. <select id="querySalesSystemFormatList" resultType="com.kmall.schedule.entity.NewSystemFormatEntiy">
  6. SELECT distinct
  7. o.id,
  8. g.goods_id,
  9. o.order_sn as receiptNo,
  10. u.username as cashRegisterNo,
  11. o.create_time as timeStampDetails,
  12. u.username as staffID,
  13. u.username as staffName,
  14. gs.hs_code as hsCode,
  15. gs.hs_code_name as hsCodeName,
  16. gs.goods_sn as ematouCode,
  17. gs.plu as plu,
  18. gs.mychem_id as mychemID,
  19. gs.english_name as productNameEN,
  20. gs.name as productNameCN,
  21. gs.prod_barcode as barcode,
  22. gs.ciq_prod_model as packSize,
  23. gs.goods_number as goodsNumber,
  24. uc.name as productSpecification,
  25. b.name as brand,
  26. gs.daily_price as edlp,
  27. sr.bottom_line_price as costPrice,
  28. sr.bottom_line_price*gs.goods_number as primeCost,
  29. g.number as unitSold,
  30. g.actual_payment_amount as totalSalesInclTax,
  31. gs.goods_rate as taxRate,
  32. '专柜单品' as productCategory,
  33. sup.child_supplier_name as supplierName,
  34. '300' as orderStatus,
  35. g.tax_price as taxPrice,
  36. s.store_name as storeName,
  37. s.store_number as storeNameSn,
  38. o.pay_flag as payFlag,
  39. o.pay_transaction_id as orderSnWx,
  40. o.ali_trade_no as orderSnAli
  41. FROM
  42. mall_order o
  43. LEFT JOIN mall_order_goods g ON o.id = g.order_id
  44. left join mall_store s on o.store_id = s.id
  45. LEFT JOIN mall_goods gs ON g.goods_id = gs.id
  46. left join mall_sale_record record on record.order_sn = o.order_sn
  47. LEFT JOIN sys_user u ON record.saller_id = u.user_id
  48. left join sys_cus_unit_code uc on uc.code = gs.unit_code
  49. left join mall_product_store_rela sr on sr.goods_id=gs.id and sr.store_id = o.store_id
  50. left join mall_brand b on b.id=sr.brand_id
  51. left join mall_supplier sup on gs.supplier_id = sup.id
  52. WHERE 1=1
  53. <if test="orderSn != null and orderSn.trim() != ''">
  54. AND o.order_sn LIKE concat('%',#{orderSn},'%')
  55. </if>
  56. <choose>
  57. <when test="orderStatus != null and orderStatus.trim() != ''">
  58. AND o.order_status = #{orderStatus}
  59. </when>
  60. <otherwise>
  61. AND o.order_status in ('401','300')
  62. </otherwise>
  63. </choose>
  64. <if test="isOnfiilineOrder != null">
  65. AND o.is_onffline_order = #{isOnfiilineOrder}
  66. </if>
  67. <if test="startTime != null and startTime != ''">
  68. AND o.add_time <![CDATA[ > ]]> STR_TO_DATE(#{startTime}, '%Y-%m-%d %H:%i:%s')
  69. </if>
  70. <if test="endTime != null and endTime != ''">
  71. AND o.add_time <![CDATA[ < ]]> STR_TO_DATE(#{endTime}, '%Y-%m-%d %H:%i:%s')
  72. </if>
  73. <if test="storeName != null and storeName != ''">
  74. AND s.store_name LIKE concat('%',#{storeName},'%')
  75. </if>
  76. union
  77. SELECT distinct
  78. o.id,
  79. g.goods_id,
  80. o.order_sn as receiptNo,
  81. u.username as cashRegisterNo,
  82. mor.create_time as timeStampDetails,
  83. u.username as staffID,
  84. u.username as staffName,
  85. gs.hs_code as hsCode,
  86. gs.hs_code_name as hsCodeName,
  87. gs.goods_sn as ematouCode,
  88. gs.plu as plu,
  89. gs.mychem_id as mychemID,
  90. gs.english_name as productNameEN,
  91. gs.name as productNameCN,
  92. gs.prod_barcode as barcode,
  93. gs.ciq_prod_model as packSize,
  94. gs.goods_number as goodsNumber,
  95. uc.name as productSpecification,
  96. b.name as brand,
  97. gs.daily_price as edlp,
  98. sr.bottom_line_price as costPrice,
  99. sr.bottom_line_price*gs.goods_number as primeCost,
  100. g.number as unitSold,
  101. g.actual_payment_amount as totalSalesInclTax,
  102. gs.goods_rate as taxRate,
  103. '专柜单品' as productCategory,
  104. sup.child_supplier_name as supplierName,
  105. o.order_status as orderStatus,
  106. g.tax_price as taxPrice,
  107. s.store_name as storeName,
  108. s.store_number as storeNameSn,
  109. o.pay_flag as payFlag,
  110. o.pay_transaction_id as orderSnWx,
  111. o.ali_trade_no as orderSnAli
  112. FROM
  113. mall_order o
  114. LEFT JOIN mall_order_goods g ON o.id = g.order_id
  115. left join mall_store s on o.store_id = s.id
  116. LEFT JOIN mall_goods gs ON g.goods_id = gs.id
  117. left join mall_sale_record record on record.order_sn = o.order_sn
  118. LEFT JOIN sys_user u ON record.saller_id = u.user_id
  119. left join sys_cus_unit_code uc on uc.code = gs.unit_code
  120. left join mall_product_store_rela sr on sr.goods_id=gs.id and sr.store_id = o.store_id
  121. left join mall_brand b on b.id=sr.brand_id
  122. left join mall_supplier sup on gs.supplier_id = sup.id
  123. left join mall_order_refund mor on mor.out_refund_no = o.order_sn
  124. WHERE 1=1
  125. <if test="orderSn != null and orderSn.trim() != ''">
  126. AND o.order_sn LIKE concat('%',#{orderSn},'%')
  127. </if>
  128. <choose>
  129. <when test="orderStatus != null and orderStatus.trim() != ''">
  130. AND o.order_status = #{orderStatus}
  131. </when>
  132. <otherwise>
  133. AND o.order_status = '401'
  134. </otherwise>
  135. </choose>
  136. <if test="isOnfiilineOrder != null">
  137. AND o.is_onffline_order = #{isOnfiilineOrder}
  138. </if>
  139. <if test="startTime != null and startTime != ''">
  140. AND mor.create_time <![CDATA[ > ]]> STR_TO_DATE(#{startTime}, '%Y-%m-%d %H:%i:%s')
  141. </if>
  142. <if test="endTime != null and endTime != ''">
  143. AND mor.create_time <![CDATA[ < ]]> STR_TO_DATE(#{endTime}, '%Y-%m-%d %H:%i:%s')
  144. </if>
  145. <if test="storeName != null and storeName != ''">
  146. AND s.store_name LIKE concat('%',#{storeName},'%')
  147. </if>
  148. </select>
  149. <!--记录推送数据-->
  150. <insert id="writebackSalesDet" parameterType="com.kmall.schedule.entity.NewSystemFormatEntiy">
  151. insert into mall_sales_detail_data_log
  152. <trim prefix="(" suffix=")" suffixOverrides=",">
  153. <if test="merchSn != null">merch_sn,</if>
  154. <if test="merchSnName != null">merch_sn_name,</if>
  155. <if test="thirdMerchSn != null">third_merch_sn,</if>
  156. <if test="thirdMerchSnName != null">third_merch_sn_name,</if>
  157. <if test="receiptNo != null">receipt_no,</if>
  158. <if test="storeName != null">store_name,</if>
  159. <if test="storeNameSn != null">store_name_sn,</if>
  160. <if test="cashRegisterNo != null">ash_register_no,</if>
  161. <if test="timeStampDetails != null">time_stamp,</if>
  162. <if test="staffID != null">staff_id,</if>
  163. <if test="staffName != null">staff_name,</if>
  164. <if test="payFlag != null">pay_flag,</if>
  165. <if test="orderStatus != null">order_status,</if>
  166. <if test="orderSnWx != null">order_sn_wx,</if>
  167. <if test="orderSnAli != null">order_sn_ali,</if>
  168. <if test="hsCode != null">hs_code,</if>
  169. <if test="hsCodeName != null">hs_code_name,</if>
  170. <if test="ematouCode != null">ematou_code,</if>
  171. <if test="plu != null">plu,</if>
  172. <if test="mychemID != null">mychem_id,</if>
  173. <if test="productNameEN != null">product_name_en,</if>
  174. <if test="productNameCN != null">product_name_cn,</if>
  175. <if test="barcode != null">barcode,</if>
  176. <if test="packSize != null">pack_size,</if>
  177. <if test="productSpecification != null">product_spec,</if>
  178. <if test="brand != null">brand,</if>
  179. <if test="edlp != null">edlp,</if>
  180. <if test="currentPrice != null">current_price,</if>
  181. <if test="costPrice != null">cost_price,</if>
  182. <if test="taxRate != null">tax_rate,</if>
  183. <if test="productCategory != null">product_category,</if>
  184. <if test="supplierName != null">supplier_name,</if>
  185. <if test="transactionType != null">transaction_type,</if>
  186. <if test="saleReturnType != null">sale_return_type,</if>
  187. <if test="salesDetStatus != null">det_status,</if>
  188. <if test="salesDetMsg != null">det_msg,</if>
  189. det_date
  190. </trim>
  191. <trim prefix="values (" suffix=")" suffixOverrides=",">
  192. <if test="merchSn != null">#{merchSn},</if>
  193. <if test="merchSnName != null">#{merchSnName},</if>
  194. <if test="thirdMerchSn != null">#{thirdMerchSn},</if>
  195. <if test="thirdMerchSnName != null">#{thirdMerchSnName},</if>
  196. <if test="receiptNo != null">#{receiptNo},</if>
  197. <if test="storeName != null">#{storeName},</if>
  198. <if test="storeNameSn != null">#{storeNameSn},</if>
  199. <if test="cashRegisterNo != null">#{cashRegisterNo},</if>
  200. <if test="timeStampDetails != null">#{timeStampDetails},</if>
  201. <if test="staffID != null">#{staffID},</if>
  202. <if test="staffName != null">#{staffName},</if>
  203. <if test="payFlag != null">#{payFlag},</if>
  204. <if test="orderStatus != null">#{orderStatus},</if>
  205. <if test="orderSnWx != null">#{orderSnWx},</if>
  206. <if test="orderSnAli != null">#{orderSnAli},</if>
  207. <if test="hsCode != null">#{hsCode},</if>
  208. <if test="hsCodeName != null">#{hsCodeName},</if>
  209. <if test="ematouCode != null">#{ematouCode},</if>
  210. <if test="plu != null">#{plu},</if>
  211. <if test="mychemID != null">#{mychemID},</if>
  212. <if test="productNameEN != null">#{productNameEN},</if>
  213. <if test="productNameCN != null">#{productNameCN},</if>
  214. <if test="barcode != null">#{barcode},</if>
  215. <if test="packSize != null">#{packSize},</if>
  216. <if test="productSpecification != null">#{productSpecification},</if>
  217. <if test="brand != null">#{brand},</if>
  218. <if test="edlp != null">#{edlp},</if>
  219. <if test="currentPrice != null">#{currentPrice},</if>
  220. <if test="costPrice != null">#{costPrice},</if>
  221. <if test="taxRate != null">#{taxRate},</if>
  222. <if test="productCategory != null">#{productCategory},</if>
  223. <if test="supplierName != null">#{supplierName},</if>
  224. <if test="transactionType != null">#{transactionType},</if>
  225. <if test="saleReturnType != null">#{saleReturnType},</if>
  226. <if test="salesDetStatus != null">#{salesDetStatus},</if>
  227. <if test="salesDetMsg != null">#{salesDetMsg},</if>
  228. sysdate()
  229. </trim>
  230. </insert>
  231. <!-- 根据key,查询value -->
  232. <select id="querySalesByKey" parameterType="string" resultType="string">
  233. select value from sys_config where `key` = #{key}
  234. </select>
  235. <!-- 查询商户名称和第三方商户信息-->
  236. <select id="queryMerch" parameterType="java.lang.String" resultType="com.kmall.schedule.entity.NewSystemFormatEntiy">
  237. SELECT
  238. mall.merch_name as merchSnName,
  239. biz.third_party_merch_code as thirdMerchSn,
  240. biz.third_party_merch_name as thirdMerchSnName
  241. FROM
  242. mall_merch mall
  243. LEFT JOIN third_merchant_biz biz ON mall.merch_sn = biz.merch_sn
  244. WHERE
  245. mall.merch_sn = #{merchSn}
  246. </select>
  247. <!--数据重推-->
  248. <select id="querySalesAgain" parameterType="java.util.Map" resultType="com.kmall.schedule.entity.NewSystemFormatEntiy">
  249. SELECT
  250. merch_sn,
  251. merch_sn_name,
  252. third_merch_sn,
  253. third_merch_sn_name,
  254. receipt_no,
  255. store_name,
  256. store_name_sn,
  257. ash_register_no,
  258. time_stamp,
  259. staff_id,
  260. staff_name,
  261. pay_flag,
  262. order_status,
  263. order_sn_wx,
  264. order_sn_ali,
  265. hs_code,
  266. hs_code_name,
  267. ematou_code,
  268. plu,
  269. mychem_id,
  270. product_name_en,
  271. product_name_cn,
  272. barcode,
  273. pack_size,
  274. product_spec,
  275. brand,
  276. edlp,
  277. current_price,
  278. cost_price,
  279. tax_rate,
  280. product_category,
  281. supplier_name,
  282. transaction_type,
  283. sale_return_type,
  284. remark
  285. FROM
  286. mall_sales_detail_data_log
  287. WHERE
  288. <if test="startTime != null and startTime != ''">
  289. det_date &gt; STR_TO_DATE(#{startTime}, '%Y-%m-%d %H:%i:%s')
  290. </if>
  291. <if test="endTime != null and endTime != ''">
  292. AND time_stamp &lt;= STR_TO_DATE(#{endTime}, '%Y-%m-%d %H:%i:%s')
  293. </if>
  294. AND det_status = 2
  295. </select>
  296. </mapper>