初始化仓库
This commit is contained in:
61
admin/controllers/StoreController.php
Normal file
61
admin/controllers/StoreController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace admin\controllers;
|
||||
|
||||
use common\core\BaseController;
|
||||
use common\helpers\FuncHelper;
|
||||
use common\models\Store;
|
||||
use common\services\UploadService;
|
||||
use common\services\WeappService;
|
||||
use common\services\WechatService;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user