| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace common\services;
- use Yii;
- use common\models\xhWifi;
- use common\components\configDict;
- use common\components\weixinUtil;
- use common\components\util;
- class xhWifiService {
- /**
- * 根据shopId取门店设置的所有wifi
- */
- public static function getListByShopId($shopId)
- {
- $cacheKey = configDict::getCacheKey('xhWifiList').$shopId;
- $exists = Yii::$app->redis->executeCommand('EXISTS', [$cacheKey]);
- if(empty($exists)){
- $wifi = self::getAllByCondition(['shopId'=>$shopId]);
- $string = !empty($wifi) ? json_encode($wifi) : '';
- Yii::$app->redis->executeCommand('SET', [$cacheKey,$string]);
- }else{
- $cacheData = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- $wifi = !empty($cacheData) ? json_decode($cacheData,true) : [];
- }
- return $wifi;
- }
-
- public static function getAllByCondition($condition)
- {
- return xhWifi::getAllByCondition($condition);
- }
- /**
- * 下载Wifi二维码图片到本地
- * @param $shopId
- * @param $ssid
- * @param $merchant
- * @return array
- */
- public static function DownLoadWifiQrImg($shopId, $ssid, $merchant){
- $re = (new weixinUtil($merchant))->getWifiQrCode($shopId, $ssid, 0);
- if($re['errcode'] == 0){
- $imgUrl = $re['data']['qrcode_url'];
- }else{
- return $re['errmsg'];
- }
- $webRootDir = dirname(Yii::$app->basePath);
- $saveQrCodeDir = $webRootDir . '/images/qrcode/weixinQrcode';
- $status = util::downLoadImage($imgUrl, $saveQrCodeDir, $shopId.'.jpg');
- return $status;
- }
- /**
- * Wifi二维码图片是否已下载
- * @param $shopId
- * @return bool true:存在; false:不存在
- */
- public static function existQrImage($shopId){
- $webRootDir = dirname(Yii::$app->basePath);
- $saveQrCodeDir = $webRootDir . '/images/qrcode/weixinQrcode/';
- $qrImage = $saveQrCodeDir . $shopId . '.jpg';
- return file_exists($qrImage);
- }
- }
|