OtherOrder.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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\order;
  12. use app\model\store\SystemStoreStaff;
  13. use app\model\user\User;
  14. use crmeb\basic\BaseModel;
  15. use crmeb\traits\ModelTrait;
  16. use think\Model;
  17. class OtherOrder extends BaseModel
  18. {
  19. use ModelTrait;
  20. /**
  21. * 数据表主键
  22. * @var string
  23. */
  24. protected $pk = 'id';
  25. /**
  26. * 模型名称
  27. * @var string
  28. */
  29. protected $name = 'other_order';
  30. protected $insert = ['add_time'];
  31. // protected $hidden = ['add_time', 'is_del', 'uid'];
  32. /**
  33. * 门店ID
  34. * @param $query
  35. * @param $value
  36. */
  37. public function searchStoreIdAttr($query, $value)
  38. {
  39. if ($value !== '') {
  40. if ($value == -1) {//所有门店
  41. $query->where('store_id', '>', 0);
  42. } else {
  43. $query->where('store_id', $value);
  44. }
  45. }
  46. }
  47. /**
  48. * 门店店员ID
  49. * @param $query
  50. * @param $value
  51. */
  52. public function searchStaffIdAttr($query, $value)
  53. {
  54. if ($value) {
  55. if (is_array($value)) {
  56. $query->whereIn('staff_id', $value);
  57. } else {
  58. $query->where('staff_id', $value);
  59. }
  60. }
  61. }
  62. /**
  63. * 订单类型
  64. * @param $query
  65. * @param $value
  66. */
  67. public function searchTypeAttr($query, $value)
  68. {
  69. if ($value) {
  70. if (is_array($value)) {
  71. $query->where('type', 'in', $value);
  72. } else {
  73. $query->where('type', $value);
  74. }
  75. }
  76. }
  77. public function searchPaidAttr($query, $value)
  78. {
  79. $query->where('paid', $value);
  80. }
  81. /**
  82. * 支付方式不属于
  83. * @param $query
  84. * @param $value
  85. */
  86. public function searchPayTypeNoAttr($query, $value)
  87. {
  88. $query->where('pay_type', '<>', $value);
  89. }
  90. /**
  91. * 用户来源
  92. * @param Model $query
  93. * @param $value
  94. */
  95. public function searchChannelTypeAttr($query, $value)
  96. {
  97. if ($value != '') $query->where('channel_type', $value);
  98. }
  99. /**
  100. * 订单id搜索器
  101. * @param $query
  102. * @param $value
  103. */
  104. public function searchOrderIdAttr($query, $value)
  105. {
  106. if ($value != "") {
  107. $query->where('order_id', $value);
  108. }
  109. }
  110. /**
  111. * 一对一关联用户表
  112. * @return \think\model\relation\HasOne
  113. */
  114. public function user()
  115. {
  116. return $this->hasOne(User::class, 'uid', 'uid')->field(['uid', 'nickname', 'avatar', 'phone', 'spread_uid', 'overdue_time', 'now_money', 'integral']);
  117. }
  118. /**
  119. * @return model\relation\HasOne
  120. */
  121. public function staff()
  122. {
  123. return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')
  124. ->field(['id', 'uid', 'store_id', 'staff_name'])
  125. ->bind([
  126. 'staff_uid' => 'uid',
  127. 'staff_store_id' => 'store_id',
  128. 'staff_name' => 'staff_name'
  129. ]);;
  130. }
  131. /**
  132. * 会员类型
  133. * @param $query
  134. * @param $value
  135. */
  136. public function searchMemberTypeAttr($query, $value)
  137. {
  138. if ($value && $value != 'card' && $value != 'free') {
  139. $query->where('member_type', $value);
  140. } elseif ($value == 'card') {
  141. $query->where('member_type', 'free')->where('code', '<>', '');
  142. } elseif ($value == 'free') {
  143. $query->where('member_type', 'free')->where('code', '');
  144. }
  145. }
  146. /**
  147. * 支付方式
  148. * @param $query
  149. * @param $value
  150. */
  151. public function searchPayTypeAttr($query, $value)
  152. {
  153. if ($value) {
  154. if ($value == "free") {
  155. $query->where(function ($query) {
  156. $query->where('type', 'in', [0, 2, 4])->whereOr(function ($query) {
  157. $query->where(['type' => 1, 'is_free' => 1]);
  158. });
  159. });
  160. } else {
  161. $query->where('pay_type', $value);
  162. }
  163. }
  164. }
  165. /**
  166. * @param $query
  167. * @param $value
  168. */
  169. public function searchAddTimeAttr($query, $value)
  170. {
  171. if ($value) {
  172. $query->whereTime('add_time', 'between', $value);
  173. }
  174. }
  175. /**
  176. * @param $query
  177. * @param $value
  178. */
  179. public function searchUidAttr($query, $value)
  180. {
  181. if ($value) {
  182. $query->where('uid', 'in', $value);
  183. }
  184. }
  185. }