pull/1/head
wangmingchuan321@qq.com 1 year ago
parent 0d401273da
commit 4319f5fbb9
  1. 24
      app/api/controller/Goods.php
  2. 1
      app/api/controller/sharp/Goods.php
  3. 3
      app/api/model/Goods.php
  4. 164
      app/api/service/Goods.php
  5. 31
      app/common/model/Goods.php

@ -117,16 +117,32 @@ class Goods extends Controller
{ {
$service = new GoodsService; $service = new GoodsService;
$goodsList = $service->brandList(); $goodsList = $service->brandList();
return $this->renderSuccess(compact('goodsList')); return $this->renderSuccess($goodsList);
} }
public function newList(): Json public function charts(): Json
{ {
$service = new GoodsService; $service = new GoodsService;
$goodsList = $service->newList(); $goodsList = $service->charts();
return $this->renderSuccess(compact('goodsList')); return $this->renderSuccess($goodsList);
}
public function chartsGoodsList(): Json
{
$service = new GoodsService;
$goodsList = $service->chartsGoodsList();
return $this->renderSuccess($goodsList);
}
public function chartsGoodsJing(): Json
{
$service = new GoodsService;
$goodsList = $service->chartsGoodsJing();
return $this->renderSuccess($goodsList);
} }
public function cityInfo(): Json public function cityInfo(): Json
{ {
$service = new GoodsService; $service = new GoodsService;

@ -36,7 +36,6 @@ class Goods extends Controller
*/ */
public function list(int $activeTimeId): Json public function list(int $activeTimeId): Json
{ {
// 获取秒杀活动会场首页数据 // 获取秒杀活动会场首页数据
$service = new ActiveService; $service = new ActiveService;
$list = $service->getGoodsListByActiveTimeId($activeTimeId); $list = $service->getGoodsListByActiveTimeId($activeTimeId);

@ -96,10 +96,13 @@ class Goods extends GoodsModel
*/ */
public function getList(array $param = [], int $listRows = 15) public function getList(array $param = [], int $listRows = 15)
{ {
// 整理查询参数 // 整理查询参数
$params = array_merge($param, ['status' => GoodsStatusEnum::ON_SALE]); $params = array_merge($param, ['status' => GoodsStatusEnum::ON_SALE]);
// 获取商品列表 // 获取商品列表
$list = parent::getList($params, $listRows); $list = parent::getList($params, $listRows);
if ($list->isEmpty()) { if ($list->isEmpty()) {
return $list; return $list;
} }

@ -15,10 +15,14 @@ namespace app\api\service;
use app\api\model\Goods as GoodsModel; use app\api\model\Goods as GoodsModel;
use app\api\model\Setting as SettingModel; use app\api\model\Setting as SettingModel;
use app\api\model\GoodsSku as GoodsSkuModel; use app\api\model\GoodsSku as GoodsSkuModel;
use app\api\model\Category as CategoryModel;
use app\common\model\store\Shop as ShopModel;
use app\api\service\sharp\Active as ActiveService;
use app\common\enum\Setting as SettingEnum; use app\common\enum\Setting as SettingEnum;
use app\common\service\Goods as GoodsService; use app\common\service\Goods as GoodsService;
use app\api\model\sharp\Active as SharpActiveModel; use app\api\model\sharp\Active as SharpActiveModel;
use app\api\model\sharp\ActiveTime as ActiveTimeModel; use app\api\model\sharp\ActiveTime as ActiveTimeModel;
use app\api\controller\sharp\Goods as miaosha;
/** /**
* 商品服务类 * 商品服务类
@ -53,6 +57,7 @@ class Goods extends GoodsService
{ {
// 获取商品推荐数据 // 获取商品推荐数据
$setting = $this->getRecommendedSetting(); $setting = $this->getRecommendedSetting();
// 获取商品数据 // 获取商品数据
$model = new GoodsModel; $model = new GoodsModel;
if ($setting['params']['source'] === 'choice') { if ($setting['params']['source'] === 'choice') {
@ -74,65 +79,160 @@ class Goods extends GoodsService
} }
//大牌正品列表 //大牌正品列表
public function brandList(): array public function brandList()
{ {
$page = (int)$_GET['page'];
$model = new GoodsModel; $model = new GoodsModel;
$list = $model->where([
'is_delete' => 0, $goodsList = $model->getList([
'status' => 10, 'status' => 10,
'is_brand' => 1, 'is_delete' => 0,
'store_id' => $_GET['store_id'] 'is_brand' => $_GET['is_brand'],
])->select()->toArray(); 'is_new' => $_GET['is_new'],
'store_id' => $_GET['store_id'],
'categoryId' => (int)$_GET['categoryId'],
], 15);
if (empty($goodsList) && $goodsList->isEmpty()) {
return [];
}
$list = $goodsList->toArray();
$list['data'] = $this->formatGoodsList($goodsList);
return $list; return $list;
// $list = $model->where([
// 'is_delete' => 0,
// 'status' => 10,
// 'is_brand' => 1,
// 'store_id' => $_GET['store_id']
// ])->field('goods_name,sales_initial,sales_actual,goods_id,goods_price_min')->paginate($page)->toArray();
} }
//新品首发
public function newList(): array //排行榜分类列表 一级
public function charts(): array
{ {
$model = new GoodsModel; $model = new CategoryModel;
$list = $model->where([ $list = $model->where([
'is_delete' => 0, 'parent_id' => 0,
'status' => 10, 'status' => 1,
'is_new' => 1, 'is_paihang' => 1,
'store_id' => $_GET['store_id'] 'store_id' => $_GET['store_id']
])->select()->toArray(); ])->order('category_id desc')->select()->toArray();
return $list; return $list;
} }
//同城信息
public function cityInfo(): array public function chartsGoodsList()
{ {
$model = new GoodsModel; $model = new GoodsModel;
$list = $model->where([
'is_delete' => 0, $goodsList = $model->getList([
'status' => 10, 'status' => 10,
'is_brand' => 1, 'is_delete' => 0,
'store_id' => $_GET['store_id'] 'paihang' => 1,
])->select()->toArray(); 'store_id' => $_GET['store_id'],
'categoryId' => (int)$_GET['categoryId'],
], 15);
if (empty($goodsList) && $goodsList->isEmpty()) {
return [];
}
$list = $goodsList->toArray();
$list['data'] = $this->formatGoodsList($goodsList);
return $list; return $list;
} }
//抢购会场列表 public function chartsGoodsJing(): array
public function panicList()
{ {
$model = new SharpActiveModel; $model = new CategoryModel;
$list = $model->alias('a')
->join('sharpActiveTime', 'a.active_id = sharpActiveTime.active_id', 'left')->where([ $list = $model->where([
'a.is_delete' => 0, 'parent_id' => 0,
'a.status' => 1, 'status' => 1,
'a.store_id' => $_GET['store_id'], 'is_paihang' => 1,
'sharpActiveTime.status' => 1, 'store_id' => $_GET['store_id']
])->select()->toArray(); ])->order('category_id desc')->select()->toArray();
$model = new GoodsModel;
foreach ($list as &$v) { foreach ($list as &$v) {
$v['active_date'] = date('Y-m-d H:i:s', $v['active_date']); $goodsList = $model->getList([
'status' => 10,
'is_delete' => 0,
'paihang' => 1,
'store_id' => $_GET['store_id'],
'categoryId' => $v['category_id'],
], 3);
$list2 = $goodsList->toArray()['data'];
$v['goods_list'] = $this->formatGoodsList($list2);
} }
return $list; return $list;
} }
//同城信息
public function cityInfo(): array
{
$model = new ShopModel;
$list = $model->where([
'is_delete' => 0,
'status' => 1,
'store_id' => $_GET['store_id'],
'is_main' => 1,
])->field('shop_name,star,shop_hours,
province_id,city_id,region_id,shop_id,address,latitude,longitude')->find()->toArray();
return $list;
}
// //抢购会场列表
// public function panicList()
// {
// //只拉第一个活动
// $model = new SharpActiveModel;
//
// $info = $model->alias('a')
// ->where([
// 'a.is_delete' => 0,
// 'a.status' => 1,
// 'a.store_id' => $_GET['store_id'],
//// 'sharpActiveTime.status' => 1,
// ])->order(['a.active_id' => 'desc'])->find()->toArray();
// if (empty($info)) {
// return [];
// }
//
// $info['create_date'] = date('Y-m-d H:i:s', $info['active_date']);
// $aid = $info['active_id'];
// $time = ActiveTimeModel::where([
// 'status' => 1,
// 'active_id' => $aid,
// ])->order('active_time asc')->select()->toArray();
// if (empty($time)) {
// return [];
// }
//
// // 获取秒杀活动会场首页数据
// $service = new ActiveService;
//
//// $miaosha = $service->getGoodsListByActiveTimeId((int)$time[0]['active_time_id'])->toArray()['data'] ?? [];
//
// $info['create_time'] = date('Y-m-d', $info['active_date']) . ' ' . $time[0]['active_time'] . ':00';
// $info['lats_time'] = strtotime($info['create_time']) - time();
// $list['info'] = $info;
// $list['detail'] = $time;
//
// return $list;
// }
/** /**
* 格式化商品列表 * 格式化商品列表
* @param $goodsList * @param $goodsList
@ -152,11 +252,13 @@ class Goods extends GoodsService
'line_price_min' => $goods['line_price_min'], 'line_price_min' => $goods['line_price_min'],
'line_price_max' => $goods['line_price_max'], 'line_price_max' => $goods['line_price_max'],
'goods_sales' => $goods['goods_sales'], 'goods_sales' => $goods['goods_sales'],
'remaizhishu' => $goods['remaizhishu'],
]; ];
} }
return $data; return $data;
} }
/** /**
* 获取商品推荐设置 * 获取商品推荐设置
* @return array * @return array

@ -178,6 +178,7 @@ class Goods extends BaseModel
public function getList(array $param = [], int $listRows = 15) public function getList(array $param = [], int $listRows = 15)
{ {
// 筛选条件 // 筛选条件
$query = $this->getQueryFilter($param); $query = $this->getQueryFilter($param);
// 设置显示的销量 goods_sales // 设置显示的销量 goods_sales
$query->field(['(sales_initial + sales_actual) as goods_sales']); $query->field(['(sales_initial + sales_actual) as goods_sales']);
@ -190,6 +191,7 @@ class Goods extends BaseModel
->where('is_delete', '=', 0) ->where('is_delete', '=', 0)
->order($sort) ->order($sort)
->paginate($listRows); ->paginate($listRows);
// 整理列表数据并返回 // 整理列表数据并返回
return $this->setGoodsListData($list); return $this->setGoodsListData($list);
} }
@ -232,6 +234,7 @@ class Goods extends BaseModel
'goodsNo' => null, // 商品编码 'goodsNo' => null, // 商品编码
'status' => 0, // 商品状态(0全部 10上架 20下架) 'status' => 0, // 商品状态(0全部 10上架 20下架)
]); ]);
// 实例化新查询对象 // 实例化新查询对象
$query = $this->getNewQuery(); $query = $this->getNewQuery();
// 筛选条件 // 筛选条件
@ -246,18 +249,43 @@ class Goods extends BaseModel
} }
// 商品状态 // 商品状态
$params['status'] > 0 && $filter[] = ['status', '=', (int)$params['status']]; $params['status'] > 0 && $filter[] = ['status', '=', (int)$params['status']];
$a = 1;
// 商品分类 // 商品分类
if ($params['categoryId'] > 0) { if ($params['categoryId'] > 0) {
// 关联商品与分类关系记录表 // 关联商品与分类关系记录表
$GoodsCategoryRelName = (new GoodsCategoryRelModel())->getName(); $GoodsCategoryRelName = (new GoodsCategoryRelModel())->getName();
$query->join($GoodsCategoryRelName, "{$GoodsCategoryRelName}.goods_id = {$this->name}.goods_id"); $query->join($GoodsCategoryRelName, "{$GoodsCategoryRelName}.goods_id = {$this->name}.goods_id");
// 设置分类ID条件 // 设置分类ID条件
$query->where('goods_category_rel.category_id', '=', (int)$params['categoryId']); // $query->where('goods_category_rel.category_id', '=', (int)$params['categoryId']);
$query->where([
'goods_category_rel.category_id' => (int)$params['categoryId'],
'goods.store_id' => (int)$params['store_id'],
]);
$a = 1;
} }
// 商品名称 // 商品名称
!empty($params['goodsName']) && $filter[] = ['goods_name', 'like', "%{$params['goodsName']}%"]; !empty($params['goodsName']) && $filter[] = ['goods_name', 'like', "%{$params['goodsName']}%"];
// 商品编码 // 商品编码
!empty($params['goodsNo']) && $filter[] = ['goods_no', 'like', "%{$params['goodsNo']}%"]; !empty($params['goodsNo']) && $filter[] = ['goods_no', 'like', "%{$params['goodsNo']}%"];
//wmc
if (!empty($param['is_brand'])) {
$filter[] = ['is_brand', '=', $param['is_brand']];
}
if (!empty($param['is_new'])) {
$filter[] = ['is_new', '=', $param['is_new']];
}
if (!empty($param['store_id']) && $a == 0) {
$filter[] = ['store_id', '=', $param['store_id']];
}
if (!empty($param['paihang'])) {
$filter[] = ['paihang', '>', 0];
$query->order('paihang asc');
}
// 实例化新查询对象 // 实例化新查询对象
return $query->where($filter); return $query->where($filter);
} }
@ -277,6 +305,7 @@ class Goods extends BaseModel
foreach ($list as &$goods) { foreach ($list as &$goods) {
$goods = $this->setGoodsData($goods, $callback); $goods = $this->setGoodsData($goods, $callback);
} }
return $list; return $list;
} }

Loading…
Cancel
Save