RechargeChannelGroup.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\SoftDeletes;
  4. class RechargeChannelGroup extends BaseModel
  5. {
  6. use SoftDeletes;
  7. protected $table = 'recharge_channel_group';
  8. protected $fillable = ['name', 'recharge_type', 'withdraw_type', 'activity_type'];
  9. protected $hidden = [];
  10. // 修改器:将逗号分隔字符串转为数组
  11. public function getRechargeTypeAttribute($value)
  12. {
  13. return $value ? explode(',', $value) : [];
  14. }
  15. // 设置器:将数组转为逗号分隔字符串
  16. public function setRechargeTypeAttribute($value)
  17. {
  18. $this->attributes['recharge_type'] = is_array($value) ? implode(',', $value) : $value;
  19. }
  20. public function getWithdrawTypeAttribute($value)
  21. {
  22. return $value ? explode(',', $value) : [];
  23. }
  24. public function setWithdrawTypeAttribute($value)
  25. {
  26. $this->attributes['withdraw_type'] = is_array($value) ? implode(',', $value) : $value;
  27. }
  28. public function getActivityTypeAttribute($value)
  29. {
  30. return $value ? explode(',', $value) : [];
  31. }
  32. public function setActivityTypeAttribute($value)
  33. {
  34. if (!$value) {
  35. $this->attributes['activity_type'] = '';
  36. return;
  37. }
  38. $this->attributes['activity_type'] = is_array($value) ? implode(',', $value) : $value;
  39. }
  40. public static function getActivityType($id) {
  41. $id = $id > 0 ? $id : 1;
  42. $activity_type = self::where('id', $id)->value('activity_type');
  43. return $activity_type;
  44. }
  45. }