| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="shop.alien.mapper.ManagementInfoMapper">
- <select id="getAllManagementInfo" resultType="shop.alien.entity.store.ManagementInfo">
- SELECT
- store.id AS store_id,
- store.store_name,
- IFNULL(meal.coupon_count, 0) AS meal_coupon_count,
- IFNULL(meal.order_count, 0) AS meal_order_count,
- ROUND(IFNULL(meal.order_amount, 0) / 100,2) AS meal_order_amount,
- IFNULL(meal.income_count, 0) AS meal_income_count,
- ROUND(IFNULL(meal.income_money, 0) / 100,2) AS meal_income_money,
- IFNULL(coupon.coupon_count, 0) AS coupon_coupon_count,
- IFNULL(coupon.order_count, 0) AS coupon_order_count,
- ROUND(IFNULL(coupon.order_amount, 0) / 100,2) AS coupon_order_amount,
- IFNULL(coupon.income_count, 0) AS coupon_income_count,
- ROUND(IFNULL(coupon.income_money, 0) / 100,2) AS coupon_income_money,
- ROUND(IFNULL(allInfo.cash_out_money, 0) / 100,2) AS cashout_money,
- ROUND(IFNULL(allInfo.account_frozen, 0) / 100,2) AS account_frozen
- FROM
- store_info store
- LEFT JOIN merchant_reconciliation_coupon coupon ON store.id = coupon.store_id
- LEFT JOIN merchant_reconciliation_meal meal ON store.id = meal.store_id
- LEFT JOIN merchant_reconciliation allInfo ON store.id = allInfo.store_id
- where 1 = 1
- <if test="storeName != null and storeName != ''">
- AND store.store_name LIKE CONCAT('%', #{storeName}, '%')
- </if>
- </select>
- <select id="getBillingRanking" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- store.id,
- store.store_name,
- ROUND(IFNULL( sum( money ), 0 ) / 100,2) AS income_money
- FROM
- store_info store
- LEFT JOIN ( SELECT * FROM store_income_details_record WHERE created_time > #{startDate} AND created_time < #{endDate} ) income ON store.id = income.store_id
- GROUP BY
- store.id
- ORDER BY
- income_money DESC
- </select>
- <select id="getAmountPaid" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- ROUND(IFNULL(SUM( money ),0) / 100,2) AS amountPaid
- FROM
- store_cash_out_record cash
- WHERE
- created_time > #{startDate} AND created_time < #{endDate}
- </select>
- <select id="getTotalTransactionAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- ROUND(IFNULL(SUM( money ),0) / 100,2) AS totalTransactionAmount
- FROM
- store_income_details_record income
- where
- 1 = 1
- <if test="storeId != null and storeId != ''">
- AND store_id = #{storeId}
- </if>
- </select>
- <select id="getTransactionAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- ROUND(IFNULL(SUM( money ),0) / 100,2) AS totalTransactionAmount
- FROM
- store_income_details_record income
- WHERE
- created_time > #{startDate} AND created_time < #{endDate}
- </select>
- <select id="getTransactionNumber" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- COUNT(1) AS transactionNumber
- FROM
- store_cash_out_record cash
- WHERE
- created_time > #{startDate} AND created_time < #{endDate}
- </select>
- <select id="getAllOrderAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- ROUND(IFNULL(SUM( final_price ),0) / 100,2) AS allOrderAmount
- FROM
- life_user_order
- where
- 1 = 1
- <if test="storeId != null and storeId != ''">
- AND store_id = #{storeId}
- </if>
- </select>
- <select id="getOrderAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- ROUND(IFNULL(SUM( final_price ),0),2) AS allOrderAmount
- FROM
- life_user_order
- where
- created_time > #{startDate} AND created_time < #{endDate}
- </select>
- <select id="getAllWrittenOffAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- ROUND(IFNULL(SUM( money ),0) / 100,2) AS allWrittenOffAmount
- FROM
- store_income_details_record
- where
- 1 = 1
- <if test="storeId != null and storeId != ''">
- AND store_id = #{storeId}
- </if>
- </select>
- <select id="getWrittenOffAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- ROUND(IFNULL(SUM( money ),0) / 100,2) AS allWrittenOffAmount
- FROM
- store_income_details_record
- where
- created_time > #{startDate} AND created_time < #{endDate}
- </select>
- <select id="getTotalWithdrawalAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- ROUND(IFNULL(SUM( money ),0) / 100,2) AS totalWithdrawalAmount
- FROM
- store_cash_out_record cash
- where
- 1 = 1
- <if test="storeId != null and storeId != ''">
- AND store_id = #{storeId}
- </if>
- </select>
- <select id="getWithdrawalAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- ROUND(IFNULL(SUM( money ),0) / 100,2) AS totalWithdrawalAmount
- FROM
- store_cash_out_record cash
- where payment_status = 1 and
- created_time > #{startDate} AND created_time < #{endDate}
- </select>
- <select id="getStoreOrderDetail" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- userOrder.id,
- userOrder.user_id,
- userInfo.user_name,
- coupon.type,
- CASE
- type
- WHEN 1 THEN
- "代金券"
- WHEN 2 THEN
- "套餐"
- END AS type_name,
- coupon.`name`,
- "1" AS buy_count,
- ROUND(userOrder.price / 100,2) AS buy_amount,
- userOrder.buy_time AS buy_time,
- userOrder.used_time AS used_time,
- userOrder.refund_time AS refund_time,
- userOrder.`status` AS `status`,
- CASE
- coupon.STATUS
- WHEN 0 THEN
- "待使用"
- WHEN 1 THEN
- "已核销"
- WHEN 2 THEN
- "已过期"
- WHEN 3 THEN
- "待退款"
- WHEN 4 THEN
- "已退款"
- END AS status_name,
- userOrder.order_no
- FROM
- life_user_order userOrder
- LEFT JOIN life_coupon coupon ON coupon.id = userOrder.id
- LEFT JOIN life_user userInfo ON userOrder.user_id = userInfo.id
- WHERE
- userOrder.store_id = #{storeId}
- <if test = "orderNo != null and orderNo != ''" >
- AND userOrder.order_no = #{orderNo}
- </if >
- <if test = "userId != null and userId != ''" >
- AND userOrder.user_id = #{userId}
- </if >
- <if test = "userName != null and userName != ''" >
- AND userInfo.user_name like concat('%',#{userName},'%')
- </if >
- </select>
- <select id="getUserCount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- count( 1 ) AS user_count
- FROM
- ( SELECT DISTINCT user_id FROM life_user_order
- WHERE 1 = 1
- <if test = "storeId != null and storeId != ''" >
- AND store_id = #{storeId}
- </if >
- ) a
- </select>
- <select id="getOrderTransactionNumber" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- count( 1 ) AS order_transaction_number
- FROM
- life_user_order
- WHERE
- 1 = 1
- <if test = "storeId != null and storeId != ''" >
- AND store_id = #{storeId}
- </if >
- </select>
- <select id="getVerificationAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- ROUND(IFNULL(SUM(money),0) / 100,2) AS verification_amount
- FROM
- store_income_details_record
- WHERE 1 = 1
- <if test = "storeId != null and storeId != ''" >
- AND store_id = #{storeId}
- </if >
- </select>
- <select id="getApplicationForWithdrawal" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- cash.id AS cash_id,
- store.store_name AS store_name ,
- storeUser.phone AS store_phone ,
- store.id AS store_id,
- cash.cash_out_type,
- CASE
- cash.cash_out_type
- WHEN 0 THEN
- "手动提现"
- WHEN 1 THEN
- "到期自动提现"
- END AS cash_out_type_name,
- ROUND(IFNULL(cash.money, 0) / 100,2) AS money,
- cash.created_time,
- cash.payment_date,
- cash.approve_time,
- cash.pay_date,
- cash.fail_reason,
- cash.payment_status
- FROM
- store_cash_out_record cash
- LEFT JOIN store_info store ON cash.store_id = store.id
- LEFT JOIN store_user storeUser ON storeUser.store_id = store.id
- WHERE 1 = 1
- <if test = "storeId != null and storeId != ''" >
- AND cash.store_id = #{storeId}
- </if >
- <if test="storeName != null and storeName != ''">
- AND store.store_name LIKE CONCAT('%', #{storeName}, '%')
- </if>
- </select>
- <select id="getPlatformNetProfit" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- select IFNULL(ROUND(sum(all_data.platform_profit),2), 0) AS profit from
- (SELECT
- ROUND(SUM(final_price) * (IFNULL(store.commission_rate, 3)/100),2) AS platform_profit
- FROM
- life_user_order `order`
- LEFT JOIN store_info store ON store.id = `order`.store_id
- WHERE
- `status` = 2
- <if test="dataTime != null and dataTime != ''">
- AND
- `order`.used_time > #{dataTime}
- </if>
- GROUP BY
- store.id) all_data
- </select>
- <select id="getOrderQuantity" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- IFNULL(COUNT( 1 ) ,0) AS count
- FROM
- life_user_order
- WHERE
- ( `status` in (1, 2)
- <if test="dataTime != null and dataTime != ''">
- AND
- buy_time > #{dataTime}
- </if>
- )
- </select>
- <select id="getTradingVolume" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- IFNULL(ROUND( sum( final_price ), 2 ),0) AS profit
- FROM
- life_user_order
- WHERE
- ( `status` = 2
- <if test="dataTime != null and dataTime != ''">
- AND
- used_time > #{dataTime}
- </if>
- )
- OR ( `status` = 1
- <if test="dataTime != null and dataTime != ''">
- AND
- buy_time > #{dataTime}
- </if>
- )
- </select>
- <select id="getQueryNetProfitDay" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- -- 使用递归 CTE 生成 1 到 23 的小时序列
- WITH RECURSIVE hours AS (
- SELECT 0 AS hour_num
- UNION ALL
- SELECT hour_num + 1
- FROM hours
- WHERE hour_num < 23
- )
- SELECT
- concat(h.hour_num,":00") AS hour_num,
- COALESCE(ROUND(SUM(o.final_price) * 0.04, 2), 0) AS profit
- FROM
- hours h
- LEFT JOIN
- life_user_order o
- ON
- h.hour_num = HOUR(o.used_time)
- AND o.`status` = 1
- <if test="dataTime != null and dataTime != ''">
- AND o.used_time >= #{dataTime}
- </if>
- GROUP BY
- h.hour_num
- ORDER BY
- h.hour_num;
- </select>
- <select id="getQueryNetProfitWeek" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- WITH RECURSIVE date_sequence AS (
- SELECT DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) AS hour_num
- UNION ALL
- SELECT hour_num + INTERVAL 1 DAY
- FROM date_sequence
- WHERE hour_num < DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) + INTERVAL 6 DAY
- )
- SELECT
- DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
- COALESCE(ROUND(SUM(luo.final_price) * 0.04, 2), 0) AS profit
- FROM
- date_sequence ds
- LEFT JOIN
- life_user_order luo
- ON
- luo.used_time >= ds.hour_num AND luo.used_time < ds.hour_num + INTERVAL 1 DAY
- AND luo.`status` = 1
- GROUP BY
- ds.hour_num
- ORDER BY
- ds.hour_num;
- </select>
- <select id="getQueryNetProfitMonth" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- WITH RECURSIVE date_sequence AS (
- SELECT DATE_FORMAT(#{dataTime}, '%Y-%m-01') AS hour_num
- UNION ALL
- SELECT DATE_ADD(hour_num, INTERVAL 1 DAY)
- FROM date_sequence
- WHERE DATE_ADD(hour_num, INTERVAL 1 DAY) <= LAST_DAY(#{dataTime})
- )
- SELECT
- DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
- COALESCE(ROUND(SUM(luo.final_price) * 0.04, 2), 0) AS profit
- FROM
- date_sequence ds
- LEFT JOIN
- life_user_order luo
- ON
- luo.used_time >= ds.hour_num AND luo.used_time < DATE_ADD(ds.hour_num, INTERVAL 1 DAY)
- AND luo.`status` = 1
- GROUP BY
- ds.hour_num
- ORDER BY
- ds.hour_num;
- </select>
- <select id="getQueryNetProfitYear" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- WITH RECURSIVE month_sequence AS (
- SELECT 1 AS hour_num
- UNION ALL
- SELECT hour_num + 1
- FROM month_sequence
- WHERE hour_num < 12
- )
- SELECT
- CONCAT(ms.hour_num,'月') AS hour_num,
- COALESCE(ROUND(SUM(luo.final_price) * 0.04, 2), 0) AS profit
- FROM
- month_sequence ms
- LEFT JOIN
- life_user_order luo
- ON
- MONTH(luo.used_time) = ms.hour_num
- AND YEAR(luo.used_time) = YEAR(#{dataTime})
- AND luo.`status` = 1
- GROUP BY
- ms.hour_num
- ORDER BY
- ms.hour_num;
- </select>
- <select id="getTradingVolumeDay" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- WITH RECURSIVE hours AS (
- SELECT 0 AS hour_num
- UNION ALL
- SELECT hour_num + 1
- FROM hours
- WHERE hour_num < 23
- )
- SELECT
- concat(h.hour_num,":00") AS hour_num,
- COALESCE(ROUND(SUM(o.final_price), 2), 0) AS profit
- FROM
- hours h
- LEFT JOIN
- life_user_order o
- ON ( h.hour_num = HOUR( o.used_time ) AND ( o.`status` = 1 AND o.used_time >= #{dataTime} ) )
- OR ( h.hour_num = HOUR( o.buy_time ) AND ( o.`status` = 0 AND o.buy_time >= #{dataTime} ) )
- GROUP BY
- h.hour_num
- ORDER BY
- h.hour_num;
- </select>
- <select id="getTradingVolumeWeek" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- WITH RECURSIVE date_sequence AS (
- SELECT DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) AS hour_num
- UNION ALL
- SELECT hour_num + INTERVAL 1 DAY
- FROM date_sequence
- WHERE hour_num < DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) + INTERVAL 6 DAY
- )
- SELECT
- DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
- COALESCE(ROUND(SUM(luo.final_price), 2), 0) AS profit
- FROM
- date_sequence ds
- LEFT JOIN
- life_user_order luo
- ON
- (luo.used_time >= ds.hour_num
- AND luo.used_time < ds.hour_num + INTERVAL 1 DAY
- AND luo.`status` = 1 )
- OR
- (luo.buy_time >= ds.hour_num
- AND luo.buy_time < ds.hour_num + INTERVAL 1 DAY
- AND luo.`status` = 0 )
- GROUP BY
- ds.hour_num
- ORDER BY
- ds.hour_num;
- </select>
- <select id="getTradingVolumeMonth" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- WITH RECURSIVE date_sequence AS (
- SELECT DATE_FORMAT(#{dataTime}, '%Y-%m-01') AS hour_num
- UNION ALL
- SELECT DATE_ADD(hour_num, INTERVAL 1 DAY)
- FROM date_sequence
- WHERE DATE_ADD(hour_num, INTERVAL 1 DAY) <= LAST_DAY(#{dataTime})
- )
- SELECT
- DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
- COALESCE(ROUND(SUM(luo.final_price), 2), 0) AS profit
- FROM
- date_sequence ds
- LEFT JOIN
- life_user_order luo
- ON
- (luo.used_time >= ds.hour_num
- AND luo.used_time < DATE_ADD( ds.hour_num, INTERVAL 1 DAY )
- AND luo.`status` = 1 )
- OR
- (luo.buy_time >= ds.hour_num
- AND luo.buy_time < DATE_ADD( ds.hour_num, INTERVAL 1 DAY )
- AND luo.`status` = 0 )
- GROUP BY
- ds.hour_num
- ORDER BY
- ds.hour_num;
- </select>
- <select id="getTradingVolumeYear" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- WITH RECURSIVE month_sequence AS (
- SELECT 1 AS hour_num
- UNION ALL
- SELECT hour_num + 1
- FROM month_sequence
- WHERE hour_num < 12
- )
- SELECT
- CONCAT(ms.hour_num,'月') AS hour_num,
- COALESCE(ROUND(SUM(luo.final_price), 2), 0) AS profit
- FROM
- month_sequence ms
- LEFT JOIN
- life_user_order luo
- ON
- (MONTH( luo.used_time ) = ms.hour_num
- AND YEAR( luo.used_time ) = YEAR( #{dataTime} )
- AND luo.`status` = 1 )
- OR
- (MONTH( luo.buy_time ) = ms.hour_num
- AND YEAR( luo.buy_time ) = YEAR( #{dataTime} )
- AND luo.`status` = 0 )
- GROUP BY
- ms.hour_num
- ORDER BY
- ms.hour_num;
- </select>
- <select id="getOrderQuantityDay" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- -- 使用 CTE 生成 0 到 23 的小时序列
- WITH hours AS (
- SELECT 0 AS hour_of_day
- UNION ALL SELECT 1
- UNION ALL SELECT 2
- UNION ALL SELECT 3
- UNION ALL SELECT 4
- UNION ALL SELECT 5
- UNION ALL SELECT 6
- UNION ALL SELECT 7
- UNION ALL SELECT 8
- UNION ALL SELECT 9
- UNION ALL SELECT 10
- UNION ALL SELECT 11
- UNION ALL SELECT 12
- UNION ALL SELECT 13
- UNION ALL SELECT 14
- UNION ALL SELECT 15
- UNION ALL SELECT 16
- UNION ALL SELECT 17
- UNION ALL SELECT 18
- UNION ALL SELECT 19
- UNION ALL SELECT 20
- UNION ALL SELECT 21
- UNION ALL SELECT 22
- UNION ALL SELECT 23
- )
- -- 主查询,左连接小时序列和原查询结果
- SELECT
- concat(h.hour_of_day,":00") AS hour_num,
- COALESCE(orders.order_count, 0) AS profit
- FROM
- hours h
- LEFT JOIN (
- SELECT
- HOUR(CASE WHEN `status` = 1 THEN used_time ELSE buy_time END) AS hour_of_day,
- COUNT(*) AS order_count
- FROM
- life_user_order
- WHERE
- (
- `status` = 1
- AND used_time > #{dataTime}
- )
- OR (
- `status` = 0
- AND buy_time > #{dataTime}
- )
- GROUP BY
- HOUR(CASE WHEN `status` = 1 THEN used_time ELSE buy_time END)
- ) orders ON h.hour_of_day = orders.hour_of_day
- ORDER BY
- h.hour_of_day;
- </select>
- <select id="getOrderQuantityWeek" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- WITH RECURSIVE date_sequence AS (
- SELECT DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) AS hour_num
- UNION ALL
- SELECT hour_num + INTERVAL 1 DAY
- FROM date_sequence
- WHERE hour_num < DATE_SUB(#{dataTime}, INTERVAL WEEKDAY(#{dataTime}) DAY) + INTERVAL 6 DAY
- )
- SELECT
- DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
- COALESCE(count(luo.id), 0) AS profit
- FROM
- date_sequence ds
- LEFT JOIN
- life_user_order luo
- ON
- (luo.used_time >= ds.hour_num AND luo.used_time < ds.hour_num + INTERVAL 1 DAY
- AND luo.`status` = 1) or
- (luo.buy_time >= ds.hour_num AND luo.buy_time < ds.hour_num + INTERVAL 1 DAY
- AND luo.`status` = 0)
- GROUP BY
- ds.hour_num
- ORDER BY
- ds.hour_num;
- </select>
- <select id="getOrderQuantityMonth" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- WITH RECURSIVE date_sequence AS (
- SELECT DATE_FORMAT(#{dataTime}, '%Y-%m-01') AS hour_num
- UNION ALL
- SELECT DATE_ADD(hour_num, INTERVAL 1 DAY)
- FROM date_sequence
- WHERE DATE_ADD(hour_num, INTERVAL 1 DAY) <= LAST_DAY(#{dataTime})
- )
- SELECT
- DATE_FORMAT(ds.hour_num, '%c-%d') AS hour_num,
- COALESCE(count(luo.id), 0) AS profit
- FROM
- date_sequence ds
- LEFT JOIN
- life_user_order luo
- ON
- (luo.used_time >= ds.hour_num AND luo.used_time < ds.hour_num + INTERVAL 1 DAY
- AND luo.`status` = 1) or
- (luo.buy_time >= ds.hour_num AND luo.buy_time < ds.hour_num + INTERVAL 1 DAY
- AND luo.`status` = 0)
- GROUP BY
- ds.hour_num
- ORDER BY
- ds.hour_num;
- </select>
- <select id="getOrderQuantityYear" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- WITH months AS (
- SELECT
- CONCAT(YEAR(#{dataTime}), '-', LPAD(seq, 2, '0')) AS month
- FROM (
- SELECT 1 AS seq UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL
- SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL
- SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL
- SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12
- ) seq
- )
- SELECT
- CONCAT(MONTH(STR_TO_DATE(m.MONTH, '%Y-%m')),'月') AS hour_num,
- COALESCE(orders.order_count, 0) AS profit
- FROM
- months m
- LEFT JOIN (
- SELECT
- DATE_FORMAT(CASE WHEN `status` = 1 THEN used_time ELSE buy_time END, '%Y-%m') AS month,
- COUNT(*) AS order_count
- FROM
- life_user_order
- WHERE
- (
- `status` = 1
- AND used_time > #{dataTime}
- )
- OR (
- `status` = 0
- AND buy_time > #{dataTime}
- )
- GROUP BY
- DATE_FORMAT(CASE WHEN `status` = 1 THEN used_time ELSE buy_time END, '%Y-%m')
- ) orders ON m.month = orders.month
- ORDER BY
- m.month;
- </select>
- <select id="getSalesVolume" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- <!-- 初始化用户变量 -->
- SELECT
- profit,
- store.`store_name`
- FROM
- (
- SELECT
- count(id) AS profit,
- store_id
- FROM
- life_user_order
- WHERE
- ( `status` = 1 AND used_time >= #{startTime} AND used_time < #{endTime})
- OR ( `status` = 0 AND buy_time >= #{startTime} AND buy_time < #{endTime})
- GROUP BY
- store_id
- LIMIT 10
- ) statistic
- LEFT JOIN store_info store ON store.id = statistic.store_id
- ORDER BY
- profit DESC
- </select>
- <select id="getStorePlatformProfitDetails" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- store_id,
- store.store_name,
- ROUND(SUM(final_price), 2 ) AS operation_revenue,
- ROUND(SUM(final_price) - ROUND(SUM(final_price) * (IFNULL(store.commission_rate, 3)/100),2), 2) AS store_profit,
- ROUND(SUM(final_price) * (IFNULL(store.commission_rate, 3)/100),2) AS platform_profit
- FROM
- life_user_order `order`
- LEFT JOIN store_info store ON store.id = `order`.store_id
- WHERE
- `status` = 2
- <if test="startTime != null and startTime != ''" >
- AND used_time > #{startTime}
- </if>
- <if test="endTime != null and endTime != ''" >
- AND used_time < #{endTime}
- </if>
- <if test="storeId != null and storeId != ''" >
- AND store_id like concat('%',#{storeId},'%')
- </if>
- <if test="storeName != null and storeName != ''" >
- AND store_name like concat('%',#{storeName},'%')
- </if>
- GROUP BY
- store.id
- ORDER BY
- `order`.created_time DESC
- </select>
- <select id="getRefundOrderQuantity" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- COUNT( 1 ) AS `count`
- FROM
- life_user_order
- WHERE
- `status` = 5
- <if test="dataTime != null and dataTime != ''">
- AND refund_time > #{dataTime}
- </if>
- </select>
- <select id="getTotalOrderVolume" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- COUNT( 1 ) AS `count`
- FROM
- life_user_order `order`
- WHERE
- delete_flag = 0
- <if test="dataTime != null and dataTime != ''">
- AND buy_time > #{dataTime}
- </if>
- </select>
- <select id="getStorePlatformOrderVolume" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- with total_coupon as(
- select id coupon_id,2 coupon_type,lgbm.group_name coupon_name, SUBSTRING_INDEX(image_id, ',', 1) AS image_id
- from life_group_buy_main lgbm where lgbm.delete_flag = 0
- union all
- select id coupon_id,1 coupon_type,lc.name coupon_name, SUBSTRING_INDEX(image_path, ',', 1) AS image_id
- from life_coupon lc where lc.delete_flag = 0
- )
- SELECT
- order_no,
- `order`.id as order_id,
- `order`.created_time AS order_time,
- `order`.finish_time AS finish_time,
- `order`.cancel_time AS cancel_time,
- `order`.pay_time AS pay_time,
- `order`.buy_time AS buy_time_str,
- ROUND(`order`.final_price, 2) AS final_price,
- CASE
- `order`.`status`
- WHEN 0 THEN '待支付'
- WHEN 1 THEN '已支付/待使用'
- WHEN 2 THEN '已核销'
- WHEN 3 THEN '已过期'
- WHEN 4 THEN '已取消'
- WHEN 5 THEN '已退款'
- WHEN 6 THEN '退款失败'
- WHEN 7 THEN '已完成'
- END AS status_name,
- simg.img_url,
- tc.*,
- store.store_name
- FROM
- life_user_order `order`
- left join store_info store on `order`.store_id = store.id
- left join order_coupon_middle ocm on ocm.order_id = `order`.id and ocm.delete_flag = 0
- inner join total_coupon tc on tc.coupon_id = ocm.coupon_id and tc.coupon_type = `order`.coupon_type
- left join store_img simg on simg.id = tc.image_id and simg.delete_flag = 0
- <where>
- 1 = 1
- <if test="orderType != null and orderType != ''">
- AND `order`.`status` = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- AND buy_time > #{startTime}
- </if>
- <if test="orderId != null and orderId != ''">
- AND `order`.`order_no` like concat('%',#{orderId},'%')
- </if>
- <if test="couponType != null and couponType != ''">
- AND tc.coupon_type = #{couponType}
- </if>
- <if test="couponName != null and couponName != ''">
- AND tc.coupon_name like concat('%',#{couponName},'%')
- </if>
- <if test="storeName != null and storeName != ''">
- AND store.store_name like concat('%',#{storeName},'%')
- </if>
- </where>
- ORDER BY
- `order`.created_time DESC
- </select>
- <select id="getRefundAmount" resultType="shop.alien.entity.store.vo.ManagementInfoVo">
- SELECT
- IFNULL(ROUND( SUM( final_price ), 2 ),0) AS profit
- FROM
- life_user_order `order`
- WHERE
- `status` = 4
- <if test="dataTime != null and dataTime != ''" >
- AND `order`.refund_time > #{dataTime}
- </if>
- </select>
- </mapper>
|