Question.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\model\base\question;
  3. /**
  4. * @title: 问答中心-问题
  5. * @Description:
  6. * @Author: goldenrock 112049337@qq.com
  7. * @Date: 2024-06-12 09:26:12
  8. * @return {*}
  9. * @method: POST
  10. * @LastEditTime: 2024-06-13 10:29:24
  11. * @LastEditors: goldenrock 112049337@qq.com
  12. */
  13. use app\common\model\Common;
  14. use app\common\model\base\user\User;
  15. class Question extends Common
  16. {
  17. protected $name = 'system_question';
  18. protected $createTime = 'create_at';
  19. protected $updateTime = 'update_at';
  20. protected $deleteTime = 'delete_at';
  21. protected $append = ['type_txt','status_txt','uid_txt'];
  22. static public function typeList()
  23. {
  24. $list = QuestionType::cache(50)->column('title','id');
  25. return $list;
  26. }
  27. public function getTypeTxtAttr($value,$data)
  28. {
  29. $value = $value ? $value : (isset($data['type_id']) ? $data['type_id'] : '');
  30. $list = self::typeList();
  31. return isset($list[$value]) ? $list[$value] : '';
  32. }
  33. static public function statusList()
  34. {
  35. return [1=>'待回复',2=>'已回复'];
  36. }
  37. public function getStatusTxtAttr($value,$data)
  38. {
  39. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  40. $list = self::statusList();
  41. return isset($list[$value]) ? $list[$value] : '';
  42. }
  43. public function getUidTxtAttr($value,$data)
  44. {
  45. $value = $value ? $value : (isset($data['uid']) ? $data['uid'] : '');
  46. $list = User::cache(50)->column('name','user_id');
  47. return isset($list[$value]) ? $list[$value] : '';
  48. }
  49. public function answers()
  50. {
  51. return $this->hasMany(QuestionAnswer::class,'question_id','id');
  52. }
  53. public function user()
  54. {
  55. return $this->belongsTo(User::class,'uid','user_id')->visible(['avatar','name']);
  56. }
  57. }