|
@@ -5,6 +5,7 @@ namespace app\api\controller\company;
|
|
|
use app\common\controller\Apic;
|
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
|
+use GuzzleHttp\Client;
|
|
|
|
|
|
/**
|
|
|
* 套餐管理
|
|
@@ -107,6 +108,43 @@ class Package extends Apic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function showposter(){
|
|
|
+ $id = input('id',1);
|
|
|
+ $this->getMiniCode($id,$this->auth->company_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getMiniCode($id,$companyid)
|
|
|
+ {
|
|
|
+ $package = Db::name('package')->where('id',$id)->find();
|
|
|
+
|
|
|
+ $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
|
|
|
+ if (empty($package['mini_code'])) {
|
|
|
+ $client = new Client();
|
|
|
+ $tk = getAccessToken();
|
|
|
+ $miniCodeConfig = config('param.mini_code');
|
|
|
+ //$miniCodeConfig['env_version'] = 'trial'; //强制体验版
|
|
|
+ $miniCodeConfig['scene'] = 'id='.$id.'&shopId='.$companyid;
|
|
|
+ $res2 = $client->request('POST', 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$tk, [
|
|
|
+ 'json' => $miniCodeConfig,
|
|
|
+ ]);
|
|
|
+ $fileName = md5($id);
|
|
|
+ $fileUrl = '/uploads/package/'.$fileName.'.png';
|
|
|
+ $code = $res2->getBody()->getContents();
|
|
|
+ file_put_contents(ROOT_PATH.'/public'.$fileUrl,$code);
|
|
|
+
|
|
|
+ $companyRes = Db::name('package')->where('id',$id)->update(['mini_code'=>$fileUrl]);
|
|
|
+ if ($companyRes === false) {
|
|
|
+ $this->error('生成套餐小程序码失败');
|
|
|
+ }
|
|
|
+ $miniCode = $httpStr.$fileUrl;
|
|
|
+ } else {
|
|
|
+ $miniCode = $httpStr.$package['mini_code'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('success',$miniCode);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
//上下架
|
|
|
public function changestatus(){
|
|
|
//验证
|