StoreCombinationAttrResult.php 1.1 KB

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