ShippingTemplates.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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\shipping;
  12. use crmeb\traits\ModelTrait;
  13. use crmeb\basic\BaseModel;
  14. use think\Model;
  15. /**
  16. * 运费模板Model
  17. * Class ShippingTemplates
  18. * @package app\model\product\shipping
  19. */
  20. class ShippingTemplates extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'shipping_templates';
  33. /**
  34. * 是否开启包邮获取器
  35. * @param $value
  36. * @return string
  37. */
  38. public function getAppointAttr($value)
  39. {
  40. $status = [1 => '开启', 0 => '关闭'];
  41. return $status[$value];
  42. }
  43. /**
  44. * 添加时间获取器
  45. * @param $value
  46. * @return false|string
  47. */
  48. public function getAddTimeAttr($value)
  49. {
  50. $value = date('Y-m-d H:i:s', $value);
  51. return $value;
  52. }
  53. /**
  54. * 运费地区一对多关联
  55. * @return \think\model\relation\HasMany
  56. */
  57. public function region()
  58. {
  59. return $this->hasMany(ShippingTemplatesRegion::class, 'temp_id', 'id');
  60. }
  61. /**
  62. * 包邮地区一对多关联
  63. * @return \think\model\relation\HasMany
  64. */
  65. public function free()
  66. {
  67. return $this->hasMany(ShippingTemplatesFree::class, 'temp_id', 'id');
  68. }
  69. /**
  70. * ID搜索器
  71. * @param Model $query
  72. * @param $value
  73. * @param $data
  74. */
  75. public function searchIdAttr($query, $value)
  76. {
  77. if (is_array($value)) {
  78. $query->whereIn('id', $value);
  79. } else {
  80. $query->where('id', $value);
  81. }
  82. }
  83. /**
  84. * 模板名称搜索器
  85. * @param Model $query
  86. * @param $value
  87. * @param $data
  88. */
  89. public function searchNameAttr($query, $value)
  90. {
  91. if ($value) {
  92. $query->where('name', 'like', '%' . $value . '%');
  93. }
  94. }
  95. /**
  96. * 计费方式搜索器
  97. * @param Model $query
  98. * @param $value
  99. */
  100. public function searchGroupAttr($query, $value)
  101. {
  102. if (is_array($value)) {
  103. if ($value) $query->whereIn('group', $value);
  104. } else {
  105. if ($value !== '') $query->where('group', $value);
  106. }
  107. }
  108. /**
  109. * 商户搜索器
  110. * @param Model $query
  111. * @param $value
  112. */
  113. public function searchTypeAttr($query, $value)
  114. {
  115. if (is_array($value)) {
  116. if ($value) $query->whereIn('type', $value);
  117. } else {
  118. if ($value !== '') $query->where('type', $value);
  119. }
  120. }
  121. /**
  122. * 关联门店ID、供应商ID搜索器
  123. * @param Model $query
  124. * @param $value
  125. */
  126. public function searchRelationIdAttr($query, $value)
  127. {
  128. if (is_array($value)) {
  129. if ($value) $query->whereIn('relation_id', $value);
  130. } else {
  131. if ($value !== '') $query->where('relation_id', $value);
  132. }
  133. }
  134. /**
  135. * 供应商
  136. * @param Model $query
  137. * @param $value
  138. */
  139. public function searchSupplierIdAttr($query, $value)
  140. {
  141. if (is_array($value)) {
  142. if ($value) $query->whereIn('relation_id', $value)->where('type', 2);
  143. } else {
  144. if ($value !== '') $query->where('relation_id', $value)->where('type', 2);
  145. }
  146. }
  147. /**
  148. * 门店
  149. * @param Model $query
  150. * @param $value
  151. */
  152. public function searchStoreIdAttr($query, $value)
  153. {
  154. if (is_array($value)) {
  155. if ($value) $query->whereIn('relation_id', $value)->where('type', 1);
  156. } else {
  157. if ($value !== '') $query->where('relation_id', $value)->where('type', 1);
  158. }
  159. }
  160. }