|
@@ -6,6 +6,7 @@ namespace app\admin\controller;
|
|
|
use app\admin\model\GoodLog;
|
|
|
use think\App;
|
|
|
use think\facade\Db;
|
|
|
+use think\facade\Validate;
|
|
|
|
|
|
//线上商品
|
|
|
class Good extends Base
|
|
@@ -844,4 +845,86 @@ class Good extends Base
|
|
|
return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //根据价格区间,筛选符合条件的商品列表
|
|
|
+ public function getGoodListByLadder()
|
|
|
+ {
|
|
|
+
|
|
|
+ //1.请求参数
|
|
|
+ $min_price = $this->request->post('min_price/f', 0, 'trim');
|
|
|
+ $max_price = $this->request->post('max_price/f', 0, 'trim');
|
|
|
+ $page = $this->request->post('page/d', 1, 'trim');
|
|
|
+ $size = $this->request->post('size/d', 15, 'trim');
|
|
|
+
|
|
|
+ //2.参数校验
|
|
|
+ $val=Validate::rule([
|
|
|
+ 'min_price'=>'require|float|elt:max_price',
|
|
|
+ 'max_price'=>'require|float|egt:min_price',
|
|
|
+ 'page'=>'require|number|gt:0',
|
|
|
+ 'size'=>'require|number|gt:0',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if(!$val->check(['min_price'=>$min_price,'max_price'=>$max_price,'page'=>$page,'size'=>$size])) return error_show(1004,$val->getError());
|
|
|
+
|
|
|
+ //3.组织SQL语句
|
|
|
+ $skuCodes = Db::name('good_ladder')
|
|
|
+ ->field('skuCode')
|
|
|
+ ->whereBetween('sale_price', [$min_price, $max_price])
|
|
|
+ ->where(['is_del' => 0, 'status' => 1])
|
|
|
+ ->group('skuCode')
|
|
|
+ ->buildSql();
|
|
|
+
|
|
|
+ //4.查询列表并补充相关信息(从list方法照搬)
|
|
|
+ $list = Db::name('good')
|
|
|
+ ->alias("a")
|
|
|
+ ->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status,gb.createrid purchase_id,gb.creater purchase,gl.min_num,gl.max_num")//成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
|
|
|
+ ->leftJoin("good_platform b", "a.spuCode=b.spuCode")
|
|
|
+ ->leftJoin("good_basic gb", "gb.spuCode=a.spuCode")
|
|
|
+ ->leftJoin("good_ladder gl", "gl.skuCode=b.skuCode")
|
|
|
+ ->where('b.skuCode in ' . $skuCodes)
|
|
|
+ ->page($page, $size)
|
|
|
+ ->order("b.addtime desc")
|
|
|
+ ->select();
|
|
|
+ $data = [];
|
|
|
+ foreach ($list as $value) {
|
|
|
+ $value['cat_info'] = made($value['cat_id'], []);
|
|
|
+ $platform = Db::name("platform")->where(["id" => $value['platform_code']])->find();
|
|
|
+ $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name'] : "";
|
|
|
+ $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en'] : "";
|
|
|
+ $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
|
|
|
+ $value['supplier_name'] = isset($supplier['name']) ? $supplier['name'] : "";
|
|
|
+ $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
|
|
|
+ $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
|
|
|
+ $unit = Db::name("unit")->where(["id" => $value['good_unit']])->find();
|
|
|
+ $value['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
|
|
|
+ $company = Db::name("business")->where(["companyNo" => $value['companyNo']])->find();
|
|
|
+ $value['company'] = isset($company['company']) ? $company['company'] : "";
|
|
|
+ $value['stock_total'] = Db::name("good_stock")->where(['spuCode' => $value['spuCode'], "is_del" => 0])->sum("usable_stock");
|
|
|
+ $value['status'] = $value['exam_status'];
|
|
|
+ $value['exclusive'] = makeExcluse($value['is_exclusive']);
|
|
|
+ $value['good_info_img'] = $value['good_info_img'];
|
|
|
+ $value['good_img'] = $value['good_img'];
|
|
|
+ $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
|
|
|
+ $speclist = [];
|
|
|
+ if (!empty($spec)) {
|
|
|
+ foreach ($spec as $val) {
|
|
|
+ $temp = [];
|
|
|
+ $temp['spec_id'] = $val['spec_id'];
|
|
|
+ $temp['spec_value_id'] = $val['spec_value_id'];
|
|
|
+ $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
|
|
|
+ $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
|
|
|
+ $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
|
|
|
+ $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
|
|
|
+ $speclist[] = $temp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $value['specinfo'] = $speclist;
|
|
|
+ $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : "";
|
|
|
+ $data[] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ return app_show(0, '请求成功', $data);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|