UserMerchant.php 1.2 KB

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