StoreProductAttr.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\wap\model\store;
  12. use basic\ModelBasic;
  13. use think\Db;
  14. use traits\ModelTrait;
  15. class StoreProductAttr extends ModelBasic
  16. {
  17. use ModelTrait;
  18. protected function getAttrValuesAttr($value)
  19. {
  20. return explode(',',$value);
  21. }
  22. public static function storeProductAttrValueDb()
  23. {
  24. return Db::name('StoreProductAttrValue');
  25. }
  26. /**
  27. * 获取商品属性数据
  28. * @param $productId
  29. * @return array
  30. */
  31. public static function getProductAttrDetail($productId)
  32. {
  33. $attr = self::where('product_id',$productId)->select()->toArray()?:[];
  34. $_values = self::storeProductAttrValueDb()->where('product_id',$productId)->select();
  35. $values = [];
  36. foreach ($_values as $value){
  37. $values[$value['suk']] = $value;
  38. }
  39. return [$attr,$values];
  40. }
  41. public static function uniqueByStock($unique)
  42. {
  43. return self::storeProductAttrValueDb()->where('unique',$unique)->value('stock')?:0;
  44. }
  45. public static function uniqueByAttrInfo($unique, $field = '*')
  46. {
  47. return self::storeProductAttrValueDb()->field($field)->where('unique',$unique)->find();
  48. }
  49. public static function issetProductUnique($productId,$unique)
  50. {
  51. $res = self::be(['product_id'=>$productId]);
  52. if($unique){
  53. return $res && self::storeProductAttrValueDb()->where('product_id',$productId)->where('unique',$unique)->count() > 0;
  54. }else{
  55. return !$res;
  56. }
  57. }
  58. }