diff --git a/app/api/controller/MallNews.php b/app/api/controller/MallNews.php index 87ea591d..09312a63 100755 --- a/app/api/controller/MallNews.php +++ b/app/api/controller/MallNews.php @@ -24,7 +24,8 @@ class MallNews extends Api { if($this->request->isGet()) { $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); }else{ return JsonServer::error('请求方式错误'); diff --git a/app/api/logic/MallNewsLogic.php b/app/api/logic/MallNewsLogic.php index 68e47a1b..bd3910b8 100755 --- a/app/api/logic/MallNewsLogic.php +++ b/app/api/logic/MallNewsLogic.php @@ -9,6 +9,7 @@ use think\facade\Config; use think\facade\Db; use app\common\model\MallNews; use app\common\model\MallNewsFile; +use app\common\model\MallNewsShop; 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') - ->where(['id' => $id, 'delete_time' => 0]) - ->find()->toArray(); + 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')->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(); - } + $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']); + } - 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']; + $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(); + } + + 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; + } private static function content(&$arg)