dever 4 vuotta sitten
vanhempi
commit
1cd4b3f624
9 muutettua tiedostoa jossa 250 lisäystä ja 57 poistoa
  1. 7 7
      database/freight.php
  2. 32 7
      database/info.php
  3. 5 5
      database/info_sku.php
  4. 18 7
      database/order.php
  5. 111 0
      database/reward.php
  6. 50 5
      lib/Info.php
  7. 9 18
      lib/Manage.php
  8. 10 0
      lib/Order.php
  9. 8 8
      lib/Pay.php

+ 7 - 7
database/freight.php

@@ -111,11 +111,11 @@ return array
 		
 		'first_price'		=> array
 		(
-			'type' 		=> 'int-11',
+			'type' 		=> 'varchar-100',
 			'name' 		=> '首件价格-如果是百分比类型,这里如果填的是10,那就是总价的10%',
 			'default' 	=> '',
 			'desc' 		=> '运费价格',
-			'match' 	=> 'is_numeric',
+			'match' 	=> 'is_string',
 			'update'	=> 'text',
 			'list'		=> true,
 		),
@@ -133,23 +133,23 @@ return array
 		
 		'next_price'		=> array
 		(
-			'type' 		=> 'int-11',
+			'type' 		=> 'varchar-100',
 			'name' 		=> '续件价格-如果是百分比类型,这里如果填的是10,那就是总价的10%',
 			'default' 	=> '',
 			'desc' 		=> '续件价格',
-			'match' 	=> 'is_numeric',
+			'match' 	=> 'is_string',
 			'update'	=> 'text',
 			'list'		=> true,
 		),
 
 		'free'		=> array
 		(
-			'type' 		=> 'int-11',
+			'type' 		=> 'varchar-100',
 			'name' 		=> '总价满多少减免运费',
 			'default' 	=> '',
 			'desc' 		=> '满多少减免运费',
-			'match' 	=> 'is_numeric',
-			'update'	=> 'text',
+			'match' 	=> 'is_string',
+			//'update'	=> 'text',
 			//'list'		=> true,
 		),
 

+ 32 - 7
database/info.php

@@ -55,7 +55,11 @@ $mode = array
 	2 => '自提',
 	3 => '快递+自提',
 );
-
+$reward_type = array
+(
+    1 => '数值',
+    2 => '百分比',
+);
 $config = array
 (
 	# 表名
@@ -123,7 +127,7 @@ $config = array
 			'match' 	=> 'is_numeric',
 			'update'	=> 'radio',
 			'option'	=> $platform,
-			'control'	=> 'type',
+			'control'	=> 'platform',
 		),
 
 		'shape'		=> array
@@ -159,7 +163,7 @@ $config = array
 			'search'	=> 'fulltext',
 			//'list'		=> true,
 			//'edit'		=> true,
-			'show'		=> 'type=2,3,4,11',
+			'show'		=> 'platform=2,3,4,11',
 		),
 
 		'code'		=> array
@@ -173,7 +177,7 @@ $config = array
 			'search'	=> 'fulltext',
 			//'list'		=> true,
 			//'edit'		=> true,
-			'show'		=> 'type=2,4',
+			'show'		=> 'platform=2,4',
 		),
 
 		'price_type'		=> array
@@ -190,7 +194,7 @@ $config = array
 
 		'price'		=> array
 		(
-			'type' 		=> 'varchar-50',
+			'type' 		=> 'varchar-100',
 			'name' 		=> '售价',
 			'default' 	=> '',
 			'desc' 		=> '售价',
@@ -201,7 +205,7 @@ $config = array
 
 		's_price'		=> array
 		(
-			'type' 		=> 'varchar-50',
+			'type' 		=> 'varchar-100',
 			'name' 		=> '原价',
 			'default' 	=> '',
 			'desc' 		=> '原价',
@@ -220,6 +224,27 @@ $config = array
 			'update'	=> 'text',
 		),
 
+		'reward_type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '佣金类型',
+			'default' 	=> '1',
+			'desc' 		=> '佣金类型',
+			'match' 	=> 'option',
+			'update'	=> 'radio',
+			'option'	=> $reward_type,
+		),
+
+		'reward_value'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '佣金-如果此处填写值,则通用的佣金配置将失效',
+			'default' 	=> '',
+			'desc' 		=> '佣金',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+		),
+
 		'goods_area'		=> array
 		(
 			'type' 		=> 'int-11',
@@ -563,7 +588,7 @@ $config = array
                 'id' => 'yes',
             ),
             'type' => 'one',
-            'col' => 'id,name,category,brand_id,shop_id,pic_cover,pic,sell_num+sell_add_num as sell_num,content,platform,price_type,price,s_price,num,link,code,mode,goods_area',
+            'col' => 'id,name,category,brand_id,shop_id,pic_cover,pic,sell_num+sell_add_num as sell_num,content,platform,price_type,price,s_price,num-sell_num as num,link,code,mode,goods_area,shape,reward_value,reward_type',
         ),
 	),
 );

+ 5 - 5
database/info_sku.php

@@ -56,22 +56,22 @@ $config = array
 
 		'price'		=> array
 		(
-			'type' 		=> 'varchar-50',
+			'type' 		=> 'decimal-10,2',
 			'name' 		=> '售价',
 			'default' 	=> '',
 			'desc' 		=> '售价',
-			'match' 	=> 'is_string',
+			'match' 	=> 'is_numeric',
 			'update'	=> 'text',
 			'list'		=> true,
 		),
 
 		's_price'		=> array
 		(
-			'type' 		=> 'varchar-50',
+			'type' 		=> 'decimal-10,2',
 			'name' 		=> '原价',
 			'default' 	=> '',
 			'desc' 		=> '原价',
-			'match' 	=> 'is_string',
+			'match' 	=> 'is_numeric',
 			'update'	=> 'text',
 			'list'		=> true,
 		),
@@ -163,7 +163,7 @@ $config = array
 			),
 			'type' => 'all',
 			'order' => array('id' => 'desc'),
-			'col' => '*|key',
+			'col' => '*,num-sell_num as num|key',
 		),
 
 		'getMinOne' => array

+ 18 - 7
database/order.php

@@ -47,7 +47,7 @@ $config = array
                 'result' => 'id',
             ),
             'list_name'	=> '订单详情',
-            'list'		=> 'Dever::load("goods/manage.order", {id})',
+            'list'		=> 'Dever::load("goods/lib/manage.order", {id})',
             //'list'      => '{parent_uid} > 0 ? Dever::load("passport/user-one#username", {parent_uid}) : "无邀请人"',
         ),
 
@@ -85,7 +85,7 @@ $config = array
 			'name' 		=> '数据源id',
 			'default' 	=> '',
 			'desc' 		=> '数据源id',
-			//'match' 	=> 'is_numeric',
+			'match' 	=> 'is_numeric',
 			//'list'		=> true,
 		),
 
@@ -159,7 +159,7 @@ $config = array
 
 		'cash'		=> array
 		(
-			'type' 		=> 'decimal-10,2',
+			'type' 		=> 'varchar-100',
 			'name' 		=> '价格',
 			'default' 	=> '',
 			'desc' 		=> '价格',
@@ -179,6 +179,17 @@ $config = array
 			//'list'		=> true,
 		),
 
+		'reward'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '佣金',
+			'default' 	=> '',
+			'desc' 		=> '佣金',
+			'match' 	=> 'option',
+			//'update'	=> 'text',
+			//'list'		=> true,
+		),
+
 		'mode'		=> array
 		(
 			'type' 		=> 'int-11',
@@ -257,7 +268,7 @@ $config = array
 			'match' 	=> 'is_numeric',
 			'option'	=> $confirm,
 			'list'		=> true,
-			'edit'		=> true,
+			'edit'		=> '{status} == 2 ? true : false',
 		),
 
 		'freight_id'		=> array
@@ -271,7 +282,7 @@ $config = array
 
 		'freight_price'		=> array
 		(
-			'type' 		=> 'decimal-10,2',
+			'type' 		=> 'varchar-100',
 			'name' 		=> '运费',
 			'default' 	=> '',
 			'desc' 		=> '运费',
@@ -280,7 +291,7 @@ $config = array
 
 		'price'		=> array
 		(
-			'type' 		=> 'decimal-10,2',
+			'type' 		=> 'varchar-100',
 			'name' 		=> '最终付款价格',
 			'default' 	=> '',
 			'desc' 		=> '最终付款价格',
@@ -330,7 +341,7 @@ $config = array
             'desc'      => '付款时间',
             'match'     => 'option',
             'search'	=> 'date',
-            'list'      => '"{pay_time}" ? date("Y-m-d H:i:s", {pay_time}) : ""',
+            'list'      => '"{pay_time}" ? date("Y-m-d H:i:s", {pay_time}) : ""',
             //'update'    => 'date',
             //'callback'  => 'maketime',
         ),

+ 111 - 0
database/reward.php

@@ -0,0 +1,111 @@
+<?php
+$type = array
+(
+    1 => '数值',
+    2 => '百分比',
+);
+return array
+(
+    # 表名
+    'name' => 'reward',
+    # 显示给用户看的名称
+    'lang' => '佣金配置',
+    'order' => 2,
+
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'        => true,
+        ),
+
+        'category'      => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '分类',
+            'default'   => '',
+            'desc'      => '分类',
+            'match'     => 'is_string',
+            'search'    => 'linkage',
+            'update'    => 'linkage',
+            'option'    => Dever::url('api.get', 'category'),
+            'list'      => 'Dever::load("category/api.string", "{category}")',
+        ),
+
+        'type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '类型',
+			'default' 	=> '1',
+			'desc' 		=> '类型',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'radio',
+			'option'	=> $type,
+			'list'		=> true,
+			'search'	=> 'select',
+		),
+
+		'value'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '佣金-如果是百分比类型,这里如果填的是10,那就是总价的10%',
+			'default' 	=> '',
+			'desc' 		=> '佣金',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '录入时间',
+            'match'     => array('is_numeric', DEVER_TIME),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        //'delete' => false,
+        //'edit' => false,
+        //'insert' => false,
+    ),
+
+    'request' => array
+    (
+        # 列表
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'category' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'limit' => '0,10',
+            'col' => '*',
+        ),
+    )
+);

+ 50 - 5
lib/Info.php

@@ -260,6 +260,9 @@ class Info
                 $info['freight_id'] = $freight['id'];
                 $info['freight_price'] = $freight['price'];
             }
+
+            # 佣金计算
+            $info['reward'] = $this->reward($info, $info['price']*$num);
         }
 
         return $info;
@@ -304,12 +307,12 @@ class Info
     }
 
     # 获取基本信息
-    public function getInfo($id, $attr = true, $order = 'view_reorder', $user = array())
+    public function getInfo($id, $attr = true, $order = 'view_reorder', $user = array(), $reward = false)
     {
         $info = Dever::db($this->table_info)->getOne($id);
 
         if ($info && $attr) {
-            $info = $this->info($info, $order, false, $user);
+            $info = $this->info($info, $order, false, $user, $reward);
         }
 
         if ($info['pic']) {
@@ -320,7 +323,7 @@ class Info
     }
 
     # 获取基本信息
-    public function info($info, $key = 'list_reorder', $is_sell = false, $user = array())
+    public function info($info, $key = 'list_reorder', $is_sell = false, $user = array(), $reward = false)
     {
         if ($info['price_type'] == 2) {
             
@@ -383,14 +386,56 @@ class Info
         $info = $this->getInfoLink($info);
 
         $info['freight'] = 0;
-        if ($info['platform'] == 1) {
+        if ($info['platform'] == 1 && $user) {
             # 获取运费
             $info['freight'] = $this->freight($info, $info['price']['min']['price'], $user);
         }
+        # 佣金计算
+        if ($reward) {
+            $info['reward'] = $this->reward($info, $info['price']['min']['price']);
+        }
 
     	return $info;
     }
 
+    # 佣金计算
+    private function reward($info, $price)
+    {
+        if ($info['reward_value'] && $info['reward_value'] > 0) {
+            if ($info['reward_type'] == 2) {
+                $info['reward_value'] = round(($info['reward_value']/100) * $price, 2);
+            }
+            return $info['reward_value'];
+        }
+        $array = explode(',', $info['category']);
+        $cate = $reward = array();
+        $total = count($array);
+        $total -= 1;
+        foreach ($array as $k => $v) {
+            $cate[$k] = $v;
+            if ($k < $total) {
+                $cate[] = '-1';
+            }
+            $where['category'] = $cate;
+
+            $data = Dever::db('goods/reward')->one($where);
+            if ($data) {
+                $reward = $data;
+            }
+        }
+
+        if ($reward) {
+            if ($reward['value'] && $reward['value'] > 0) {
+                if ($reward['type'] == 2) {
+                    $reward['value'] = round(($reward['value']/100) * $price, 2);
+                }
+                return $reward['value'];
+            }
+        }
+
+        return 0;
+    }
+
     # 运费计算,暂时用省份代表地区
     private function freight($info, $goods_price, $user = array(), $num = 1)
     {
@@ -427,7 +472,7 @@ class Info
             }
 
             if ($freight['type'] == 2) {
-                $freight['price'] = $goods_price*$num*($price/100);
+                $freight['price'] = round($goods_price*$num*($price/100), 2);
             } else {
                 $freight['price'] = $price;
             }

+ 9 - 18
lib/Manage.php

@@ -159,11 +159,11 @@ class Manage
     {
         $info = Dever::db('goods/order')->one($id);
         if ($info) {
-            $table['编号'] = $info['id'];
-            $table['订单号'] = $info['order_id'];
+            $table['编号'] = '<font style="color:red">' . $info['id'] . '</font>';
+            $table['订单号'] = '<font style="color:blue">' . $info['order_id'] . '</font>';
             $config = Dever::db('goods/info')->config;
-            $table['平台'] = $config['platform'];
-            $table['形态'] = $config['shape'];
+            $table['平台'] = $config['config_platform'][$info['platform']];
+            $table['形态'] = $config['config_shape'][$info['shape']];
             if ($info['type'] == 'collection') {
                 $user = Dever::load('user/lib/info')->get($info['uid'], $info['type_id']);
             } else {
@@ -180,6 +180,7 @@ class Manage
                 }
                 
                 $table['邀请人'] = $user['username'] . '('.$user['mobile'].')';
+                $table['邀请人佣金'] = $info['parent_reward'] . '元';
             }
 
             $table['商品名'] = $info['name'];
@@ -187,10 +188,6 @@ class Manage
                 $sku = Dever::db('goods/info_sku')->one($info['sku_id']);
             }
 
-            $table['总价'] = $info['price'] . '元';
-            $table['单价'] = $info['cash'] . '元';
-            $table['数量'] = $info['num'];
-
             if ($info['mode'] > 0) {
                 $mode = $config['config_mode'];
                 $mode = $mode[$info['mode']];
@@ -205,24 +202,18 @@ class Manage
                     $table['联系人'] = $info['username'];
                     $table['联系电话'] = $info['mobile'];
                     $table['运费'] = $info['freight_price'];
-                    if ($info['confirm'] == 1) {
-                        $table['自提码'] = '未提';
-                    } else {
-                        $table['自提码'] = '已提';
-                    }
                 }
 
                 if ($info['store_id'] && $info['mode'] == 2) {
                     $store = Dever::db('goods/store')->one($info['store_id']);
                     $table['自提点'] = $store['name'];
                     $table['自提码'] = $info['id'];
-                    if ($info['confirm'] == 1) {
-                        $table['自提码'] = '未提';
-                    } else {
-                        $table['自提码'] = '已提';
-                    }
                 }
             }
+
+            $table['单价'] = $info['cash'] . '元';
+            $table['数量'] = $info['num'];
+            $table['总价'] = $info['price'] . '元';
         }
 
         return Dever::table($table);

+ 10 - 0
lib/Order.php

@@ -37,4 +37,14 @@ class Order
 
 		return $order;
 	}
+
+	# 验证是否买过
+	public function checkBuy($uid, $goods_id)
+	{
+		$where['uid'] = $uid;
+		$where['info_id'] = $goods_id;
+		$where['status'] = 2;
+
+		return Dever::db('goods/order')->one($where);
+	}
 }

+ 8 - 8
lib/Pay.php

@@ -9,7 +9,7 @@ use Dever;
 class Pay
 {
     # 发起支付
-	public function action($parent_uid, $user, $id, $sku, $num, $mode, $store_id, $system_source, $type = false, $type_id = false)
+	public function action($parent_uid, $user, $id, $sku, $num, $mode, $store_id, $system_source, $type = false, $type_id = false, $refer = '')
     {
         if (!$user) {
             Dever::alert('错误的用户信息');
@@ -51,9 +51,9 @@ class Pay
             $price += $order_data['freight_price'];
         }
         $order_data['price'] = $price;
+        $order_data['reward'] = $goods['reward'];
         $order_data['system_source'] = $system_source;
         $order_data['order_id'] = $this->getOrderId();
-        print_r($order_data);die;
         $id = Dever::db('goods/order')->insert($order_data);
 
         if (!$id) {
@@ -63,13 +63,14 @@ class Pay
         $param = array
         (
             'project_id' => 1,
-            'channel_id' => $shop['channel_id'],
+            'channel_id' => $shop['pay_channel'],
             'system_source' => $system_source,
             'uid' => $uid,
             'name' => $order_data['name'],
             'cash' => $price,
             'product_id' => $goods['id'],
             'order_id' => $order_data['order_id'],
+            'refer' => $refer,
         );
 
         $receipt = Dever::input('receipt');
@@ -107,8 +108,7 @@ class Pay
         $status = $send['pay_status'];
         $msg = $send['pay_msg'];
 
-        $order = Dever::db('goods/order')->one(array('order_id' => $order_id));
-
+        $order = Dever::db('goods/order')->one(array('order_id' => $order_id, 'time' => time()));
         if ($order && $order['status'] == 1) {
 
             if ($status == 2) {
@@ -124,12 +124,13 @@ class Pay
                 }
 
                 # 增加积分
-                if ($order['parent_uid'] > 0) {
+                if ($order['parent_uid'] > 0 && $order['parent_uid'] != $order['uid']) {
                     $uid = $order['parent_uid'] . '_' . $order['uid'];
+                    Dever::score($order['parent_uid'], 'sell_my_goods', '销售自营商品', false, $order['reward'], false, $order['type'], $order['type_id']);
                 } else {
                     $uid = $order['uid'];
                 }
-                Dever::score($uid, 'buy_my_goods', '购买自营商品', false, false, false, $order['type'], $order['type_id']);
+                Dever::score($uid, 'buy_my_goods', '购买自营商品', false, $order['reward'], false, $order['type'], $order['type_id']);
 
                 # 发消息
                 if (Dever::project('message')) {
@@ -137,7 +138,6 @@ class Pay
                 }
             }
 
-
             $update['status'] = $status;
             $update['where_id'] = $order['id'];
             $update['pay_time'] = time();