xhWxOpenService.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. {
  9. public static function getById($id = 0)
  10. {
  11. $merchant = xhWxOpen::getByCondition(['id' => $id]);
  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($isOpen)
  37. {
  38. $open = [];
  39. if ($isOpen == 1) {
  40. $open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
  41. }
  42. if ($isOpen == 2) {
  43. $open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
  44. }
  45. if (empty($open)) {
  46. util::fail('没有找到平台');
  47. }
  48. $merchantId = $open['merchantId'];
  49. $merchant = xhMerchantService::getById($merchantId);
  50. return $merchant;
  51. }
  52. }