<noframes id="bhrfl"><address id="bhrfl"></address>

    <address id="bhrfl"></address>

    <noframes id="bhrfl"><address id="bhrfl"><th id="bhrfl"></th></address>

    <form id="bhrfl"><th id="bhrfl"><progress id="bhrfl"></progress></th></form>

    <em id="bhrfl"><span id="bhrfl"></span></em>

    全部
    常見問題
    產品動態
    精選推薦

    如何二開分銷功能

    管理 管理 編輯 刪除

           首先我們要知道什么是分銷系統?

          分銷系統指通過互聯網將供應商與經銷商有機地聯系在一起,為企業的業務經營及與貿易伙伴的合作提供了一種全新的模式。供應商、分支機構和經銷商之間可以實現實時地提交業務單據、查詢產品供應和庫存狀況、并獲得市場、銷售信息及客戶支持,實現了供應商、分支機構與經銷商之間端到端的供應鏈管理,有效地縮短了供銷鏈。

          知識付費的分銷功能主要體現在專題課程及會員模塊;用戶購買專題課程、會員后會給用戶的上級和上上級返傭。

    那么分銷系統是如何實現的呢?

    知識付費系統中在用戶進入系統時若是帶有上級的信息,那么這個用戶就是別的用戶發展的下級,我們就需要記錄該用戶的上級信息。數據庫用戶表eb_user表中有字段spread_uid(推廣員id),該字段記錄的是用戶的上級id。

    首先確定什么時候執行分銷功能?分銷功能執行肯定是需要訂單結束后,這樣可以避免大多數用戶退款后的傭金返還問題。

    然后就是分銷代碼的書寫了,知識付費分銷分為人人分銷和指定分銷;人人分銷是指系統中的所有用戶均可參與分銷活動,并且在下級用戶購買后可以獲得傭金。指定分銷是指只有系統設置推廣權限的用戶才能在下級用戶購買后獲得傭金。因為知識付費的分銷是二級分銷,所有我們是直接寫了一級返傭和二級返傭的方法,在執行完一級返傭后執行二級返傭,這是分銷的最簡單邏輯了。

    以專題課程為例,在專題課程購買成功后執行返傭。

        /**
         * //TODO 專題支付成功后
         * @param $orderId
         * @param $notify
         * @return bool
         */
        public static function paySuccess($orderId)
        {
            $order = self::where('order_id', $orderId)->where('type', 0)->find();
            if (!$order) return false;
            $resPink = true;
            $res2 = true;
            $res3 = true;
            User::bcInc($order['uid'], 'pay_count', 1, 'uid');
            $res1 = self::where('order_id', $orderId)->where('type', 0)->update(['paid' => 1, 'pay_time' => time()]);
            if ($res1 && $order['pay_type'] != 'yue') {
                $res2 = UserBill::expend('購買專題', $order['uid'], $order['pay_type'], 'pay_product', $order['pay_price'], $order['id'], 0, '支付' . floatval($order['pay_price']) . '元購買專題');
            }
            if ($res1) {
                $res3 = MerchantFlowingWater::setMerchantFlowingWater($order, 0);
            }
            if ($order['combination_id'] && $res1 && !$order['refund_status']) {
                $resPink = StorePink::createPink($order);//創建拼團
            } else {
                if (!$order['is_gift']) {
                    //如果是專欄,記錄專欄下所有專題購買。
                    SpecialBuy::setAllBuySpecial($orderId, $order['uid'], $order['cart_id']);
                    TestPaperObtain::setTestPaper($orderId, $order['uid'], $order['cart_id'], 2);
                    DataDownloadBuy::setDataDownload($orderId, $order['uid'], $order['cart_id'], 0);
                    try {
                        //專題返傭
                        User::backOrderBrokerage($order);
                    } catch (\Throwable $e) {
                    }
                }
            }
            StoreOrderStatus::status($order->id, 'pay_success', '用戶付款成功');
            $site_url = SystemConfigService::get('site_url');
            try {
                $wechat_notification_message = SystemConfigService::get('wechat_notification_message');
                if ($wechat_notification_message == 1) {
                    $title = Special::getName($order['cart_id']);
                    WechatTemplateService::sendTemplate(WechatUser::where('uid', $order['uid'])->value('openid'), WechatTemplateService::ORDER_PAY_SUCCESS, [
                        'character_string2' => $orderId,
                        'thing3' => mb_substr($title, 0, 20, 'utf-8'),
                        'amount5' => $order['pay_price'],
                        'time4' => date('Y-m-d H:i:s', time())
                    ], $site_url . Url::build('wap/special/grade_special'));
                    WechatTemplateService::sendAdminNoticeTemplate($order['mer_id'], [
                        'character_string2' => $orderId,
                        'thing3' => mb_substr($title, 0, 20, 'utf-8'),
                        'amount5' => $order['pay_price'],
                        'time4' => date('Y-m-d H:i:s', time())
                    ]);
                } else {
                    $data['character_string1']['value'] = $orderId;
                    $data['amount3']['value'] = $order['pay_price'];
                    $data['time2']['value'] = date('Y-m-d H:i:s', time());
                    $data['thing6']['value'] = '您購買的專題已支付成功!';
                    RoutineTemplate::sendOrderSuccess($data, $order['uid'], $site_url . Url::build('wap/special/grade_special'));
                    $dataAdmin['character_string1']['value'] = $orderId;
                    $dataAdmin['amount3']['value'] = $order['pay_price'];
                    $dataAdmin['time2']['value'] = date('Y-m-d H:i:s', time());
                    $dataAdmin['thing6']['value'] = '您有一個新的課程訂單!';
                    RoutineTemplate::sendAdminNoticeTemplate($dataAdmin);
                }
            } catch (\Throwable $e) {
            }
            $res = $res1 && $resPink && $res2 && $res3;
            return false !== $res;
        }


    /**
         * 一級推廣 專題
         * @param $orderInfo
         * @return bool
         */
        public static function backOrderBrokerage($orderInfo)
        {
            $userInfo = self::getUserData($orderInfo['uid']);
            if (!$userInfo || !$userInfo['spread_uid']) return true;
            $storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ?: 1;//獲取后臺分銷類型
            if ($storeBrokerageStatu == 1) {
                if (!self::be(['uid' => $userInfo['spread_uid'], 'is_promoter' => 1])) return true;
            }
            $data = Special::getIndividualDistributionSettings($orderInfo['cart_id']);
            if (isset($data['is_alone']) && $data['is_alone']) {
                if (!isset($data['brokerage_ratio']) || !$data['brokerage_ratio']) return true;
                $brokerageRatio = bcdiv($data['brokerage_ratio'], 100, 2);
            } else {
                $course_distribution_switch = SystemConfigService::get('course_distribution_switch');//課程分銷開關
                if ($course_distribution_switch == 0) return true;
                $brokerageRatio = bcdiv(SystemConfigService::get('store_brokerage_ratio'), 100, 2);
            }
            if ($brokerageRatio <= 0) return true;
            $brokeragePrice = bcmul($orderInfo['pay_price'], $brokerageRatio, 2);
            if ($brokeragePrice <= 0) return true;
            $mark = '一級推廣人' . $userInfo['nickname'] . '消費' . floatval($orderInfo['pay_price']) . '元購買專題,獎勵推廣傭金' . floatval($brokeragePrice);
            $bill = UserBill::billDoesDataExist($userInfo['spread_uid'], 'now_money', 'brokerage', $brokeragePrice, $orderInfo['id']);
            if ($bill) return true;
            self::beginTrans();
            $res1 = UserBill::income('購買專題返傭', $userInfo['spread_uid'], 'now_money', 'brokerage', $brokeragePrice, $orderInfo['id'], 0, $mark);
            $res2 = self::bcInc($userInfo['spread_uid'], 'brokerage_price', $brokeragePrice, 'uid');
            $User = self::getUserData($userInfo['spread_uid']);
            if (!$User) {
                self::checkTrans(false);
                return true;
            }
            $wechat_notification_message = SystemConfigService::get('wechat_notification_message');
            if (!$wechat_notification_message) {
                $dat['thing8']['value'] = '返傭金額';
                $dat['date4']['value'] = date('Y-m-d H:i:s', time());
                $dat['amount1']['value'] = $brokeragePrice;
                $dat['amount2']['value'] = $User['brokerage_price'];
                $dat['thing5']['value'] = '您收到一筆專題返傭!';
                RoutineTemplate::sendAccountChanges($dat, $userInfo['spread_uid'], Url::build('wap/spread/commission', [], true, true));
            }
            $dats['brokerage_price'] = $brokeragePrice;
            SmsTemplate::sendSms($userInfo['spread_uid'], $dats, 'ORDER_BROKERAGE');
            $res = $res1 && $res2;
            self::checkTrans($res);
            if ($res) self::backOrderBrokerageTwo($orderInfo);
            return $res;
        }
    
        /**
         * 二級推廣 專題
         * @param $orderInfo
         * @return bool
         */
        public static function backOrderBrokerageTwo($orderInfo)
        {
            $userInfo = self::getUserData($orderInfo['uid']);
            $userInfoTwo = self::getUserData($userInfo['spread_uid']);
            if (!$userInfoTwo || !$userInfoTwo['spread_uid']) return true;
            $storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ?: 1;//獲取后臺分銷類型
            if ($storeBrokerageStatu == 1) {
                if (!self::be(['uid' => $userInfoTwo['spread_uid'], 'is_promoter' => 1])) return true;
            }
            $data = Special::getIndividualDistributionSettings($orderInfo['cart_id']);
            if (isset($data['is_alone']) && $data['is_alone']) {
                if (!isset($data['brokerage_two']) || !$data['brokerage_two']) return true;
                $brokerageRatio = bcdiv($data['brokerage_two'], 100, 2);
            } else {
                $course_distribution_switch = SystemConfigService::get('course_distribution_switch');//課程分銷開關
                if ($course_distribution_switch == 0) return true;
                $brokerageRatio = bcdiv(SystemConfigService::get('store_brokerage_two'), 100, 2);
            }
            if ($brokerageRatio <= 0) return true;
            $brokeragePrice = bcmul($orderInfo['pay_price'], $brokerageRatio, 2);
            if ($brokeragePrice <= 0) return true;
            $mark = '二級推廣人' . $userInfo['nickname'] . '消費' . floatval($orderInfo['pay_price']) . '元購買專題,獎勵推廣傭金' . floatval($brokeragePrice);
            $bill = UserBill::billDoesDataExist($userInfo['spread_uid'], 'now_money', 'brokerage', $brokeragePrice, $orderInfo['id']);
            if ($bill) return true;
            self::beginTrans();
            $res1 = UserBill::income('購買專題返傭', $userInfoTwo['spread_uid'], 'now_money', 'brokerage', $brokeragePrice, $orderInfo['id'], 0, $mark);
            $res2 = self::bcInc($userInfoTwo['spread_uid'], 'brokerage_price', $brokeragePrice, 'uid');
            $User = self::getUserData($userInfoTwo['spread_uid']);
            if (!$User) {
                self::checkTrans(false);
                return true;
            }
            $wechat_notification_message = SystemConfigService::get('wechat_notification_message');
            if (!$wechat_notification_message) {
                $dat['thing8']['value'] = '返傭金額';
                $dat['date4']['value'] = date('Y-m-d H:i:s', time());
                $dat['amount1']['value'] = $brokeragePrice;
                $dat['amount2']['value'] = $User['brokerage_price'];
                $dat['thing5']['value'] = '您收到一筆專題返傭!';
                RoutineTemplate::sendAccountChanges($dat, $userInfoTwo['spread_uid'], Url::build('wap/spread/commission', [], true, true));
            }
            $dats['brokerage_price'] = $brokeragePrice;
            SmsTemplate::sendSms($userInfoTwo['spread_uid'], $dats, 'ORDER_BROKERAGE');
            $res = $res1 && $res2;
            self::checkTrans($res);
            return $res;
        }
    

    這樣專題課程的二級分銷就完成了,若是想再加第三級分銷,我們一樣的邏輯,獲取二級的上級,然后判斷返傭即可。

    請登錄后查看

    全 最后編輯于2025-03-19 17:29:01

    快捷回復
    回復
    回復
    回復({{post_count}}) {{!is_user ? '我的回復' :'全部回復'}}
    排序 默認正序 回復倒序 點贊倒序

    {{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level }}

    作者 管理員 企業

    {{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
    {{item.is_suggest == 1? '取消推薦': '推薦'}}
    沙發 板凳 地板 {{item.floor}}#
    {{item.user_info.title || '暫無簡介'}}
    附件

    {{itemf.name}}

    {{item.created_at}}  {{item.ip_address}}
    打賞
    已打賞¥{{item.reward_price}}
    {{item.like_count}}
    {{item.showReply ? '取消回復' : '回復'}}
    刪除
    回復
    回復

    {{itemc.user_info.nickname}}

    {{itemc.user_name}}

    回復 {{itemc.comment_user_info.nickname}}

    附件

    {{itemf.name}}

    {{itemc.created_at}}
    打賞
    已打賞¥{{itemc.reward_price}}
    {{itemc.like_count}}
    {{itemc.showReply ? '取消回復' : '回復'}}
    刪除
    回復
    回復
    查看更多
    打賞
    已打賞¥{{reward_price}}
    770
    {{like_count}}
    {{collect_count}}
    添加回復 ({{post_count}})

    相關推薦

    快速安全登錄

    使用微信掃碼登錄
    {{item.label}} 加精
    {{item.label}} {{item.label}} 板塊推薦 常見問題 產品動態 精選推薦 首頁頭條 首頁動態 首頁推薦
    取 消 確 定
    回復
    回復
    問題:
    問題自動獲取的帖子內容,不準確時需要手動修改. [獲取答案]
    答案:
    提交
    bug 需求 取 消 確 定
    打賞金額
    當前余額:¥{{rewardUserInfo.reward_price}}
    {{item.price}}元
    請輸入 0.1-{{reward_max_price}} 范圍內的數值
    打賞成功
    ¥{{price}}
    完成 確認打賞

    微信登錄/注冊

    切換手機號登錄

    {{ bind_phone ? '綁定手機' : '手機登錄'}}

    {{codeText}}
    切換微信登錄/注冊
    暫不綁定
    亚洲欧美字幕
    CRMEB客服

    CRMEB咨詢熱線 咨詢熱線

    400-8888-794

    微信掃碼咨詢

    CRMEB開源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
    返回頂部 返回頂部
    CRMEB客服