UserIntegral.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 app\model\order\StoreOrder;
  13. use app\model\store\SystemStoreStaff;
  14. use crmeb\basic\BaseModel;
  15. use crmeb\traits\ModelTrait;
  16. use think\model;
  17. /**
  18. * Class UserRecharge
  19. * @package app\model\user
  20. */
  21. class UserIntegral extends BaseModel
  22. {
  23. use ModelTrait;
  24. /**
  25. * 数据表主键
  26. * @var string
  27. */
  28. protected $pk = 'id';
  29. /**
  30. * 模型名称
  31. * @var string
  32. */
  33. protected $name = 'user_integral';
  34. protected $insert = ['add_time'];
  35. protected function setAddTimeAttr()
  36. {
  37. return time();
  38. }
  39. /**
  40. * 关联user
  41. * @return model\relation\HasOne
  42. */
  43. public function user()
  44. {
  45. return $this->hasOne(User::class, 'uid', 'uid', false)->bind([
  46. 'nickname' => 'nickname',
  47. 'avatar' => 'avatar',
  48. 'phone' => 'phone',
  49. 'now_money' => 'now_money',
  50. 'integral' => 'integral',
  51. 'delete_time' => 'delete_time'
  52. ]);
  53. }
  54. public function user_order()
  55. {
  56. return $this->hasOne(StoreOrder::class, 'id', 'link_id');
  57. }
  58. /**
  59. * 用户uid
  60. * @param Model $query
  61. * @param $value
  62. */
  63. public function searchUidAttr($query, $value)
  64. {
  65. if (is_array($value))
  66. $query->whereIn('uid', $value);
  67. else
  68. $query->where('uid', $value);
  69. }
  70. /**
  71. * 门店ID
  72. * @param $query
  73. * @param $value
  74. */
  75. public function searchStatusAttr($query, $value)
  76. {
  77. $query->where('status', $value);
  78. }
  79. /**
  80. * 门店ID
  81. * @param $query
  82. * @param $value
  83. */
  84. public function searchAddTimeGtAttr($query, $value)
  85. {
  86. $query->where('add_time', '>', $value);
  87. }
  88. /**
  89. * 门店ID
  90. * @param $query
  91. * @param $value
  92. */
  93. public function searchExtractTimeGtAttr($query, $value)
  94. {
  95. $query->where('extract_time', '>', $value);
  96. }
  97. /**
  98. * 门店店员ID
  99. * @param $query
  100. * @param $value
  101. */
  102. public function searchTypeAttr($query, $value)
  103. {
  104. $query->where('type', $value);
  105. }
  106. /**
  107. * 订单号
  108. * @param Model $query
  109. * @param $value
  110. */
  111. public function searchOrderIdAttr($query, $value)
  112. {
  113. $query->where('link_id', $value);
  114. }
  115. public function searchOrderIdNotAttr($query, $value)
  116. {
  117. $query->where('link_id', '<>', $value);
  118. }
  119. /**
  120. * 订单号
  121. * @param Model $query
  122. * @param $value
  123. */
  124. public function searchExtractPriceAttr($query, $value)
  125. {
  126. $query->where('(num *' . $value . ')>=extract_sum');
  127. }
  128. }