ShippingTemplates.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\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\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 getTypeAttr($value)
  39. {
  40. $status = [1 => '按件数', 2 => '按重量', 3 => '按体积'];
  41. return $status[$value];
  42. }
  43. /**
  44. * 是否开启包邮获取器
  45. * @param $value
  46. * @return string
  47. */
  48. public function getAppointAttr($value)
  49. {
  50. $status = [1 => '开启', 0 => '关闭'];
  51. return $status[$value];
  52. }
  53. /**
  54. * 添加时间获取器
  55. * @param $value
  56. * @return false|string
  57. */
  58. public function getAddTimeAttr($value)
  59. {
  60. $value = date('Y-m-d H:i:s', $value);
  61. return $value;
  62. }
  63. /**
  64. * 运费地区一对多关联
  65. * @return \think\model\relation\HasMany
  66. */
  67. public function region()
  68. {
  69. return $this->hasMany(ShippingTemplatesRegion::class, 'temp_id', 'id');
  70. }
  71. /**
  72. * 包邮地区一对多关联
  73. * @return \think\model\relation\HasMany
  74. */
  75. public function free()
  76. {
  77. return $this->hasMany(ShippingTemplatesFree::class, 'temp_id', 'id');
  78. }
  79. /**
  80. * ID搜索器
  81. * @param Model $query
  82. * @param $value
  83. * @param $data
  84. */
  85. public function searchIdAttr($query, $value)
  86. {
  87. if (is_array($value)) {
  88. $query->whereIn('id', $value);
  89. } else {
  90. $query->where('id', $value);
  91. }
  92. }
  93. /**
  94. * 模板名称搜索器
  95. * @param Model $query
  96. * @param $value
  97. * @param $data
  98. */
  99. public function searchNameAttr($query, $value)
  100. {
  101. if ($value) {
  102. $query->where('name', 'like', '%' . $value . '%');
  103. }
  104. }
  105. }