StoreOrderWriteoff.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. /**
  18. * 订单核销记录Model
  19. * Class StoreOrderWriteoff
  20. * @package app\model\order
  21. */
  22. class StoreOrderWriteoff extends BaseModel
  23. {
  24. use ModelTrait;
  25. /**
  26. * 模型名称
  27. * @var string
  28. */
  29. protected $name = 'store_order_writeoff';
  30. /**
  31. * 获取领取人名称头像
  32. * @return \think\model\relation\HasOne
  33. */
  34. public function userInfo()
  35. {
  36. return $this->hasOne(User::class, 'uid', 'uid')->field('uid,nickname,avatar,phone')->bind(['nickname', 'avatar', 'phone']);
  37. }
  38. /**
  39. * 订单信息
  40. * @return \think\model\relation\HasOne
  41. */
  42. public function orderInfo()
  43. {
  44. return $this->hasOne(StoreOrder::class, 'id', 'oid');
  45. }
  46. /**
  47. * 订单商品信息
  48. * @return \think\model\relation\HasOne
  49. */
  50. public function cartInfo()
  51. {
  52. return $this->hasOne(StoreOrderCartInfo::class, 'id', 'order_cart_id');
  53. }
  54. /**
  55. * 店员信息
  56. * @return \think\model\relation\HasOne
  57. */
  58. public function staffInfo()
  59. {
  60. return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->field('id,store_id,staff_name')->bind(['staff_name']);
  61. }
  62. /**
  63. * 订单ID搜索器
  64. * @param Model $query
  65. * @param $value
  66. * @param $data
  67. */
  68. public function searchOidAttr($query, $value, $data)
  69. {
  70. if ($value) {
  71. if (is_array($value)) {
  72. $query->whereIn('oid', $value);
  73. } else {
  74. $query->where('oid', $value);
  75. }
  76. }
  77. }
  78. /**
  79. * UID搜索器
  80. * @param Model $query
  81. * @param $value
  82. */
  83. public function searchUidAttr($query, $value)
  84. {
  85. if ($value) {
  86. if (is_array($value)) {
  87. $query->whereIn('uid', $value);
  88. } else {
  89. $query->where('uid', $value);
  90. }
  91. }
  92. }
  93. /**
  94. * 商品类型搜索器
  95. * @param Model $query
  96. * @param $value
  97. */
  98. public function searchTypeAttr($query, $value)
  99. {
  100. if (is_array($value)) {
  101. if ($value) $query->whereIn('type', $value);
  102. } else {
  103. if ($value !== '') $query->where('type', $value);
  104. }
  105. }
  106. /**
  107. * 关联门店ID、供应商ID搜索器
  108. * @param Model $query
  109. * @param $value
  110. */
  111. public function searchRelationIdAttr($query, $value)
  112. {
  113. if (is_array($value)) {
  114. if ($value) $query->whereIn('relation_id', $value);
  115. } else {
  116. if ($value !== '') $query->where('relation_id', $value);
  117. }
  118. }
  119. /**
  120. * product_id搜索器
  121. * @param Model $query
  122. * @param $value
  123. */
  124. public function searchProductIdAttr($query, $value)
  125. {
  126. if ($value) {
  127. if (is_array($value)) {
  128. $query->whereIn('product_id', $value);
  129. } else {
  130. $query->where('product_id', $value);
  131. }
  132. }
  133. }
  134. /**
  135. * 订单商品ID搜索器
  136. * @param Model $query
  137. * @param $value
  138. * @param $data
  139. */
  140. public function searchOrderCartIdAttr($query, $value, $data)
  141. {
  142. if ($value) {
  143. if (is_array($value)) {
  144. $query->whereIn('order_cart_id', $value);
  145. } else {
  146. $query->where('order_cart_id', $value);
  147. }
  148. }
  149. }
  150. /**
  151. * staff_id搜索器
  152. * @param Model $query
  153. * @param $value
  154. */
  155. public function searchStaffIdAttr($query, $value)
  156. {
  157. if ($value) {
  158. if (is_array($value)) {
  159. $query->whereIn('staff_id', $value);
  160. } else {
  161. $query->where('staff_id', $value);
  162. }
  163. }
  164. }
  165. }