|
@@ -5,7 +5,9 @@ namespace app\api\controller\company;
|
|
use app\common\controller\Apic;
|
|
use app\common\controller\Apic;
|
|
use app\common\library\Sms;
|
|
use app\common\library\Sms;
|
|
use fast\Random;
|
|
use fast\Random;
|
|
|
|
+use GuzzleHttp\Client;
|
|
use think\Config;
|
|
use think\Config;
|
|
|
|
+use think\Exception;
|
|
use think\Validate;
|
|
use think\Validate;
|
|
|
|
|
|
use think\Db;
|
|
use think\Db;
|
|
@@ -154,5 +156,50 @@ class User extends Apic
|
|
$this->success('资料更新完成');
|
|
$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());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|