StoreIntegralAttrValue.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/12/08
  5. */
  6. namespace app\admin\model\ump;
  7. use crmeb\basic\BaseModel;
  8. use crmeb\traits\ModelTrait;
  9. class StoreIntegralAttrValue extends BaseModel
  10. {
  11. /**
  12. * 模型名称
  13. * @var string
  14. */
  15. protected $name = 'store_integral_attr_value';
  16. use ModelTrait;
  17. protected $insert = ['unique'];
  18. protected function setSukAttr($value)
  19. {
  20. return is_array($value) ? implode(',',$value) : $value;
  21. }
  22. protected function setUniqueAttr($value,$data)
  23. {
  24. if(is_array($data['suk'])) $data['suk'] = $this->setSukAttr($data['suk']);
  25. return self::uniqueId($data['product_id'].$data['suk'].uniqid(true));
  26. }
  27. public static function decProductAttrStock($productId,$unique,$num)
  28. {
  29. return false !== self::where('product_id',$productId)->where('unique',$unique)
  30. ->dec('stock',$num)->inc('sales',$num)->update();
  31. }
  32. public static function uniqueId($key)
  33. {
  34. return substr(md5($key),12,8);
  35. }
  36. public static function clearProductAttrValue($productId)
  37. {
  38. return self::where('product_id',$productId)->delete();
  39. }
  40. }