dever 6 years ago
parent
commit
deba8a7b47
3 changed files with 219 additions and 0 deletions
  1. 92 0
      database/app.php
  2. 21 0
      database/user.php
  3. 106 0
      src/App.php

+ 92 - 0
database/app.php

@@ -0,0 +1,92 @@
+<?php
+
+$source_type = array (
+	'ios' => 'ios',
+	'android' => 'android',
+);
+
+return array
+(
+	# 表名
+	'name' => 'app',
+	# 显示给用户看的名称
+	'lang' => 'app用户列表',
+	'order' => 9,
+	'menu' => false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			'order'		=> 'desc',
+			'list'		=> true,
+		),
+
+		'uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'select',
+			'search'	=> 'fulltext',
+			'list'		=> '{uid} > 0 ? Dever::load("passport/user-one#username", {uid}) . "(" . Dever::load("passport/user-one#mobile", {uid}). ")": "未知用户"',
+			//'list'		=> true,
+			//'edit'		=> true,
+		),
+
+		'source_type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户来源',
+			'default' 	=> '1',
+			'desc' 		=> '请选择用户来源',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $source_type,
+			//'search'	=> 'select',
+			//'list'		=> true,
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'search'	=> 'date',
+			'insert'	=> true,
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	'manage' => array
+	(
+		'insert' => false,
+		'edit' => false,
+		'delete' => false,
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		
+	),
+);

+ 21 - 0
database/user.php

@@ -32,6 +32,14 @@ $bind = array
 	2 => '未绑定',
 );
 
+$source_type = array (
+	'ios' => 'ios',
+	'android' => 'android',
+	'h5' => 'h5',
+	'applet' => '小程序',
+	'pc' => '网站',
+);
+
 $email = Dever::rule('email');
 $email = 'option';
 $mobile = Dever::rule('mobile');
@@ -91,6 +99,19 @@ return array
 			'list'		=> true,
 		),
 
+		'source_type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户来源',
+			'default' 	=> '',
+			'desc' 		=> '请选择用户来源',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $source_type,
+			//'search'	=> 'select',
+			//'list'		=> true,
+		),
+
 		'email'		=> array
 		(
 			'type' 		=> 'varchar-150',

+ 106 - 0
src/App.php

@@ -0,0 +1,106 @@
+<?php
+namespace Passport\Src;
+
+use Dever;
+use Passport\Src\Lib\Base;
+
+class App extends Base
+{
+    /**
+     * 更新用户信息
+     *
+     * @return mixed
+     */
+    public function update()
+    {
+        $uid = $this->check();
+        $name = Dever::input('username');
+        $pic = Dever::input('avatar');
+        $sex = Dever::input('gender');
+        $city = Dever::input('city');
+        $mobile = Dever::input('mobile');
+        $province = Dever::input('province');
+        $country = Dever::input('country');
+
+        $info = Dever::load('passport/user-one', $uid);
+        if ($info) {
+            $update['set_username'] = $name;
+            $update['set_avatar'] = $pic;
+            $update['set_sex'] = $sex;
+            $update['set_city'] = $city;
+            $update['set_province'] = $province;
+            $update['set_country'] = $country;
+            if ($country && $province && $city) {
+            	$update['set_area'] = $country . ',' . $province . ',' . $city;
+            }
+            
+            $update['where_id'] = $uid;
+            Dever::load('passport/user-update', $update);
+        } else {
+            Dever::alert('无效的用户id,请重新登录');
+        }
+
+        $result = Dever::db('passport/user')->one($uid);
+        $result['uid'] = $uid;
+        $result['signature'] = Dever::login($uid);
+
+        return $result;
+    }
+
+    /**
+     * 生成用户或者登录
+     *
+     * @return int
+     */
+    public function login()
+    {
+    	$mobile = Dever::input('mobile');
+    	$code = Dever::input('code');
+    	$source_type = Dever::input('source_type', 'applet');
+    	$send['skin'] = 'code';
+    	$send['mobile'] = $mobile;
+    	$send['code'] = $code;
+
+        # 添加测试账号
+        if ($mobile) {
+
+        } else {
+        	$mobile = Dever::load('passport/reg')->checkMobileExists();
+        }
+    	
+
+        $uid = false;
+        $info = Dever::load('passport/user-one', array('mobile' => $mobile));
+        if (!$info) {
+            $user['add_username'] = Dever::hide($mobile);
+            $user['add_mobile'] = $mobile;
+            $user['add_temp'] = 1;
+            $user['add_source_type'] = $source_type;
+            $uid = Dever::load('passport/user-insert', $user);
+        } else {
+        	$uid = $info['id'];
+        }
+
+        # 记录app登录日志
+        $appData = array('info_id' => $this->data['info']['id'], 'uid' => $uid, 'source_type' => $source_type);
+        $app = Dever::db('passport/app')->one($appData);
+        if (!$app) {
+        	Dever::db('passport/app')->insert($appData);
+        }
+
+        $result = Dever::db('passport/user')->one($uid);
+        $result['uid'] = $uid;
+        $result['signature'] = Dever::login($uid);
+        return $result;
+    }
+
+    //获取用户信息
+    public function user() {
+        $uid = $this->check();
+        $data=Dever::db('passport/user')->one($uid);
+        if(!$data['pic']){
+                $data['pic']=DEVER_APP_HOST . '../data/upload/pic.png';
+        }
+        return $data;
+    }
+}