StoreIntegralOrder.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\activity\integral;
  12. use app\model\user\User;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * TODO 订单Model
  18. * Class StoreOrder
  19. * @package app\model\order
  20. */
  21. class StoreIntegralOrder 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 = 'store_integral_order';
  34. protected $insert = ['add_time'];
  35. /**
  36. * 更新时间
  37. * @var bool | string | int
  38. */
  39. protected $updateTime = false;
  40. /**
  41. * 创建时间修改器
  42. * @return int
  43. */
  44. protected function setAddTimeAttr()
  45. {
  46. return time();
  47. }
  48. /**
  49. * 一对一关联用户表
  50. * @return \think\model\relation\HasOne
  51. */
  52. public function user()
  53. {
  54. return $this->hasOne(User::class, 'uid', 'uid')->field(['uid', 'nickname', 'phone', 'spread_uid'])->bind([
  55. 'nickname' => 'nickname',
  56. 'phone' => 'phone',
  57. 'spread_uid' => 'spread_uid',
  58. ]);
  59. }
  60. /**
  61. * 订单ID搜索器
  62. * @param Model $query
  63. * @param $value
  64. */
  65. public function searchOrderIdAttr($query, $value)
  66. {
  67. $query->where('order_id', $value);
  68. }
  69. /**
  70. * 订单状态搜索器
  71. * @param Model $query
  72. * @param $value
  73. */
  74. public function searchStatusAttr($query, $value)
  75. {
  76. if ($value !== '') {
  77. $query->where('status', $value);
  78. }
  79. }
  80. /**
  81. * 商品id搜索器
  82. * @param Model $query
  83. * @param $value
  84. */
  85. public function searchProductIdAttr($query, $value)
  86. {
  87. if ($value !== '') {
  88. if(is_array($value)){
  89. $query->whereIn('product_id', $value);
  90. }else{
  91. $query->where('product_id', $value);
  92. }
  93. }
  94. }
  95. /**
  96. * 核销码搜索器
  97. * @param Model $query
  98. * @param $value
  99. */
  100. public function searchVerifyCodeAttr($query, $value)
  101. {
  102. $query->where('verify_code', $value);
  103. }
  104. /**
  105. * @param Model $query
  106. * @param $value
  107. */
  108. public function searchIdAttr($query, $value)
  109. {
  110. if (is_array($value)) {
  111. $query->whereIn('id', $value);
  112. } else {
  113. $query->where('id', $value);
  114. }
  115. }
  116. /**
  117. * 订单id或者用户名搜索器
  118. * @param $query
  119. * @param $value
  120. */
  121. public function searchOrderIdRealNameAttr($query, $value)
  122. {
  123. $query->where('order_id|real_name', $value);
  124. }
  125. /**
  126. * 用户ID搜索器
  127. * @param Model $query
  128. * @param $value
  129. */
  130. public function searchUidAttr($query, $value)
  131. {
  132. if (is_array($value))
  133. $query->whereIn('uid', $value);
  134. else
  135. $query->where('uid', $value);
  136. }
  137. /**
  138. * 用户来源
  139. * @param Model $query
  140. * @param $value
  141. */
  142. public function searchChannelTypeAttr($query, $value)
  143. {
  144. if ($value != '') $query->where('channel_type', $value);
  145. }
  146. }