Servicequestion.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. ];
  21. public function getOptionsJsonAttr($value)
  22. {
  23. if ($value = json_decode($value, true)) {
  24. $data = [];
  25. foreach ($value as $key => $row) {
  26. $arr['key'] = $key;
  27. $arr['value'] = $row;
  28. $arr['click_index'] = false;
  29. array_push($data, $arr);
  30. }
  31. return $data;
  32. }
  33. return [];
  34. }
  35. protected static function init()
  36. {
  37. self::afterInsert(function ($row) {
  38. $pk = $row->getPk();
  39. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  40. });
  41. }
  42. public function getKindList()
  43. {
  44. return ['SINGLE' => __('Kind single'), 'MULTI' => __('Kind multi')];
  45. }
  46. public function getStatusList()
  47. {
  48. return ['1' => __('Status 1'), '0' => __('Status 0')];
  49. }
  50. public function getKindTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['kind']) ? $data['kind'] : '');
  53. $list = $this->getKindList();
  54. return isset($list[$value]) ? $list[$value] : '';
  55. }
  56. public function getStatusTextAttr($value, $data)
  57. {
  58. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  59. $list = $this->getStatusList();
  60. return isset($list[$value]) ? $list[$value] : '';
  61. }
  62. public function paper()
  63. {
  64. return $this->belongsTo('app\admin\model\Servicepaper', 'paper_id', 'id', [], 'LEFT')->setEagerlyType(0);
  65. }
  66. }