Feedback.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\common\model;
  3. use think\db\Query;
  4. use think\Model;
  5. use think\model\relation\BelongsTo;
  6. class Feedback extends Model
  7. {
  8. // 表名
  9. protected $table = 'feedback';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = true;
  12. // 定义时间戳字段名
  13. protected $createTime = 'created_at';
  14. protected $updateTime = false;
  15. protected $deleteTime = false;
  16. // 追加属性
  17. protected $append = [
  18. 'created_at_text'
  19. ];
  20. protected $type=[
  21. 'images'=>'array',
  22. 'content'=>'json',
  23. ];
  24. public function getCreatedAtTextAttr($value, $data)
  25. {
  26. $value = $value ? $value : (isset($data['created_at']) ? $data['created_at'] : '');
  27. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  28. }
  29. protected function setCreatedAtAttr($value)
  30. {
  31. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  32. }
  33. /**
  34. * @return User|BelongsTo
  35. */
  36. public function user()
  37. {
  38. return $this->belongsTo(User::class)->removeOption('soft_delete');
  39. }
  40. public function deal($body){
  41. $this['deal_at']=time();
  42. $this['deal_body']=$body;
  43. $this->save();
  44. }
  45. public function scopeWait(Query $query,$un=true){
  46. if($un) {
  47. $query->whereNull('deal_at');
  48. }else{
  49. $query->whereNotNull('deal_at');
  50. }
  51. }
  52. }