当前位置:首页 > CMS教程 > ecshop > 列表

ecshop自动分成二次开发实例

发布:smiling 来源: PHP粉丝网  添加日期:2015-12-10 13:52:15 浏览: 评论:0 

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

大概逻辑:

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

核心代码:lib_common.php

  1. //分成积分计算 
  2.  
  3. function fenchenjifen($usertype=3,$point){
  4.  
  5.  $affiliate = unserialize($GLOBALS['_CFG']['affiliate']); 
  6.  
  7. if($usertype==3){   //采购                          
  8.  
  9.                 if ($affiliate['config']['level_register_up']) 
  10.  
  11.         { 
  12.  
  13.             $affiliate['config']['level_register_up'] /= 100; 
  14.  
  15.         } 
  16.  
  17.             $point_cg = round($affiliate['config']['level_register_up'] * intval($point), 0); 
  18.  
  19.             return $point_cg; 
  20.  
  21.         }    
  22.  
  23. if($usertype==1){//经销商 
  24.  
  25.         if ($affiliate['config']['level_money_all']) 
  26.  
  27.         { 
  28.  
  29.             $affiliate['config']['level_money_all'] /= 100; 
  30.  
  31.         } 
  32.  
  33.             $point_cg = round($affiliate['config']['level_money_all'] * intval($point), 0); 
  34.  
  35.             return $point_cg; 
  36.  
  37.         }    
  38.  
  39. if($usertype==2){//财务 
  40.  
  41.     if ($affiliate['config']['level_register_all']) 
  42.  
  43.         { 
  44.  
  45.             $affiliate['config']['level_register_all'] /= 100; 
  46.  
  47.         } 
  48.  
  49.             $point_cg = round($affiliate['config']['level_register_all'] * intval($point), 0); 
  50.  
  51.             return $point_cg; 
  52.  
  53.         }  
  54.  
  55. } 
  56.  
  57.    
  58. /** 
  59.  
  60. *  
  61.  
  62. * @param <a href="/tags.php/undefined/" target="_blank">undefined</a> $order  订单信息 
  63.  
  64. * @param undefined $buyuser 购买者信息 
  65.  
  66. * @param undefined $integral 计算积分 
  67.  
  68. * $type = 1 增加  $type=-1 撤销 
  69.  
  70. * 分成log状态99 
  71.  
  72. */ 
  73.  
  74. function fun_fencheng_change($order,$buyuser,$integral=array(),$type=1){//店铺分成计算 
  75.  
  76.     if(intval($order['parent_shopid'])==0) return false; 
  77.  
  78.     if(!is_array($buyuser)) return false; 
  79.  
  80.        
  81.  
  82.     $order_id=$order['order_id']; 
  83.  
  84.     $separate_by=99; 
  85.  
  86.     switch($buyuser['usertype']){ 
  87.  
  88.         case '0'://购买者类型 
  89.  
  90.          $row = $GLOBALS['db']->getRow("SELECT * from " . $GLOBALS['ecs']->table('users') . " u ". 
  91.  
  92.                     " WHERE u.shopid  =".$order['parent_shopid']." and u.usertype=1" 
  93.  
  94.                 );//获取pid 
  95.  
  96.            
  97.  
  98.             $up_uid = $row['user_id'];           
  99.  
  100.             if(!emptyempty($up_uid) && $up_uid > 0) 
  101.  
  102.             { 
  103.  
  104.                 $money=$point=0;     
  105.  
  106.                 $point= fenchenjifen(1,$integral['custom_points']);  
  107.  
  108.                            
  109.  
  110.                // $info = sprintf($GLOBALS['_LANG']['separate_info'], $order['order_sn'], $money, $point); 
  111.  
  112.                 $info="订单".$order['order_sn']."分成获得积分:".$point; 
  113.  
  114.                 log_account_change($up_uid, $money, 0, ($type)*$point, ($type)*$point, $info); 
  115.  
  116.                 //var_dump($info);   
  117.  
  118.                 if($type==1){            
  119.  
  120.                    
  121.  
  122.                 write_affiliate_log1($order_id, $up_uid, $row['user_name'], $money, $point, $separate_by); 
  123.  
  124.                 }else{ 
  125.  
  126.                     rollback_affiliate_log($order_id); 
  127.  
  128.                 } 
  129.  
  130.                 $orderupdate['is_separate']=$type==1?$separate_by:0; 
  131.  
  132.                  $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), 
  133.  
  134.         $orderupdate, 'UPDATE', "order_id = '$order_id'"); 
  135.  
  136.             } 
  137.  
  138.         break; 
  139.  
  140.         case '3': 
  141.  
  142.         $row = $GLOBALS['db']->getAll("SELECT u.shopid,u.user_id,u.usertype, u.user_name FROM " . $GLOBALS['ecs']->table('users') . " u ". 
  143.  
  144.                     " WHERE u.shopid= ".$order['parent_shopid']." and u.usertype in (1,2)"); 
  145.  
  146.                     <a href="/tags.php/foreach/" target="_blank">foreach</a>($row as $val){ // 经销商和财务获得分成 
  147.  
  148.                         if($val['usertype']==1){ 
  149.  
  150.                             $pointf = fenchenjifen(1,$integral['custom_points']);    
  151.  
  152.                             } 
  153.  
  154.                         if($val['usertype']==2){ 
  155.  
  156.                             $pointf = fenchenjifen(2,$integral['custom_points']);    
  157.  
  158.                             }    
  159.  
  160.                             $up_uid = $val['user_id']; 
  161.  
  162.                             //$info = sprintf($GLOBALS['_LANG']['separate_info'], $order['order_sn'], $money, $pointf); 
  163.  
  164.                             $info="订单".$order['order_sn']."分成获得积分:".$pointf; 
  165.  
  166.                 log_account_change($up_uid, $money, 0, ($type)*$pointf, ($type)*$pointf, $info); 
  167.  
  168.                    
  169.  
  170.                 if($type==1){            
  171.  
  172.                       write_affiliate_log1($order_id, $up_uid, $val['user_name'], $money, $pointf, $separate_by); 
  173.  
  174.                 }else{ 
  175.  
  176.                     rollback_affiliate_log($order_id); 
  177.  
  178.                 } 
  179.  
  180.                  $orderupdate['is_separate']=$type==1?$separate_by:0; 
  181.  
  182.                  $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), 
  183.  
  184.         $orderupdate, 'UPDATE', "order_id = '$order_id'");       
  185.  
  186.                     } 
  187.  
  188.            
  189.  
  190.         break; 
  191.  
  192.     } 
  193.  
  194.     return true; 
  195.  
  196. } 
  197.  
  198.    
  199.  
  200. /** 
  201.  
  202. *  
  203.  
  204. * @param undefined $oid 
  205.  
  206. * @param undefined $uid 
  207.  
  208. * @param undefined $username 
  209.  
  210. * @param undefined $money 
  211.  
  212. * @param undefined $point 
  213.  
  214. * @param undefined $separate_by 
  215.  
  216. * 写入订单分成 log 
  217.  
  218. */ 
  219.  
  220. function write_affiliate_log1($oid, $uid, $username, $money, $point, $separate_by) 
  221.  
  222. { 
  223.  
  224.     $time = gmtime(); 
  225.  
  226.     $sql = "INSERT INTO " . $GLOBALS['ecs']->table('affiliate_log') . "( order_id, user_id, user_name, time, money, point, separate_type)". 
  227.  
  228.                                                               " VALUES ( '$oid', '$uid', '$username', '$time', '$money', '$point', $separate_by)"; 
  229.  
  230.     if ($oid) 
  231.  
  232.     { 
  233.  
  234.         $GLOBALS['db']->query($sql); 
  235.  
  236.     } 
  237.  
  238. }  
  239.  
  240. //撤销订单分成 
  241.  
  242. function rollback_affiliate_log($order_id,$falg=-2){ 
  243. //phpfensi.com 
  244.       $sql = "UPDATE " . $GLOBALS['ecs']->table('affiliate_log') . 
  245.  
  246.                " SET separate_type = '$falg'" . 
  247.  
  248.                " WHERE order_id = '$order_id'"; 
  249.  
  250.          $GLOBALS['db']->query($sql); 
  251.  
  252. } 

需要注意的点:

后台发货程序在admin/order.php 需要修改的地方有:发货 866行,取消发货 1035行 改为未发货 3961行 退货4132行.

本代码只计算分成部分,自己下单部分另外.

这个代码是按照店铺ID分成,多商户的,为ecshop二次开发版,无法用于原版.

调用分成:fun_fencheng_change($order,$user,$integral,1);

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

Tags: ecshop二次开发 ecshop开发实例

分享到: