ManagementInfoMapper.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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="shop.alien.mapper.ManagementInfoMapper">
  6. <select id="getAllManagementInfo" resultType="shop.alien.entity.store.ManagementInfo">
  7. SELECT
  8. store.id AS store_id,
  9. store.store_name,
  10. IFNULL(meal.coupon_count, 0) AS meal_coupon_count,
  11. IFNULL(meal.order_count, 0) AS meal_order_count,
  12. ROUND(IFNULL(meal.order_amount, 0) / 100,2) AS meal_order_amount,
  13. IFNULL(meal.income_count, 0) AS meal_income_count,
  14. ROUND(IFNULL(meal.income_money, 0) / 100,2) AS meal_income_money,
  15. IFNULL(coupon.coupon_count, 0) AS coupon_coupon_count,
  16. IFNULL(coupon.order_count, 0) AS coupon_order_count,
  17. ROUND(IFNULL(coupon.order_amount, 0) / 100,2) AS coupon_order_amount,
  18. IFNULL(coupon.income_count, 0) AS coupon_income_count,
  19. ROUND(IFNULL(coupon.income_money, 0) / 100,2) AS coupon_income_money,
  20. ROUND(IFNULL(allInfo.cash_out_money, 0) / 100,2) AS cashout_money,
  21. ROUND(IFNULL(allInfo.account_frozen, 0) / 100,2) AS account_frozen
  22. FROM
  23. store_info store
  24. LEFT JOIN merchant_reconciliation_coupon coupon ON store.id = coupon.store_id
  25. LEFT JOIN merchant_reconciliation_meal meal ON store.id = meal.store_id
  26. LEFT JOIN merchant_reconciliation allInfo ON store.id = allInfo.store_id
  27. where 1 = 1
  28. <if test="storeName != null and storeName != ''">
  29. AND store.store_name LIKE CONCAT('%', #{storeName}, '%')
  30. </if>
  31. </select>
  32. <select id="getBillingRanking" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  33. SELECT
  34. store.id,
  35. store.store_name,
  36. ROUND(IFNULL( sum( money ), 0 ) / 100,2) AS income_money
  37. FROM
  38. store_info store
  39. LEFT JOIN ( SELECT * FROM store_income_details_record WHERE created_time > #{startDate} AND created_time &lt; #{endDate} ) income ON store.id = income.store_id
  40. WHERE store.delete_flag = 0
  41. GROUP BY
  42. store.id
  43. ORDER BY
  44. income_money DESC
  45. </select>
  46. <select id="getAmountPaid" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  47. SELECT
  48. ROUND(IFNULL(SUM( money ),0) / 100,2) AS amountPaid
  49. FROM
  50. store_cash_out_record cash
  51. WHERE
  52. created_time > #{startDate} AND created_time &lt; #{endDate}
  53. </select>
  54. <select id="getTotalTransactionAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  55. SELECT
  56. ROUND(IFNULL(SUM( money ),0) / 100,2) AS totalTransactionAmount
  57. FROM
  58. store_income_details_record income
  59. where
  60. 1 = 1
  61. <if test="storeId != null and storeId != ''">
  62. AND store_id = #{storeId}
  63. </if>
  64. </select>
  65. <select id="getTransactionAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  66. SELECT
  67. ROUND(IFNULL(SUM( money ),0) / 100,2) AS totalTransactionAmount
  68. FROM
  69. store_income_details_record income
  70. WHERE
  71. created_time > #{startDate} AND created_time &lt; #{endDate}
  72. </select>
  73. <select id="getTransactionNumber" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  74. SELECT
  75. COUNT(1) AS transactionNumber
  76. FROM
  77. store_cash_out_record cash
  78. WHERE
  79. created_time > #{startDate} AND created_time &lt; #{endDate}
  80. </select>
  81. <select id="getAllOrderAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  82. SELECT
  83. ROUND(IFNULL(SUM( final_price ),0) / 100,2) AS allOrderAmount
  84. FROM
  85. life_user_order
  86. where
  87. 1 = 1
  88. <if test="storeId != null and storeId != ''">
  89. AND store_id = #{storeId}
  90. </if>
  91. </select>
  92. <select id="getOrderAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  93. SELECT
  94. ROUND(IFNULL(SUM( final_price ),0),2) AS allOrderAmount
  95. FROM
  96. life_user_order
  97. where
  98. created_time > #{startDate} AND created_time &lt; #{endDate}
  99. </select>
  100. <select id="getAllWrittenOffAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  101. SELECT
  102. ROUND(IFNULL(SUM( money ),0) / 100,2) AS allWrittenOffAmount
  103. FROM
  104. store_income_details_record
  105. where
  106. 1 = 1
  107. <if test="storeId != null and storeId != ''">
  108. AND store_id = #{storeId}
  109. </if>
  110. </select>
  111. <select id="getWrittenOffAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  112. SELECT
  113. ROUND(IFNULL(SUM( money ),0) / 100,2) AS allWrittenOffAmount
  114. FROM
  115. store_income_details_record
  116. where
  117. created_time > #{startDate} AND created_time &lt; #{endDate}
  118. </select>
  119. <select id="getTotalWithdrawalAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  120. SELECT
  121. ROUND(IFNULL(SUM( money ),0) / 100,2) AS totalWithdrawalAmount
  122. FROM
  123. store_cash_out_record cash
  124. where
  125. 1 = 1
  126. <if test="storeId != null and storeId != ''">
  127. AND store_id = #{storeId}
  128. </if>
  129. </select>
  130. <select id="getWithdrawalAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  131. SELECT
  132. ROUND(IFNULL(SUM( money ),0) / 100,2) AS totalWithdrawalAmount
  133. FROM
  134. store_cash_out_record cash
  135. where payment_status = 1 and
  136. created_time > #{startDate} AND created_time &lt; #{endDate}
  137. </select>
  138. <select id="getStoreOrderDetail" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  139. SELECT
  140. userOrder.id,
  141. userOrder.user_id,
  142. userInfo.user_name,
  143. coupon.type,
  144. CASE
  145. type
  146. WHEN 1 THEN
  147. "代金券"
  148. WHEN 2 THEN
  149. "套餐"
  150. END AS type_name,
  151. coupon.`name`,
  152. "1" AS buy_count,
  153. ROUND(userOrder.price / 100,2) AS buy_amount,
  154. userOrder.buy_time AS buy_time,
  155. userOrder.used_time AS used_time,
  156. userOrder.refund_time AS refund_time,
  157. userOrder.`status` AS `status`,
  158. CASE
  159. coupon.STATUS
  160. WHEN 0 THEN
  161. "待使用"
  162. WHEN 1 THEN
  163. "已核销"
  164. WHEN 2 THEN
  165. "已过期"
  166. WHEN 3 THEN
  167. "待退款"
  168. WHEN 4 THEN
  169. "已退款"
  170. END AS status_name,
  171. userOrder.order_no
  172. FROM
  173. life_user_order userOrder
  174. LEFT JOIN life_coupon coupon ON coupon.id = userOrder.id
  175. LEFT JOIN life_user userInfo ON userOrder.user_id = userInfo.id
  176. WHERE
  177. userOrder.store_id = #{storeId}
  178. <if test = "orderNo != null and orderNo != ''" >
  179. AND userOrder.order_no = #{orderNo}
  180. </if >
  181. <if test = "userId != null and userId != ''" >
  182. AND userOrder.user_id = #{userId}
  183. </if >
  184. <if test = "userName != null and userName != ''" >
  185. AND userInfo.user_name like concat('%',#{userName},'%')
  186. </if >
  187. </select>
  188. <select id="getUserCount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  189. SELECT
  190. count( 1 ) AS user_count
  191. FROM
  192. ( SELECT DISTINCT user_id FROM life_user_order
  193. WHERE 1 = 1
  194. <if test = "storeId != null and storeId != ''" >
  195. AND store_id = #{storeId}
  196. </if >
  197. ) a
  198. </select>
  199. <select id="getOrderTransactionNumber" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  200. SELECT
  201. count( 1 ) AS order_transaction_number
  202. FROM
  203. life_user_order
  204. WHERE
  205. 1 = 1
  206. <if test = "storeId != null and storeId != ''" >
  207. AND store_id = #{storeId}
  208. </if >
  209. </select>
  210. <select id="getVerificationAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  211. SELECT
  212. ROUND(IFNULL(SUM(money),0) / 100,2) AS verification_amount
  213. FROM
  214. store_income_details_record
  215. WHERE 1 = 1
  216. <if test = "storeId != null and storeId != ''" >
  217. AND store_id = #{storeId}
  218. </if >
  219. </select>
  220. <select id="getApplicationForWithdrawal" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  221. SELECT
  222. cash.id AS cash_id,
  223. store.store_name AS store_name ,
  224. storeUser.phone AS store_phone ,
  225. store.id AS store_id,
  226. cash.cash_out_type,
  227. CASE
  228. cash.cash_out_type
  229. WHEN 0 THEN
  230. "手动提现"
  231. WHEN 1 THEN
  232. "到期自动提现"
  233. END AS cash_out_type_name,
  234. ROUND(IFNULL(cash.money, 0) / 100,2) AS money,
  235. cash.created_time,
  236. cash.payment_date,
  237. cash.approve_time,
  238. cash.pay_date,
  239. cash.fail_reason,
  240. cash.payment_status
  241. FROM
  242. store_cash_out_record cash
  243. LEFT JOIN store_info store ON cash.store_id = store.id
  244. LEFT JOIN store_user storeUser ON storeUser.store_id = store.id
  245. WHERE 1 = 1
  246. <if test = "storeId != null and storeId != ''" >
  247. AND cash.store_id = #{storeId}
  248. </if >
  249. <if test="storeName != null and storeName != ''">
  250. AND store.store_name LIKE CONCAT('%', #{storeName}, '%')
  251. </if>
  252. </select>
  253. <select id="getCashOutDetail" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  254. SELECT
  255. cash.id AS cash_id,
  256. store.store_name AS store_name ,
  257. storeUser.phone AS store_phone ,
  258. store.id AS store_id,
  259. cash.cash_out_type,
  260. CASE
  261. cash.cash_out_type
  262. WHEN 0 THEN
  263. "手动提现"
  264. WHEN 1 THEN
  265. "到期自动提现"
  266. END AS cash_out_type_name,
  267. ROUND(IFNULL(cash.money, 0) / 100,2) AS money,
  268. cash.created_time,
  269. cash.payment_date,
  270. cash.approve_time,
  271. cash.pay_date,
  272. cash.fail_reason,
  273. cash.payment_status,
  274. cash.approve_fail_reason
  275. FROM
  276. store_cash_out_record cash
  277. LEFT JOIN store_info store ON cash.store_id = store.id
  278. LEFT JOIN store_user storeUser ON storeUser.store_id = store.id
  279. WHERE cash.id = #{id}
  280. </select>
  281. <select id="getPlatformNetProfit" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  282. select IFNULL(ROUND(sum(all_data.platform_profit),2), 0) AS profit from
  283. (SELECT
  284. ROUND(SUM(final_price) * (IFNULL(store.commission_rate, 3)/100),2) AS platform_profit
  285. FROM
  286. life_user_order `order`
  287. LEFT JOIN store_info store ON store.id = `order`.store_id
  288. WHERE
  289. `status` = 2
  290. <if test="dataTime != null and dataTime != ''">
  291. AND
  292. `order`.used_time > #{dataTime}
  293. </if>
  294. GROUP BY
  295. store.id) all_data
  296. </select>
  297. <select id="getOrderQuantity" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  298. SELECT
  299. IFNULL(COUNT( 1 ) ,0) AS count
  300. FROM
  301. life_user_order
  302. WHERE
  303. ( `status` in (1, 2)
  304. <if test="dataTime != null and dataTime != ''">
  305. AND
  306. buy_time > #{dataTime}
  307. </if>
  308. )
  309. </select>
  310. <select id="getTradingVolume" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  311. SELECT
  312. IFNULL(ROUND( sum( final_price ), 2 ),0) AS profit
  313. FROM
  314. life_user_order
  315. WHERE
  316. ( `status` = 2
  317. <if test="dataTime != null and dataTime != ''">
  318. AND
  319. used_time > #{dataTime}
  320. </if>
  321. )
  322. OR ( `status` = 1
  323. <if test="dataTime != null and dataTime != ''">
  324. AND
  325. buy_time > #{dataTime}
  326. </if>
  327. )
  328. </select>
  329. <select id="getQueryNetProfitDay" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  330. -- 使用递归 CTE 生成 1 到 23 的小时序列
  331. WITH RECURSIVE hours AS (
  332. SELECT 0 AS hour_num
  333. UNION ALL
  334. SELECT hour_num + 1
  335. FROM hours
  336. WHERE hour_num &lt; 23
  337. )
  338. SELECT
  339. concat(h.hour_num,":00") AS hour_num,
  340. COALESCE(ROUND(SUM(o.final_price) * 0.04, 2), 0) AS profit
  341. FROM
  342. hours h
  343. LEFT JOIN
  344. life_user_order o
  345. ON
  346. h.hour_num = HOUR(o.used_time)
  347. AND o.`status` = 1
  348. <if test="dataTime != null and dataTime != ''">
  349. AND o.used_time >= #{dataTime}
  350. </if>
  351. GROUP BY
  352. h.hour_num
  353. ORDER BY
  354. h.hour_num;
  355. </select>
  356. <select id="getQueryNetProfitWeek" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  357. WITH RECURSIVE date_sequence AS (
  358. SELECT DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) AS hour_num
  359. UNION ALL
  360. SELECT hour_num + INTERVAL 1 DAY
  361. FROM date_sequence
  362. WHERE hour_num &lt; DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) + INTERVAL 6 DAY
  363. )
  364. SELECT
  365. DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
  366. COALESCE(ROUND(SUM(luo.final_price) * 0.04, 2), 0) AS profit
  367. FROM
  368. date_sequence ds
  369. LEFT JOIN
  370. life_user_order luo
  371. ON
  372. luo.used_time >= ds.hour_num AND luo.used_time &lt; ds.hour_num + INTERVAL 1 DAY
  373. AND luo.`status` = 1
  374. GROUP BY
  375. ds.hour_num
  376. ORDER BY
  377. ds.hour_num;
  378. </select>
  379. <select id="getQueryNetProfitMonth" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  380. WITH RECURSIVE date_sequence AS (
  381. SELECT DATE_FORMAT(#{dataTime}, '%Y-%m-01') AS hour_num
  382. UNION ALL
  383. SELECT DATE_ADD(hour_num, INTERVAL 1 DAY)
  384. FROM date_sequence
  385. WHERE DATE_ADD(hour_num, INTERVAL 1 DAY) &lt;= LAST_DAY(#{dataTime})
  386. )
  387. SELECT
  388. DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
  389. COALESCE(ROUND(SUM(luo.final_price) * 0.04, 2), 0) AS profit
  390. FROM
  391. date_sequence ds
  392. LEFT JOIN
  393. life_user_order luo
  394. ON
  395. luo.used_time >= ds.hour_num AND luo.used_time &lt; DATE_ADD(ds.hour_num, INTERVAL 1 DAY)
  396. AND luo.`status` = 1
  397. GROUP BY
  398. ds.hour_num
  399. ORDER BY
  400. ds.hour_num;
  401. </select>
  402. <select id="getQueryNetProfitYear" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  403. WITH RECURSIVE month_sequence AS (
  404. SELECT 1 AS hour_num
  405. UNION ALL
  406. SELECT hour_num + 1
  407. FROM month_sequence
  408. WHERE hour_num &lt; 12
  409. )
  410. SELECT
  411. CONCAT(ms.hour_num,'月') AS hour_num,
  412. COALESCE(ROUND(SUM(luo.final_price) * 0.04, 2), 0) AS profit
  413. FROM
  414. month_sequence ms
  415. LEFT JOIN
  416. life_user_order luo
  417. ON
  418. MONTH(luo.used_time) = ms.hour_num
  419. AND YEAR(luo.used_time) = YEAR(#{dataTime})
  420. AND luo.`status` = 1
  421. GROUP BY
  422. ms.hour_num
  423. ORDER BY
  424. ms.hour_num;
  425. </select>
  426. <select id="getTradingVolumeDay" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  427. WITH RECURSIVE hours AS (
  428. SELECT 0 AS hour_num
  429. UNION ALL
  430. SELECT hour_num + 1
  431. FROM hours
  432. WHERE hour_num &lt; 23
  433. )
  434. SELECT
  435. concat(h.hour_num,":00") AS hour_num,
  436. COALESCE(ROUND(SUM(o.final_price), 2), 0) AS profit
  437. FROM
  438. hours h
  439. LEFT JOIN
  440. life_user_order o
  441. ON ( h.hour_num = HOUR( o.used_time ) AND ( o.`status` = 1 AND o.used_time >= #{dataTime} ) )
  442. OR ( h.hour_num = HOUR( o.buy_time ) AND ( o.`status` = 0 AND o.buy_time >= #{dataTime} ) )
  443. GROUP BY
  444. h.hour_num
  445. ORDER BY
  446. h.hour_num;
  447. </select>
  448. <select id="getTradingVolumeWeek" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  449. WITH RECURSIVE date_sequence AS (
  450. SELECT DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) AS hour_num
  451. UNION ALL
  452. SELECT hour_num + INTERVAL 1 DAY
  453. FROM date_sequence
  454. WHERE hour_num &lt; DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) + INTERVAL 6 DAY
  455. )
  456. SELECT
  457. DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
  458. COALESCE(ROUND(SUM(luo.final_price), 2), 0) AS profit
  459. FROM
  460. date_sequence ds
  461. LEFT JOIN
  462. life_user_order luo
  463. ON
  464. (luo.used_time >= ds.hour_num
  465. AND luo.used_time &lt; ds.hour_num + INTERVAL 1 DAY
  466. AND luo.`status` = 1 )
  467. OR
  468. (luo.buy_time >= ds.hour_num
  469. AND luo.buy_time &lt; ds.hour_num + INTERVAL 1 DAY
  470. AND luo.`status` = 0 )
  471. GROUP BY
  472. ds.hour_num
  473. ORDER BY
  474. ds.hour_num;
  475. </select>
  476. <select id="getTradingVolumeMonth" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  477. WITH RECURSIVE date_sequence AS (
  478. SELECT DATE_FORMAT(#{dataTime}, '%Y-%m-01') AS hour_num
  479. UNION ALL
  480. SELECT DATE_ADD(hour_num, INTERVAL 1 DAY)
  481. FROM date_sequence
  482. WHERE DATE_ADD(hour_num, INTERVAL 1 DAY) &lt;= LAST_DAY(#{dataTime})
  483. )
  484. SELECT
  485. DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
  486. COALESCE(ROUND(SUM(luo.final_price), 2), 0) AS profit
  487. FROM
  488. date_sequence ds
  489. LEFT JOIN
  490. life_user_order luo
  491. ON
  492. (luo.used_time >= ds.hour_num
  493. AND luo.used_time &lt; DATE_ADD( ds.hour_num, INTERVAL 1 DAY )
  494. AND luo.`status` = 1 )
  495. OR
  496. (luo.buy_time >= ds.hour_num
  497. AND luo.buy_time &lt; DATE_ADD( ds.hour_num, INTERVAL 1 DAY )
  498. AND luo.`status` = 0 )
  499. GROUP BY
  500. ds.hour_num
  501. ORDER BY
  502. ds.hour_num;
  503. </select>
  504. <select id="getTradingVolumeYear" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  505. WITH RECURSIVE month_sequence AS (
  506. SELECT 1 AS hour_num
  507. UNION ALL
  508. SELECT hour_num + 1
  509. FROM month_sequence
  510. WHERE hour_num &lt; 12
  511. )
  512. SELECT
  513. CONCAT(ms.hour_num,'月') AS hour_num,
  514. COALESCE(ROUND(SUM(luo.final_price), 2), 0) AS profit
  515. FROM
  516. month_sequence ms
  517. LEFT JOIN
  518. life_user_order luo
  519. ON
  520. (MONTH( luo.used_time ) = ms.hour_num
  521. AND YEAR( luo.used_time ) = YEAR( #{dataTime} )
  522. AND luo.`status` = 1 )
  523. OR
  524. (MONTH( luo.buy_time ) = ms.hour_num
  525. AND YEAR( luo.buy_time ) = YEAR( #{dataTime} )
  526. AND luo.`status` = 0 )
  527. GROUP BY
  528. ms.hour_num
  529. ORDER BY
  530. ms.hour_num;
  531. </select>
  532. <select id="getOrderQuantityDay" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  533. -- 使用 CTE 生成 0 到 23 的小时序列
  534. WITH hours AS (
  535. SELECT 0 AS hour_of_day
  536. UNION ALL SELECT 1
  537. UNION ALL SELECT 2
  538. UNION ALL SELECT 3
  539. UNION ALL SELECT 4
  540. UNION ALL SELECT 5
  541. UNION ALL SELECT 6
  542. UNION ALL SELECT 7
  543. UNION ALL SELECT 8
  544. UNION ALL SELECT 9
  545. UNION ALL SELECT 10
  546. UNION ALL SELECT 11
  547. UNION ALL SELECT 12
  548. UNION ALL SELECT 13
  549. UNION ALL SELECT 14
  550. UNION ALL SELECT 15
  551. UNION ALL SELECT 16
  552. UNION ALL SELECT 17
  553. UNION ALL SELECT 18
  554. UNION ALL SELECT 19
  555. UNION ALL SELECT 20
  556. UNION ALL SELECT 21
  557. UNION ALL SELECT 22
  558. UNION ALL SELECT 23
  559. )
  560. -- 主查询,左连接小时序列和原查询结果
  561. SELECT
  562. concat(h.hour_of_day,":00") AS hour_num,
  563. COALESCE(orders.order_count, 0) AS profit
  564. FROM
  565. hours h
  566. LEFT JOIN (
  567. SELECT
  568. HOUR(CASE WHEN `status` = 1 THEN used_time ELSE buy_time END) AS hour_of_day,
  569. COUNT(*) AS order_count
  570. FROM
  571. life_user_order
  572. WHERE
  573. (
  574. `status` = 1
  575. AND used_time > #{dataTime}
  576. )
  577. OR (
  578. `status` = 0
  579. AND buy_time > #{dataTime}
  580. )
  581. GROUP BY
  582. HOUR(CASE WHEN `status` = 1 THEN used_time ELSE buy_time END)
  583. ) orders ON h.hour_of_day = orders.hour_of_day
  584. ORDER BY
  585. h.hour_of_day;
  586. </select>
  587. <select id="getOrderQuantityWeek" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  588. WITH RECURSIVE date_sequence AS (
  589. SELECT DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) AS hour_num
  590. UNION ALL
  591. SELECT hour_num + INTERVAL 1 DAY
  592. FROM date_sequence
  593. WHERE hour_num &lt; DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) + INTERVAL 6 DAY
  594. )
  595. SELECT
  596. DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
  597. COALESCE(count(luo.id), 0) AS profit
  598. FROM
  599. date_sequence ds
  600. LEFT JOIN
  601. life_user_order luo
  602. ON
  603. (luo.used_time >= ds.hour_num AND luo.used_time &lt; ds.hour_num + INTERVAL 1 DAY
  604. AND luo.`status` = 1) or
  605. (luo.buy_time >= ds.hour_num AND luo.buy_time &lt; ds.hour_num + INTERVAL 1 DAY
  606. AND luo.`status` = 0)
  607. GROUP BY
  608. ds.hour_num
  609. ORDER BY
  610. ds.hour_num;
  611. </select>
  612. <select id="getOrderQuantityMonth" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  613. WITH RECURSIVE date_sequence AS (
  614. SELECT DATE_FORMAT(#{dataTime}, '%Y-%m-01') AS hour_num
  615. UNION ALL
  616. SELECT DATE_ADD(hour_num, INTERVAL 1 DAY)
  617. FROM date_sequence
  618. WHERE DATE_ADD(hour_num, INTERVAL 1 DAY) &lt;= LAST_DAY(#{dataTime})
  619. )
  620. SELECT
  621. DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
  622. COALESCE(count(luo.id), 0) AS profit
  623. FROM
  624. date_sequence ds
  625. LEFT JOIN
  626. life_user_order luo
  627. ON
  628. (luo.used_time >= ds.hour_num AND luo.used_time &lt; ds.hour_num + INTERVAL 1 DAY
  629. AND luo.`status` = 1) or
  630. (luo.buy_time >= ds.hour_num AND luo.buy_time &lt; ds.hour_num + INTERVAL 1 DAY
  631. AND luo.`status` = 0)
  632. GROUP BY
  633. ds.hour_num
  634. ORDER BY
  635. ds.hour_num;
  636. </select>
  637. <select id="getOrderQuantityYear" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  638. WITH months AS (
  639. SELECT
  640. CONCAT(YEAR(#{dataTime}), '-', LPAD(seq, 2, '0')) AS month
  641. FROM (
  642. SELECT 1 AS seq UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL
  643. SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL
  644. SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL
  645. SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12
  646. ) seq
  647. )
  648. SELECT
  649. CONCAT(MONTH(STR_TO_DATE(m.MONTH, '%Y-%m')),'月') AS hour_num,
  650. COALESCE(orders.order_count, 0) AS profit
  651. FROM
  652. months m
  653. LEFT JOIN (
  654. SELECT
  655. DATE_FORMAT(CASE WHEN `status` = 1 THEN used_time ELSE buy_time END, '%Y-%m') AS month,
  656. COUNT(*) AS order_count
  657. FROM
  658. life_user_order
  659. WHERE
  660. (
  661. `status` = 1
  662. AND used_time > #{dataTime}
  663. )
  664. OR (
  665. `status` = 0
  666. AND buy_time > #{dataTime}
  667. )
  668. GROUP BY
  669. DATE_FORMAT(CASE WHEN `status` = 1 THEN used_time ELSE buy_time END, '%Y-%m')
  670. ) orders ON m.month = orders.month
  671. ORDER BY
  672. m.month;
  673. </select>
  674. <select id="getSalesVolume" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  675. <!-- 初始化用户变量 -->
  676. SELECT
  677. profit,
  678. store.`store_name`
  679. FROM
  680. (
  681. SELECT
  682. count(id) AS profit,
  683. store_id
  684. FROM
  685. life_user_order
  686. WHERE
  687. ( `status` = 1 AND used_time >= #{startTime} AND used_time &lt; #{endTime})
  688. OR ( `status` = 0 AND buy_time >= #{startTime} AND buy_time &lt; #{endTime})
  689. GROUP BY
  690. store_id
  691. LIMIT 10
  692. ) statistic
  693. LEFT JOIN store_info store ON store.id = statistic.store_id
  694. ORDER BY
  695. profit DESC
  696. </select>
  697. <select id="getStorePlatformProfitDetails" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  698. SELECT
  699. store_id,
  700. store.store_name,
  701. ROUND(SUM(final_price), 2 ) AS operation_revenue,
  702. ROUND(SUM(final_price) - ROUND(SUM(final_price) * (IFNULL(store.commission_rate, 3)/100),2), 2) AS store_profit,
  703. ROUND(SUM(final_price) * (IFNULL(store.commission_rate, 3)/100),2) AS platform_profit
  704. FROM
  705. life_user_order `order`
  706. LEFT JOIN store_info store ON store.id = `order`.store_id
  707. WHERE
  708. `status` = 2
  709. <if test="startTime != null and startTime != ''" >
  710. AND used_time > #{startTime}
  711. </if>
  712. <if test="endTime != null and endTime != ''" >
  713. AND used_time &lt; #{endTime}
  714. </if>
  715. <if test="storeId != null and storeId != ''" >
  716. AND store_id like concat('%',#{storeId},'%')
  717. </if>
  718. <if test="storeName != null and storeName != ''" >
  719. AND store_name like concat('%',#{storeName},'%')
  720. </if>
  721. GROUP BY
  722. store.id
  723. ORDER BY
  724. `order`.created_time DESC
  725. </select>
  726. <select id="getRefundOrderQuantity" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  727. SELECT
  728. COUNT( 1 ) AS `count`
  729. FROM
  730. life_user_order
  731. WHERE
  732. `status` = 5
  733. <if test="dataTime != null and dataTime != ''">
  734. AND refund_time > #{dataTime}
  735. </if>
  736. </select>
  737. <select id="getTotalOrderVolume" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  738. SELECT
  739. COUNT( 1 ) AS `count`
  740. FROM
  741. life_user_order `order`
  742. WHERE
  743. delete_flag = 0
  744. <if test="dataTime != null and dataTime != ''">
  745. AND buy_time > #{dataTime}
  746. </if>
  747. </select>
  748. <select id="getStorePlatformOrderVolume" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  749. with total_coupon as(
  750. select id coupon_id,2 coupon_type,lgbm.group_name coupon_name, SUBSTRING_INDEX(image_id, ',', 1) AS image_id
  751. from life_group_buy_main lgbm where lgbm.delete_flag = 0
  752. union all
  753. select id coupon_id,1 coupon_type,lc.name coupon_name, SUBSTRING_INDEX(image_path, ',', 1) AS image_id
  754. from life_coupon lc where lc.delete_flag = 0
  755. )
  756. SELECT
  757. order_no,
  758. `order`.id as order_id,
  759. `order`.created_time AS order_time,
  760. `order`.finish_time AS finish_time,
  761. `order`.cancel_time AS cancel_time,
  762. `order`.pay_time AS pay_time,
  763. `order`.buy_time AS buy_time_str,
  764. ROUND(`order`.final_price, 2) AS final_price,
  765. CASE
  766. `order`.`status`
  767. WHEN 0 THEN '待支付'
  768. WHEN 1 THEN '已支付/待使用'
  769. WHEN 2 THEN '已核销'
  770. WHEN 3 THEN '已过期'
  771. WHEN 4 THEN '已取消'
  772. WHEN 5 THEN '已退款'
  773. WHEN 6 THEN '退款失败'
  774. WHEN 7 THEN '已完成'
  775. END AS status_name,
  776. simg.img_url,
  777. tc.*,
  778. store.store_name
  779. FROM
  780. life_user_order `order`
  781. left join store_info store on `order`.store_id = store.id
  782. left join order_coupon_middle ocm on ocm.order_id = `order`.id and ocm.delete_flag = 0
  783. inner join total_coupon tc on tc.coupon_id = ocm.coupon_id and tc.coupon_type = `order`.coupon_type
  784. left join store_img simg on simg.id = tc.image_id and simg.delete_flag = 0
  785. <where>
  786. 1 = 1
  787. <if test="orderType != null and orderType != ''">
  788. AND `order`.`status` = #{orderType}
  789. </if>
  790. <if test="startTime != null and startTime != ''">
  791. AND buy_time > #{startTime}
  792. </if>
  793. <if test="orderId != null and orderId != ''">
  794. AND `order`.`order_no` like concat('%',#{orderId},'%')
  795. </if>
  796. <if test="couponType != null and couponType != ''">
  797. AND tc.coupon_type = #{couponType}
  798. </if>
  799. <if test="couponName != null and couponName != ''">
  800. AND tc.coupon_name like concat('%',#{couponName},'%')
  801. </if>
  802. <if test="storeName != null and storeName != ''">
  803. AND store.store_name like concat('%',#{storeName},'%')
  804. </if>
  805. </where>
  806. ORDER BY
  807. `order`.created_time DESC
  808. </select>
  809. <select id="getRefundAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
  810. SELECT
  811. IFNULL(ROUND( SUM( final_price ), 2 ),0) AS profit
  812. FROM
  813. life_user_order `order`
  814. WHERE
  815. `status` = 4
  816. <if test="dataTime != null and dataTime != ''" >
  817. AND `order`.refund_time > #{dataTime}
  818. </if>
  819. </select>
  820. </mapper>