Home php教程 php手册 ecshop自动分成二次开发实例

ecshop自动分成二次开发实例

May 22, 2016 pm 06:38 PM
foreach undefined

自动分成功能在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);
}
Copy after login

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

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


永久地址:

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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList? What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList? Apr 27, 2023 pm 03:40 PM

1. The difference between Iterator and foreach is the polymorphic difference (the bottom layer of foreach is Iterator) Iterator is an interface type, it does not care about the type of collection or array; both for and foreach need to know the type of collection first, even the type of elements in the collection; 1. Why is it said that the bottom layer of foreach is the code written by Iterator: Decompiled code: 2. The difference between remove in foreach and iterator. First, look at the Alibaba Java Development Manual, but no error will be reported in case 1, and an error will be reported in case 2 (java. util.ConcurrentModificationException) first

How to determine the number of foreach loop in php How to determine the number of foreach loop in php Jul 10, 2023 pm 02:18 PM

​The steps for PHP to determine the number of the foreach loop: 1. Create an array of "$fruits"; 2. Create a counter variable "$counter" with an initial value of 0; 3. Use "foreach" to loop through the array, and Increase the value of the counter variable in the loop body, and then output each element and their index; 4. Output the value of the counter variable outside the "foreach" loop to confirm which element the loop reaches.

Solution to PHP Notice: Undefined property: Solution to PHP Notice: Undefined property: Jun 22, 2023 pm 02:48 PM

When writing code in PHP, we may encounter the error message "Notice: Undefinedproperty". This error means that we are accessing an undefined property, usually because the property has not been initialized in the code. So, how to solve this problem? Here are a few possible solutions: Initialize properties This is the simplest way to solve this problem. Explicitly initializing a property in code ensures that it is defined before use. For example: class

TypeError: Cannot read property '$XXX' of undefined in Vue, how to deal with it? TypeError: Cannot read property '$XXX' of undefined in Vue, how to deal with it? Nov 25, 2023 pm 12:14 PM

If you often encounter the error message "TypeError: Cannotreadproperty'$XXX'ofundefined" when developing with Vue.js, how should you deal with it? This article explains the causes of this error and how to fix it. The cause of the problem is that when using Vue.js, we often use this to call methods of Vue components, such as: exportdefault{data()

PHP returns an array with key values ​​flipped PHP returns an array with key values ​​flipped Mar 21, 2024 pm 02:10 PM

This article will explain in detail how PHP returns an array after key value flipping. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP Key Value Flip Array Key value flip is an operation on an array that swaps the keys and values ​​in the array to generate a new array with the original key as the value and the original value as the key. Implementation method In PHP, you can perform key-value flipping of an array through the following methods: array_flip() function: The array_flip() function is specially used for key-value flipping operations. It receives an array as argument and returns a new array with the keys and values ​​swapped. $original_array=[

What do undefined and null mean? What do undefined and null mean? Nov 20, 2023 pm 02:39 PM

In JavaScript, both undefined and null represent the concept of "nothing": 1. undefined represents an uninitialized variable or a non-existent property. When a variable is declared but no value is assigned to it, the value of the variable is undefined , when accessing properties that do not exist in the object, the returned value is also undefined; 2. null represents an empty object reference. In some cases, the object reference can be set to null to release the memory it occupies.

what is undefined what is undefined Jul 31, 2023 pm 02:28 PM

undefined represents a state in which a value or variable does not exist or is undefined. It can be used as a default value to determine whether a variable has been assigned a value, and can also be used to set default parameter values. Although undefined may have different meanings and usages in different programming languages, understanding the concept of undefined can help us better understand and write programs.

How to solve 'undefined: path.Join' error in golang? How to solve 'undefined: path.Join' error in golang? Jun 24, 2023 pm 01:12 PM

In the Go language, the path package is one of the important tools for processing file paths. The path.Join() function can combine multiple paths into a complete path. However, sometimes you will encounter the error message "undefined: path.Join", what should you do? Here are several common solutions: Check the import statement First, you need to confirm that you have imported the path package correctly. In Go language, when importing a package, you can

See all articles