链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

  1. <?php
  2. namespace App\Models\v3;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\Model;
  5. class CouponSetting extends Model
  6. {
  7. use HasDateTimeFormatter;
  8. protected $table = 'lanzu_coupon_setting';
  9. protected $dateFormat = 'U';
  10. public static $_CATEGORY = [1=>'领取方式'];
  11. public static $_STATUS = ['禁用','正常'];
  12. protected $appends = [
  13. 'category_text',
  14. 'status_text'
  15. ];
  16. public function getCategoryTextAttribute($value)
  17. {
  18. $value = $value ? $value : $this->category;
  19. return isset(self::$_CATEGORY[$value]) ? self::$_CATEGORY[$value] : '';
  20. }
  21. public function getStatusTextAttribute($value)
  22. {
  23. $value = $value ? $value : $this->status;
  24. return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : '';
  25. }
  26. /**
  27. * 获取数组
  28. */
  29. public static function getSettingArray($where = [],$options = [])
  30. {
  31. $model = self::where('status',1)
  32. ->whereNull('deleted_at');
  33. if(!empty($where)){
  34. $model->where($where);
  35. }
  36. $list = $model->pluck('name','id')->toArray();
  37. if(!empty($options)){
  38. return array_merge($options,$list);
  39. }else{
  40. return $list;
  41. }
  42. }
  43. /**
  44. * 根据id获取单条数据
  45. */
  46. public static function getSettingInfo($id,$field = '*')
  47. {
  48. // return self::select($field)->find($id);
  49. return self::select($field)->where('id',$id)->first();
  50. }
  51. }