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. ];
  23. public function getCreatedAtTextAttr($value, $data)
  24. {
  25. $value = $value ? $value : (isset($data['created_at']) ? $data['created_at'] : '');
  26. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  27. }
  28. protected function setCreatedAtAttr($value)
  29. {
  30. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  31. }
  32. /**
  33. * @return User|BelongsTo
  34. */
  35. public function user()
  36. {
  37. return $this->belongsTo(User::class)->removeOption('soft_delete');
  38. }
  39. public function deal($body){
  40. $this['deal_at']=time();
  41. $this['deal_body']=$body;
  42. $this->save();
  43. }
  44. public function scopeWait(Query $query,$un=true){
  45. if($un) {
  46. $query->whereNull('deal_at');
  47. }else{
  48. $query->whereNotNull('deal_at');
  49. }
  50. }
  51. }