UserInfo.php 892 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\common\model;
  3. use think\db\Query;
  4. use think\Model;
  5. /**
  6. * 会员模型
  7. * @method Query|self exists($data)
  8. * @property array custom
  9. */
  10. class UserInfo extends Model
  11. {
  12. public function user(){
  13. return $this->belongsTo(User::class)->removeOption('soft_delete');
  14. }
  15. public function setCustomAttr($value){
  16. if(!$value){
  17. $value=[];
  18. }
  19. return json_encode($value,JSON_UNESCAPED_UNICODE);
  20. }
  21. public function getCustomAttr($value){
  22. $data=json_decode($value,true);
  23. static $config;
  24. if(!$config){
  25. $config=config('site.userApprove')?:[];
  26. }
  27. $res=[];
  28. foreach ($config as $key=>$title){
  29. $res[]=[
  30. 'key'=>$key,
  31. 'title'=>$title,
  32. 'value'=>$data[$key]??'',
  33. ];
  34. }
  35. return $res;
  36. }
  37. }