AppUserMapper.xml 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.ytpm.question.dao.AppUserMapper">
  4. <insert id="addOne" parameterType="com.ytpm.app.model.YtDyzUser">
  5. insert into yt_dyz_user
  6. (user_id,
  7. nick_name,
  8. head_img,
  9. registry_time,
  10. last_login_time,
  11. last_login_ip,
  12. login_days,
  13. total_video,
  14. total_income,
  15. nearly_income,
  16. red_packet_balance,
  17. red_packet_amount,
  18. points_balance,
  19. points_total,
  20. withdraw_total,
  21. sign_days,
  22. user_status,
  23. risk_reason,
  24. wx_open_id,
  25. ditch_id,
  26. platform_id,
  27. app_id,
  28. power,
  29. phone,
  30. phone_json,
  31. device_id)
  32. values (#{userId},
  33. #{nickName},
  34. #{headImg},
  35. #{registryTime},
  36. #{lastLoginTime},
  37. #{lastLoginIp},
  38. #{loginDays},
  39. #{totalVideo},
  40. #{totalIncome},
  41. #{nearlyIncome},
  42. #{redPacketBalance},
  43. #{redPacketAmount},
  44. #{pointsBalance},
  45. #{pointsTotal},
  46. #{withdrawTotal},
  47. #{signDays},
  48. #{userStatus},
  49. #{riskReason},
  50. #{wxOpenId},
  51. #{ditchId},
  52. #{platformId},
  53. #{appId},
  54. #{power},
  55. #{phone},
  56. #{phoneJson},
  57. #{deviceId})
  58. </insert>
  59. <insert id="addPowerRecord">
  60. insert into yt_dyz_power_record
  61. (
  62. record_id, user_id, type, remark, add_time
  63. )
  64. values
  65. (
  66. #{recordId},#{userId},#{type},#{remark},#{addTime}
  67. )
  68. </insert>
  69. <insert id="saveAppConfig">
  70. insert into yt_app_default_config
  71. (
  72. config_name,
  73. open_id,
  74. secret,
  75. app_id,
  76. app_key,
  77. app_type,
  78. ditch_id
  79. )
  80. values
  81. (
  82. #{configName},
  83. #{openId},
  84. #{secret},
  85. #{appId},
  86. #{appKey},
  87. #{appType},
  88. #{ditchId}
  89. )
  90. </insert>
  91. <update id="updateAppConfig">
  92. update yt_app_default_config
  93. <set>
  94. <if test="canSimulator != null">
  95. can_simulator = #{canSimulator},
  96. </if>
  97. <if test="configName != null">
  98. config_name = #{configName},
  99. </if>
  100. <if test="openId != null">
  101. open_id = #{openId},
  102. </if>
  103. <if test="secret != null">
  104. secret = #{secret},
  105. </if>
  106. <if test="appKey != null">
  107. app_key = #{appKey},
  108. </if>
  109. <if test="appType != null">
  110. app_type = #{appType},
  111. </if>
  112. <if test="takuAppId != null">
  113. taku_app_id = #{takuAppId},
  114. </if>
  115. <if test="takuKey != null">
  116. taku_key = #{takuKey},
  117. </if>
  118. <if test="takuBannerPid != null">
  119. taku_banner_pid = #{takuBannerPid},
  120. </if>
  121. <if test="takuNativePid != null">
  122. taku_native_pid = #{takuNativePid},
  123. </if>
  124. <if test="takuRewardPid != null">
  125. taku_reward_pid = #{takuRewardPid},
  126. </if>
  127. <if test="takuInterstitialPid != null">
  128. taku_interstitial_pid = #{takuInterstitialPid},
  129. </if>
  130. <if test="canUseRoot != null">
  131. can_use_root = #{canUseRoot},
  132. </if>
  133. <if test="canUseAdb != null">
  134. can_use_adb = #{canUseAdb},
  135. </if>
  136. <if test="canUseFloat != null">
  137. can_use_float = #{canUseFloat},
  138. </if>
  139. <if test="canAccumulation != null">
  140. can_accumulation = #{canAccumulation},
  141. </if>
  142. <if test="ditchId != null">
  143. ditch_id = #{ditchId},
  144. </if>
  145. <if test="powerWaitTime != null">
  146. power_wait_time = #{powerWaitTime},
  147. </if>
  148. <if test="interstitialIntervalTime != null">
  149. interstitial_interval_time = #{interstitialIntervalTime},
  150. </if>
  151. <if test="flowIntervalTime != null">
  152. flow_interval_time = #{flowIntervalTime},
  153. </if>
  154. <if test="taskLimitTip != null">
  155. task_limit_tip = #{taskLimitTip},
  156. </if>
  157. <if test="lowValueTip != null">
  158. low_value_tip = #{lowValueTip},
  159. </if>
  160. <if test="brushTip != null">
  161. brush_tip = #{brushTip},
  162. </if>
  163. <if test="startWaitTime != null">
  164. start_wait_time = #{startWaitTime},
  165. </if>
  166. <if test="canCacheVideo != null">
  167. can_cache_video = #{canCacheVideo},
  168. </if>
  169. <if test="canAllowAutoRefresh != null">
  170. can_allow_auto_refresh = #{canAllowAutoRefresh}
  171. </if>
  172. </set>
  173. where app_id = #{appId}
  174. </update>
  175. <update id="addOnePower">
  176. update yt_dyz_user set power = power+1 where user_id = #{userId}
  177. </update>
  178. <update id="subOnePower">
  179. update yt_dyz_user set power = power-1 where user_id = #{userId}
  180. </update>
  181. <update id="updateUser" parameterType="com.ytpm.app.model.YtDyzUser">
  182. update yt_dyz_user
  183. <set>
  184. <if test="nickName != null">
  185. nick_name = #{nickName},
  186. </if>
  187. <if test="phone != null">
  188. phone = #{phone},
  189. </if>
  190. <if test="deviceId != null">
  191. device_id = #{deviceId},
  192. </if>
  193. <if test="headImg != null">
  194. head_img = #{headImg},
  195. </if>
  196. <if test="power != null">
  197. power = #{power},
  198. </if>
  199. <if test="lastLoginTime != null">
  200. last_login_time = #{lastLoginTime},
  201. </if>
  202. <if test="lastLoginIp != null">
  203. last_login_ip = #{lastLoginIp},
  204. </if>
  205. <if test="loginDays != null">
  206. login_days = #{loginDays},
  207. </if>
  208. <if test="totalVideo != null">
  209. total_video = #{totalVideo},
  210. </if>
  211. <if test="totalIncome != null">
  212. total_income = #{totalIncome},
  213. </if>
  214. <if test="nearlyIncome != null">
  215. nearly_income = #{nearlyIncome},
  216. </if>
  217. <if test="redPacketBalance != null">
  218. red_packet_balance = #{redPacketBalance},
  219. </if>
  220. <if test="redPacketAmount != null">
  221. red_packet_amount = #{redPacketAmount},
  222. </if>
  223. <if test="pointsBalance != null">
  224. points_balance = #{pointsBalance},
  225. </if>
  226. <if test="pointsTotal != null">
  227. points_total = #{pointsTotal},
  228. </if>
  229. <if test="withdrawTotal != null">
  230. withdraw_total = #{withdrawTotal},
  231. </if>
  232. <if test="signDays != null">
  233. sign_days = #{signDays},
  234. </if>
  235. <if test="userStatus != null">
  236. user_status = #{userStatus},
  237. </if>
  238. <if test="riskReason != null">
  239. risk_reason = #{riskReason},
  240. </if>
  241. <if test="wxOpenId != null">
  242. wx_open_id = #{wxOpenId},
  243. </if>
  244. <if test="phoneJson != null">
  245. phone_json = #{phoneJson},
  246. </if>
  247. <if test="platformId != null">
  248. platform_id = #{platformId}
  249. </if>
  250. </set>
  251. where user_id = #{userId}
  252. </update>
  253. <delete id="delByAppId">
  254. delete from yt_app_default_config where app_id = #{appId}
  255. </delete>
  256. <select id="getYtAppUser" resultType="com.ytpm.app.model.YtDyzUser">
  257. select
  258. user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power,
  259. registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, nearly_income,
  260. red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total,
  261. sign_days, user_status, risk_reason, wx_open_id, platform_id
  262. from yt_dyz_user
  263. where wx_open_id = #{openid}
  264. and ditch_id = #{ditchId}
  265. </select>
  266. <select id="queryAll" resultType="com.ytpm.app.view.YtAppUserListView">
  267. select
  268. user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power,
  269. registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, nearly_income,
  270. red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total,
  271. sign_days, user_status, risk_reason, wx_open_id, platform_id
  272. from yt_dyz_user
  273. where 1 = 1
  274. <if test="userId != null and userId !=''">
  275. and user_id = #{userId}
  276. </if>
  277. <if test="nickName != null and nickName !=''">
  278. and nick_name like concat('%',#{nickName},'%')
  279. </if>
  280. <if test="ditchId != null">
  281. and ditch_id = #{ditchId}
  282. </if>
  283. <if test="userStatus != null">
  284. and user_status = #{userStatus}
  285. </if>
  286. <if test="registryTimeBegin != null">
  287. and DATE_FORMAT(registry_time, '%Y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{registryTimeBegin}, '%Y-%m-%d')
  288. </if>
  289. <if test="registryTimeEnd != null">
  290. and DATE_FORMAT(registry_time, '%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{registryTimeEnd}, '%Y-%m-%d')
  291. </if>
  292. <if test="lastLoginTimeBegin != null">
  293. and DATE_FORMAT(last_login_time, '%Y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{lastLoginTimeBegin}, '%Y-%m-%d')
  294. </if>
  295. <if test="lastLoginTimeEnd != null">
  296. and DATE_FORMAT(last_login_time, '%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{lastLoginTimeEnd}, '%Y-%m-%d')
  297. </if>
  298. <if test="appIds != null and appIds != ''">
  299. and app_id in
  300. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  301. #{item}
  302. </foreach>
  303. </if>
  304. order by user_id desc
  305. </select>
  306. <select id="selectPrimaryKey" resultType="com.ytpm.app.model.YtDyzUser">
  307. select
  308. user_id,app_id,phone,device_id, ditch_id, head_img, nick_name, registry_time, last_login_time, last_login_ip,
  309. login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total,
  310. withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id, power, nearly_income
  311. from yt_dyz_user
  312. where user_id = #{userId}
  313. </select>
  314. <resultMap id="UserMap" type="com.ytpm.app.model.YtDyzUser">
  315. <id column="user_id" property="userId" />
  316. <result column="head_img" property="headImg" />
  317. <result column="nick_name" property="nickName" />
  318. <result column="phone" property="phone" />
  319. <result column="device_id" property="deviceId" />
  320. <result column="registry_time" property="registryTime" />
  321. <result column="last_login_time" property="lastLoginTime" />
  322. <result column="last_login_ip" property="lastLoginIp" />
  323. <result column="login_days" property="loginDays" />
  324. <result column="total_video" property="totalVideo" />
  325. <result column="total_income" property="totalIncome" />
  326. <result column="nearly_income" property="nearlyIncome" />
  327. <result column="red_packet_balance" property="redPacketBalance" />
  328. <result column="red_packet_amount" property="redPacketAmount" />
  329. <result column="points_balance" property="pointsBalance" />
  330. <result column="points_total" property="pointsTotal" />
  331. <result column="withdraw_total" property="withdrawTotal" />
  332. <result column="sign_days" property="signDays" />
  333. <result column="user_status" property="userStatus" />
  334. <result column="risk_reason" property="riskReason" />
  335. <result column="wx_open_id" property="wxOpenId" />
  336. <result column="ditch_id" property="ditchId" />
  337. <result column="app_id" property="appId" />
  338. <result column="platform_id" property="platformId" />
  339. <result column="power" property="power" />
  340. <collection property="loginRecordList" ofType="com.ytpm.app.model.YtDyzLoginRecord">
  341. <result column="record_id" property="recordId" />
  342. <result column="user_id" property="userId" />
  343. <result column="login_time" property="loginTime" />
  344. <result column="device_brand" property="deviceBrand" />
  345. <result column="device_model" property="deviceModel" />
  346. <result column="login_ip" property="loginIp" />
  347. <result column="operator" property="operator" />
  348. <result column="ip_addr" property="ipAddr" />
  349. </collection>
  350. </resultMap>
  351. <select id="getUserList" resultMap="UserMap">
  352. select
  353. du.user_id,
  354. du.head_img,
  355. du.nick_name,
  356. du.phone,
  357. du.device_id,
  358. du.registry_time,
  359. du.last_login_time,
  360. du.last_login_ip,
  361. du.login_days,
  362. du.total_video,
  363. du.total_income,
  364. du.nearly_income,
  365. du.red_packet_balance,
  366. du.red_packet_amount,
  367. du.points_balance,
  368. du.points_total,
  369. du.withdraw_total,
  370. du.sign_days,
  371. du.user_status,
  372. du.risk_reason,
  373. du.wx_open_id,
  374. du.ditch_id,
  375. du.app_id,
  376. du.platform_id,
  377. du.power,
  378. lr.record_id,
  379. lr.login_time,
  380. lr.device_brand,
  381. lr. device_model,
  382. lr.login_ip,
  383. lr.operator,
  384. lr.ip_addr
  385. from yt_dyz_user du
  386. left join yt_dyz_login_record lr on du.user_id = lr.user_id
  387. <where>
  388. <if test="userIds != null and userIds != ''">
  389. and du.user_id in
  390. <foreach collection="userIds.split(',')" item="item" separator="," open="(" close=")">
  391. #{item}
  392. </foreach>
  393. </if>
  394. <if test="loginTimeBegin != null">
  395. and du.last_login_time <![CDATA[>=]]> #{loginTimeBegin}
  396. </if>
  397. <if test="loginTimeEnd != null">
  398. and du.last_login_time <![CDATA[<=]]> #{loginTimeEnd}
  399. </if>
  400. </where>
  401. group by du.user_id
  402. </select>
  403. <select id="queryAllByTime" resultType="com.ytpm.app.model.YtDyzUser">
  404. SELECT
  405. user_id,app_id,phone,device_id, nick_name, head_img, power,
  406. registry_time,last_login_time, last_login_ip, login_days, total_video, total_income, nearly_income,
  407. red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total,
  408. sign_days, user_status, risk_reason, wx_open_id, platform_id
  409. FROM yt_dyz_user
  410. <where>
  411. <if test="startTime != null">
  412. AND registry_time >= #{startTime}
  413. </if>
  414. <if test="endTime != null">
  415. AND registry_time &lt;= #{endTime}
  416. </if>
  417. <choose>
  418. <when test="appIdList == null or appIdList.isEmpty()">
  419. AND 1 = 0
  420. </when>
  421. <otherwise>
  422. AND app_id IN
  423. <foreach collection="appIdList" item="item"
  424. open="(" close=")" separator=",">
  425. #{item}
  426. </foreach>
  427. </otherwise>
  428. </choose>
  429. </where>
  430. ORDER BY registry_time DESC
  431. </select>
  432. <select id="countUsersByHour" resultType="com.ytpm.app.view.HourCountView">
  433. SELECT HOUR(registry_time) AS hour, COUNT(*) AS count
  434. FROM yt_dyz_user
  435. WHERE registry_time BETWEEN #{startTime} AND #{endTime}
  436. <choose>
  437. <when test="appIdList == null or appIdList.isEmpty()">
  438. AND 1 = 0
  439. </when>
  440. <otherwise>
  441. AND app_id IN
  442. <foreach collection="appIdList" item="item"
  443. open="(" close=")" separator=",">
  444. #{item}
  445. </foreach>
  446. </otherwise>
  447. </choose>
  448. GROUP BY HOUR(registry_time)
  449. </select>
  450. <select id="queryTodayBanned" resultType="com.ytpm.app.model.YtDyzUser">
  451. select user_id from yt_dyz_user
  452. where registry_time BETWEEN #{startTime} AND #{endTime}
  453. and user_id in
  454. <foreach collection="userIdList" item="item"
  455. open="(" close=")" separator=",">
  456. #{item}
  457. </foreach>
  458. </select>
  459. <select id="getDefaultConfig" resultType="com.ytpm.app.view.WxDefaultConfig">
  460. select
  461. config_id, config_name, open_id as app_id, secret, app_id as platformAppId, app_key as platformAppSecret,
  462. app_type,user_path, login_path,ad_path,answer_path,power_path,can_simulator,
  463. taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid,
  464. can_use_root, can_use_adb, can_use_float, can_accumulation,
  465. ditch_id, power_wait_time, interstitial_interval_time,
  466. low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,
  467. can_cache_video,can_allow_auto_refresh
  468. from yt_app_default_config
  469. where app_type = #{appType}
  470. </select>
  471. <select id="getDefaultConfigByAppId" resultType="com.ytpm.app.view.WxDefaultConfig">
  472. select
  473. config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
  474. answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
  475. taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
  476. ditch_id, power_wait_time, interstitial_interval_time,
  477. low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,
  478. can_cache_video,can_allow_auto_refresh
  479. from yt_app_default_config
  480. where app_id = #{appId}
  481. </select>
  482. <select id="getSecretByAppId" resultType="java.lang.String">
  483. select
  484. config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
  485. answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
  486. taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
  487. ditch_id, power_wait_time, interstitial_interval_time,
  488. low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,
  489. can_cache_video,can_allow_auto_refresh
  490. from yt_app_default_config
  491. where app_id = #{appId}
  492. </select>
  493. <select id="queryByOpenid" resultType="com.ytpm.app.model.YtDyzUser">
  494. select
  495. user_id,phone,device_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days,
  496. total_video, total_income, nearly_income, red_packet_balance, red_packet_amount, points_balance, points_total,
  497. withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power
  498. from yt_dyz_user
  499. where wx_open_id = #{openid}
  500. </select>
  501. <select id="getByDeviceId" resultType="java.lang.String">
  502. select platform_id
  503. from yt_dyz_user
  504. where device_id = #{deviceId} and wx_open_id = #{openid}
  505. limit 1
  506. </select>
  507. <select id="getConfigByIds" resultType="com.ytpm.app.view.WxDefaultConfig">
  508. select
  509. config_id, config_name, open_id, secret, app_id, app_key, app_type, user_path, login_path, ad_path,
  510. answer_path, power_path,taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid,
  511. taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,can_simulator,
  512. ditch_id, power_wait_time, interstitial_interval_time,
  513. low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
  514. from yt_app_default_config
  515. where app_id in
  516. <foreach collection="appIds.split(',')" item="item" separator="," open="(" close=")">
  517. #{item}
  518. </foreach>
  519. </select>
  520. <select id="getAdCount" resultType="java.lang.Integer">
  521. select sum(total_video)
  522. from yt_dyz_user
  523. where app_id in
  524. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  525. #{item}
  526. </foreach>
  527. </select>
  528. <select id="getRevenueCount" resultType="java.math.BigDecimal">
  529. select sum(total_income)
  530. from yt_dyz_user
  531. where app_id in
  532. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  533. #{item}
  534. </foreach>
  535. </select>
  536. <select id="getAppRanking" resultType="com.ytpm.middle.view.AppRankingListVO">
  537. SELECT
  538. u.app_id,
  539. sum( ar.revenue ) totalRevenue
  540. FROM
  541. yt_dyz_ad_record ar
  542. JOIN yt_dyz_user u ON ar.user_id = u.user_id
  543. <where>
  544. <if test="sortBy != null">
  545. <choose>
  546. <when test="sortBy == 1">
  547. DATE_FORMAT( ar.finish_time, '%Y-%m-%d' ) = CURRENT_DATE()
  548. </when>
  549. <when test=" sortBy == 2">
  550. YEARWEEK( ar.finish_time, 1 ) = YEARWEEK(now(),1)
  551. </when>
  552. <otherwise>
  553. DATE_FORMAT( ar.finish_time, '%Y-%m' ) = DATE_FORMAT(NOW(), '%Y-%m')
  554. </otherwise>
  555. </choose>
  556. </if>
  557. </where>
  558. GROUP BY
  559. u.app_id
  560. ORDER BY
  561. sum( ar.revenue ) DESC
  562. LIMIT #{limit}
  563. </select>
  564. <select id="getUserRanking" resultType="com.ytpm.middle.view.UserRankingListVO">
  565. SELECT
  566. u.user_id,
  567. u.nick_name,
  568. u.head_img,
  569. u.total_video,
  570. sum( ar.revenue ) totalIncome
  571. FROM
  572. yt_dyz_ad_record ar
  573. JOIN yt_dyz_user u ON ar.user_id = u.user_id
  574. <where>
  575. <if test="sortBy != null">
  576. <choose>
  577. <when test="sortBy == 1">
  578. DATE_FORMAT( ar.finish_time, '%Y-%m-%d' ) = CURRENT_DATE()
  579. </when>
  580. <when test=" sortBy == 2">
  581. YEARWEEK( ar.finish_time, 1 ) = YEARWEEK(now(),1)
  582. </when>
  583. <otherwise>
  584. DATE_FORMAT( ar.finish_time, '%Y-%m' ) = DATE_FORMAT(NOW(), '%Y-%m')
  585. </otherwise>
  586. </choose>
  587. </if>
  588. </where>
  589. GROUP BY ar.user_id
  590. ORDER BY
  591. sum( ar.revenue ) DESC
  592. limit #{limit}
  593. </select>
  594. <select id="countUserByAppIds" resultType="java.lang.Integer">
  595. select
  596. count(user_id)
  597. from yt_dyz_user
  598. where app_id in
  599. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  600. #{item}
  601. </foreach>
  602. </select>
  603. <select id="countRevenueByAppIds" resultType="java.math.BigDecimal">
  604. select
  605. sum(total_income)
  606. from yt_dyz_user
  607. where app_id in
  608. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  609. #{item}
  610. </foreach>
  611. </select>
  612. <select id="countBannedByAppIds" resultType="java.lang.Integer">
  613. select
  614. count(user_id)
  615. from yt_dyz_user
  616. where user_status > 1 and app_id in
  617. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  618. #{item}
  619. </foreach>
  620. </select>
  621. <select id="countRegistryUser" resultType="java.lang.Integer">
  622. select
  623. count(user_id)
  624. from yt_dyz_user
  625. where app_id = #{appId}
  626. <if test="type != null and type ==1">
  627. and DATE(registry_time) = DATE(now())
  628. </if>
  629. <if test="type != null and type ==2">
  630. and DATE(registry_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  631. </if>
  632. <if test="type != null and type ==3">
  633. and DATE_FORMAT(registry_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
  634. </if>
  635. </select>
  636. <select id="countLoginUser" resultType="java.lang.Integer">
  637. select
  638. count(user_id)
  639. from yt_dyz_user
  640. where app_id = #{appId}
  641. <if test="type != null and type ==1">
  642. and DATE(last_login_time) = DATE(now())
  643. </if>
  644. <if test="type != null and type ==2">
  645. and DATE(last_login_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  646. </if>
  647. <if test="type != null and type ==3">
  648. and DATE_FORMAT(last_login_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
  649. </if>
  650. </select>
  651. <select id="countRegistryHour" resultType="com.ytpm.middle.view.AppUserHourVO">
  652. select
  653. DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
  654. count(user_id) `count`
  655. from yt_dyz_user
  656. where app_id = #{appId}
  657. <if test="type != null and type ==1">
  658. and DATE(registry_time) = DATE(now())
  659. </if>
  660. <if test="type != null and type ==2">
  661. and DATE(registry_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  662. </if>
  663. <if test="type != null and type ==3">
  664. and DATE_FORMAT(registry_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
  665. </if>
  666. group by `time`
  667. </select>
  668. <select id="countLoginHour" resultType="com.ytpm.middle.view.AppUserHourVO">
  669. select
  670. DATE_FORMAT(last_login_time,'%Y-%m-%d %H:00:00') as `time`,
  671. count(user_id) `count`
  672. from yt_dyz_user
  673. where app_id = #{appId}
  674. <if test="type != null and type ==1">
  675. and DATE(last_login_time) = DATE(now())
  676. </if>
  677. <if test="type != null and type ==2">
  678. and DATE(last_login_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  679. </if>
  680. <if test="type != null and type ==3">
  681. and DATE_FORMAT(last_login_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
  682. </if>
  683. group by `time`
  684. </select>
  685. <select id="queryByUserIds" resultType="com.ytpm.app.model.YtDyzUser">
  686. select
  687. user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
  688. from yt_dyz_user
  689. where user_id in
  690. <foreach collection="userIds.split(',')" separator="," item="item" open="(" close=")">
  691. #{item}
  692. </foreach>
  693. </select>
  694. <resultMap id="UserAdMap" type="com.ytpm.agent.view.AgentAuditCheckVO">
  695. <id column="user_id" property="userId" />
  696. <result column="app_id" property="appId" />
  697. <result column="nick_name" property="nickName" />
  698. <collection property="adRecordList" ofType="com.ytpm.app.model.YtDyzAdRecord">
  699. <result column="record_id" property="recordId" />
  700. <result column="placement_id" property="placementId" />
  701. <result column="ad_source_id" property="adSourceId" />
  702. <result column="ad_source_type" property="adSourceType" />
  703. <result column="ad_source_index" property="adSourceIndex" />
  704. <result column="revenue" property="revenue" />
  705. <result column="ecpm" property="ecpm" />
  706. <result column="network_form_id" property="networkFormId" />
  707. <result column="network_name" property="networkName" />
  708. <result column="network_placement_id" property="networkPlacementId" />
  709. <result column="finish_time" property="finishTime" />
  710. <result column="begin_time" property="beginTime" />
  711. </collection>
  712. </resultMap>
  713. <select id="queryTodayUserAd" resultMap="UserAdMap">
  714. select
  715. u.user_id,
  716. u.app_id,
  717. u.nick_name,
  718. ar.record_id,
  719. ar.placement_id,
  720. ar.ad_source_id,
  721. ar.ad_source_type,
  722. ar.ad_source_index,
  723. ar.revenue,
  724. ar.ecpm,
  725. ar.network_form_id,
  726. ar.network_name,
  727. ar.network_placement_id,
  728. ar.finish_time,
  729. ar.begin_time
  730. from yt_dyz_ad_record ar
  731. join yt_dyz_user u on ar.user_id = u.user_id
  732. where ar.ad_source_type = #{adSourceType} and ar.app_id = #{appId} and ar.user_id in
  733. <foreach collection="userIds.split(',')" separator="," item="item" open="(" close=")">
  734. #{item}
  735. </foreach>
  736. and DATE_FORMAT(ar.finish_time, '%Y-%m-%d') = current_date()
  737. </select>
  738. <select id="getMonthRegistryUser" resultType="com.ytpm.app.model.YtDyzUser">
  739. select
  740. user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days,
  741. total_video, total_income, nearly_income, red_packet_balance, red_packet_amount, points_balance, points_total,
  742. withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id,
  743. power, phone, device_id
  744. from yt_dyz_user
  745. where app_id in
  746. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  747. #{item}
  748. </foreach>
  749. <if test="type != null and type == 1">
  750. and DATE_FORMAT(registry_time, '%Y-%m') = DATE_FORMAT(now(),'%Y-%m')
  751. </if>
  752. <if test="type != null and type == 2">
  753. and DATE_FORMAT(last_login_time, '%Y-%m') = DATE_FORMAT(now(),'%Y-%m')
  754. </if>
  755. </select>
  756. <select id="countDitch" resultType="java.lang.Integer">
  757. select
  758. count( distinct ditch_id)
  759. from yt_dyz_user
  760. where device_id = #{deviceId}
  761. and registry_time > (NOW() - INTERVAL #{hours} HOUR )
  762. </select>
  763. <select id="countLoginDitch" resultType="java.lang.Integer">
  764. select
  765. count( distinct ditch_id)
  766. from yt_dyz_user
  767. where device_id = #{deviceId}
  768. and last_login_time > (NOW() - INTERVAL #{hours} HOUR )
  769. </select>
  770. <select id="getLastRegistryUser" resultType="com.ytpm.app.model.YtDyzUser">
  771. select
  772. user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days,
  773. total_video, total_income, nearly_income, red_packet_balance, red_packet_amount, points_balance, points_total,
  774. withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id,
  775. power, phone, device_id, phone_json
  776. from yt_dyz_user
  777. where device_id = #{deviceId}
  778. </select>
  779. <select id="getByDeviceAndDitch" resultType="com.ytpm.app.model.YtDyzUser">
  780. select
  781. user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days,
  782. total_video, total_income, nearly_income, red_packet_balance, red_packet_amount, points_balance, points_total,
  783. withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id,
  784. power, phone, device_id, phone_json
  785. from yt_dyz_user
  786. where device_id = #{deviceId} and ditch_id = #{ditchId} limit 1
  787. </select>
  788. <select id="getPlatformByDeviceId" resultType="java.lang.String">
  789. select platform_id
  790. from yt_dyz_user
  791. where device_id = #{deviceId}
  792. limit 1
  793. </select>
  794. <update id="unlockUser">
  795. update yt_dyz_user
  796. set user_status = 1
  797. where user_status > 1
  798. and user_id in
  799. <foreach collection="userIds.split(',')" item="item" separator="," open="(" close=")">
  800. #{item}
  801. </foreach>
  802. </update>
  803. <update id="updateTotal">
  804. UPDATE yt_dyz_user
  805. SET nearly_income = 0, nearly_begin_time = NOW()
  806. WHERE user_id = #{userId}
  807. AND last_login_time <![CDATA[ < ]]> DATE_SUB(NOW(), INTERVAL 3 DAY)
  808. AND IFNULL(nearly_begin_time, NOW()) <![CDATA[ < ]]> DATE_SUB(NOW(), INTERVAL 3 DAY);
  809. UPDATE yt_dyz_user SET nearly_begin_time = NOW() WHERE user_id = #{userId} AND nearly_begin_time IS NULL;
  810. UPDATE yt_dyz_user
  811. SET total_video = COALESCE(total_video, 0) + #{videoCount},
  812. total_income = COALESCE(total_income, 0) + #{revenue},
  813. nearly_income = COALESCE(nearly_income, 0) + #{revenue}
  814. WHERE user_id = #{userId};
  815. </update>
  816. </mapper>