Report.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\admin\model\ask;
  3. use addons\ask\library\Service;
  4. use think\Model;
  5. class Report extends Model
  6. {
  7. // 表名
  8. protected $name = 'ask_report';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text',
  17. 'type_text',
  18. 'reason_text',
  19. ];
  20. public function getTypeList()
  21. {
  22. return ['question' => __('Question'), 'article' => __('Article'), 'answer' => __('Answer'), 'tag' => __('Tag'), 'comment' => __('Comment')];
  23. }
  24. public function getReasonList()
  25. {
  26. $config = get_addon_config('ask');
  27. return $config['reportreasonlist'];
  28. }
  29. public function getStatusList()
  30. {
  31. return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
  32. }
  33. public function getTypeTextAttr($value, $data)
  34. {
  35. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  36. $list = $this->getTypeList();
  37. return isset($list[$value]) ? $list[$value] : '';
  38. }
  39. public function getReasonTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['reason']) ? $data['reason'] : '');
  42. $list = $this->getReasonList();
  43. return isset($list[$value]) ? $list[$value] : '';
  44. }
  45. public function getStatusTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  48. $list = $this->getStatusList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. public function user()
  52. {
  53. return $this->belongsTo("\app\common\model\User", 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  54. }
  55. }