SystemFormData.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\system\form;
  12. use app\model\user\User;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. class SystemFormData extends BaseModel
  17. {
  18. use ModelTrait;
  19. /**
  20. * 数据表主键
  21. * @var string
  22. */
  23. protected $pk = 'id';
  24. /**
  25. * 模型名称
  26. * @var string
  27. */
  28. protected $name = 'system_form_data';
  29. protected $updateTime = false;
  30. /**
  31. * 添加时间获取器
  32. * @param $value
  33. * @return false|string
  34. */
  35. public function getAddTimeAttr($value)
  36. {
  37. return date('Y-m-d H:i:s', $value);
  38. }
  39. /**
  40. * 收集数据信息
  41. * @param $value
  42. * @return array|mixed
  43. */
  44. protected function getValueAttr($value)
  45. {
  46. if ($value) {
  47. return is_string($value) ? json_decode($value, true) : $value;
  48. }
  49. return [];
  50. }
  51. /**
  52. * 关联user
  53. * @return \think\model\relation\HasOne
  54. */
  55. public function user()
  56. {
  57. return $this->hasOne(User::class, 'uid', 'uid')->field('uid,nickname,avatar,phone')->bind(['nickname', 'avatar', 'phone']);
  58. }
  59. /**
  60. * 关联系统表单
  61. * @return \think\model\relation\HasOne
  62. */
  63. public function systemForm()
  64. {
  65. return $this->hasOne(SystemForm::class, 'id', 'system_form_id')->field('id,name')->bind(['system_form_name' => 'name']);
  66. }
  67. /**
  68. * UID搜索器
  69. * @param Model $query
  70. * @param $value
  71. */
  72. public function searchUidAttr($query, $value)
  73. {
  74. if (is_array($value)) {
  75. if ($value) $query->whereIn('uid', $value);
  76. } else {
  77. if ($value !== '') $query->where('uid', $value);
  78. }
  79. }
  80. /**
  81. * system_form_id搜索器
  82. * @param Model $query
  83. * @param $value
  84. */
  85. public function searchSystemFormIdAttr($query, $value)
  86. {
  87. if (is_array($value)) {
  88. if ($value) $query->whereIn('system_form_id', $value);
  89. } else {
  90. if ($value !== '') $query->where('system_form_id', $value);
  91. }
  92. }
  93. /**
  94. * 类型搜索器
  95. * @param Model $query
  96. * @param $value
  97. */
  98. public function searchTypeAttr($query, $value)
  99. {
  100. if ($value != '') {
  101. if (is_array($value)) {
  102. $query->whereIn('type', $value);
  103. } else {
  104. $query->where('type', $value);
  105. }
  106. }
  107. }
  108. /**
  109. * 关联门店ID、供应商ID搜索器
  110. * @param Model $query
  111. * @param $value
  112. */
  113. public function searchRelationIdAttr($query, $value)
  114. {
  115. if (is_array($value)) {
  116. if ($value) $query->whereIn('relation_id', $value);
  117. } else {
  118. if ($value !== '') $query->where('relation_id', $value);
  119. }
  120. }
  121. /**
  122. * 是否删除搜索器
  123. * @param Model $query
  124. * @param $value
  125. */
  126. public function searchIsDelAttr($query, $value)
  127. {
  128. if ($value !== '') $query->where('is_del', $value);
  129. }
  130. }