diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 75c149a1..6b779157 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -289,4 +289,15 @@ class Goods extends Api 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('请求方式错误'); + } + } } \ No newline at end of file diff --git a/app/api/logic/GoodsLogic.php b/app/api/logic/GoodsLogic.php index d16d2098..8f4b8257 100644 --- a/app/api/logic/GoodsLogic.php +++ b/app/api/logic/GoodsLogic.php @@ -78,7 +78,7 @@ class GoodsLogic extends Logic $goodsDetail['member_price'] = 0; // 会员价数组 $member_price = []; - foreach ($goodsDetail['goods_item'] as &$goods_item) { + foreach ($goodsDetail['goods_item'] as &$goods_item) { $is_member = Goods::where('id',$goods_item['goods_id'])->value('is_member'); $goods_item['is_member'] = $is_member; if($is_member == 1 && $discount && $userId){ @@ -277,7 +277,7 @@ class GoodsLogic extends Logic ['del', '=', 0], ['activity_start_time', '<=', time()], ['activity_end_time', '>=', time()] - ])->findOrEmpty()->toArray(); + ])->findOrEmpty()->toArray(); if ($teamActivity) { $teamFound = (new TeamFound())->alias('TF') @@ -290,7 +290,7 @@ class GoodsLogic extends Logic ['status', '=', 0], ['invalid_time', '>=', time()] ])->join('procurement U', 'U.id=TF.user_id') - ->select()->toArray(); + ->select()->toArray(); foreach ($teamFound as &$found) { unset($found['shop_id']); @@ -400,7 +400,8 @@ class GoodsLogic extends Logic $wh = "find_in_set(".$get['platform_cate_id'].", third_cate_id)"; } } - } + + } // 品牌 if(isset($get['brand_id']) && !empty($get['brand_id']) && filter_var($get['brand_id'], FILTER_VALIDATE_INT)) { @@ -456,13 +457,17 @@ class GoodsLogic extends Logic $settpye = 0; if($p_id != 0&&$set_id!=0){ $set = Procurementset::where("set_id",$set_id)->where("set_state",1)->find(); + // $where[] = ['second_cate_id', 'in', $set['goods_twotype']]; $set_array = json_decode($set['goods_onetype'], true); $w = ['second_cate_id', 'in', $set_array[0]['child_id']]; - foreach($set_array as $key=>$value){ - if($value['id'] == $get['platform_cate_id']){ - $w = ['second_cate_id', 'in', $value['child_id']]; + if(isset($get['platform_cate_id'])){ + foreach($set_array as $key=>$value){ + if($value['id'] == $get['platform_cate_id']){ + $w = ['second_cate_id', 'in', $value['child_id']]; + } } } + $where[] = $w; if($set != null){ if($set['set_pro']!=0){ @@ -507,6 +512,7 @@ class GoodsLogic extends Logic $set_price_type = 3; } if($set['set_pro']!=0){ + // $set_price_type = 1; //min_price if($set['set_pro_type'] == 1){ $item['purchase_price'] = round($item['purchase_price']*(100+$set['set_pro'])/100,2); @@ -517,10 +523,10 @@ class GoodsLogic extends Logic }else{ $item['purchase_price'] = "0.00"; } - } + } } if($set['set_issued']!=0){ - + // $set_price_type = 2; //market_price if($set['set_issued_type'] == 1){ $item['issuing_price'] = round($item['issuing_price']*(100+$set['set_issued'])/100,2); @@ -534,7 +540,7 @@ class GoodsLogic extends Logic } } if($set['set_wholesale']!=0){ - + // $set_price_type = 3; //market_price if($set['set_wholesale_type'] == 1){ $item['wholesale_price'] = round($item['wholesale_price']*(100+$set['set_wholesale'])/100,2); @@ -632,7 +638,7 @@ class GoodsLogic extends Logic $set_price_type = 3; } if ($set['set_pro'] != 0) { - + // $set_price_type = 1; if ($set['set_pro_type'] == 1) { $list[$key]['purchase_price'] = round($value['purchase_price'] * (100 + $set['set_pro']) / 100, 2); } @@ -641,7 +647,7 @@ class GoodsLogic extends Logic } } if ($set['set_issued'] != 0) { - + // $set_price_type = 2; if ($set['set_issued_type'] == 1) { $list[$key]['issuing_price'] = round($value['issuing_price'] * (100 + $set['set_issued']) / 100, 2); } @@ -650,7 +656,7 @@ class GoodsLogic extends Logic } } if ($set['set_wholesale'] != 0) { - + // $set_price_type = 3; if ($set['set_wholesale_type'] == 1) { $list[$key]['wholesale_price'] = round($value['wholesale_price'] * (100 + $set['set_wholesale']) / 100, 2); } @@ -841,15 +847,31 @@ class GoodsLogic extends Logic } else { $isShow = 0; } - + return [ 'is_show' => $isShow, 'earnings' => $earnings ]; } - public static function getGoodsTypeList() + + public static function searchByName($shop_name) { - $result = GoodsCategory::where('is_show',1)->select(); - return $result; + if (!$shop_name) { + return false; + } + + $onSaleWhere = [ + 'del' => GoodsEnum::DEL_NORMAL, // 未删除 + 'status' => GoodsEnum::STATUS_SHELVES, // 上架中 + 'audit_status' => GoodsEnum::AUDIT_STATUS_OK, // 审核通过 + ]; + + $where[] = ['name', 'like', '%' . $shop_name . '%']; + $goods = Goods::field('id, name') + ->where($onSaleWhere) + ->where($where) + ->select()->toArray(); + + return $goods; } }