ChannelSubscribeSettingService.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: z-yang
  5. * Date: 2018/3/13
  6. * Time: 11:31
  7. */
  8. namespace App\Modules\Channel\Services;
  9. use App\Modules\Channel\Models\ChannelSubscribeSetting;
  10. class ChannelSubscribeSettingService
  11. {
  12. /**
  13. * @param $distribution_channel_id
  14. * @return mixed
  15. */
  16. public static function getSubscribeTypeByChannelId($distribution_channel_id){
  17. return ChannelSubscribeSetting::where('distribution_channel_id',$distribution_channel_id)->select('force_subscribe_type','resource_url')->first();
  18. }
  19. public static function getSubscribeTypeByAppId($appid){
  20. return ChannelSubscribeSetting::where('appid',$appid)->select('id','force_subscribe_type','resource_url')->first();
  21. }
  22. /**
  23. * @param array $data
  24. * @return bool
  25. */
  26. public static function updateOrSettingForceSubScribe(array $data){
  27. if(empty($data['distribution_channel_id']) || empty($data['force_subscribe_type']) || empty($data['appid'])){
  28. return false;
  29. }
  30. $old = self::getSubscribeTypeByAppId($data['appid']);
  31. if($old){
  32. $old->force_subscribe_type = $data['force_subscribe_type'];
  33. if(isset($data['resource_url'])){
  34. $old->resource_url = $data['resource_url'];
  35. }
  36. $old->save();
  37. return true;
  38. }else{
  39. ChannelSubscribeSetting::create($data);
  40. return true;
  41. }
  42. }
  43. }