搜尋
首頁php教程php手册ecshop自动分成二次开发实例

自动分成功能在ecshop系统自带是没有的,如果我们需要对一单添加分成功能我们是需要进入二次开发的,下面小编来为各位介绍一个例子。

大概逻辑:

后台操作一个订单发货的时候进行自动分成,后台取消发货,退货,改为未发货的时候去掉自动分成部分。

核心代码:lib_common.php

//分成积分计算

<?php
function fenchenjifen($usertype = 3, $point) {
    $affiliate = unserialize($GLOBALS[&#39;_CFG&#39;][&#39;affiliate&#39;]);
    if ($usertype == 3) { //采购
        if ($affiliate[&#39;config&#39;][&#39;level_register_up&#39;]) {
            $affiliate[&#39;config&#39;][&#39;level_register_up&#39;]/= 100;
        }
        $point_cg = round($affiliate[&#39;config&#39;][&#39;level_register_up&#39;] * intval($point) , 0);
        return $point_cg;
    }
    if ($usertype == 1) { //经销商
        if ($affiliate[&#39;config&#39;][&#39;level_money_all&#39;]) {
            $affiliate[&#39;config&#39;][&#39;level_money_all&#39;]/= 100;
        }
        $point_cg = round($affiliate[&#39;config&#39;][&#39;level_money_all&#39;] * intval($point) , 0);
        return $point_cg;
    }
    if ($usertype == 2) { //财务
        if ($affiliate[&#39;config&#39;][&#39;level_register_all&#39;]) {
            $affiliate[&#39;config&#39;][&#39;level_register_all&#39;]/= 100;
        }
        $point_cg = round($affiliate[&#39;config&#39;][&#39;level_register_all&#39;] * intval($point) , 0);
        return $point_cg;
    }
}
/**
 *
 * @param undefined $order  订单信息
 * @param undefined $buyuser 购买者信息
 * @param undefined $integral 计算积分
 * $type = 1 增加  $type=-1 撤销
 * 分成log状态99
 */
function fun_fencheng_change($order, $buyuser, $integral = array() , $type = 1) { //店铺分成计算
    if (intval($order[&#39;parent_shopid&#39;]) == 0) return false;
    if (!is_array($buyuser)) return false;
    $order_id = $order[&#39;order_id&#39;];
    $separate_by = 99;
    switch ($buyuser[&#39;usertype&#39;]) {
        case &#39;0&#39;: //购买者类型
            $row = $GLOBALS[&#39;db&#39;]->getRow("SELECT * from " . $GLOBALS[&#39;ecs&#39;]->table(&#39;users&#39;) . " u " . " WHERE u.shopid  =" . $order[&#39;parent_shopid&#39;] . " and u.usertype=1"); //获取pid
            $up_uid = $row[&#39;user_id&#39;];
            if (!empty($up_uid) && $up_uid > 0) {
                $money = $point = 0;
                $point = fenchenjifen(1, $integral[&#39;custom_points&#39;]);
                // $info = sprintf($GLOBALS[&#39;_LANG&#39;][&#39;separate_info&#39;], $order[&#39;order_sn&#39;], $money, $point);
                $info = "订单" . $order[&#39;order_sn&#39;] . "分成获得积分:" . $point;
                log_account_change($up_uid, $money, 0, ($type) * $point, ($type) * $point, $info);
                //var_dump($info);
                if ($type == 1) {
                    write_affiliate_log1($order_id, $up_uid, $row[&#39;user_name&#39;], $money, $point, $separate_by);
                } else {
                    rollback_affiliate_log($order_id);
                }
                $orderupdate[&#39;is_separate&#39;] = $type == 1 ? $separate_by : 0;
                $GLOBALS[&#39;db&#39;]->autoExecute($GLOBALS[&#39;ecs&#39;]->table(&#39;order_info&#39;) , $orderupdate, &#39;UPDATE&#39;, "order_id = &#39;$order_id&#39;");
            }
            break;
        case &#39;3&#39;:
            $row = $GLOBALS[&#39;db&#39;]->getAll("SELECT u.shopid,u.user_id,u.usertype, u.user_name FROM " . $GLOBALS[&#39;ecs&#39;]->table(&#39;users&#39;) . " u " . " WHERE u.shopid= " . $order[&#39;parent_shopid&#39;] . " and u.usertype in (1,2)");
            foreach ($row as $val) { // 经销商和财务获得分成
                if ($val[&#39;usertype&#39;] == 1) {
                    $pointf = fenchenjifen(1, $integral[&#39;custom_points&#39;]);
                }
                if ($val[&#39;usertype&#39;] == 2) {
                    $pointf = fenchenjifen(2, $integral[&#39;custom_points&#39;]);
                }
                $up_uid = $val[&#39;user_id&#39;];
                //$info = sprintf($GLOBALS[&#39;_LANG&#39;][&#39;separate_info&#39;], $order[&#39;order_sn&#39;], $money, $pointf);
                $info = "订单" . $order[&#39;order_sn&#39;] . "分成获得积分:" . $pointf;
                log_account_change($up_uid, $money, 0, ($type) * $pointf, ($type) * $pointf, $info);
                if ($type == 1) {
                    write_affiliate_log1($order_id, $up_uid, $val[&#39;user_name&#39;], $money, $pointf, $separate_by);
                } else {
                    rollback_affiliate_log($order_id);
                }
                $orderupdate[&#39;is_separate&#39;] = $type == 1 ? $separate_by : 0;
                $GLOBALS[&#39;db&#39;]->autoExecute($GLOBALS[&#39;ecs&#39;]->table(&#39;order_info&#39;) , $orderupdate, &#39;UPDATE&#39;, "order_id = &#39;$order_id&#39;");
            }
            break;
    }
    return true;
}
/**
 *
 * @param undefined $oid
 * @param undefined $uid
 * @param undefined $username
 * @param undefined $money
 * @param undefined $point
 * @param undefined $separate_by
 * 写入订单分成 log
 */
function write_affiliate_log1($oid, $uid, $username, $money, $point, $separate_by) {
    $time = gmtime();
    $sql = "INSERT INTO " . $GLOBALS[&#39;ecs&#39;]->table(&#39;affiliate_log&#39;) . "( order_id, user_id, user_name, time, money, point, separate_type)" . " VALUES ( &#39;$oid&#39;, &#39;$uid&#39;, &#39;$username&#39;, &#39;$time&#39;, &#39;$money&#39;, &#39;$point&#39;, $separate_by)";
    if ($oid) {
        $GLOBALS[&#39;db&#39;]->query($sql);
    }
}
//撤销订单分成
function rollback_affiliate_log($order_id, $falg = - 2) {
    $sql = "UPDATE " . $GLOBALS[&#39;ecs&#39;]->table(&#39;affiliate_log&#39;) . " SET separate_type = &#39;$falg&#39;" . " WHERE order_id = &#39;$order_id&#39;";
    $GLOBALS[&#39;db&#39;]->query($sql);
}

需要注意的点:后台发货程序在admin / order . php需要修改的地方有:发货866行,取消发货1035行改为未发货3961行退货4132行。本代码只计算分成部分。自己下单部分另外。这个代码是按照店铺ID分成,多商户的。为ecshop二次开发版。无法用于原版。调用分成:fun_fencheng_change($order, $user, $integral, 1);

取消分成:fun_fencheng_change($order, $user, $integral, -1);


永久地址:

转载随意~请带上教程地址吧^^

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前By尊渡假赌尊渡假赌尊渡假赌
威爾R.E.P.O.有交叉遊戲嗎?
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具