修改接口

This commit is contained in:
wangxiaowei 2024-08-09 04:45:50 +08:00
parent 981844a25a
commit a0ebd8e0a1
2 changed files with 31 additions and 15 deletions

@ -24,7 +24,8 @@ class MallNews extends Api
{ {
if($this->request->isGet()) { if($this->request->isGet()) {
$id = $this->request->get('id'); $id = $this->request->get('id');
$data = MallNewsLogic::detail($id); $mall_type = $this->request->get('mall_type');
$data = MallNewsLogic::detail($id, $mall_type);
return JsonServer::success('获取成功', $data); return JsonServer::success('获取成功', $data);
}else{ }else{
return JsonServer::error('请求方式错误'); return JsonServer::error('请求方式错误');

@ -9,6 +9,7 @@ use think\facade\Config;
use think\facade\Db; use think\facade\Db;
use app\common\model\MallNews; use app\common\model\MallNews;
use app\common\model\MallNewsFile; use app\common\model\MallNewsFile;
use app\common\model\MallNewsShop;
class MallNewsLogic extends Logic class MallNewsLogic extends Logic
{ {
@ -43,27 +44,41 @@ class MallNewsLogic extends Logic
]; ];
} }
public static function detail($id) public static function detail($id, $mall_type)
{ {
$mall_news = MallNews::with('files') if ($mall_type == 1) {
->where(['id' => $id, 'delete_time' => 0]) $mall_news = MallNewsShop::where(['id' => $id, 'delete_time' => 0])->find()->toArray();
->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();
}
if ($mall_news['shop_id'] > 0) { $file = MallNewsFile::where(['mall_news_shop_id' => $id])->field('mall_news_shop_id, src')->select()->toArray();
$mall_news['shop'] = Goods::where(['id' => $mall_news['shop_id']])->field('name, image, min_price')->find()->toArray(); foreach ($file as &$v) {
} $v['src'] = UrlServer::getFileUrl('uploads/images/' . $v['src']);
}
if (isset($mall_news['files'])) { $mall_news['files'] = $file;
foreach ($mall_news['files'] as &$v) { } else {
if ($mall_news['type'] == 0) { $mall_news = MallNews::with('files')
$v['src'] = UrlServer::getFileUrl('uploads/images/' . $v['src']); ->where(['id' => $id, 'delete_time' => 0])
} else { ->find()->toArray();
$v['src'] = Config::get('aliyunoss.domain') . self::$FILE_VIDEO_PATH . '/'. $v['src'];
if ($mall_news['shop_id'] > 0) {
$mall_news['shop'] = Goods::where(['id' => $mall_news['shop_id']])->field('name, image, min_price')->find()->toArray();
}
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'];
}
} }
} }
} }
return $mall_news; return $mall_news;
} }
private static function content(&$arg) private static function content(&$arg)