From 4b8f4cc0fc68e4a2b8c430d4e8205c26bcb574b6 Mon Sep 17 00:00:00 2001 From: "wangmingchuan321@qq.com" Date: Tue, 26 Dec 2023 22:17:57 +0800 Subject: [PATCH] 11 --- .../store/product/ProductRepository.php | 387 +++++++++--------- .../user/UserExtractRepository.php | 2 - 2 files changed, 198 insertions(+), 191 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 7d60dc1..62fe53d 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -60,47 +60,48 @@ class ProductRepository extends BaseRepository protected $dao; const CREATE_PARAMS = [ - "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "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], + "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "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], ['pay_limit', 0], - ["attrValue",[]], - ['give_coupon_ids',[]], - ['type',0], - ['svip_price',0], - ['svip_price_type',0], - ['params',[]], + ["attrValue", []], + ['give_coupon_ids', []], + ['type', 0], + ['svip_price', 0], + ['svip_price_type', 0], + ['params', []], ]; protected $admin_filed = 'Product.product_id,Product.mer_id,brand_id,spec_type,unit_name,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,U.rank,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,star,ficti,integral_total,integral_price_total,sys_labels,param_temp_id,mer_svip_status,svip_price,svip_price_type'; protected $filed = 'Product.product_id,Product.mer_id,brand_id,unit_name,spec_type,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,integral_total,integral_price_total,mer_labels,Product.is_good,Product.is_del,type,param_temp_id,mer_svip_status,svip_price,svip_price_type'; - const NOTIC_MSG = [ - 1 => [ - '0' => 'product_success', - '1' => 'product_seckill_success', - '2' => 'product_presell_success', - '3' => 'product_assist_success', - '4' => 'product_group_success', - 'msg' => '审核通过' - ], - -1 => [ - '0' => 'product_fail', - '1' => 'product_seckill_fail', - '2' => 'product_presell_fail', - '3' => 'product_assist_fail', - '4' => 'product_group_fail', - 'msg' => '审核失败' - ], - -2 => [ - '0' => 'product_fail', - '1' => 'product_seckill_fail', - '2' => 'product_presell_fail', - '3' => 'product_assist_fail', - '4' => 'product_group_fail', - 'msg' => '被下架' - ], - ]; + const NOTIC_MSG = [ + 1 => [ + '0' => 'product_success', + '1' => 'product_seckill_success', + '2' => 'product_presell_success', + '3' => 'product_assist_success', + '4' => 'product_group_success', + 'msg' => '审核通过' + ], + -1 => [ + '0' => 'product_fail', + '1' => 'product_seckill_fail', + '2' => 'product_presell_fail', + '3' => 'product_assist_fail', + '4' => 'product_group_fail', + 'msg' => '审核失败' + ], + -2 => [ + '0' => 'product_fail', + '1' => 'product_seckill_fail', + '2' => 'product_presell_fail', + '3' => 'product_assist_fail', + '4' => 'product_group_fail', + 'msg' => '被下架' + ], + ]; + /** * ProductRepository constructor. * @param dao $dao @@ -216,19 +217,19 @@ class ProductRepository extends BaseRepository if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误'); } $content = [ - 'content' => $conType ? json_encode($data['content']) : $data['content'] , + 'content' => $conType ? json_encode($data['content']) : $data['content'], 'type' => $conType ]; $product = $this->setProduct($data); - event('product.create.before', compact('data','productType','conType')); - return Db::transaction(function () use ($data, $productType,$conType,$content,$product) { + event('product.create.before', compact('data', 'productType', 'conType')); + return Db::transaction(function () use ($data, $productType, $conType, $content, $product) { $activity_id = 0; $result = $this->dao->create($product); $settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0); $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']); $settleParams['attr'] = $this->setAttr($data['attr'], $result->product_id); - if ($productType ==0 ) app()->make(ParameterValueRepository::class)->create($result->product_id, $data['params'] ?? [],$data['mer_id']); - $this->save($result->product_id, $settleParams, $content,$product,$productType); + if ($productType == 0) app()->make(ParameterValueRepository::class)->create($result->product_id, $data['params'] ?? [], $data['mer_id']); + $this->save($result->product_id, $settleParams, $content, $product, $productType); if (in_array($productType, [0, 1])) { if ($productType == 1) { //秒杀商品 $dat = $this->setSeckillProduct($data); @@ -241,7 +242,7 @@ class ProductRepository extends BaseRepository app()->make(SpuRepository::class)->create($product, $result->product_id, $activity_id, $productType); } $product = $result; - event('product.create',compact('product')); + event('product.create', compact('product')); return $result->product_id; }); } @@ -258,20 +259,20 @@ class ProductRepository extends BaseRepository $data['attr'] = []; if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误'); } - event('product.update.before', compact('id','data','merId','productType','conType')); + event('product.update.before', compact('id', 'data', 'merId', 'productType', 'conType')); $spuData = $product = $this->setProduct($data); $settleParams = $this->setAttrValue($data, $id, $productType, 1); $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId); $settleParams['attr'] = $this->setAttr($data['attr'], $id); $content = [ - 'content' => $conType ? json_encode($data['content']) : $data['content'] , + 'content' => $conType ? json_encode($data['content']) : $data['content'], 'type' => $conType ]; $spuData['price'] = $settleParams['data']['price']; $spuData['mer_id'] = $merId; $spuData['mer_labels'] = $data['mer_labels']; - Db::transaction(function () use ($id, $data, $productType, $settleParams,$content,$product,$spuData,$merId) { + Db::transaction(function () use ($id, $data, $productType, $settleParams, $content, $product, $spuData, $merId) { $this->save($id, $settleParams, $content, $product, $productType); if ($productType == 1) { //秒杀商品 $dat = $this->setSeckillProduct($data); @@ -283,7 +284,7 @@ class ProductRepository extends BaseRepository $make->create($id, $data['params'] ?? [], $merId); } app()->make(SpuRepository::class)->baseUpdate($spuData, $id, 0, $productType); - event('product.update',compact('id')); + event('product.update', compact('id')); app()->make(SpuRepository::class)->changeStatus($id, $productType); }); } @@ -300,11 +301,11 @@ class ProductRepository extends BaseRepository $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId); $settleParams['attr'] = $this->setAttr($data['attr'], $id); $data['price'] = $settleParams['data']['price']; - unset($data['attrValue'],$data['attr'],$data['mer_cate_id']); + unset($data['attrValue'], $data['attr'], $data['mer_cate_id']); $ret = app()->make(SpuRepository::class)->getSearch(['product_id' => $id, 'product_type' => 0,])->find(); - Db::transaction(function () use ($id, $data, $settleParams,$ret) { + Db::transaction(function () use ($id, $data, $settleParams, $ret) { $this->save($id, $settleParams, null, [], 0); - app()->make(SpuRepository::class)->update($ret->spu_id,['price' => $data['price']]); + app()->make(SpuRepository::class)->update($ret->spu_id, ['price' => $data['price']]); Queue(SendSmsJob::class, ['tempId' => 'PRODUCT_INCREASE', 'id' => $id]); }); } @@ -343,12 +344,12 @@ class ProductRepository extends BaseRepository if (isset($settleParams['attrValue'])) { $arr = array_chunk($settleParams['attrValue'], 30); - foreach ($arr as $item){ + foreach ($arr as $item) { app()->make(ProductAttrValueRepository::class)->insertAll($item); } } - if ($content){ - app()->make(ProductContentRepository::class)->clearAttr($id,$content['type']); + if ($content) { + app()->make(ProductContentRepository::class)->clearAttr($id, $content['type']); $this->dao->createContent($id, $content); } @@ -361,9 +362,9 @@ class ProductRepository extends BaseRepository } $res = $this->dao->update($id, $data); - if(isset($data['status']) && $data['status'] !== 1 ){ - $message = '您有1个新的'. ($productType ? '秒杀商品' : ($data['is_gift_bag'] ? '礼包商品' :'商品')) . '待审核'; - $type = $productType ? 'new_seckill' : ($data['is_gift_bag'] ? 'new_bag' :'new_product'); + if (isset($data['status']) && $data['status'] !== 1) { + $message = '您有1个新的' . ($productType ? '秒杀商品' : ($data['is_gift_bag'] ? '礼包商品' : '商品')) . '待审核'; + $type = $productType ? 'new_seckill' : ($data['is_gift_bag'] ? 'new_bag' : 'new_product'); SwooleTaskService::admin('notice', [ 'type' => $type, 'data' => [ @@ -434,10 +435,10 @@ class ProductRepository extends BaseRepository $give_coupon_ids = implode(',', $gcoupon_ids); } - if(isset($data['integral_rate'])){ + if (isset($data['integral_rate'])) { $integral_rate = $data['integral_rate']; - if($data['integral_rate'] < 0) $integral_rate = -1; - if($data['integral_rate'] > 100) $integral_rate = 100; + if ($data['integral_rate'] < 0) $integral_rate = -1; + if ($data['integral_rate'] > 100) $integral_rate = 100; } @@ -446,25 +447,25 @@ class ProductRepository extends BaseRepository 'image' => $data['image'], 'slider_image' => is_array($data['slider_image']) ? implode(',', $data['slider_image']) : '', 'store_info' => $data['store_info'] ?? '', - 'keyword' => $data['keyword']??'', + 'keyword' => $data['keyword'] ?? '', 'brand_id' => $data['brand_id'] ?? 0, 'cate_id' => $data['cate_id'] ?? 0, - 'unit_name' => $data['unit_name']??'件', + 'unit_name' => $data['unit_name'] ?? '件', 'sort' => $data['sort'] ?? 0, 'is_show' => $data['is_show'] ?? 0, - 'is_used' => (isset($data['status']) && $data['status'] == 1) ? 1 : 0, + 'is_used' => (isset($data['status']) && $data['status'] == 1) ? 1 : 0, 'is_good' => $data['is_good'] ?? 0, - 'video_link' => $data['video_link']??'', + 'video_link' => $data['video_link'] ?? '', 'temp_id' => $data['delivery_free'] ? 0 : ($data['temp_id'] ?? 0), - 'extension_type' => $data['extension_type']??0, + 'extension_type' => $data['extension_type'] ?? 0, 'spec_type' => $data['spec_type'] ?? 0, - 'status' => $data['status']??0, + 'status' => $data['status'] ?? 0, 'give_coupon_ids' => $give_coupon_ids, 'mer_status' => $data['mer_status'], - 'guarantee_template_id' => $data['guarantee_template_id']??0, + 'guarantee_template_id' => $data['guarantee_template_id'] ?? 0, 'is_gift_bag' => $data['is_gift_bag'] ?? 0, - 'integral_rate' => $integral_rate ?? 0, - 'delivery_way' => implode(',',$data['delivery_way']), + 'integral_rate' => $integral_rate ?? 0, + 'delivery_way' => implode(',', $data['delivery_way']), 'delivery_free' => $data['delivery_free'] ?? 0, 'once_min_count' => $data['once_min_count'] ?? 0, 'once_max_count' => $data['once_max_count'] ?? 0, @@ -482,7 +483,7 @@ class ProductRepository extends BaseRepository if (isset($data['param_temp_id'])) $result['param_temp_id'] = $data['param_temp_id']; if (isset($data['extend'])) - $result['extend'] = $data['extend'] ? json_encode($data['extend'], JSON_UNESCAPED_UNICODE) :[]; + $result['extend'] = $data['extend'] ? json_encode($data['extend'], JSON_UNESCAPED_UNICODE) : []; return $result; } @@ -519,7 +520,7 @@ class ProductRepository extends BaseRepository public function setAttr(array $data, int $productId) { $result = []; - try{ + try { foreach ($data as $value) { $result[] = [ 'type' => 0, @@ -571,11 +572,11 @@ class ProductRepository extends BaseRepository } if ($data['svip_price_type'] == 2) { $_svip_price = $value['svip_price']; - $svip_price = !$svip_price ? $value['svip_price'] : (($svip_price > $value['svip_price']) ? $value['svip_price'] : $svip_price); + $svip_price = !$svip_price ? $value['svip_price'] : (($svip_price > $value['svip_price']) ? $value['svip_price'] : $svip_price); } - $cost = !$cost ? $value['cost'] : (($cost > $value['cost']) ?$cost: $value['cost']); - $price = !$price ? $sprice : (($price > $sprice) ? $sprice : $price); + $cost = !$cost ? $value['cost'] : (($cost > $value['cost']) ? $cost : $value['cost']); + $price = !$price ? $sprice : (($price > $sprice) ? $sprice : $price); $ot_price = !$ot_price ? $ot_price_ : (($ot_price > $ot_price_) ? $ot_price : $ot_price_); $unique = $this->setUnique($productId, $sku, $productType); @@ -585,8 +586,8 @@ class ProductRepository extends BaseRepository "image" => $value["image"] ?? '', "cost" => $value['cost'] ? (($value['cost'] < 0) ? 0 : $value['cost']) : 0, "price" => $value['price'] ? (($value['price'] < 0) ? 0 : $value['price']) : 0, - "volume" => isset($value['volume']) ? ($value['volume'] ? (($value['volume'] < 0) ? 0 : $value['volume']) : 0) :0, - "weight" => isset($value['weight']) ? ($value['weight'] ? (($value['weight'] < 0) ? 0 : $value['weight']) : 0) :0, + "volume" => isset($value['volume']) ? ($value['volume'] ? (($value['volume'] < 0) ? 0 : $value['volume']) : 0) : 0, + "weight" => isset($value['weight']) ? ($value['weight'] ? (($value['weight'] < 0) ? 0 : $value['weight']) : 0) : 0, "stock" => $value['stock'] ? (($value['stock'] < 0) ? 0 : $value['stock']) : 0, "ot_price" => $value['ot_price'] ? (($value['ot_price'] < 0) ? 0 : $value['ot_price']) : 0, "extension_one" => $extension_status ? ($value['extension_one'] ?? 0) : 0, @@ -601,14 +602,14 @@ class ProductRepository extends BaseRepository $stock = $stock + intval($value['stock']); } $result['data'] = [ - 'price' => $price , + 'price' => $price, 'stock' => $stock, - 'ot_price' => $ot_price, - 'cost' => $cost, + 'ot_price' => $ot_price, + 'cost' => $cost, 'svip_price' => $svip_price, ]; } catch (\Exception $exception) { - throw new ValidateException('规格错误 :'.$exception->getMessage()); + throw new ValidateException('规格错误 :' . $exception->getMessage()); } return $result; } @@ -640,11 +641,11 @@ class ProductRepository extends BaseRepository */ public function getAdminOneProduct(int $id, ?int $activeId, $conType = 0) { - $with = ['attr', 'attrValue', 'oldAttrValue', 'merCateId.category', 'storeCategory', 'brand', 'temp', 'seckillActive', - 'content' => function($query) use($conType){ - $query->where('type',$conType); + $with = ['attr', 'attrValue', 'oldAttrValue', 'merCateId.category', 'storeCategory', 'brand', 'temp', 'seckillActive', + 'content' => function ($query) use ($conType) { + $query->where('type', $conType); }, - 'merchant'=> function($query){ + 'merchant' => function ($query) { $query->field('mer_id,mer_avatar,mer_name,is_trader'); }, 'guarantee.templateValue.value', @@ -653,8 +654,8 @@ class ProductRepository extends BaseRepository $data = $this->dao->geTrashedtProduct($id)->with($with)->find(); - $data['delivery_way'] = empty($data['delivery_way']) ? [2] : explode(',',$data['delivery_way']); - $data['extend'] = empty($data['extend']) ? [] : json_decode($data['extend']); + $data['delivery_way'] = empty($data['delivery_way']) ? [2] : explode(',', $data['delivery_way']); + $data['extend'] = empty($data['extend']) ? [] : json_decode($data['extend']); $make_order = app()->make(StoreCouponRepository::class); $where = [['coupon_id', 'in', $data['give_coupon_ids']]]; $data['coupon'] = $make_order->selectWhere($where, 'coupon_id,title')->toArray(); @@ -665,10 +666,10 @@ class ProductRepository extends BaseRepository $append = ['us_status', 'params']; $activeId = 0; } - if ($data['product_type'] == 1){ + if ($data['product_type'] == 1) { $activeId = $data->seckillActive->seckill_active_id; $make = app()->make(StoreOrderRepository::class); - $append = ['us_status','seckill_status']; + $append = ['us_status', 'seckill_status']; } if ($data['product_type'] == 2) $make = app()->make(ProductPresellSkuRepository::class); if ($data['product_type'] == 3) $make = app()->make(ProductAssistSkuRepository::class); @@ -695,7 +696,7 @@ class ProductRepository extends BaseRepository 'detail' => $v['attr_values'] ]; } - $attrValue = (in_array($data['product_type'], [3, 4])) ? $data['oldAttrValue'] : $data['attrValue']; + $attrValue = (in_array($data['product_type'], [3, 4])) ? $data['oldAttrValue'] : $data['attrValue']; unset($data['oldAttrValue'], $data['attrValue']); $arr = []; if (in_array($data['product_type'], [1, 3])) $value_make = app()->make(ProductAttrValueRepository::class); @@ -861,7 +862,7 @@ class ProductRepository extends BaseRepository $data->append(['us_status']); $list = hasMany( - $data , + $data, 'mer_labels', ProductLabel::class, 'product_label_id', @@ -897,7 +898,7 @@ class ProductRepository extends BaseRepository $data->append(['seckill_status', 'us_status']); $list = hasMany( - $data , + $data, 'mer_labels', ProductLabel::class, 'product_label_id', @@ -930,9 +931,9 @@ class ProductRepository extends BaseRepository ]); $count = $query->count(); $data = $query->page($page, $limit)->setOption('field', [])->field($this->admin_filed)->select(); - $data->append([ 'us_status']); + $data->append(['us_status']); $list = hasMany( - $data , + $data, 'sys_labels', ProductLabel::class, 'product_label_id', @@ -977,7 +978,7 @@ class ProductRepository extends BaseRepository $data->append(['seckill_status', 'us_status']); $list = hasMany( - $data , + $data, 'sys_labels', ProductLabel::class, 'product_label_id', @@ -1046,7 +1047,7 @@ class ProductRepository extends BaseRepository $list = $query->page($page, $limit)->setOption('field', [])->field($field)->select() ->each(function ($item) use ($make) { $item['sales'] = $make->seckillOrderCounut($item['product_id']); - $item['stop'] = $item->end_time; + $item['stop'] = $item->end_time; return $item; }); } @@ -1113,11 +1114,11 @@ class ProductRepository extends BaseRepository * @author Qinii * @day 2020-08-05 */ - public function seckillDetail(int $id,$userInfo) + public function seckillDetail(int $id, $userInfo) { $where = $this->seckillShow(); $where['product_id'] = $id; - return $this->apiProductDetail($where, 1, null,$userInfo); + return $this->apiProductDetail($where, 1, null, $userInfo); } public function apiProductDetail(array $where, int $productType, ?int $activityId, $userInfo = null) @@ -1126,13 +1127,13 @@ class ProductRepository extends BaseRepository $field = 'is_show,product_id,mer_id,image,slider_image,store_name,store_info,unit_name,price,cost,ot_price,stock,sales,video_link,product_type,extension_type,old_product_id,rate,guarantee_template_id,temp_id,once_max_count,pay_limit,once_min_count,integral_rate,delivery_way,delivery_free,type,cate_id,svip_price_type,svip_price,mer_svip_status'; $with = [ 'attr', - 'content' => function($query) { + 'content' => function ($query) { $query->order('type ASC'); }, 'attrValue', 'oldAttrValue', 'merchant' => function ($query) { - $query->with(['type_name'])->append(['isset_certificate','services_type']); + $query->with(['type_name'])->append(['isset_certificate', 'services_type']); }, 'seckillActive' => function ($query) { $query->field('start_day,end_day,start_time,end_time,product_id'); @@ -1140,10 +1141,10 @@ class ProductRepository extends BaseRepository 'temp' ]; - $append = ['guaranteeTemplate','params']; + $append = ['guaranteeTemplate', 'params']; $where['product_type'] = $productType; $res = $this->dao->getWhere($where, $field, $with); - if (!$res) return []; + if (!$res) return []; switch ($res['product_type']) { case 0: $append[] = 'max_integral'; @@ -1180,8 +1181,8 @@ class ProductRepository extends BaseRepository } $attr = $this->detailAttr($res['attr']); - $attrValue = (in_array($res['product_type'], [3, 4])) ? $res['oldAttrValue'] : $res['attrValue']; - $sku = $this->detailAttrValue($attrValue, $userInfo, $productType, $activityId); + $attrValue = (in_array($res['product_type'], [3, 4])) ? $res['oldAttrValue'] : $res['attrValue']; + $sku = $this->detailAttrValue($attrValue, $userInfo, $productType, $activityId); $res['isRelation'] = $isRelation ?? false; $care = false; @@ -1191,7 +1192,7 @@ class ProductRepository extends BaseRepository $res['merchant']['top_banner'] = merchantConfig($res['mer_id'], 'mer_pc_top'); $res['merchant']['care'] = $care; $res['replayData'] = null; - if (systemConfig('sys_reply_status')){ + if (systemConfig('sys_reply_status')) { $res['replayData'] = app()->make(ProductReplyRepository::class)->getReplyRate($res['product_id']); $append[] = 'topReply'; } @@ -1232,11 +1233,20 @@ class ProductRepository extends BaseRepository $res['top_pid'] = $hot['top_pid'] ?? 0; } //活动氛围图 - if (in_array($res['product_type'],[0,2,4])){ - $active = app()->make(StoreActivityRepository::class)->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_ATMOSPHERE,$res['spu_id'],$res['cate_id'],$res['mer_id']); + if (in_array($res['product_type'], [0, 2, 4])) { + $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']; } + + $res['is_pre'] = 1; + //该店铺限购商品的总金额 + $res['pre_count'] = 9999; + //在该店铺购买商品的总金额 + $res['pre_used'] = 9999; + //用户店铺额外额度 + $res['pre_num'] = 9999; + return $res; } @@ -1252,20 +1262,20 @@ class ProductRepository extends BaseRepository { $data = []; //热卖排行 - $lv = systemConfig('hot_ranking_lv') ?:0; + $lv = systemConfig('hot_ranking_lv') ?: 0; $categoryMake = app()->make(StoreCategoryRepository::class); $cate = $categoryMake->getWhere(['store_category_id' => $cateId]); if ($lv != 2 && $cate) $cateId = $lv == 1 ? $cate->pathIds[2] : $cate->pathIds[1]; $RedisCacheService = app()->make(RedisCacheService::class); - $prefix = env('QUEUE_NAME','merchant').'_hot_ranking_'; - $key = ( $prefix.'top_item_'.$cateId.'_'.$spuId); + $prefix = env('QUEUE_NAME', 'merchant') . '_hot_ranking_'; + $key = ($prefix . 'top_item_' . $cateId . '_' . $spuId); $k1 = $RedisCacheService->keys($key); if ($k1) { $top = $RedisCacheService->handler()->get($key); $top = json_decode($top); $data['top_name'] = $top[0]; - $data['top_num'] = $top[1]; - $data['top_pid'] = $cateId; + $data['top_num'] = $top[1]; + $data['top_pid'] = $cateId; } return $data; } @@ -1278,24 +1288,24 @@ class ProductRepository extends BaseRepository * @author Qinii * @day 12/7/21 */ - public function getRecommend($productId,$merId) + public function getRecommend($productId, $merId) { $make = app()->make(ProductCateRepository::class); $product_id = []; if ($productId) { $catId = $make->getSearch(['product_id' => $productId])->column('mer_cate_id'); - $product_id = $make->getSearch([])->whereIn('mer_cate_id',$catId)->column('product_id'); + $product_id = $make->getSearch([])->whereIn('mer_cate_id', $catId)->column('product_id'); } $query = $this->dao->getSearch([]) ->where($this->dao->productShow()) - ->when($productId,function($query) use ($productId) { - $query->where('product_id','<>',$productId); + ->when($productId, function ($query) use ($productId) { + $query->where('product_id', '<>', $productId); }) - ->when($product_id,function($query) use ($product_id) { - $query->whereIn('product_id',$product_id); + ->when($product_id, function ($query) use ($product_id) { + $query->whereIn('product_id', $product_id); }) - ->where('mer_id',$merId); + ->where('mer_id', $merId); $data = []; $count = $query->count(); @@ -1303,7 +1313,7 @@ class ProductRepository extends BaseRepository $productIds[] = $productId; $data = $this->dao->getSearch([]) ->where($this->dao->productShow()) - ->whereNotIn('product_id',$productIds) + ->whereNotIn('product_id', $productIds) ->where('mer_id', $merId) ->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,sales,create_time') ->order('sort DESC,create_time DESC') @@ -1311,9 +1321,9 @@ class ProductRepository extends BaseRepository ->select()->toArray(); } - if ($count > 0 ){ - $count = $count > 3 ? 3 : $count; - $res = $query->setOption('field',[])->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,sales,create_time') + if ($count > 0) { + $count = $count > 3 ? 3 : $count; + $res = $query->setOption('field', [])->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,sales,create_time') ->order('sort DESC,create_time DESC') ->limit($count) ->select()->toArray(); @@ -1323,7 +1333,6 @@ class ProductRepository extends BaseRepository } - /** * TODO 单商品属性 * @param $data @@ -1397,6 +1406,7 @@ class ProductRepository extends BaseRepository } return compact('item', 'stock'); } + /** * TODO 单商品sku * @param $data @@ -1413,17 +1423,17 @@ class ProductRepository extends BaseRepository $make_group = app()->make(ProductGroupSkuRepository::class); foreach ($data as $value) { $_value = [ - 'sku' => $value['sku'], - 'price' => $value['price'], - 'stock' => $value['stock'], - 'image' => $value['image'], + 'sku' => $value['sku'], + 'price' => $value['price'], + 'stock' => $value['stock'], + 'image' => $value['image'], 'weight' => $value['weight'], 'volume' => $value['volume'], - 'sales' => $value['sales'], + 'sales' => $value['sales'], 'unique' => $value['unique'], 'bar_code' => $value['bar_code'], ]; - if($productType == 0 ){ + if ($productType == 0) { $_value['ot_price'] = $value['ot_price']; $_value['svip_price'] = $value['svip_price']; } @@ -1551,15 +1561,15 @@ class ProductRepository extends BaseRepository throw new ValidateException('商品正在参与预售活动'); if ($status == 1 && $product['product_type'] == 3) throw new ValidateException('商品正在参与助力活动'); - $this->dao->update($id,[$field => $status]); - app()->make(SpuRepository::class)->changeStatus($id,$product->product_type); + $this->dao->update($id, [$field => $status]); + app()->make(SpuRepository::class)->changeStatus($id, $product->product_type); } public function batchSwitchShow($id, $status, $field, $merId = 0) { $where['product_id'] = $id; if ($merId) $where['mer_id'] = $merId; - $products = $this->dao->getSearch([])->where('product_id','in', $id)->select(); + $products = $this->dao->getSearch([])->where('product_id', 'in', $id)->select(); if (!$products) throw new ValidateException('数据不存在'); foreach ($products as $product) { @@ -1567,12 +1577,12 @@ class ProductRepository extends BaseRepository if ($merId && $product['mer_id'] !== $merId) throw new ValidateException('商品不属于您'); if ($status == 1 && $product['product_type'] == 2) - throw new ValidateException('ID:'.$product->product_id . ' 商品正在参与预售活动'); + throw new ValidateException('ID:' . $product->product_id . ' 商品正在参与预售活动'); if ($status == 1 && $product['product_type'] == 3) - throw new ValidateException('ID:'.$product->product_id . ' 商品正在参与助力活动'); + throw new ValidateException('ID:' . $product->product_id . ' 商品正在参与助力活动'); } - $this->dao->updates($id,[$field => $status]); - Queue::push(ChangeSpuStatusJob::class,['id' => $id,'product_type'=> $product_type]); + $this->dao->updates($id, [$field => $status]); + Queue::push(ChangeSpuStatusJob::class, ['id' => $id, 'product_type' => $product_type]); } /** @@ -1582,7 +1592,7 @@ class ProductRepository extends BaseRepository * @author Qinii * @day 2022/11/14 */ - public function switchStatus($id,$data) + public function switchStatus($id, $data) { $product = $this->getSearch([])->find($id); $this->dao->update($id, $data); @@ -1597,7 +1607,7 @@ class ProductRepository extends BaseRepository 'id' => $product['product_id'] ] ], $product['mer_id']); - app()->make(SpuRepository::class)->changeStatus($id,$product->product_type); + app()->make(SpuRepository::class)->changeStatus($id, $product->product_type); } /** @@ -1608,9 +1618,9 @@ class ProductRepository extends BaseRepository * @author Qinii * @day 2022/9/6 */ - public function batchSwitchStatus(array $id,array $data) + public function batchSwitchStatus(array $id, array $data) { - $productData = $this->getSearch([])->where('product_id','in', $id)->select(); + $productData = $this->getSearch([])->where('product_id', 'in', $id)->select(); foreach ($productData as $product) { $product_type = $product['product_type']; $type = self::NOTIC_MSG[$data['status']][$product['product_type']]; @@ -1626,7 +1636,7 @@ class ProductRepository extends BaseRepository } $this->dao->updates($id, $data); Queue(ChangeSpuStatusJob::class, ['id' => $id, 'product_type' => $product_type]); - event('product.status',compact('id','data')); + event('product.status', compact('id', 'data')); } @@ -1794,13 +1804,13 @@ class ProductRepository extends BaseRepository //立即购买 限购 if ($data['is_new']) { $cart_num = $data['cart_num']; - } else { + } else { //加入购物车 //购物车现有 - $_num = $this->productOnceCountCart($where['product_id'],$data['product_attr_unique'], $userInfo->uid); + $_num = $this->productOnceCountCart($where['product_id'], $data['product_attr_unique'], $userInfo->uid); $cart_num = $_num + $data['cart_num']; } - if ($sku['stock'] < $cart_num ) throw new ValidateException('库存不足'); + if ($sku['stock'] < $cart_num) throw new ValidateException('库存不足'); //添加购物车 if (!$data['is_new']) { $cart = app()->make(StoreCartRepository::class)->getCartByProductSku($data['product_attr_unique'], $userInfo->uid); @@ -1816,7 +1826,7 @@ class ProductRepository extends BaseRepository * @author Qinii * @day 5/26/21 */ - public function productOnceCountCart($productId,$product_attr_unique,$uid) + public function productOnceCountCart($productId, $product_attr_unique, $uid) { $make = app()->make(StoreCartRepository::class); $where = [ @@ -1857,7 +1867,7 @@ class ProductRepository extends BaseRepository $value_make = app()->make(ProductAttrValueRepository::class); $sku = $value_make->getOptionByUnique($data['product_attr_unique']); - if ($sku['stock'] <= $count) throw new ValidateException('限购数量不足'); + if ($sku['stock'] <= $count) throw new ValidateException('限购数量不足'); $_sku = $value_make->getWhere(['sku' => $sku['sku'], 'product_id' => $product['old_product_id']]); if (!$_sku) throw new ValidateException('原商品SKU不存在'); if ($_sku['stock'] <= 0) throw new ValidateException('原库存不足'); @@ -1966,7 +1976,7 @@ class ProductRepository extends BaseRepository $data = app()->make(GuaranteeTemplateRepository::class)->getSearch($where)->with( [ 'templateValue' => [ - 'value' => function($query){ + 'value' => function ($query) { $query->field('guarantee_id,guarantee_name,guarantee_info'); } ], @@ -1982,15 +1992,15 @@ class ProductRepository extends BaseRepository * @author Qinii * @day 5/24/21 */ - public function increaseTake(int $uid, string $unique,int $type,int $product_id) + public function increaseTake(int $uid, string $unique, int $type, int $product_id) { $status = systemConfig('procudt_increase_status'); - if(!$status) throw new ValidateException('未开启到货通知'); + if (!$status) throw new ValidateException('未开启到货通知'); $make = app()->make(ProductTakeRepository::class); $where['product_id'] = $product_id; - if($unique) $where['unique'] = $unique; + if ($unique) $where['unique'] = $unique; $sku = app()->make(ProductAttrValueRepository::class)->getWhere($where); - if(!$sku) throw new ValidateException('商品不存在'); + if (!$sku) throw new ValidateException('商品不存在'); $data = [ 'product_id' => $sku['product_id'], 'unique' => $unique ?: 1, @@ -2016,23 +2026,23 @@ class ProductRepository extends BaseRepository } $productType = 0; $product = $this->setProduct($data); - if(isset($data['start_day'])){ //秒杀 + if (isset($data['start_day'])) { //秒杀 $product['stop'] = time() + 3600; $productType = 1; } - if(isset($data['presell_type'])){ //预售 + if (isset($data['presell_type'])) { //预售 $product['start_time'] = $data['start_time']; $product['end_time'] = $data['end_time']; $product['presell_type'] = $data['presell_type']; $product['delivery_type'] = $data['delivery_type']; $product['delivery_day'] = $data['delivery_day']; - $product['p_end_time'] = $data['end_time']; - $product['final_start_time'] = $data['final_start_time']; - $product['final_end_time'] = $data['final_end_time']; + $product['p_end_time'] = $data['end_time']; + $product['final_start_time'] = $data['final_start_time']; + $product['final_end_time'] = $data['final_end_time']; $productType = 2; } - if(isset($data['assist_count'])){ + if (isset($data['assist_count'])) { //助力 $product['assist_count'] = $data['assist_count']; $product['assist_user_count'] = $data['assist_user_count']; @@ -2040,14 +2050,14 @@ class ProductRepository extends BaseRepository $productType = 3; } - if(isset($data['buying_count_num'])) { + if (isset($data['buying_count_num'])) { // $product['buying_count_num'] = $data['buying_count_num']; $product['pay_count'] = $data['pay_count']; $productType = 4; } - $product['slider_image'] = explode(',',$product['slider_image']); + $product['slider_image'] = explode(',', $product['slider_image']); $product['merchant'] = $data['merchant']; $product['content'] = ['content' => $data['content']]; $settleParams = $this->setAttrValue($data, 0, $productType, 0); @@ -2060,36 +2070,36 @@ class ProductRepository extends BaseRepository $product['product_type'] = $productType; foreach ($settleParams['attrValue'] as $k => $value) { $_value = [ - 'sku' => $value['sku'], - 'price' => $value['price'], - 'stock' => $value['stock'], - 'image' => $value['image'], + 'sku' => $value['sku'], + 'price' => $value['price'], + 'stock' => $value['stock'], + 'image' => $value['image'], 'weight' => $value['weight'], 'volume' => $value['volume'], - 'sales' => $value['sales'], + 'sales' => $value['sales'], 'unique' => $value['unique'], 'bar_code' => $value['bar_code'], ]; $sku[$value['sku']] = $_value; } - $preview_key = 'preview'.$data['mer_id'].$productType.'_'.time(); - unset($settleParams['data'],$settleParams['attrValue']); + $preview_key = 'preview' . $data['mer_id'] . $productType . '_' . time(); + unset($settleParams['data'], $settleParams['attrValue']); $settleParams['sku'] = $sku; - $settleParams['attr'] = $this->detailAttr($settleParams['attr'],1); + $settleParams['attr'] = $this->detailAttr($settleParams['attr'], 1); - if(isset($data['guarantee_template_id'])) { + if (isset($data['guarantee_template_id'])) { $guarantee_id = app()->make(GuaranteeValueRepository::class)->getSearch(['guarantee_template_id' => $data['guarantee_template_id']])->column('guarantee_id'); $product['guaranteeTemplate'] = app()->make(GuaranteeRepository::class)->getSearch(['status' => 1, 'is_del' => 0])->where('guarantee_id', 'in', $guarantee_id)->select(); } - if(isset($data['temp_id'])) { + if (isset($data['temp_id'])) { $product['temp'] = app()->make(ShippingTemplateRepository::class)->getSearch(['shipping_template_id' => $data['temp_id']])->find(); } - $ret = array_merge($product,$settleParams); + $ret = array_merge($product, $settleParams); - Cache::set($preview_key,$ret); + Cache::set($preview_key, $ret); - return compact('preview_key','ret'); + return compact('preview_key', 'ret'); } @@ -2102,8 +2112,7 @@ class ProductRepository extends BaseRepository */ public function getPreview(array $data) { - switch($data['product_type']) - { + switch ($data['product_type']) { case 0: return $this->apiProductDetail(['product_id' => $data['id']], 0, 0); break; @@ -2113,20 +2122,20 @@ class ProductRepository extends BaseRepository break; case 2: $make = app()->make(ProductPresellRepository::class); - $res = $make->getWhere([$make->getPk()=> $data['id']])->toArray(); + $res = $make->getWhere([$make->getPk() => $data['id']])->toArray(); $ret = $this->apiProductDetail(['product_id' => $res['product_id']], 2, $data['id'])->toArray(); $ret['ot_price'] = $ret['price']; $ret['start_time'] = $res['start_time']; $ret['p_end_time'] = $res['end_time']; - $ret = array_merge($ret,$res); + $ret = array_merge($ret, $res); break; case 3: $make = app()->make(ProductAssistRepository::class); - $res = $make->getWhere([$make->getPk()=> $data['id']])->toArray(); + $res = $make->getWhere([$make->getPk() => $data['id']])->toArray(); $ret = $this->apiProductDetail(['product_id' => $res['product_id']], 3, $data['id'])->toArray(); - $ret = array_merge($ret,$res); - foreach ($ret['sku'] as $value){ + $ret = array_merge($ret, $res); + foreach ($ret['sku'] as $value) { $ret['price'] = $value['price']; $ret['stock'] = $value['stock']; } @@ -2136,7 +2145,7 @@ class ProductRepository extends BaseRepository $res = $make->get($data['id'])->toArray(); $ret = $this->apiProductDetail(['product_id' => $res['product_id']], 4, $data['id'])->toArray(); $ret['ot_price'] = $ret['price']; - $ret = array_merge($ret,$res); + $ret = array_merge($ret, $res); break; default: break; @@ -2149,7 +2158,7 @@ class ProductRepository extends BaseRepository $where['product_id'] = $id; $field = isset($data['sys_labels']) ? 'sys_labels' : 'mer_labels'; if ($merId) $where['mer_id'] = $merId; - app()->make(ProductLabelRepository::class)->checkHas($merId,$data[$field]); + app()->make(ProductLabelRepository::class)->checkHas($merId, $data[$field]); $ret = $this->dao->getWhere($where); $activeId = $ret->seckillActive->seckill_active_id ?? 0; @@ -2168,7 +2177,7 @@ class ProductRepository extends BaseRepository return app()->make(ProductAttrValueRepository::class)->getSearch(['product_id' => $id])->select()->append(['is_svip_price']); } - public function checkParams($data,$merId,$id = null) + public function checkParams($data, $merId, $id = null) { if (!$data['pay_limit']) $data['once_max_count'] = 0; if ($data['brand_id'] > 0 && !$this->merBrandExists($data['brand_id'])) @@ -2180,26 +2189,26 @@ class ProductRepository extends BaseRepository if ($data['delivery_way'] == 2 && !$this->merShippingExists($merId, $data['temp_id'])) throw new ValidateException('运费模板不存在'); if (isset($data['type']) && $data['type'] && $data['extend']) { - $key = ['email','text','number','date','time','idCard','mobile','image']; + $key = ['email', 'text', 'number', 'date', 'time', 'idCard', 'mobile', 'image']; if (count($data['extend']) > 10) throw new ValidateException('附加表单不能超过10条'); $title = []; foreach ($data['extend'] as $item) { - if (empty($item['title']) ) - throw new ValidateException('表单名称不能为空:'.$item['key']); - if (in_array($item['title'],$title)) - throw new ValidateException('表单名称不能重复:'.$item['title']); + if (empty($item['title'])) + throw new ValidateException('表单名称不能为空:' . $item['key']); + if (in_array($item['title'], $title)) + throw new ValidateException('表单名称不能重复:' . $item['title']); $title[] = $item['title']; if (!in_array($item['key'], $key)) - throw new ValidateException('表单类型错误:'.$item['key']); + throw new ValidateException('表单类型错误:' . $item['key']); $extend[] = [ 'title' => $item['title'], - 'key' => $item['key'] , + 'key' => $item['key'], 'require' => $item['require'], ]; } } - app()->make(ProductLabelRepository::class)->checkHas($merId,$data['mer_labels']); - $count = app()->make(StoreCategoryRepository::class)->getWhereCount(['store_category_id' => $data['cate_id'],'is_show' => 1]); + app()->make(ProductLabelRepository::class)->checkHas($merId, $data['mer_labels']); + $count = app()->make(StoreCategoryRepository::class)->getWhereCount(['store_category_id' => $data['cate_id'], 'is_show' => 1]); if (!$count) throw new ValidateException('平台分类不存在或不可用'); app()->make(StoreProductValidate::class)->check($data); if ($id) unset($data['type']); diff --git a/app/common/repositories/user/UserExtractRepository.php b/app/common/repositories/user/UserExtractRepository.php index e299576..a8bd5fa 100644 --- a/app/common/repositories/user/UserExtractRepository.php +++ b/app/common/repositories/user/UserExtractRepository.php @@ -69,8 +69,6 @@ class UserExtractRepository extends BaseRepository */ public function getList(array $where, $page, $limit) { - $a = UserRepository::transAdd(); - echo 13;die; $query = $this->dao->search($where)->with(['user' => function ($query) { $query->field('uid,avatar,nickname'); }]);