RechargeChannelGroup.php 1.5 KB

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