StoreProductSpecs.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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\specs;
  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 StoreProductSpecs
  19. * @package app\model\product\specs
  20. */
  21. class StoreProductSpecs 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_specs';
  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. * id搜索器
  45. * @param Model $query
  46. * @param $value
  47. */
  48. public function searchIdAttr($query, $value)
  49. {
  50. if (is_array($value)) {
  51. if ($value) $query->whereIn('id', $value);
  52. } else {
  53. if ($value !== '') $query->where('id', $value);
  54. }
  55. }
  56. /**
  57. * @param Model $query
  58. * @param $value
  59. */
  60. public function searchNameAttr($query, $value)
  61. {
  62. $query->whereLike('name', '%' . $value . '%');
  63. }
  64. /**
  65. * temp_id搜索器
  66. * @param Model $query
  67. * @param $value
  68. */
  69. public function searchTempIdAttr($query, $value)
  70. {
  71. if (is_array($value)) {
  72. if ($value) $query->whereIn('temp_id', $value);
  73. } else {
  74. if ($value !== '') $query->where('temp_id', $value);
  75. }
  76. }
  77. /**
  78. * status搜索器
  79. * @param Model $query
  80. * @param $value
  81. */
  82. public function searchStatusAttr($query, $value)
  83. {
  84. if ($value !== '') $query->where('status', $value);
  85. }
  86. /**
  87. * 商户搜索器
  88. * @param Model $query
  89. * @param $value
  90. */
  91. public function searchTypeAttr($query, $value)
  92. {
  93. if (is_array($value)) {
  94. if ($value) $query->whereIn('type', $value);
  95. } else {
  96. if ($value !== '') $query->where('type', $value);
  97. }
  98. }
  99. /**
  100. * 关联门店ID、供应商ID搜索器
  101. * @param Model $query
  102. * @param $value
  103. */
  104. public function searchRelationIdAttr($query, $value)
  105. {
  106. if (is_array($value)) {
  107. if ($value) $query->whereIn('relation_id', $value);
  108. } else {
  109. if ($value !== '') $query->where('relation_id', $value);
  110. }
  111. }
  112. /**
  113. * 供应商
  114. * @param Model $query
  115. * @param $value
  116. */
  117. public function searchSupplierIdAttr($query, $value)
  118. {
  119. if (is_array($value)) {
  120. if ($value) $query->whereIn('relation_id', $value)->where('type', 2);
  121. } else {
  122. if ($value !== '') $query->where('relation_id', $value)->where('type', 2);
  123. }
  124. }
  125. /**
  126. * 门店
  127. * @param Model $query
  128. * @param $value
  129. */
  130. public function searchStoreIdAttr($query, $value)
  131. {
  132. if (is_array($value)) {
  133. if ($value) $query->whereIn('relation_id', $value)->where('type', 1);
  134. } else {
  135. if ($value !== '') $query->where('relation_id', $value)->where('type', 1);
  136. }
  137. }
  138. }