Browse Source

商家分离,另一套登录系统

lizhen_gitee 1 year ago
parent
commit
556491acd4

+ 0 - 133
application/api/controller/company/User.php

@@ -4,9 +4,6 @@ namespace app\api\controller\company;
 
 use app\common\controller\Apic;
 use app\common\library\Sms;
-use fast\Random;
-use GuzzleHttp\Client;
-use think\Config;
 use think\Exception;
 use think\Validate;
 
@@ -136,135 +133,5 @@ class User extends Apic
         $this->success('资料更新完成');
     }
 
-    /**
-     * 设置店铺地址
-     */
-    public function setaddress()
-    {
-        //验证
-        if($this->auth->type != 1){
-            $this->error('只有门店老板才能设置');
-        }
-        $field = [
-            'province_name',
-            'city_name',
-            'area_name',
-            'province_id',
-            'city_id',
-            'area_id',
-            'address',
-        ];
-
-        $data = request_post_hub($field);
-
-        $data['full_address'] = $data['province_name'].$data['city_name'].$data['area_name'].$data['address'];
-        $data['updatetime'] = time();
-
-        $update_rs = Db::name('company')->where('id',$this->auth->company_id)->update($data);
-
-        $this->success('资料更新完成');
-    }
-
-    /**
-     * 小程序码
-     * @return void
-     */
-    public function getMiniCode()
-    {
-        try {
-            $companyId = $this->auth->company_id;
-            $companyWhere['id'] = $companyId;
-            $companyWhere['status'] = 1;
-            $company = Db::name('company')->where($companyWhere)->find();
-            if (empty($company)) {
-                throw new Exception('未找到门店信息');
-            }
-            $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
-            if (empty($company['mini_code'])) {
-                $client = new Client();
-                $tk = getAccessToken();
-                $miniCodeConfig = config('param.mini_code');
-                $miniCodeConfig['scene'] = 'shopId='.$companyId;
-                $res2 = $client->request('POST', 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$tk, [
-                    'json' => $miniCodeConfig,
-                ]);
-                $fileName = md5($companyId);
-                $fileUrl = '/uploads/company/'.$fileName.'.png';
-                $code = $res2->getBody()->getContents();
-                file_put_contents(ROOT_PATH.'/public'.$fileUrl,$code);
-                $companyData['mini_code'] = $fileUrl;
-                $companyRes = Db::name('company')->where($companyWhere)->update($companyData);
-                if (!$companyRes) {
-                    throw new Exception('更新门店信息失败');
-                }
-                $miniCode = $httpStr.$fileUrl.'?v='.time();
-            } else {
-                $miniCode = $httpStr.$company['mini_code'].'?v='.time();
-            }
-            $result = [
-                'mini_code' => $miniCode,
-                'company_name' => $this->auth->company->name,
-                'company_image' => one_domain_image($this->auth->company->image),
-            ];
-            $this->success('获取成功',$result);
-        } catch (Exception $e) {
-            $this->error($e->getMessage());
-        }
-    }
-
-    /**
-     * 获取用户openid
-     */
-    public function getUserOpenid() {
-        // code值
-        $code = $this->request->param('code');
-        if (!$code) {
-            $this->error(__('Invalid parameters'));
-        }
-
-        $config = config('company_wxMiniProgram');
-        $getopenid = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['appid'].'&secret='.$config['secret'].'&js_code='.$code.'&grant_type=authorization_code';
-        $openidInfo = $this->getJson($getopenid);
-        if(!isset($openidInfo['openid'])) {
-            $this->error('用户openid获取失败',$openidInfo);
-        }
-        //  获取的结果存入数据库
-        /*$find = Db::name('company_sessionkey')->where(['openid'=>$openidInfo['openid']])->find();
-        if($find) {
-            $update = [];
-            $update['sessionkey'] = $openidInfo['session_key'];
-            $update['createtime'] = time();
-            $res = Db::name('company_sessionkey')->where(['openid'=>$openidInfo['openid']])->update($update);
-        } else {
-            $insert = [];
-            $insert['sessionkey'] = $openidInfo['session_key'];
-            $insert['openid'] = $openidInfo['openid'];
-            $insert['unionid'] = isset($openidInfo['unionid']) ? $openidInfo['unionid'] : '';
-            $insert['createtime'] = time();
-            $res = Db::name('company_sessionkey')->insertGetId($insert);
-        }*/
-
-        if(!empty($openidInfo)) {
-            $this->success('获取成功',$openidInfo);
-        } else {
-            $this->error('获取失败');
-        }
 
-    }
-
-    /**
-     * json 请求
-     * @param $url
-     * @return mixed
-     */
-    private function getJson($url){
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $url);
-        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
-        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-        $output = curl_exec($ch);
-        curl_close($ch);
-        return json_decode($output, true);
-    }
 }

+ 2 - 5
application/common/controller/Apic.php

@@ -2,7 +2,7 @@
 
 namespace app\common\controller;
 
-use app\common\library\Authcompany as Auth;
+use app\common\library\Authcoach as Auth;
 use think\Config;
 use think\exception\HttpResponseException;
 use think\exception\ValidateException;
@@ -64,8 +64,6 @@ class Apic
      */
     protected $responseType = 'json';
 
-    public $page = 1;
-    public $listrow = 10;
 
     /**
      * 构造方法
@@ -75,8 +73,7 @@ class Apic
     public function __construct(Request $request = null)
     {
         $this->request = is_null($request) ? Request::instance() : $request;
-        $this->page = input('page',1);
-        $this->listrow= input('listrow',10);
+
 
         // 控制器初始化
         $this->_initialize();

+ 13 - 76
application/common/library/Authcompany.php → application/common/library/Authcoach.php

@@ -2,8 +2,7 @@
 
 namespace app\common\library;
 
-use app\common\model\CompanyStaff;
-use app\common\model\Company;
+use app\common\model\Coach;
 use app\common\model\UserRule;
 use fast\Random;
 use think\Config;
@@ -13,7 +12,7 @@ use think\Hook;
 use think\Request;
 use think\Validate;
 
-class Authcompany
+class Authcoach
 {
     protected static $instance = null;
     protected $_error = '';
@@ -28,12 +27,12 @@ class Authcompany
     protected $config = [];
     protected $options = [];
     //protected $allowFields = ['id', 'name', 'logo','image','contacts', 'mobile','province_name','city_name','area_name','province_id','city_id','area_id','address','full_address','longitude','latitude','aptitude_images','open_hours','staff'];
-    protected $allowFields = ['id','company_id','type','truename','mobile','company'];
+    protected $allowFields = ['id','type','truename','mobile'];
 
 
     public function __construct($options = [])
     {
-        if ($config = Config::get('company')) {
+        if ($config = Config::get('coach')) {
             $this->config = array_merge($this->config, $config);
         }
         $this->options = array_merge($this->config, $options);
@@ -107,13 +106,13 @@ class Authcompany
         if ($this->_error) {
             return false;
         }
-        $data = Tokencompany::get($token);
+        $data = Tokencoach::get($token);
         if (!$data) {
             return false;
         }
         $user_id = intval($data['user_id']);
         if ($user_id > 0) {
-            $user = CompanyStaff::get($user_id);
+            $user = Coach::get($user_id);
             if (!$user) {
                 $this->setError('Account not exist');
                 return false;
@@ -123,7 +122,7 @@ class Authcompany
                 return false;
             }
 
-            if(!$user->company_id){
+           /* if(!$user->company_id){
                 $this->setError('Account not exist');
                 return false;
             }
@@ -133,14 +132,14 @@ class Authcompany
                 return false;
             }
 
-            $user->company = $companyinfo;
+            $user->company = $companyinfo;*/
 
             $this->_user = $user;
             $this->_logined = true;
             $this->_token = $token;
 
             //初始化成功的事件
-            Hook::listen("company_init_successed", $this->_user);
+//            Hook::listen("company_init_successed", $this->_user);
 
             return true;
         } else {
@@ -160,7 +159,7 @@ class Authcompany
     public function login($account, $password, $openid)
     {
         $field = 'mobile';
-        $user = CompanyStaff::get([$field => $account]);
+        $user = Coach::get([$field => $account]);
         if (!$user) {
             $this->setError('Account is incorrect');
             return false;
@@ -193,7 +192,7 @@ class Authcompany
         //设置登录标识
         $this->_logined = false;
         //删除Token
-        Tokencompany::delete($this->_token);
+        Tokencoach::delete($this->_token);
         //退出成功的事件
         Hook::listen("user_logout_successed", $this->_user);
         return true;
@@ -217,10 +216,10 @@ class Authcompany
 
         $salt = Random::alnum();
         $newpassword = $this->getEncryptPassword($newpassword, $salt);
-        unset($this->_user['company']);
+        //unset($this->_user['company']);
         $this->_user->save(['password' => $newpassword, 'salt' => $salt]);
 
-        Tokencompany::delete($this->_token);
+        Tokencoach::delete($this->_token);
 
         //同步到admin
         $admin = [
@@ -329,9 +328,6 @@ class Authcompany
 
         //追加
         $userinfo['company']['image'] = one_domain_image($userinfo['company']['image']);
-        $userinfo['money'] = model('walletcompany')->getWallet($this->company_id,'money'); //可提现金额
-        $userinfo['dongjie_money'] = Db::name('order')->where('company_id',$this->company_id)->where('status',2)->where('ordertype',3)->sum('pay_fee');//冻结金额,即出售的套餐,但没使用的
-        $userinfo['all_money'] = bcadd($userinfo['money'],$userinfo['dongjie_money'],2);
 
         /////////////////////////////////////
         //个人信息
@@ -340,65 +336,6 @@ class Authcompany
 
 
 
-        //今日开单
-        $map = [
-            'company_id' => $this->company_id,
-            'finish_time' => ['BETWEEN',[$strattime,$endtime]], //开单时间用完成时间
-            'status'     => 3,
-        ];
-        if($this->type == 2){
-            //员工的
-            $map['staff_id'] = $this->id;
-        }
-
-        $userinfo['today_order_totalfee'] = Db::name('order')->where($map)->sum('total_fee');;
-
-        //今日新增客户
-        $map = [
-            'company_id' => $this->company_id,
-            'createtime'=>['BETWEEN',[$strattime,$endtime]],
-        ];
-        if($this->type == 2){
-            //员工的
-            $map['staff_id'] = $this->id;
-        }
-        $userinfo['today_newcus'] = Db::name('user_wallet')->where($map)->count();
-
-        //今日新增预约
-        $map = [
-            'company_id' => $this->company_id,
-            'createtime'=>['BETWEEN',[$strattime,$endtime]],
-        ];
-        $userinfo['today_newpre'] = Db::name('pre_order')->where($map)->count();
-
-        //已接单订单数量
-        $map = [
-            'company_id' => $this->company_id,
-            'status'     => 2,
-        ];
-        $userinfo['order_unfinish'] = Db::name('order')->where($map)->count();
-
-        //昨日订单数量
-        $starttime = strtotime(date('Y-m-d')) - 86400;
-        $endtime = strtotime(date('Y-m-d')) - 1;
-        $map = [
-            'company_id' => $this->company_id,
-            'status'     => 3,
-            'finish_time'=> ['BETWEEN',[$starttime,$endtime]],
-        ];
-        $userinfo['order_zuori'] = Db::name('order')->where($map)->count();
-
-        //7日订单数量
-        $starttime = strtotime(date('Y-m-d')) - 86400*6;
-        $endtime   = strtotime(date('Y-m-d')) + 86399;
-        $map = [
-            'company_id' => $this->company_id,
-            'status'     => 3,
-            'finish_time'=> ['BETWEEN',[$starttime,$endtime]],
-        ];
-        $userinfo['order_qiri'] = Db::name('order')->where($map)->count();
-
-
         return $userinfo;
     }
 

+ 3 - 3
application/common/library/Tokencompany.php → application/common/library/Tokencoach.php

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

+ 1 - 1
application/common/library/tokencompany/Driver.php → application/common/library/tokencoach/Driver.php

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

+ 3 - 3
application/common/library/tokencompany/driver/Mysql.php → application/common/library/tokencoach/driver/Mysql.php

@@ -1,8 +1,8 @@
 <?php
 
-namespace app\common\library\tokencompany\driver;
+namespace app\common\library\tokencoach\driver;
 
-use app\common\library\tokencompany\Driver;
+use app\common\library\tokencoach\Driver;
 
 /**
  * Token操作类
@@ -15,7 +15,7 @@ class Mysql extends Driver
      * @var array
      */
     protected $options = [
-        'table'      => 'company_token',
+        'table'      => 'coach_token',
         'expire'     => 2592000,
         'connection' => [],
     ];

+ 2 - 5
application/common/model/Company.php → application/common/model/Coach.php

@@ -8,7 +8,7 @@ use think\Model;
 /**
  * 会员模型
  */
-class Company extends Model
+class Coach extends Model
 {
 
     // 表名
@@ -21,8 +21,5 @@ class Company extends Model
     // 追加属性
     protected $append = [];
 
-    public function getStatusList()
-    {
-        return ['-1' => '已申请', '0' => '待审核', '1' => '审核通过', '2' => '审核不通过'];
-    }
+
 }