lrf há 2 anos atrás
pai
commit
1d23e03518

+ 7 - 0
app/controller/user/config/.point.js

@@ -37,4 +37,11 @@ module.exports = {
       count: true,
     },
   },
+  computedTotal: {
+    parameters: {
+      query: {
+        customer: 'customer',
+      },
+    },
+  },
 };

+ 13 - 0
app/service/user/point.js

@@ -12,6 +12,19 @@ class PointService extends CrudService {
     this.orderDetailModel = this.ctx.model.Trade.OrderDetail;
     this.userModel = this.ctx.model.User.User;
   }
+
+  async computedTotal({ customer }) {
+    assert(customer, '缺少用户信息');
+    const res = await this.model.find({ customer });
+    const total = res.reduce((p, n) => {
+      let point = n.point;
+      if (!(n.source === '0' || n.source === '1')) point = -point;
+      return this.ctx.plus(p, point);
+    }, 0);
+    return total;
+  }
+
+
   /**
    * 添加积分;将处理添加至事务之中
    * @param {String} orderDetail_id 订单详情id

+ 1 - 0
app/z_router/user/point.js

@@ -7,6 +7,7 @@ const rkey = 'point';
 const ckey = 'user.point';
 const keyZh = '积分';
 const routes = [
+  { method: 'get', path: `${rkey}/computedTotal`, controller: `${ckey}.computedTotal`, name: `${ckey}computedTotal`, zh: `${keyZh}计算总分` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
   { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },