首页 > php教程 > php手册 > 正文

ecshop自动分成二次开发实例

php中文网
发布: 2016-05-22 18:38:44
原创
1997人浏览过

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

大概逻辑:

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

核心代码:lib_common.php

//分成积分计算

<?php
function fenchenjifen($usertype = 3, $point) {
    $affiliate = unserialize($GLOBALS['_CFG']['affiliate']);
    if ($usertype == 3) { //采购
        if ($affiliate['config']['level_register_up']) {
            $affiliate['config']['level_register_up']/= 100;
        }
        $point_cg = round($affiliate['config']['level_register_up'] * intval($point) , 0);
        return $point_cg;
    }
    if ($usertype == 1) { //经销商
        if ($affiliate['config']['level_money_all']) {
            $affiliate['config']['level_money_all']/= 100;
        }
        $point_cg = round($affiliate['config']['level_money_all'] * intval($point) , 0);
        return $point_cg;
    }
    if ($usertype == 2) { //财务
        if ($affiliate['config']['level_register_all']) {
            $affiliate['config']['level_register_all']/= 100;
        }
        $point_cg = round($affiliate['config']['level_register_all'] * 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['parent_shopid']) == 0) return false;
    if (!is_array($buyuser)) return false;
    $order_id = $order['order_id'];
    $separate_by = 99;
    switch ($buyuser['usertype']) {
        case '0': //购买者类型
            $row = $GLOBALS['db']->getRow("SELECT * from " . $GLOBALS['ecs']->table('users') . " u " . " WHERE u.shopid  =" . $order['parent_shopid'] . " and u.usertype=1"); //获取pid
            $up_uid = $row['user_id'];
            if (!empty($up_uid) && $up_uid > 0) {
                $money = $point = 0;
                $point = fenchenjifen(1, $integral['custom_points']);
                // $info = sprintf($GLOBALS['_LANG']['separate_info'], $order['order_sn'], $money, $point);
                $info = "订单" . $order['order_sn'] . "分成获得积分:" . $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['user_name'], $money, $point, $separate_by);
                } else {
                    rollback_affiliate_log($order_id);
                }
                $orderupdate['is_separate'] = $type == 1 ? $separate_by : 0;
                $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info') , $orderupdate, 'UPDATE', "order_id = '$order_id'");
            }
            break;
        case '3':
            $row = $GLOBALS['db']->getAll("SELECT u.shopid,u.user_id,u.usertype, u.user_name FROM " . $GLOBALS['ecs']->table('users') . " u " . " WHERE u.shopid= " . $order['parent_shopid'] . " and u.usertype in (1,2)");
            foreach ($row as $val) { // 经销商和财务获得分成
                if ($val['usertype'] == 1) {
                    $pointf = fenchenjifen(1, $integral['custom_points']);
                }
                if ($val['usertype'] == 2) {
                    $pointf = fenchenjifen(2, $integral['custom_points']);
                }
                $up_uid = $val['user_id'];
                //$info = sprintf($GLOBALS['_LANG']['separate_info'], $order['order_sn'], $money, $pointf);
                $info = "订单" . $order['order_sn'] . "分成获得积分:" . $pointf;
                log_account_change($up_uid, $money, 0, ($type) * $pointf, ($type) * $pointf, $info);
                if ($type == 1) {
                    write_affiliate_log1($order_id, $up_uid, $val['user_name'], $money, $pointf, $separate_by);
                } else {
                    rollback_affiliate_log($order_id);
                }
                $orderupdate['is_separate'] = $type == 1 ? $separate_by : 0;
                $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info') , $orderupdate, 'UPDATE', "order_id = '$order_id'");
            }
            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['ecs']->table('affiliate_log') . "( order_id, user_id, user_name, time, money, point, separate_type)" . " VALUES ( '$oid', '$uid', '$username', '$time', '$money', '$point', $separate_by)";
    if ($oid) {
        $GLOBALS['db']->query($sql);
    }
}
//撤销订单分成
function rollback_affiliate_log($order_id, $falg = - 2) {
    $sql = "UPDATE " . $GLOBALS['ecs']->table('affiliate_log') . " SET separate_type = '$falg'" . " WHERE order_id = '$order_id'";
    $GLOBALS['db']->query($sql);
}
登录后复制

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

东盟商机最新AC版As2007  SP1
东盟商机最新AC版As2007 SP1

AS系统本次的主要更新和新开发的功能如下(暂不详述): 1、修复了普及版的一些大大小小的BUG 2、重新规划整个后台,使后台更加个性化、智能化、更加易用 3、重写了广告部分模块,使其更加专业化 4、重写了文章采集模块,添加了定时自动采集功能 5、添加了供求信息采集功能 6、重写了友情连接功能(原来的太简单了) 8、重写了生成HTML模块。(几个主要模块首页不用原来的生成方式,不再会被卡巴斯机杀毒软

东盟商机最新AC版As2007  SP1 0
查看详情 东盟商机最新AC版As2007  SP1

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


永久地址:

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

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号