dever il y a 4 ans
Parent
commit
b077bea5bf
5 fichiers modifiés avec 168 ajouts et 28 suppressions
  1. 72 6
      database/freight.php
  2. 14 1
      database/info.php
  3. 21 0
      database/order.php
  4. 50 18
      lib/Info.php
  5. 11 3
      lib/Pay.php

+ 72 - 6
database/freight.php

@@ -4,6 +4,13 @@ $type = array
 	1 => '数值',
 	2 => '百分比',
 );
+
+$pricing_type = array
+(
+	1 => '按件数',
+	//2 => '按重量',
+	//3 => '按体积',
+);
 return array
 (
 	# 表名
@@ -39,16 +46,29 @@ return array
 			'list'		=> 'Dever::load("category/api.string", "{category}")',
 		),
 
+		'goods_area'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '商品所在地区-先按照省份计算',
+			'default' 	=> '',
+			'desc' 		=> '商品所在地区',
+			'match' 	=> 'is_string',
+			//'search'	=> 'linkage',
+			'update'	=> 'linkage',
+			'option'	=> Dever::url('api.get?level_total=1', 'area'),
+			'list'		=> 'Dever::load("area/api.string", "{goods_area}")',
+		),
+
 		'area'		=> array
 		(
-			'type' 		=> 'varchar-500',
-			'name' 		=> '地区',
+			'type' 		=> 'int-11',
+			'name' 		=> '送达地区',
 			'default' 	=> '',
-			'desc' 		=> '地区',
+			'desc' 		=> '送达地区',
 			'match' 	=> 'is_string',
 			'search'	=> 'linkage',
 			'update'	=> 'linkage',
-			'option'	=> Dever::url('api.get', 'area'),
+			'option'	=> Dever::url('api.get?level_total=1', 'area'),
 			'list'		=> 'Dever::load("area/api.string", "{area}")',
 		),
 
@@ -61,14 +81,38 @@ return array
 			'match' 	=> 'option',
 			'update'	=> 'radio',
 			'option'	=> $type,
+			//'list'		=> true,
+			//'search'	=> 'select',
+		),
+
+		'pricing_type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '计价类型',
+			'default' 	=> '1',
+			'desc' 		=> '计价类型',
+			'match' 	=> 'option',
+			'update'	=> 'radio',
+			'option'	=> $pricing_type,
 			'list'		=> true,
 			'search'	=> 'select',
 		),
+
+		'first_num'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '首件数量-如果计价类型是按重量,这里就是首件的重量,这里填写了2,就是满2件算首件',
+			'default' 	=> '',
+			'desc' 		=> '首件数量',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
 		
-		'price'		=> array
+		'first_price'		=> array
 		(
 			'type' 		=> 'int-11',
-			'name' 		=> '运费价格-如果是百分比类型,这里如果填的是10,那就是总价的10%',
+			'name' 		=> '首件价格-如果是百分比类型,这里如果填的是10,那就是总价的10%',
 			'default' 	=> '',
 			'desc' 		=> '运费价格',
 			'match' 	=> 'is_numeric',
@@ -76,6 +120,28 @@ return array
 			'list'		=> true,
 		),
 
+		'next_num'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '续件数量-如果计价类型是按重量,这里就是续件的重量',
+			'default' 	=> '',
+			'desc' 		=> '续件数量',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+		
+		'next_price'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '续件价格-如果是百分比类型,这里如果填的是10,那就是总价的10%',
+			'default' 	=> '',
+			'desc' 		=> '续件价格',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
 		'free'		=> array
 		(
 			'type' 		=> 'int-11',

+ 14 - 1
database/info.php

@@ -218,6 +218,19 @@ $config = array
 			'update'	=> 'text',
 		),
 
+		'goods_area'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '所在地区',
+			'default' 	=> '',
+			'desc' 		=> '所在地区',
+			'match' 	=> 'is_string',
+			//'search'	=> 'linkage',
+			'update'	=> 'linkage',
+			'option'	=> Dever::url('api.get?level_total=1', 'area'),
+			//'list'		=> 'Dever::load("area/api.string", "{goods_area}")',
+		),
+
 		'brand_id'		=> array
 		(
 			'type' 		=> 'int-11',
@@ -548,7 +561,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,type,price_type,price,s_price,num,link,code,mode',
+            'col' => 'id,name,category,brand_id,shop_id,pic_cover,pic,sell_num+sell_add_num as sell_num,content,type,price_type,price,s_price,num,link,code,mode,goods_area',
         ),
 	),
 );

+ 21 - 0
database/order.php

@@ -144,6 +144,27 @@ $config = array
 			'list'		=> true,
 		),
 
+		'freight_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '运费模板',
+			'default' 	=> '',
+			'desc' 		=> '运费模板',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+		),
+
+		'freight_price'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '运费',
+			'default' 	=> '',
+			'desc' 		=> '运费',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
 		'system_source'     => array
         (
             'type'      => 'tinyint-1',

+ 50 - 18
lib/Info.php

@@ -240,16 +240,25 @@ class Info
     }
 
     # 获取支付所需要的信息
-    public function getPayInfo($id, $sku)
+    public function getPayInfo($id, $sku, $num = 1, $user = array())
     {
         $info = Dever::db($this->table_info)->getOne($id);
 
-        if ($info && $sku > 0) {
-            $where['info_id'] = $info['id'];
-            $where['id'] = $sku;
-            $sku = Dever::db('goods/info_sku')->one($where);
-            if ($sku) {
-                $info['price'] = $sku['price'];
+        if ($info) {
+            $info['freight_id'] = 0;
+            $info['freight_price'] = 0;
+            if ($sku > 0) {
+                $where['info_id'] = $info['id'];
+                $where['id'] = $sku;
+                $sku = Dever::db('goods/info_sku')->one($where);
+                if ($sku) {
+                    $info['price'] = $sku['price'];
+                }
+            }
+            $freight = $this->freight($info, $info['price'], $user, $num);
+            if ($freight) {
+                $info['freight_id'] = $freight['id'];
+                $info['freight_price'] = $freight['price'];
             }
         }
 
@@ -257,12 +266,12 @@ class Info
     }
 
     # 获取基本信息
-    public function getInfo($id, $attr = true, $order = 'view_reorder')
+    public function getInfo($id, $attr = true, $order = 'view_reorder', $user = array())
     {
         $info = Dever::db($this->table_info)->getOne($id);
 
         if ($info && $attr) {
-            $info = $this->info($info, $order);
+            $info = $this->info($info, $order, false, $user);
         }
 
         if ($info['pic']) {
@@ -273,14 +282,8 @@ class Info
     }
 
     # 获取基本信息
-    public function info($info, $key = 'list_reorder', $is_sell = false)
+    public function info($info, $key = 'list_reorder', $is_sell = false, $user = array())
     {
-        $info['freight'] = 0;
-        if ($info['type'] == 1) {
-            # 获取运费
-            $info['freight'] = $this->freight($info);
-        }
-        
         if ($info['price_type'] == 2) {
             
             $attr = $this->setAttr($info['category'], $key);
@@ -341,28 +344,57 @@ class Info
 
         $info = $this->getInfoLink($info);
 
+        $info['freight'] = 0;
+        if ($info['type'] == 1) {
+            # 获取运费
+            $info['freight'] = $this->freight($info, $info['price']['min']['price'], $user);
+        }
+
     	return $info;
     }
 
-    private function freight($info)
+    # 运费计算,暂时用省份代表地区
+    private function freight($info, $goods_price, $user = array(), $num = 1)
     {
-        # 之后要加入当前用户的地理位置
         $array = explode(',', $info['category']);
         $cate = $freight = array();
         $total = count($array);
         $total -= 1;
+        if ($info && $info['goods_area']) {
+            $where['goods_area'] = $info['goods_area'];
+        }
+        # 用户所在地理位置 
+        if ($user && $user['area_id']) {
+            $area = explode(',', $user['area_id']);
+            $where['area'] = $area[0];
+        }
         foreach ($array as $k => $v) {
             $cate[$k] = $v;
             if ($k < $total) {
                 $cate[] = '-1';
             }
             $where['category'] = $cate;
+
             $data = Dever::db('goods/freight')->one($where);
             if ($data) {
                 $freight = $data;
             }
         }
 
+        if ($freight) {
+            $price = $freight['first_price'];
+            if ($num > $freight['first_num']) {
+                $num = $num - $freight['first_num'];
+                $price = $freight['first_price'] + ($freight['next_price']*$num);
+            }
+
+            if ($freight['type'] == 2) {
+                $freight['price'] = $goods_price*($price/100);
+            } else {
+                $freight['price'] = $price;
+            }
+        }
+
         return $freight;
     }
 

+ 11 - 3
lib/Pay.php

@@ -9,13 +9,18 @@ use Dever;
 class Pay
 {
     # 发起支付
-	public function action($parent_uid, $uid, $id, $sku, $num, $address_id, $system_source, $type = false, $type_id = false)
+	public function action($parent_uid, $user, $id, $sku, $num, $address_id, $system_source, $type = false, $type_id = false)
     {
-        if (!$uid) {
+        if (!$user) {
             Dever::alert('错误的用户信息');
         }
 
-        $goods = Dever::load('goods/lib/info')->getPayInfo($id, $sku);
+        $uid = $user['id'];
+
+        $goods = Dever::load('goods/lib/info')->getPayInfo($id, $sku, $num, $user);
+        if (!$goods) {
+            Dever::alert('错误的商品信息');
+        }
         $shop = Dever::db('goods/shop')->one($goods['shop_id']);
         
         if ($parent_uid) {
@@ -30,9 +35,12 @@ class Pay
         $order_data['address_id'] = $address_id;
         $order_data['name'] = $goods['name'];
         $order_data['cash'] = $goods['price'];
+        $order_data['freight_id'] = $goods['freight_id'];
+        $order_data['freight_price'] = $goods['freight_price'];
         $order_data['num'] = $num;
         $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) {