OrderGoodsMapper.xml 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.zhongzheng.modules.order.mapper.OrderGoodsMapper">
  6. <resultMap type="com.zhongzheng.modules.order.domain.OrderGoods" id="OrderGoodsResult">
  7. <result property="orderGoodsId" column="order_goods_id"/>
  8. <result property="orderSn" column="order_sn"/>
  9. <result property="goodsId" column="goods_id"/>
  10. <result property="goodsInputData" column="goods_input_data"/>
  11. <result property="goodsPrice" column="goods_price"/>
  12. <result property="goodsRealPrice" column="goods_real_price"/>
  13. <result property="createTime" column="create_time"/>
  14. <result property="updateTime" column="update_time"/>
  15. <result property="status" column="status"/>
  16. <result property="goodsReceived" column="goods_received"/>
  17. <result property="refundStatus" column="refund_status"/>
  18. <result property="payStatus" column="pay_status"/>
  19. <result property="businessOwner" column="business_owner"/>
  20. <result property="dept" column="dept"/>
  21. <result property="source" column="source"/>
  22. <result property="school" column="school"/>
  23. <result property="address" column="address"/>
  24. <result property="company" column="company"/>
  25. <result property="remark" column="remark"/>
  26. <result property="gradeId" column="grade_id"/>
  27. <result property="rebuyOrderGoodsId" column="rebuy_order_goods_id"/>
  28. <result property="studyCount" column="study_count"/>
  29. <result property="serviceStartTime" column="service_start_time"/>
  30. <result property="serviceEndTime" column="service_end_time"/>
  31. <result property="closeReason" column="close_reason"/>
  32. <result property="sevenClassVersion" column="seven_class_version"/>
  33. <result property="sevenClassStatus" column="seven_class_status"/>
  34. <result property="sevenYear" column="seven_year"/>
  35. <result property="sevenClassCopy" column="seven_class_copy"/>
  36. </resultMap>
  37. <resultMap type="com.zhongzheng.modules.order.vo.OrderGoodsVo" id="OrderGoodsResultVo">
  38. <result property="orderGoodsId" column="order_goods_id"/>
  39. <result property="orderSn" column="order_sn"/>
  40. <result property="goodsId" column="goods_id"/>
  41. <result property="goodsInputData" column="goods_input_data"/>
  42. <result property="goodsPrice" column="goods_price"/>
  43. <result property="goodsRealPrice" column="goods_real_price"/>
  44. <result property="status" column="status"/>
  45. <result property="goodsReceived" column="goods_received"/>
  46. <result property="refundStatus" column="refund_status"/>
  47. <result property="payStatus" column="pay_status"/>
  48. <result property="businessOwner" column="business_owner"/>
  49. <result property="dept" column="dept"/>
  50. <result property="source" column="source"/>
  51. <result property="school" column="school"/>
  52. <result property="address" column="address"/>
  53. <result property="company" column="company"/>
  54. <result property="createTime" column="create_time"/>
  55. <result property="remark" column="remark"/>
  56. <result property="userId" column="user_id"/>
  57. <result property="realname" column="realname"/>
  58. <result property="rebuyOrderGoodsId" column="rebuy_order_goods_id"/>
  59. <result property="externalLink" column="external_link"/>
  60. <result property="externalLinkStatus" column="external_link_status"/>
  61. <result property="periodStatus" column="period_status"/>
  62. <result property="distributionCode" column="distribution_code"/>
  63. <result property="distributionLinkCode" column="distribution_link_code"/>
  64. <result property="code" column="code"/>
  65. <result property="goodsName" column="goods_name"/>
  66. <result property="educationName" column="education_name"/>
  67. <result property="projectName" column="project_name"/>
  68. <result property="businessName" column="business_name"/>
  69. <result property="createBy" column="create_by"/>
  70. <result property="goodsType" column="goods_type"/>
  71. <result property="gradeId" column="grade_id"/>
  72. <result property="coverUrl" column="cover_url"/>
  73. <result property="gradeName" column="class_name"/>
  74. <result property="studyCount" column="study_count"/>
  75. <result property="class_name" column="gradeName"/>
  76. <result property="serviceStartTime" column="service_start_time"/>
  77. <result property="serviceEndTime" column="service_end_time"/>
  78. <result property="orderStatus" column="order_status"/>
  79. <result property="classStartTime" column="class_start_time"/>
  80. <result property="classEndTime" column="class_end_time"/>
  81. <result property="interfaceAccountId" column="interface_account_id"/>
  82. <result property="interfacePushId" column="interface_push_id"/>
  83. <result property="introduce" column="introduce"/>
  84. <result property="learningStatus" column="learning_status"/>
  85. <result property="learningTimeStart" column="learning_time_start"/>
  86. <result property="officialLearningUrl" column="official_learning_url"/>
  87. <result property="learnStatus" column="learn_status"/>
  88. <result property="officialStatus" column="official_status"/>
  89. <result property="classStatus" column="class_status"/>
  90. <result property="closeReason" column="close_reason"/>
  91. <result property="joinLiveNum" column="join_live_num"/>
  92. <result property="seeTime" column="see_time"/>
  93. <result property="categoryName" column="category_name"/>
  94. <result property="subjectIds" column="subject_ids"/>
  95. <result property="businessId" column="business_id"/>
  96. <result property="examNum" column="exam_num"/>
  97. <result property="recordNum" column="record_num"/>
  98. <result property="sysUserId" column="sys_user_id"/>
  99. <result property="applyStatus" column="apply_status"/>
  100. <result property="subExamStatus" column="sub_exam_status"/>
  101. <result property="subPerformance" column="sub_performance"/>
  102. <result property="subResult" column="sub_result"/>
  103. <result property="subApplySiteStartTime" column="sub_apply_site_start_time"/>
  104. <result property="subApplySiteEndTime" column="sub_apply_site_end_time"/>
  105. <result property="subApplySiteExamTime" column="sub_apply_site_exam_time"/>
  106. <result property="subscribeId" column="subscribe_id"/>
  107. <result property="gradeId" column="grade_id"/>
  108. <result property="userStudyCount" column="user_study_count"/>
  109. <result property="goodsLearningOrder" column="goods_learning_order"/>
  110. <result property="classHours" column="class_hours"/>
  111. <result property="courseNum" column="course_num"/>
  112. <result property="idCard" column="id_card" typeHandler="com.zhongzheng.common.type.EncryptHandler"/>
  113. <result property="sevenClassVersion" column="seven_class_version"/>
  114. <result property="sevenClassStatus" column="seven_class_status"/>
  115. <result property="sevenYear" column="seven_year"/>
  116. <result property="orderYear" column="order_year"/>
  117. <result property="sevenClassCopy" column="seven_class_copy"/>
  118. <result property="studyStatus" column="study_status"/>
  119. <result property="mailSign" column="mail_sign"/>
  120. <result property="profileStatus" column="profile_status"/>
  121. <result property="profileChangeStatus" column="profile_change_status"/>
  122. </resultMap>
  123. <select id="selectListBybo" parameterType="com.zhongzheng.modules.order.bo.OrderGoodsQueryBo"
  124. resultMap="OrderGoodsResultVo">
  125. SELECT
  126. og.*,
  127. g.`code`,
  128. g.goods_name,
  129. g.goods_type,
  130. g.cover_url,
  131. g.mail_sign,
  132. cet.education_name,
  133. cpt.project_name,
  134. cb.business_name
  135. FROM
  136. order_goods og
  137. LEFT JOIN goods g ON og.goods_id = g.goods_id
  138. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  139. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  140. LEFT JOIN course_business cb ON g.business_id = cb.id
  141. LEFT JOIN `order` o ON o.order_sn = og.order_sn
  142. WHERE
  143. 1 = 1
  144. and og.status = 1
  145. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  146. AND og.refund_status in
  147. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  148. #{item}
  149. </foreach>
  150. </if>
  151. <if test="goodsId != null and goodsId != ''">
  152. AND og.goods_id = #{goodsId}
  153. </if>
  154. <if test="userId != null">
  155. AND o.user_id = #{userId}
  156. </if>
  157. <if test="orderSn != null and orderSn != ''">
  158. AND og.order_sn = #{orderSn}
  159. </if>
  160. <if test="payStatusList != null and payStatusList.size()!=0 ">
  161. AND og.pay_status in
  162. <foreach collection="payStatusList" item="item" index="index" open="(" close=")" separator=",">
  163. #{item}
  164. </foreach>
  165. </if>
  166. <if test="orderGoodsIds != null and orderGoodsIds.size()!=0 ">
  167. AND og.order_goods_id in
  168. <foreach collection="orderGoodsIds" item="item" index="index" open="(" close=")" separator=",">
  169. #{item}
  170. </foreach>
  171. </if>
  172. </select>
  173. <select id="selectDetail" parameterType="com.zhongzheng.modules.order.bo.OrderGoodsQueryBo"
  174. resultMap="OrderGoodsResultVo">
  175. SELECT
  176. og.*,
  177. o.order_status,
  178. g.`code`,
  179. g.goods_name,
  180. g.goods_type,
  181. cet.education_name,
  182. cpt.project_name,
  183. cb.business_name,
  184. cg.class_name,
  185. o.create_username as create_by,
  186. cg.class_start_time,
  187. cg.class_end_time,
  188. cg.interface_account_id,
  189. cg.interface_push_id,
  190. g.introduce,
  191. cg.learning_status,
  192. cg.learning_time_start,
  193. cg.official_learning_url,
  194. cgu.learn_status,
  195. cgu.official_status,
  196. cg.class_status,
  197. m.category_name
  198. FROM
  199. order_goods og
  200. LEFT JOIN class_grade cg on og.grade_id = cg.grade_id
  201. LEFT JOIN goods g ON og.goods_id = g.goods_id
  202. LEFT JOIN major m ON g.major_id = m.id
  203. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  204. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  205. LEFT JOIN course_business cb ON g.business_id = cb.id
  206. LEFT JOIN `order` o ON og.order_sn = o.order_sn
  207. LEFT JOIN class_grade_user cgu on cgu.user_id = o.user_id and cgu.grade_id = cg.grade_id and cgu.order_goods_id = og.order_goods_id
  208. WHERE
  209. 1=1
  210. <if test="orderSn != null and orderSn != ''">
  211. AND og.order_sn = #{orderSn} AND og.goods_id = #{goodsId}
  212. </if>
  213. <if test="orderGoodsId != null and orderGoodsId != ''">
  214. AND og.order_goods_id= #{orderGoodsId}
  215. </if>
  216. </select>
  217. <select id="selectOrderGoods" parameterType="com.zhongzheng.modules.order.bo.OrderGoodsQueryBo"
  218. resultMap="OrderGoodsResultVo">
  219. SELECT og.*,
  220. o.user_id
  221. FROM `order` o
  222. LEFT JOIN order_goods og on o.order_sn = og.order_sn
  223. where 1 = 1
  224. and og.`status` = 1
  225. and og.refund_status in (0, 1, 3)
  226. and og.pay_status in (2, 3, 4)
  227. AND (SELECT COUNT(1)
  228. FROM inform_user iu
  229. where iu.user_id = o.user_id and iu.goods_id = og.goods_id and system_status = 1) &lt; 1
  230. </select>
  231. <select id="selectOrderTwoGoods" parameterType="com.zhongzheng.modules.order.bo.OrderGoodsQueryBo"
  232. resultMap="OrderGoodsResultVo">
  233. SELECT og.*,
  234. o.user_id
  235. FROM `order` o
  236. LEFT JOIN order_goods og on o.order_sn = og.order_sn
  237. where 1 = 1
  238. and og.`status` = 1
  239. and og.refund_status in (0, 1, 3)
  240. and og.pay_status in (2, 3, 4)
  241. AND (SELECT COUNT(1)
  242. FROM inform_user iu
  243. where iu.user_id = o.user_id and iu.goods_id = og.goods_id and system_status = 3) &lt; 1
  244. </select>
  245. <select id="sendGoods" resultMap="OrderGoodsResultVo">
  246. SELECT og.*,
  247. o.user_id
  248. FROM `order` o
  249. LEFT JOIN order_goods og on o.order_sn = og.order_sn
  250. where 1 = 1
  251. and og.`status` = 1
  252. and og.refund_status in (0, 1, 3)
  253. and og.pay_status in (2, 3, 4)
  254. and (SELECT COUNT(1)
  255. FROM user_exam_goods ueg
  256. where ueg.user_id = o.user_id and og.goods_id = ueg.goods_id) &lt; 1
  257. and (SELECT COUNT(1)
  258. FROM exam_number en
  259. LEFT JOIN exam_number_goods eng on en.exam_number_id = eng.exam_number_id
  260. where eng.goods_id = og.goods_id
  261. and en.`status` = 1) > 0
  262. </select>
  263. <select id="getBuyGoodsHistory" parameterType="com.zhongzheng.modules.order.bo.OrderGoodsQueryBo" resultType="Long">
  264. SELECT ifnull(count(*), 0) num
  265. FROM `order` o
  266. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  267. WHERE o.user_id = #{userId}
  268. AND og.goods_id = #{goodsId}
  269. AND og.`status` = 1
  270. AND og.pay_status > 1
  271. AND og.refund_status != 2
  272. </select>
  273. <select id="getBuyGoodsReadyPay" parameterType="com.zhongzheng.modules.order.bo.OrderGoodsQueryBo"
  274. resultType="Long">
  275. SELECT ifnull(count(*), 0) num
  276. FROM `order` o
  277. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  278. WHERE o.user_id = #{userId}
  279. AND og.goods_id = #{goodsId}
  280. AND o.order_status = 0
  281. </select>
  282. <select id="rebuyInfo" parameterType="com.zhongzheng.modules.order.bo.OrderGoodsQueryBo"
  283. resultMap="OrderGoodsResultVo">
  284. SELECT og.order_sn,
  285. g.goods_name,
  286. cg.class_name
  287. FROM order_goods og
  288. LEFT JOIN goods g ON og.goods_id = g.goods_id
  289. LEFT JOIN class_grade cg ON og.grade_id = cg.grade_id
  290. LEFT JOIN `order` o on og.order_sn = o.order_sn
  291. LEFT JOIN class_grade_user cgu ON cgu.grade_id = cg.grade_id and cgu.order_goods_id = og.order_goods_id and cgu.user_id = #{userId}
  292. WHERE o.user_id = #{userId}
  293. and og.goods_id = #{goodsId}
  294. and og.pay_status in (2, 3, 4)
  295. and og.order_goods_id != #{orderGoodsId}
  296. and cgu.period_plush = 1
  297. </select>
  298. <select id="gradeGoods" parameterType="com.zhongzheng.modules.order.bo.OrderGoodsQueryBo"
  299. resultMap="OrderGoodsResultVo">
  300. SELECT og.*
  301. FROM order_goods og
  302. LEFT JOIN `order` o on og.order_sn = o.order_sn
  303. WHERE o.user_id = #{userId}
  304. and og.grade_id = #{gradeId}
  305. and og.order_goods_id = #{orderGoodsId}
  306. and og.pay_status in (2, 3, 4)
  307. and og.refund_status !=2
  308. </select>
  309. <select id="selectCanInvoiceList" parameterType="com.zhongzheng.modules.order.bo.OrderGoodsQueryBo"
  310. resultMap="OrderGoodsResultVo">
  311. SELECT
  312. og.*,
  313. g.`code`,
  314. g.goods_name,
  315. g.goods_type,
  316. g.cover_url
  317. FROM
  318. order_goods og
  319. LEFT JOIN goods g ON og.goods_id = g.goods_id
  320. LEFT JOIN `order` o ON o.order_sn = og.order_sn
  321. WHERE
  322. 1 = 1
  323. AND og.order_goods_id NOT IN (
  324. SELECT
  325. oio.order_goods_id
  326. FROM
  327. order_invoice oi
  328. LEFT JOIN order_invoice_order oio ON oi.invoice_id = oio.invoice_id
  329. WHERE
  330. oi.period_status IN ( 1, 3 ) and oi.user_id = #{userId} and oi.status != -1 and oio.order_goods_id is not NULL)
  331. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  332. AND og.refund_status in
  333. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  334. #{item}
  335. </foreach>
  336. </if>
  337. <if test="goodsId != null and goodsId != ''">
  338. AND og.goods_id = #{goodsId}
  339. </if>
  340. <if test="userId != null">
  341. AND o.user_id = #{userId}
  342. </if>
  343. <if test="orderSn != null and orderSn != ''">
  344. AND og.order_sn = #{orderSn}
  345. </if>
  346. <if test="payStatusList != null and payStatusList.size()!=0 ">
  347. AND og.pay_status in
  348. <foreach collection="payStatusList" item="item" index="index" open="(" close=")" separator=",">
  349. #{item}
  350. </foreach>
  351. </if>
  352. <if test="orderGoodsIds != null and orderGoodsIds.size()!=0 ">
  353. AND og.order_goods_id in
  354. <foreach collection="orderGoodsIds" item="item" index="index" open="(" close=")" separator=",">
  355. #{item}
  356. </foreach>
  357. </if>
  358. </select>
  359. <select id="selectBuyGoodsUserList" parameterType="com.zhongzheng.modules.order.bo.OrderGoodsQueryBo"
  360. resultMap="OrderGoodsResultVo">
  361. SELECT DISTINCT u.user_id,
  362. u.realname
  363. FROM order_goods og
  364. LEFT JOIN `order` o ON og.order_sn = o.order_sn
  365. LEFT JOIN `user` u ON o.user_id = u.user_id
  366. WHERE og.`status` = 1
  367. -- AND og.refund_status IN (0, 1, 3)
  368. AND og.refund_status IN (0,3)
  369. AND og.pay_status IN (2, 3, 4)
  370. AND og.goods_id = #{goodsId}
  371. </select>
  372. <select id="listLiveGoodsList" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo"
  373. resultMap="OrderGoodsResultVo">
  374. SELECT
  375. g.*,
  376. o.user_id,
  377. o.order_sn,
  378. og.service_start_time,
  379. og.service_end_time,
  380. og.order_goods_id,
  381. u.realname,
  382. u.id_card,
  383. u.user_id,
  384. un.live_num as join_live_num,
  385. un.study_duration as see_time
  386. FROM `order` o
  387. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  388. LEFT JOIN goods g ON og.goods_id = g.goods_id
  389. LEFT JOIN `user` u ON u.user_id = o.user_id
  390. LEFT JOIN (SELECT
  391. usr.order_goods_id,
  392. count( DISTINCT usr.section_id ) live_num,
  393. SUM( usr.study_duration ) study_duration
  394. FROM
  395. user_study_record usr
  396. LEFT JOIN course_section cs ON usr.section_id = cs.section_id
  397. WHERE
  398. cs.section_type IN ( 2, 3 )
  399. GROUP BY
  400. usr.order_goods_id)un on un.order_goods_id = og.order_goods_id
  401. WHERE
  402. 1 = 1
  403. AND g.goods_type = 6
  404. AND og.pay_status IN ( 2, 3, 4 )
  405. -- AND og.refund_status IN (0,3,1)
  406. AND og.refund_status IN (0,3)
  407. <if test="goodsId != null and goodsId != ''">
  408. AND og.goods_id = #{goodsId}
  409. </if>
  410. <if test="searchKey != null and searchKey != ''">
  411. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%') or
  412. u.realname like concat('%', #{searchKey}, '%') or u.id_card like concat('%', #{searchKey}, '%'))
  413. </if>
  414. ORDER BY og.create_time DESC
  415. </select>
  416. <select id="listGoodsUserLive" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo"
  417. resultMap="OrderGoodsResultVo">
  418. SELECT
  419. g.*,
  420. cet.education_name,
  421. cpt.project_name,
  422. cb.business_name,
  423. o.user_id,
  424. og.create_time as order_create_time,
  425. og.service_start_time,
  426. og.service_end_time,
  427. og.order_goods_id
  428. FROM
  429. order_goods og
  430. LEFT JOIN goods g on g.goods_id =og.goods_id
  431. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  432. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  433. LEFT JOIN course_business cb ON g.business_id = cb.id
  434. LEFT JOIN `order` o on o.order_sn = og.order_sn
  435. WHERE
  436. 1 = 1
  437. AND g.goods_type = 6
  438. AND o.user_id=#{userId}
  439. AND og.`status` =1
  440. and og.pay_status in (2,3,4)
  441. -- AND og.refund_status in (0,3,1)
  442. AND og.refund_status in (0,3)
  443. <if test="educationTypeId != null and educationTypeId != ''">
  444. AND g.education_type_id = #{educationTypeId}
  445. </if>
  446. <if test="businessId != null and businessId != ''">
  447. AND g.business_id = #{businessId}
  448. </if>
  449. ORDER BY og.create_time DESC
  450. </select>
  451. <select id="listUserVideoLive" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo"
  452. resultMap="OrderGoodsResultVo">
  453. SELECT
  454. g.*,
  455. cet.education_name,
  456. cpt.project_name,
  457. cb.business_name,
  458. cb.goods_learning_order,
  459. o.user_id,
  460. og.create_time as order_create_time,
  461. og.service_start_time,
  462. og.service_end_time,
  463. og.order_goods_id,
  464. og.seven_year as order_year,
  465. og.grade_id,
  466. (SELECT
  467. COUNT( m.id )
  468. FROM
  469. goods_course c LEFT JOIN course_menu_exam m ON m.course_id = c.course_id
  470. where
  471. m.type in (1,3)
  472. and c.goods_id = g.goods_id) as exam_num,
  473. -- (SELECT COUNT(DISTINCT ubr.module_id,ubr.chapter_id,ubr.exam_id) FROM user_bank_record ubr LEFT JOIN
  474. -- class_grade_goods cgg on cgg.goods_id
  475. -- = ubr.goods_id where ubr.`status`=1 and ubr.report_status=1 and ubr.grade_id = og.grade_id and ubr.order_goods_id = og.order_goods_id and ubr.user_id =
  476. -- o.user_id and ubr.current_status = 1) as record_num,
  477. (case WHEN (SELECT COUNT(1) FROM exam_apply_goods eag LEFT JOIN exam_apply ea on eag.apply_id = ea.apply_id LEFT JOIN exam_apply_user eau on eau.apply_id = ea.apply_id where eag.goods_id = g.goods_id and ea.`status` = 1 and unix_timestamp(now()) BETWEEN ea.apply_start_time and ea.apply_end_time) >0 then 1 ELSE 0 end) as apply_status,
  478. us.exam_status as sub_exam_status,
  479. us.performance as sub_performance,
  480. us.`result` as sub_result,
  481. us.subscribe_id,
  482. us.apply_site_start_time as sub_apply_site_start_time,
  483. us.apply_site_end_time as sub_apply_site_end_time,
  484. us.apply_site_exam_time as sub_apply_site_exam_time,
  485. (SELECT COUNT(1) FROM goods_course gc where gc.goods_id = g.goods_id) as course_num,
  486. og.study_count as user_study_count,
  487. (SELECT `status` from user_profile where user_id = o.user_id and goods_id = g.goods_id and current_status = 1 and type_status = 1 and order_goods_id = og.order_goods_id limit 1 ) as profile_status,
  488. (SELECT change_status from user_profile where user_id = o.user_id and goods_id = g.goods_id and current_status = 1 and type_status = 1 and order_goods_id = og.order_goods_id limit 1 ) as profile_change_status,
  489. (SELECT count(*) from user_study_record usr where usr.user_id = o.user_id and usr.order_goods_id = og.order_goods_id) as study_status
  490. FROM
  491. order_goods og
  492. LEFT JOIN goods g on g.goods_id =og.goods_id
  493. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  494. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  495. LEFT JOIN course_business cb ON g.business_id = cb.id
  496. LEFT JOIN `order` o on o.order_sn = og.order_sn
  497. LEFT JOIN (SELECT * from user_subscribe where subscribe_id in (SELECT MAX(subscribe_id) from user_subscribe where user_id = #{userId} and subscribe_status = 1 GROUP BY order_goods_id)) us on us.order_goods_id = og.order_goods_id
  498. WHERE
  499. 1 = 1
  500. AND g.goods_type in (1,6)
  501. AND o.user_id=#{userId}
  502. AND og.`status` =1
  503. and og.pay_status in (2,3,4)
  504. -- AND og.refund_status in (0,3,1)
  505. AND og.refund_status in (0,3)
  506. <if test="educationTypeId != null and educationTypeId != ''">
  507. AND g.education_type_id = #{educationTypeId}
  508. </if>
  509. <if test="businessId != null and businessId != ''">
  510. AND g.business_id = #{businessId}
  511. </if>
  512. ORDER BY og.create_time DESC
  513. </select>
  514. <select id="listUserSubjectGoods" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo"
  515. resultMap="OrderGoodsResultVo">
  516. SELECT
  517. og.goods_id,
  518. og.grade_id,
  519. og.order_sn,
  520. g.business_id,
  521. g.subject_ids,
  522. cg.class_status,
  523. cg.class_start_time,
  524. cg.class_end_time,
  525. cg.class_name,
  526. g.goods_name,
  527. og.goods_price,
  528. og.seven_year as order_year,
  529. og.goods_real_price
  530. FROM
  531. `order` o
  532. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  533. LEFT JOIN goods g ON og.goods_id = g.goods_id
  534. LEFT JOIN class_grade cg ON og.grade_id = cg.grade_id
  535. WHERE
  536. o.user_id = #{userId}
  537. AND og.`status` =1
  538. and og.pay_status in (2,3,4)
  539. AND og.refund_status in (0,3,1)
  540. <if test="businessId != null and businessId != ''">
  541. AND g.business_id = #{businessId}
  542. </if>
  543. <if test="subjectId != null and subjectId != ''">
  544. AND FIND_IN_SET(#{subjectId},g.subject_ids)
  545. </if>
  546. </select>
  547. <select id="selectBuyUserList" parameterType="java.lang.Long" resultMap="OrderGoodsResultVo">
  548. SELECT og.*,
  549. o.user_id
  550. FROM order_goods og
  551. LEFT JOIN `order` o ON og.order_sn = o.order_sn
  552. LEFT JOIN mock_major_subject_goods mmsg ON og.goods_id = mmsg.goods_id
  553. WHERE og.refund_status != 2
  554. and og.pay_status in (2,3,4)
  555. and og.`status` = 1
  556. and mmsg.mock_major_subject_id = #{mockMajorSubjectId}
  557. </select>
  558. <select id="getLiveList" parameterType="java.lang.Long" resultType="com.zhongzheng.modules.course.vo.CourseLiveVo">
  559. SELECT
  560. *
  561. FROM
  562. (
  563. SELECT
  564. gc.course_id AS courseId,
  565. og.order_goods_id AS orderGoodsId,
  566. g.goods_id AS goodsId,
  567. cm.menu_id AS chapterId,
  568. '' AS moduleId,
  569. ct.*
  570. FROM
  571. `order` o
  572. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  573. LEFT JOIN goods g ON og.goods_id = g.goods_id
  574. INNER JOIN goods_course gc ON g.goods_id = gc.goods_id
  575. LEFT JOIN course_menu cm ON gc.course_id = cm.course_id
  576. LEFT JOIN course_chapter_section cs ON cm.menu_id = cs.chapter_id
  577. LEFT JOIN course_section ct ON cs.section_id = ct.section_id
  578. WHERE
  579. o.user_id = #{userId}
  580. AND og.pay_status IN ( 2, 3, 4 )
  581. -- AND og.refund_status != 2
  582. AND og.refund_status IN (0,3)
  583. AND og.STATUS = 1
  584. AND o.`status` = 1
  585. AND g.`status` = 1
  586. AND g.goods_type = 6
  587. AND cm.type = 2
  588. AND ct.section_type = 2 UNION ALL
  589. SELECT
  590. gc.course_id AS courseId,
  591. og.order_goods_id AS orderGoodsId,
  592. g.goods_id AS goodsId,
  593. '' AS chapterId,
  594. '' AS moduleId,
  595. ct.*
  596. FROM
  597. `order` o
  598. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  599. LEFT JOIN goods g ON og.goods_id = g.goods_id
  600. INNER JOIN goods_course gc ON g.goods_id = gc.goods_id
  601. LEFT JOIN course_menu cm ON gc.course_id = cm.course_id
  602. LEFT JOIN course_section ct ON cm.menu_id = ct.section_id
  603. WHERE
  604. o.user_id = #{userId}
  605. AND og.pay_status IN ( 2, 3, 4 )
  606. -- AND og.refund_status != 2
  607. AND og.refund_status IN (0,3)
  608. AND og.STATUS = 1
  609. AND o.`status` = 1
  610. AND g.`status` = 1
  611. AND g.goods_type = 6
  612. AND cm.type = 3
  613. AND ct.section_type = 2 UNION ALL
  614. SELECT
  615. gc.course_id AS courseId,
  616. og.order_goods_id AS orderGoodsId,
  617. g.goods_id AS goodsId,
  618. cmc.chapter_id AS chapterId,
  619. cmc.module_id AS moduleId,
  620. ct.*
  621. FROM
  622. `order` o
  623. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  624. LEFT JOIN goods g ON og.goods_id = g.goods_id
  625. INNER JOIN goods_course gc ON g.goods_id = gc.goods_id
  626. LEFT JOIN course_menu cm ON gc.course_id = cm.course_id
  627. LEFT JOIN course_module_chapter cmc ON cm.menu_id = cmc.module_id
  628. LEFT JOIN course_chapter_section ccs ON cmc.chapter_id = ccs.chapter_id
  629. LEFT JOIN course_section ct ON ccs.section_id = ct.section_id
  630. WHERE
  631. o.user_id = #{userId}
  632. AND og.pay_status IN ( 2, 3, 4 )
  633. -- AND og.refund_status != 2
  634. AND og.refund_status IN (0,3)
  635. AND og.STATUS = 1
  636. AND o.`status` = 1
  637. AND g.`status` = 1
  638. AND g.goods_type = 6
  639. AND cm.type = 1
  640. AND ct.section_type = 2
  641. ) a
  642. ORDER BY
  643. a.live_start_time ASC
  644. </select>
  645. <select id="getBuyNotStudyList" parameterType="com.zhongzheng.modules.order.bo.OrderQueryBo" resultMap="OrderGoodsResultVo">
  646. SELECT
  647. o.user_id,
  648. any_value (og.order_goods_id) order_goods_id,
  649. any_value (g.goods_id) goods_id,
  650. any_value (og.grade_id) grade_id,
  651. any_value (cg.sys_user_id) sys_user_id,
  652. any_value (g.goods_name) goods_name
  653. FROM
  654. order_goods og
  655. LEFT JOIN `order` o ON og.order_sn = o.order_sn
  656. LEFT JOIN goods g ON og.goods_id = g.goods_id
  657. LEFT JOIN class_grade cg ON og.grade_id = cg.grade_id
  658. LEFT JOIN ( SELECT count(*) study_num, usr.user_id, usr.grade_id FROM user_study_record usr GROUP BY usr.user_id, usr.grade_id ) r ON r.grade_id = og.grade_id
  659. AND r.user_id = o.user_id
  660. WHERE
  661. og.refund_status != 2
  662. AND og.pay_status IN ( 2, 3, 4 )
  663. AND og.`status` = 1
  664. AND g.goods_type = 1
  665. AND r.study_num IS NULL
  666. AND og.create_time > #{startTime}
  667. AND #{endTime} >= og.create_time
  668. GROUP BY o.user_id
  669. </select>
  670. <select id="getLongNotStudyList" parameterType="com.zhongzheng.modules.order.bo.OrderQueryBo" resultMap="OrderGoodsResultVo">
  671. SELECT
  672. o.user_id,
  673. any_value (og.order_goods_id) order_goods_id,
  674. any_value (g.goods_id) goods_id,
  675. any_value (og.grade_id) grade_id,
  676. any_value (cg.sys_user_id) sys_user_id,
  677. any_value (g.goods_name) goods_name
  678. FROM
  679. order_goods og
  680. LEFT JOIN `order` o ON og.order_sn = o.order_sn
  681. LEFT JOIN goods g ON og.goods_id = g.goods_id
  682. LEFT JOIN class_grade cg ON og.grade_id = cg.grade_id
  683. LEFT JOIN ( SELECT MAX(usr.update_time) last_time, usr.user_id, usr.grade_id FROM user_study_record usr GROUP BY usr.user_id, usr.grade_id ) r ON r.grade_id = og.grade_id
  684. AND r.user_id = o.user_id
  685. WHERE
  686. og.refund_status != 2
  687. AND og.pay_status IN ( 2, 3, 4 )
  688. AND og.`status` = 1
  689. AND g.goods_type = 1
  690. AND r.last_time > #{startTime}
  691. AND #{endTime} >= r.last_time
  692. GROUP BY o.user_id
  693. </select>
  694. <select id="getGoodsSectionList" parameterType="java.lang.Long" resultType="com.zhongzheng.modules.goods.vo.GoodsSectionListVo">
  695. SELECT
  696. *
  697. FROM
  698. (
  699. SELECT
  700. gc.goods_id,
  701. gc.sort AS gcSort,
  702. cm.sort AS cmSort,
  703. cmd.sort AS cmdSort,
  704. ccs.sort AS ccsSort,
  705. cs.sort AS csSort,
  706. cm.course_id,
  707. cmd.module_id,
  708. ccs.chapter_id,
  709. cs.section_id,
  710. cs.`name` as sectionName
  711. FROM
  712. goods_course gc
  713. LEFT JOIN course_menu cm ON gc.course_id = cm.course_id
  714. LEFT JOIN course_module_chapter cmd ON cm.menu_id = cmd.module_id
  715. LEFT JOIN course_chapter_section ccs ON cmd.chapter_id = ccs.chapter_id
  716. LEFT JOIN course_section cs ON ccs.section_id = cs.section_id
  717. WHERE
  718. gc.goods_id = #{goodsId}
  719. AND cm.type = 1
  720. UNION ALL
  721. SELECT
  722. gc.goods_id,
  723. gc.sort AS gcSort,
  724. cm.sort AS cmSort,
  725. NULL AS cmdSort,
  726. ccs.sort AS ccsSort,
  727. cs.sort AS csSort,
  728. cm.course_id,
  729. 0 AS module_id,
  730. ccs.chapter_id,
  731. cs.section_id,
  732. cs.`name` as sectionName
  733. FROM
  734. goods_course gc
  735. LEFT JOIN course_menu cm ON gc.course_id = cm.course_id
  736. LEFT JOIN course_chapter_section ccs ON cm.menu_id = ccs.chapter_id
  737. LEFT JOIN course_section cs ON ccs.section_id = cs.section_id
  738. WHERE
  739. gc.goods_id = #{goodsId}
  740. AND cm.type = 2
  741. UNION ALL
  742. SELECT
  743. gc.goods_id,
  744. gc.sort AS gcSort,
  745. cm.sort AS cmSort,
  746. NULL AS cmdSort,
  747. NULL AS ccsSort,
  748. cs.sort AS csSort,
  749. cm.course_id,
  750. 0 AS module_id,
  751. 0 AS chapter_id,
  752. cs.section_id,
  753. cs.`name` as sectionName
  754. FROM
  755. goods_course gc
  756. LEFT JOIN course_menu cm ON gc.course_id = cm.course_id
  757. LEFT JOIN course_section cs ON cm.menu_id = cs.section_id
  758. WHERE
  759. gc.goods_id = #{goodsId}
  760. AND cm.type = 3
  761. ) a
  762. ORDER BY
  763. a.gcSort,
  764. cmSort,
  765. cmdSort,
  766. ccsSort,
  767. csSort
  768. </select>
  769. <select id="getOrderByGoods" parameterType="java.lang.Long" resultType="com.zhongzheng.modules.order.domain.OrderGoods">
  770. SELECT
  771. *
  772. FROM
  773. order_goods og
  774. LEFT JOIN `order` o ON og.order_sn = o.order_sn
  775. LEFT JOIN goods g ON og.goods_id = g.goods_id
  776. WHERE
  777. og.`status` = 1
  778. AND o.`status` = 1
  779. AND g.`status` = 1
  780. AND og.refund_status != 2
  781. AND og.pay_status IN ( 2, 3, 4 )
  782. AND o.user_id = #{userId}
  783. AND g.goods_id = #{goodsId}
  784. LIMIT 1
  785. </select>
  786. <resultMap id="getlist" type="com.zhongzheng.modules.top.goods.vo.TopOldOrderGoodsListVo">
  787. <result property="orderGoodsId" column="order_goods_id"/>
  788. <result property="gradeId" column="grade_id"/>
  789. <result property="goodsId" column="goods_id"/>
  790. <result property="userId" column="user_id" />
  791. <result property="userName" column="realname" />
  792. <result property="userCard" column="id_card" typeHandler="com.zhongzheng.common.type.EncryptHandler"/>
  793. <result property="userPhone" column="telphone" typeHandler="com.zhongzheng.common.type.EncryptHandler"/>
  794. <result property="goodsName" column="goods_name"/>
  795. <result property="goodsType" column="goods_type"/>
  796. <result property="subjectIds" column="subject_ids"/>
  797. <result property="businessName" column="business_name"/>
  798. <result property="goodsPrice" column="goods_price"/>
  799. <result property="goodsRealPrice" column="goods_real_price"/>
  800. <result property="checkStatus" column="check_status"/>
  801. <result property="goodsYear" column="goods_year"/>
  802. <result property="divideType" column="divide_type"/>
  803. <result property="divideRate" column="divide_rate"/>
  804. <result property="divideMoney" column="divide_money"/>
  805. </resultMap>
  806. <select id="listByOrderSn" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderGoodsQuery" resultMap="getlist">
  807. SELECT
  808. og.order_goods_id,
  809. og.grade_id,
  810. og.goods_id,
  811. u.user_id,
  812. u.realname,
  813. u.id_card,
  814. u.telphone,
  815. g.goods_name,
  816. g.goods_type,
  817. g.subject_ids,
  818. CONCAT( cb.business_name, cpt.project_name ) AS business_name,
  819. og.goods_price,
  820. og.goods_real_price,
  821. og.goods_year,
  822. og.divide_type,
  823. og.divide_rate,
  824. og.divide_money,
  825. 1 as check_status
  826. FROM
  827. order_goods og
  828. LEFT JOIN goods g ON og.goods_id = g.goods_id
  829. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  830. LEFT JOIN course_business cb ON g.business_id = cb.id
  831. LEFT JOIN `order` o ON og.order_sn = o.order_sn
  832. LEFT JOIN `user` u ON o.user_id = u.user_id
  833. WHERE
  834. og.order_sn = #{orderSn}
  835. AND og.`status` = 1
  836. -- AND og.refund_status != 2
  837. -- AND og.pay_status IN ( 2, 3, 4 )
  838. <if test="userCard != null and userCard != ''">
  839. AND u.id_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  840. </if>
  841. <if test="userName != null and userName != ''">
  842. AND u.realname LIKE CONCAT( '%', #{userName}, '%' )
  843. </if>
  844. </select>
  845. <select id="getBusinessById" parameterType="java.lang.Long" resultType="java.lang.String">
  846. SELECT
  847. CONCAT( '学校业务', cet.education_name, cb.business_name, cpt.project_name ) AS businessName
  848. FROM
  849. order_goods og
  850. LEFT JOIN goods g ON og.goods_id = g.goods_id
  851. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  852. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  853. LEFT JOIN course_business cb ON g.business_id = cb.id
  854. WHERE
  855. og.`status` = 1
  856. AND og.order_goods_id = #{orderGoodsId}
  857. </select>
  858. <select id="getApplyOrderGoods" parameterType="map" resultType="com.zhongzheng.modules.order.domain.OrderGoods">
  859. SELECT
  860. og.*
  861. FROM
  862. order_goods og
  863. LEFT JOIN `order` o ON og.order_sn = o.order_sn
  864. WHERE
  865. og.`status` = 1
  866. AND og.refund_status != 2
  867. AND og.pay_status IN ( 2, 3, 4 )
  868. AND og.goods_id in
  869. <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
  870. #{item}
  871. </foreach>
  872. AND o.`status` = 1
  873. AND o.user_id = #{userId}
  874. </select>
  875. <select id="getSevenLastOne" parameterType="map" resultType="com.zhongzheng.modules.order.domain.OrderGoods">
  876. SELECT
  877. og.*
  878. FROM
  879. order_goods og
  880. LEFT JOIN goods g ON og.goods_id = g.goods_id
  881. LEFT JOIN `order` o ON og.order_sn = o.order_sn
  882. WHERE
  883. og.`status` = 1
  884. AND og.refund_status != 2
  885. AND o.user_id = #{userId}
  886. AND og.pay_status IN ( 2, 3, 4 )
  887. AND g.project_id = #{projectId}
  888. AND og.seven_class_status = 3
  889. AND og.seven_year = #{sevenYear}
  890. AND og.seven_class_version > 0
  891. ORDER BY og.seven_class_version DESC
  892. LIMIT 1
  893. </select>
  894. <select id="countOrderGoodsByYear" parameterType="map" resultType="java.lang.Long">
  895. SELECT
  896. COUNT( og.order_goods_id )
  897. FROM
  898. order_goods og
  899. LEFT JOIN `order` o ON og.order_sn = o.order_sn
  900. WHERE
  901. og.refund_status != 2
  902. AND og.pay_status IN ( 2, 3, 4 )
  903. AND og.`status` = 1
  904. AND o.`status` = 1
  905. AND o.user_id = #{userId}
  906. AND og.goods_id = #{goodsId}
  907. AND og.seven_year = #{sevenYear}
  908. AND og.service_start_time <![CDATA[ <= ]]> UNIX_TIMESTAMP()
  909. AND og.service_end_time <![CDATA[ >= ]]> UNIX_TIMESTAMP()
  910. </select>
  911. <select id="getByIdNoTenant" parameterType="java.lang.Long" resultType="com.zhongzheng.modules.order.domain.OrderGoods">
  912. SELECT
  913. *
  914. FROM
  915. order_goods
  916. WHERE
  917. order_goods_id = #{orderGoodsId}
  918. </select>
  919. <select id="getMailList" parameterType="com.zhongzheng.modules.order.bo.MailOrderBo" resultType="com.zhongzheng.modules.order.vo.MailOrderVo">
  920. SELECT
  921. order_sn,
  922. mail_status,
  923. consignee,
  924. consignee_phone,
  925. consignee_site,
  926. mail_remark
  927. FROM
  928. `order`
  929. WHERE
  930. `status` = 1
  931. AND order_type = 5
  932. <if test="orderSn != null and orderSn != ''">
  933. AND order_sn = #{orderSn}
  934. </if>
  935. <if test="mailStatus != null">
  936. AND mail_status = #{mailStatus}
  937. </if>
  938. order by create_time DESC
  939. </select>
  940. <select id="sendTenOrderGoods" parameterType="java.lang.Long" resultMap="OrderGoodsResultVo">
  941. SELECT
  942. og.*,o.user_id
  943. FROM
  944. order_goods og
  945. LEFT JOIN `order` o on og.order_sn = o.order_sn
  946. LEFT JOIN goods g on og.goods_id = g.goods_id
  947. LEFT JOIN inform_remind_business irb on irb.business_id = g.business_id
  948. where 1=1
  949. and irb.remind_id =#{remindId}
  950. and og.status = 1
  951. AND og.service_end_time BETWEEN ( unix_timestamp(now()) + 864000) AND (unix_timestamp(now()) + 950400)
  952. </select>
  953. <select id="listByNotTenant" resultType="com.zhongzheng.modules.order.domain.OrderGoods">
  954. SELECT og.* FROM order_goods og
  955. LEFT JOIN goods g ON og.goods_id = g.goods_id
  956. WHERE og.`status` = 1
  957. AND (( og.course_num IS NULL OR og.course_num = 0 ) AND ( og.exam_num IS NULL OR og.exam_num = 0 ))
  958. AND og.refund_status != 2
  959. AND og.pay_status != 1
  960. AND g.goods_type = 1
  961. </select>
  962. <update id="upBatchNumById" parameterType="com.zhongzheng.modules.order.domain.OrderGoods">
  963. UPDATE order_goods SET course_num = #{courseNum}, exam_num = #{examNum} WHERE order_goods_id = #{orderGoodsId}
  964. </update>
  965. </mapper>