Feedback.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. use app\common\Enum\FeedbackEnum;
  6. class Feedback extends Model
  7. {
  8. use SoftDelete;
  9. // 表名
  10. protected $table = 'shop_feedback';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = 'integer';
  13. // 定义时间戳字段名
  14. protected $createTime = 'createtime';
  15. protected $updateTime = 'updatetime';
  16. protected $deleteTime = 'deletetime';
  17. // 追加属性
  18. protected $append = [
  19. ];
  20. public function setImagesAttr($value)
  21. {
  22. if (is_array($value)) {
  23. return implode(',', $value);
  24. }
  25. return $value;
  26. }
  27. public function user()
  28. {
  29. return $this->belongsTo('User', 'user_id', 'id');
  30. }
  31. public function getTypeTextAttr($value, $data)
  32. {
  33. return FeedbackEnum::getFeedbackTypeText($data['type']);
  34. }
  35. public function getImageTextAttr($value, $data){
  36. return json_decode($data['images'], true);
  37. }
  38. public function getImagesAttr($value)
  39. {
  40. if ($value === '' || $value === null) {
  41. return [];
  42. }
  43. return explode(',', $value);
  44. }
  45. }