后端添加本地生活商品订单
This commit is contained in:
parent
73ba8e50d6
commit
0a46fcd6bb
29
app/api/controller/GroupBuyGoods.php
Normal file
29
app/api/controller/GroupBuyGoods.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\logic\GroupBuyLogic;
|
||||
use app\common\basics\Api;
|
||||
use app\common\server\JsonServer;
|
||||
|
||||
class GroupBuyGoods extends Api
|
||||
{
|
||||
public $like_not_need_login = ['getGroupBuyGoods',];
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* getGroupBuyGoods
|
||||
* 商品抢购列表
|
||||
*/
|
||||
public function getGroupBuyGoods(){
|
||||
|
||||
$get = $this->request->get();
|
||||
$get['page_no'] = $this->page_no;
|
||||
$get['page_size'] = $this->page_size;
|
||||
$data = GroupBuyLogic::getGroupBuyGoods($get);
|
||||
|
||||
return JsonServer::success('', $data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,6 +27,7 @@ use app\common\model\team\TeamActivity;
|
||||
use app\common\model\team\TeamFound;
|
||||
use app\common\model\team\TeamGoods;
|
||||
use app\common\model\user\UserLevel;
|
||||
use app\common\model\groupbuy\GroupbuyGoods;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
use think\facade\Db;
|
||||
@ -213,6 +214,8 @@ class GoodsLogic extends Logic
|
||||
];
|
||||
// 检查商品是否在参与活动,替换商品价格
|
||||
$goodsDetailArr = self::checkActivity($goodsDetailArr);
|
||||
// 检查商品是否参与抢购活动,替换商品价格、库存。
|
||||
$goodsDetailArr = self::rushBuy($goodsDetailArr);
|
||||
// 是否收藏
|
||||
$goodsDetailArr['is_collect'] = 0;
|
||||
if($userId) { // 非游客
|
||||
@ -1062,4 +1065,53 @@ class GoodsLogic extends Logic
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public static function rushBuy($goods){
|
||||
|
||||
// 判断是否是秒杀中的商品
|
||||
$GroupbuyGoods = GroupbuyGoods::where([
|
||||
['del', '=', 1],
|
||||
['goods_id', '=', $goods['id']],
|
||||
['status', '=', 1],
|
||||
])->select()->toArray();
|
||||
|
||||
// 判断此商品是否为抢购商品
|
||||
if(!$GroupbuyGoods){
|
||||
return $goods;
|
||||
}
|
||||
|
||||
foreach($GroupbuyGoods as $item) {
|
||||
// 获取该商品的秒杀信息
|
||||
$GroupbuyGoods_info = GroupbuyGoods::where([
|
||||
'goods_id' => $goods['id'],
|
||||
])->column('goods_id,item_id,activity_price', 'item_id');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 确定是抢购商品
|
||||
// 先将商品市场价换成原SKU最小价
|
||||
$goods['market_price'] = $goods['min_price'];
|
||||
// 替换活动价
|
||||
foreach($goods['goods_item'] as &$item) {
|
||||
|
||||
// 商品价格替换为最小的秒杀价
|
||||
if($goods['min_price'] > $GroupbuyGoods_info[$item['id']]['activity_price']) {
|
||||
$goods['min_price'] = $GroupbuyGoods_info[$item['id']]['activity_price'];
|
||||
}
|
||||
// 原市场价替换为原SKU售价
|
||||
$item['market_price'] = $item['price'];
|
||||
// SKU替换抢购价
|
||||
$item['price'] = $GroupbuyGoods_info[$item['id']]['activity_price'];
|
||||
}
|
||||
|
||||
$today_date = date('Y-m-d');
|
||||
$goods['activity'] = [
|
||||
'type' => 2,
|
||||
'type_desc' => '抢购商品',
|
||||
];
|
||||
return $goods;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
57
app/api/logic/GroupBuyLogic.php
Normal file
57
app/api/logic/GroupBuyLogic.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\groupbuy\GroupbuyGoods;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
class GroupBuyLogic extends Logic
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $get
|
||||
* @return array
|
||||
* 抢购商品列表
|
||||
*/
|
||||
public static function getGroupBuyGoods($get):array
|
||||
{
|
||||
$where = [
|
||||
'gu.del'=>'1',
|
||||
'gu.status'=> '1'
|
||||
];
|
||||
|
||||
$field = 'gu.*,g.id as goods_id,g.name as goods_name,g.image as goods_image,g.min_price as goods_min_price';
|
||||
|
||||
//查询抢购商品
|
||||
$lists = GroupbuyGoods::alias('gu')
|
||||
->leftJoin('goods g', 'g.id=gu.goods_id')
|
||||
->group('g.id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
//分页处理
|
||||
$count = count($lists);
|
||||
$index = ($get['page_no']-1) * $get['page_size'];
|
||||
$lists = array_slice($lists, $index, $get['page_size']);
|
||||
|
||||
//处理列表数据
|
||||
foreach($lists as &$item) {
|
||||
// 图片加域名
|
||||
$item['goods_image'] = UrlServer::getFileUrl($item['goods_image']);
|
||||
}
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists,
|
||||
'page_no' => $get['page_no'],
|
||||
'page_size' => $get['page_size'],
|
||||
'more' => is_more($count, $get['page_no'], $get['page_size'])
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user