Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

StoreOrderInvoice.php 3.3KB

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