编程语言
首页 > 编程语言> > 幸运拼系统代码幸运拼团系统源码分享

幸运拼系统代码幸运拼团系统源码分享

作者:互联网

幸运拼系统代码幸运拼团系统源码分享

幸运拼系统逻辑描述

以下内容是分享的幸运拼团系统的模式逻辑流程和部分核心代码,为了让大家便于理解,系统核心代码已为分享给大家,大家可以自行分析,幸运拼团系统开发技术微信交流:15889726201,欢迎探讨

 

一,拼团产品区
  幸运拼系统的后台可以设置多个拼团产品,并根据拼团产品的价格设置价格专区,每个专区都有多种产品,会员可以根据自己的需求选择不同的商品进行拼团。

二,幸运拼参团奖励

  拼团模式可以选择2人 3人,甚至20人的超级拼团模式
  例如:20人(系统.自动匹配人)参团拼一个100元产品,只有一个人拼中,无论拼中还是拼不中参团一次奖励1元,参团需要活跃度,参团一次消耗1个活跃度

三,幸运拼活跃度获取方法
  1,每天签到领10个活跃度
  2,直接推广(一级)一人可获得20活跃度(要求参团一次)
  3,间接推广(二级)一人可获得10活跃度(要求参团一次)


四,5次拼团产品系统奖励机制
  参团累计拼中5次产品可获得幸运星1颗,奖励600元(例如:你拼中了5次100元的产品,系统奖励给当前会员600元的积分奖励)

五,SVIP(团队长)
  晋升SVIP需要直推5人(这5个人要求最低参团一次)
六,幸运拼SVIP奖励
  当你成为SVIP后,就可以拿团队无限层所有人的拼团佣金
  1~400次每次奖励0.5元
  401~4000次每次奖励1元
  4001~40000次每次奖励1.5元
  40000次以上每次奖励2元

七,幸运拼平级奖
  如果下级和上级同时是SVIP,上级可得到下级每天佣金的10%

八,幸运拼操作流程
  注册登录之后,在首页签到领取活跃值,有了活跃值就可以参与拼团了,选择自己想要的产品参加拼团

 

 

幸运拼团核心代码见下

/**
 * TODO 拼团产品Model
 * Class StoreCombination
 * @package app\models\store
 */
class StoreCombination extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'store_combination';

    use ModelTrait;

    public function getDescriptionAttr($value)
    {
        return htmlspecialchars_decode($value);
    }

    /**
     * @param $where
     * @return array
     */
    public static function get_list($length = 10)
    {
        if ($post = input('post.')) {
            $where = $post['where'];
            $model = new self();
            $model = $model->alias('c');
            $model = $model->join('StoreProduct s', 's.id=c.product_id');
            $model = $model->where('c.is_show', 1)->where('c.is_del', 0)->where('c.start_time', '<', time())->where('c.stop_time', '>', time());
            if (!empty($where['search'])) {
                $model = $model->where('c.title', 'like', "%{$where['search']}%");
                $model = $model->whereOr('s.keyword', 'like', "{$where['search']}%");
            }
            $model = $model->field('c.*,s.price as product_price');
            if ($where['key']) {
                if ($where['sales'] == 1) {
                    $model = $model->order('c.sales desc');
                } else if ($where['sales'] == 2) {
                    $model = $model->order('c.sales asc');
                }
                if ($where['price'] == 1) {
                    $model = $model->order('c.price desc');
                } else if ($where['price'] == 2) {
                    $model = $model->order('c.price asc');
                }
                if ($where['people'] == 1) {
                    $model = $model->order('c.people asc');
                }
                if ($where['default'] == 1) {
                    $model = $model->order('c.sort desc,c.id desc');
                }
            } else {
                $model = $model->order('c.sort desc,c.id desc');
            }
            $page = is_string($where['page']) ? (int)$where['page'] + 1 : $where['page'] + 1;
            $list = $model->page($page, $length)->select()->toArray();
            return ['list' => $list, 'page' => $page];
        }
    }

    /**
     * 获取拼团数据
     * @param int $page
     * @param int $limit
     * @return mixed
     */
    public static function getAll($page = 0, $limit = 20)
    {
        $model = new self();
        $model = $model->alias('c');
        $model = $model->join('StoreProduct s', 's.id=c.product_id');
        $model = $model->field('c.*,s.price as product_price');
        $model = $model->order('c.sort desc,c.id desc');
        $model = $model->where('c.is_show', 1);
        $model = $model->where('c.is_del', 0);
        $model = $model->where('c.start_time', '<', time());
        $model = $model->where('c.stop_time', '>', time());
        if ($page) $model = $model->page($page, $limit);
        return $model->select()->each(function ($item) {
            $item['image'] = set_file_url($item['image']);
        });
    }

    /**
     * 获取是否有拼团产品
     * */
    public static function getPinkIsOpen()
    {
        return self::alias('c')->join('StoreProduct s', 's.id=c.product_id')->where('c.is_show', 1)->where('c.is_del', 0)
            ->where('c.start_time', '<', time())->where('c.stop_time', '>', time())->count();
    }

    /**
     * 获取一条拼团数据
     * @param $id
     * @return mixed
     */
    public static function getCombinationOne($id)
    {
        $model = new self();
        $model = $model->alias('c');
        $model = $model->join('StoreProduct s', 's.id=c.product_id');
        $model = $model->field('c.*,s.price as product_price,SUM(s.sales+s.ficti) as total');
        $model = $model->where('c.is_show', 1);
        $model = $model->where('c.is_del', 0);
        $model = $model->where('c.id', $id);
        $model = $model->where('c.start_time', '<', time());
        $model = $model->where('c.stop_time', '>', time() - 86400);
        $info = $model->find();
        if ($info['id']) {
            return $info;
        } else {
            return [];
        }
    }

    /**
     * 获取推荐的拼团产品
     * @return mixed
     */
    public static function getCombinationHost($limit = 0)
    {
        $model = new self();
        $model = $model->alias('c');
        $model = $model->join('StoreProduct s', 's.id=c.product_id');
        $model = $model->field('c.id,c.image,c.price,c.sales,c.title,c.people,s.price as product_price');
        $model = $model->where('c.is_del', 0);
        $model = $model->where('c.is_host', 1);
        $model = $model->where('c.start_time', '<', time());
        $model = $model->where('c.stop_time', '>', time());
        if ($limit) $model = $model->limit($limit);
        return $model->select();
    }

    /**
     * 修改销量和库存
     * @param $num
     * @param $CombinationId
     * @return bool
     */
    public static function decCombinationStock($num, $CombinationId, $unique)
    {
        $product_id = self::where('id', $CombinationId)->value('product_id');
        if ($unique) {
            $res = false !== StoreProductAttrValue::decProductAttrStock($CombinationId, $unique, $num, 3);
            $res = $res && self::where('id', $CombinationId)->dec('stock', $num)->dec('quota', $num)->inc('sales', $num)->update();
            $sku = StoreProductAttrValue::where('product_id', $CombinationId)->where('unique', $unique)->where('type', 3)->value('suk');
            $res = $res && StoreProductAttrValue::where('product_id', $product_id)->where('suk', $sku)->where('type', 0)->dec('stock', $num)->inc('sales', $num)->update();
        } else {
            $res = false !== self::where('id', $CombinationId)->dec('stock', $num)->inc('sales', $num)->update();
        }
        $res = $res && StoreProduct::where('id', $product_id)->dec('stock', $num)->inc('sales', $num)->update();
        return $res;
    }

    /**
     * 增加库存,减少销量
     * @param $num
     * @param $CombinationId
     * @return bool
     */
    public static function incCombinationStock($num, $CombinationId, $unique = '')
    {

        $combination = self::where('id', $CombinationId)->field(['product_id', 'stock', 'sales', 'quota'])->find();
        if (!$combination) return true;
        if ($combination->sales > 0) $combination->sales = bcsub($combination->sales, $num, 0);
        if ($combination->sales < 0) $combination->sales = 0;
        $res = true;
        if ($unique) {
            $res = false !== StoreProductAttrValue::incProductAttrStock($CombinationId, $unique, $num, 3);
            $sku = StoreProductAttrValue::where('product_id', $CombinationId)->where('unique', $unique)->where('type', 3)->value('suk');
            $res = $res && StoreProductAttrValue::where('product_id', $combination['product_id'])->where('suk', $sku)->where('type', 0)->inc('stock', $num)->dec('sales', $num)->update();
        }
        $combination->stock = bcadd($combination->stock, $num, 0);
        $combination->quota = bcadd($combination->quota, $num, 0);
        $res = $res && $combination->save() && StoreProduct::where('id', $combination['product_id'])->inc('stock', $num)->dec('sales', $num)->update();
        return $res;
    }

    /**
     * 判断库存是否足够
     * @param $id
     * @param $cart_num
     * @return int|mixed
     */
    public static function getCombinationStock($id, $cart_num)
    {
        $stock = self::where('id', $id)->value('stock');
        return $stock > $cart_num ? $stock : 0;
    }

    /**
     * 获取字段值
     * @param $id
     * @param $field
     * @return mixed
     */
    public static function getCombinationField($id, $field = 'title')
    {
        return self::where('id', $id)->value($field);
    }

    /**
     * 获取产品状态
     * @param $id
     * @return mixed
     */
    public static function isValidCombination($id)
    {
        $model = new self();
        $model = $model->where('id', $id);
        $model = $model->where('is_del', 0);
        $model = $model->where('is_show', 1);
        return $model->count();
    }

    /**
     * 增加浏览量
     * @param int $id
     * @return bool
     */
    public static function editIncBrowse($id = 0)
    {
        if (!$id) return false;
        $browse = self::where('id', $id)->value('browse');
        $browse = bcadd($browse, 1, 0);
        self::edit(['browse' => $browse], $id);
    }

    public static function completeGroup()
    {
        $fpff = fopen("./fflock.txt", "w+");

        if(flock($fpff,LOCK_EX)){

            $pinkListEndWin = self::pinkListEndWin();

            if (!$pinkListEndWin) return true;
            $pinkListEndWin = $pinkListEndWin->toArray();
            foreach ($pinkListEndWin as $key => $value) {
                $countPeople = (int)bcadd(StorePink::where('k_id', $value['id'])->count(), 1, 0);
                //如果拼团人数未达到
                if ($countPeople < $value['people']){
                    continue;
                }

                $pinkLists = StorePink::where('k_id', $value['id'])->column('id', 'id');
                $pinkLists[] = $value['id'];
                $pinkLists = array_values($pinkLists);

                //随机出中奖者
                $win_id_index = array_rand($pinkLists,1);
                //$win_id_index = 12;
                $win_id = $pinkLists[$win_id_index];
                if( !$win_id )
                    continue;

                try{
                    self::beginTrans();

                    //设置未已开奖
                    StorePink::where('id','IN',$pinkLists)->update(['is_win'=>1]);

                    /** ::todo 中奖处理开始 */
                    //拼团中奖
                    unset($pinkLists[$win_id_index]);
                    $win_info = StorePink::get($win_id);
                    if( ! $win_info )
                        continue;
                    $win_info = $win_info->toArray();

                    //发放中奖的推荐奖励
                    self::sendRecommendReward($win_info['uid'],$win_info['price'],$win_info['cid'],0);

                    //修改订单状态
                    $update_info = [
                        'status' => 2, //订单状态,
                    ];
                    StoreOrder::update($update_info,['order_id'=>$win_info['order_id']]);
                    /** ::todo 未中奖处理开始 */
                    self::failRefundPink($pinkLists);//申请退款

                    self::commitTrans();
                } catch (\Exception $e)
                {
                    self::rollbackTrans();
                    var_dump($e->getMessage());
                    continue;
                }
            }
            flock($fpff,LOCK_UN);
        }

        fclose($fpff);
    }

    /**
     * 获取拼团数据
     * @return \think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function pinkListEndWin()
    {
        $model = StorePink::field('id,people');//开团编号
        $model = $model->where('stop_time', '<=', time());//小于当前时间
        $model = $model->where('status', 2);//进行中的拼团
        $model = $model->where('k_id', 0);//团长
        $model = $model->where('is_win', 0);//是否开奖
        $model = $model->where('is_refund', 0);//未退款
        return $model->select();
    }

    /**
     * 发放推广奖励
     * @param $uid
     * @param $price
     * @param $cid
     * @param int $type
     * @return mixed
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function sendRecommendReward($uid,$price,$cid,$type=0)
    {
        $user_info = User::getUserInfo($uid);
        if( $user_info['spread_uid'] > 0 )
        {
            $combination_info = self::find($cid);
            if( $combination_info )
                $combination_info = $combination_info->toArray();

            $spreadUserInfo = User::getUserInfo($user_info['spread_uid']);
            if( $spreadUserInfo )
            {
                $reward_rate = $type ? $combination_info['indirect_recommend_tate'] : $combination_info['direct_recommend_tate'];
                $reward_num = bcmul($price,$reward_rate/100,2);
                if($reward_num){

                    $note = $type ? '间推奖励' : '直推奖励';
                    User::bcInc($spreadUserInfo['uid'], 'now_money', $reward_num, 'uid');
                    UserBill::income($note, $spreadUserInfo['uid'], 'now_money', 'product_profits', $reward_num, $combination_info['product_id'], bcadd($spreadUserInfo['now_money'], $reward_num, 2), $note . floatval($price) . '元');
                    if( $spreadUserInfo['spread_uid'] > 0 && $type == 0 )
                        return self::sendRecommendReward($spreadUserInfo['uid'],$price,$cid,1);

                }
            }
        }
    }


    /**
     * 拼团未中 申请退款
     * @param $pinkList
     * @return bool
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function failRefundPink($pinkList)
    {

        $refundPinkList = StorePink::where('id', 'IN', $pinkList)->column('order_id,uid,price,id,cid,people,pid', 'id');

        if (!count($refundPinkList)) return true;

        foreach ($refundPinkList as $key => $item) {
            $fail_rebate_rate = self::where('id', $item['cid'])->value('fail_rebate_rate');
            if( $fail_rebate_rate < 0 )
                return false;

            $refund_price = bcdiv($item['price']*$fail_rebate_rate/100,$item['people']-1,2);

            $user_info = User::getUserInfo($item['uid']);

            //拼团未中奖返点
            User::bcInc($item['uid'], 'now_money', $refund_price, 'uid');
            UserBill::income('拼团未中奖', $item['uid'], 'now_money', 'product_profits', $refund_price, $item['pid'], bcadd($user_info['now_money'], $refund_price, 2), '拼团未中奖' . floatval($refund_price) . '元');

            User::bcInc($item['uid'], 'now_money', $item['price'], 'uid');
            UserBill::income('拼团未中奖退款', $item['uid'], 'now_money', 'product_profits', $item['price'], $item['pid'], bcadd($item['price'],bcadd($user_info['now_money'], $refund_price, 2),2), '拼团未中奖退款' . floatval($refund_price) . '元');

            //退款
            self::ptorderApplyRefund($item['order_id'], $item['uid'], '拼团未中奖');//申请退款

            //修改拼团订单状态
            StorePink::where('id', $item['id'])->update(['status' => 3]);

        }
    }

    /**
     * 退款处理
     * @param $uni
     * @param $uid
     * @param string $refundReasonWap
     * @param string $refundReasonWapExplain
     * @param array $refundReasonWapImg
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function ptorderApplyRefund($uni, $uid, $refundReasonWap = '', $refundReasonWapExplain = '', $refundReasonWapImg = [])
    {
        $order = StoreOrder::getUserOrderDetail($uid, $uni);
        if (!$order) return self::setErrorInfo('支付订单不存在!');
        if ($order['refund_status'] == 2) return self::setErrorInfo('订单已退款!');
        if ($order['refund_status'] == 1) return self::setErrorInfo('正在申请退款中!');
        if ($order['status'] == 1) return self::setErrorInfo('订单当前无法退款!');

        $res1 = false !== StoreOrderStatus::status($order['id'], 'apply_refund', '用户申请退款,原因:' . $refundReasonWap);
        $res2 = false !== StoreOrder::edit(['status'=>'-1','refund_status' => 2, 'refund_reason_time' => time(), 'refund_reason_wap' => $refundReasonWap, 'refund_reason_wap_explain' => $refundReasonWapExplain, 'refund_reason_wap_img' => json_encode($refundReasonWapImg)], $order['id'], 'id');
        return true;
    }

 

以上代码是分享的幸运拼团系统部分核心代码,为了让大家便于理解,系统核心代码已为分享给大家,大家可以自行分析,幸运拼团系统开发技术微信交流:15889726201,欢迎探讨

 

posted on 2021-01-09 13:42  海姆达尔  阅读(685)  评论(0)  编辑  收藏

标签:return,price,id,源码,拼团,幸运,where,model
来源: https://blog.51cto.com/u_13168809/2834718