|
@@ -1,17 +1,43 @@
|
|
|
'use strict';
|
|
|
-
|
|
|
+const _ = require('lodash');
|
|
|
+const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
const Controller = require('egg').Controller;
|
|
|
class HomeController extends Controller {
|
|
|
async index() {
|
|
|
const { ctx } = this;
|
|
|
+ // throw new BusinessError(ErrorCode.DATA_NOT_EXIST,'数据不存在')
|
|
|
+ this.newtest();
|
|
|
ctx.body = 'hi, egg';
|
|
|
- await this.ctx.service.util.rabbitMq.initDeadProcess();
|
|
|
}
|
|
|
async m1() {
|
|
|
- // const { taskMqConfig } = this.app.config;
|
|
|
- // const body = this.ctx.request.body;
|
|
|
- // await this.ctx.service.util.rabbitMq.makeTask(taskMqConfig.queue, body);
|
|
|
- this.ctx.ok();
|
|
|
+ let score = 5;
|
|
|
+ let arr = [ 5, 4, 1, 2, 4, 3, 2, 5, 5, 2, 3, 5, 0, 5, 2, 3 ];
|
|
|
+ arr = arr.sort((a, b) => b - a);
|
|
|
+ const length = arr.length;
|
|
|
+ console.log(arr);
|
|
|
+ console.log(length);
|
|
|
+ let mid,
|
|
|
+ midIndex;
|
|
|
+ const wl = [],
|
|
|
+ gl = [];
|
|
|
+ if (length % 2 !== 0) {
|
|
|
+ midIndex = this.ctx.plus(Math.floor(length / 2), 1);
|
|
|
+ mid = arr[midIndex];
|
|
|
+ } else {
|
|
|
+ midIndex = this.ctx.divide(length, 2);
|
|
|
+ mid = this.ctx.divide(this.ctx.plus(arr[midIndex], arr[midIndex + 1]), 2);
|
|
|
+ }
|
|
|
+ for (const i of arr) {
|
|
|
+ if (i >= mid) gl.push(i);
|
|
|
+ else wl.push(i);
|
|
|
+ }
|
|
|
+ const offset = _.floor(this.ctx.divide(gl.length, 10));
|
|
|
+ for (let i = 0; i < offset.length; i++) {
|
|
|
+ wl.pop();
|
|
|
+ }
|
|
|
+ score = this.ctx.minus(score, this.ctx.multiply(wl.length, 0.01));
|
|
|
+
|
|
|
+ this.ctx.ok({ data: score });
|
|
|
}
|
|
|
|
|
|
async makeCoupons() {
|