MaterialMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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.gree.mall.miniapp.commonmapper.MaterialMapper">
  4. <select id="buyList" resultType="com.gree.mall.miniapp.bean.material.SalesOrderBean">
  5. SELECT
  6. a.*
  7. FROM
  8. websit_sales a
  9. <where>
  10. a.company_wechat_id = #{companyWechatId}
  11. AND worker_id = #{userId}
  12. <if test="flag!=null and flag!=''">
  13. AND a.flag = #{flag}
  14. </if>
  15. <if test="flag==null or flag==''">
  16. AND a.flag IN ('SAVE', 'SUBMIT', 'PAY_NOT_TAKE', 'PAY_TAKE')
  17. </if>
  18. </where>
  19. ORDER BY a.create_time DESC
  20. </select>
  21. <select id="existStockCategory" resultType="com.gree.mall.miniapp.bean.material.WebsitSalesCategoryVO">
  22. SELECT
  23. c.category_id,
  24. c.category_name
  25. FROM
  26. websit_stock a
  27. LEFT JOIN websit_goods b ON a.goods_id = b.goods_id
  28. LEFT JOIN websit_goods_category c ON b.goods_category_id = c.category_id
  29. WHERE
  30. a.company_wechat_id = #{companyWechatId}
  31. AND a.websit_id = #{websitId}
  32. AND a.goods_type = 'M'
  33. AND a.qty > 0
  34. GROUP BY b.goods_category_id
  35. </select>
  36. <select id="existStockGoods" resultType="com.gree.mall.miniapp.bean.material.WebsitSalesGoodsVO">
  37. SELECT
  38. a.goods_id,
  39. b.goods_name,
  40. <if test="goodsType=='M'.toString()">
  41. c.price,
  42. </if>
  43. <if test="goodsType=='P'.toString()">
  44. b.market_price AS price,
  45. </if>
  46. b.goods_code,
  47. b.goods_spell,
  48. b.goods_specification,
  49. b.goods_stock_unit,
  50. b.goods_sales_unit,
  51. b.brand_rela_name,
  52. b.product_rela_name,
  53. b.convert_bit_scale,
  54. b.goods_sales_convert_qty,
  55. b.manage_worker_stock,
  56. a.qty
  57. FROM
  58. websit_stock a
  59. JOIN websit_goods b ON a.goods_id = b.goods_id
  60. <if test="goodsType=='M'.toString()">
  61. LEFT JOIN websit_goods_price c ON a.websit_id = c.websit_id AND a.goods_id = c.goods_id
  62. </if>
  63. WHERE
  64. a.company_wechat_id = #{companyWechatId}
  65. <if test="goodsType=='M'.toString() and categoryId!=null and categoryId!=''">
  66. AND b.goods_category_id = #{categoryId}
  67. </if>
  68. <if test="goodsName!=null and goodsName!=''">
  69. AND b.goods_name LIKE CONCAT('%',#{goodsName},'%')
  70. </if>
  71. AND a.websit_id = #{websitId}
  72. AND a.goods_type = #{goodsType}
  73. AND a.qty > 0
  74. GROUP BY a.goods_id
  75. LIMIT 100
  76. </select>
  77. <select id="notStockGoods" resultType="com.gree.mall.miniapp.bean.material.WebsitSalesGoodsVO">
  78. SELECT
  79. b.goods_id,
  80. b.goods_name,
  81. b.market_price AS price,
  82. b.goods_code,
  83. b.goods_spell,
  84. b.goods_specification,
  85. b.goods_stock_unit,
  86. b.goods_sales_unit,
  87. b.brand_rela_name,
  88. b.product_rela_name,
  89. b.convert_bit_scale,
  90. b.goods_sales_convert_qty,
  91. b.manage_worker_stock,
  92. b.part_type,
  93. 0 AS qty
  94. FROM
  95. websit_goods b
  96. WHERE
  97. b.company_wechat_id = #{companyWechatId}
  98. <if test="goodsName!=null and goodsName!=''">
  99. AND b.goods_name LIKE CONCAT('%',#{goodsName},'%')
  100. </if>
  101. AND b.goods_type = #{goodsType}
  102. AND b.status = 'ON'
  103. AND b.norm_type = 'M'
  104. </select>
  105. <select id="normRecordList" resultType="com.gree.mall.miniapp.bean.material.NormRecordVO">
  106. SELECT
  107. a.*
  108. FROM
  109. websit_norm_record a
  110. WHERE
  111. a.company_wechat_id = #{companyWechatId}
  112. AND a.worker_id = #{userId}
  113. <if test="orderId!=null and orderId!=''">
  114. AND a.order_id LIKE CONCAT ('%', #{orderId}, '%')
  115. </if>
  116. <if test="goodsType!=null and goodsType!=''">
  117. AND a.goods_type = #{goodsType}
  118. </if>
  119. <if test="startTime!=null and startTime!=''">
  120. AND a.use_time BETWEEN #{startTime} AND #{endTime}
  121. </if>
  122. ORDER BY a.use_time DESC
  123. </select>
  124. <select id="partsRefundList" resultType="com.gree.mall.miniapp.bean.material.PartsRefundVO">
  125. SELECT
  126. a.*
  127. FROM
  128. websit_parts_ret a
  129. WHERE
  130. a.company_wechat_id = #{companyWechatId}
  131. AND a.worker_id = #{userId}
  132. <if test="type!=null and type!=''">
  133. AND a.type = #{type}
  134. </if>
  135. <if test="status!=null and status!=''">
  136. AND a.flag = #{status}
  137. </if>
  138. </select>
  139. <select id="queryShoppingCartList" resultType="com.gree.mall.miniapp.bean.material.WebsitShoppingCartList">
  140. SELECT
  141. a.*
  142. FROM
  143. websit_shopping_cart a
  144. WHERE
  145. a.worker_id = #{workerId}
  146. AND a.websit_id = #{websitId}
  147. AND a.goods_type = #{goodsType}
  148. </select>
  149. <select id="queryWorkerStockQty"
  150. resultType="com.gree.mall.miniapp.bean.material.stock.WorkerNormStockBean">
  151. SELECT
  152. a.norm_id,
  153. a.worker_goods_id,
  154. a.qty,
  155. b.goods_name,
  156. b.is_small,
  157. b.sales_unit,
  158. c.qty AS stock_qty
  159. FROM
  160. websit_norm_rela a
  161. JOIN
  162. worker_goods b
  163. ON a.company_wechat_id = b.company_wechat_id AND a.worker_goods_id = b.goods_id
  164. LEFT JOIN
  165. worker_stock c
  166. ON c.worker_id = #{workerId} AND a.company_wechat_id = c.company_wechat_id AND a.worker_goods_id = c.goods_id
  167. WHERE
  168. a.norm_id = #{goodsId}
  169. </select>
  170. <select id="appList" resultType="com.gree.mall.miniapp.bean.material.parts.NewRefundManageBean">
  171. SELECT
  172. a.company_wechat_id,
  173. a.company_wechat_name,
  174. a.apply_no,
  175. a.sales_id,
  176. a.apply_category,
  177. CASE a.apply_category WHEN 'HOME' THEN '家用空调'
  178. WHEN 'TRADE' THEN '商用空调'
  179. WHEN 'ELEC' THEN '生活电器(小家电)'
  180. ELSE '' END AS applyCategoryName,
  181. a.apply_type,
  182. CASE a.apply_type WHEN 'NEW' THEN '新件返还'
  183. WHEN 'LOST' THEN '破损返还'
  184. WHEN 'BUG' THEN '故障返还'
  185. ELSE '' END AS applyTypeName,
  186. a.refund_mode,
  187. CASE a.refund_mode WHEN 'EXPRESS' THEN '快递'
  188. WHEN 'SELF' THEN '网点自还'
  189. ELSE '' END AS refundModeName,
  190. a.express_no,
  191. a.receive_address,
  192. a.receive_websit_id,
  193. a.receive_websit_name,
  194. a.receive_parts_websit_id,
  195. a.websit_Address,
  196. a.identity,
  197. a.worker_id,
  198. a.worker_name,
  199. a.refund_amount,
  200. a.refund_amount_mode,
  201. IF(refund_amount_mode = 'CASH', '现金', '微信') AS refundAmountModeName,
  202. a.remark,
  203. a.examine_remark,
  204. a.flag,
  205. CASE a.flag WHEN 'SAVE' THEN '保存'
  206. WHEN 'SUBMIT' THEN '待审批'
  207. WHEN 'AGREE' THEN '待返还'
  208. WHEN 'REJECT' THEN '驳回'
  209. WHEN 'REFUNDED' THEN '已返还'
  210. ELSE '' END AS flagName,
  211. a.create_by,
  212. a.create_time,
  213. a.update_by,
  214. a.update_time,
  215. a.submit_by,
  216. a.submit_time,
  217. a.examine_by,
  218. a.examine_time,
  219. a.refunded_by,
  220. a.refunded_time
  221. FROM
  222. websit_parts_new_refund_manage a
  223. LEFT JOIN websit_parts_new_refund_manage_item b ON a.apply_no = b.apply_no
  224. <where>
  225. <if test="applyNo != null and applyNo != ''">
  226. AND a.apply_no = #{applyNo}
  227. </if>
  228. <if test="flag != null and flag != ''">
  229. AND a.flag = #{flag}
  230. </if>
  231. <if test="identity != null and identity != ''">
  232. AND a.identity = #{identity}
  233. </if>
  234. <if test="partsNumber != null and partsNumber != ''">
  235. AND b.parts_number = #{partsNumber}
  236. </if>
  237. </where>
  238. GROUP BY a.apply_no, a.create_time
  239. ORDER BY a.create_time DESC
  240. </select>
  241. <select id="querySalesPushFlagItem" resultType="com.gree.mall.miniapp.plus.entity.WebsitPartsSalesItem">
  242. SELECT
  243. id,
  244. identity,
  245. websit_id,
  246. parts_websit_id,
  247. parts_id,
  248. parts_number,
  249. parts_name,
  250. material_group_name,
  251. goods_stock_unit,
  252. sales_id,
  253. sales_price,
  254. market_price,
  255. second_price,
  256. qty,
  257. examine_qty,
  258. new_refund_qty,
  259. old_refund_qty,
  260. total_amount,
  261. refund_amount_mode,
  262. push_flag,
  263. create_by,
  264. create_time,
  265. update_by,
  266. update_time,
  267. examine_time
  268. FROM
  269. websit_parts_sales_item
  270. WHERE
  271. identity = #{identity}
  272. AND websit_id = #{websitId}
  273. AND parts_websit_id = #{partsWebsitId}
  274. <if test="pushFlag != null and pushFlag != ''">
  275. AND push_flag = #{pushFlag}
  276. </if>
  277. <if test="salesId != null and salesId != ''">
  278. AND sales_id = #{salesId}
  279. </if>
  280. AND parts_number IN
  281. <foreach item="item" index="index" collection="records" open="(" separator=","
  282. close=")">
  283. #{item.partsNumber}
  284. </foreach>
  285. ORDER BY
  286. examine_time
  287. FOR UPDATE
  288. </select>
  289. <select id="appSalesList" resultType="com.gree.mall.miniapp.bean.material.parts.PartsSalesOrderBean">
  290. SELECT
  291. a.*,
  292. CASE a.order_source WHEN 'SELF' THEN '自建订单'
  293. WHEN 'ONLINE' THEN '在线订单'
  294. ELSE '' END AS buyTypeName,
  295. CASE a.status WHEN 'SAVE' THEN '保存未提交'
  296. WHEN 'SUBMIT' THEN '已提交'
  297. <!-- WHEN '2' THEN '已支付' -->
  298. WHEN 'PAYED' THEN
  299. <!-- WHEN '3' THEN '已提货' -->
  300. (case when a.worker_confirm_date is not null and a.websit_confirm_date is not null then '已提货'
  301. when a.worker_confirm_date is not null then '师傅已提货'
  302. when a.websit_confirm_date is not null then '网点已提货' else '已支付' end)
  303. WHEN 'END' THEN '已完成'
  304. WHEN 'CANCEL' THEN '已取消'
  305. ELSE '' END AS stateName,
  306. CASE a.pushFlag WHEN 'SALES' THEN '销售'
  307. WHEN 'TRANS' THEN '转销售'
  308. WHEN 'END' THEN '完结'
  309. ELSE '' END AS pushFlagName
  310. FROM
  311. websit_parts_sales a, websit_parts_sales_item b
  312. WHERE
  313. a.id = b.sales_id
  314. AND a.del = 0
  315. AND a.identity = #{identity}
  316. <if test="salesId != null and salesId != ''">
  317. AND a.id = #{salesId}
  318. </if>
  319. <if test="status != null and status != ''">
  320. <!-- and 1 = 0 -->
  321. <if test="status == 'SAVE'.toString() or status == 'SUBMIT'.toString() or status == 'END'.toString() or status == 'CANCEL'.toString()">
  322. AND a.status = #{state}
  323. </if>
  324. <if test="state == 'PAYED'.toString()">
  325. AND a.status = 'PAYED' AND (a.worker_confirm_date is null and a.websit_confirm_date is null)
  326. </if>
  327. </if>
  328. <if test="pushFlag != null and pushFlag != ''">
  329. AND a.pushFlag = #{pushFlag}
  330. AND b.qty > 0
  331. </if>
  332. <if test="partsNumber != null and partsNumber != ''">
  333. AND b.parts_number = #{partsNumber}
  334. </if>
  335. GROUP BY
  336. a.identity, a.id, a.create_time
  337. ORDER BY
  338. a.create_time DESC
  339. </select>
  340. <select id="selectItemBySalesOrderId"
  341. resultType="com.gree.mall.miniapp.bean.material.parts.PartsSalesOrderItemBean">
  342. select
  343. a.id ,
  344. a.identity ,
  345. a.websit_id,
  346. a.parts_websit_id,
  347. a.parts_id,
  348. a.parts_number,
  349. a.parts_name,
  350. a.material_group_name,
  351. a.goods_stock_unit,
  352. a.sales_id,
  353. a.sales_price,
  354. a.market_price,
  355. a.second_price,
  356. IF(d.status = 'END', a.examine_qty, a.qty) AS qty,
  357. a.examine_qty,
  358. a.new_refund_qty,
  359. a.old_refund_qty ,
  360. a.total_amount,
  361. a.push_flag ,
  362. a.create_by ,
  363. a.create_time,
  364. a.update_by,
  365. a.update_time,
  366. IFNULL(c.qty, 0) stockQty
  367. FROM websit_parts_sales_item a JOIN websit_goods b ON a.parts_id = b.goods_id
  368. LEFT JOIN websit_stock c ON a.websit_id = c.websit_id AND a.parts_number = c.goods_id AND a.parts_websit_id = c.parts_websit_id
  369. JOIN websit_parts_sales d ON a.sales_id = d.id
  370. WHERE a.sales_id = #{id}
  371. </select>
  372. <select id="queryOldRefundRecordById"
  373. resultType="com.gree.mall.miniapp.bean.material.parts.OldRefundManageRecordBean">
  374. SELECT
  375. a.*
  376. FROM
  377. websit_parts_old_refund_manage_record a
  378. WHERE
  379. sales_id = #{id}
  380. </select>
  381. <select id="websitGroupList" resultType="com.gree.mall.miniapp.plus.entity.WebsitGoods">
  382. SELECT
  383. material_group_name AS `value`
  384. FROM
  385. websit_stock
  386. WHERE
  387. company_wechat_id = #{companyWechatId}
  388. AND websit_id = #{websitId}
  389. AND parts_websit_id = #{partsWebsiteNumber}
  390. AND qty > 0
  391. GROUP BY
  392. material_group_name
  393. </select>
  394. <select id="existWebsitStockList"
  395. resultType="com.gree.mall.miniapp.bean.material.parts.WebsitPartsStockBean">
  396. SELECT
  397. a.id,
  398. a.websit_id,
  399. a.websit_name,
  400. a.parts_websit_id,
  401. a.goods_id,
  402. a.goods_name,
  403. b.material_group_name,
  404. b.part_type,
  405. b.market_price,
  406. b.goods_stock_unit,
  407. a.qty,
  408. a.old_qty
  409. FROM
  410. websit_stock a LEFT JOIN websit_goods b ON a.goods_id = b.goods_code
  411. WHERE
  412. a.company_wechat_id = #{companyWechatId}
  413. AND a.websit_id = #{websitId}
  414. AND a.parts_websit_id = #{partsWebsitId}
  415. <if test="partsNumber != null and partsNumber != ''">
  416. AND a.goods_id = #{partsNumber}
  417. </if>
  418. <if test="partsName != null and partsName != ''">
  419. AND a.goods_name LIKE CONCAT('%', #{partsName}, '%')
  420. </if>
  421. <if test="materialGroupName != null and materialGroupName != ''">
  422. AND a.goods_stock_unit = #{materialGroupName}
  423. </if>
  424. AND a.goods_type = 'P'
  425. AND a.qty > 0
  426. </select>
  427. </mapper>