宅男在线永久免费观看网直播,亚洲欧洲日产国码无码久久99,野花社区在线观看视频,亚洲人交乣女bbw,一本一本久久a久久精品综合不卡

全部
常見問題
產(chǎn)品動(dòng)態(tài)
精選推薦

如何二開分銷功能

管理 管理 編輯 刪除

       首先我們要知道什么是分銷系統(tǒng)

      分銷系統(tǒng)指通過互聯(lián)網(wǎng)將供應(yīng)商與經(jīng)銷商有機(jī)地聯(lián)系在一起,為企業(yè)的業(yè)務(wù)經(jīng)營及與貿(mào)易伙伴的合作提供了一種全新的模式。供應(yīng)商、分支機(jī)構(gòu)和經(jīng)銷商之間可以實(shí)現(xiàn)實(shí)時(shí)地提交業(yè)務(wù)單據(jù)、查詢產(chǎn)品供應(yīng)和庫存狀況、并獲得市場、銷售信息及客戶支持,實(shí)現(xiàn)了供應(yīng)商、分支機(jī)構(gòu)與經(jīng)銷商之間端到端的供應(yīng)鏈管理,有效地縮短了供銷鏈。

      知識付費(fèi)的分銷功能主要體現(xiàn)在專題課程及會(huì)員模塊;用戶購買專題課程、會(huì)員后會(huì)給用戶的上級和上上級返傭。

那么分銷系統(tǒng)是如何實(shí)現(xiàn)的呢?

知識付費(fèi)系統(tǒng)中在用戶進(jìn)入系統(tǒng)時(shí)若是帶有上級的信息,那么這個(gè)用戶就是別的用戶發(fā)展的下級,我們就需要記錄該用戶的上級信息。數(shù)據(jù)庫用戶表eb_user表中有字段spread_uid(推廣員id),該字段記錄的是用戶的上級id。

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

然后就是分銷代碼的書寫了,知識付費(fèi)分銷分為人人分銷和指定分銷;人人分銷是指系統(tǒng)中的所有用戶均可參與分銷活動(dòng),并且在下級用戶購買后可以獲得傭金。指定分銷是指只有系統(tǒng)設(shè)置推廣權(quán)限的用戶才能在下級用戶購買后獲得傭金。因?yàn)橹R付費(fèi)的分銷是二級分銷,所有我們是直接寫了一級返傭和二級返傭的方法,在執(zhí)行完一級返傭后執(zhí)行二級返傭,這是分銷的最簡單邏輯了。

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

    /**
     * //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);//創(chuàng)建拼團(tuán)
        } 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'] = '您有一個(gè)新的課程訂單!';
                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');//課程分銷開關(guān)
            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'] . '消費(fèi)' . floatval($orderInfo['pay_price']) . '元購買專題,獎(jiǎng)勵(lì)推廣傭金' . 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');//課程分銷開關(guān)
            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'] . '消費(fèi)' . floatval($orderInfo['pay_price']) . '元購買專題,獎(jiǎng)勵(lì)推廣傭金' . 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

快捷回復(fù)
回復(fù)
回復(fù)
回復(fù)({{post_count}}) {{!is_user ? '我的回復(fù)' :'全部回復(fù)'}}
排序 默認(rèn)正序 回復(fù)倒序 點(diǎn)贊倒序

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

作者 管理員 企業(yè)

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

{{itemf.name}}

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

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回復(fù) {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

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

相關(guān)推薦

快速安全登錄

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

微信登錄/注冊

切換手機(jī)號登錄

{{ bind_phone ? '綁定手機(jī)' : '手機(jī)登錄'}}

{{codeText}}
切換微信登錄/注冊
暫不綁定
CRMEB客服

CRMEB咨詢熱線 咨詢熱線

400-8888-794

微信掃碼咨詢

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