87 lines
2.1 KiB
PHP
87 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace app\api\logic;
|
|
|
|
use app\common\basics\Logic;
|
|
use app\common\model\groupbuy\GroupbuyGoods;
|
|
use app\common\server\UrlServer;
|
|
use app\common\model\groupbuy\GroupbuyConfig;
|
|
|
|
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)
|
|
->order("gu.activity_price asc")
|
|
->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']);
|
|
}
|
|
$lists = [];
|
|
|
|
$data = GroupbuyConfig::select();
|
|
$config = array();
|
|
if (!empty($data)) {
|
|
$result = $data->toArray();
|
|
foreach ($result as &$v) {
|
|
if ($v['name'] == 'service') {
|
|
$v['value'] = explode(',', $v['value']);
|
|
}
|
|
$config[$v['name']] = $v['value'];
|
|
}
|
|
}
|
|
|
|
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']),
|
|
'config' => $config,
|
|
];
|
|
|
|
}
|
|
|
|
public static function isGroupbuy($item_id){
|
|
|
|
$where = [
|
|
'item_id'=>$item_id,
|
|
'status'=>1,
|
|
'del'=>1
|
|
];
|
|
$groupBuy = GroupbuyGoods::where($where)->find();
|
|
|
|
return $groupBuy;
|
|
|
|
}
|
|
|
|
|
|
}
|