xhWxOpenService.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace common\services;
  3. use common\components\util;
  4. use Yii;
  5. use common\components\stringUtil;
  6. use common\components\dict;
  7. use common\models\xhWxOpen;
  8. class xhWxOpenService
  9. {
  10. public static function getById($id = 0)
  11. {
  12. $merchant = xhWxOpen::getByCondition(['id' => $id]);
  13. return $merchant;
  14. }
  15. public static function updateById($id, $data)
  16. {
  17. xhWxOpen::updateById($id, $data);
  18. self::refresh($id);
  19. }
  20. public static function refresh($id)
  21. {
  22. $preKey = dict::getCacheKey('wxOpen');
  23. $cacheKey = $preKey . $id;
  24. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  25. self::getById($id);
  26. }
  27. public static function add($data)
  28. {
  29. $data = xhWxOpen::add($data);
  30. $id = $data['id'];
  31. self::refresh($id);
  32. return $data;
  33. }
  34. /**
  35. * 取平台相应的商家
  36. */
  37. public static function getMerchant($isOpen)
  38. {
  39. $open = [];
  40. if ($isOpen == 1) {
  41. $open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
  42. } elseif ($isOpen == 2) {
  43. $open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
  44. } elseif ($isOpen == 3) {
  45. $open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_MALL]);
  46. } else {
  47. util::fail('没有找到平台');
  48. }
  49. $merchantId = $open['merchantId'];
  50. $merchant = xhMerchantService::getById($merchantId);
  51. return $merchant;
  52. }
  53. }