PHP拼多多模式,砍价免费拿商品算法

PHP拼多多砍价免费拿商品算法 我12年开始做网站,对拼多多关注两三年了,一直对他们的拉新模式很感兴趣,下面我对砍价送礼品的算法跟大家分享下。

拼多多砍价免费拿商品有几个核心的东西:

1.需要拉新多人给商品,这个是直接在数据库配置的

2.是否给商品,如果不想给商品,系统会在接近砍价成功时候,不断返回小金额的砍价,如果金额小于0.01,无论是新的粉丝来砍价还是老会员,都会直接返回0.00元,永远无法砍价到。

3.不满足拉新人数要求,如果砍刀均价已经达到临界值0.01元,都会直接返回0.00元,直到拉新任务完成。

<?php

/**拼多多砍价算法
 * Created by PhpStorm.
 * Website:https://www.youhuajun.com
 * User: Benjamin
 * Date: 2019/9/6
 * Time: 9:15
 */
class Pinduoduo
{
    /**计算本次折扣金额
     * @param $price商品单价
     * @param $currentPrice当前商品价格,即折扣后的价格
     * @param $followerCount当前拉新人数
     * @param $needCount所需拉新人数
     * @param $willSucess是否给钱,默认是给钱,不给钱永远砍价不到
     */
    public function caculateDiscountAmount($price,$currentPrice,$followerCount,$needCount,$isNewFollower=false,$willSucess=true){

        if($isNewFollower==false){
            $followerCount = $followerCount+1;
        }

        $rate = $currentPrice/$price;
        switch($rate){
            case 0.2 <= $rate && $rate<=1:
                $averageMoney = $followerCount/$needCount;
                $discountMoney = $this->makeDiscountAmount($currentPrice,$averageMoney);
                break;
            case 0 <= $rate && $rate<0.2:
                $averageMoney = $followerCount/$needCount;
                //接近价格,但是没有满足人数,直接返回0元
                if($averageMoney <= '0.01'&&$followerCount < $needCount){
                    $discountMoney = '0.00';
                    break;
                }

                $discountMoney = $this->makeDiscountAmount($currentPrice,$averageMoney);

                //不给商品的,永远无法达到条件
                if($willSucess==false){
                    if(($currentPrice-$discountMoney)<=0){
                         $discountMoney = '0.00';
                    }
                    break;
                }

                if($isNewFollower==false){
                    $discountMoney = sprintf("%.2f", $discountMoney/5);
                    if($averageMoney<0.5){
                        $discountMoney = sprintf("%.2f", $discountMoney/20);
                    }
                }
                break;
            default:
                $discountMoney = '0.00';
        }
            return  $discountMoney;
    }

    /**计算指定条件砍价金额
     * @param $currentPrice当前价格
     * @param $averageMoney平均折扣
     * @param int $step
     * @return float
     */
    private function makeDiscountAmount($currentPrice,$averageMoney,$step=5){
        $discountMoney = $currentPrice/$step;
        if($discountMoney>$averageMoney){
            $this->makeDiscountAmount($currentPrice,$averageMoney,$step=1);
        }
        return sprintf("%.2f", $discountMoney);
    }

}

简庆旺博客
请先登录后发表评论
  • latest comments
  • 总共0条评论