xhWxOpenService.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace common\services;
  3. use Yii;
  4. use common\components\stringUtil;
  5. use common\components\configDict;
  6. use common\models\xhWxOpen;
  7. class xhWxOpenService {
  8. public static function getById($id=0)
  9. {
  10. $condition = ['id' => $id];
  11. $merchant = xhWxOpen::getByCondition($condition);
  12. return $merchant;
  13. }
  14. public static function updateById($id, $data)
  15. {
  16. xhWxOpen::updateById($id, $data);
  17. self::refresh($id);
  18. }
  19. public static function refresh($id)
  20. {
  21. $preKey = configDict::getCacheKey('wxOpen');
  22. $cacheKey = $preKey.$id;
  23. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  24. self::getById($id);
  25. }
  26. public static function add($data)
  27. {
  28. $data = xhWxOpen::add($data);
  29. $id = $data['id'];
  30. self::refresh($id);
  31. return $data;
  32. }
  33. /**
  34. * 取平台相应的商家
  35. */
  36. public static function getMerchant()
  37. {
  38. $wxOpenId = configDict::getConfig('openId');
  39. $wxOpen = xhWxOpenService::getById($wxOpenId);
  40. $merchantId = $wxOpen['merchantId'];
  41. $merchant = xhMerchantService::getById($merchantId);
  42. return $merchant;
  43. }
  44. }