1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace app\common\model;
- use think\db\Query;
- use think\Model;
- use think\model\relation\BelongsTo;
- class Feedback extends Model
- {
-
-
- // 表名
- protected $table = 'feedback';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- // 定义时间戳字段名
- protected $createTime = 'created_at';
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'created_at_text'
- ];
- protected $type=[
- 'images'=>'array',
- 'content'=>'json',
- ];
-
- public function getCreatedAtTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['created_at']) ? $data['created_at'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setCreatedAtAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- /**
- * @return User|BelongsTo
- */
- public function user()
- {
- return $this->belongsTo(User::class)->removeOption('soft_delete');
- }
- public function deal($body){
- $this['deal_at']=time();
- $this['deal_body']=$body;
- $this->save();
- }
- public function scopeWait(Query $query,$un=true){
- if($un) {
- $query->whereNull('deal_at');
- }else{
- $query->whereNotNull('deal_at');
- }
- }
- }
|