StoreProductAttrResult.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\admin\model\store;
  12. use basic\ModelBasic;
  13. use traits\ModelTrait;
  14. class StoreProductAttrResult extends ModelBasic
  15. {
  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. }