diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 2f2f86b..353f846 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -13,8 +13,11 @@ namespace app\common\repositories\store\product; +use app\common\model\store\order\StoreOrderProduct; +use app\common\model\store\product\Product; use app\common\model\store\product\ProductLabel; use app\common\model\user\User; +use app\common\model\user\UserPre; use app\common\repositories\community\CommunityRepository; use app\common\repositories\store\coupon\StoreCouponRepository; use app\common\repositories\store\GuaranteeRepository; @@ -60,7 +63,7 @@ class ProductRepository extends BaseRepository protected $dao; const CREATE_PARAMS = [ - "image", "slider_image", "store_name", "store_info", "keyword", "bar_code",'is_pre', "guarantee_template_id", "cate_id", "mer_cate_id", "unit_name", "sort", "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free', 'param_temp_id', 'extend', + "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", 'is_pre', "guarantee_template_id", "cate_id", "mer_cate_id", "unit_name", "sort", "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free', 'param_temp_id', 'extend', ["brand_id", 0], ['once_max_count', 0], ['once_min_count', 0], @@ -214,7 +217,7 @@ class ProductRepository extends BaseRepository { if (!$data['spec_type']) { $data['attr'] = []; - if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误'); + if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误1'); } $content = [ 'content' => $conType ? json_encode($data['content']) : $data['content'], @@ -257,7 +260,7 @@ class ProductRepository extends BaseRepository { if (!$data['spec_type']) { $data['attr'] = []; - if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误'); +// if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误2'); } event('product.update.before', compact('id', 'data', 'merId', 'productType', 'conType')); $spuData = $product = $this->setProduct($data); @@ -1237,16 +1240,39 @@ class ProductRepository extends BaseRepository $active = app()->make(StoreActivityRepository::class)->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_ATMOSPHERE, $res['spu_id'], $res['cate_id'], $res['mer_id']); if ($active) $res['atmosphere_pic'] = $active['pic']; } + $p = Product::getDB()->where('product_id', $res['product_id'])->find(); + $merid = $p->mer_id; + $userpre = UserPre::getDB()->where('mer_id', $merid)->where('uid', $userInfo->uid)->where('status', 1)->sum('num') ?? 0; + //该商品是否限购 + $res['is_pre'] = $p->is_pre; + //用户店铺额外额度 + $res['pre_num'] = $userpre; + + //wmc + $info = Product::getDB()->alias('a') + ->where('a.is_del', 0) + ->where('a.is_show', 1) + ->where('a.mer_id', $merid) + ->where('a.status', 1) + ->where('a.is_used', 1) + ->where('a.is_pre', 1) + ->sum('price'); - $res['is_pre'] = 1; //该店铺限购商品的总金额 - $res['pre_count'] = 9999; - //在该店铺购买商品的总金额 - $res['pre_used'] = 9999; - //用户店铺额外额度 - $res['pre_num'] = 9999; + $res['pre_count'] = $info; + + + //在该店铺购买限购商品的总金额 + $info2 = StoreOrderProduct::getDB()->alias('a') + ->leftJoin('StoreProduct b', 'a.product_id = b.product_id') + ->where('a.uid', $userInfo->uid) + ->where('b.mer_id', $merid) + ->where('b.is_pre', $p->is_pre) + ->sum('b.price'); + $res['pre_used'] = $info2; + return $res; }