lrf преди 2 години
родител
ревизия
e20e5401bb
променени са 3 файла, в които са добавени 6 реда и са изтрити 6 реда
  1. 0 1
      app/controller/trade/config/.coupon.js
  2. 5 4
      app/service/trade/coupon.js
  3. 1 1
      app/z_router/trade/coupon.js

+ 0 - 1
app/controller/trade/config/.coupon.js

@@ -90,7 +90,6 @@ module.exports = {
       query: ['skip', 'limit'],
       sort: ['meta.createdAt'],
       desc: true,
-      count: true,
     },
   },
 };

+ 5 - 4
app/service/trade/coupon.js

@@ -16,10 +16,10 @@ class CouponService extends CrudService {
   async userView(filter, { skip = 0, limit, sort, desc, projection } = {}) {
     const customer = _.get(this.ctx, 'user._id');
     if (!customer) throw new BusinessError(ErrorCode.NOT_LOGIN, '未找到用户登陆信息');
-    let list = await this.query({ ...filter, status: '0' }, { skip, limit, sort, desc, projection });
-    list = await this.makeShowData(list);
+    let data = await this.query({ ...filter, status: '0' }, { skip, limit, sort, desc, projection });
+    data = await this.makeShowData(data);
     // 还需要判断用户是否领取过了
-    for (const coupon of list) {
+    for (const coupon of data) {
       const { get_limit, get_limit_config } = coupon;
       if (get_limit === 'nolimit') coupon.canGet = true;
       else {
@@ -29,7 +29,8 @@ class CouponService extends CrudService {
         else coupon.canGet = true;
       }
     }
-    return list;
+    const total = await this.model.count({ ...filter, status: '0' });
+    return { data, total };
   }
 
 

+ 1 - 1
app/z_router/trade/coupon.js

@@ -7,7 +7,7 @@ const rkey = 'coupon';
 const ckey = 'trade.coupon';
 const keyZh = '优惠券';
 const routes = [
-  { method: 'get', path: `${rkey}/userView`, controller: `${ckey}.userView`, name: `${ckey}userView`, zh: `${keyZh}-用户领取页面` },
+  { method: 'get', path: `${rkey}/userView`, middleware: [ 'dealQuery' ], controller: `${ckey}.userView`, name: `${ckey}userView`, 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}` },