wanghousheng 10 months ago
commit e014aac067
  1. 19
      app/api/controller/Goods.php
  2. 61
      app/api/model/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();

@ -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);

Loading…
Cancel
Save