rabin 8 ヶ月 前
コミット
783f3b30cd
13 ファイル変更266 行追加21 行削除
  1. 2 2
      database/auth.php
  2. 1 0
      database/info.php
  3. 1 1
      database/invoice.php
  4. 12 2
      lib/Address.php
  5. 159 0
      lib/Applet.php
  6. 3 3
      lib/Core.php
  7. 4 0
      lib/Info.php
  8. 10 0
      lib/Invoice.php
  9. 27 0
      lib/Wechat.php
  10. 1 1
      src/Address.php
  11. 35 1
      src/Info.php
  12. 3 3
      src/Invoice.php
  13. 8 8
      src/Main.php

+ 2 - 2
database/auth.php

@@ -249,7 +249,7 @@ return array
             'desc'      => '审核备注',
             'match'     => 'is_string',
             'update'    => $col ? 'textarea' : false,
-            'show'      => 'audit_status=2',
+            'show'      => 'audit_status=3',
             'list'      => '"{audit_desc}" ? "{audit_desc}" : "-"',
         ),
 
@@ -302,7 +302,7 @@ return array
         # 列表
         'list_button' => array
         (
-            'edit' => array('审核', 'audit_status,audit_desc', '{audit_status} == 2'),
+            'edit' => array('审核', 'audit_status,audit_desc', '{status} == 1'),
         ),
     ),
 );

+ 1 - 0
database/info.php

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

+ 1 - 1
database/invoice.php

@@ -118,7 +118,7 @@ return array
 
         'mobile'        => array
         (
-            'type'      => 'varchar-11',
+            'type'      => 'varchar-150',
             'name'      => '手机号',
             'default'   => '',
             'desc'      => '手机号',

+ 12 - 2
lib/Address.php

@@ -45,6 +45,16 @@ class Address
         }
     }
 
+    # 获取地址
+    public function get($source_id, $source_table, $uid, $address_id)
+    {
+        $info = $this->getData($source_id, $source_table, 1);
+        if (!$info) {
+            $info = $this->getInfo($uid, $address_id);
+        }
+        return $info;
+    }
+
     # 按照类型获取地址
     public function getData($source_id, $source_table = 'user/info', $type = 2)
     {
@@ -130,14 +140,14 @@ class Address
     }
 
     # 添加或者更新地址
-    public function update($id, $source_id, $source_table, $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 = '', $tag = '')
     {
         if ($contact) {
             $update['contact'] = $contact;
         }
 
         if ($mobile) {
-            $update['mobile'] = $mobile;
+            $update['phone'] = $mobile;
         } else {
             Dever::alert('请输入手机号');
         }

+ 159 - 0
lib/Applet.php

@@ -0,0 +1,159 @@
+<?php
+namespace User\Lib;
+
+use Dever;
+
+# 小程序
+class Applet
+{
+	public function getOpenid($uid, $system_source = 5, $project_id = 1)
+	{
+		$openid = false;
+		$code = Dever::input('code');
+		if ($code) {
+			$info = $this->getInfo($code);
+			if (isset($info['openid'])) {
+                $openid = $info['openid'];
+                Dever::load('user/lib/wechat')->update($uid, $openid, $system_source, $project_id);
+            }
+		}
+		if (!$openid && $uid > 0) {
+            $wechat = Dever::load('user/lib/wechat')->getInfo($uid, $system_source, $project_id);
+            if ($wechat) {
+                $openid = $wechat['openid'];
+            }
+        }
+
+		return $openid;
+	}
+
+    private function getInfo($code)
+    {
+        $session_key = Dever::input('session_key');
+        if ($session_key) {
+            return array('session_key' => $session_key, 'openid' => $openid);
+        }
+        $applet = $this->getApplet();
+        $appid = $applet['appid'];
+        $secret = $applet['secret'];
+        $url = $applet['url'];
+        if (!$applet || !$applet['appid'] || !$applet['secret']) {
+            Dever::alert('错误的appid');
+        }
+
+        $url .= '?appid=' . $appid;
+        $url .= '&secret=' . $secret;
+        $url .= '&js_code=' . $code;
+        $url .= '&grant_type=authorization_code';
+
+        $data = Dever::curl($url);
+        Dever::log($data, 'passport_applet');
+        if (strstr($data, 'errcode')) {
+            Dever::alert($data);
+        }
+
+        $data = Dever::json_decode($data);
+
+        return $data;
+    }
+
+    private function unionid($session_key)
+    {
+        $data = $this->decryptData($session_key);
+        if ($data && isset($data->unionId)) {
+            return $data->unionId;
+        }
+        
+        return false;
+    }
+
+    private function getWechatData($session_key)
+    {
+        $result = array();
+        $data = $this->decryptData($session_key);
+
+        $result['openid'] = '';
+        $result['unionid'] = '';
+        $result['mobile'] = '';
+        $result['phone'] = '';
+        if ($data && isset($data->openId)) {
+            $result['openid'] = $data->openId;
+            if (isset($data->unionId)) {
+                $result['unionid'] = $data->unionId;
+            }
+        }
+
+        if ($data && isset($data->phoneNumber)) {
+            if (isset($data->phoneNumber)) {
+                $result['phone'] = $data->phoneNumber;
+            }
+        }
+
+        if ($data && isset($data->purePhoneNumber)) {  
+            if (isset($data->purePhoneNumber)) {
+                $result['mobile'] = $data->purePhoneNumber;
+            }
+        }
+        
+        return $result;
+    }
+
+    private function decryptData($session_key)
+    {
+        $iv = Dever::input('iv');
+        $encryptedData = Dever::input('encryptedData');
+
+        if (!$iv || !$encryptedData) {
+            return false;
+        }
+        if (strlen($session_key) != 24) {
+            return false;
+        }
+        if (strlen($iv) != 24) {
+            return false;
+        }
+
+        $aesKey = base64_decode($session_key);
+
+        $aesIV = base64_decode($iv);
+
+        $aesCipher = base64_decode($encryptedData);
+
+        $result = openssl_decrypt($aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);
+
+        $dataObj = json_decode($result);
+        if ($dataObj  == NULL) {
+            return false;
+        }
+        /*
+        $applet = Dever::config('base', 'project')->applet;
+        $appid = $applet['appid'];
+        if($dataObj->watermark->appid != $appid) {
+            return false;
+        }*/
+        return $dataObj;
+    }
+
+    private function getApplet()
+    {
+        $applet = Dever::config('base', 'project')->applet;
+        $system = Dever::input('system', 1);
+
+        $system = Dever::db('passport/system')->find($system);
+        $project = false;
+        if ($system && $system['token_project_id'] > 0 && Dever::project('token')) {
+            $project = Dever::db('token/project')->find($system['token_project_id']);
+        }
+
+        if ($project) {
+            $applet['appid'] = $project['appid'];
+            $applet['secret'] = $project['secret'];
+        }
+
+        if (!$applet || !$applet['appid'] || !$applet['secret']) {
+            Dever::alert('错误的appid');
+        }
+
+        return $applet;
+    }
+}

+ 3 - 3
lib/Core.php

@@ -12,11 +12,11 @@ class Core
 
     public function __construct()
     {
-        $this->uid = Dever::load('user/lib/info')->check();
+        $this->uid = Dever::load('user/lib/info')->check(false);
         if ($this->uid <= 0) {
-            $this->uid = 1;
+            $this->uid = Dever::db('user/info')->config['auto'];
         }
-        $this->user = Dever::db('user/lib/info')->get($this->uid);
+        $this->user = Dever::load('user/lib/info')->get($this->uid);
 
         if ($this->user) {
             $this->user['uid'] = $this->user['id'];

+ 4 - 0
lib/Info.php

@@ -61,6 +61,7 @@ class Info
                 $info['name'] = $info['username'];
                 $info['area_string'] = '';
                 $info['avatar'] = '';
+                $info['aname'] = $info['name'] . ($info['mobile'] ? '('.$info['mobile'].')' : '');
             }
         } else {
             $info = Dever::db('user/info')->find($uid);
@@ -75,6 +76,9 @@ class Info
                         $info['avatar'] = $avatar['avatar'];
                     }
                 }
+
+
+                $info['aname'] = $info['name'] . '('.$info['mobile'].')';
             }
         }
 

+ 10 - 0
lib/Invoice.php

@@ -5,6 +5,16 @@ use Dever;
 
 class Invoice
 {
+    # 获取发票
+    public function get($source_id, $source_table, $uid, $address_id)
+    {
+        $info = $this->getData($source_id, $source_table, 1);
+        if (!$info) {
+            $info = $this->getInfo($uid, $address_id);
+        }
+        return $info;
+    }
+    
     # 获取默认发票
     public function getData($source_id, $source_table = 'user/info', $type = 2)
     {

+ 27 - 0
lib/Wechat.php

@@ -0,0 +1,27 @@
+<?php
+namespace User\Lib;
+
+use Dever;
+
+class Wechat
+{
+	public function getInfo($uid, $system_source = 5, $project_id = 1)
+	{
+		return Dever::db('user/wechat')->one(array('uid' => $uid, 'project_id' => $project_id, 'system_source' => $system_source));
+	}
+
+	public function update($uid, $openid, $system_source = 5, $project_id = 1)
+	{
+		$info = $this->getInfo($uid, $system_source, $project_id);
+		$data['uid'] = $uid;
+		$data['openid'] = $openid;
+		$data['system_source'] = $system_source;
+		$data['project_id'] = $project_id;
+		if ($info) {
+			$data['where_id'] = $info['id'];
+			return Dever::db('user/wechat')->update($data);
+		} else {
+			return Dever::db('user/wechat')->insert($data);
+		}
+	}
+}

+ 1 - 1
src/Address.php

@@ -54,6 +54,6 @@ class Address extends Core
         $mobile = Dever::input('mobile');
         $tag = Dever::input('tag');
 
-        return Dever::load('user/lib/address')->update($id, $source_id, $source_table, $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, $county, $town, $address, $tag);
     }
 }

+ 35 - 1
src/Info.php

@@ -15,12 +15,46 @@ class Info extends Core
             $this->data['score'] = Dever::load('score/lib/core')->getUserScore($this->uid);
         }
         if (Dever::project('account')) {
-            $this->data['account'] = Dever::load('account/lib/info')->getInfo($this->uid);
+            $this->data['account'] = Dever::load('account/lib/info')->getUserInfo($this->uid);
         }
         
         return $this->data;
     }
 
+    # 获取邀请码
+    public function invite()
+    {
+        if (Dever::project('invite')) {
+            $this->data['code'] = Dever::load('invite/api')->code($this->uid);
+        }
+
+        if (Dever::project('set')) {
+            $this->data['config'] = Dever::load('set/lib/config')->getInfo();
+        }
+
+        return $this->data;
+    }
+
+    # 根据邀请码获取信息
+    public function getInviteInfo()
+    {
+        $this->data['parent'] = array();
+        $code = Dever::input('code');
+        if ($code) {
+            $uid = Dever::load('invite/api')->getUid($code);
+            if (!$uid || $uid <= 0) {
+                Dever::alert('邀请码不正确');
+            }
+            $this->data['parent'] = Dever::load('user/lib/info')->get($this->uid);
+        }
+
+        if (Dever::project('set')) {
+            $this->data['config'] = Dever::load('set/lib/config')->getInfo();
+        }
+
+        return $this->data;
+    }
+
     # 更新用户信息
     public function update()
     {

+ 3 - 3
src/Invoice.php

@@ -1,6 +1,6 @@
 <?php
 namespace User\Src;
-
+use Dever;
 use User\Lib\Core;
 class Invoice extends Core
 {
@@ -38,13 +38,13 @@ class Invoice extends Core
     }
 
     # 添加或者更新地址接口
-    public function up()
+    public function update()
     {
         $source_id = $this->uid;
         $source_table = 'user/info';
         $id = Dever::input('id');
         $type = Dever::input('type', 2);
-        $title_type = Dever::input('title_type');
+        $title_type = Dever::input('title_type', 2);
         $title = Dever::input('title');
         $email = Dever::input('email');
         $mobile = Dever::input('mobile');

+ 8 - 8
src/Main.php

@@ -50,33 +50,33 @@ class Main
     {
     	$password = Dever::input('password');
     	if ($password) {
-    		$password = sha1($password);
     		$param['mobile'] = $this->getMobile();
     	} else {
     		$param['mobile'] = $this->checkCode();
     	}
     	$param['project_id'] = Dever::input('project_id', 1);
-    	$info = Dever::db('passport/user')->one($param);
+    	$info = Dever::db('user/info')->one($param);
+        $param['system_source'] = Dever::input('system_source', 1);
     	if ($info) {
+            $password = sha1($password);
     		if ($password != $info['password']) {
     			Dever::alert('您的账号或密码错误');
     		}
     		$uid = $info['id'];
     	} else {
-    		$param['system_source'] = Dever::input('system_source', 1);
-	    	$param['username'] = Dever::input('username');
-        	if (!$param['username']) {
-        		$param['username'] = Dever::hide($param['mobile']);
+	    	$param['name'] = Dever::input('name');
+        	if (!$param['name']) {
+        		$param['name'] = Dever::hide($param['mobile']);
         	}
         	if ($password) {
         		$param['password'] = $password;
         	}
-        	$uid = Dever::db('passport/user')->insert($param);
+        	$uid = Dever::db('user/info')->insert($param);
         	if ($uid) {
         		Dever::score($uid, 'reg', '账号注册');
         		if (Dever::project('message')) {
         			$project = Dever::db('user/project')->find($param['project_id']);
-	                $content = '亲爱的' . $param['username'] . ',欢迎来到' . $project['name'];
+	                $content = '亲爱的' . $param['name'] . ',欢迎来到' . $project['name'];
 	                Dever::load('message/lib/data')->push(-1, $uid, '欢迎语', $content, 1);
 	            }
 	            $invite = Dever::input('invite');