UserMerchant.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\common\model\user;
  12. use app\common\model\BaseModel;
  13. /**
  14. * Class UserMerchant
  15. * @package app\common\model\user
  16. * @author xaboy
  17. * @day 2020/10/20
  18. */
  19. class UserMerchant extends BaseModel
  20. {
  21. /**
  22. * @return string|null
  23. * @author xaboy
  24. * @day 2020/10/20
  25. */
  26. public static function tablePk(): ?string
  27. {
  28. return 'user_merchant_id';
  29. }
  30. /**
  31. * @return string
  32. * @author xaboy
  33. * @day 2020/10/20
  34. */
  35. public static function tableName(): string
  36. {
  37. return 'user_merchant';
  38. }
  39. public function user()
  40. {
  41. return $this->hasOne(User::class, 'uid', 'uid');
  42. }
  43. /**
  44. * @param $value
  45. * @return array
  46. * @author xaboy
  47. * @day 2020-05-09
  48. */
  49. public function getLabelIdAttr($value)
  50. {
  51. return $value ? explode(',', $value) : [];
  52. }
  53. /**
  54. * @param $value
  55. * @return string
  56. * @author xaboy
  57. * @day 2020-05-09
  58. */
  59. public function setLabelIdAttr($value)
  60. {
  61. return implode(',', $value);
  62. }
  63. public function getAuthLabelAttr()
  64. {
  65. return app()->make(UserLabel::class)->whereIn('label_id', $this->label_id)->where('mer_id', $this->mer_id)->where('type', 1)->column('label_id');
  66. }
  67. }