From 29360e515384f5f3a213657519f7c5dcc8f2aa0a Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 11:52:31 +0800 Subject: [PATCH 01/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 16 +++++++++------- .../api/store/merchant/MerchantIntention.php | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 61253bb3..432e1918 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -313,13 +313,13 @@ class ProductRepository extends BaseRepository $res = $this->dao->get($id); $data['svip_price_type'] = $res['svip_price_type']; $settleParams = $this->setAttrValue($data, $id, 0, 1,$merId); - $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId); + // $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']); $ret = Spu::getInstance()->where('product_id', $id)->whereIn('product_type',[0, 98, 99])->find(); Db::transaction(function () use ($id, $data, $settleParams,$ret) { - $this->save($id, $settleParams, null, [], 0); + $this->save($id, $settleParams, null, [], 0,false); app()->make(SpuRepository::class)->update($ret->spu_id,['price' => $data['price']]); Queue(SendSmsJob::class, ['tempId' => 'PRODUCT_INCREASE', 'id' => $id]); }); @@ -349,11 +349,13 @@ class ProductRepository extends BaseRepository * @param $content * @return int */ - public function save($id, $settleParams, $content, $data = [], $productType = 0) + public function save($id, $settleParams, $content, $data = [], $productType = 0,$is_phone=true) { - (app()->make(ProductAttrRepository::class))->clearAttr($id); - (app()->make(ProductAttrValueRepository::class))->clearAttr($id); - (app()->make(ProductCateRepository::class))->clearAttr($id); + if($is_phone==true){ + (app()->make(ProductAttrRepository::class))->clearAttr($id); + (app()->make(ProductAttrValueRepository::class))->clearAttr($id); + (app()->make(ProductCateRepository::class))->clearAttr($id); + } if (isset($settleParams['cate'])) (app()->make(ProductCateRepository::class)->insert($settleParams['cate'])); if (isset($settleParams['attr'])) (app()->make(ProductAttrRepository::class))->insert($settleParams['attr']); @@ -378,7 +380,7 @@ class ProductRepository extends BaseRepository $res = $this->dao->update($id, $data); if(isset($data['status']) && $data['status'] !== 1 ){ - $message = '您有1个新的'. ($productType ? '秒杀商品' : ($data['is_gift_bag'] ? '礼包商品' :'商品')) . '待审核'; + $message = '您有1个新的'. $productType .'商品待审核';//? '秒杀商品' : ($data['is_gift_bag'] ? '礼包商品' :'商品')) . $type = $productType ? 'new_seckill' : ($data['is_gift_bag'] ? 'new_bag' :'new_product'); SwooleTaskService::admin('notice', [ 'type' => $type, diff --git a/app/controller/api/store/merchant/MerchantIntention.php b/app/controller/api/store/merchant/MerchantIntention.php index 08fc6346..11f92c99 100644 --- a/app/controller/api/store/merchant/MerchantIntention.php +++ b/app/controller/api/store/merchant/MerchantIntention.php @@ -93,7 +93,7 @@ class MerchantIntention extends BaseController 'street' => $data['street_id'] ?? '', 'address' => $data['address'] ?? '', 'mer_intention_id' => $intention->mer_intention_id, - 'type_id'=>$data['mer_type_id'] + 'type_id'=>$data['mer_type_id']??'' ]; $postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant'; $res = $this->sendMerIntentionApply($sendData, $postUrl); From 22c4cb85188c919df1e7bf60af329c76ee850e17 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 13:44:02 +0800 Subject: [PATCH 02/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 452 +++++++++--------- 1 file changed, 221 insertions(+), 231 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 432e1918..e2642fa6 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -69,50 +69,50 @@ 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', 'source_product_id', 'stock', - ["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', 'source_product_id', 'stock', + ["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,update_time,source_product_id'; protected $filed = 'Product.bar_code,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,update_time,source_product_id'; const NOTIC_MSG = [ - 1 => [ - '0' => 'product_success', - '1' => 'product_seckill_success', - '2' => 'product_presell_success', - '3' => 'product_assist_success', - '4' => 'product_group_success', - '98' => 'product_success', - 'msg' => '审核通过' - ], - -1 => [ - '0' => 'product_fail', - '1' => 'product_seckill_fail', - '2' => 'product_presell_fail', - '3' => 'product_assist_fail', - '4' => 'product_group_fail', - '98' => 'product_fail', - 'msg' => '审核失败' - ], - -2 => [ - '0' => 'product_fail', - '1' => 'product_seckill_fail', - '2' => 'product_presell_fail', - '3' => 'product_assist_fail', - '4' => 'product_group_fail', - '98' => 'product_fail', - 'msg' => '被下架' - ], - ]; + 1 => [ + '0' => 'product_success', + '1' => 'product_seckill_success', + '2' => 'product_presell_success', + '3' => 'product_assist_success', + '4' => 'product_group_success', + '98' => 'product_success', + 'msg' => '审核通过' + ], + -1 => [ + '0' => 'product_fail', + '1' => 'product_seckill_fail', + '2' => 'product_presell_fail', + '3' => 'product_assist_fail', + '4' => 'product_group_fail', + '98' => 'product_fail', + 'msg' => '审核失败' + ], + -2 => [ + '0' => 'product_fail', + '1' => 'product_seckill_fail', + '2' => 'product_presell_fail', + '3' => 'product_assist_fail', + '4' => 'product_group_fail', + '98' => 'product_fail', + 'msg' => '被下架' + ], + ]; /** * ProductRepository constructor. * @param dao $dao @@ -228,21 +228,21 @@ 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; $product['product_type'] = $productType; $result = $this->dao->create($product); - - $settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0,$data['mer_id']); + + $settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0, $data['mer_id']); // $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']); $settleParams['attr'] = $this->setAttr($data['attr'], $result->product_id); - if (in_array($productType, [0, 98, 99])) 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, 98, 99])) 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, 98, 99])) { if ($productType == 1) { //秒杀商品 $dat = $this->setSeckillProduct($data); @@ -255,7 +255,7 @@ class ProductRepository extends BaseRepository app()->make(SpuRepository::class)->create($product, $result->product_id, $activity_id, $productType); } $product = $result; - event('product.create',compact('product', 'data', 'conType')); + event('product.create', compact('product', 'data', 'conType')); return $result->product_id; }); } @@ -272,19 +272,19 @@ 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,$merId); + $settleParams = $this->setAttrValue($data, $id, $productType, 1, $merId); $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); @@ -296,7 +296,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')); if ($data['status'] == 0) { event('product.sell', ['product_id' => [$id]]); } @@ -312,15 +312,15 @@ class ProductRepository extends BaseRepository } $res = $this->dao->get($id); $data['svip_price_type'] = $res['svip_price_type']; - $settleParams = $this->setAttrValue($data, $id, 0, 1,$merId); - // $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId); - // $settleParams['attr'] = $this->setAttr($data['attr'], $id); + $settleParams = $this->setAttrValue($data, $id, 0, 1, $merId); + $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']); - $ret = Spu::getInstance()->where('product_id', $id)->whereIn('product_type',[0, 98, 99])->find(); - Db::transaction(function () use ($id, $data, $settleParams,$ret) { - $this->save($id, $settleParams, null, [], 0,false); - app()->make(SpuRepository::class)->update($ret->spu_id,['price' => $data['price']]); + unset($data['attrValue'], $data['attr'], $data['mer_cate_id']); + $ret = Spu::getInstance()->where('product_id', $id)->whereIn('product_type', [0, 98, 99])->find(); + 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']]); Queue(SendSmsJob::class, ['tempId' => 'PRODUCT_INCREASE', 'id' => $id]); }); } @@ -349,24 +349,22 @@ class ProductRepository extends BaseRepository * @param $content * @return int */ - public function save($id, $settleParams, $content, $data = [], $productType = 0,$is_phone=true) + public function save($id, $settleParams, $content, $data = [], $productType = 0) { - if($is_phone==true){ - (app()->make(ProductAttrRepository::class))->clearAttr($id); - (app()->make(ProductAttrValueRepository::class))->clearAttr($id); - (app()->make(ProductCateRepository::class))->clearAttr($id); - } + (app()->make(ProductAttrRepository::class))->clearAttr($id); + (app()->make(ProductAttrValueRepository::class))->clearAttr($id); + (app()->make(ProductCateRepository::class))->clearAttr($id); if (isset($settleParams['cate'])) (app()->make(ProductCateRepository::class)->insert($settleParams['cate'])); if (isset($settleParams['attr'])) (app()->make(ProductAttrRepository::class))->insert($settleParams['attr']); 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); } @@ -379,9 +377,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' => [ @@ -452,11 +450,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; } $result = [ 'store_name' => $data['store_name'], @@ -464,25 +461,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']), + '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, @@ -503,7 +500,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; } @@ -540,7 +537,7 @@ class ProductRepository extends BaseRepository public function setAttr(array $data, int $productId) { $result = []; - try{ + try { foreach ($data as $value) { $result[] = [ 'type' => 0, @@ -564,9 +561,9 @@ class ProductRepository extends BaseRepository * @param int $productId * @return mixed */ - public function setAttrValue(array $data, int $productId, int $productType, int $isUpdate = 0,int $merId = 0) + public function setAttrValue(array $data, int $productId, int $productType, int $isUpdate = 0, int $merId = 0) { - if($merId<=0){ + if ($merId <= 0) { throw new ValidateException('添加商品商户id不能为0'); } $extension_status = systemConfig('extension_status'); @@ -597,8 +594,8 @@ class ProductRepository extends BaseRepository $_svip_price = $value['svip_price']; $svip_price = !$svip_price ? $value['svip_price'] : (($svip_price > $value['svip_price']) ? $value['svip_price'] : $svip_price); } - $procure_price=$value['procure_price']??0.00; - $cost = !$cost ? $value['cost'] : (($cost > $value['cost']) ?$cost: $value['cost']); + $procure_price = $value['procure_price'] ?? 0.00; + $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_); @@ -609,8 +606,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, @@ -627,7 +624,7 @@ class ProductRepository extends BaseRepository $stock = $stock + intval($value['stock']); } $result['data'] = [ - 'price' => $price , + 'price' => $price, 'stock' => $stock, 'ot_price' => $ot_price, 'cost' => $cost, @@ -635,7 +632,7 @@ class ProductRepository extends BaseRepository 'procure_price' => $procure_price, ]; } catch (\Exception $exception) { - throw new ValidateException('规格错误 :'.$exception->getMessage()); + throw new ValidateException('规格错误 :' . $exception->getMessage()); } return $result; } @@ -652,8 +649,8 @@ class ProductRepository extends BaseRepository public function setUnique(int $id, $sku, int $type) { $str = strval($type); - $result=strlen($str); - $length=12-$result; + $result = strlen($str); + $length = 12 - $result; return $unique = substr(md5($sku . $id), 12, $length) . $type; // $has = (app()->make(ProductAttrValueRepository::class))->merUniqueExists(null, $unique); // return $has ? false : $unique; @@ -670,9 +667,10 @@ class ProductRepository extends BaseRepository */ public function getAdminOneProduct(int $id, ?int $activeId, $conType = 0) { - $with = ['attr', 'attrValue', 'oldAttrValue', 'merCateId.category', 'storeCategory', 'brand', 'temp', 'seckillActive', + $with = [ + 'attr', 'attrValue', 'oldAttrValue', 'merCateId.category', 'storeCategory', 'brand', 'temp', 'seckillActive', 'content', - 'merchant'=> function($query){ + 'merchant' => function ($query) { $query->field('mer_id,mer_avatar,mer_name,is_trader'); }, 'guarantee.templateValue.value', @@ -681,7 +679,7 @@ 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['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']]]; @@ -693,10 +691,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); @@ -759,28 +757,26 @@ class ProductRepository extends BaseRepository $data['attrValue'] = $arr; $content = $data['content']['content'] ?? ''; $data['content_arr'] = []; - if (isset($data['content']) &&$data['content']['type']==1){ + if (isset($data['content']) && $data['content']['type'] == 1) { $arr = json_decode($content); - if(is_array($arr)){ + if (is_array($arr)) { $data['content_arr'] = $arr; - if($arr){ - $content=''; - if(isset($arr['image'])){ - foreach($arr['image'] as $k=>$v){ - $content.='
'; + if ($arr) { + $content = ''; + if (isset($arr['image'])) { + foreach ($arr['image'] as $k => $v) { + $content .= '
'; + } + } else { + foreach ($arr as $k => $v) { + $content .= '
'; } - }else{ - foreach($arr as $k=>$v){ - $content.='
'; - } } - } - }else{ + } else { $content = $arr; } - - } + } unset($data['content']); $data['content'] = $content; return $data; @@ -910,7 +906,7 @@ class ProductRepository extends BaseRepository $data->append(['us_status']); $list = hasMany( - $data , + $data, 'mer_labels', ProductLabel::class, 'product_label_id', @@ -946,7 +942,7 @@ class ProductRepository extends BaseRepository $data->append(['seckill_status', 'us_status']); $list = hasMany( - $data , + $data, 'mer_labels', ProductLabel::class, 'product_label_id', @@ -979,9 +975,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', @@ -1026,7 +1022,7 @@ class ProductRepository extends BaseRepository $data->append(['seckill_status', 'us_status']); $list = hasMany( - $data , + $data, 'sys_labels', ProductLabel::class, 'product_label_id', @@ -1143,7 +1139,7 @@ class ProductRepository extends BaseRepository * @param $id * @param $userInfo */ - public function detail(int $id, $userInfo,$product_type) + public function detail(int $id, $userInfo, $product_type) { $where = [ 'is_show' => 1, @@ -1162,11 +1158,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) @@ -1178,7 +1174,7 @@ class ProductRepository extends BaseRepository 'attrValue', 'oldAttrValue', 'merchant' => function ($query) { - $query->with(['type_names'])->append(['isset_certificate','services_type']); + $query->with(['type_names'])->append(['isset_certificate', 'services_type']); }, 'seckillActive' => function ($query) { $query->field('start_day,end_day,start_time,end_time,product_id'); @@ -1186,7 +1182,7 @@ class ProductRepository extends BaseRepository 'temp' ]; - $append = ['guaranteeTemplate','params']; + $append = ['guaranteeTemplate', 'params']; if (empty($where['product_id']) || $productType != 0) { $where['product_type'] = $productType; } @@ -1241,7 +1237,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'; } @@ -1260,28 +1256,26 @@ class ProductRepository extends BaseRepository $res['sku'] = $sku; $res->append($append); if ($res['content'] && $res['content']['type'] == 1) { - $content= json_decode($res['content']['content']); - if(is_Array($content) && isset($content['image'])){ + $content = json_decode($res['content']['content']); + if (is_Array($content) && isset($content['image'])) { // $img='

'; - $image= $content['image']??[]; + $image = $content['image'] ?? []; // foreach($content['image'] as $k=>$v){ // $img =$img. ''; // } - $res['content']['content']=['image'=>$image]; - - }elseif(is_object($content)){ - $image= $content->image??[]; - // $img='

'; - // foreach($image as $k=>$v){ - // $img =$img. ''; - // } - $res['content']['content']=['image'=>$image]; - } - else{ - if(is_Array($content)){ - $res['content']['content']=['image'=>$content]; - }else{ - $res['content']['content']=$content; + $res['content']['content'] = ['image' => $image]; + } elseif (is_object($content)) { + $image = $content->image ?? []; + // $img='

'; + // foreach($image as $k=>$v){ + // $img =$img. ''; + // } + $res['content']['content'] = ['image' => $image]; + } else { + if (is_Array($content)) { + $res['content']['content'] = ['image' => $content]; + } else { + $res['content']['content'] = $content; } } } @@ -1304,8 +1298,8 @@ 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']; } return $res; @@ -1323,13 +1317,13 @@ 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); @@ -1349,24 +1343,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(); // if ($count < 3) { @@ -1380,9 +1374,9 @@ class ProductRepository extends BaseRepository // ->limit((3 - $count)) // ->select()->toArray(); // } - if ($count > 0 ){ + 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') + $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(); @@ -1493,7 +1487,7 @@ class ProductRepository extends BaseRepository 'bar_code' => $value['bar_code'], 'procure_price' => $value['procure_price'], ]; - if($productType == 0 ){ + if ($productType == 0) { $_value['ot_price'] = $value['ot_price']; $_value['svip_price'] = $value['svip_price']; } @@ -1626,12 +1620,12 @@ class ProductRepository extends BaseRepository Db::rollback(); throw new ValidateException('商品更新出错'); } - $changeStatus= app()->make(SpuRepository::class)->changeStatus($id, $product->product_type); - if ($changeStatus=== false) { + $changeStatus = app()->make(SpuRepository::class)->changeStatus($id, $product->product_type); + if ($changeStatus === false) { Db::rollback(); throw new ValidateException('商品spu更新出错'); - }else{ - if ($product->product_type==0){ + } else { + if ($product->product_type == 0) { event('product.sell', ['product_id' => [$id]]); } } @@ -1642,7 +1636,7 @@ class ProductRepository extends BaseRepository { $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('数据不存在'); $productIds = []; @@ -1654,18 +1648,18 @@ 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 . ' 商品正在参与助力活动'); } Db::startTrans(); try { - if ($this->dao->updates($id,[$field => $status]) === false) { + if ($this->dao->updates($id, [$field => $status]) === false) { throw new \Exception('商品操作出错', 500); } event('product.sell', ['product_id' => $productIds]); Db::commit(); - Queue::push(ChangeSpuStatusJob::class,['id' => $id,'product_type'=> $product_type]); + Queue::push(ChangeSpuStatusJob::class, ['id' => $id, 'product_type' => $product_type]); } catch (\Exception $e) { Db::rollback(); throw new \Exception('商品操作出错', $e->getCode()); @@ -1679,7 +1673,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); @@ -1694,10 +1688,9 @@ 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); event('product.sell', ['product_id' => [$id]]); - $this->switchShow($id,$status,'is_used',0); - + $this->switchShow($id, $status, 'is_used', 0); } /** @@ -1708,9 +1701,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']]; @@ -1723,14 +1716,13 @@ class ProductRepository extends BaseRepository 'id' => $product['product_id'] ] ], $product['mer_id']); - if($data['status']==1){ - $this->switchShow($product['product_id'],1,'is_used',0); + if ($data['status'] == 1) { + $this->switchShow($product['product_id'], 1, 'is_used', 0); } - } $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')); event('product.sell', ['product_id' => $id]); } @@ -1912,16 +1904,16 @@ 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,$data['product_type']); + $_num = $this->productOnceCountCart($where['product_id'], $data['product_attr_unique'], $userInfo->uid, $data['product_type']); $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,$data['product_type']); + $cart = app()->make(StoreCartRepository::class)->getCartByProductSku($data['product_attr_unique'], $userInfo->uid, $data['product_type']); } return compact('product', 'sku', 'cart'); } @@ -1934,7 +1926,7 @@ class ProductRepository extends BaseRepository * @author Qinii * @day 5/26/21 */ - public function productOnceCountCart($productId,$product_attr_unique,$uid,$product_type=0) + public function productOnceCountCart($productId, $product_attr_unique, $uid, $product_type = 0) { $make = app()->make(StoreCartRepository::class); $where = [ @@ -2084,11 +2076,12 @@ 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'); } ], - ])->find(); + ] + )->find(); return $data ?? []; } @@ -2100,15 +2093,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, @@ -2134,11 +2127,11 @@ 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']; @@ -2150,7 +2143,7 @@ class ProductRepository extends BaseRepository $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']; @@ -2158,14 +2151,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); @@ -2190,24 +2183,24 @@ class ProductRepository extends BaseRepository ]; $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'); } @@ -2220,8 +2213,7 @@ class ProductRepository extends BaseRepository */ public function getPreview(array $data) { - switch($data['product_type']) - { + switch ($data['product_type']) { case 0: case 98: case 99: @@ -2233,20 +2225,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']; } @@ -2256,7 +2248,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; @@ -2269,7 +2261,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; @@ -2288,7 +2280,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'])) @@ -2300,20 +2292,20 @@ 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'], ]; } @@ -2321,8 +2313,8 @@ class ProductRepository extends BaseRepository foreach ($data['attrValue'] as $k => $item) { //$data['attrValue'][$k]['stock'] = 0; } - 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']); @@ -2346,8 +2338,8 @@ class ProductRepository extends BaseRepository $model = new PurchaseRecord(); $stockIn = $params['number'] ?? 0; $price = $params['price'] ?? 0; - if($stockIn==0){ - $stockIn=1; + if ($stockIn == 0) { + $stockIn = 1; } if (empty($params['product_id']) && !empty($params['order_product_id'])) { //有商品无规格或者无商品无规格,导入商品和规格 @@ -2364,11 +2356,11 @@ class ProductRepository extends BaseRepository throw new \Exception('商品规格导入出错', 500); } } - if( $orderProduct->is_imported == 1){ - + if ($orderProduct->is_imported == 1) { + ProductAttrValue::where('mer_id', $merId) - ->where('product_id', $product['product_id']) - ->update(['stock'=>$attrValue->stock + $stockIn]); + ->where('product_id', $product['product_id']) + ->update(['stock' => $attrValue->stock + $stockIn]); $data = [ 'order_id' => $params['order_id'] ?? 0, 'order_product_id' => $params['order_product_id'] ?? 0, @@ -2378,7 +2370,7 @@ class ProductRepository extends BaseRepository 'unique' => $attrValue['unique'], 'price' => $price, 'mer_id' => $product->mer_id, - 'supplier_mer_id' => $orderMerId??0, + 'supplier_mer_id' => $orderMerId ?? 0, ]; if (!$model->save($data)) { throw new \Exception('入库失败', 500); @@ -2398,7 +2390,6 @@ class ProductRepository extends BaseRepository $productId = $this->import($params['order_product_id'], request()->userInfo()); $product = $this->get($productId); $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $productId)->find(); - } } else { //有商品有规格 @@ -2538,7 +2529,7 @@ class ProductRepository extends BaseRepository $data = $query->page($page, $limit)->setOption('field', [])->field($this->filed)->select(); $data->append(['us_status']); $list = hasMany( - $data , + $data, 'mer_labels', ProductLabel::class, 'product_label_id', @@ -2548,5 +2539,4 @@ class ProductRepository extends BaseRepository ); return compact('count', 'list'); } - } From b9298d45c0c38f309b75bb710a5c754398c11cfb Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 15:17:39 +0800 Subject: [PATCH 03/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 25 ++++++++++++------- app/controller/api/server/StoreProduct.php | 8 ++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index e2642fa6..2df79cbd 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2339,7 +2339,12 @@ class ProductRepository extends BaseRepository $stockIn = $params['number'] ?? 0; $price = $params['price'] ?? 0; if ($stockIn == 0) { - $stockIn = 1; + $number=$model->where('order_id',$params['order_id']) + ->where('order_product_id',$params['order_product_id'])->where('order_unique',$params['order_unique'])->value('number'); + if($number<=0){ + throw new ValidateException('数量不能为空'); + } + $stockIn = $number; } if (empty($params['product_id']) && !empty($params['order_product_id'])) { //有商品无规格或者无商品无规格,导入商品和规格 @@ -2353,10 +2358,10 @@ class ProductRepository extends BaseRepository if (empty($orderProduct)) { $unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']); if (!$unique) { - throw new \Exception('商品规格导入出错', 500); + throw new ValidateException('商品规格导入出错'); } } - if ($orderProduct->is_imported == 1) { + if ($orderProduct->is_imported == 0) { ProductAttrValue::where('mer_id', $merId) ->where('product_id', $product['product_id']) @@ -2373,10 +2378,12 @@ class ProductRepository extends BaseRepository 'supplier_mer_id' => $orderMerId ?? 0, ]; if (!$model->save($data)) { - throw new \Exception('入库失败', 500); + throw new ValidateException('入库失败'); } Db::commit(); return true; + }else{ + throw new ValidateException('该商品已导入过'); } $stockIn = $orderProduct['product_num'] ?? 0; $price = $orderProduct['product_price'] ?? 0; @@ -2397,7 +2404,7 @@ class ProductRepository extends BaseRepository $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $params['product_id'])->where('unique', $params['unique'])->find(); } if (!$product || !$attrValue) { - throw new DataNotFoundException('商品或规格不存在'); + throw new ValidateException('商品或规格不存在'); } if ($stockIn <= 0) { throw new ValidateException('入库数量不能小于等于0'); @@ -2406,7 +2413,7 @@ class ProductRepository extends BaseRepository $attrValue->save(); $product->stock = $stockIn + $product->stock; if (!$product->save()) { - throw new \Exception('商品库存保存失败', 500); + throw new ValidateException('商品库存保存失败'); } $data = [ 'order_id' => $params['order_id'] ?? 0, @@ -2420,15 +2427,15 @@ class ProductRepository extends BaseRepository 'supplier_mer_id' => $supplierMerId, ]; if (!$model->save($data)) { - throw new \Exception('入库失败', 500); + throw new ValidateException('入库失败'); } if (isset($orderProduct) && !$orderProduct->save(['is_imported' => 1])) { - throw new \Exception('订单商品更新出错', 500); + throw new ValidateException('订单商品更新出错'); } Db::commit(); } catch (\Exception $e) { Db::rollback(); - throw new \Exception($e->getMessage(), $e->getCode()); + throw new ValidateException($e->getMessage(), $e->getCode()); } return true; } diff --git a/app/controller/api/server/StoreProduct.php b/app/controller/api/server/StoreProduct.php index 0a3ef2e2..acc64471 100644 --- a/app/controller/api/server/StoreProduct.php +++ b/app/controller/api/server/StoreProduct.php @@ -239,8 +239,12 @@ class StoreProduct extends BaseController public function stockIn() { $params = $this->request->param(); - $this->repository->stockIn($this->merId, $params); - return app('json')->success('入库成功'); + $res=$this->repository->stockIn($this->merId, $params); + if($res){ + return app('json')->success('入库成功'); + }else{ + return app('json')->success('入库失败'); + } } } From 8c716b11e29cf065a5d0288f862cf9cc2941c93c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 15:23:16 +0800 Subject: [PATCH 04/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/store/product/ProductRepository.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 2df79cbd..cb0b7fab 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2338,14 +2338,6 @@ class ProductRepository extends BaseRepository $model = new PurchaseRecord(); $stockIn = $params['number'] ?? 0; $price = $params['price'] ?? 0; - if ($stockIn == 0) { - $number=$model->where('order_id',$params['order_id']) - ->where('order_product_id',$params['order_product_id'])->where('order_unique',$params['order_unique'])->value('number'); - if($number<=0){ - throw new ValidateException('数量不能为空'); - } - $stockIn = $number; - } if (empty($params['product_id']) && !empty($params['order_product_id'])) { //有商品无规格或者无商品无规格,导入商品和规格 $product = $this->getWhere(['source_product_id' => $params['order_product_id'], 'mer_id' => $merId]); @@ -2362,6 +2354,8 @@ class ProductRepository extends BaseRepository } } if ($orderProduct->is_imported == 0) { + + $stockIn=$orderProduct['product_num']; ProductAttrValue::where('mer_id', $merId) ->where('product_id', $product['product_id']) From ccb4b1489aff8631280687b633e643c276356a00 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 15:24:51 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index cb0b7fab..84659ffe 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2354,7 +2354,6 @@ class ProductRepository extends BaseRepository } } if ($orderProduct->is_imported == 0) { - $stockIn=$orderProduct['product_num']; ProductAttrValue::where('mer_id', $merId) @@ -2374,6 +2373,7 @@ class ProductRepository extends BaseRepository if (!$model->save($data)) { throw new ValidateException('入库失败'); } + $orderProduct->save(['is_imported' => 1]); Db::commit(); return true; }else{ From 62b5044d331e9e76b93b5fa48ff344f6a34b5c97 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 15:42:39 +0800 Subject: [PATCH 06/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 84659ffe..4193dc27 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2355,10 +2355,8 @@ class ProductRepository extends BaseRepository } if ($orderProduct->is_imported == 0) { $stockIn=$orderProduct['product_num']; - - ProductAttrValue::where('mer_id', $merId) - ->where('product_id', $product['product_id']) - ->update(['stock' => $attrValue->stock + $stockIn]); + $attrValue->update(['stock' => $attrValue->stock + $stockIn]); + $product->stock = $stockIn + $product->stock; $data = [ 'order_id' => $params['order_id'] ?? 0, 'order_product_id' => $params['order_product_id'] ?? 0, From 7f2f1057df4ef0de7266becc5d042d5f258af469 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 15:59:53 +0800 Subject: [PATCH 07/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/store/product/ProductRepository.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 4193dc27..4052098c 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2338,6 +2338,12 @@ class ProductRepository extends BaseRepository $model = new PurchaseRecord(); $stockIn = $params['number'] ?? 0; $price = $params['price'] ?? 0; + $orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id']) + ->where('product_sku', $params['order_unique'])->find(); + $stockIn=$orderProduct['product_num']; + if ($stockIn <= 0) { + throw new ValidateException('入库数量不能小于等于0'); + } if (empty($params['product_id']) && !empty($params['order_product_id'])) { //有商品无规格或者无商品无规格,导入商品和规格 $product = $this->getWhere(['source_product_id' => $params['order_product_id'], 'mer_id' => $merId]); @@ -2346,7 +2352,6 @@ class ProductRepository extends BaseRepository if (!empty($params['order_id'])) { //采购、委托订单导入 $orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id'); - $orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])->where('product_sku', $params['order_unique'])->find(); if (empty($orderProduct)) { $unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']); if (!$unique) { @@ -2354,7 +2359,6 @@ class ProductRepository extends BaseRepository } } if ($orderProduct->is_imported == 0) { - $stockIn=$orderProduct['product_num']; $attrValue->update(['stock' => $attrValue->stock + $stockIn]); $product->stock = $stockIn + $product->stock; $data = [ @@ -2398,9 +2402,6 @@ class ProductRepository extends BaseRepository if (!$product || !$attrValue) { throw new ValidateException('商品或规格不存在'); } - if ($stockIn <= 0) { - throw new ValidateException('入库数量不能小于等于0'); - } $attrValue->stock = $attrValue->stock + $stockIn; $attrValue->save(); $product->stock = $stockIn + $product->stock; From 15f0927d416ec31e9b1ab0508f106b054b5c385b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 16:09:22 +0800 Subject: [PATCH 08/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 4052098c..92f0be31 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2359,7 +2359,8 @@ class ProductRepository extends BaseRepository } } if ($orderProduct->is_imported == 0) { - $attrValue->update(['stock' => $attrValue->stock + $stockIn]); + + $attrValue->stock=$attrValue->stock + $stockIn; $product->stock = $stockIn + $product->stock; $data = [ 'order_id' => $params['order_id'] ?? 0, From 785b5bd56241d9d0a2a7a774eb942c573931e83c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 17:04:08 +0800 Subject: [PATCH 09/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 92f0be31..a1074364 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2358,6 +2358,7 @@ class ProductRepository extends BaseRepository throw new ValidateException('商品规格导入出错'); } } + $product->stock = $stockIn + $product->stock; if ($orderProduct->is_imported == 0) { $attrValue->stock=$attrValue->stock + $stockIn; @@ -2377,6 +2378,8 @@ class ProductRepository extends BaseRepository throw new ValidateException('入库失败'); } $orderProduct->save(['is_imported' => 1]); + $attrValue->save(); + $product->save(); Db::commit(); return true; }else{ From 039e5bce9ac54798416c5a7ae7f30d1c8ca09106 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 17:17:13 +0800 Subject: [PATCH 10/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 2 +- app/controller/api/server/StoreProduct.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index a1074364..915f9660 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2348,7 +2348,7 @@ class ProductRepository extends BaseRepository //有商品无规格或者无商品无规格,导入商品和规格 $product = $this->getWhere(['source_product_id' => $params['order_product_id'], 'mer_id' => $merId]); if (!empty($product)) { - $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->find(); + $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('unique', $params['unique'])->find(); if (!empty($params['order_id'])) { //采购、委托订单导入 $orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id'); diff --git a/app/controller/api/server/StoreProduct.php b/app/controller/api/server/StoreProduct.php index acc64471..24ba3c60 100644 --- a/app/controller/api/server/StoreProduct.php +++ b/app/controller/api/server/StoreProduct.php @@ -239,11 +239,14 @@ class StoreProduct extends BaseController public function stockIn() { $params = $this->request->param(); + if($params['unique']==''){ + return app('json')->fail('多规格编号不能为空'); + } $res=$this->repository->stockIn($this->merId, $params); if($res){ return app('json')->success('入库成功'); }else{ - return app('json')->success('入库失败'); + return app('json')->fail('入库失败'); } } From f2dee282cc2e30789a5cb5a921d528c29619fbaf Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 17:28:13 +0800 Subject: [PATCH 11/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 915f9660..ae45c876 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2358,7 +2358,6 @@ class ProductRepository extends BaseRepository throw new ValidateException('商品规格导入出错'); } } - $product->stock = $stockIn + $product->stock; if ($orderProduct->is_imported == 0) { $attrValue->stock=$attrValue->stock + $stockIn; From 259481de46a5e7706be8f3860fa7006a9fcedb9b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 16 Nov 2023 19:16:10 +0800 Subject: [PATCH 12/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/event.php | 1 + app/listener/OrderTask.php | 147 +++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 app/listener/OrderTask.php diff --git a/app/event.php b/app/event.php index d63961fe..b6928bde 100644 --- a/app/event.php +++ b/app/event.php @@ -75,6 +75,7 @@ return [ 'refund.after'=>[\app\listener\AfterRefund::class], 'refund.deliver'=>[\app\listener\DeliverRefund::class], 'order.create'=>[\app\listener\OrderCreate::class], + 'order.task'=>[\app\listener\OrderTask::class], ], 'subscribe' => [], diff --git a/app/listener/OrderTask.php b/app/listener/OrderTask.php new file mode 100644 index 00000000..ea076675 --- /dev/null +++ b/app/listener/OrderTask.php @@ -0,0 +1,147 @@ +where('order_id', $order['order_id'])->where('is_refund', 'in', [0, 2])->field('product_id,product_sku,refund_num')->select(); + + foreach ($product_arr as $k => $v) { + $product_id = $this->import($v, $order); + + // app(ProductRepository::class)->create($find, 0); + } + // $productId = $this->import($params['order_product_id'], request()->userInfo()); + // $product = $this->get($productId); + // $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $productId)->find(); + } + } catch (\Exception $e) { + Log::error($e->getMessage() . 'lien:' . $e->getLine()); + } + } + + public function import($product, $order) + { + $mer_id = Db::name('store_service')->where('uid', $order['uid'])->where('status', 1)->value('mer_id'); + if ($mer_id == 0) { + Log::error('采购导入商品:商户不存在'); + return false; + } + $find = Db::name('store_product')->where('product_id', $product['product_id'])->find(); + if ($find) { + if (!in_array($find['product_type'], [0, 98])) { + Log::error('采购导入商品:不是普通商品'); + return false; + } + $exist = Db::name('store_product')->where('source_product_id', $product['product_id'])->where('mer_id', $mer_id)->find(); + if ($exist) { + $store_product_attr_value = Db::name('store_product_attr_value')->where('product_id', $exist['product_id'])->where('unique', $product['product_sku'])->find(); + if ($store_product_attr_value) { + Log::error('采购导入商品:已经导入过该商品了'); + return false; + } + $find['attrValue'] = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']]) + ->where('unique', $product['product_sku']) + ->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume,detail,sku') + ->withAttr('detail', function ($value) { + return empty($value) ? [] : json_decode($value, true); + }) + ->find(); + } else { + + $find['attrValue'] = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']]) + ->where('unique', $product['product_sku']) + ->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume,detail,sku') + ->withAttr('detail', function ($value) { + return empty($value) ? [] : json_decode($value, true); + }) + ->find(); + + $attr = Db::name('store_product_attr')->where('product_id', $find['product_id'])->field('attr_name,attr_values,type')->select(); + foreach ($attr as $item) { + $attr_values = explode('-!-', $item['attr_values']); + foreach ($attr_values as $value) { + if ($value == $find['attrValue']['sku']) { + $find['attr'][] = ['attr_name' => $item['attr_name'], 'detail' => $value]; + } + } + } + $find['attrValue']['stock'] = $product['refund_num']; + + $find['content'] = Db::name('store_product_content')->where('product_id', $find['product_id'])->value('content'); + $find['is_show'] = 0; + $find['mer_id'] = $mer_id; + $find['temp_id'] = ""; + $find['give_coupon_ids'] = []; + $find['params'] = []; + $find['extend'] = []; + $find['param_temp_id'] = []; + $find['mer_labels'] = []; + $find['delivery_way'] = [0 => "2"]; + $find["guarantee_template_id"] = ""; + $find['product_type'] = 0; + $find['mer_cate_id'] = [0 => 0]; + $find['is_used'] = 1; + $find['status'] = 1; + $find['mer_status'] = 1; + $find['source_product_id'] = $product['product_id']; + $find['slider_image'] = explode(',', $find['slider_image']); + unset($find['product_id'], $find['create_time']); + $productId = app(ProductRepository::class)->create($find, 0); + $data=['order_id'=>$order['order_id'],'order_product_id'=>$order['order_product_id'], + 'product_id'=>$productId,'number'=>$product['refund_num'],'order_unique'=>$product['product_sku'], + 'price'=> $find['attrValue']['price'],'supplierMerId'=> $order['mer_id'],'mer_id'=>$mer_id + ]; + $this->purchase_record($data); + } + } + } + + + public function purchase_record($data){ + $model = new PurchaseRecord(); + $data = [ + 'order_id' => $data['order_id'] ?? 0, + 'order_product_id' => $data['order_product_id'] ?? 0, + 'product_id' => $data['product_id'], + 'number' => $data['number'], + 'order_unique' => $data['order_unique'] ?? '', + 'unique' => $data['unique'], + 'price' => $data['price'], + 'mer_id' => $data['mer_id'], + 'supplier_mer_id' => $data['supplierMerId'], + ]; + $model->save($data); + } +} From 4a543633e336af98469e2da7d14d579cf0a1462a Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 17 Nov 2023 11:13:58 +0800 Subject: [PATCH 13/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=A4=9A=E8=A7=84?= =?UTF-8?q?=E6=A0=BC=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/event.php | 2 +- app/listener/{OrderTask.php => OrderTake.php} | 79 ++++++++++++++----- 2 files changed, 61 insertions(+), 20 deletions(-) rename app/listener/{OrderTask.php => OrderTake.php} (61%) diff --git a/app/event.php b/app/event.php index b6928bde..7ae53a8c 100644 --- a/app/event.php +++ b/app/event.php @@ -75,7 +75,7 @@ return [ 'refund.after'=>[\app\listener\AfterRefund::class], 'refund.deliver'=>[\app\listener\DeliverRefund::class], 'order.create'=>[\app\listener\OrderCreate::class], - 'order.task'=>[\app\listener\OrderTask::class], + 'order.take'=>[\app\listener\OrderTake::class], ], 'subscribe' => [], diff --git a/app/listener/OrderTask.php b/app/listener/OrderTake.php similarity index 61% rename from app/listener/OrderTask.php rename to app/listener/OrderTake.php index ea076675..ad18a354 100644 --- a/app/listener/OrderTask.php +++ b/app/listener/OrderTake.php @@ -15,11 +15,12 @@ use crmeb\utils\DingTalk; use think\facade\Db; use think\facade\Log; use app\common\model\store\product\PurchaseRecord; +use app\common\model\system\Extend; /** * 收货后的逻辑 */ -class OrderTask +class OrderTake { public $totalAmount; @@ -36,10 +37,9 @@ class OrderTask $order = $event['order']; if ($order['source'] == 200 && $order['activity_type'] == 98) { $product_arr = Db::name('store_order_product')->where('order_id', $order['order_id'])->where('is_refund', 'in', [0, 2])->field('product_id,product_sku,refund_num')->select(); - foreach ($product_arr as $k => $v) { - $product_id = $this->import($v, $order); - + $this->import($v, $order); + // app(ProductRepository::class)->create($find, 0); } // $productId = $this->import($params['order_product_id'], request()->userInfo()); @@ -58,26 +58,67 @@ class OrderTask Log::error('采购导入商品:商户不存在'); return false; } + /**原始商品数据 */ $find = Db::name('store_product')->where('product_id', $product['product_id'])->find(); if ($find) { if (!in_array($find['product_type'], [0, 98])) { Log::error('采购导入商品:不是普通商品'); return false; } + /**查询是否导入过该商品 */ $exist = Db::name('store_product')->where('source_product_id', $product['product_id'])->where('mer_id', $mer_id)->find(); if ($exist) { $store_product_attr_value = Db::name('store_product_attr_value')->where('product_id', $exist['product_id'])->where('unique', $product['product_sku'])->find(); if ($store_product_attr_value) { - Log::error('采购导入商品:已经导入过该商品了'); + Log::error('采购导入商品:已经导入过该规格了'); return false; } - $find['attrValue'] = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']]) + $attrValue = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']]) ->where('unique', $product['product_sku']) ->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume,detail,sku') ->withAttr('detail', function ($value) { return empty($value) ? [] : json_decode($value, true); }) ->find(); + $find['attr'] = []; + if ($attrValue['detail']) { + foreach ($attrValue['detail'] as $kk => $vv) { + + $attr_values = Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk) + ->value('attr_values'); + if ($attr_values) { + $attr_values = explode('-!-', $attr_values); + if (!in_array($vv, $attr_values)) { + $attr_values[] = $vv; + $attr_values = implode('-!-', $attr_values); + Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]); + } + } else { + $attr_values = $vv; + + Db::name('store_product_attr')->insert( + [ + 'product_id' => $exist['product_id'], + 'attr_name' => $kk, 'attr_values' => $attr_values + ] + ); + } + } + } + $attrValue['stock'] = $product['refund_num']; + $unique = app(ProductRepository::class)->setUnique($exist['product_id'], $attrValue['sku'], 0); + $attrValue['unique'] = $unique; + $attrValue['detail'] = json_encode($attrValue['detail']); + $attrValue['product_id'] = $exist['product_id']; + $attrValue['mer_id'] = $mer_id; + Db::name('store_product_attr_value')->insert($attrValue); + Db::name('store_product')->where('product_id',$exist['product_id'])->update(['stock'=>$product['refund_num']+$exist['stock']]); + $data = [ + 'order_id' => $order['order_id'], 'order_product_id' => $order['product_id'], + 'product_id' => $exist['product_id'], 'number' => $product['refund_num'], 'order_unique' => $product['product_sku'], + 'price' => $attrValue['price'], 'supplierMerId' => $order['mer_id'], 'mer_id' => $mer_id, 'unique' => $unique + ]; + $this->purchase_record($data); } else { $find['attrValue'] = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']]) @@ -88,15 +129,13 @@ class OrderTask }) ->find(); - $attr = Db::name('store_product_attr')->where('product_id', $find['product_id'])->field('attr_name,attr_values,type')->select(); - foreach ($attr as $item) { - $attr_values = explode('-!-', $item['attr_values']); - foreach ($attr_values as $value) { - if ($value == $find['attrValue']['sku']) { - $find['attr'][] = ['attr_name' => $item['attr_name'], 'detail' => $value]; - } + $find['attr'] = []; + if ($find['attrValue']['detail']) { + foreach ($find['attrValue']['detail'] as $kk => $vv) { + $find['attr'][] = ['attr_name' => $kk, 'detail' => $vv]; } } + $find['attrValue']['stock'] = $product['refund_num']; $find['content'] = Db::name('store_product_content')->where('product_id', $find['product_id'])->value('content'); @@ -119,17 +158,19 @@ class OrderTask $find['slider_image'] = explode(',', $find['slider_image']); unset($find['product_id'], $find['create_time']); $productId = app(ProductRepository::class)->create($find, 0); - $data=['order_id'=>$order['order_id'],'order_product_id'=>$order['order_product_id'], - 'product_id'=>$productId,'number'=>$product['refund_num'],'order_unique'=>$product['product_sku'], - 'price'=> $find['attrValue']['price'],'supplierMerId'=> $order['mer_id'],'mer_id'=>$mer_id - ]; + $data = [ + 'order_id' => $order['order_id'], 'order_product_id' => $order['product_id'], + 'product_id' => $productId, 'number' => $product['refund_num'], 'order_unique' => $product['product_sku'], + 'price' => $find['attrValue']['price'], 'supplierMerId' => $order['mer_id'], 'mer_id' => $mer_id + ]; $this->purchase_record($data); } } } - public function purchase_record($data){ + public function purchase_record($data) + { $model = new PurchaseRecord(); $data = [ 'order_id' => $data['order_id'] ?? 0, @@ -137,7 +178,7 @@ class OrderTask 'product_id' => $data['product_id'], 'number' => $data['number'], 'order_unique' => $data['order_unique'] ?? '', - 'unique' => $data['unique'], + 'unique' => $data['unique'] ?? '', 'price' => $data['price'], 'mer_id' => $data['mer_id'], 'supplier_mer_id' => $data['supplierMerId'], From 15715e717c88f09a1875378955761e13cc45d539 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 17 Nov 2023 13:51:45 +0800 Subject: [PATCH 14/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/merchant/MerchantIntention.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controller/api/store/merchant/MerchantIntention.php b/app/controller/api/store/merchant/MerchantIntention.php index 11f92c99..8b84a2a4 100644 --- a/app/controller/api/store/merchant/MerchantIntention.php +++ b/app/controller/api/store/merchant/MerchantIntention.php @@ -203,7 +203,9 @@ class MerchantIntention extends BaseController 'bank_back' => $data['bank_back'] ?? '', 'cardno_front' => $data['cardno_front'] ?? '', 'cardno_back' => $data['cardno_back'] ?? '', - 'mer_intention_id' => $intentionId + 'mer_intention_id' => $intentionId, + 'type_id'=>$data['mer_type_id']??'' + ]; $postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant'; $res = $this->sendMerIntentionApply($sendData, $postUrl); @@ -297,7 +299,9 @@ class MerchantIntention extends BaseController 'area' => $data['area_id'] ?? '', 'street' => $data['street_id'] ?? '', 'address' => $data['address'] ?? '', - 'mer_intention_id' => $id + 'mer_intention_id' => $id, + 'type_id'=>$data['mer_type_id']??'' + ]; $postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant'; $res = $this->sendMerIntentionApply($sendData, $postUrl); From 44f915df67e56e33dc32d51a05a25782264f4620 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 17 Nov 2023 18:01:25 +0800 Subject: [PATCH 15/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index ae45c876..fddaa417 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -779,6 +779,12 @@ class ProductRepository extends BaseRepository } unset($data['content']); $data['content'] = $content; + // $attr = $this->detailAttr($data['attr']); + $attrValue =$data['attrValue']; + + $sku = $this->detailAttrValue($attrValue, null, $data['product_type'], null); + $data['sku'] = $sku; + return $data; } From ee6829fd1883c731e573a68d60d2c0646a1fe0d9 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 17 Nov 2023 18:40:35 +0800 Subject: [PATCH 16/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/merchant/MerchantIntention.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/store/merchant/MerchantIntention.php b/app/controller/api/store/merchant/MerchantIntention.php index 8b84a2a4..86f321a8 100644 --- a/app/controller/api/store/merchant/MerchantIntention.php +++ b/app/controller/api/store/merchant/MerchantIntention.php @@ -204,7 +204,7 @@ class MerchantIntention extends BaseController 'cardno_front' => $data['cardno_front'] ?? '', 'cardno_back' => $data['cardno_back'] ?? '', 'mer_intention_id' => $intentionId, - 'type_id'=>$data['mer_type_id']??'' + 'type_id'=>$merInfo['type_id']??'' ]; $postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant'; From 637047894ef79b766844ca60567d32047461c9c1 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 18 Nov 2023 13:42:08 +0800 Subject: [PATCH 17/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/SpuRepository.php | 2 +- app/listener/OrderTake.php | 38 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index f77195f7..27c9918c 100644 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -90,7 +90,7 @@ class SpuRepository extends BaseRepository 'keyword' => $param['keyword'] ?? '', 'image' => $param['image'], 'price' => $param['price'], - 'status' => 0, + 'status' => $param['status']??0, 'rank' => $param['rank'] ?? 0, 'temp_id' => $param['temp_id'], 'sort' => $param['sort'] ?? 0, diff --git a/app/listener/OrderTake.php b/app/listener/OrderTake.php index ad18a354..7fafc292 100644 --- a/app/listener/OrderTake.php +++ b/app/listener/OrderTake.php @@ -39,12 +39,7 @@ class OrderTake $product_arr = Db::name('store_order_product')->where('order_id', $order['order_id'])->where('is_refund', 'in', [0, 2])->field('product_id,product_sku,refund_num')->select(); foreach ($product_arr as $k => $v) { $this->import($v, $order); - - // app(ProductRepository::class)->create($find, 0); } - // $productId = $this->import($params['order_product_id'], request()->userInfo()); - // $product = $this->get($productId); - // $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $productId)->find(); } } catch (\Exception $e) { Log::error($e->getMessage() . 'lien:' . $e->getLine()); @@ -73,6 +68,7 @@ class OrderTake Log::error('采购导入商品:已经导入过该规格了'); return false; } + /**查询原始商品的规格 */ $attrValue = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']]) ->where('unique', $product['product_sku']) ->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume,detail,sku') @@ -81,18 +77,21 @@ class OrderTake }) ->find(); $find['attr'] = []; + $is_update=false; if ($attrValue['detail']) { foreach ($attrValue['detail'] as $kk => $vv) { - - $attr_values = Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk) - ->value('attr_values'); - if ($attr_values) { + /**查询当前规格是否存在 */ + $attr_values_find = Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk) + ->find(); + if ($attr_values_find) { + $attr_values= $attr_values_find['attr_values']; $attr_values = explode('-!-', $attr_values); if (!in_array($vv, $attr_values)) { $attr_values[] = $vv; $attr_values = implode('-!-', $attr_values); Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]); } + $is_update=true; } else { $attr_values = $vv; @@ -105,13 +104,20 @@ class OrderTake } } } - $attrValue['stock'] = $product['refund_num']; - $unique = app(ProductRepository::class)->setUnique($exist['product_id'], $attrValue['sku'], 0); - $attrValue['unique'] = $unique; - $attrValue['detail'] = json_encode($attrValue['detail']); - $attrValue['product_id'] = $exist['product_id']; - $attrValue['mer_id'] = $mer_id; - Db::name('store_product_attr_value')->insert($attrValue); + /**规格新增还是更新 */ + if($is_update==false){ + $attrValue['stock'] = $product['refund_num']; + $unique = app(ProductRepository::class)->setUnique($exist['product_id'], $attrValue['sku'], 0); + $attrValue['unique'] = $unique; + $attrValue['detail'] = json_encode($attrValue['detail']); + $attrValue['product_id'] = $exist['product_id']; + $attrValue['mer_id'] = $mer_id; + Db::name('store_product_attr_value')->insert($attrValue); + }else{ + Db::name('store_product_attr_value')->where(['unique'=>$attr_values_find['unique'],'product_id', + $attr_values_find['product_id'],'mer_id'=>$mer_id,])->update(['stock'=>$product['refund_num']+$attr_values_find['stock']]); + } + Db::name('store_product')->where('product_id',$exist['product_id'])->update(['stock'=>$product['refund_num']+$exist['stock']]); $data = [ 'order_id' => $order['order_id'], 'order_product_id' => $order['product_id'], From f363de8995890fd5178516156238638df7b0aa4f Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 20 Nov 2023 10:35:27 +0800 Subject: [PATCH 18/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A7=8D=E5=85=BB?= =?UTF-8?q?=E6=AE=96=E6=88=B7=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Statistics.php | 63 ++++++++++++++++++++++++------- route/api.php | 1 + 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/app/controller/api/Statistics.php b/app/controller/api/Statistics.php index e94d16d3..85f6bbb1 100644 --- a/app/controller/api/Statistics.php +++ b/app/controller/api/Statistics.php @@ -109,11 +109,11 @@ class Statistics extends BaseController if (isset($parmas['keyword']) && $parmas['keyword'] != '') { $where[] = ['store_name', 'like', '%' . $parmas['keyword'] . '%']; } - $count=Db::name('store_product')->where($where)->count(); + $count = Db::name('store_product')->where($where)->count(); $list = Db::name('store_product')->where($where)->page($parmas['page']) ->field('product_id,store_name,image,price') ->limit(10)->select(); - return app('json')->success(['page' => $parmas['page'], 'data' => $list,'count'=>$count]); + return app('json')->success(['page' => $parmas['page'], 'data' => $list, 'count' => $count]); } /** @@ -149,7 +149,7 @@ class Statistics extends BaseController if (!isset($parmas['goods_id']) || $parmas['goods_id'] == '') { return app('json')->fail('goods_id:格式错误'); } - $mer_id=Db::name('merchant_intention')->where('mer_intention_id', $parmas['mer_intention_id'])->value('mer_id'); + $mer_id = Db::name('merchant_intention')->where('mer_intention_id', $parmas['mer_intention_id'])->value('mer_id'); $where[] = ['p.create_time', 'between time', [date("Y-m-d H:i:s", $parmas['start_time']), date("Y-m-d H:i:s", $parmas['end_time'])]]; $where[] = ['p.product_id', 'in', explode(',', $parmas['goods_id'])]; $where[] = ['p.is_refund', '=', 0]; @@ -231,7 +231,7 @@ class Statistics extends BaseController // return app('json')->fail('type:格式错误'); // } $area[] = ['street_id', 'in', explode(',', $parmas['responsible_area'])]; - $area[] = ['type_id', '=',17]; + $area[] = ['type_id', '=', 17]; $merchant = Db::name('merchant')->where($area)->column('mer_id'); if (!$merchant) { @@ -262,17 +262,52 @@ class Statistics extends BaseController if (!isset($parmas['phone']) || $parmas['phone'] == '') { return app('json')->fail('phone:格式错误'); } - $user_id= Db::name('user')->where('account',$parmas['phone'])->value('uid'); - if(!$user_id){ + $user_id = Db::name('user')->where('account', $parmas['phone'])->value('uid'); + if (!$user_id) { return app('json')->fail('查询的手机号用户不存在'); } - $where[]=['create_time','between time',[date("Y-m-d H:i:s",$parmas['start_time']),date("Y-m-d H:i:s",$parmas['end_time'])]]; - $where[]=['paid','=',1]; - $where[]=['status','<>',-1]; - $where[]=['uid','=',$user_id]; - $count=Db::name('store_order') - ->where($where) - ->sum('pay_price'); - return app('json')->success(['trade_amount'=>$count]); + $where[] = ['create_time', 'between time', [date("Y-m-d H:i:s", $parmas['start_time']), date("Y-m-d H:i:s", $parmas['end_time'])]]; + $where[] = ['paid', '=', 1]; + $where[] = ['status', '<>', -1]; + $where[] = ['uid', '=', $user_id]; + $count = Db::name('store_order') + ->where($where) + ->sum('pay_price'); + return app('json')->success(['trade_amount' => $count]); + } + + /** + * 查询镇农科公司负责片区内的种养殖商户和供应链商户交易额 + *暂无种养殖商户分类 + */ + public function SupplyChainVillageBreedingPriceCount() + { + $parmas = $this->request->param(); + + if (!isset($parmas['start_time']) || $parmas['start_time'] == '') { + return app('json')->fail('start_time:格式错误'); } + if (!isset($parmas['end_time']) || $parmas['end_time'] == '') { + return app('json')->fail('end_time:格式错误'); + } + if (!isset($parmas['village']) || $parmas['village'] == '') { + return app('json')->fail('village:格式错误'); + } + $village_id = Db::name('geo_village')->where('village_code', $parmas['village'])->value('village_id'); + $merchant_category_id = Db::name('merchant_category')->where('code', 'zhongyangzhi')->value('merchant_category_id'); + $area[] = ['village_id', '=', $village_id]; + $area[] = ['category_id', '=', $merchant_category_id]; + + $merchant = Db::name('merchant')->where($area)->column('mer_id'); + if (!$merchant) { + return app('json')->fail('查询商户为空'); + } + $where[] = ['p.create_time', 'between time', [date("Y-m-d H:i:s", $parmas['start_time']), date("Y-m-d H:i:s", $parmas['end_time'])]]; + $where[] = ['p.is_refund', '=', 0]; + $count = Db::name('store_order_product')->alias('p') + ->where($where) + ->join('store_order o', 'o.mer_id in (' . implode(',', $merchant) . ') and o.paid=1 and o.is_del=0') + ->sum('p.total_price'); + return app('json')->success(['trade_amount' => $count]); + } } diff --git a/route/api.php b/route/api.php index e47ccf46..8856b174 100644 --- a/route/api.php +++ b/route/api.php @@ -704,6 +704,7 @@ Route::group('api/', function () { Route::get('supply_chain_product_price_count', '/SupplyChainProductPriceCount'); Route::get('supply_chain_street_product_price_count', '/SupplyChainStreetProductPriceCount'); Route::get('supply_chain_breeding_street_product_count', '/SupplyChainBreedingStreetProductCount'); + Route::get('supply_chain_village_breeding_price_count', '/SupplyChainVillageBreedingPriceCount'); Route::get('store_order_user_trade_amount', '/StoreOrderUserTradeAmount'); })->prefix('api.Statistics'); From ee92e1f33c1d599be8473be22a9d297454dd0424 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 20 Nov 2023 13:42:46 +0800 Subject: [PATCH 19/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/system/merchant/Merchant.php | 3 +- app/controller/api/server/StoreProduct.php | 50 ++++++++++--------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/app/controller/admin/system/merchant/Merchant.php b/app/controller/admin/system/merchant/Merchant.php index 96facf9f..aadfd407 100644 --- a/app/controller/admin/system/merchant/Merchant.php +++ b/app/controller/admin/system/merchant/Merchant.php @@ -244,7 +244,8 @@ class Merchant extends BaseController if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); $admins=$this->request->adminInfo(); - if($admins['admin_id']!=1){ + $admin_arr=explode(',',env('MERCHANT_Arr')); + if($admins['admin_id']!=1 && !in_array($admins['roles'],$admin_arr)){ $adminInfo = $adminRepository->merIdByAdmin($id,['account'=>'yy'.$admins['account']],2); if(!$adminInfo){ $pwd =password_hash(rand(100000,999999), PASSWORD_BCRYPT); diff --git a/app/controller/api/server/StoreProduct.php b/app/controller/api/server/StoreProduct.php index 24ba3c60..8c2871d7 100644 --- a/app/controller/api/server/StoreProduct.php +++ b/app/controller/api/server/StoreProduct.php @@ -58,14 +58,14 @@ class StoreProduct extends BaseController public function lst($merId) { [$page, $limit] = $this->getPage(); - $where = $this->request->params(['cate_id', 'keyword', ['type',20], 'mer_cate_id', 'is_gift_bag', 'status', 'us_status', 'product_id', 'mer_labels',['order','sort']]); + $where = $this->request->params(['cate_id', 'keyword', ['type', 20], 'mer_cate_id', 'is_gift_bag', 'status', 'us_status', 'product_id', 'mer_labels', ['order', 'sort']]); $merchant = app()->make(MerchantRepository::class)->get($merId); - $typeCode=Db::name('merchant_type')->where('mer_type_id',$merchant['type_id'])->value('type_code'); + $typeCode = Db::name('merchant_type')->where('mer_type_id', $merchant['type_id'])->value('type_code'); // if ($merchant['type_id']==12){ - if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){ - $product_type=98;//供应链 - }else{ - $product_type=0;//普通商品 + if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) { + $product_type = 98; //供应链 + } else { + $product_type = 0; //普通商品 } $where = array_merge($where, $this->repository->switchType($where['type'], $merId, $product_type)); return app('json')->success($this->repository->getList($merId, $where, $page, $limit)); @@ -82,21 +82,26 @@ class StoreProduct extends BaseController public function create($merId, StoreProductValidate $validate) { $res = $this->request->params($this->repository::CREATE_PARAMS); - $data = $this->repository->checkParams($res,$merId); + $data = $this->repository->checkParams($res, $merId); $data['mer_id'] = $merId; $data['is_gift_bag'] = 0; $merchant = app()->make(MerchantRepository::class)->get($merId); $data['status'] = $merchant->is_audit ? 0 : 1; $data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1; $data['rate'] = 3; - $typeCode=Db::name('merchant_type')->where('mer_type_id',$merchant['type_id'])->value('type_code'); - if ($merchant['type_id']==12){ - if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){ - $product_type=98;//供应链 - }else{ - $product_type=0;//普通商品 + $typeCode = Db::name('merchant_type')->where('mer_type_id', $merchant['type_id'])->value('type_code'); + $product_type = 0; //普通商品 + if ($merchant['type_id'] == 12) { + if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) { + $product_type = 98; //供应链 + } } $productId = $this->repository->create($data, $product_type, 1); + if ($productId) { + return app('json')->success('添加成功'); + } else { + return app('json')->fail('添加失败'); + } // $unique = Db::name('store_product_attr_value')->where('product_id', $productId)->value('unique'); // if (!empty($unique) && $stockNum > 0) { // $this->repository->stockIn($merId, [ @@ -104,8 +109,6 @@ class StoreProduct extends BaseController // 'unique' => $unique, // 'number' => $stockNum, // ]); - } - return app('json')->success('添加成功'); } /** @@ -120,7 +123,7 @@ class StoreProduct extends BaseController public function update($merId, $id, StoreProductValidate $validate) { $res = $this->request->params($this->repository::CREATE_PARAMS); - $data = $this->repository->checkParams($res,$merId,$id); + $data = $this->repository->checkParams($res, $merId, $id); $merchant = app()->make(MerchantRepository::class)->get($merId); if (!$this->repository->merExists($merId, $id)) @@ -167,7 +170,7 @@ class StoreProduct extends BaseController $status = $this->request->param('status', 0) == 1 ? 1 : 0; if (!$this->repository->merExists($merId, $id)) return app('json')->fail('数据不存在'); - $this->repository->switchShow($id,$status, 'is_show',$merId); + $this->repository->switchShow($id, $status, 'is_show', $merId); return app('json')->success('修改成功'); } @@ -194,9 +197,9 @@ class StoreProduct extends BaseController $data['extension_status'] = systemConfig('extension_status'); $data['integral_status'] = 0; $data['integral_rate'] = 0; - if(systemConfig('integral_status') && merchantConfig($merId,'mer_integral_status')) { + if (systemConfig('integral_status') && merchantConfig($merId, 'mer_integral_status')) { $data['integral_status'] = 1; - $data['integral_rate'] = merchantConfig($merId,'mer_integral_rate'); + $data['integral_rate'] = merchantConfig($merId, 'mer_integral_rate'); } $merchant = app()->make(MerchantRepository::class)->get($merId); $data['delivery_way'] = $merchant->delivery_way; @@ -239,15 +242,14 @@ class StoreProduct extends BaseController public function stockIn() { $params = $this->request->param(); - if($params['unique']==''){ + if ($params['unique'] == '') { return app('json')->fail('多规格编号不能为空'); } - $res=$this->repository->stockIn($this->merId, $params); - if($res){ + $res = $this->repository->stockIn($this->merId, $params); + if ($res) { return app('json')->success('入库成功'); - }else{ + } else { return app('json')->fail('入库失败'); } } - } From fbb25484a3ef149e43953f521e4b5f5e6ae6787c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 20 Nov 2023 15:23:30 +0800 Subject: [PATCH 20/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/system/merchant/Merchant.php | 8 +++++++- app/controller/api/Statistics.php | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controller/admin/system/merchant/Merchant.php b/app/controller/admin/system/merchant/Merchant.php index aadfd407..4b79b5cd 100644 --- a/app/controller/admin/system/merchant/Merchant.php +++ b/app/controller/admin/system/merchant/Merchant.php @@ -245,7 +245,13 @@ class Merchant extends BaseController return app('json')->fail('数据不存在'); $admins=$this->request->adminInfo(); $admin_arr=explode(',',env('MERCHANT_Arr')); - if($admins['admin_id']!=1 && !in_array($admins['roles'],$admin_arr)){ + $is_true=false; + foreach ($admins['roles'] as $k=>$v){ + if(in_array($v,$admin_arr)){ + $is_true=true; + } + } + if($admins['admin_id']!=1 && $is_true==false){ $adminInfo = $adminRepository->merIdByAdmin($id,['account'=>'yy'.$admins['account']],2); if(!$adminInfo){ $pwd =password_hash(rand(100000,999999), PASSWORD_BCRYPT); diff --git a/app/controller/api/Statistics.php b/app/controller/api/Statistics.php index 85f6bbb1..b4dcca17 100644 --- a/app/controller/api/Statistics.php +++ b/app/controller/api/Statistics.php @@ -262,7 +262,8 @@ class Statistics extends BaseController if (!isset($parmas['phone']) || $parmas['phone'] == '') { return app('json')->fail('phone:格式错误'); } - $user_id = Db::name('user')->where('account', $parmas['phone'])->value('uid'); + $account[] = ['account', 'in', explode(',', $parmas['phone'])]; + $user_id = Db::name('user')->where($account)->value('uid'); if (!$user_id) { return app('json')->fail('查询的手机号用户不存在'); } From c0907dbeade2a964283516092c1aa24a766fb14d Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 20 Nov 2023 15:24:42 +0800 Subject: [PATCH 21/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/server/StoreProduct.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controller/api/server/StoreProduct.php b/app/controller/api/server/StoreProduct.php index 8c2871d7..f210075a 100644 --- a/app/controller/api/server/StoreProduct.php +++ b/app/controller/api/server/StoreProduct.php @@ -138,8 +138,12 @@ class StoreProduct extends BaseController $data['mer_id'] = $merId; $typeSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeSupplyChain'])->value('mer_type_id'); $productType = $merchant->type_id == $typeSupplyChainId ? 98 : 0; - $this->repository->edit($id, $data, $merId, $productType, 1); - return app('json')->success('编辑成功'); + $product=$this->repository->edit($id, $data, $merId, $productType, 1); + if ($product) { + return app('json')->success('编辑成功'); + } else { + return app('json')->fail('编辑失败'); + } } /**