You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StoreIntegralOrder.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace app\model\activity\integral;
  3. use app\model\product\sku\StoreProductVirtual;
  4. use app\model\user\User;
  5. use crmeb\basic\BaseModel;
  6. use crmeb\traits\ModelTrait;
  7. use think\Model;
  8. /**
  9. * 订单Model
  10. * Class StoreIntegralOrder
  11. * @package app\model\activity\integral
  12. */
  13. class StoreIntegralOrder extends BaseModel
  14. {
  15. use ModelTrait;
  16. /**
  17. * 数据表主键
  18. * @var string
  19. */
  20. protected $pk = 'id';
  21. /**
  22. * 模型名称
  23. * @var string
  24. */
  25. protected $name = 'store_integral_order';
  26. protected $insert = ['add_time'];
  27. /**
  28. * 更新时间
  29. * @var bool | string | int
  30. */
  31. protected $updateTime = false;
  32. /**
  33. * 创建时间修改器
  34. * @return int
  35. */
  36. protected function setAddTimeAttr()
  37. {
  38. return time();
  39. }
  40. /**
  41. * 购物车信息获取器
  42. * @param $value
  43. * @return array|mixed
  44. */
  45. public function getCartInfoAttr($value)
  46. {
  47. return is_string($value) ? json_decode($value, true) ?? [] : [];
  48. }
  49. /**
  50. * 配送信息
  51. * @param $value
  52. * @param $data
  53. * @return mixed
  54. */
  55. protected function getCustomFormAttr($value)
  56. {
  57. if ($value) {
  58. return is_string($value) ? json_decode($value, true) : $value;
  59. }
  60. return [];
  61. }
  62. /**
  63. * 一对一关联用户表
  64. * @return \think\model\relation\HasOne
  65. */
  66. public function user()
  67. {
  68. return $this->hasOne(User::class, 'uid', 'uid')->field(['uid', 'nickname', 'phone', 'spread_uid'])->bind([
  69. 'nickname' => 'nickname',
  70. 'phone' => 'phone',
  71. 'spread_uid' => 'spread_uid',
  72. ]);
  73. }
  74. /**
  75. * 关联卡密
  76. * @return \think\model\relation\HasMany
  77. */
  78. public function virtual()
  79. {
  80. return $this->hasMany(StoreProductVirtual::class, 'order_id', 'order_id')->where('order_type', 2);
  81. }
  82. /**
  83. * 关联订单记录
  84. * @return \think\model\relation\HasMany
  85. */
  86. public function orderStatus()
  87. {
  88. return $this->hasMany(StoreIntegralOrderStatus::class, 'oid', 'id');
  89. }
  90. /**
  91. * 订单ID搜索器
  92. * @param Model $query
  93. * @param $value
  94. */
  95. public function searchOrderIdAttr($query, $value)
  96. {
  97. $query->where('order_id', $value);
  98. }
  99. /**
  100. * 订单状态搜索器
  101. * @param Model $query
  102. * @param $value
  103. */
  104. public function searchStatusAttr($query, $value)
  105. {
  106. if ($value !== '') {
  107. $query->where('status', $value);
  108. }
  109. }
  110. /**
  111. * 商品id搜索器
  112. * @param Model $query
  113. * @param $value
  114. */
  115. public function searchProductIdAttr($query, $value)
  116. {
  117. if ($value !== '') {
  118. if (is_array($value)) {
  119. $query->whereIn('product_id', $value);
  120. } else {
  121. $query->where('product_id', $value);
  122. }
  123. }
  124. }
  125. /**
  126. * 核销码搜索器
  127. * @param Model $query
  128. * @param $value
  129. */
  130. public function searchVerifyCodeAttr($query, $value)
  131. {
  132. $query->where('verify_code', $value);
  133. }
  134. /**
  135. * @param Model $query
  136. * @param $value
  137. */
  138. public function searchIdAttr($query, $value)
  139. {
  140. if (is_array($value)) {
  141. $query->whereIn('id', $value);
  142. } else {
  143. $query->where('id', $value);
  144. }
  145. }
  146. /**
  147. * 订单id或者用户名搜索器
  148. * @param $query
  149. * @param $value
  150. */
  151. public function searchOrderIdRealNameAttr($query, $value)
  152. {
  153. $query->where('order_id|real_name', $value);
  154. }
  155. /**
  156. * 用户ID搜索器
  157. * @param Model $query
  158. * @param $value
  159. */
  160. public function searchUidAttr($query, $value)
  161. {
  162. if (is_array($value))
  163. $query->whereIn('uid', $value);
  164. else
  165. $query->where('uid', $value);
  166. }
  167. /**
  168. * 用户来源
  169. * @param Model $query
  170. * @param $value
  171. */
  172. public function searchChannelTypeAttr($query, $value)
  173. {
  174. if ($value != '') $query->where('channel_type', $value);
  175. }
  176. }