73 lines
2.1 KiB
PHP
73 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Yunshop\MinApp\Backend\Controllers;
|
|
|
|
|
|
use app\common\components\BaseController;
|
|
use Yunshop\MinApp\Common\Models\WechatAttachmentNewsModel;
|
|
use Yunshop\MinApp\Common\Models\WechatNewsModel;
|
|
use Yunshop\MinApp\Common\Services\WechatAttachment;
|
|
use Yunshop\Wechat\admin\material\model\WechatAttachmentNews;
|
|
use Yunshop\MinApp\Common\Models\AttachmentModel;
|
|
|
|
|
|
class NewsController extends BaseController
|
|
{
|
|
|
|
public function index()
|
|
{
|
|
return view('Yunshop\MinApp::news',[]);
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取图文数据
|
|
*/
|
|
public function getNews()
|
|
{
|
|
$search = request()->search;
|
|
$page = request()->page ?: 0;
|
|
if (config('app.framework') == 'platform') {
|
|
if (!app('plugins')->isEnabled('wechat')) {
|
|
return $this->errorJson('没有开启公众号插件');
|
|
}
|
|
$data = WechatAttachmentNewsModel::getAttachmentWechatNews($page,$search)->toArray();
|
|
} else {
|
|
$data = AttachmentModel::getAttachmentWechatNews($search)->paginate(20)->toArray();
|
|
}
|
|
|
|
foreach ($data['data'] as $key => &$attachment) {
|
|
if (!$attachment['has_many_wechat_news']){
|
|
array_splice($data['data'] , $key, 1);
|
|
}
|
|
foreach ($attachment['has_many_wechat_news'] as &$has_many_wechat_news) {
|
|
if (strpos($has_many_wechat_news['thumb_url'],'http') === 0) {
|
|
$has_many_wechat_news['thumb_url'] = yz_tomedia($has_many_wechat_news['thumb_url']);// yzWebFullUrl('plugin.wechat.admin.material.controller.material.getWechatImageResource',['attachment'=>$has_many_wechat_news['thumb_url']]);
|
|
} else if(strpos($attachment,'image') === 0) {
|
|
$has_many_wechat_news['thumb_url'] = yz_tomedia($has_many_wechat_news['thumb_url'],true);
|
|
}
|
|
}
|
|
}
|
|
return $this->successJson('success',$data);
|
|
}
|
|
|
|
|
|
public function save()
|
|
{
|
|
$data = request()->data;
|
|
if ($data) {
|
|
if (\Setting::set('plugin.min_app_news', $data)) {
|
|
return $this->successJson('设置成功');
|
|
}
|
|
return $this->errorJson('保存失败');
|
|
}
|
|
}
|
|
|
|
public function getData()
|
|
{
|
|
$set = \Setting::get('plugin.min_app_news');
|
|
$set['thumb_url'] = yz_tomedia($set['thumb_url']);
|
|
return $this->successJson('ok',$set);
|
|
}
|
|
|
|
} |