MaterialMapper.xml 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  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. <resultMap id="newRefundManageAppList" type="com.gree.mall.miniapp.bean.material.parts.NewRefundManageBean">
  5. <id column="applyNo" jdbcType="VARCHAR" property="applyNo"/>
  6. <result column="sales_Id" jdbcType="VARCHAR" property="salesId"/>
  7. <result column="apply_category" jdbcType="VARCHAR" property="applyCategory"/>
  8. <result column="apply_category_name" jdbcType="VARCHAR" property="applyCategoryName"/>
  9. <result column="apply_type" jdbcType="VARCHAR" property="applyType"/>
  10. <result column="apply_type_name" jdbcType="VARCHAR" property="applyTypeName"/>
  11. <result column="refund_mode" jdbcType="VARCHAR" property="refundMode"/>
  12. <result column="refund_mode_name" jdbcType="VARCHAR" property="refundModeName"/>
  13. <result column="express_no" jdbcType="VARCHAR" property="expressNo"/>
  14. <result column="receive_address" jdbcType="VARCHAR" property="receiveAddress"/>
  15. <result column="receive_websit_id" jdbcType="VARCHAR" property="receiveWebsitId"/>
  16. <result column="receive_websit_Name" jdbcType="VARCHAR" property="receiveWebsitName"/>
  17. <result column="receive_parts_websit_id" jdbcType="VARCHAR" property="receivePartsWebsitId"/>
  18. <result column="websit_Address" jdbcType="VARCHAR" property="websitAddress"/>
  19. <result column="identity" jdbcType="VARCHAR" property="identity"/>
  20. <result column="worker_id" jdbcType="VARCHAR" property="workerId"/>
  21. <result column="worker_name" jdbcType="VARCHAR" property="workerName"/>
  22. <result column="refund_amount" jdbcType="DECIMAL" property="refundAmount"/>
  23. <result column="refund_amount_mode" jdbcType="VARCHAR" property="refundAmountMode"/>
  24. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  25. <result column="examine_remark" jdbcType="VARCHAR" property="examineRemark"/>
  26. <result column="flag" jdbcType="VARCHAR" property="flag"/>
  27. <result column="flag_name" jdbcType="VARCHAR" property="flagName"/>
  28. <result column="create_by" jdbcType="VARCHAR" property="createBy"/>
  29. <result column="create_time" jdbcType="DATE" property="createTime"/>
  30. <result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
  31. <result column="update_time" jdbcType="DATE" property="updateTime"/>
  32. <result column="submit_by" jdbcType="VARCHAR" property="submitBy"/>
  33. <result column="submit_time" jdbcType="DATE" property="submitTime"/>
  34. <result column="examine_by" jdbcType="VARCHAR" property="examineBy"/>
  35. <result column="examine_time" jdbcType="DATE" property="examineTime"/>
  36. <result column="refunded_by" jdbcType="VARCHAR" property="refundedBy"/>
  37. <result column="refunded_time" jdbcType="DATE" property="refundedTime"/>
  38. <collection property="newRefundManageItemBeanList" ofType="com.gree.mall.miniapp.bean.material.parts.NewRefundManageItemBean"
  39. column="apply_no" javaType="java.util.List"
  40. select="selectNewRefundManageItemByApplyNo">
  41. </collection>
  42. <collection property="partsNewRefundManageRecordList" ofType="com.gree.mall.miniapp.bean.material.parts.NewRefundManageRecordBean"
  43. column="apply_no" javaType="java.util.List"
  44. select="selectNewRefundManageRecordByApplyNo">
  45. </collection>
  46. </resultMap>
  47. <resultMap id="newRefundManageItemResultMap" type="com.gree.mall.miniapp.bean.material.parts.NewRefundManageItemBean">
  48. <id column="id" jdbcType="VARCHAR" property="id"/>
  49. <result column="apply_no" jdbcType="VARCHAR" property="applyNo"/>
  50. <result column="sales_Id" jdbcType="VARCHAR" property="salesId"/>
  51. <result column="parts_number" jdbcType="VARCHAR" property="partsNumber"/>
  52. <result column="parts_name" jdbcType="VARCHAR" property="partsName"/>
  53. <result column="material_group_name" jdbcType="VARCHAR" property="materialGroupName"/>
  54. <result column="goods_stock_unit" jdbcType="VARCHAR" property="goodsStockUnit"/>
  55. <result column="qty" jdbcType="DECIMAL" property="qty"/>
  56. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  57. <result column="image" jdbcType="VARCHAR" property="image"/>
  58. <result column="custom_no" jdbcType="VARCHAR" property="customNo"/>
  59. <result column="create_time" jdbcType="DATE" property="createTime"/>
  60. </resultMap>
  61. <resultMap id="newRefundManageRecordResultMap" type="com.gree.mall.miniapp.bean.material.parts.NewRefundManageRecordBean">
  62. <id column="id" jdbcType="VARCHAR" property="id"/>
  63. <result column="item_id" jdbcType="VARCHAR" property="itemId"/>
  64. <result column="apply_no" jdbcType="VARCHAR" property="applyNo"/>
  65. <result column="sales_Id" jdbcType="VARCHAR" property="salesId"/>
  66. <result column="parts_number" jdbcType="VARCHAR" property="partsNumber"/>
  67. <result column="parts_name" jdbcType="VARCHAR" property="partsName"/>
  68. <result column="sales_price" jdbcType="DECIMAL" property="salesPrice"/>
  69. <result column="market_price" jdbcType="DECIMAL" property="marketPrice"/>
  70. <result column="second_price" jdbcType="DECIMAL" property="secondPrice"/>
  71. <result column="qty" jdbcType="DECIMAL" property="qty"/>
  72. <result column="total_amount" jdbcType="DECIMAL" property="totalAmount"/>
  73. <result column="refund_amount" jdbcType="DECIMAL" property="refundAmount"/>
  74. <result column="refund_time" jdbcType="DATE" property="refundTime"/>
  75. <result column="refund_state" jdbcType="VARCHAR" property="refundState"/>
  76. <result column="refund_state_name" jdbcType="VARCHAR" property="refundStateName"/>
  77. <result column="refund_mch_no" jdbcType="VARCHAR" property="refundMchNo"/>
  78. <result column="refund_account_no" jdbcType="VARCHAR" property="refundAccountNo"/>
  79. <result column="refund_serialnumber" jdbcType="VARCHAR" property="refundSerialnumber"/>
  80. <result column="create_time" jdbcType="DATE" property="createTime"/>
  81. </resultMap>
  82. <select id="buyList" resultType="com.gree.mall.miniapp.bean.material.SalesOrderBean">
  83. SELECT
  84. a.*
  85. FROM
  86. websit_sales a
  87. <where>
  88. a.company_wechat_id = #{companyWechatId}
  89. AND worker_id = #{userId}
  90. <if test="flag!=null and flag!=''">
  91. AND a.flag = #{flag}
  92. </if>
  93. <if test="flag==null or flag==''">
  94. AND a.flag IN ('SAVE', 'SUBMIT', 'PAY_NOT_TAKE', 'PAY_TAKE')
  95. </if>
  96. </where>
  97. ORDER BY a.create_time DESC
  98. </select>
  99. <select id="existStockCategory" resultType="com.gree.mall.miniapp.bean.material.WebsitSalesCategoryVO">
  100. SELECT
  101. c.category_id,
  102. c.category_name
  103. FROM
  104. websit_stock a
  105. LEFT JOIN websit_goods b ON a.goods_id = b.goods_id
  106. LEFT JOIN websit_goods_category c ON b.goods_category_id = c.category_id
  107. WHERE
  108. a.company_wechat_id = #{companyWechatId}
  109. AND a.websit_id = #{websitId}
  110. AND a.goods_type = 'M'
  111. AND a.qty > 0
  112. GROUP BY b.goods_category_id
  113. </select>
  114. <select id="existStockGoods" resultType="com.gree.mall.miniapp.bean.material.WebsitSalesGoodsVO">
  115. SELECT
  116. a.goods_id,
  117. b.goods_name,
  118. <if test="goodsType=='M'.toString()">
  119. c.price,
  120. </if>
  121. <if test="goodsType=='P'.toString()">
  122. b.market_price AS price,
  123. </if>
  124. b.goods_code,
  125. b.goods_spell,
  126. b.goods_specification,
  127. b.goods_stock_unit,
  128. b.goods_sales_unit,
  129. b.brand_rela_name,
  130. b.product_rela_name,
  131. b.convert_bit_scale,
  132. b.goods_sales_convert_qty,
  133. b.manage_worker_stock,
  134. a.qty
  135. FROM
  136. websit_stock a
  137. JOIN websit_goods b ON a.goods_id = b.goods_id
  138. <if test="goodsType=='M'.toString()">
  139. LEFT JOIN websit_goods_price c ON a.websit_id = c.websit_id AND a.goods_id = c.goods_id
  140. </if>
  141. WHERE
  142. a.company_wechat_id = #{companyWechatId}
  143. <if test="goodsType=='M'.toString() and categoryId!=null and categoryId!=''">
  144. AND b.goods_category_id = #{categoryId}
  145. </if>
  146. <if test="goodsName!=null and goodsName!=''">
  147. AND b.goods_name LIKE CONCAT('%',#{goodsName},'%')
  148. </if>
  149. AND a.websit_id = #{websitId}
  150. AND a.goods_type = #{goodsType}
  151. AND a.qty > 0
  152. GROUP BY a.goods_id
  153. LIMIT 100
  154. </select>
  155. <select id="notStockGoods" resultType="com.gree.mall.miniapp.bean.material.WebsitSalesGoodsVO">
  156. SELECT
  157. b.goods_id,
  158. b.goods_name,
  159. b.market_price AS price,
  160. b.goods_code,
  161. b.goods_spell,
  162. b.goods_specification,
  163. b.goods_stock_unit,
  164. b.goods_sales_unit,
  165. b.brand_rela_name,
  166. b.product_rela_name,
  167. b.convert_bit_scale,
  168. b.goods_sales_convert_qty,
  169. b.manage_worker_stock,
  170. b.part_type,
  171. 0 AS qty
  172. FROM
  173. websit_goods b
  174. WHERE
  175. b.company_wechat_id = #{companyWechatId}
  176. <if test="goodsName!=null and goodsName!=''">
  177. AND b.goods_name LIKE CONCAT('%',#{goodsName},'%')
  178. </if>
  179. AND b.goods_type = #{goodsType}
  180. AND b.status = 'ON'
  181. AND b.norm_type = 'M'
  182. </select>
  183. <select id="normRecordList" resultType="com.gree.mall.miniapp.bean.material.NormRecordVO">
  184. SELECT
  185. a.*
  186. FROM
  187. websit_norm_record a
  188. WHERE
  189. a.company_wechat_id = #{companyWechatId}
  190. AND a.worker_id = #{userId}
  191. <if test="orderId!=null and orderId!=''">
  192. AND a.order_id LIKE CONCAT ('%', #{orderId}, '%')
  193. </if>
  194. <if test="goodsType!=null and goodsType!=''">
  195. AND a.goods_type = #{goodsType}
  196. </if>
  197. <if test="startTime!=null and startTime!=''">
  198. AND a.use_time BETWEEN #{startTime} AND #{endTime}
  199. </if>
  200. ORDER BY a.use_time DESC
  201. </select>
  202. <select id="partsRefundList" resultType="com.gree.mall.miniapp.bean.material.PartsRefundVO">
  203. SELECT
  204. a.*
  205. FROM
  206. websit_parts_ret a
  207. WHERE
  208. a.company_wechat_id = #{companyWechatId}
  209. AND a.worker_id = #{userId}
  210. <if test="type!=null and type!=''">
  211. AND a.type = #{type}
  212. </if>
  213. <if test="status!=null and status!=''">
  214. AND a.flag = #{status}
  215. </if>
  216. </select>
  217. <select id="queryShoppingCartList" resultType="com.gree.mall.miniapp.bean.material.WebsitShoppingCartList">
  218. SELECT
  219. a.*
  220. FROM
  221. websit_shopping_cart a
  222. WHERE
  223. a.worker_id = #{workerId}
  224. AND a.websit_id = #{websitId}
  225. AND a.goods_type = #{goodsType}
  226. </select>
  227. <select id="queryWorkerStockQty"
  228. resultType="com.gree.mall.miniapp.bean.material.stock.WorkerNormStockBean">
  229. SELECT
  230. a.norm_id,
  231. a.worker_goods_id,
  232. a.qty,
  233. b.goods_name,
  234. b.is_small,
  235. b.sales_unit,
  236. c.qty AS stock_qty
  237. FROM
  238. websit_norm_rela a
  239. JOIN
  240. worker_goods b
  241. ON a.company_wechat_id = b.company_wechat_id AND a.worker_goods_id = b.goods_id
  242. LEFT JOIN
  243. worker_stock c
  244. ON c.worker_id = #{workerId} AND a.company_wechat_id = c.company_wechat_id AND a.worker_goods_id = c.goods_id
  245. WHERE
  246. a.norm_id = #{goodsId}
  247. </select>
  248. <select id="appList" resultMap="newRefundManageAppList">
  249. SELECT
  250. a.company_wechat_id,
  251. a.company_wechat_name,
  252. a.apply_no,
  253. a.sales_id,
  254. a.apply_category,
  255. CASE a.apply_category WHEN 'HOME' THEN '家用空调'
  256. WHEN 'TRADE' THEN '商用空调'
  257. WHEN 'ELEC' THEN '生活电器(小家电)'
  258. ELSE '' END AS applyCategoryName,
  259. a.apply_type,
  260. CASE a.apply_type WHEN 'NEW' THEN '新件返还'
  261. WHEN 'LOST' THEN '破损返还'
  262. WHEN 'BUG' THEN '故障返还'
  263. ELSE '' END AS applyTypeName,
  264. a.refund_mode,
  265. CASE a.refund_mode WHEN 'EXPRESS' THEN '快递'
  266. WHEN 'SELF' THEN '网点自还'
  267. ELSE '' END AS refundModeName,
  268. a.express_no,
  269. a.receive_address,
  270. a.receive_websit_id,
  271. a.receive_websit_name,
  272. a.receive_parts_websit_id,
  273. a.websit_Address,
  274. a.identity,
  275. a.worker_id,
  276. a.worker_name,
  277. a.refund_amount,
  278. a.refund_amount_mode,
  279. IF(refund_amount_mode = 'CASH', '现金', '微信') AS refundAmountModeName,
  280. a.remark,
  281. a.examine_remark,
  282. a.flag,
  283. CASE a.flag WHEN 'SAVE' THEN '保存'
  284. WHEN 'SUBMIT' THEN '待审批'
  285. WHEN 'AGREE' THEN '待返还'
  286. WHEN 'REJECT' THEN '驳回'
  287. WHEN 'REFUNDED' THEN '已返还'
  288. ELSE '' END AS flagName,
  289. a.create_by,
  290. a.create_time,
  291. a.update_by,
  292. a.update_time,
  293. a.submit_by,
  294. a.submit_time,
  295. a.examine_by,
  296. a.examine_time,
  297. a.refunded_by,
  298. a.refunded_time
  299. FROM
  300. websit_parts_new_refund_manage a
  301. LEFT JOIN websit_parts_new_refund_manage_item b ON a.apply_no = b.apply_no
  302. <where>
  303. a.company_wechat_id = #{companyWechatId}
  304. <if test="applyNo != null and applyNo != ''">
  305. AND a.apply_no = #{applyNo}
  306. </if>
  307. <if test="flag != null and flag != ''">
  308. AND a.flag = #{flag}
  309. </if>
  310. <if test="identity != null and identity != ''">
  311. AND a.identity = #{identity}
  312. </if>
  313. <if test="partsNumber != null and partsNumber != ''">
  314. AND b.parts_number = #{partsNumber}
  315. </if>
  316. </where>
  317. GROUP BY a.apply_no, a.create_time
  318. ORDER BY a.create_time DESC
  319. </select>
  320. <select id="querySalesPushFlagItem" resultType="com.gree.mall.miniapp.plus.entity.WebsitPartsSalesItem">
  321. SELECT
  322. id,
  323. identity,
  324. websit_id,
  325. parts_websit_id,
  326. parts_id,
  327. parts_number,
  328. parts_name,
  329. material_group_name,
  330. goods_stock_unit,
  331. sales_id,
  332. sales_price,
  333. market_price,
  334. second_price,
  335. qty,
  336. examine_qty,
  337. new_refund_qty,
  338. old_refund_qty,
  339. total_amount,
  340. refund_amount_mode,
  341. push_flag,
  342. create_by,
  343. create_time,
  344. update_by,
  345. update_time,
  346. examine_time
  347. FROM
  348. websit_parts_sales_item
  349. WHERE
  350. identity = #{identity}
  351. AND websit_id = #{websitId}
  352. AND parts_websit_id = #{partsWebsitId}
  353. <if test="pushFlag != null and pushFlag != ''">
  354. AND push_flag = #{pushFlag}
  355. </if>
  356. <if test="salesId != null and salesId != ''">
  357. AND sales_id = #{salesId}
  358. </if>
  359. AND parts_number IN
  360. <foreach item="item" index="index" collection="records" open="(" separator=","
  361. close=")">
  362. #{item.partsNumber}
  363. </foreach>
  364. ORDER BY
  365. examine_time
  366. FOR UPDATE
  367. </select>
  368. <select id="appSalesList" resultType="com.gree.mall.miniapp.bean.material.parts.PartsSalesOrderBean">
  369. SELECT
  370. a.*,
  371. CASE a.order_source WHEN 'SELF' THEN '自建订单'
  372. WHEN 'ONLINE' THEN '在线订单'
  373. ELSE '' END AS buyTypeName,
  374. CASE a.status WHEN 'SAVE' THEN '保存未提交'
  375. WHEN 'SUBMIT' THEN '已提交'
  376. <!-- WHEN '2' THEN '已支付' -->
  377. WHEN 'PAYED' THEN
  378. <!-- WHEN '3' THEN '已提货' -->
  379. (case when a.worker_confirm_date is not null and a.websit_confirm_date is not null then '已提货'
  380. when a.worker_confirm_date is not null then '师傅已提货'
  381. when a.websit_confirm_date is not null then '网点已提货' else '已支付' end)
  382. WHEN 'END' THEN '已完成'
  383. WHEN 'CANCEL' THEN '已取消'
  384. ELSE '' END AS stateName,
  385. CASE a.pushFlag WHEN 'SALES' THEN '销售'
  386. WHEN 'TRANS' THEN '转销售'
  387. WHEN 'END' THEN '完结'
  388. ELSE '' END AS pushFlagName
  389. FROM
  390. websit_parts_sales a, websit_parts_sales_item b
  391. WHERE
  392. a.company_wechat_id = #{companyWechatId}
  393. AND a.id = b.sales_id
  394. AND a.del = 0
  395. AND a.identity = #{identity}
  396. <if test="salesId != null and salesId != ''">
  397. AND a.id = #{salesId}
  398. </if>
  399. <if test="status != null and status != ''">
  400. <!-- and 1 = 0 -->
  401. <if test="status == 'SAVE'.toString() or status == 'SUBMIT'.toString() or status == 'END'.toString() or status == 'CANCEL'.toString()">
  402. AND a.status = #{status}
  403. </if>
  404. <if test="status == 'PAYED'.toString()">
  405. AND a.status = 'PAYED' AND (a.worker_confirm_date is null and a.websit_confirm_date is null)
  406. </if>
  407. </if>
  408. <if test="pushFlag != null and pushFlag != ''">
  409. AND a.pushFlag = #{pushFlag}
  410. AND b.qty > 0
  411. </if>
  412. <if test="partsNumber != null and partsNumber != ''">
  413. AND b.parts_number = #{partsNumber}
  414. </if>
  415. GROUP BY
  416. a.identity, a.id, a.create_time
  417. ORDER BY
  418. a.create_time DESC
  419. </select>
  420. <select id="selectItemBySalesOrderId"
  421. resultType="com.gree.mall.miniapp.bean.material.parts.PartsSalesOrderItemBean">
  422. select
  423. a.id ,
  424. a.identity ,
  425. a.websit_id,
  426. a.parts_websit_id,
  427. a.parts_id,
  428. a.parts_number,
  429. a.parts_name,
  430. a.material_group_name,
  431. a.goods_stock_unit,
  432. a.sales_id,
  433. a.sales_price,
  434. a.market_price,
  435. a.second_price,
  436. IF(d.status = 'END', a.examine_qty, a.qty) AS qty,
  437. a.examine_qty,
  438. a.new_refund_qty,
  439. a.old_refund_qty ,
  440. a.total_amount,
  441. a.push_flag ,
  442. a.create_by ,
  443. a.create_time,
  444. a.update_by,
  445. a.update_time,
  446. IFNULL(c.qty, 0) stockQty
  447. FROM websit_parts_sales_item a JOIN websit_goods b ON a.parts_id = b.goods_id
  448. 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
  449. JOIN websit_parts_sales d ON a.sales_id = d.id
  450. WHERE a.sales_id = #{id}
  451. </select>
  452. <select id="queryOldRefundRecordById"
  453. resultType="com.gree.mall.miniapp.bean.material.parts.OldRefundManageRecordBean">
  454. SELECT
  455. a.*
  456. FROM
  457. websit_parts_old_refund_manage_record a
  458. WHERE
  459. sales_id = #{id}
  460. </select>
  461. <select id="websitGroupList" resultType="java.lang.String">
  462. SELECT
  463. material_group_name
  464. FROM
  465. websit_stock
  466. WHERE
  467. company_wechat_id = #{companyWechatId}
  468. AND websit_id = #{websitId}
  469. AND parts_websit_id = #{partsWebsitId}
  470. AND qty > 0
  471. GROUP BY
  472. material_group_name
  473. </select>
  474. <select id="existWebsitStockList"
  475. resultType="com.gree.mall.miniapp.bean.material.parts.WebsitPartsStockBean">
  476. SELECT
  477. a.id,
  478. a.websit_id,
  479. a.websit_name,
  480. a.parts_websit_id,
  481. a.goods_id,
  482. a.goods_name,
  483. b.material_group_name,
  484. b.part_type,
  485. b.market_price,
  486. b.goods_stock_unit,
  487. a.qty,
  488. a.old_qty
  489. FROM
  490. websit_stock a LEFT JOIN websit_goods b ON a.company_wechat_id = b.company_wechat_id AND a.goods_id = b.goods_code
  491. WHERE
  492. a.company_wechat_id = #{companyWechatId}
  493. AND a.websit_id = #{websitId}
  494. AND a.parts_websit_id = #{partsWebsitId}
  495. <if test="partsNumber != null and partsNumber != ''">
  496. AND a.goods_id = #{partsNumber}
  497. </if>
  498. <if test="partsName != null and partsName != ''">
  499. AND a.goods_name LIKE CONCAT('%', #{partsName}, '%')
  500. </if>
  501. <if test="materialGroupName != null and materialGroupName != ''">
  502. AND a.goods_stock_unit = #{materialGroupName}
  503. </if>
  504. AND a.goods_type = 'P'
  505. AND a.qty > 0
  506. </select>
  507. <select id="existWebsitList" resultType="com.gree.mall.miniapp.plus.entity.AdminWebsit">
  508. SELECT
  509. websit_id, websit_name AS name, parts_websit_id
  510. FROM
  511. worker_stock
  512. WHERE
  513. company_wechat_id = #{companyWechatId}
  514. AND identity = #{identity}
  515. AND goods_type = 'P'
  516. GROUP BY
  517. websit_id, parts_websit_id
  518. </select>
  519. <select id="existWebsitGroupList" resultType="java.lang.String">
  520. SELECT
  521. material_group_name
  522. FROM
  523. worker_stock
  524. WHERE
  525. company_wechat_id = #{companyWechatId}
  526. AND identity = #{identity}
  527. AND websit_id = #{websitId}
  528. AND parts_websit_id = #{partsWebsitId}
  529. AND goods_type = 'P'
  530. <choose>
  531. <when test="partsAttr != null and partsAttr == 'NEW'">
  532. AND qty > 0
  533. </when>
  534. <when test="partsAttr != null and partsAttr == 'OLD'">
  535. AND old_qty > 0
  536. </when>
  537. <when test="partsAttr != null and partsAttr == 'WAY'">
  538. AND way_qty > 0
  539. </when>
  540. <otherwise>
  541. AND id = 0
  542. </otherwise>
  543. </choose>
  544. GROUP BY
  545. material_group_name
  546. </select>
  547. <select id="existWorkerStockList"
  548. resultType="com.gree.mall.miniapp.bean.material.parts.PartsWorkerStockBean">
  549. SELECT
  550. a.*,
  551. b.market_price
  552. FROM
  553. worker_stock a LEFT JOIN websit_goods b ON a.company_wechat_id = b.company_wechat_id AND a.goods_id = b.goods_code
  554. WHERE
  555. a.company_wechat_id = #{companyWechatId}
  556. AND a.goods_type = 'P'
  557. AND a.identity = #{identity}
  558. AND a.websit_id = #{websitId}
  559. AND a.parts_websit_id = #{partsWebsitId}
  560. <if test="partsNumber != null and partsNumber != ''">
  561. AND a.goods_id = #{partsNumber}
  562. </if>
  563. <if test="partsName != null and partsName != ''">
  564. AND a.goods_name LIKE CONCAT('%',#{partsName},'%')
  565. </if>
  566. <if test="materialGroupName != null and materialGroupName != ''">
  567. AND a.material_group_name = #{materialGroupName}
  568. </if>
  569. <if test="productRelaId != null and productRelaId != ''">
  570. AND b.product_rela_id LIKE CONCAT('%',#{productRelaId},'%')
  571. </if>
  572. <choose>
  573. <when test="partsAttr != null and partsAttr == 'NEW'">
  574. AND a.qty > 0
  575. </when>
  576. <when test="partsAttr != null and partsAttr == 'OLD'">
  577. AND a.old_qty > 0
  578. </when>
  579. <when test="partsAttr != null and partsAttr == 'WAY'">
  580. AND a.way_qty > 0
  581. </when>
  582. <otherwise>
  583. AND a.id = 0
  584. </otherwise>
  585. </choose>
  586. </select>
  587. <select id="querySalesEndTimeByIdentity"
  588. resultType="com.gree.mall.miniapp.plus.entity.WebsitPartsSalesItem">
  589. SELECT
  590. b.parts_number,
  591. b.qty,
  592. a.end_time AS examineTime
  593. FROM
  594. websit_parts_sales a, websit_parts_sales_item b
  595. WHERE
  596. a.id = b.sales_id
  597. AND a.company_wechat_id = #{companyWechatId}
  598. AND a.pushFlag = 'SALES'
  599. AND a.identity = #{identity}
  600. AND a.websit_id = #{websitId}
  601. AND a.parts_websit_id = #{partsWebsitId}
  602. AND b.qty > 0
  603. GROUP BY b.parts_number
  604. </select>
  605. <select id="workerStockStatistics"
  606. resultType="com.gree.mall.miniapp.bean.material.parts.WorkerStockCensusBean">
  607. SELECT t.worker_id, t.identity,
  608. SUM(IFNULL(qty,0)) as newQty,
  609. SUM(IFNULL(old_qty,0)) as oldQty
  610. FROM worker_stock t
  611. WHERE identity = #{identity}
  612. AND goods_type = 'P'
  613. <if test="websitId != null and websitId != ''">
  614. AND t.websit_id = #{websitId}
  615. </if>
  616. GROUP BY t.identity
  617. </select>
  618. <select id="workerNewStockStatistics"
  619. resultType="com.gree.mall.miniapp.bean.material.parts.WorkerStockCensusBean">
  620. SELECT
  621. SUM(
  622. IFNULL( b.qty, 0 )) AS newRefundQty,
  623. SUM(
  624. IFNULL( b.total_amount, 0 )) AS newRefundAmount
  625. FROM
  626. websit_parts_new_refund_manage a
  627. INNER JOIN websit_parts_new_refund_manage_record b ON a.apply_no = b.apply_no
  628. WHERE
  629. a.flag IN ( 'SAVE', 'SUBMIT', 'AGREE' )
  630. AND a.identity = #{identity}
  631. <if test="websitId != null and websitId != ''">
  632. AND a.receive_websit_id = #{websitId}
  633. </if>
  634. GROUP BY
  635. a.identity
  636. </select>
  637. <select id="workerOldStockStatistics"
  638. resultType="com.gree.mall.miniapp.bean.material.parts.WorkerStockCensusBean">
  639. SELECT
  640. SUM(
  641. IFNULL( b.qty, 0 )) AS oldRefundQty,
  642. SUM(
  643. IFNULL( b.total_amount, 0 )) AS oldRefundAmount
  644. FROM
  645. websit_parts_old_refund_manage a
  646. INNER JOIN websit_parts_old_refund_manage_record b ON a.apply_no = b.apply_no
  647. WHERE
  648. a.flag IN ( 'SAVE', 'SUBMIT' )
  649. AND a.identity = #{identity}
  650. <if test="websitId != null and websitId != ''">
  651. AND a.receive_websit_id = #{websitId}
  652. </if>
  653. GROUP BY
  654. a.identity
  655. </select>
  656. <select id="appOldRefundList" resultType="com.gree.mall.miniapp.bean.material.parts.OldRefundManageBean">
  657. SELECT
  658. a.company_wechat_id,
  659. a.company_wechat_name,
  660. a.apply_no,
  661. a.apply_category,
  662. CASE a.apply_category WHEN 'HOME' THEN '家用空调'
  663. WHEN 'TRADE' THEN '商用空调'
  664. WHEN 'ELEC' THEN '生活电器(小家电)'
  665. ELSE '' END AS applyCategoryName,
  666. a.apply_type,
  667. CASE a.apply_type WHEN 'NEW' THEN '新件返还'
  668. WHEN 'LOST' THEN '破损返还'
  669. WHEN 'BUG' THEN '故障返还'
  670. ELSE '' END AS applyTypeName,
  671. a.refund_mode,
  672. CASE a.refund_mode WHEN 'EXPRESS' THEN '快递'
  673. WHEN 'SELF' THEN '网点自还'
  674. ELSE '' END AS refundModeName,
  675. a.repair_flag,
  676. CASE a.repair_flag WHEN 'INNER' THEN '保内'
  677. WHEN 'OUTSIDE' THEN '保外'
  678. ELSE '' END AS repairFlagName,
  679. a.express_no,
  680. a.receive_address,
  681. a.receive_websit_id,
  682. a.receive_websit_name,
  683. a.receive_parts_websit_id,
  684. a.websit_Address,
  685. a.identity,
  686. a.worker_id,
  687. a.worker_name,
  688. a.work_order_no,
  689. a.pg_id,
  690. a.customer_name,
  691. a.customer_tel,
  692. a.refund_amount,
  693. a.refund_amount_mode,
  694. a.settlement_state,
  695. CASE a.settlement_state WHEN 0 THEN '未结算'
  696. WHEN 1 THEN '已结算'
  697. ELSE '' END AS settlementStateName,
  698. a.remark,
  699. a.examine_remark,
  700. a.flag,
  701. CASE WHEN a.flag = 'SAVE' THEN '保存'
  702. WHEN a.flag = 'SUBMIT' THEN '待审批'
  703. WHEN a.flag = 'AGREE' and a.repair_flag = 'INNER' THEN '待返还'
  704. WHEN a.flag = 'AGREE' and a.repair_flag = 'OUTSIDE' THEN '通过'
  705. WHEN a.flag = 'REJECT' THEN '驳回'
  706. WHEN a.flag = 'REFUNDED' THEN '已返还'
  707. ELSE a.flag = '' END AS flagName,
  708. a.create_by,
  709. a.create_time,
  710. a.update_by,
  711. a.update_time,
  712. a.submit_by,
  713. a.submit_time,
  714. a.examine_by,
  715. a.examine_time,
  716. a.refunded_by,
  717. a.refunded_time
  718. FROM
  719. websit_parts_old_refund_manage a
  720. LEFT JOIN websit_parts_old_refund_manage_item b ON a.apply_no = b.apply_no
  721. <where>
  722. a.company_wechat_id = #{companyWechatId}
  723. <if test="applyNo != null and applyNo != ''">
  724. AND a.apply_no = #{applyNo}
  725. </if>
  726. <if test="flag != null and flag != ''">
  727. AND a.flag = #{flag}
  728. </if>
  729. <if test="identity != null and identity != ''">
  730. AND a.identity = #{identity}
  731. </if>
  732. <if test="partsNumber != null and partsNumber != ''">
  733. AND b.new_parts_number = #{partsNumber}
  734. </if>
  735. <if test="repairFlag != null and repairFlag != ''">
  736. AND a.repair_flag = #{repairFlag}
  737. </if>
  738. </where>
  739. GROUP BY a.apply_no, a.create_time
  740. ORDER BY a.create_time DESC
  741. </select>
  742. <select id="queryWebsitList" resultType="com.gree.mall.miniapp.bean.material.parts.WebsitExtends">
  743. SELECT
  744. a.*,
  745. <!-- 按距离排序计算 -->
  746. TRUNCATE(ACOS(
  747. SIN((PI() / 180) * lat) * SIN((PI() / 180) * #{latitude})
  748. + COS((PI() / 180) * lat) * COS((PI() / 180) * #{latitude}) * COS((PI() / 180) * #{longitude} - (PI() / 180) * lng)
  749. ) * 6371,0) as distance
  750. from admin_websit a
  751. <where>
  752. <if test="websitId == null">
  753. AND a.status = 1
  754. </if>
  755. </where>
  756. order by distance asc, websit_id
  757. </select>
  758. <select id="selectNewRefundManageItemByApplyNo" resultMap="newRefundManageItemResultMap">
  759. SELECT
  760. id,
  761. apply_no,
  762. sales_id,
  763. parts_number,
  764. parts_name,
  765. material_group_name,
  766. goods_stock_unit,
  767. qty,
  768. remark,
  769. image,
  770. custom_no,
  771. create_time
  772. FROM
  773. websit_parts_new_refund_manage_item
  774. WHERE
  775. apply_no = #{applyNo}
  776. </select>
  777. <select id="selectNewRefundManageRecordByApplyNo" resultMap="newRefundManageRecordResultMap">
  778. SELECT
  779. id,
  780. item_id,
  781. apply_no,
  782. sales_id,
  783. sales_item_id,
  784. parts_number,
  785. parts_name,
  786. sales_price,
  787. market_price,
  788. second_price,
  789. qty,
  790. total_amount,
  791. refund_amount,
  792. refund_time,
  793. refund_state,
  794. CASE refund_state WHEN 'OK' THEN '成功'
  795. WHEN 'FAIL' THEN '失败'
  796. WHEN 'WAIT' THEN '等待'
  797. ELSE '' END AS refundStateName,
  798. refund_mch_no,
  799. refund_account_no,
  800. refund_serialnumber,
  801. create_time
  802. FROM
  803. websit_parts_new_refund_manage_record
  804. WHERE
  805. apply_no = #{applyNo}
  806. </select>
  807. </mapper>