From 0d744027c9d8f3cf81de6344f17633cf538343ef Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Sat, 23 Dec 2023 15:20:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=A0=87=E7=AD=BE=E5=95=86?= =?UTF-8?q?=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 45 +++++- app/controller/api/server/StoreProduct.php | 30 ++++ .../merchant/store/product/Product.php | 148 +++++++++++------- route/api.php | 3 +- route/merchant/product.php | 6 + 5 files changed, 166 insertions(+), 66 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 26a8391e..d584372e 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -541,7 +541,7 @@ class ProductRepository extends BaseRepository { $result = []; foreach ($data as $value) { - if (is_int($value)||$value['category']) { + if (is_int($value) || $value['category']) { $result[] = [ 'product_id' => $productId, 'mer_cate_id' => $value, @@ -1939,13 +1939,13 @@ class ProductRepository extends BaseRepository } else { //加入购物车 //购物车现有 - $_num = $this->productOnceCountCart($where['product_id'], $data['product_attr_unique'], $userInfo->uid, $data['product_type'],$data['source']); + $_num = $this->productOnceCountCart($where['product_id'], $data['product_attr_unique'], $userInfo->uid, $data['product_type'], $data['source']); $cart_num = $_num + $data['cart_num']; } 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'],$data['source']); + $cart = app()->make(StoreCartRepository::class)->getCartByProductSku($data['product_attr_unique'], $userInfo->uid, $data['product_type'], $data['source']); } return compact('product', 'sku', 'cart'); } @@ -1958,7 +1958,7 @@ class ProductRepository extends BaseRepository * @author Qinii * @day 5/26/21 */ - public function productOnceCountCart($productId, $product_attr_unique, $uid, $product_type = 0,$source=0) + public function productOnceCountCart($productId, $product_attr_unique, $uid, $product_type = 0, $source = 0) { $make = app()->make(StoreCartRepository::class); $where = [ @@ -1970,7 +1970,7 @@ class ProductRepository extends BaseRepository 'product_id' => $productId, 'uid' => $uid, 'product_attr_unique' => $product_attr_unique, - 'source'=>$source + 'source' => $source ]; $cart_num = $make->getSearch($where)->sum('cart_num'); return $cart_num; @@ -2575,4 +2575,39 @@ class ProductRepository extends BaseRepository ); return compact('count', 'list'); } + + /** + * 添加商品到云市场 + */ + public function add_cloud_product($data, $merchant) + { + if ($data['is_del'] == 1) { + return Db::name('cloud_product')->where('product_id', $data['product_id'])->delete(); + } + if ($data['product_id'] && $data['type']) { + switch ($data['type']) { + case 'two': + $data['type'] = 6; + break; + case 'three': + $data['mer_id'] = 7; + case 'seven': + $data['type'] = 8; + } + $datas = [ + 'product_id' => $data['product_id'], + 'mer_id' => $merchant['mer_id'], + 'source_mer_id' => 0, + 'street_code' => $merchant['street_id'], + 'type_id' => $merchant['type_id'], + 'category_id' => $merchant['category_id'], + 'weight' => 1, + 'status' => 1, + 'create_time' => date('Y-m-d H:i:s'), + 'mer_labels' => ',' . $data['type'] . ',', + ]; + return Db::name('cloud_product')->insert($datas); + } + return false; + } } diff --git a/app/controller/api/server/StoreProduct.php b/app/controller/api/server/StoreProduct.php index f210075a..77701c93 100644 --- a/app/controller/api/server/StoreProduct.php +++ b/app/controller/api/server/StoreProduct.php @@ -256,4 +256,34 @@ class StoreProduct extends BaseController return app('json')->fail('入库失败'); } } + + + + /** + * 商户添加商品到云仓 + */ + public function add_cloud_product() + { + $data = $this->request->params(['product_id', 'type', 'is_del']); + $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $this->merId,])->find(); + $res = $this->repository->add_cloud_product($data, $merchant); + if ($res) { + return app('json')->success('设置成功'); + } else { + return app('json')->fail('设置失败'); + } + } + + + /** + * 云仓商品列表 + */ + public function cloud_product_list(){ + [$page, $limit] = $this->getPage(); + $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $this->merId,])->find(); + $select=Db::name('store_product_cloud')->where('mer_id',$merchant['mer_id']) + ->page($page)->limit($limit)->select()->toArray(); + $count = Db::name('store_product_cloud')->where('mer_id',$merchant['mer_id'])->count(); + return app('json')->success(['list'=>$select,'count'=>$count]); + } } diff --git a/app/controller/merchant/store/product/Product.php b/app/controller/merchant/store/product/Product.php index 294ee9f5..bd50b45d 100644 --- a/app/controller/merchant/store/product/Product.php +++ b/app/controller/merchant/store/product/Product.php @@ -29,14 +29,14 @@ use think\facade\Db; class Product extends BaseController { - protected $repository ; + protected $repository; /** * Product constructor. * @param App $app * @param repository $repository */ - public function __construct(App $app ,repository $repository) + public function __construct(App $app, repository $repository) { parent::__construct($app); $this->repository = $repository; @@ -50,17 +50,17 @@ class Product extends BaseController public function lst() { [$page, $limit] = $this->getPage(); - $where = $this->request->params(['temp_id','cate_id','keyword',['type',1],'mer_cate_id','is_gift_bag','status','us_status','product_id','mer_labels',['order','sort'],'is_ficti','svip_price_type']); - $where = array_merge($where,$this->repository->switchType($where['type'],$this->request->merId(),0)); - $type=$this->request->merchant()['type_id']; - $typeCode=Db::name('merchant_type')->where('mer_type_id',$type)->value('type_code'); - $product_type=0; + $where = $this->request->params(['temp_id', 'cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'is_gift_bag', 'status', 'us_status', 'product_id', 'mer_labels', ['order', 'sort'], 'is_ficti', 'svip_price_type']); + $where = array_merge($where, $this->repository->switchType($where['type'], $this->request->merId(), 0)); + $type = $this->request->merchant()['type_id']; + $typeCode = Db::name('merchant_type')->where('mer_type_id', $type)->value('type_code'); + $product_type = 0; // if ($type==12){ - if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){ - $where['product_type']=98;//供应链 + if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) { + $where['product_type'] = 98; //供应链 } - return app('json')->success($this->repository->getList($this->request->merId(),$where, $page, $limit)); + return app('json')->success($this->repository->getList($this->request->merId(), $where, $page, $limit)); } /** @@ -71,9 +71,9 @@ class Product extends BaseController */ public function detail($id) { - if(!$this->repository->merExists($this->request->merId(),$id)) + if (!$this->repository->merExists($this->request->merId(), $id)) return app('json')->fail('数据不存在'); - return app('json')->success($this->repository->getAdminOneProduct($id,null)); + return app('json')->success($this->repository->getAdminOneProduct($id, null)); } /** @@ -85,7 +85,7 @@ class Product extends BaseController public function create() { $params = $this->request->params($this->repository::CREATE_PARAMS); - $data = $this->repository->checkParams($params,$this->request->merId()); + $data = $this->repository->checkParams($params, $this->request->merId()); // $cate_id=StoreCategory::where('pid',$data['cate_id'])->where('level',2)->value('store_category_id'); // if(!$cate_id){ // return app('json')->fail('请先添加第三级分类'); @@ -97,15 +97,15 @@ class Product extends BaseController $data['status'] = $this->request->merchant()->is_audit ? 0 : 1; $data['mer_status'] = ($this->request->merchant()->is_del || !$this->request->merchant()->mer_state || !$this->request->merchant()->status) ? 0 : 1; $data['rate'] = 3; - $typeCode=Db::name('merchant_type')->where('mer_type_id',$this->request->merchant()->type_id)->value('type_code'); + $typeCode = Db::name('merchant_type')->where('mer_type_id', $this->request->merchant()->type_id)->value('type_code'); // if ($this->request->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; //普通商品 } $data['update_time'] = date('Y-m-d H:i:s'); - $this->repository->create($data,$product_type,1); + $this->repository->create($data, $product_type, 1); return app('json')->success('添加成功'); } @@ -119,7 +119,7 @@ class Product extends BaseController public function update($id) { $params = $this->request->params($this->repository::CREATE_PARAMS); - $data = $this->repository->checkParams($params,$this->request->merId(), $id); + $data = $this->repository->checkParams($params, $this->request->merId(), $id); if (!$this->repository->merExists($this->request->merId(), $id)) return app('json')->fail('数据不存在'); $pro = $this->repository->getWhere(['product_id' => $id]); @@ -133,7 +133,7 @@ class Product extends BaseController $data['update_time'] = date('Y-m-d H:i:s'); $typeSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeSupplyChain'])->value('mer_type_id'); $productType = $this->request->merchant()->type_id == $typeSupplyChainId ? 98 : 0; - $this->repository->edit($id, $data, $this->request->merId(), $productType,1); + $this->repository->edit($id, $data, $this->request->merId(), $productType, 1); return app('json')->success('编辑成功'); } @@ -145,9 +145,9 @@ class Product extends BaseController */ public function delete($id) { - if(!$this->repository->merExists($this->request->merId(),$id)) + if (!$this->repository->merExists($this->request->merId(), $id)) return app('json')->fail('数据不存在'); - if($this->repository->getWhereCount(['product_id' => $id,'is_show' => 1,'status' => 1])) + if ($this->repository->getWhereCount(['product_id' => $id, 'is_show' => 1, 'status' => 1])) return app('json')->fail('商品上架中'); $this->repository->delete($id); //queue(ChangeSpuStatusJob::class,['product_type' => 0,'id' => $id]); @@ -157,9 +157,9 @@ class Product extends BaseController public function destory($id) { - if(!$this->repository->merDeleteExists($this->request->merId(),$id)) + if (!$this->repository->merDeleteExists($this->request->merId(), $id)) return app('json')->fail('只能删除回收站的商品'); - if(app()->make(StoreCartRepository::class)->getProductById($id)) + if (app()->make(StoreCartRepository::class)->getProductById($id)) return app('json')->fail('商品有被加入购物车不可删除'); $this->repository->destory($id); return app('json')->success('删除成功'); @@ -174,14 +174,14 @@ class Product extends BaseController */ public function getStatusFilter() { - $type=$this->request->merchant()['type_id']; - $product_type=0; - $typeCode=Db::name('merchant_type')->where('mer_type_id',$type)->value('type_code'); + $type = $this->request->merchant()['type_id']; + $product_type = 0; + $typeCode = Db::name('merchant_type')->where('mer_type_id', $type)->value('type_code'); // if ($type==12){ - if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){ - $product_type=98;//供应链 + if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) { + $product_type = 98; //供应链 } - return app('json')->success($this->repository->getFilter($this->request->merId(),'商品',$product_type)); + return app('json')->success($this->repository->getFilter($this->request->merId(), '商品', $product_type)); } /** @@ -192,10 +192,10 @@ class Product extends BaseController */ public function config() { - $data = systemConfig(['extension_status','svip_switch_status','integral_status']); - $merData= merchantConfig($this->request->merId(),['mer_integral_status','mer_integral_rate','mer_svip_status','svip_store_rate']); - $svip_store_rate = $merData['svip_store_rate'] > 0 ? bcdiv($merData['svip_store_rate'],100,2) : 0; - $data['mer_svip_status'] = ($data['svip_switch_status'] && $merData['mer_svip_status'] != 0 ) ? 1 : 0; + $data = systemConfig(['extension_status', 'svip_switch_status', 'integral_status']); + $merData = merchantConfig($this->request->merId(), ['mer_integral_status', 'mer_integral_rate', 'mer_svip_status', 'svip_store_rate']); + $svip_store_rate = $merData['svip_store_rate'] > 0 ? bcdiv($merData['svip_store_rate'], 100, 2) : 0; + $data['mer_svip_status'] = ($data['svip_switch_status'] && $merData['mer_svip_status'] != 0) ? 1 : 0; $data['svip_store_rate'] = $svip_store_rate; $data['integral_status'] = $data['integral_status'] && $merData['mer_integral_status'] ? 1 : 0; $data['integral_rate'] = $merData['mer_integral_rate'] ?: 0; @@ -213,7 +213,7 @@ class Product extends BaseController */ public function restore($id) { - if(!$this->repository->merDeleteExists($this->request->merId(),$id)) + if (!$this->repository->merDeleteExists($this->request->merId(), $id)) return app('json')->fail('只能恢复回收站的商品'); $this->repository->restore($id); return app('json')->success('商品已恢复'); @@ -235,7 +235,7 @@ class Product extends BaseController public function updateSort($id) { $sort = $this->request->param('sort'); - $this->repository->updateSort($id,$this->request->merId(),['sort' => $sort]); + $this->repository->updateSort($id, $this->request->merId(), ['sort' => $sort]); return app('json')->success('修改成功'); } @@ -265,7 +265,7 @@ class Product extends BaseController public function setLabels($id) { $data = $this->request->params(['mer_labels']); - app()->make(SpuRepository::class)->setLabels($id,0,$data,$this->request->merId()); + app()->make(SpuRepository::class)->setLabels($id, 0, $data, $this->request->merId()); return app('json')->success('修改成功'); } @@ -279,7 +279,7 @@ class Product extends BaseController { $params = [ "mer_cate_id", - "sort" , + "sort", "is_show", "is_good", "attr", @@ -291,12 +291,12 @@ class Product extends BaseController // $count = app()->make(StoreCategoryRepository::class)->getWhereCount(['store_category_id' => $data['mer_cate_id'],'is_show' => 1,'mer_id' => $this->request->merId()]); // if (!$count) throw new ValidateException('商户分类不存在或不可用'); $data['status'] = 1; - $res=$this->repository->freeTrial($id, $data,$this->request->merId()); - if($res && $params['is_stock']==1){ - $arr=[ - 'mer_id'=>$this->request->merId(), - 'product_id'=>$data['attrValue'][0]['product_id'], - 'create_time'=>date('Y-m-d H:i:s') + $res = $this->repository->freeTrial($id, $data, $this->request->merId()); + if ($res && $params['is_stock'] == 1) { + $arr = [ + 'mer_id' => $this->request->merId(), + 'product_id' => $data['attrValue'][0]['product_id'], + 'create_time' => date('Y-m-d H:i:s') ]; Db::name('store_product_stock')->insert($arr); } @@ -313,7 +313,7 @@ class Product extends BaseController public function switchStatus($id) { $status = $this->request->param('status', 0) == 1 ? 1 : 0; - $this->repository->switchShow($id, $status,'is_show',$this->request->merId()); + $this->repository->switchShow($id, $status, 'is_show', $this->request->merId()); return app('json')->success('修改成功'); } @@ -329,7 +329,7 @@ class Product extends BaseController $ids = $this->request->param('ids'); if (empty($ids)) return app('json')->fail('请选择商品'); $status = $this->request->param('status') == 1 ? 1 : 0; - $this->repository->batchSwitchShow($ids,$status,'is_show',$this->request->merId()); + $this->repository->batchSwitchShow($ids, $status, 'is_show', $this->request->merId()); return app('json')->success('修改成功'); } @@ -342,7 +342,7 @@ class Product extends BaseController public function batchTemplate() { $ids = $this->request->param('ids'); - $ids = is_array($ids) ? $ids : explode(',',$ids); + $ids = is_array($ids) ? $ids : explode(',', $ids); $data = $this->request->params(['temp_id']); if (empty($ids)) return app('json')->fail('请选择商品'); if (empty($data['temp_id'])) return app('json')->fail('请选择运费模板'); @@ -351,7 +351,7 @@ class Product extends BaseController if (!$make->merInExists($this->request->merId(), [$data['temp_id']])) return app('json')->fail('请选择您自己的运费模板'); $data['delivery_free'] = 0; - $this->repository->updates($ids,$data); + $this->repository->updates($ids, $data); return app('json')->success('修改成功'); } @@ -368,7 +368,7 @@ class Product extends BaseController if (empty($ids)) return app('json')->fail('请选择商品'); if (!$this->repository->merInExists($this->request->merId(), $ids)) return app('json')->fail('请选择您自己商品'); - app()->make(SpuRepository::class)->batchLabels($ids, $data,$this->request->merId()); + app()->make(SpuRepository::class)->batchLabels($ids, $data, $this->request->merId()); return app('json')->success('修改成功'); } @@ -385,7 +385,7 @@ class Product extends BaseController if (empty($ids)) return app('json')->fail('请选择商品'); if (!$this->repository->merInExists($this->request->merId(), $ids)) return app('json')->fail('请选择您自己商品'); - $this->repository->updates($ids,$data); + $this->repository->updates($ids, $data); return app('json')->success('修改成功'); } @@ -399,37 +399,65 @@ class Product extends BaseController public function batchExtension(ProductAttrValueRepository $repository) { $ids = $this->request->param('ids'); - $data = $this->request->params(['extension_one','extension_two']); + $data = $this->request->params(['extension_one', 'extension_two']); if ($data['extension_one'] > 1 || $data['extension_one'] < 0 || $data['extension_two'] < 0 || $data['extension_two'] > 1) { return app('json')->fail('比例0~1之间'); } if (empty($ids)) return app('json')->fail('请选择商品'); if (!$this->repository->merInExists($this->request->merId(), $ids)) return app('json')->fail('请选择您自己商品'); - $repository->updatesExtension($ids,$data); + $repository->updatesExtension($ids, $data); return app('json')->success('修改成功'); } public function batchSvipType() { $ids = $this->request->param('ids'); - $data = $this->request->params([['svip_price_type',0]]); + $data = $this->request->params([['svip_price_type', 0]]); if (empty($ids)) return app('json')->fail('请选择商品'); if (!$this->repository->merInExists($this->request->merId(), $ids)) return app('json')->fail('请选择您自己商品'); - $this->repository->updates($ids,$data); + $this->repository->updates($ids, $data); return app('json')->success('修改成功'); } /** * 导入商品列表管理 */ - public function xlsx_import_list(){ + public function xlsx_import_list() + { [$page, $limit] = $this->getPage(); - $select=Db::name('store_product_import')->where('mer_id',$this->request->merId())->page($page)->limit($limit)->select()->toArray(); - $count=Db::name('store_product_import')->where('mer_id',$this->request->merId())->count(); - return app('json')->success(['list'=>$select,'count'=>$count]); - + $select = Db::name('store_product_import')->where('mer_id', $this->request->merId())->page($page)->limit($limit)->select()->toArray(); + $count = Db::name('store_product_import')->where('mer_id', $this->request->merId())->count(); + return app('json')->success(['list' => $select, 'count' => $count]); } + + /** + * 商户添加商品到云仓 + */ + public function add_cloud_product() + { + $data = $this->request->params(['product_id', 'type', 'is_del']); + $res = $this->repository->add_cloud_product($data, $this->request->merchant()); + if ($res) { + return app('json')->success('设置成功'); + } else { + return app('json')->fail('设置失败'); + } + } + + + /** + * 云仓商品列表 + */ + public function cloud_product_list(){ + [$page, $limit] = $this->getPage(); + + $select=Db::name('store_product_cloud')->where('mer_id',$this->request->merId()) + ->page($page)->limit($limit)->select()->toArray(); + $count = Db::name('store_product_cloud')->where('mer_id',$this->request->merId())->count(); + return app('json')->success(['list'=>$select,'count'=>$count]); + } + } diff --git a/route/api.php b/route/api.php index 397f3572..ec72ebc4 100644 --- a/route/api.php +++ b/route/api.php @@ -304,7 +304,8 @@ Route::group('api/', function () { Route::post('product/good/:id', 'StoreProduct/updateGood'); Route::get('product/config', 'StoreProduct/config'); Route::post('product/stockIn', 'StoreProduct/stockIn'); - + Route::post('product/add_cloud_product', 'StoreProduct/add_cloud_product'); + Route::get('product/cloud_product_list', 'StoreProduct/cloud_product_list'); //商品分类 Route::get('category/lst', 'StoreCategory/lst'); Route::post('category/create', 'StoreCategory/create'); diff --git a/route/merchant/product.php b/route/merchant/product.php index b6cf3134..cdb1d2dd 100644 --- a/route/merchant/product.php +++ b/route/merchant/product.php @@ -204,6 +204,12 @@ Route::group(function () { Route::post('labels/:id', '/setLabels')->name('merchantStoreProductLabels')->option([ '_alias' => '标签', ]); + Route::post('add_cloud_product', '/add_cloud_product')->option([ + '_alias' => '商户设置云商品', + ]); + Route::get('cloud_product_list', '/cloud_product_list')->option([ + '_alias' => '云商品列表', + ]); Route::get('attr_value/:id', '/getAttrValue')->name('merchantStoreProductAttrValue')->option([ '_alias' => '获取规格', ]);