xhWifiService.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace common\services;
  3. use Yii;
  4. use common\models\xhWifi;
  5. use common\components\dict;
  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 = dict::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. * @return bool true:存在; false:不存在
  34. */
  35. public static function existQrImage($shopId){
  36. $webRootDir = dirname(Yii::$app->basePath);
  37. $saveQrCodeDir = $webRootDir . '/images/qrcode/weixinQrcode/';
  38. $qrImage = $saveQrCodeDir . $shopId . '.jpg';
  39. return file_exists($qrImage);
  40. }
  41. }