Browse Source

Merge branch 'master' of http://git.huxiukeji.com/lizhen/lanjingling

lizhen_gitee 1 year ago
parent
commit
898cc00ea5
2 changed files with 48 additions and 51 deletions
  1. 0 50
      application/api/controller/User.php
  2. 48 1
      application/api/controller/company/User.php

+ 0 - 50
application/api/controller/User.php

@@ -13,7 +13,6 @@ use think\Validate;
 
 use think\Db;
 use miniprogram\wxBizDataCrypt;
-use GuzzleHttp\Client;
 
 /**
  * 会员接口
@@ -663,53 +662,4 @@ class User extends Api
         }
     }
 
-    /**
-     * 小程序码
-     * @return void
-     */
-    public function getMiniCode()
-    {
-        try {
-            $companyId = $this->request->param('company_id',0);
-            if (empty($companyId)) {
-                throw new Exception('参数错误');
-            }
-            $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();
-                $res2 = $client->request('POST', 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$tk, [
-                    'json' => [
-                        //'page' => 'pages/home/index',
-                        'env_version'=>'trial',
-                        'scene' => 'shopId='.$companyId,
-                    ]
-                ]);
-                $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;
-            } else {
-                $miniCode = $httpStr.$company['mini_code'];
-            }
-            $result = [
-                'mini_code' => $miniCode,
-            ];
-            $this->success('获取成功',$result);
-        } catch (Exception $e) {
-            $this->error($e->getMessage());
-        }
-    }
 }

+ 48 - 1
application/api/controller/company/User.php

@@ -5,7 +5,9 @@ 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;
 
 use think\Db;
@@ -154,5 +156,50 @@ class User extends Apic
         $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();
+                $res2 = $client->request('POST', 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$tk, [
+                    'json' => [
+                        //'page' => 'pages/home/index',
+                        'env_version'=>'trial',
+                        'scene' => 'shopId='.$companyId,
+                    ]
+                ]);
+                $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;
+            } else {
+                $miniCode = $httpStr.$company['mini_code'];
+            }
+            $result = [
+                'mini_code' => $miniCode,
+            ];
+            $this->success('获取成功',$result);
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+    }
 }