StoreProductEnsure.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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\product\ensure;
  12. use app\model\product\product\StoreProduct;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 商品保障服务
  18. * Class StoreProductEnsure
  19. * @package app\model\product\label
  20. */
  21. class StoreProductEnsure extends BaseModel
  22. {
  23. use ModelTrait;
  24. /**
  25. * 数据表主键
  26. * @var string
  27. */
  28. protected $pk = 'id';
  29. /**
  30. * 模型名称
  31. * @var string
  32. */
  33. protected $name = 'store_product_ensure';
  34. /**
  35. * 添加时间获取器
  36. * @param $value
  37. * @return false|string
  38. */
  39. protected function getAddTimeAttr($value)
  40. {
  41. return date('Y-m-d H:i:s', $value);
  42. }
  43. /**
  44. * @param Model $query
  45. * @param $value
  46. */
  47. public function searchNameAttr($query, $value)
  48. {
  49. $query->whereLike('id|name', '%' . $value . '%');
  50. }
  51. /**
  52. * 商户搜索器
  53. * @param Model $query
  54. * @param $value
  55. */
  56. public function searchTypeAttr($query, $value)
  57. {
  58. if (is_array($value)) {
  59. if ($value) $query->whereIn('type', $value);
  60. } else {
  61. if ($value !== '') $query->where('type', $value);
  62. }
  63. }
  64. /**
  65. * 关联门店ID、供应商ID搜索器
  66. * @param Model $query
  67. * @param $value
  68. */
  69. public function searchRelationIdAttr($query, $value)
  70. {
  71. if (is_array($value)) {
  72. if ($value) $query->whereIn('relation_id', $value);
  73. } else {
  74. if ($value !== '') $query->where('relation_id', $value);
  75. }
  76. }
  77. /**
  78. * 供应商
  79. * @param Model $query
  80. * @param $value
  81. */
  82. public function searchSupplierIdAttr($query, $value)
  83. {
  84. if (is_array($value)) {
  85. if ($value) $query->whereIn('relation_id', $value)->where('type', 2);
  86. } else {
  87. if ($value !== '') $query->where('relation_id', $value)->where('type', 2);
  88. }
  89. }
  90. /**
  91. * 门店
  92. * @param Model $query
  93. * @param $value
  94. */
  95. public function searchStoreIdAttr($query, $value)
  96. {
  97. if (is_array($value)) {
  98. if ($value) $query->whereIn('relation_id', $value)->where('type', 1);
  99. } else {
  100. if ($value !== '') $query->where('relation_id', $value)->where('type', 1);
  101. }
  102. }
  103. /**
  104. * status搜索器
  105. * @param Model $query
  106. * @param $value
  107. */
  108. public function searchStatusAttr($query, $value)
  109. {
  110. if ($value !== '') $query->where('status', $value);
  111. }
  112. /**
  113. * @param $query
  114. * @param $value
  115. * @author 等风来
  116. * @email 136327134@qq.com
  117. * @date 2022/11/2
  118. */
  119. public function searchIdsAttr($query, $value)
  120. {
  121. if (is_array($value)) {
  122. $query->whereIn('id', $value);
  123. }
  124. }
  125. }