123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\wap\model\store;
- use basic\ModelBasic;
- use think\Db;
- use traits\ModelTrait;
- class StoreProductAttr extends ModelBasic
- {
- use ModelTrait;
- protected function getAttrValuesAttr($value)
- {
- return explode(',',$value);
- }
- public static function storeProductAttrValueDb()
- {
- return Db::name('StoreProductAttrValue');
- }
- /**
- * 获取商品属性数据
- * @param $productId
- * @return array
- */
- public static function getProductAttrDetail($productId)
- {
- $attr = self::where('product_id',$productId)->select()->toArray()?:[];
- $_values = self::storeProductAttrValueDb()->where('product_id',$productId)->select();
- $values = [];
- foreach ($_values as $value){
- $values[$value['suk']] = $value;
- }
- return [$attr,$values];
- }
- public static function uniqueByStock($unique)
- {
- return self::storeProductAttrValueDb()->where('unique',$unique)->value('stock')?:0;
- }
- public static function uniqueByAttrInfo($unique, $field = '*')
- {
- return self::storeProductAttrValueDb()->field($field)->where('unique',$unique)->find();
- }
- public static function issetProductUnique($productId,$unique)
- {
- $res = self::be(['product_id'=>$productId]);
- if($unique){
- return $res && self::storeProductAttrValueDb()->where('product_id',$productId)->where('unique',$unique)->count() > 0;
- }else{
- return !$res;
- }
- }
- }
|