NotifySubscriptionConfigService.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace addons\TinyShop\services\common;
  3. use common\enums\AppEnum;
  4. use common\components\Service;
  5. use common\enums\StatusEnum;
  6. use addons\TinyShop\common\models\common\NotifySubscriptionConfig;
  7. /**
  8. * Class NotifySubscriptionConfigService
  9. * @package addons\TinyShop\services\common
  10. * @author jianyan74 <751393839@qq.com>
  11. */
  12. class NotifySubscriptionConfigService extends Service
  13. {
  14. /**
  15. * @param $app_id
  16. * @param $member_id
  17. * @return NotifySubscriptionConfig|array|\yii\db\ActiveRecord
  18. */
  19. public function findByMemberId($member_id, $merchant_id, $app_id = AppEnum::API)
  20. {
  21. $config = NotifySubscriptionConfig::find()
  22. ->where(['member_id' => $member_id])
  23. ->one();
  24. if (!$config) {
  25. $config = new NotifySubscriptionConfig();
  26. $config->app_id = $app_id;
  27. $config->merchant_id = $merchant_id;
  28. $config->member_id = $member_id;
  29. $config->action = $this->getAction($app_id);
  30. $config->save();
  31. }
  32. return $config;
  33. }
  34. /**
  35. * @param $app_id
  36. * @return array
  37. */
  38. protected function getAction($app_id)
  39. {
  40. switch ($app_id) {
  41. default :
  42. return [
  43. 'all' => StatusEnum::ENABLED,
  44. ];
  45. break;
  46. }
  47. }
  48. }
粤ICP备19079148号