幸運拼系統代碼幸運拼團系統源碼分享


幸運拼系統邏輯描述

以下內容是分享的幸運拼團系統的模式邏輯流程和部分核心代碼,為了讓大家便於理解,系統核心代碼已為分享給大家,大家可以自行分析,幸運拼團系統開發技術微信交流: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,歡迎探討

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM