1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace app\common\model;
- use think\Model;
- class UserCoupons extends Model
- {
-
-
- // 表名
- protected $name = 'user_coupons';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'endtime_text'
- ];
- public function getEndtimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setEndtimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- public function user()
- {
- return $this->belongsTo('User', 'user_id', 'id',[],'LEFT')->setEagerlyType(0);
- }
- public function company()
- {
- return $this->belongsTo('Company', 'company_id', 'id',[],'LEFT')->setEagerlyType(0);
- }
- }
|