dlh_test_server/app/api/logic/MallNewsLogic.php

121 lines
4.7 KiB
PHP
Raw Normal View History

2024-08-03 10:04:14 +08:00
<?php
namespace app\api\logic;
use app\common\basics\Logic;
use app\common\model\goods\Goods;
use app\common\model\goods\GoodsSubsidy;
2024-08-03 10:04:14 +08:00
use app\common\server\UrlServer;
use think\facade\Config;
use think\facade\Db;
use app\common\model\MallNews;
use app\common\model\MallNewsFile;
2024-08-09 04:45:50 +08:00
use app\common\model\MallNewsShop;
2024-08-03 10:04:14 +08:00
class MallNewsLogic extends Logic
{
private static $FILE_VIDEO_PATH = 'mall_news/video';
public static function lists($page, $size)
{
$top = MallNews::with('files')
->where(['is_top' => 1, 'delete_time' => 0])
->order('sort desc, create_time desc')
->select();
self::content($top);
$list = MallNews::with('files')
->where(['is_top' => 0, 'delete_time' => 0])
->order('sort desc, create_time desc')
->page($page,$size)
->select();
self::content($list);
$count = MallNews::where(['is_top' => 0, 'delete_time' => 0])->count();
$more = is_more($count, $page, $size); //是否有下一页
return [
'list' => $list,
'page_no' => $page,
'page_size' => $size,
'count' => $count,
'more' => $more,
'top' => $top,
];
}
2024-08-09 04:45:50 +08:00
public static function detail($id, $mall_type)
2024-08-03 10:04:14 +08:00
{
2024-08-09 04:45:50 +08:00
if ($mall_type == 1) {
$mall_news = MallNewsShop::where(['id' => $id, 'delete_time' => 0])->find()->toArray();
if ($mall_news['shop_id'] > 0) {
$mall_news['shop'] = Goods::where(['id' => $mall_news['shop_id']])->field('name, image, min_price, subsidy_id')->find()->toArray();
// 获取返补比例, subsidy_id为0的就传递一个ID为4的固定ID
$mall_news['subsidy'] = (new GoodsSubsidy())->getSubsidyById($mall_news['shop']['subsidy_id'] > 0 ? $mall_news['shop']['subsidy_id'] : 4);
$mall_news['subsidy_txt'] = '最高返' . $mall_news['subsidy']['subsidy'];
2024-08-09 04:45:50 +08:00
}
2024-08-03 10:04:14 +08:00
2024-08-09 04:45:50 +08:00
$file = MallNewsFile::where(['mall_news_shop_id' => $id])->field('mall_news_shop_id, src')->select()->toArray();
foreach ($file as &$v) {
$v['src'] = UrlServer::getFileUrl('uploads/images/' . $v['src']);
}
$mall_news['files'] = $file;
} else {
$mall_news = MallNews::with('files')
->where(['id' => $id, 'delete_time' => 0])
->find()->toArray();
if ($mall_news['shop_id'] > 0) {
$mall_news['shop'] = Goods::where(['id' => $mall_news['shop_id']])->field('name, image, min_price')->find()->toArray();
// 获取返补比例, subsidy_id为0的就传递一个ID为4的固定ID
$mall_news['subsidy'] = (new GoodsSubsidy())->getSubsidyById($mall_news['shop']['subsidy_id'] > 0 ? $mall_news['shop']['subsidy_id'] : 4);
$mall_news['subsidy_txt'] = '最高返' . $mall_news['subsidy']['subsidy'];
2024-08-09 04:45:50 +08:00
}
2024-08-03 10:04:14 +08:00
2024-08-09 04:45:50 +08:00
if (isset($mall_news['files'])) {
foreach ($mall_news['files'] as &$v) {
if ($mall_news['type'] == 0) {
$v['src'] = UrlServer::getFileUrl('uploads/images/' . $v['src']);
} else {
$v['src'] = Config::get('aliyunoss.domain') . self::$FILE_VIDEO_PATH . '/'. $v['src'];
}
2024-08-03 10:04:14 +08:00
}
}
}
return $mall_news;
2024-08-09 04:45:50 +08:00
2024-08-03 10:04:14 +08:00
}
private static function content(&$arg)
{
foreach ($arg as &$v) {
2024-08-09 04:56:15 +08:00
if ($v['mall_type'] == 0) {
if ($v['shop_id'] > 0) {
$v['shop'] = Goods::field('name, image, min_price')->find($v['shop_id']);
}
2024-08-03 10:04:14 +08:00
2024-08-09 04:56:15 +08:00
if (isset($v['files'])) {
foreach ($v['files'] as &$v1) {
if ($v['type'] == 0) {
$v1['src'] = UrlServer::getFileUrl('uploads/images/' . $v1['src']);
} else {
$v1['src'] = Config::get('aliyunoss.domain') . self::$FILE_VIDEO_PATH . '/'. $v1['src'];
}
}
}
} else if ($v['mall_type'] == 1) {
$ids = explode(',', $v['mall_news_goods_id']);
foreach ($ids as $k => &$v2) {
$res = MallNewsFile::where('mall_news_shop_id', $v2)->field('mall_news_shop_id, src')->select()->toArray();
foreach ($res as &$v3) {
$v3['image'] = UrlServer::getFileUrl('uploads/images/' . $v3['src']);
2024-08-03 10:04:14 +08:00
}
2024-08-09 04:56:15 +08:00
$arr[$k] = $res;
2024-08-03 10:04:14 +08:00
}
2024-08-09 04:56:15 +08:00
$v['shop'] = $arr;
2024-08-03 10:04:14 +08:00
}
}
}
}