lrf 2 years ago
parent
commit
de369e8f95
1 changed files with 14 additions and 14 deletions
  1. 14 14
      app/service/user/userCoupon.js

+ 14 - 14
app/service/user/userCoupon.js

@@ -202,7 +202,7 @@ class UserCouponService extends CrudService {
         const r = arr.findIndex((f) => arr1.find((ff) => _.isEqual(f, ff)));
         console.log(r);
        */
-      const r = s.goods.some((g) => g.tags.find((f) => tags.find((ff) => _.isEqual(f, ff))));
+      const r = s.goods.some(g => g.tags.find(f => tags.find(ff => _.isEqual(f, ff))));
       if (r) {
         result = true;
         break;
@@ -218,16 +218,16 @@ class UserCouponService extends CrudService {
    */
   async computedOrderCouponDiscount(couponIds, goodsSpecs) {
     const result = {}; // 最终结果: 以 couponId: { goodsSpecId: ${money} } 为明细格式
-    const goodsSpecIds = goodsSpecs.map((i) => i.id);
+    const goodsSpecIds = goodsSpecs.map(i => i.id);
     const { populate: gp } = this.ctx.service.shop.goodsSpec.getRefMods();
     let goodsSpecList = await this.goodsSpecModel.find({ _id: goodsSpecIds }).populate(gp);
     goodsSpecList = this.resetGoodsSpecData(goodsSpecList, goodsSpecs);
     const { populate: cp } = this.getRefMods();
     let userCouponList = await this.model.find({ _id: couponIds }, { customer: 0 }).populate(cp);
     // 先查下有没有不能用的,有不能用的需要返回
-    let cantUse = userCouponList.find((f) => f.status !== '0');
+    let cantUse = userCouponList.find(f => f.status !== '0');
     if (cantUse) throw new BusinessError(ErrorCode.DATA_INVALID, `优惠券:${_.get(cantUse, 'coupon.name')}已使用`);
-    cantUse = userCouponList.find((f) => !this.checkCanUse_expire(f));
+    cantUse = userCouponList.find(f => !this.checkCanUse_expire(f));
     if (cantUse) throw new BusinessError(ErrorCode.DATA_INVALID, `优惠券:${_.get(cantUse, 'coupon.name')}不能使用`);
     userCouponList = this.resetUserCouponData(userCouponList);
     // 上面整理完数据之后,下面开始用 均分优惠金额
@@ -239,7 +239,7 @@ class UserCouponService extends CrudService {
       // 平台券,都可以
       if (issue === '0') goodsList = goodsSpecList;
       // 店铺券,需要过滤店铺
-      else goodsList = goodsSpecList.filter((f) => ObjectId(shop).equals(_.get(f, 'shop._id')));
+      else goodsList = goodsSpecList.filter(f => ObjectId(shop).equals(_.get(f, 'shop._id')));
       // 2.商品已确定,再确定是否是指定分类
       if (use_limit !== 'all') {
         // all的情况不需要再次过滤出不符合的条件: all为全部商品类型
@@ -368,11 +368,11 @@ class UserCouponService extends CrudService {
    * @param {Array} tags 商品标签
    */
   getGoodsInTags(goodsSpecList, tags) {
-    const arr = goodsSpecList.filter((f) => {
+    const arr = goodsSpecList.filter(f => {
       const gtags = _.get(f, 'goods.tags');
       // 没打标签或者标签里没有内容的直接过滤出去
       if (!gtags || gtags.length <= 0) return false;
-      const r = gtags.find((f) => tags.find((ff) => _.isEqual(ff, f)));
+      const r = gtags.find(f => tags.find(ff => _.isEqual(ff, f)));
       return r;
     });
     return arr;
@@ -385,16 +385,16 @@ class UserCouponService extends CrudService {
    * @param {Array} orderInfo 有关订单的信息 {id,buy_num}
    */
   resetGoodsSpecData(list, orderInfo) {
-    const nouse = ['meta', '__v'];
-    const arr = list.map((i) => {
+    const nouse = [ 'meta', '__v' ];
+    const arr = list.map(i => {
       const obj = {};
-      const goodsSpec = _.omit(i, [...nouse, 'goods']);
-      const shop = _.omit(_.get(i, 'goods.shop'), [...nouse]);
-      const goods = _.omit(_.get(i, 'goods'), [...nouse, 'shop']);
+      const goodsSpec = _.omit(i, [ ...nouse, 'goods' ]);
+      const shop = _.omit(_.get(i, 'goods.shop'), [ ...nouse ]);
+      const goods = _.omit(_.get(i, 'goods'), [ ...nouse, 'shop' ]);
       obj.goodsSpec = goodsSpec;
       obj.shop = shop;
       obj.goods = goods;
-      const r = orderInfo.find((f) => ObjectId(f.id).equals(goodsSpec._id));
+      const r = orderInfo.find(f => ObjectId(f.id).equals(goodsSpec._id));
       if (r) obj.buy_num = r.buy_num;
       if (obj.buy_num) {
         obj.goods_total = parseInt(obj.buy_num) * parseFloat(_.get(obj.goodsSpec, 'sell_money'));
@@ -408,7 +408,7 @@ class UserCouponService extends CrudService {
    * @param {Array} list 用户优惠券列表
    */
   resetUserCouponData(list) {
-    const arr = list.map((i) => {
+    const arr = list.map(i => {
       const { _id, meta, coupon } = i;
       const cd = _.pick(coupon, [
         'issue',