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
62 lines
1.7 KiB
<?php
|
|
|
|
namespace App\Models\v3;
|
|
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class CouponSetting extends Model
|
|
{
|
|
use HasDateTimeFormatter;
|
|
protected $table = 'lanzu_coupon_setting';
|
|
protected $dateFormat = 'U';
|
|
|
|
public static $publishTime = 3600;// 发布优惠券时,优惠券的结束时间至少比当前时间多一个小时
|
|
public static $category = [1=>'领取方式'];
|
|
public static $status = ['禁用','正常'];
|
|
|
|
protected $appends = [
|
|
'category_text',
|
|
'status_text'
|
|
];
|
|
|
|
public function getCategoryTextAttribute($value)
|
|
{
|
|
$value = $value ? $value : $this->category;
|
|
return isset(self::$category[$value]) ? self::$category[$value] : '';
|
|
}
|
|
public function getStatusTextAttribute($value)
|
|
{
|
|
$value = $value ? $value : $this->status;
|
|
return isset(self::$status[$value]) ? self::$status[$value] : '';
|
|
}
|
|
|
|
/**
|
|
* 获取数组
|
|
*/
|
|
public static function getSettingArray($where = [],$options = [])
|
|
{
|
|
$model = self::where('status',1)
|
|
->whereNull('deleted_at');
|
|
|
|
if(!empty($where)){
|
|
$model->where($where);
|
|
}
|
|
$list = $model->pluck('id','name')->toArray();
|
|
if(!empty($options)){
|
|
$new = array_merge($options,$list);
|
|
return array_flip($new);
|
|
}else{
|
|
return array_flip($list);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 根据id获取单条数据
|
|
*/
|
|
public static function getSettingInfo($id,$field = '*')
|
|
{
|
|
// return self::select($field)->find($id);
|
|
return self::select($field)->where('id',$id)->first();
|
|
}
|
|
}
|