LinkStoreModel.php 824 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. * @description:
  4. * @Date: 2022-09-26 20:27:01
  5. * @LastEditTime: 2022-09-26 20:27:53
  6. */
  7. namespace app\model;
  8. use think\Model;
  9. class LinkStoreModel extends Model
  10. {
  11. protected $name = "linkstore";
  12. protected $pk = "id";
  13. protected $jsonAssoc = true;
  14. protected $json = ['custom'];
  15. function userInfo(): \think\model\relation\HasOne
  16. {
  17. return $this->hasOne(UserModel::class, 'id', 'user_id')->field('id,nickname');
  18. }
  19. function setGroupIdsAttr($val): string
  20. {
  21. if (count($val) > 0) {
  22. return join(',', $val);
  23. }
  24. return '0';
  25. }
  26. function getGroupIdsAttr($val): array
  27. {
  28. if (strlen($val)) {
  29. return array_map('intval', explode(',', $val));
  30. }
  31. return [];
  32. }
  33. }