Files
chazhi_shop_backend/app/admin/logic/SelectLinkLogic.php
2026-04-14 17:46:22 +08:00

213 lines
6.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | LikeShop100%开源免费商用电商系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | Gitee下载https://gitee.com/likemarket/likeshopv2
// | 访问官网https://www.likemarket.net
// | 访问社区https://home.likemarket.net
// | 访问手册http://doc.likemarket.net
// | 微信公众号:好象科技
// | 好象科技开发团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | Author: LikeShopTeam
// +----------------------------------------------------------------------
namespace app\admin\logic;
use app\common\enum\MenuEnum;
use app\common\enum\TeamEnum;
use app\common\model\activity_area\ActivityArea;
use app\common\model\goods\Goods;
use app\common\model\goods\GoodsCategory as GoodsCategoryModel;
use app\common\model\seckill\SeckillGoods;
use app\common\model\shop\Shop;
use app\common\model\team\TeamActivity;
use app\common\model\team\TeamFound;
use app\common\model\team\TeamJoin;
use app\common\server\UrlServer;
class SelectLinkLogic
{
/**
* @notes 获取基础页面
*/
public static function getBasePage()
{
return [
'基础页面' => MenuEnum::getMenuContent(1, true),
'个人中心' => MenuEnum::getMenuContent(2, true),
'分销' => MenuEnum::getMenuContent(3, true),
];
}
/**
* @notes 获取普通商品
*/
public static function getOrdinaryGoods($get)
{
$where[] = ['del','=',0];
if(isset($get['goods_name']) && $get['goods_name']){
$where[] = ['name','like','%'.$get['goods_name'].'%'];
}
$lists = Goods::where($where)
->paginate(['list_rows'=>$get['limit'],'page'=>$get['page']]);
$list = $lists->items();
foreach ($list as $key => $goods){
$price = $goods['min_price'].'~'.$goods['max_price'];
if($goods['min_price'] !== $goods['max_price']){
$price = $goods['min_price'];
}
$list[$key]['price'] = $price;
}
$count = $lists->total();
return ['count'=>$count,'lists'=>$list];
}
/**
* @notes 获取平台商品分类
*/
public static function getPlatformGoodsCategory($get)
{
$lists = GoodsCategoryModel::field('id,name')
->where(['level'=>1,'is_show'=>1,'del'=>0])
->order('sort', 'asc')
->select()
->toArray();
$count = GoodsCategoryModel::where(['level'=>1,'is_show'=>1,'del'=>0])->count();
return ['count'=>$count,'lists'=>$lists];
}
/**
* @notes 获取商家列表
*/
public static function getShopList($get)
{
$where = [
['del', '=', 0],
['del', '=', 0]
];
$model = new Shop();
$lists = $model->field('id,name')
->where($where)
->order('id', 'desc')
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
}
/**
* @notes 获取活动专区
*/
public static function getActivityArea($get)
{
$where[] = ['del', '=', 0];
$where[] = ['status', '=', 1];
$lists = ActivityArea::where($where)
->field('id,name')
->page($get['page'], $get['limit'])
->select();
$count = ActivityArea::where($where)
->count();
return ['count' => $count, 'lists' => $lists];
}
/**
* @notes 获取秒杀商品
*/
public static function getSeckillGoods($get)
{
$where = [
['sg.del', '=', 0],
];
// 商品名称
if(isset($get['goods_name']) && !($get['goods_name'] == '')) {
$where[] = ['g.name', 'like', '%'.trim($get['goods_name']).'%'];
}
$lists = SeckillGoods::alias('sg')
->leftJoin('goods g', 'sg.goods_id=g.id')
->field('sg.seckill_id,g.name,g.image,g.min_price,g.max_price,start_date,end_date,g.id')
->where($where)
->group('sg.goods_id')
->order(['sg.id' => 'desc'])
->select()
->toArray();
foreach($lists as &$item) {
// 秒杀价格
$price = SeckillGoods::where([
'del' => 0,
'seckill_id' => $item['seckill_id'],
'goods_id' => $item['id'],
'start_date' => $item['start_date'],
'end_date' => $item['end_date'],
])->column('price', 'id');
$seckill_min_price = min($price);
$seckill_max_price = max($price);
$item['seckill_price'] = $seckill_min_price == $seckill_max_price ? '¥ ' .$seckill_min_price : '¥ '. $seckill_min_price . ' ~ ¥ ' . $seckill_max_price;
// 商品价格
$item['goods_price'] = $item['min_price'] == $item['max_price'] ? '¥ ' .$item['min_price'] : '¥ '. $item['min_price'] .' ~ ¥ '. $item['max_price'];
}
// 分页
$count = count($lists);
$index = ($get['page'] -1) * $get['limit'];
$lists = array_slice($lists, $index, $get['limit']);
return ['count' => $count,'lists' => $lists];
}
/**
* @notes 获取拼团商品
*/
public static function getTeamGoods($get)
{
$where[] = ['T.del', '=', 0];
$where[] = ['T.status', '=', 1];
if (!empty($get['goods_name']) and $get['goods_name']) {
$where[] = ['G.name', 'like', '%'.$get['goods_name'].'%'];
}
$model = new TeamActivity();
$lists = $model->alias('T')->field('G.id,G.name,G.image,TG.team_price')
->where($where)
->join('goods G', 'G.id = T.goods_id')
->join('team_goods TG', 'TG.team_id = T.id')
->paginate([
'page' => $get['page'] ?? 1,
'list_rows' => $get['limit'] ?? 20,
'var_page' => 'page'
])->toArray();
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
}
}