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

摘要:
幸运联盟系统的逻辑描述如下:共享幸运联盟系统模型逻辑流程和部分核心代码。为了让每个人都更容易理解,系统核心代码已共享,供每个人自己分析。幸运联盟系统微信通讯开发技术:15889726201,欢迎讨论。幸运联盟系统在联盟产品区的后台可以设置多个联盟产品,价格区根据集团产品的价格设置。每个专区都有多种产品,会员可以根据自己的需求选择不同的产品。2、 您可以选择幸运的比赛模式

幸运拼系统逻辑描述

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

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

二,幸运拼参团奖励

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

幸运拼系统代码幸运拼团系统源码分享第1张

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


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

幸运拼系统代码幸运拼团系统源码分享第2张

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

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

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

幸运拼系统代码幸运拼团系统源码分享第3张

幸运拼团核心代码见下

/**
 * TODO 拼团产品Model
 * Class StoreCombination
 * @package appmodelsstore
 */
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 	hinkCollection
     * @throws 	hinkdbexceptionDataNotFoundException
     * @throws 	hinkdbexceptionDbException
     * @throws 	hinkdbexceptionModelNotFoundException
     */
    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 	hinkException
     * @throws 	hinkdbexceptionDataNotFoundException
     * @throws 	hinkdbexceptionDbException
     * @throws 	hinkdbexceptionModelNotFoundException
     */
    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 	hinkException
     * @throws 	hinkdbexceptionDataNotFoundException
     * @throws 	hinkdbexceptionModelNotFoundException
     */
    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 	hinkdbexceptionDataNotFoundException
     * @throws 	hinkdbexceptionModelNotFoundException
     */
    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,欢迎探讨

免责声明:文章转载自《幸运拼系统代码幸运拼团系统源码分享》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇C#内存管理与垃圾回收堆栈、堆、方法区介绍下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

自己写的一个随机生成ID号的函数(C#)

public string GetRandomNum(int num_down , int num_up){ //传递随机数的上下限 用于限制其长度 注意 num_up的值上限1000000000int re=0; Random ro=new Random(unchecked((int)DateTime.Now.Ticks));re=ro.Next(num...

Sencha Touch开发实例:有动画效果iPad的网站首页

在51CTO的专题“Sencha Touch入门教程”中我们已对如何使用Sencha touch进行开发有了初步的认识。在本系列教程中,将学习如何使用Sencha Touch,开发一个适合在iPad上运行的网页应用,并详细讲解其中的技巧。本文的阅读对象为对Sencha Touch有一定基础的读者,如果读者不熟悉相关内容,请先查看51CTO的专题。 构图设计...

thinkphp 对数据库的操作

   框架有时会用到数据库的内容,在"ThinkPhp框架知识"的那篇随笔中提到过,现在这篇随笔详细的描述下。 数据库的操作,无疑就是连接数据库,然后对数据库中的表进行各种查询,然后就是对数据的增删改的操作,一步步的讲述一下框架对数据库的操作 想要操作数据库,第一步必然是要:链接数据库 一、链接数据库 (1)找到模块文件夹中的Conf文件夹,然后进行编...

pytest自学第二期

好,现在开始学习pytest第二章2 pytest初级用法2.1 通过python解释器调用 pytest 在控制台输入命令:   python -m pytest 文档说这种方式相当于直接调用 pytest,唯一的不同是这样调用会把当前目录添加到sys.path (这句是重点,重点是啥,我不知道,   我不知道这有什么用c 以后就这样,如果有自己学过但是...

(转)使用SVN+CruiseControl+ANT实现持续集成之一

在前面的文章中, 介绍自己当时所在团队的处境(使用.NET开发),一个不到十个人的研发团队在保证正常开发进度同时需要并发支持四、五十个项目问题处理,经常为了程序版 本冲突、日常测试版本、发布版本提供等重复枯燥无味的手工劳动,导致团队成员身心俱疲。经历这样痛苦的一段时间,终于忍受不了,通过命令行实现了包括获 取、编译、发布过程的集成,大大减轻版本编译的时间,此...

Linux动态频率调节系统CPUFreq之三:governor

在上一篇文章中,介绍了cpufreq的core层,core提供了cpufreq系统的初始化,公共数据结构的建立以及对cpufreq中其它子部件提供注册功能。core的最核心功能是对policy的管理,一个policy通过cpufreq_policy结构中的governor字段,和某个governor相关联,本章的内容正是要对governor进行讨论。 通过...