StoreCombinationAttrResult.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\admin\model\ump;
  3. use crmeb\basic\BaseModel;
  4. use crmeb\traits\ModelTrait;
  5. class StoreCombinationAttrResult extends BaseModel
  6. {
  7. /**
  8. * 模型名称
  9. * @var string
  10. */
  11. protected $name = 'store_combination_attr_result';
  12. use ModelTrait;
  13. protected $insert = ['change_time'];
  14. protected static function setChangeTimeAttr($value)
  15. {
  16. return time();
  17. }
  18. protected static function setResultAttr($value)
  19. {
  20. return is_array($value) ? json_encode($value) : $value;
  21. }
  22. public static function setResult($result, $product_id)
  23. {
  24. $result = self::setResultAttr($result);
  25. $change_time = self::setChangeTimeAttr(0);
  26. return self::insert(compact('product_id', 'result', 'change_time'), true);
  27. }
  28. public static function getResult($productId)
  29. {
  30. return json_decode(self::where('product_id', $productId)->value('result'), true) ?: [];
  31. }
  32. public static function clearResult($productId)
  33. {
  34. return self::del($productId);
  35. }
  36. }