OtherOrder.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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\order;
  12. use app\model\user\User;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. class OtherOrder extends BaseModel
  17. {
  18. use ModelTrait;
  19. /**
  20. * 数据表主键
  21. * @var string
  22. */
  23. protected $pk = 'id';
  24. /**
  25. * 模型名称
  26. * @var string
  27. */
  28. protected $name = 'other_order';
  29. protected $insert = ['add_time'];
  30. // protected $hidden = ['add_time', 'is_del', 'uid'];
  31. /**订单类型
  32. * @param $query
  33. * @param $value
  34. */
  35. public function searchTypeAttr($query, $value)
  36. {
  37. if (is_array($value)) {
  38. $query->where('type', 'in', $value);
  39. }else{
  40. $query->where('type', $value);
  41. }
  42. }
  43. public function searchPaidAttr($query, $value)
  44. {
  45. $query->where('paid', $value);
  46. }
  47. /**支付方式不属于
  48. * @param $query
  49. * @param $value
  50. */
  51. public function searchPayTypeNoAttr($query, $value)
  52. {
  53. $query->where('pay_type', '<>', $value);
  54. }
  55. /**
  56. * 用户来源
  57. * @param Model $query
  58. * @param $value
  59. */
  60. public function searchChannelTypeAttr($query, $value)
  61. {
  62. if ($value != '') $query->where('channel_type', $value);
  63. }
  64. /**订单id搜索器
  65. * @param $query
  66. * @param $value
  67. */
  68. public function searchOrderIdAttr($query, $value)
  69. {
  70. if ($value != ""){
  71. $query->where('order_id', $value);
  72. }
  73. }
  74. /**
  75. * 一对一关联用户表
  76. * @return \think\model\relation\HasOne
  77. */
  78. public function user()
  79. {
  80. return $this->hasOne(User::class, 'uid', 'uid')->field(['uid', 'nickname', 'phone', 'spread_uid', 'overdue_time']);
  81. }
  82. /**会员类型
  83. * @param $query
  84. * @param $value
  85. */
  86. public function searchMemberTypeAttr($query, $value)
  87. {
  88. if ($value && $value != 'card' && $value != 'free') {
  89. $query->where('member_type', $value);
  90. } elseif ($value == 'card') {
  91. $query->where('member_type', 'free')->where('code', '<>', '');
  92. } elseif ($value == 'free') {
  93. $query->where('member_type', 'free')->where('code', '');
  94. }
  95. }
  96. /**支付方式
  97. * @param $query
  98. * @param $value
  99. */
  100. public function searchPayTypeAttr($query, $value)
  101. {
  102. if ($value){
  103. if ($value == "free"){
  104. $query->where(function($query){
  105. $query->where('type', 'in', [0,2])->whereOr(function($query){
  106. $query->where(['type' => 1, 'is_free' => 1]);
  107. });
  108. });
  109. }else{
  110. $query->where('pay_type', $value);
  111. }
  112. }
  113. }
  114. /**
  115. * @param $query
  116. * @param $value
  117. */
  118. public function searchAddTimeAttr($query, $value)
  119. {
  120. if ($value){
  121. $query->whereTime('add_time', 'between', $value);
  122. }
  123. }
  124. /**
  125. * @param $query
  126. * @param $value
  127. */
  128. public function searchUidAttr($query, $value)
  129. {
  130. if ($value){
  131. $query->where('uid', 'in', $value);
  132. }
  133. }
  134. }