dlh_test_server/app/api/logic/GroupBuyLogic.php

87 lines
2.3 KiB
PHP
Raw Normal View History

2024-09-25 14:09:04 +08:00
<?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;
2024-09-25 14:09:04 +08:00
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)
2024-10-02 17:36:34 +08:00
->order("gu.activity_price asc")
2024-09-25 14:09:04 +08:00
->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']);
}
$data = GroupbuyConfig::select();
$config = array();
if (!empty($data)) {
$result = $data->toArray();
foreach ($result as &$v) {
if ($v['name'] == 'end_time') {
$v['value'] = strtotime($v['value']);
}
2024-11-29 09:13:21 +08:00
if ($v['name'] == 'service' && $v['value']) {
$v['value'] = explode(',', $v['value']);
}
2024-11-29 09:13:21 +08:00
$config[$v['name']] = $v['value'];
}
}
2024-09-25 14:09:04 +08:00
return [
'count' => $count,
'lists' => $lists,
'page_no' => $get['page_no'],
'page_size' => $get['page_size'],
2024-09-28 15:44:33 +08:00
'more' => is_more($count, $get['page_no'], $get['page_size']),
'config' => $config,
2024-09-25 14:09:04 +08:00
];
}
2024-09-27 14:15:02 +08:00
public static function isGroupbuy($item_id){
$where = [
'item_id'=>$item_id,
'status'=>1,
'del'=>1
];
$groupBuy = GroupbuyGoods::where($where)->find();
return $groupBuy;
}
}