Ecshop is automatically divided into secondary development instances

Source: Internet
Author: User
Tags sprintf

Rough logic:
The background operation automatically divides an order when it is delivered. The background cancels the delivery and returns the order. Instead, it removes the automatic parts when it is not delivered.
Core code: lib_common.php

// Function fenchenjifen ($ usertype = 3, $ point) {$ affiliate = unserialize ($ GLOBALS ['_ CFG'] ['affiliate']); if ($ usertype = 3) {// purchase 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) {// dealer 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) {// Financial 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 und Efined $ order information * @ param undefined $ buyuser purchaser information * @ param undefined $ integral calculation points * $ type = 1 increase $ type =-1 undo * split into log status 99 */ function fun_fencheng_change ($ order, $ buyuser, $ integral = array (), $ type = 1) {// shop partition calculation 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': // buyer type $ row = $ GLOBALS ['DB']-> getRow ("SELECT * from ". $ GLOBALS ['ecs']-> table ('users '). "u ". "WHERE u. shopid = ". $ order ['parent _ shopid ']. "and u. usertype = 1 "); // Obtain the pid $ up_uid = $ row ['User _ id']; if (! Empty ($ up_uid) & $ up_uid> 0) {$ money = $ point = 0; $ point = fenchenjifen (1, $ integral ['m M _ points']); // $ info = sprintf ($ GLOBALS ['_ LANG'] ['separate _ info'], $ order ['Order _ sn '], $ money, $ point ); $ info = "order ". $ order ['Order _ sn ']. "Points for splitting :". $ 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) {// the dealer and finance are divided into if ($ val [ 'Usertype'] = 1) {$ pointf = fenchenjifen (1, $ integral ['m M _ points ']);} if ($ val ['usertype'] = 2) {$ pointf = fenchenjifen (2, $ integral ['m M _ points']);} $ up_uid = $ val ['User _ id']; // $ info = sprintf ($ GLOBALS ['_ LANG'] ['separate _ info'], $ order ['Order _ sn '], $ money, $ pointf); $ info = "order ". $ order ['Order _ sn ']. "Points for splitting :". $ 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 * The write order is divided into log */function write_affiliate_log1 ($ oid, $ uid, $ username, $ money, $ point, $ separate_by) {$ time = gmtime (); $ SQL = "INSERT ". $ GLOBALS ['ecs']-> table ('affiliate _ log '). "(order_id, user_id, user_name, time, money, point, separate_type )". "VALUES ('$ ID',' $ uid', '$ username',' $ time', '$ money',' $ point', $ separate_by )"; if ($ oid) {$ GLOBALS ['DB']-> query ($ SQL) ;}// revoke the order into 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 );}


Notes:
The background shipping program is in admin/order. php
The items to be modified are as follows: Ship 866 rows, cancel shipping 1035 rows, and change to 3961 rows without shipping.
This code only calculates the parts. Order part separately.
This code is divided into multiple merchants according to the store ID. This is the secondary development version of ecshop. Cannot be used in the original version.
Call splitting: fun_fencheng_change ($ order, $ user, $ integral, 1 );
Unsharding: fun_fencheng_change ($ order, $ user, $ integral,-1 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.