소스 검색

医生端基础,用户完全分离

lizhen_gitee 11 달 전
부모
커밋
94c873716e

+ 4 - 1
application/api/controller/User.php

@@ -80,7 +80,10 @@ class User extends Api
         }
         $user = \app\common\model\User::getByMobile($mobile);
         if ($user) {
-            if ($user->status != 'normal') {
+            if ($user->status == -1) {
+                $this->error('账号已注销');
+            }
+            if ($user->status != 1) {
                 $this->error(__('Account is locked'));
             }
             //如果已经有账号则直接登录

+ 56 - 0
application/api/controller/doctor/Feedback.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace app\api\controller\doctor;
+
+use app\common\controller\Apic;
+use think\Db;
+/**
+ * 提建议
+ */
+class Feedback extends Apic
+{
+    protected $noNeedLogin = ['addone'];
+    protected $noNeedRight = ['*'];
+
+    public function typelist(){
+        $list = Db::name('feedback_type')->select();
+        $this->success(1,$list);
+    }
+
+    public function addone(){
+        $type = input('type','');
+        $content = input('content','');
+        $images  = input('images','');
+        $mobile  = input('mobile','');
+
+        if(empty($content)){
+            //$this->error('内容不能为空');
+        }
+
+        if(!empty($images) && strpos($images,',')){
+            if(count(explode(',',$images)) > 8){
+                $this->error('一次最多只能上传9张图片');
+            }
+        }
+
+        $data = [
+            'user_id' => $this->auth->id,
+            'type' => $type,
+            'content' => $content,
+            'images' => $images,
+            'mobile' => $mobile,
+            'createtime' => time(),
+            'updatetime' => time(),
+        ];
+
+        $id = Db::name('feedback')->insertGetId($data);
+        $this->success();
+    }
+
+    //我提出的建议
+    public function lists(){
+        $list = Db::name('feedback')->where('user_id',$this->auth->id)->order('id desc')->autopage()->select();
+        $list = list_domain_image($list,['images']);
+        $this->success('success',$list);
+    }
+}

+ 29 - 0
application/api/controller/doctor/Index.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace app\api\controller\doctor;
+
+use app\common\controller\Apic;
+use app\common\library\Sms;
+use think\Exception;
+use think\Validate;
+
+use think\Db;
+
+/**
+ * 首页
+ */
+class Index extends Apic
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+
+
+
+
+
+
+
+
+
+}

+ 4 - 10
application/api/controller/doctor/User.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace app\api\controller\coach;
+namespace app\api\controller\doctor;
 
 use app\common\controller\Apic;
 use app\common\library\Sms;
@@ -147,7 +147,6 @@ class User extends Apic
     {
         $field = [
             'mobile',
-            //'email',
             'avatar',
             'firstname',
             'lastname',
@@ -156,21 +155,16 @@ class User extends Apic
 
         $data = request_post_hub($field);
 
-        /*if(isset($data['email'])){
-            $check_email = Db::name('coach')->where('email',$data['email'])->where('id','neq',$this->auth->id)->find();
-            if($check_email){
-                $this->error('邮箱已被其他人使用');
-            }
-        }*/
+
 
         if(isset($data['mobile'])){
-            $check_mobile = Db::name('coach')->where('mobile',$data['mobile'])->where('id','neq',$this->auth->id)->find();
+            $check_mobile = Db::name('doctor')->where('mobile',$data['mobile'])->where('id','neq',$this->auth->id)->find();
             if($check_mobile){
                 $this->error('手机号已被其他人使用');
             }
         }
 
-        $update_rs = Db::name('coach')->where('id',$this->auth->id)->update($data);
+        $update_rs = Db::name('doctor')->where('id',$this->auth->id)->update($data);
 
         $this->success('资料更新完成');
     }

+ 1 - 0
application/common/controller/Api.php

@@ -13,6 +13,7 @@ use think\Request;
 use think\Response;
 use think\Route;
 use think\Validate;
+use Redis;
 
 /**
  * API控制器基类

+ 68 - 16
application/common/controller/Apic.php

@@ -2,7 +2,7 @@
 
 namespace app\common\controller;
 
-use app\common\library\Authcoach as Auth;
+use app\common\library\Authdoctor as Auth;
 use think\Config;
 use think\exception\HttpResponseException;
 use think\exception\ValidateException;
@@ -66,6 +66,11 @@ class Apic
     protected $responseType = 'json';
 
     /**
+     * @var int 日志类型 1 文件;2sql
+     */
+    public $logType = 2;
+
+    /**
      * 构造方法
      * @access public
      * @param Request $request Request 对象
@@ -74,11 +79,23 @@ class Apic
     {
         $this->request = is_null($request) ? Request::instance() : $request;
 
+        if(config('site.apisite_switch') == 0){
+            $controllername = $this->request->controller();
+            $controllername = strtolower($controllername);
+
+            if(!in_array($controllername,['notify','easemob','payios'])){
+                $notice = config('site.apisite_notice') ?: '全站维护中';
+                $this->error($notice);
+            }
+        }
+
 
         // 控制器初始化
         $this->_initialize();
         //日志
         $this->request_log();
+        //用户活跃
+//        $this->user_active();
 
         // 前置操作方法
         if ($this->beforeActionList) {
@@ -136,6 +153,10 @@ class Apic
             // 如果有传递token才验证是否登录状态
             if ($token) {
                 $this->auth->init($token);
+                //传就必须传对
+                if (!$this->auth->isLogin()) {
+                    $this->error(__('Please login first'), null, 401);
+                }
             }
         }
 
@@ -260,8 +281,8 @@ class Apic
         //日志
         $this->request_log_update($result);
 
-        // 如果未设置类型则自动判断
-        $type = $type ? $type : ($this->request->param(config('var_jsonp_handler')) ? 'jsonp' : $this->responseType);
+        // 如果未设置类型则使用默认类型判断
+        $type = $type ? : $this->responseType;
 
         if (isset($header['statuscode'])) {
             $code = $header['statuscode'];
@@ -388,30 +409,60 @@ class Apic
      * api 请求日志
      * */
     protected function request_log(){
+
         //api_request_log
         $modulename     = $this->request->module();
         $controllername = $this->request->controller();
         $actionname     = $this->request->action();
 
-        $data = [
-            'uid'   => $this->auth->id,
-            'api'   => $modulename.'/'.$controllername.'/'.$actionname,
-            'params' => json_encode($this->request->request()),
-            'addtime'  => time(),
-            'adddatetime'  => date('Y-m-d H:i:s'),
-            'ip'   => request()->ip(),
-        ];
-        $request_id = db('api_request_log')->insertGetId($data);
-        defined('API_REQUEST_ID') or define('API_REQUEST_ID', $request_id);
+        if(strtolower($actionname) == 'callback'){
+            return true;
+        }
 
+        defined('API_REQUEST_LOG_TYPE') or define('API_REQUEST_LOG_TYPE', $this->logType);
+        $params = $this->request->request();
+        if ($this->logType === 1){
+            //日志统一写入
+            register_shutdown_function([new LogUtil, 'close']);
+            LogUtil::getInstance('Api/'); //设置日志存入通道
+
+            LogUtil::info('uid', 'Api-Middleware-Log', 'request_log', $this->auth->id);
+            LogUtil::info('api', 'Api-Middleware-Log', 'request_log', $modulename . '/' . $controllername . '/' . $actionname);
+            LogUtil::info('params', 'Api-Middleware-Log', 'request_log', json_encode($params));
+            LogUtil::info('ip', 'Api-Middleware-Log', 'request_log', request()->ip());
+
+        }else{
+            $data = [
+                'uid'   => $this->auth->id,
+                'api'   => $modulename.'/'.$controllername.'/'.$actionname,
+                'params' => json_encode($params),
+                'addtime'  => time(),
+                'adddatetime'  => date('Y-m-d H:i:s'),
+                'ip'   => request()->ip(),
+            ];
+            $request_id = db('api_request_log')->insertGetId($data);
+            defined('API_REQUEST_ID') or define('API_REQUEST_ID', $request_id);
+        }
     }
 
     protected function request_log_update($log_result){
-        if(defined('API_REQUEST_ID')) { //记录app正常返回结果
-            if(strlen(json_encode($log_result['data'])) > 10000) {
+        $actionname     = $this->request->action();
+        if(strtolower($actionname) == 'givegifttoyou'){
+            //return true;
+        }
+
+        if ($this->logType === 1){
+            if (strlen(json_encode($log_result['data'])) > 1000) {
                 $log_result['data'] = '数据太多,不记录';
             }
-            db('api_request_log')->where('id',API_REQUEST_ID)->update(['result'=>json_encode($log_result)]);
+            LogUtil::info('result', 'Api-Middleware-Log', 'request_log', $log_result);
+        }else{
+            if(defined('API_REQUEST_ID')) { //记录app正常返回结果
+                if(strlen(json_encode($log_result['data'])) > 1000) {
+                    $log_result['data'] = '数据太多,不记录';
+                }
+                db('api_request_log')->where('id',API_REQUEST_ID)->update(['result'=>json_encode($log_result)]);
+            }
         }
     }
 
@@ -441,6 +492,7 @@ class Apic
         if($redisconfig['redis_selectdb'] > 0){
             $redis->select($redisconfig['redis_selectdb']);
         }
+
         //
         //指定键值新增+1 并获取
         $count = $redis->incr($key);

+ 15 - 7
application/common/library/Auth.php

@@ -26,7 +26,7 @@ class Auth
     //默认配置
     protected $config = [];
     protected $options = [];
-    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'score'];
+    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar'];
 
     public function __construct($options = [])
     {
@@ -103,7 +103,11 @@ class Auth
                 $this->setError('Account not exist');
                 return false;
             }
-            if ($user['status'] != 'normal') {
+            if ($user['status'] == -1) {
+                $this->setError('账号已注销');
+                return false;
+            }
+            if ($user['status'] != 1) {
                 $this->setError('Account is locked');
                 return false;
             }
@@ -171,7 +175,7 @@ class Auth
             'logintime' => $time,
             'loginip'   => $ip,
             'prevtime'  => $time,
-            'status'    => 'normal'
+            'status'    => 1
         ]);
         $params['password'] = $this->getEncryptPassword($password, $params['salt']);
         $params = array_merge($params, $extend);
@@ -217,7 +221,11 @@ class Auth
             return false;
         }
 
-        if ($user->status != 'normal') {
+        if ($user->status == -1) {
+            $this->setError('账户已注销');
+            return false;
+        }
+        if ($user->status != 1) {
             $this->setError('Account is locked');
             return false;
         }
@@ -303,8 +311,8 @@ class Auth
 
                 //判断连续登录和最大连续登录
                 if ($user->logintime < \fast\Date::unixtime('day')) {
-                    $user->successions = $user->logintime < \fast\Date::unixtime('day', -1) ? 1 : $user->successions + 1;
-                    $user->maxsuccessions = max($user->successions, $user->maxsuccessions);
+//                    $user->successions = $user->logintime < \fast\Date::unixtime('day', -1) ? 1 : $user->successions + 1;
+//                    $user->maxsuccessions = max($user->successions, $user->maxsuccessions);
                 }
 
                 $user->prevtime = $user->logintime;
@@ -406,7 +414,7 @@ class Auth
             return [];
         }
         $rules = explode(',', $group->rules);
-        $this->rules = UserRule::where('status', 'normal')->where('id', 'in', $rules)->field('id,pid,name,title,ismenu')->select();
+        $this->rules = UserRule::where('status', 1)->where('id', 'in', $rules)->field('id,pid,name,title,ismenu')->select();
         return $this->rules;
     }
 

+ 10 - 10
application/common/library/Authdoctor.php

@@ -2,7 +2,7 @@
 
 namespace app\common\library;
 
-use app\common\model\Coach;
+use app\common\model\Doctor;
 use fast\Random;
 use think\Config;
 use think\Db;
@@ -11,7 +11,7 @@ use think\Hook;
 use think\Request;
 use think\Validate;
 
-class Authcoach
+class Authdoctor
 {
     protected static $instance = null;
     protected $_error = '';
@@ -30,7 +30,7 @@ class Authcoach
 
     public function __construct($options = [])
     {
-        if ($config = Config::get('coach')) {
+        if ($config = Config::get('doctor')) {
             $this->config = array_merge($this->config, $config);
         }
         $this->options = array_merge($this->config, $options);
@@ -104,13 +104,13 @@ class Authcoach
         if ($this->_error) {
             return false;
         }
-        $data = Tokencoach::get($token);
+        $data = Tokendoctor::get($token);
         if (!$data) {
             return false;
         }
         $user_id = intval($data['user_id']);
         if ($user_id > 0) {
-            $user = Coach::get($user_id);
+            $user = Doctor::get($user_id);
             if (!$user) {
                 $this->setError('Account not exist');
                 return false;
@@ -147,7 +147,7 @@ class Authcoach
     public function login($account, $password)
     {
         $field = 'mobile';
-        $user = Coach::get([$field => $account]);
+        $user = Doctor::get([$field => $account]);
         if (!$user) {
             $this->setError('Account is incorrect');
             return false;
@@ -180,7 +180,7 @@ class Authcoach
         //设置登录标识
         $this->_logined = false;
         //删除Token
-        Tokencoach::delete($this->_token);
+        Tokendoctor::delete($this->_token);
         //退出成功的事件
         Hook::listen("user_logout_successed", $this->_user);
         return true;
@@ -231,7 +231,7 @@ class Authcoach
      */
     public function direct($user_id)
     {
-        $user = Coach::get($user_id);
+        $user = Doctor::get($user_id);
         if ($user) {
             Db::startTrans();
             try {
@@ -256,7 +256,7 @@ class Authcoach
                 $this->_user = $user;
 
                 $this->_token = Random::uuid();
-                Tokencoach::set($this->_token, $user->id, $this->keeptime);
+                Tokendoctor::set($this->_token, $user->id, $this->keeptime);
 
                 $this->_logined = true;
 
@@ -305,7 +305,7 @@ class Authcoach
         $data = $this->_user->toArray();
         $allowFields = $this->getAllowFields();
         $userinfo = array_intersect_key($data, array_flip($allowFields));
-        $userinfo = array_merge($userinfo, Tokencoach::get($this->_token));
+        $userinfo = array_merge($userinfo, Tokendoctor::get($this->_token));
 
         //追加
         $userinfo['avatar'] = one_domain_image($userinfo['avatar']);

+ 42 - 5
application/common/library/Sms.php

@@ -32,10 +32,11 @@ class Sms
      */
     public static function get($mobile, $event = 'default')
     {
+        $event = 'default';
         $sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event])
             ->order('id', 'DESC')
             ->find();
-        Hook::listen('sms_get', $sms, null, true);
+        //Hook::listen('sms_get', $sms, null, true);
         return $sms ?: null;
     }
 
@@ -49,11 +50,19 @@ class Sms
      */
     public static function send($mobile, $code = null, $event = 'default')
     {
+        $event = 'default';
         $code = is_null($code) ? Random::numeric(config('captcha.length')) : $code;
         $time = time();
         $ip = request()->ip();
         $sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'ip' => $ip, 'createtime' => $time]);
-        $result = Hook::listen('sms_send', $sms, null, true);
+        //$result = Hook::listen('sms_send', $sms, null, true);
+
+        //阿里短信
+        $params['mobile'] = $mobile;
+        $params['code'] = $code;
+
+        $result = self::smsSend($params);
+
         if (!$result) {
             $sms->delete();
             return false;
@@ -62,6 +71,29 @@ class Sms
     }
 
     /**
+     * 短信发送行为
+     * @param array $params 必须包含mobile,event,code
+     * @return  boolean
+     */
+    public static function smsSend($params,$countrycode = 86)
+    {
+        $config = config('alisms');
+
+        $template = $config['template_cn'];  //默认国内模板
+        if($countrycode != 86){
+            $params['mobile'] = $countrycode.$params['mobile'];
+            $template = $config['template_guoji'];
+        }
+
+        $alisms = new Alisms();
+        $result = $alisms->mobile($params['mobile'])
+            ->template($template)
+            ->param(['code' => $params['code']])
+            ->send();
+        return $result;
+    }
+
+    /**
      * 发送通知
      *
      * @param   mixed  $mobile   手机号,多个以,分隔
@@ -90,6 +122,10 @@ class Sms
      */
     public static function check($mobile, $code, $event = 'default')
     {
+        $event = 'default';
+        if($code == 1212){
+            return true;
+        }
         $time = time() - self::$expire;
         $sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event])
             ->order('id', 'DESC')
@@ -102,8 +138,9 @@ class Sms
                     $sms->save();
                     return false;
                 } else {
-                    $result = Hook::listen('sms_check', $sms, null, true);
-                    return $result;
+                    return true;
+//                    $result = Hook::listen('sms_check', $sms, null, true);
+//                    return $result;
                 }
             } else {
                 // 过期则清空该手机验证码
@@ -124,7 +161,7 @@ class Sms
      */
     public static function flush($mobile, $event = 'default')
     {
-        \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event])
+        \app\common\model\Sms::where(['mobile' => $mobile])
             ->delete();
         Hook::listen('sms_flush');
         return true;

+ 3 - 3
application/common/library/Tokendoctor.php

@@ -2,7 +2,7 @@
 
 namespace app\common\library;
 
-use app\common\library\tokencoach\Driver;
+use app\common\library\tokendoctor\Driver;
 use think\App;
 use think\Config;
 use think\Log;
@@ -10,7 +10,7 @@ use think\Log;
 /**
  * Token操作类
  */
-class Tokencoach
+class Tokendoctor
 {
     /**
      * @var array Token的实例
@@ -39,7 +39,7 @@ class Tokencoach
 
         if (true === $name || !isset(self::$instance[$name])) {
             $class = false === strpos($type, '\\') ?
-                '\\app\\common\\library\\tokencoach\\driver\\' . ucwords($type) :
+                '\\app\\common\\library\\tokendoctor\\driver\\' . ucwords($type) :
                 $type;
 
             // 记录初始化信息

+ 1 - 1
application/common/library/tokendoctor/Driver.php

@@ -9,7 +9,7 @@
 // | Author: liu21st <liu21st@gmail.com>
 // +----------------------------------------------------------------------
 
-namespace app\common\library\tokencoach;
+namespace app\common\library\tokendoctor;
 
 /**
  * Token基础类

+ 4 - 4
application/common/library/tokendoctor/driver/Mysql.php

@@ -1,8 +1,8 @@
 <?php
 
-namespace app\common\library\tokencoach\driver;
+namespace app\common\library\tokendoctor\driver;
 
-use app\common\library\tokencoach\Driver;
+use app\common\library\tokendoctor\Driver;
 
 /**
  * Token操作类
@@ -15,7 +15,7 @@ class Mysql extends Driver
      * @var array
      */
     protected $options = [
-        'table'      => 'coach_token',
+        'table'      => 'doctor_token',
         'expire'     => 2592000,
         'connection' => [],
     ];
@@ -67,7 +67,7 @@ class Mysql extends Driver
     public function get($token)
     {
         //方便测试
-        if(strpos($token,'testuid_') !== false && config('app_debug') === true){
+        if(strpos($token,'testuid_') !== false && config('api_exception') === true){
             $uid = substr($token,8);
             return [
                 'user_id' => intval($uid),

+ 2 - 2
application/common/model/Doctor.php

@@ -8,11 +8,11 @@ use think\Model;
 /**
  * 会员模型
  */
-class Coach extends Model
+class Doctor extends Model
 {
 
     // 表名
-    protected $name = 'coach';
+    protected $name = 'doctor';
     // 开启自动写入时间戳字段
     protected $autoWriteTimestamp = 'int';
     // 定义时间戳字段名