data_active.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * @Author: YKH
  3. * @Date: 2021-12-10 09:04:02
  4. * @LastEditTime: 2022-06-07 11:02:09
  5. * @Description:
  6. * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\controller\admin\data_active.ts
  7. */
  8. import { Provide, Inject, Post, Body, ALL } from '@midwayjs/decorator';
  9. import { CoolController, BaseController } from 'midwayjs-cool-core';
  10. import { Utils } from '../../../../comm/utils';
  11. import { ShuyouDataActiveEntity } from '../../entity/data_active';
  12. import { ShuyouDataActiveService } from '../../service/data_active';
  13. import { ILogger } from '@midwayjs/logger';
  14. /**
  15. * 游戏负责人
  16. */
  17. @Provide()
  18. @CoolController({
  19. // 添加通用CRUD接口
  20. api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  21. // 设置表实体
  22. entity: ShuyouDataActiveEntity,
  23. service: ShuyouDataActiveService,
  24. before: ctx => {
  25. //前段数据转JSON格式
  26. const data = ctx.request.body;
  27. console.log(data.agentOrDirector)
  28. if (data.agentOrDirector == undefined) {
  29. data.agentOrDirector = 0
  30. }
  31. if (typeof (data.new_date) == "undefined") {
  32. data.new_date = [new Date(), new Date()]
  33. }
  34. ctx.request.body.data = JSON.stringify(data);
  35. },
  36. // 分页查询配置
  37. // pageQueryOp: {
  38. // // 让字段支持模糊查询
  39. // keyWordLikeFields: ['directorName'],
  40. // // 让字段支持筛选
  41. // fieldEq: ['directorName'],
  42. // // 添加排序
  43. // addOrderBy: {
  44. // // 排序字段及排序方式
  45. // id: 'desc',
  46. // },
  47. // },
  48. })
  49. export class ShuyouDataActiveController extends BaseController {
  50. @Inject()
  51. utils: Utils;
  52. @Inject()
  53. logger: ILogger;
  54. @Inject()
  55. ShuyouDataActiveService: ShuyouDataActiveService;
  56. @Post('/queryByDay')
  57. async queryByDay() {
  58. let new_date = this.utils.formatDate(new Date())
  59. let yest_date = this.utils.formatDate(new Date().getTime() - 24 * 60 * 60 * 1000)
  60. let today = await this.ShuyouDataActiveService.queryByDay(new_date);
  61. let yesterday = await this.ShuyouDataActiveService.queryByDay(yest_date);
  62. let today_sum_new = 0
  63. let today_sum_pay = 0
  64. let today_sum_active = 0
  65. let yest_sum_new = 0
  66. let yest_sum_pay = 0
  67. let yest_sum_active = 0
  68. let growth_new = '0%'
  69. let growth_pay = '0%'
  70. let growth_active = '0%'
  71. if (today[0].new_date) {
  72. today_sum_new = today[0].sum_new
  73. today_sum_pay = today[0].sum_pay
  74. today_sum_active = today[0].sum_active
  75. } else {
  76. return { code: -1, message: '未查询到今日数据' };
  77. }
  78. if (yesterday[0].new_date) {
  79. yest_sum_new = yesterday[0].sum_new
  80. yest_sum_pay = yesterday[0].sum_pay
  81. yest_sum_active = yesterday[0].sum_active
  82. growth_new = Number(((today_sum_new - yest_sum_new) / yest_sum_new) * 100).toFixed(2);
  83. growth_pay = Number(((today_sum_pay - yest_sum_pay) / yest_sum_pay) * 100).toFixed(2);
  84. growth_active = Number(((today_sum_active - yest_sum_active) / yest_sum_active) * 100).toFixed(2);
  85. }
  86. let res = {
  87. today: new_date,
  88. today_sum_new: today_sum_new,
  89. today_sum_pay: today_sum_pay,
  90. today_sum_active: today_sum_active,
  91. yest_sum_new: yest_sum_new,
  92. yest_sum_pay: yest_sum_pay,
  93. yest_sum_active: yest_sum_active,
  94. growth_new: growth_new,
  95. growth_pay: growth_pay,
  96. growth_active: growth_active
  97. }
  98. // this.logger.warn(res)
  99. return await this.ok({ code: 1, data: res });
  100. }
  101. /**
  102. *
  103. * 获取月数据
  104. * @return {*}
  105. * @memberof ShuyouDataActiveController
  106. */
  107. @Post('/queryByMonth')
  108. async queryByMonth() {
  109. let monthData = await this.ShuyouDataActiveService.queryByMonth();
  110. if (!monthData) {
  111. return { code: -1, message: '未查询到数据' };
  112. }
  113. // this.logger.warn(monthData)
  114. return await this.ok({ code: 1, data: monthData });
  115. }
  116. /**
  117. *
  118. * 查询今日操作次数
  119. * @return {*}
  120. * @memberof ShuyouDataActiveController
  121. */
  122. @Post('/queryOperationCount')
  123. async queryOperationCount() {
  124. let operationCount = await this.ShuyouDataActiveService.queryOperationCount();
  125. if (!operationCount) {
  126. return { code: -1, message: '未查询到数据' };
  127. }
  128. return await this.ok({ code: 1, data: operationCount });
  129. }
  130. /**
  131. *
  132. * 查询今日IP访问次数
  133. * @return {*}
  134. * @memberof ShuyouDataActiveController
  135. */
  136. @Post('/queryIpCount')
  137. async queryIpCount() {
  138. let ipCount = await this.ShuyouDataActiveService.queryIpCount();
  139. if (!ipCount) {
  140. return { code: -1, message: '未查询到数据' };
  141. }
  142. return await this.ok({ code: 1, data: ipCount });
  143. }
  144. /**
  145. *
  146. *异常统计-根据负责人和未完成原因
  147. * @param {*} queryObject
  148. * @return {*}
  149. * @memberof ShuyouDataActiveController
  150. */
  151. @Post('/queryAbnormalStatisticsByDirectorReason')
  152. async queryAbnormalStatisticsByDirectorReason(@Body(ALL) queryObject: any) {
  153. // console.log('异常统计-根据负责人和未完成原因')
  154. let { date } = queryObject
  155. if (typeof (date) == "undefined") {
  156. date = [new Date(), new Date()]
  157. }
  158. let queryAbnormalStatisticsByDirectorReason = await this.ShuyouDataActiveService.queryAbnormalStatisticsByDirectorReason(date);
  159. // console.log(queryAbnormalStatisticsByDirectorReason)
  160. if (!queryAbnormalStatisticsByDirectorReason) {
  161. return { code: -1, message: '未查询到数据' };
  162. }
  163. return await this.ok({ code: 1, data1: queryAbnormalStatisticsByDirectorReason });
  164. }
  165. //
  166. @Post('/queryGameCountByDirectorGameAgent')
  167. async queryGameCountByDirectorGameAgent(@Body(ALL) queryObject: any) {
  168. let { date } = queryObject
  169. if (typeof (date) == "undefined") {
  170. date = [new Date(), new Date()]
  171. }
  172. let queryGameCountByDirectorGameAgent = await this.ShuyouDataActiveService.queryGameCountByDirectorGameAgent(date);
  173. // console.log(queryGameCountByDirectorGameAgent)
  174. if (!queryGameCountByDirectorGameAgent) {
  175. return { code: -1, message: '未查询到数据' };
  176. }
  177. let queryGameCountByDirector = await this.ShuyouDataActiveService.queryGameCountByDirector(date);
  178. // console.log(queryGameCountByDirector)
  179. if (!queryGameCountByDirector) {
  180. return { code: -1, message: '未查询到数据' };
  181. }
  182. let queryGameCountByGameAgent = await this.ShuyouDataActiveService.queryGameCountByGameAgent(date);
  183. // console.log(queryGameCountByGameAgent)
  184. if (!queryGameCountByGameAgent) {
  185. return { code: -1, message: '未查询到数据' };
  186. }
  187. let queryGameCountByDirectorReal = await this.ShuyouDataActiveService.queryGameCountByDirectorReal(date);
  188. // console.log(queryGameCountByGameAgent)
  189. if (!queryGameCountByDirectorReal) {
  190. return { code: -1, message: '未查询到数据' };
  191. }
  192. return await this.ok({ code: 1, data1: queryGameCountByDirectorGameAgent, data2: queryGameCountByDirector, data3: queryGameCountByGameAgent, data4: queryGameCountByDirectorReal });
  193. }
  194. /**
  195. *查询今日游戏付费top5
  196. *
  197. * @return {*}
  198. * @memberof ShuyouDataActiveController
  199. */
  200. @Post('/queryTopFive')
  201. async queryTopFive() {
  202. let topFive = await this.ShuyouDataActiveService.queryTopFive();
  203. if (!topFive) {
  204. return { code: -1, message: '未查询到数据' };
  205. }
  206. return await this.ok({ code: 1, data: topFive });
  207. }
  208. }