xhWxOpenService.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. $merchant = xhWxOpen::getByCondition(['id'=>$id]);
  11. return $merchant;
  12. }
  13. public static function updateById($id, $data)
  14. {
  15. xhWxOpen::updateById($id, $data);
  16. self::refresh($id);
  17. }
  18. public static function refresh($id)
  19. {
  20. $preKey = configDict::getCacheKey('wxOpen');
  21. $cacheKey = $preKey.$id;
  22. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  23. self::getById($id);
  24. }
  25. public static function add($data)
  26. {
  27. $data = xhWxOpen::add($data);
  28. $id = $data['id'];
  29. self::refresh($id);
  30. return $data;
  31. }
  32. /**
  33. * 取平台相应的商家
  34. */
  35. public static function getMerchant()
  36. {
  37. $wxOpenId = configDict::getConfig('openId');
  38. $wxOpen = xhWxOpenService::getById($wxOpenId);
  39. $merchantId = $wxOpen['merchantId'];
  40. $merchant = xhMerchantService::getById($merchantId);
  41. return $merchant;
  42. }
  43. }