AwardIntegral.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 AwardIntegral 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 = 'award_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 userOrder()
  55. {
  56. return $this->hasOne(StoreOrder::class, 'id', 'order_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. * 用户uid
  72. * @param Model $query
  73. * @param $value
  74. */
  75. public function searchOrderPriceEltAttr($query, $value)
  76. {
  77. $query->where('order_price', '<=', $value);
  78. }
  79. /**
  80. * 门店ID
  81. * @param $query
  82. * @param $value
  83. */
  84. public function searchStatusAttr($query, $value)
  85. {
  86. $query->where('status', $value);
  87. }
  88. /**
  89. * 门店ID
  90. * @param $query
  91. * @param $value
  92. */
  93. public function searchValidAttr($query, $value)
  94. {
  95. $award_order_limit_type = sys_config('award_order_limit_type');
  96. $award_order_limit = sys_config('award_order_limit');
  97. if ($award_order_limit_type == 1) $award_order_limit = 0.01;
  98. if ($value == 1) {
  99. $query->where('status', 0)->where('sent_num<num')
  100. ->where('order_price', '>=', $award_order_limit)
  101. ->where('add_time', '>=', strtotime('2024-11-18'))
  102. ->where('pay_type', '<>', 'yue');
  103. } else if ($value == 2) {
  104. $query->where(function ($query) {
  105. $query->where('status', 1)->whereOr('sent_num>=num');
  106. })->where('order_price', '>=', $award_order_limit)
  107. ->where('add_time', '>=', strtotime('2024-11-18'))
  108. ->where('pay_type', '<>', 'yue');
  109. } else {
  110. $query->where('order_price', '<', $award_order_limit)
  111. ->whereOr('add_time', '<', strtotime('2024-11-18'))
  112. ->whereOr('pay_type', 'yue');
  113. }
  114. }
  115. /**
  116. * 门店ID
  117. * @param $query
  118. * @param $value
  119. */
  120. public function searchValidsAttr($query, $value)
  121. {
  122. $award_order_limit_type = sys_config('award_order_limit_type_2');
  123. $award_order_limit = sys_config('award_order_limit_2');
  124. if ($award_order_limit_type == 1) $award_order_limit = 0.01;
  125. if ($value == 1) {
  126. $query->where('status', 0)->where('sent_num<num')
  127. ->where('order_price', '>=', $award_order_limit)
  128. ->where('add_time', '>=', strtotime('2024-11-18'))
  129. ->where('pay_type', '<>', 'yue');
  130. } else if ($value == 2) {
  131. $query->where(function ($query) {
  132. $query->where('status', 1)->whereOr('sent_num>=num');
  133. })->where('order_price', '>=', $award_order_limit)
  134. ->where('add_time', '>=', strtotime('2024-11-18'))
  135. ->where('pay_type', '<>', 'yue');
  136. } else {
  137. $query->where('order_price', '<', $award_order_limit)
  138. ->whereOr('add_time', '<', strtotime('2024-11-18'))
  139. ->whereOr('pay_type', 'yue');
  140. }
  141. }
  142. /**
  143. * 门店ID
  144. * @param $query
  145. * @param $value
  146. */
  147. public function searchAddTimeGtAttr($query, $value)
  148. {
  149. $query->where('add_time', '>', $value);
  150. }
  151. /**
  152. * 门店ID
  153. * @param $query
  154. * @param $value
  155. */
  156. public function searchAddTimeDateAttr($query, $value)
  157. {
  158. $query->whereTime('add_time', $value);
  159. }
  160. /**
  161. * 订单号
  162. * @param Model $query
  163. * @param $value
  164. */
  165. public function searchLinkIdAttr($query, $value)
  166. {
  167. $query->where('link_id', $value);
  168. }
  169. }