StoreIntegralAttrResult.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/12/09
  5. */
  6. namespace app\admin\model\ump;
  7. use crmeb\basic\BaseModel;
  8. use crmeb\traits\ModelTrait;
  9. class StoreIntegralAttrResult extends BaseModel
  10. {
  11. /**
  12. * 模型名称
  13. * @var string
  14. */
  15. protected $name = 'store_integral_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. }