首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >购买x获得免费y公式

问购买x获得免费y公式
EN

Stack Overflow用户
提问于 2021-11-23 00:59:47
回答 0查看 62关注 0票数 0

试图找出如何制定购买x得到y免费。例如买10送1,买20送2等等。现在我只是使用像这样的公式。当更改为示例时,此公式将不起作用:购买5送1,购买10送2。

Ts

代码语言:javascript
复制
getFreeItem(){
    
    let countTotal;

    this.commonService.getOrderList$.subscribe((x) => {
      x.filter(item => {
        
        item.forEach((element, i) => {
          
          if (element.freeDealMin !== null) {
            item?.reduce((a, b) => {
              let aVal = a?.count ? a?.count : a;
              let bVal = b?.count ? b?.count : b;
             
              countTotal = aVal + bVal;
              
              return aVal + bVal;
            }, 0);

            let statusFree = element.freeDealMin/ countTotal;
            
            if (statusFree == 1) {
             
                this.freeDealQty = 1;
             
            }else if (statusFree == 0.5) {
              
                this.freeDealQty = 2;

            }else if (statusFree == 0.33333333333) {
              
                this.freeDealQty = 3;

            }
          }
        });
      });
    });
  
  } 
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70074182

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档