Servicequestion.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Servicequestion extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $table = 'service_question';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = false;
  12. // 定义时间戳字段名
  13. protected $createTime = false;
  14. protected $updateTime = false;
  15. protected $deleteTime = 'deletetime';
  16. // 追加属性
  17. protected $append = [
  18. 'kind_text',
  19. 'status_text',
  20. 'options_jsonstr'
  21. ];
  22. public function getOptionsJsonAttr($value)
  23. {
  24. if ($value = json_decode($value, true)) {
  25. $data = [];
  26. foreach ($value as $key => $row) {
  27. $arr['key'] = $key;
  28. $arr['value'] = $row;
  29. $arr['click_index'] = false;
  30. array_push($data, $arr);
  31. }
  32. return $data;
  33. }
  34. return [];
  35. }
  36. public function getOptionsJsonstrAttr($value, $data)
  37. {
  38. return $data['options_json'];
  39. }
  40. protected static function init()
  41. {
  42. self::afterInsert(function ($row) {
  43. $pk = $row->getPk();
  44. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  45. });
  46. }
  47. public function getKindList()
  48. {
  49. return ['SINGLE' => __('Kind single'), 'MULTI' => __('Kind multi')];
  50. }
  51. public function getStatusList()
  52. {
  53. return ['1' => __('Status 1'), '0' => __('Status 0')];
  54. }
  55. public function getKindTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['kind']) ? $data['kind'] : '');
  58. $list = $this->getKindList();
  59. return isset($list[$value]) ? $list[$value] : '';
  60. }
  61. public function getStatusTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  64. $list = $this->getStatusList();
  65. return isset($list[$value]) ? $list[$value] : '';
  66. }
  67. public function paper()
  68. {
  69. return $this->belongsTo('app\admin\model\Servicepaper', 'paper_id', 'id', [], 'LEFT')->setEagerlyType(0);
  70. }
  71. }