From db6ef815aad0aeb07fc3db35088690da1189bb0c Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Tue, 19 Mar 2024 15:52:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=85=8D=E5=AE=A1=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=92=8C=E5=95=86=E6=88=B7=E7=AB=AF=E5=85=A5=E5=BA=93=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=90=9C=E7=B4=A2=E5=90=8D=E7=A7=B0=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 2 +- app/controller/admin/ProductLibrary.php | 183 ++++++++++++++++ .../api/store/product/StoreMicro.php | 198 ++++++++++++++++++ .../api/store/product/StoreProduct.php | 44 ++++ route/api.php | 13 ++ 5 files changed, 439 insertions(+), 1 deletion(-) create mode 100644 app/controller/admin/ProductLibrary.php create mode 100644 app/controller/api/store/product/StoreMicro.php diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index fea25d9a..01249e1c 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -356,7 +356,7 @@ class ProductRepository extends BaseRepository } $res = $this->dao->get($id); $data['svip_price_type'] = $res['svip_price_type']; - $settleParams = $this->setAttrValue($data, $id, 0, 1); + $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']; diff --git a/app/controller/admin/ProductLibrary.php b/app/controller/admin/ProductLibrary.php new file mode 100644 index 00000000..caba68ce --- /dev/null +++ b/app/controller/admin/ProductLibrary.php @@ -0,0 +1,183 @@ +getPage(); + $param = $this->request->param(); + $where = ['is_del' => 0]; + $list = Db::name('product_library')->where($where)->page($page)->limit($limit)->order('id desc')->select(); + $count = Db::name('product_library')->count(); + return app('json')->success(['list' => $list, 'count' => $count]); + } + + public function add() + { + $param = $this->request->param(); + $data['store_name'] = $param['store_name']; + $data['store_info'] = $param['store_info']; + $data['keyword'] = $param['keyword']; + $data['bar_code'] = $param['bar_code']; + $data['is_used'] = 1; + $data['status'] = 1; + $data['cate_id'] = $param['cate_id']; + $data['unit_name'] = $param['unit_name']; + $data['price'] = $param['price']; + $data['cost'] = $param['cost']; + $data['ot_price'] = $param['ot_price']; + $data['stock'] = $param['stock']; + $data['create_time'] = date('Y-m-d H:i:s'); + $data['image'] = $param['image']; + $data['slider_image'] = $param['slider_image']; + $data['images'] = $param['images']; + $res = Db::name('product_library')->insert($data); + if ($res) { + return app('json')->success('添加成功'); + } else { + return app('json')->fail('添加失败'); + } + } + + public function edit() + { + $param = $this->request->param(); + $data['store_name'] = $param['store_name']; + $data['store_info'] = $param['store_info']; + $data['keyword'] = $param['keyword']; + $data['bar_code'] = $param['bar_code']; + $data['is_used'] = 1; + $data['status'] = 1; + $data['cate_id'] = $param['cate_id']; + $data['unit_name'] = $param['unit_name']; + $data['price'] = $param['price']; + $data['cost'] = $param['cost']; + $data['ot_price'] = $param['ot_price']; + $data['stock'] = $param['stock']; + $data['create_time'] = date('Y-m-d H:i:s'); + $data['image'] = $param['image']; + $data['slider_image'] = $param['slider_image']; + $data['images'] = $param['images']; + $res = Db::name('product_library')->where('id', $param['id'])->update($data); + if ($res) { + return app('json')->success('修改成功'); + } else { + return app('json')->fail('修改失败'); + } + } + + public function del() + { + $param = $this->request->param(); + $res = Db::name('product_library')->where('id', $param['id'])->update(['is_del' => 1]); + if ($res) { + return app('json')->success('删除成功'); + } else { + return app('json')->fail('删除失败'); + } + } + + public function caiji($code = '') + { + if ($code == '') { + return app('json')->fail('编码不能为空'); + } + $first_char = substr($code, 0, 1); + if($first_char!=0){ + $codes='0'.$code; + }else{ + $codes=$code; + } + $client = new Client("b1eb52b9-0379-4c56-b795-47d90a73ca6a"); + + $result = $client->barcodeQuery() + ->withCode($codes) + ->request(); + try { + if ($result['code'] == 0) { + $upload = UploadService::create(); + $dir = 'def/' . date('Y-m-d'); + + $param = $result['data']; + $data['store_name'] = $param['goodsName']; + $data['store_info'] = ''; + $data['keyword'] = ''; + $data['bar_code'] = $code; + $data['is_used'] = 1; + $data['status'] = 1; + $data['cate_id'] = 0; + $data['unit_name'] = ''; + $data['spec'] =$param['spec']; + $data['trademark'] =$param['trademark']; + $data['goods_type'] =$param['goodsType']; + $data['ycg'] =$param['ycg']; + $data['note'] =$param['note']; + $data['manu_address'] =$param['manuAddress']; + $data['price'] = $param['price']??0; + $data['cost'] = 0; + $data['ot_price'] = 0; + $data['stock'] = 9999999; + $data['create_time'] = date('Y-m-d H:i:s'); + $data['images'] = ''; + $arr=[]; + if ($param['img'] != '') { + $oss = $upload->to($dir)->stream($this->getPic($param['img'])); + $data['image'] = $oss->filePath; + $arr[]=$oss->filePath; + } else { + $data['image'] = 'https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230130/00ebcfdf75684f5494c0193075055d1.png'; + $data['slider_image'] = 'https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230130/00ebcfdf75684f5494c0193075055d1.png'; + } + foreach($param['imgList'] as $k=>$v){ + $oss=$upload->to($dir)->stream($this->getPic($v)); + $arr[] = $oss->filePath; + } + if(count($arr)>0){ + $data['slider_image'] =implode(',',$arr); + }else{ + $data['slider_image']=$data['image']; + } + $data['images'] = ''; + $res = Db::name('product_library')->insert($data); + + if ($res) { + $group_id=Db::name('system_group')->where('group_key','product_caiji_count')->value('group_id'); + if($group_id){ + $find=Db::name('system_group_data')->where('group_id',$group_id)->whereDay('create_time')->find(); + if($find){ + $count=json_decode($find['value'],true)['count']+1; + Db::name('system_group_data')->where('group_data_id',$find['group_data_id'])->update(['value'=>json_encode(['count'=>$count])]); + }else{ + Db::name('system_group_data')->insert(['group_id'=>$group_id,'value'=>'{"count":1}','create_time'=>date('Y-m-d H:i:s')]); + } + } + return app('json')->success('添加成功'); + } else { + throw new \think\exception\ValidateException('添加失败'); + } + } else { + Log::error('一维码商品采集错误:' . $result['data']['remark']); + throw new \think\exception\ValidateException('一维码商品采集错误:'. $result['data']['remark']); + } + } catch (\Exception $e) { + throw new \think\exception\ValidateException('一维码商品采集错误:'.$e->getMessage()); + } + } + + public function getPic($url){ + $client = new http_client(); + $a=$client->get($url); + return $a->getBody()->getContents(); + } +} diff --git a/app/controller/api/store/product/StoreMicro.php b/app/controller/api/store/product/StoreMicro.php new file mode 100644 index 00000000..9317e787 --- /dev/null +++ b/app/controller/api/store/product/StoreMicro.php @@ -0,0 +1,198 @@ + 1, 'status' => 1, 'is_del' => 0]; + $field = 'id,store_name,bar_code,manu_address,price,stock,image,slider_image,spec,trademark,manu_name,manu_address,note'; + if($code!=''){ + $res=Db::name('product_library')->where('bar_code',$code)->where($where)->field($field) + ->withAttr('slider_image',function($value,$data){ + return $value?explode(',',$value):[]; + }) + ->find(); + if($res==null){ + $ProductLibrary = app()->make(ProductLibrary::class); + try{ + $ProductLibrary->caiji($code); + $res=Db::name('product_library')->where('bar_code',$code)->where($where)->field($field) + ->withAttr('slider_image',function($value,$data){ + return $value?explode(',',$value):[]; + }) + ->find(); + }catch(Exception $e){ + return app('json')->fail('编码:'.$code.'。'.$e->getMessage()); + } + } + $find[]=$res; + }else{ + if($name==''){ + return app('json')->fail('参数不能为空'); + } + $find=Db::name('product_library')->where('store_name','like','%'.$name.'%')->where($where)->field($field) + ->withAttr('slider_image',function($value,$data){ + return $value?explode(',',$value):[]; + }) + ->select(); + } + if (count($find)==0){ + if($code!=''){ + $store_product['key']['bar_code']=$code; + }else{ + $store_product['key']['store_name']=$name; + } + $store_product['key']['is_mer_show']=0; + }else{ + $store_product['key']['is_mer_show']=1; + } + $store_product['list']=$find; + return app('json')->success($store_product); + } + + //商品详情 + public function ProductDetails($id){ + $find=Db::name('store_product')->where('product_id',$id) + ->withAttr('attr_value',function ($value,$data){ + return Db::name('store_product_attr_value')->where('product_id',$data['product_id'])->select(); + }) + ->find(); + return app('json')->success(['list'=>$find]); + } + + //提交导入商品id + public function ProductImport(){ + return app('json')->fail('该接口已废弃'); + $id = $this->request->param('id', 0); + $price = $this->request->param('price', 0); + $stock = $this->request->param('stock', 0); + $store_name = $this->request->param('store_name', ''); + $user = $this->request->userInfo(); + $where = ['is_used' => 1, 'status' => 1, 'is_del' => 0]; + try { + $mer_id = Db::name('store_service')->where('uid', $user['uid'])->where('status', 1)->value('mer_id'); + if ($mer_id == 0) { + return app('json')->fail('商户不存在'); + } + $mer= Db::name('merchant')->where('mer_id', $mer_id)->find(); + $category_name= Db::name('merchant_category')->where('merchant_category_id', $mer['category_id'])->value('category_name'); + $store_category_id= Db::name('store_category')->where(['cate_name'=>$category_name,'level'=>2,'mer_id'=>0])->value('store_category_id'); + if(!$store_category_id){ + return app('json')->fail('没有对应的分类,请联系工作人员添加'); + } + $find=Db::name('product_library')->where('id',$id)->where($where)->find(); + if ($find) { + + $exist = Db::name('store_product')->where('source_library_id', $id)->where('mer_id', $mer_id)->find(); + if ($exist) { + // return app('json')->fail('已经导入过该商品了'); + } + $find['attrValue']=[ + ['image'=>$find['image'],'price'=>$price,'cost'=>$find['cost'],'ot_price'=>$find['ot_price'], + 'svip_price'=>0,'stock'=>$stock,'bar_code'=>$find['bar_code'],'weight'=>0,'volume'=>0,'detail'=>'' + ]]; + if($mer['type_id']==12){ + $product_type=98; + }else{ + $product_type=0; + } + $find['store_name'] =$store_name??$find['store_name']; + $find['content'] =['image'=>explode(',',$find['images'])]; + $find['slider_image'] =explode(',',$find['slider_image']); + $find['is_show'] = 1; + $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",1=>'1']; + $find["guarantee_template_id"] = ""; + $find['product_type'] = $product_type; + $find['mer_cate_id'] = [0 => 0]; + $find['is_used'] = 1; + $find['status'] = 1; + $find['mer_status'] = 1; + $find['source_product_id'] = 0; + $find['source_library_id'] = $find['id']; + $find['spec_type'] = 0; + $find['delivery_free'] = 0; + $find['cate_id'] = $store_category_id; + $find['svip_price_type'] = 0; + $find['svip_price'] =0; + unset($find['create_time'], $find['id']); + } + $a= app()->make( ProductRepository::class)->create($find,$product_type,1); + if($a){ + return app('json')->success(['data'=>['product_id'=>$a],'msg'=>'导入成功']); + }else{ + return app('json')->fail('导入失败'); + } + } catch (\Exception $e) { + return app('json')->fail($e->getMessage()); + } + + } + + public function eadtProduct(){ + $id = $this->request->param('id', 0); + $image = $this->request->param('image', ''); + $slider_image = $this->request->param('slider_image', ''); + + if ($slider_image=='') return app('json')->fail('轮播图不能为空'); + if ($image=='') return app('json')->fail('首屏图不能为空'); + + try { + $res=Db::name('product_library')->where('id',$id)->update(['image'=>$image,'slider_image'=>$slider_image]); + if($res){ + return app('json')->success('更新成功'); + }else{ + return app('json')->fail('更新失败'); + } + + } catch (\Exception $e) { + // 回滚事务 + return app('json')->fail($e->getMessage()); + } + } + + /** + * 待审核添加 + */ + public function add() + { + $param = $this->request->param(); + $uid=$this->request->userInfo()['uid']; + $mer_id=Db::name('store_service')->where(['uid'=>$uid,'status'=>1,'is_del'=>0,'is_goods'=>1])->value('mer_id'); + $data['store_name'] = $param['store_name']; + $data['bar_code'] = $param['bar_code']; + $data['store_info'] = ''; + $data['keyword'] = ''; + $data['cate_id'] = 0; + $data['unit_name'] = ''; + $data['is_used'] = 1; + $data['status'] = 1; + $data['price'] = $param['price']; + $data['stock'] = $param['stock']; + $data['create_time'] = date('Y-m-d H:i:s'); + $data['image'] = $param['image']; + $data['slider_image'] = $param['slider_image']; + $data['images'] = $param['images']; + $data['mer_id'] = $mer_id; + $data['product_library_id'] = $param['product_library_id']; + $res = Db::name('product_library_examine')->insert($data); + if ($res) { + return app('json')->success('添加成功,等待审核'); + } else { + return app('json')->fail('添加失败'); + } + } +} \ No newline at end of file diff --git a/app/controller/api/store/product/StoreProduct.php b/app/controller/api/store/product/StoreProduct.php index 373e8425..549e4da5 100644 --- a/app/controller/api/store/product/StoreProduct.php +++ b/app/controller/api/store/product/StoreProduct.php @@ -25,6 +25,7 @@ use think\App; use crmeb\basic\BaseController; use app\common\repositories\store\product\ProductRepository as repository; use think\facade\Cache; +use think\facade\Db; class StoreProduct extends BaseController { @@ -284,4 +285,47 @@ class StoreProduct extends BaseController $uid = $this->request->isLogin() ? $this->request->uid() : 0; return app('json')->success($this->repository->getGoodList($id, $uid)); } + + + + /** + * 免审编辑 + */ + public function UserFreeTrial($id) + { + $params = [ + "mer_cate_id", + "sort" , + "is_show", + "is_good", + "attr", + "attrValue", + 'spec_type', + 'is_stock', + 'mer_labels' + ]; + $data = $this->request->params($params); + // $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; + $uid=$this->request->userInfo()['uid']; + $mer_id=Db::name('store_service')->where(['uid'=>$uid,'status'=>1,'is_del'=>0,'is_goods'=>1])->value('mer_id'); + if(!$mer_id){ + return app('json')->fail('编辑免申商品参数错误'); + } + $res=$this->repository->freeTrial($id, $data,$mer_id,[]); + if($res && $data['is_stock']==1){ + $arr=[ + 'mer_id'=>$mer_id, + 'uid'=>$uid, + 'product_id'=>$data['attrValue'][0]['product_id'], + 'create_time'=>date('Y-m-d H:i:s') + ]; + Db::name('store_product_stock')->insert($arr); + } + return app('json')->success('编辑成功'); + } + + + } diff --git a/route/api.php b/route/api.php index 8dcc3508..729ad9e4 100644 --- a/route/api.php +++ b/route/api.php @@ -58,6 +58,9 @@ Route::group('api/', function () { Route::post('user/spread', 'api.Auth/spread'); Route::post('merchant_license_identify', 'api.Common/merchant_license_identify');//营业执照识别 + Route::post('user_free_trial/:id', 'api.store.product.StoreProduct/UserFreeTrial')->option([ + '_alias' => '免审编辑', + ]); //优惠券 Route::group('coupon', function () { Route::post('receive/:id', 'api.store.product.StoreCoupon/receiveCoupon'); @@ -731,6 +734,16 @@ Route::group('api/', function () { Route::get('navigation', 'api.Common/getNavigation'); Route::get('micro', 'api.Common/micro'); + + + Route::group('micro', function () { + Route::get('seach_bar_code', '/seach_bar_code'); + Route::get('product_details', '/ProductDetails'); + Route::post('eadt_product', '/eadtProduct'); + Route::post('product_import', '/ProductImport'); + Route::post('product_add', '/add'); + })->prefix('api.store.product.StoreMicro'); + Route::get('version', 'admin.Common/version'); Route::get('diy', 'api.Common/diy'); //滑块验证码 From 4849540761b41f4815643ae2fb298921fc6f9e11 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Tue, 19 Mar 2024 16:13:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=95=86=E6=88=B7=E6=9D=83=E9=99=90?= =?UTF-8?q?=E9=99=90=E5=88=B6=E6=96=B0=E5=A2=9E=E6=89=B9=E5=8F=91=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 01249e1c..d7747958 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -14,6 +14,7 @@ namespace app\common\repositories\store\product; use app\common\model\store\order\StoreOrder; use app\common\model\store\product\ProductLabel; +use app\common\model\system\merchant\Merchant; use app\common\model\user\User; use app\common\repositories\community\CommunityRepository; use app\common\repositories\store\coupon\StoreCouponRepository; @@ -518,10 +519,18 @@ class ProductRepository extends BaseRepository if ($data['integral_rate'] > 100) $integral_rate = 100; } + //判断商户的权限 + $check = Merchant::getDB()->where('mer_id',$data['mer_id'])->value('wholesale'); - $wholesalePrices = array_column($data['attrValue'], 'wholesale_price'); - $minPriceOtPrice = min($wholesalePrices); - + if($check){ //权限为1或者2 + $wholesalePrices = array_column($data['attrValue'], 'wholesale_price'); + if(empty($wholesalePrices)){ + return app('json')->fail('商户为批发或者零售+批发缺失批发价'); + } + $minPriceOtPrice = min($wholesalePrices); + }else{ + $minPriceOtPrice = 0; + } $result = [ 'store_name' => $data['store_name'], 'image' => $data['image'], @@ -680,10 +689,18 @@ class ProductRepository extends BaseRepository } $new_price = $value['price'] ? (($value['price'] < 0) ? 0 : $value['price']) : 0; $otPrice = $value['ot_price'] ? (($value['ot_price'] < 0) ? 0 : $value['ot_price']) : 0; + if(isset($value['wholesale_price'])){ $wholesale_price = $value['wholesale_price'] ? (($value['wholesale_price'] < 0) ? 0 : $value['wholesale_price']) : 0; }else{ - $wholesale_price = min($new_price,$otPrice); + $check = Merchant::getDB()->where('mer_id',$data['mer_id'])->value('wholesale'); + + if($check){ + $wholesale_price = min($new_price,$otPrice); + }else{ + $wholesale_price = 0; + } + } $new_stock = $value['stock'] ? (($value['stock'] < 0) ? 0 : $value['stock']) : 0;