xhWifiService.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace common\services;
  3. use Yii;
  4. use common\models\xhWifi;
  5. use common\components\configDict;
  6. use common\components\wxUtil;
  7. use common\components\util;
  8. class xhWifiService {
  9. /**
  10. * 根据shopId取门店设置的所有wifi
  11. */
  12. public static function getListByShopId($shopId)
  13. {
  14. $cacheKey = configDict::getCacheKey('xhWifiList').$shopId;
  15. $exists = Yii::$app->redis->executeCommand('EXISTS', [$cacheKey]);
  16. if(empty($exists)){
  17. $wifi = self::getAllByCondition(['shopId'=>$shopId]);
  18. $string = !empty($wifi) ? json_encode($wifi) : '';
  19. Yii::$app->redis->executeCommand('SET', [$cacheKey,$string]);
  20. }else{
  21. $cacheData = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  22. $wifi = !empty($cacheData) ? json_decode($cacheData,true) : [];
  23. }
  24. return $wifi;
  25. }
  26. public static function getAllByCondition($condition)
  27. {
  28. return xhWifi::getAllByCondition($condition);
  29. }
  30. /**
  31. * 下载Wifi二维码图片到本地
  32. * @param $shopId
  33. * @param $ssid
  34. * @param $merchant
  35. * @return array
  36. */
  37. public static function DownLoadWifiQrImg($shopId, $ssid, $merchant){
  38. $re = (new wxUtil($merchant))->getWifiQrCode($shopId, $ssid, 0);
  39. if($re['errcode'] == 0){
  40. $imgUrl = $re['data']['qrcode_url'];
  41. }else{
  42. return $re['errmsg'];
  43. }
  44. $webRootDir = dirname(Yii::$app->basePath);
  45. $saveQrCodeDir = $webRootDir . '/images/qrcode/weixinQrcode';
  46. $status = util::downLoadImage($imgUrl, $saveQrCodeDir, $shopId.'.jpg');
  47. return $status;
  48. }
  49. /**
  50. * Wifi二维码图片是否已下载
  51. * @param $shopId
  52. * @return bool true:存在; false:不存在
  53. */
  54. public static function existQrImage($shopId){
  55. $webRootDir = dirname(Yii::$app->basePath);
  56. $saveQrCodeDir = $webRootDir . '/images/qrcode/weixinQrcode/';
  57. $qrImage = $saveQrCodeDir . $shopId . '.jpg';
  58. return file_exists($qrImage);
  59. }
  60. }