StoreProductAttr.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\sku;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\Model;
  15. /**
  16. * 商品属性Model
  17. * Class StoreProductAttr
  18. * @package app\common\model\product
  19. */
  20. class StoreProductAttr extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 模型名称
  25. * @var string
  26. */
  27. protected $name = 'store_product_attr';
  28. /**
  29. * 规格获取器
  30. * @param $value
  31. * @return false|string[]
  32. */
  33. protected function getAttrValuesAttr($value)
  34. {
  35. return explode(',', $value);
  36. }
  37. /**
  38. * 规格修改器
  39. * @param $value
  40. * @return string
  41. */
  42. protected function setAttrValuesAttr($value)
  43. {
  44. return is_array($value) ? implode(',', $value) : $value;
  45. }
  46. /**
  47. * 商品搜索器
  48. * @param Model $query
  49. * @param $value
  50. * @param $data
  51. */
  52. public function searchProductIdAttr($query, $value)
  53. {
  54. $query->where('product_id', $value);
  55. }
  56. /**
  57. * 商品类型搜索器
  58. * @param Model $query
  59. * @param $value
  60. * @param $data
  61. */
  62. public function searchTypeAttr($query, $value)
  63. {
  64. $query->where('type', $value);
  65. }
  66. }