StoreOrderInvoice.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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. public function searchInvoiceTimeAttr($query, $value)
  105. {
  106. if ($value !== '') {
  107. if (is_array($value)) {
  108. $query->whereTime('invoice_time', 'between', $value);
  109. } else {
  110. $query->where('invoice_time', $value);
  111. }
  112. }
  113. }
  114. public function searchIsPayAttr($query, $value)
  115. {
  116. if ($value !== '') {
  117. $query->where('is_pay', $value);
  118. }
  119. }
  120. }