StoreOrderInvoice.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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\user\UserInvoice;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * Class StoreOrderInvoice
  18. * @package app\model\order
  19. */
  20. class StoreOrderInvoice extends BaseModel
  21. {
  22. use ModelTrait;
  23. protected $pk = 'id';
  24. protected $name = 'store_order_invoice';
  25. protected $autoWriteTimestamp = 'int';
  26. protected $createTime = 'add_time';
  27. protected function setAddTimeAttr()
  28. {
  29. return time();
  30. }
  31. /**
  32. * 添加时间获取器
  33. * @param $value
  34. * @return false|string
  35. */
  36. public function getAddTimeAttr($value)
  37. {
  38. if (!empty($value)) {
  39. return is_string($value) ? $value : date('Y-m-d H:i:s', (int)$value);
  40. }
  41. return '';
  42. }
  43. public function getInfoAttr($value)
  44. {
  45. if (!empty($value)) {
  46. return json_decode($value, true);
  47. }
  48. return [];
  49. }
  50. public function order()
  51. {
  52. return $this->hasOne(StoreOrder::class, 'id', 'order_id');
  53. }
  54. public function invoiceInfo()
  55. {
  56. return $this->hasOne(UserInvoice::class, 'id', 'invoice_id');
  57. }
  58. public function searchCategoryAttr($query, $value)
  59. {
  60. if ($value !== '') {
  61. $query->where('category', $value);
  62. }
  63. }
  64. /**
  65. * @param Model $query
  66. * @param $value
  67. */
  68. public function searchUidAttr($query, $value)
  69. {
  70. if ($value !== '' && !is_null($value)) $query->where('uid', $value);
  71. }
  72. /**
  73. * @param Model $query
  74. * @param $value
  75. */
  76. public function searchOrderIdAttr($query, $value)
  77. {
  78. if ($value !== '' && !is_null($value)) $query->where('order_id', $value);
  79. }
  80. /**
  81. * @param Model $query
  82. * @param $value
  83. */
  84. public function searchInvoiceIdAttr($query, $value)
  85. {
  86. if ($value !== '' && !is_null($value)) $query->where('invoice_id', $value);
  87. }
  88. /**
  89. * @param Model $query
  90. * @param $value
  91. */
  92. public function searchHeaderTypeAttr($query, $value)
  93. {
  94. if ($value !== '' && !is_null($value)) $query->where('header_type', $value);
  95. }
  96. /**
  97. * @param Model $query
  98. * @param $value
  99. */
  100. public function searchTypeAttr($query, $value)
  101. {
  102. if ($value !== '' && !is_null($value)) $query->where('type', $value);
  103. }
  104. /**
  105. * @param $query
  106. * @param $value
  107. * @return void
  108. */
  109. public function searchInvoiceTimeAttr($query, $value)
  110. {
  111. if ($value !== '') {
  112. if (is_array($value)) {
  113. $query->whereTime('invoice_time', 'between', $value);
  114. } else {
  115. $query->where('invoice_time', $value);
  116. }
  117. }
  118. }
  119. /**
  120. * @param $query
  121. * @param $value
  122. * @return void
  123. */
  124. public function searchIsPayAttr($query, $value)
  125. {
  126. if ($value !== '') {
  127. $query->where('is_pay', $value);
  128. }
  129. }
  130. /**
  131. * @param $query
  132. * @param $value
  133. * @return void
  134. */
  135. public function searchIsRefundAttr($query, $value)
  136. {
  137. if ($value !== '') {
  138. $query->where('is_refund', $value);
  139. }
  140. }
  141. /**
  142. * @param $query
  143. * @param $value
  144. * @return void
  145. */
  146. public function searchIsDelAttr($query, $value)
  147. {
  148. if ($value !== '') {
  149. $query->where('is_del', $value);
  150. }
  151. }
  152. }