rabin 2 years ago
parent
commit
64b29f0441
4 changed files with 110 additions and 37 deletions
  1. 70 24
      database/address.php
  2. 1 1
      database/info.php
  3. 25 2
      lib/Address.php
  4. 14 10
      src/Address.php

+ 70 - 24
database/address.php

@@ -14,6 +14,11 @@ $tag = array
     4 => '其他',
 );
 
+$source_table = Dever::input('search_option_source_table');
+$source_id = Dever::input('search_option_source_id');
+
+$area_total = Dever::input('area_total', 3);
+
 return array
 (
     # 表名
@@ -42,7 +47,18 @@ return array
             //'list'        => true,
         ),
 
-        'uid'		=> array
+        'source_table'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '来源表名',
+			'default' 	=> '',
+			'desc' 		=> '来源表名',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'hidden',
+            'value'     => $source_table,
+		),
+
+        'source_id'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '用户名',
@@ -50,14 +66,14 @@ return array
 			'desc' 		=> '请选择用户',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'hidden',
-			'search'    => array
+			'search'    => $source_table ? array
             (
-                'api' => 'user/info-like',
+                'api' => $source_table . '-like',
                 'col' => 'search',
                 'result' => 'id',
-            ),
-            'value'     => Dever::input('search_option_uid'),
-			'list'       => 'Dever::load("user/lib/info.get#name", {uid})',
+            ) : false,
+            'value'     => $source_id,
+			'list'       => 'Dever::load("user/lib/address.getSource#name", "{source_table}", "{source_id}")',
 		),
 
 		'type'		=> array
@@ -68,12 +84,12 @@ return array
 			'desc' 		=> '类型',
 			'match' 	=> 'is_numeric',
 			'option' 	=> $type,
-			'update'	=> 'radio',
+			//'update'	=> 'radio',
 			'list'		=> true,
 			'order'		=> 'desc',
 		),
 
-		'truename'		=> array
+		'contacts'		=> array
 		(
 			'type' 		=> 'varchar-100',
 			'name' 		=> '联系人',
@@ -85,7 +101,7 @@ return array
 			'list'		=> true,
 		),
 
-		'tel'		=> array
+		'phone'		=> array
 		(
 			'type' 		=> 'varchar-100',
 			'name' 		=> '联系电话',
@@ -97,6 +113,19 @@ return array
 			'list'		=> true,
 		),
 
+		'area'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			'name' 		=> '城市地区',
+			'default' 	=> '',
+			'desc' 		=> '城市地区',
+			'match' 	=> 'is_string',
+			'search'	=> 'linkage',
+			'update'	=> 'linkage',
+			'option'	=> Dever::url('api.get?level_total=' . $area_total, 'area'),
+			'list'		=> 'Dever::load("area/api.string", "{area}")',
+		),
+
 		'province'		=> array
 		(
 			'type' 		=> 'int-11',
@@ -137,18 +166,23 @@ return array
 			//'update'	=> 'text',
 		),
 
-		'area'		=> array
-		(
-			'type' 		=> 'varchar-800',
-			'name' 		=> '城市地区',
-			'default' 	=> '',
-			'desc' 		=> '城市地区',
-			'match' 	=> 'is_string',
-			'search'	=> 'linkage',
-			'update'	=> 'linkage',
-			'option'	=> Dever::url('api.get?level_total=3', 'area'),
-			'list'		=> 'Dever::load("area/api.string", "{area}")',
-		),
+		'lng'       => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '经度',
+            'default'   => '',
+            'desc'      => '经度',
+            'match'     => 'option',
+        ),
+
+        'lat'       => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '纬度',
+            'default'   => '',
+            'desc'      => '纬度',
+            'match'     => 'option',
+        ),
 
 		'address'		=> array
 		(
@@ -169,8 +203,8 @@ return array
             'desc'      => '标签',
             'match'     => 'is_numeric',
             'option'    => $tag,
-            'update'    => 'radio',
-            'list'        => true,
+            //'update'    => 'radio',
+            //'list'        => true,
         ),
 
         'state'     => array
@@ -195,6 +229,17 @@ return array
         ),
     ),
 
+    'index' => array
+	(
+		1 => array
+		(
+			'source' => 'source_table,source_id,type',
+		),
+		
+		# 版本号 更改版本号会更新当前表的索引
+		'version' => 1,
+	),
+
     'manage' => array
     (
         
@@ -207,7 +252,8 @@ return array
 			# 匹配的正则或函数 选填项
 			'option' => array
 			(
-				'uid' => 'yes',
+				'source_table' => 'yes',
+				'source_id' => 'yes',
 				'state' => 1,
 			),
 			'type' => 'all',

+ 1 - 1
database/info.php

@@ -5,7 +5,7 @@ $list_button = array
 (
 	'list' => array('认证', '"auth&search_option_uid={id}&oper_table=info"'),
 
-	'list1' => array('地址', '"address&search_option_uid={id}&oper_table=info"'),
+	'list1' => array('地址', '"address&search_option_source_table=user/info&search_option_source_id={id}&oper_table=info"'),
 );
 if (Dever::project('account')) {
 	$list_button += array

+ 25 - 2
lib/Address.php

@@ -19,6 +19,15 @@ class Address
             if ($type == 2) {
                 Dever::db('user/address')->updateType(array('where_type' => 2, 'set_type' => 1));
             }
+            $address = Dever::param('address', $param);
+            if ($address) {
+                $geo = Dever::geo($address, $update['city']);
+                if ($geo) {
+                    $update['lng'] = $geo[0];
+                    $update['lat'] = $geo[1];
+                }
+            }
+            
             $update['type'] = $type;
             Dever::db('user/address')->update($update);
         }
@@ -60,7 +69,7 @@ class Address
     }
 
     # 添加或者更新地址
-    public function update($id, $uid, $type = 2, $mobile, $contact, $province = '', $city = '', $county = '', $town = '', $address = '', $country = '', $tag = '')
+    public function update($id, $source_id, $source_table, $type = 2, $mobile, $contact, $province = '', $city = '', $county = '', $town = '', $address = '', $country = '', $tag = '')
     {
         if ($contact) {
             $update['contact'] = $contact;
@@ -105,6 +114,13 @@ class Address
 
         if ($address) {
             $update['address'] = $address;
+            if ($address && isset($update['city']) && $update['city']) {
+                $geo = Dever::geo($address, $update['city']);
+                if ($geo) {
+                    $update['lng'] = $geo[0];
+                    $update['lat'] = $geo[1];
+                }
+            }
         }
 
         if ($tag) {
@@ -119,10 +135,17 @@ class Address
             $update['where_id'] = $id;
             Dever::db('user/address')->update($update);
         } else {
-            $update['uid'] = $uid;
+            $update['source_id'] = $source_id;
+            $update['source_table'] = $source_table;
             $id = Dever::db('user/address')->insert($update);
         }
 
         return $id;
     }
+
+    public function getSource($source_table, $source_id)
+    {
+        $info = Dever::db($source_table)->one($source_id);
+        return $info;
+    }
 }

+ 14 - 10
src/Address.php

@@ -6,9 +6,10 @@ use Dever;
 class Address
 {
     # 获取默认地址
-    public function getDefault($uid)
+    public function getDefault($source_id, $source_table = 'user/info')
     {
-        $where['uid'] = $uid;
+        $where['source_table'] = $source_table;
+        $where['source_id'] = $source_id;
         $where['type'] = 2;
         $data = Dever::db('user/address')->one($where);
 
@@ -16,9 +17,10 @@ class Address
     }
 
     # 获取某个收货地址
-    public function getInfo($uid, $id)
+    public function getInfo($source_id, $id, $source_table = 'user/info')
     {
-        $where['uid'] = $uid;
+        $where['source_table'] = $source_table;
+        $where['source_id'] = $source_id;
         $where['id'] = $id;
         $data = Dever::db('user/address')->one($where);
 
@@ -30,9 +32,10 @@ class Address
     }
 
     # 获取地址列表
-    public function getList($uid)
+    public function getList($source_id, $source_table = 'user/info')
     {
-        $where['uid'] = $uid;
+        $where['source_table'] = $source_table;
+        $where['source_id'] = $source_id;
         $data = Dever::db('user/address')->getList($where);
 
         if ($data && Dever::project('area')) {
@@ -46,9 +49,9 @@ class Address
 
 
     # 删除和恢复
-    public function delete($uid, $id, $state = 2)
+    public function delete($source_id, $id, $state = 2, $source_table = 'user/info')
     {
-        $info = $this->getOne($uid, $id);
+        $info = $this->getOne($source_id, $id, $source_table);
         if ($info) {
             $update['where_id'] = $info['id'];
             $update['state'] = $state;
@@ -63,7 +66,8 @@ class Address
     # 添加或者更新地址接口
     public function update()
     {
-        $uid = $this->check();
+        $source_id = $this->check();
+        $source_table = 'user/info';
         $id = Dever::input('id');
         $type = Dever::input('type', 2);
         $province = Dever::input('province');
@@ -75,6 +79,6 @@ class Address
         $mobile = Dever::input('mobile');
         $tag = Dever::input('tag');
 
-        return Dever::load('user/lib/address')->update($id, $uid, $type, $mobile, $contact, $province, $city, $town, $address, $country, $tag);
+        return Dever::load('user/lib/address')->update($id, $source_id, $source_table, $type, $mobile, $contact, $province, $city, $town, $address, $country, $tag);
     }
 }