链街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.

62 lines
1.7 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 $publishTime = 3600;// 发布优惠券时,优惠券的结束时间至少比当前时间多一个小时
  11. public static $category = [1=>'领取方式'];
  12. public static $status = ['禁用','正常'];
  13. protected $appends = [
  14. 'category_text',
  15. 'status_text'
  16. ];
  17. public function getCategoryTextAttribute($value)
  18. {
  19. $value = $value ? $value : $this->category;
  20. return isset(self::$category[$value]) ? self::$category[$value] : '';
  21. }
  22. public function getStatusTextAttribute($value)
  23. {
  24. $value = $value ? $value : $this->status;
  25. return isset(self::$status[$value]) ? self::$status[$value] : '';
  26. }
  27. /**
  28. * 获取数组
  29. */
  30. public static function getSettingArray($where = [],$options = [])
  31. {
  32. $model = self::where('status',1)
  33. ->whereNull('deleted_at');
  34. if(!empty($where)){
  35. $model->where($where);
  36. }
  37. $list = $model->pluck('id','name')->toArray();
  38. if(!empty($options)){
  39. $new = array_merge($options,$list);
  40. return array_flip($new);
  41. }else{
  42. return array_flip($list);
  43. }
  44. }
  45. /**
  46. * 根据id获取单条数据
  47. */
  48. public static function getSettingInfo($id,$field = '*')
  49. {
  50. // return self::select($field)->find($id);
  51. return self::select($field)->where('id',$id)->first();
  52. }
  53. }