request->isGet()) { $goodsId = $this->request->get('goods_id', '', 'trim'); $p_id = $this->request->get('p_id',0); $set_id = $this->request->get('set',0); $firend_invite_code = $this->request->get('firend_invite_code',0); $code = $this->request->get('code',0); $open=new Getopenid(); $info=$open->getAcc($code); if(isset($info['openid'])) { $openid = $info['openid']; $user_msg = UserAuth::where("openid",$openid)->find(); $firend_msg = User::where("distribution_code",$firend_invite_code)->find(); if($user_msg==null){ $data = [ 'sn' => create_user_sn(), 'create_time' => time(), "first_leader" => $firend_msg['id'], 'distribution_code' => generate_invite_code(),//分销邀请码 'is_distribution' => DistributionLogic::isDistributionMember(), 'client' => 1, 'is_new_user' => 1, 'user_ad_cret' => 1 ]; $user = User::create($data); $user_id = $user->id; $UserAuth = UserAuth::create([ "user_id"=>$user_id, "openid"=>$openid, "create_time"=>time(), "client"=>1 ]); //生成会员分销扩展表 DistributionLogic::createUserDistribution($user_id); // 生成分销基础信息表 \app\common\logic\DistributionLogic::add($user_id); } } // trace($set_id."-".$p_id, 'ceshi'); $validate = Validate::rule('goods_id', 'require|integer|gt:0'); if(!$validate->check(['goods_id'=>$goodsId])) { return JsonServer::error($validate->getError()); } $goodsDetail = GoodsLogic::getGoodsDetail($goodsId, $this->user_id,$p_id,$set_id); if(false === $goodsDetail) { $error = GoodsLogic::getError() ?? '获取商品详情失败'; return JsonServer::error($error); } $set = null; $settpye = 0; if($p_id != 0&&$set_id!=0){ $set = Procurementset::where("set_id",$set_id)->where("set_state",1)->find(); } if($p_id != 0&&$set_id==0){ $settpye = 1; $set = Procurementset::where("u_id",$p_id)->where("set_state",1)->order("set_update desc")->limit(1)->find(); } $set_price_type = 0; if ($set != null&&$settpye!=1) { if($set['price_type']==1){ $set_price_type = 1; } if($set['price_type']==2){ $set_price_type = 2; } if($set['price_type']==3){ $set_price_type = 3; } if ($set['set_pro'] != 0) { // $set_price_type = 1; if ($set['set_pro_type'] == 1) { $goodsDetail['purchase_price'] = round($goodsDetail['purchase_price'] * (100 + $set['set_pro']) / 100, 2); } if ($set['set_pro_type'] == 3) { $goodsDetail['purchase_price'] = round($goodsDetail['purchase_price'] + $set['set_pro'], 2); } } if ($set['set_issued'] != 0) { // $set_price_type = 2; if ($set['set_issued_type'] == 1) { $goodsDetail['issuing_price'] = round($goodsDetail['issuing_price'] * (100 + $set['set_issued']) / 100, 2); } if ($set['set_issued_type'] == 3) { $goodsDetail['issuing_price'] = round($goodsDetail['issuing_price'] + $set['set_issued'], 2); } } if ($set['set_wholesale'] != 0) { // $set_price_type = 3; if ($set['set_wholesale_type'] == 1) { $goodsDetail['wholesale_price'] = round($goodsDetail['wholesale_price'] * (100 + $set['set_wholesale']) / 100, 2); } if ($set['set_wholesale_type'] == 3) { $goodsDetail['wholesale_price'] = round($goodsDetail['wholesale_price'] + $set['set_wholesale'], 2); } } $rst = Mprocurement::where("user_id",$this->user_id)->where("u_state",1)->where("u_examine_state",1)->where("wholesale_state",2)->find(); foreach ($goodsDetail['goods_item'] as $k => $v) { if($rst!=null){ $number = Goodswholesale::where('item_id',$v['id'])->select(); $goodsDetail['goods_item'][$k]['number'] = $number; }else{ $goodsDetail['goods_item'][$k]['number'] = []; } $itp = GoodsItem::where("id",$v['id'])->find(); if ($set['set_pro'] != 0) { if ($set['set_pro_type'] == 1) { $goodsDetail['goods_item'][$k]['purchase_price'] = round($itp['purchase_price'] * (100 + $set['set_pro']) / 100, 2); } if ($set['set_pro_type'] == 3) { if ($itp['purchase_price'] > 0) { $goodsDetail['goods_item'][$k]['purchase_price'] = round($itp['purchase_price'] + $set['set_pro'], 2); } else { $goodsDetail['goods_item'][$k]['purchase_price'] = "0.00"; } } } if ($set['set_issued'] != 0) { if ($set['set_issued_type'] == 1) { $goodsDetail['goods_item'][$k]['issuing_price'] = round($itp['issuing_price'] * (100 + $set['set_issued']) / 100, 2); } if ($set['set_issued_type'] == 3) { if($itp['issuing_price'] > 0){ $goodsDetail['goods_item'][$k]['issuing_price'] = round($itp['issuing_price'] + $set['set_issued'], 2); }else{ $goodsDetail['goods_item'][$k]['issuing_price'] = "0.00"; } } } if ($set['set_wholesale'] != 0) { if ($set['set_wholesale_type'] == 1) { $goodsDetail['goods_item'][$k]['wholesale_pce'] = round($itp['wholesale_pce'] * (100 + $set['set_wholesale']) / 100, 2); } if ($set['set_wholesale_type'] == 3) { if($itp['wholesale_pce'] > 0){ $goodsDetail['goods_item'][$k]['wholesale_pce'] = round($itp['wholesale_pce'] + $set['set_wholesale'], 2); }else{ $goodsDetail['goods_item'][$k]['wholesale_pce'] = "0.00"; } } } } } $goodsDetail['set_price_type'] = $set_price_type; $rst = Mprocurement::where("user_id",$this->user_id)->where("u_state",1)->where("u_examine_state",1)->where("wholesale_state",2)->find(); if($rst==null){ // foreach($goodsDetail['goods_item'] as $k => $v){ // if(isset($goodsDetail['wholesale_price'] )){ // $goodsDetail['wholesale_price'] = 0; // } // } if($p_id > 0){ foreach ($goodsDetail['goods_item'] as $k => $v) { $number = Goodswholesale::where('item_id', $v['id'])->select(); $goodsDetail['goods_item'][$k]['number'] = $number; $purchase_sku= Goodspurchase::where('item_id', $v['id'])->select(); $goodsDetail['goods_item'][$k]['purchase_sku'] = $purchase_sku; } } }else{ foreach ($goodsDetail['goods_item'] as $k => $v) { $number = Goodswholesale::where('item_id', $v['id'])->select(); $goodsDetail['goods_item'][$k]['number'] = $number; $purchase_sku= Goodspurchase::where('item_id', $v['id'])->select(); $goodsDetail['goods_item'][$k]['purchase_sku'] = $purchase_sku; } } return JsonServer::success('获取商品详情成功', $goodsDetail); }else{ return JsonServer::error('请求方式错误'); } } // 备用接口调整集采规格 public function getPurchasesku(){ $post = $this->request->post(); $purchase_sku= Goodspurchase::where('item_id', $post['id'])->select(); if(!empty($purchase_sku)){ if($purchase_sku[0]['purchase_content'] == "" || $purchase_sku[0]['purchase_content'] == null){ return JsonServer::error('暂无数据'); }else{ return JsonServer::success('集采规格成功', $purchase_sku); } }else{ return JsonServer::error('暂无数据'); } } /** * 热销榜单 */ public function getHotList() { return $this->getGoodsListTemplate($this->request, 'getHotList'); } /** * 商品列表 */ public function getGoodsList(){ return $this->getGoodsListTemplate($this->request, 'getGoodsList'); } /** * 商品列表模板 * 作用:代码复用 */ public function getGoodsListTemplate($request, $methodName) { if($request->isGet()) { $get = $this->request->get(); $get['user_id'] = $this->user_id; $get['page_no'] = $this->page_no; $get['page_size'] = $this->page_size; $data = GoodsLogic::$methodName($get); // 可变方法 $user_id = $get['user_id']; $rst = Mprocurement::where("user_id",$user_id)->where("u_state",1)->where("u_examine_state",1)->find(); if($rst==null){ foreach($data as $key=>$value){ if(isset($data[$key]['wholesale_price'])){ $data[$key]['wholesale_price'] = 0; } } } return JsonServer::success('获取成功', $data); }else{ return JsonServer::error('请求方式错误'); } } /** * 根据商品栏目获取商品列表 */ public function getGoodsListByColumnId() { if($this->request->isGet()) { $columnId = $this->request->get('column_id', '', 'trim'); $p_id = $this->request->get('p_id',0); $set_id = $this->request->get('set',0); $validate = Validate::rule('column_id', 'require|integer|gt:0'); if(!$validate->check(['column_id'=>$columnId])) { return JsonServer::error($validate->getError()); } $data = GoodsLogic::getGoodsListByColumnId($columnId,$this->page_no, $this->page_size,$p_id,$set_id); return JsonServer::success('获取成功', $data); }else{ return JsonServer::error('请求方式错误'); } } public function searchByName() { if($this->request->isGet()) { $shop_name = $this->request->get('shop_name'); $data = GoodsLogic::searchByName($shop_name); return JsonServer::success('获取成功', $data); }else{ return JsonServer::error('请求方式错误'); } } }