lrf 2 years ago
parent
commit
d81048f41b

+ 32 - 6
app/controller/home.js

@@ -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() {

+ 2 - 2
app/controller/system/config/.config.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['title', 'config', 'agree', 'bottom_title'],
+    requestBody: ['title', 'config', 'agree', 'bottom_title', 'bottom_menu'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['title', 'config', 'agree', 'bottom_title'],
+    requestBody: ['title', 'config', 'agree', 'bottom_title', 'bottom_menu'],
   },
   show: {
     parameters: {

+ 5 - 0
app/model/system/config.js

@@ -8,12 +8,17 @@ const configProp = {
   pointPlan: { type: Array, zh: '积分计划' }, // 后续有待制作,目前全靠新写
   autoCloseOrder: { type: Number, zh: '自动关闭订单时间' }, // <=0时不自动关闭
 };
+const bottom_menu = {
+  list: { type: Array, zh: '菜单列表' },
+  is_use: { type: String, zh: '是否使用' },
+};
 // 系统设置
 const config = {
   title: { type: String, required: false, zh: '系统名称' }, //
   config: { type: Object, required: false, zh: '设置' }, //
   agree: { type: String, required: false, zh: '用户协议' }, // 富文本
   bottom_title: { type: String, required: false, zh: '底部加载数据结束的文字提示' }, //
+  bottom_menu: { type: Object, zh: '底部菜单' },
 };
 const schema = new Schema(config, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });

+ 1 - 1
app/service/view/goods.js

@@ -18,7 +18,7 @@ class GoodsService extends CrudService {
    * @param query.id 商品数据id
    */
   async goodsDetail({ id }) {
-    // TODO 添加宝贝数,商店3个评价
+    // 添加宝贝数,商店3个评价
     const { populate } = this.ctx.service.shop.goods.getRefMods();
     let goods = await this.goodsModel.findById(id, { file: 1, tags: 1, name: 1, shot_brief: 1, brief: 1, send_time: 1, shop: 1, view_num: 1 }).populate(populate);
     if (!goods) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到商品数据');