58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace admin\controllers;
|
|
|
|
use common\core\BaseController;
|
|
use common\models\oldDb\Store;
|
|
use common\services\WeappService;
|
|
use yii\db\Exception;
|
|
|
|
|
|
//门店
|
|
class StoreController extends BaseController
|
|
{
|
|
/**
|
|
* @doc-name 生成门店二维码
|
|
* @doc-param int store_id 门店
|
|
* @doc-return string qrcode base64的二维码图片
|
|
*/
|
|
public static function actionQrcode($store_id=null)
|
|
{
|
|
$scene = 'STORE_QR_CODE'.'_'.$store_id;
|
|
// \Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
|
|
$store = Store::find()->where([
|
|
'id' => $store_id
|
|
])->one();
|
|
if (!$store){
|
|
throw new Exception('门店不存在');
|
|
}
|
|
// if (!$store->qr_code) {
|
|
// $response = WechatService::getInstance()->app->app_code->getUnlimit($scene, [
|
|
// 'page' => 'pages/home/home',
|
|
// 'check_path' => false,
|
|
// ]);
|
|
//
|
|
// if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
|
|
// $path = 'uploads/STORE_QR_CODE/' . date('Ymd');
|
|
// $filename = $response->save('uploads/STORE_QR_CODE/' . date('Ymd'), 'STORE_QR_CODE_' . $store_id);
|
|
//
|
|
// $realpath = FuncHelper::getRealFilepath('service', $path . '/' . $filename);
|
|
//
|
|
// $uploadService = new UploadService();
|
|
// $url = $uploadService->saveFile($realpath);
|
|
//
|
|
// $store->setAttributes(['qr_code' => $url]);
|
|
// $store->save();
|
|
// }
|
|
// }
|
|
if (!$store->qr_code) {
|
|
$weappService = new WeappService();
|
|
$url= $weappService->getQrcode($scene);
|
|
$store->qr_code=$url;
|
|
$store->saveOrFail();
|
|
}
|
|
return $store->qr_code;
|
|
}
|
|
|
|
|
|
} |