UserCard.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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\user;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. /**
  15. * 用户领取卡券
  16. * Class UserCard
  17. * @package app\model\user
  18. */
  19. class UserCard extends BaseModel
  20. {
  21. use ModelTrait;
  22. /**
  23. * 数据表主键
  24. * @var string
  25. */
  26. protected $pk = 'id';
  27. /**
  28. * 模型名称
  29. * @var string
  30. */
  31. protected $name = 'user_card';
  32. /**
  33. * 用户
  34. * @return \think\model\relation\HasOne
  35. */
  36. public function user()
  37. {
  38. return $this->hasOne(User::class, 'uid', 'uid')->field('uid,nickname,avatar')->bind([
  39. 'nickname' => 'nickname',
  40. 'avatar' => 'avatar'
  41. ]);
  42. }
  43. /**
  44. * uid
  45. * @param $query
  46. * @param $value
  47. */
  48. public function searchUidAttr($query, $value)
  49. {
  50. if ($value !== '') $query->where('uid', $value);
  51. }
  52. /**
  53. * wechat_card_id
  54. * @param $query
  55. * @param $value
  56. */
  57. public function searchWechatCardIdAttr($query, $value)
  58. {
  59. if (in_array($value)) {
  60. $query->whereIn('wechat_card_id', $value);
  61. } else {
  62. if ($value !== '') $query->where('wechat_card_id', $value);
  63. }
  64. }
  65. /**
  66. * card_id
  67. * @param $query
  68. * @param $value
  69. */
  70. public function searchCardIdAttr($query, $value)
  71. {
  72. if ($value) $query->where('card_id', $value);
  73. }
  74. /**
  75. * 门店ID
  76. * @param $query
  77. * @param $value
  78. */
  79. public function searchStoreIdAttr($query, $value)
  80. {
  81. if ($value !== '') {
  82. if ($value == -1) {//所有门店
  83. $query->where('store_id', '>', 0);
  84. } else {
  85. $query->where('store_id', $value);
  86. }
  87. }
  88. }
  89. /**
  90. * 门店店员ID
  91. * @param $query
  92. * @param $value
  93. */
  94. public function searchStaffIdAttr($query, $value)
  95. {
  96. if ($value) $query->where('staff_id', $value);
  97. }
  98. /**
  99. * openid
  100. * @param $query
  101. * @param $value
  102. */
  103. public function searchOpenidAttr($query, $value)
  104. {
  105. if ($value) $query->where('openid', $value);
  106. }
  107. /**
  108. * is_submit
  109. * @param $query
  110. * @param $value
  111. */
  112. public function searchIsSubmitAttr($query, $value)
  113. {
  114. if ($value !== '') $query->where('is_submit', $value);
  115. }
  116. /**
  117. * is_del
  118. * @param $query
  119. * @param $value
  120. */
  121. public function searchIsDelAttr($query, $value)
  122. {
  123. if ($value !== '') $query->where('is_del', $value);
  124. }
  125. }