From 54990be89eafefc62eaea352a23e423be9da1a80 Mon Sep 17 00:00:00 2001 From: "wangmingchuan321@qq.com" Date: Sun, 4 Feb 2024 17:25:58 +0800 Subject: [PATCH] 111 --- app/api/controller/Goods.php | 19 +++++++++++ app/api/model/Goods.php | 61 ++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 987efc27..e13b351b 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -102,6 +102,25 @@ class Goods extends Controller return $this->renderSuccess(compact('list')); } + public function presaleCateList() + { + $param = $this->request->param(); + $model = new GoodsModel; + $list = $model->presaleCateList($param); + + return $this->renderSuccess($list); + } + + public function presaleGoodsList() + { + $param = $this->request->param(); + $model = new GoodsModel; + $list = $model->presaleGoodsList($param); + + return $this->renderSuccess(compact('list')); + } + + public function canlpresale() { $param = $this->request->param(); diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index f8e86c37..0a04f6bd 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -197,6 +197,67 @@ class Goods extends GoodsModel return $info; } + public function presaleGoodsList() + { + $info = PreSale::where([ + 'store_id' => request()->header()['storeid'], + 'is_change' => 0, + 'status' => 1, + ])->order('id desc')->find(); + + if ($info) { + $goods = explode(',', $info->goods_list); + + $list = goods::alias('a') + ->join('goods_category_rel b', 'a.goods_id = b.goods_id')->where([ + 'a.store_id' => request()->header()['storeid'], + 'a.status' => 10, + 'b.category_id' => $_GET['category_id'] + ])->whereIn('a.goods_id', $goods)->field('a.goods_id,a.goods_name,a.goods_price_min,b.category_id,a.sales_initial,a.sales_actual')->select()->toArray(); + + return $list; + } + return []; + } + + public function presaleCateList() + { + + $info = PreSale::where([ + 'store_id' => request()->header()['storeid'], + 'is_change' => 0, + 'status' => 1, + ])->order('id desc')->find(); + if ($info) { + $goods = explode(',', $info->goods_list); + $list = goods::alias('a') + ->join('goods_category_rel b', 'a.goods_id = b.goods_id') + ->join('category c', 'c.category_id = b.category_id') + ->where([ + 'a.store_id' => request()->header()['storeid'], + 'a.status' => 10, + 'c.parent_id' => 0, + ])->whereIn('a.goods_id', $goods)->field('c.*,a.sales_initial,a.sales_actual')->select()->toArray(); + + $list = $this->removeDuplicatesByField($list, 'category_id'); + $res['info'] = $info; + $res['category'] = $list; + return $res; + } + return []; + } + + function removeDuplicatesByField($array, $field) + { + $uniqueArray = array(); + foreach ($array as $item) { + if (!isset($uniqueArray[$item[$field]])) { + $uniqueArray[$item[$field]] = $item; + } + } + return array_values($uniqueArray); + } + public function canlpresale() { $userId = UserService::getCurrentLoginUserId(true);