| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689 |
- <?php
- /**
- * Created by PhpStorm.
- * User: weifeng
- * Date: 2020-02-04
- * Time: 10:10
- *
- * .--, .--,
- * ( ( \.---./ ) )
- * '.__/o o\__.'
- * {= ^ =}
- * > - <
- * / \
- * // \\
- * //| . |\\
- * "'\ /'"_.-~^`'-.
- * \ _ /--' `
- * ___)( )(___
- * (((__) (__))) 梦之所想,心之所向.
- */
- namespace app\backend\modules\upload\controllers;
- use app\backend\modules\upload\models\CoreAttach;
- use app\common\components\BaseController;
- use app\common\exceptions\ShopException;
- use app\common\services\ImageZip;
- use app\common\services\upload\UploadService;
- use app\platform\modules\system\models\SystemSetting;
- use getID3;
- class UploadController extends BaseController
- {
- protected $isPublic = true;
- protected $uniacid;
- public function __construct()
- {
- $this->uniacid = \YunShop::app()->uniacid ?: 0;
- }
- public function upload()
- {
- $file = request()->file('file');
- $type = request()->upload_type;
- if (!$file) {
- return $this->errorJson('文件上传失败.');
- }
- if (!$file->isValid()) {
- return $this->errorJson('文件上传失败.');
- }
- $auth_uid = \Auth::guard('admin')->user()->uid?:1;
- global $_W;
- // 获取文件相关信息
- $originalName = $file->getClientOriginalName(); // 文件原名
- $realPath = $file->getRealPath(); //临时文件的绝对路径
- $ext = $file->getClientOriginalExtension(); //文件后缀
- $uploadService = new UploadService();
- $upload_setting = $uploadService->getSetting();
- if ($type == 'image') {
- try {
- $upload_res = $uploadService->upload($file, $type);
- } catch (ShopException $exception) {
- return $this->errorJson($exception->getMessage());
- }
- if (config('app.framework') == 'platform') {
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => $auth_uid,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 1,
- 'module_upload_dir' => '',
- 'group_id' => intval($this->uniacid),
- 'upload_type' => $upload_setting['remote']['type'],
- 'tag_id' => 0
- ];
- \app\platform\modules\application\models\CoreAttach::create($data);
- return $this->successJson('上传成功', [
- 'name' => $originalName,
- 'ext' => $ext,
- 'filename' => $upload_res['file_name'],
- 'attachment' => $upload_res['relative_path'],
- 'url' => $upload_res['absolute_path'],
- 'is_image' => 1,
- 'filesize' => 'null',
- 'group_id' => intval($this->uniacid)
- ]);
- } else {
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => isset($_W['uid']) ? $_W['uid'] : 1,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 1,
- 'createtime' => TIMESTAMP,
- 'module_upload_dir' => '',
- 'group_id' => 0,
- ];
- CoreAttach::create($data);
- $info = array(
- 'name' => $originalName,
- 'ext' => $ext,
- 'filename' => $upload_res['file_name'],
- 'attachment' => $upload_res['relative_path'],
- 'url' => $upload_res['absolute_path'],
- 'is_image' => 1,
- 'filesize' => 'null',
- );
- if (request()->is_interface == 1) {
- return $this->successJson('上传成功',$info);
- }
- $info['state'] = 'SUCCESS';
- die(json_encode($info));
- }
- } elseif ($type == 'video') {
- try {
- $upload_res = $uploadService->upload($file, $type, 'videos');
- } catch (ShopException $exception) {
- return $this->errorJson($exception->getMessage());
- }
- if (config('app.framework') == 'platform') {
- $getID3 = new getID3();
- $ThisFileInfo = $getID3->analyze($realPath); //分析文件,$path为音频文件的地址
- $timeline = $ThisFileInfo['playtime_seconds']; //这个获得的便是音频文件的时长
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => $auth_uid,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 3,
- 'module_upload_dir' => '',
- 'group_id' => intval($this->uniacid),
- 'upload_type' => $upload_setting['remote']['type'],
- 'timeline' => $timeline
- ];
- \app\platform\modules\application\models\CoreAttach::create($data);
- return $this->successJson('上传成功', [
- 'name' => $originalName,
- 'ext' => $ext,
- 'filename' => $upload_res['file_name'],
- 'attachment' => $upload_res['relative_path'],
- 'url' => $upload_res['absolute_path'],
- 'is_image' => 0,
- 'filesize' => 'null',
- 'group_id' => intval($this->uniacid)
- ]);
- } else {
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => isset($_W['uid']) ? $_W['uid'] : 1,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 3,
- 'createtime' => TIMESTAMP,
- 'module_upload_dir' => '',
- 'group_id' => 0,
- ];
- CoreAttach::create($data);
- $info = array(
- 'name' => $originalName,
- 'ext' => $ext,
- 'filename' => $upload_res['file_name'],
- 'attachment' => $upload_res['relative_path'],
- 'url' => $upload_res['absolute_path'],
- 'is_image' => 0,
- 'filesize' => 'null',
- );
- if (request()->is_interface == 1) {
- return $this->successJson('上传成功',$info);
- }
- $info['state'] = 'SUCCESS';
- die(json_encode($info));
- }
- } elseif ($type == 'audio') {
- try {
- $upload_res = $uploadService->upload($file, $type, 'audios');
- } catch (ShopException $exception) {
- return $this->errorJson($exception->getMessage());
- }
- if (config('app.framework') == 'platform') {
- $getID3 = new getID3();
- $ThisFileInfo = $getID3->analyze($realPath); //分析文件,$path为音频文件的地址
- $timeline = $ThisFileInfo['playtime_seconds']; //这个获得的便是音频文件的时长
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => $auth_uid,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 3,
- 'module_upload_dir' => '',
- 'group_id' => intval($this->uniacid),
- 'upload_type' => $upload_setting['remote']['type'],
- 'timeline' => $timeline,
- 'tag_id' => 0
- ];
- \app\platform\modules\application\models\CoreAttach::create($data);
- return $this->successJson('上传成功', [
- 'name' => $originalName,
- 'ext' => $ext,
- 'filename' => $upload_res['file_name'],
- 'attachment' => $upload_res['relative_path'],
- 'url' => $upload_res['absolute_path'],
- 'is_image' => 0,
- 'filesize' => 'null',
- 'group_id' => intval($this->uniacid)
- ]);
- } else {
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => isset($_W['uid']) ? $_W['uid'] : 1,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 3,
- 'createtime' => TIMESTAMP,
- 'module_upload_dir' => '',
- 'group_id' => 0,
- 'tag_id' => 0
- ];
- CoreAttach::create($data);
- $info = array(
- 'name' => $originalName,
- 'ext' => $ext,
- 'filename' => $upload_res['file_name'],
- 'attachment' => $upload_res['relative_path'],
- 'url' => $upload_res['absolute_path'],
- 'is_image' => 0,
- 'filesize' => 'null',
- );
- $info['state'] = 'SUCCESS';
- die(json_encode($info));
- }
- }
- return true;
- }
- public function fetch()
- {
- $url = trim(request()->url);
- $resp = ihttp_get($url);
- if (!$resp) {
- return $this->errorJson('提取文件失败');
- }
- if (strexists($resp['headers']['Content-Type'], 'image')) {
- switch ($resp['headers']['Content-Type']) {
- case 'application/x-jpg':
- case 'image/jpeg':
- $ext = 'jpg';
- break;
- case 'image/png':
- $ext = 'png';
- break;
- case 'image/gif':
- $ext = 'gif';
- break;
- default:
- return $this->errorJson('提取资源失败, 资源文件类型错误.');
- break;
- }
- } else {
- return $this->errorJson('提取资源失败, 仅支持图片提取.');
- }
- $originName = pathinfo($url, PATHINFO_BASENAME);
- $newOriginalName = md5($originName . str_random(6)) . '.' . $ext;
- //本地上传
- $result = \Storage::disk('image')->put($newOriginalName, $resp['content']);
- if (!$result) {
- return $this->successJson('上传失败');
- }
- $url = \Storage::disk('image')->url($newOriginalName);
- if (config('app.framework') == 'platform') {
- $remote = SystemSetting::settingLoad('remote', 'system_remote');
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => \Auth::guard('admin')->user()->uid,
- 'filename' => $newOriginalName,
- 'attachment' => $url,
- 'type' => 1,
- 'module_upload_dir' => '',
- 'group_id' => intval($this->uniacid),
- 'upload_type' => $remote['type'],
- 'tag_id' => 0
- ];
- \app\platform\modules\application\models\CoreAttach::create($data);
- //远程上传
- if ($remote['type'] != 0) {
- file_remote_upload($url, true, $remote);
- }
- return $this->successJson('上传成功', [
- 'img' => $url,
- 'img_url' => yz_tomedia($url),
- ]);
- } else {
- //全局配置
- global $_W;
- //公众号独立配置信息 优先使用公众号独立配置
- $uni_setting = app('WqUniSetting')->get()->toArray();
- if (!empty($uni_setting['remote']) && iunserializer($uni_setting['remote'])['type'] != 0) {
- $setting['remote'] = iunserializer($uni_setting['remote']);
- $remote = $setting['remote'];
- } else {
- $remote = $_W['setting']['remote'];
- }
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => $_W['uid'],
- 'filename' => $newOriginalName,
- 'attachment' => $url,
- 'type' => 1,
- 'createtime' => TIMESTAMP,
- 'module_upload_dir' => '',
- 'group_id' => 0,
- 'tag_id' => 0
- ];
- CoreAttach::create($data);
- //远程上传
- if ($remote['type'] != 0) {
- file_remote_upload_wq($url, true, $remote);
- }
- return $this->successJson('上传成功', [
- 'img' => $url,
- 'img_url' => yz_tomedia($url),
- ]);
- }
- }
- public function getImage()
- {
- if (config('app.framework') == 'platform') {
- $result = $this->getNewImage();
- } else {
- $result = $this->getWqImage();
- }
- return $this->successJson('ok', $result);
- }
- public function getWqImage()
- {
- $uid = \Auth::guard('admin')->user()->uid;
- $year = request()->year;
- $month = intval(request()->month);
- $page = max(1, intval(request()->page));
- $groupid = intval(request()->group_id);
- $page_size = 33;
- if ($page <= 1) {
- $page = 0;
- $offset = ($page)*$page_size;
- } else {
- $offset = ($page-1)*$page_size;
- }
- $core_attach = new CoreAttach;
- $core_attach = $core_attach->where(['uniacid'=>$this->uniacid,'type'=>1]);
- if (\YunShop::app()->isfounder !== true) {
- $core_attach = $core_attach->where('uid', $uid);
- }
- if ($groupid > 0) {
- $core_attach = $core_attach->where('group_id', $groupid);
- }
- if ($groupid == 0) {
- $core_attach = $core_attach->where('group_id', -1);
- }
- if ($year || $month) {
- $start_time = $month ? strtotime("{$year}-{$month}-01") : strtotime("{$year}-1-01");
- $end_time = $month ? strtotime('+1 month', $start_time) : strtotime('+12 month', $start_time);
- $core_attach = $core_attach->where('createtime', '>=', $start_time)->where('createtime', '<=', $end_time);
- }
- $count = $core_attach->count();
- $core_attach = $core_attach->orderby('createtime', 'desc')->offset($offset)->limit($page_size)->get();
- foreach ($core_attach as &$item) {
- $item['attach'] = yz_tomedia($item['attachment'], true);
- $item['url'] = $item['attach'];
- }
- if (request()->is_interface == 1) {
- return $this->successJson('上传成功',$core_attach);
- }
- $pager = pagination($count, $page, $page_size,'',$context = array('before' => 5, 'after' => 4, 'isajax' => '1'));
- $result = array('items' => $core_attach, 'pager' => $pager);
- iajax(0, $result);
- }
- public function getNewImage()
- {
- $uid = \Auth::guard('admin')->user()->uid;
- $search = [];
- if (request()->year != '不限') {
- $search['year'] = request()->year;
- }
- if(request()->month != '不限') {
- $search['month'] = request()->month;
- }
- $query = \app\platform\modules\application\models\CoreAttach::search($search)->where('type', 1);
- if (\YunShop::app()->isfounder !== true) {
- $query->where('uid', $uid);
- }
- //type = 1 图片
- $core_attach = $query->orderby('created_at', 'desc')->paginate(33);
- foreach ($core_attach as &$item) {
- $item['url'] = yz_tomedia($item['attachment']);
- unset($item['uid']);
- }
- return $core_attach;
- }
- public function getVideo()
- {
- if (config('app.framework') == 'platform') {
- $uid = \Auth::guard('admin')->user()->uid;
- $search = [];
- if (request()->year != '不限') {
- $search['year'] = request()->year;
- }
- if (request()->month != '不限') {
- $search['month'] = request()->month;
- }
- $query = \app\platform\modules\application\models\CoreAttach::search($search)->where(['type'=>3]);
- if (\YunShop::app()->isfounder !== true) {
- $query->where('uid', $uid);
- }
- //type = 3 视频
- $core_attach = $query->orderby('created_at', 'desc')->paginate(33);
- foreach ($core_attach as &$item) {
- $item['url'] = yz_tomedia($item['attachment']);
- unset($item['uid']);
- }
- return $this->successJson('ok', $core_attach);
- }
- global $_W;
- $uid = $_W['uid'];
- $core_attach = new CoreAttach();
- $page_index = max(1, request()->page);
- $page_size = 5;
- if ($page_index <=1) {
- $page_index = 0;
- $offset = $page_index * $page_size;
- } else {
- $offset = ($page_index - 1) * $page_size;
- }
- if (\YunShop::app()->isfounder !== true) {
- $core_attach = $core_attach->where('uid', $uid);
- }
- $total = $core_attach->count();
- $core_attach = $core_attach->where(['type'=>3,'uniacid'=>$this->uniacid])->orderby('createtime', 'desc')->offset($offset)->limit(24)->get();
- foreach ($core_attach as &$item) {
- $item['url'] = yz_tomedia($item['attachment']);
- unset($item['uid']);
- }
- $pager = pagination($total, 1, 24, '', $context = array('before' => 5, 'after' => 4, 'isajax' => '1'));
- $result = array('items' => $core_attach, 'pager' => $pager);
- iajax(0, $result);die;
- }
- public function delete()
- {
- $id = intval(request()->id);
- if (config('app.framework') == 'platform') {
- $remote = SystemSetting::settingLoad('remote', 'system_remote');
- $core_attach = \app\platform\modules\application\models\CoreAttach::where('id', $id);
- } else {
- global $_W;
- $remote = $_W['setting']['remote'];
- $core_attach = CoreAttach::where('id', $id);
- }
- $core_attach = $core_attach->first();
- if ($core_attach['upload_type']) {
- $remote_url = '';
- if ($remote['type'] == 2) {
- $remote_url = $remote['alioss']['url'];
- }
- if ($remote['type'] == 4) {
- $remote_url = $remote['cos']['url'];
- }
- if ($remote_url && strexists($core_attach['attachment'], $remote_url)) {
- $str_len = strlen($remote_url);
- $core_attach['attachment'] = substr($core_attach['attachment'], $str_len+1);
- }
- $status = file_remote_delete($core_attach['attachment'], $core_attach['upload_type'], $remote);
- } else {
- $status = file_delete($core_attach['attachment']);
- }
- if ($core_attach->delete()) {
- return $this->successJson('删除成功');
- } else {
- return $this->errorJson('删除数据表数据失败');
- }
- }
- public function jsUpload()
- {
- $file = request()->file('file');
- $type = request()->upload_type;
- if (!$file) {
- return $this->errorJson('请传入正确参数.');
- }
- if (!$file->isValid()) {
- return $this->errorJson('上传失败.');
- }
- $auth_uid = \Auth::guard('admin')->user()->uid ?: 1;
- global $_W;
- // 获取文件相关信息
- $originalName = $file->getClientOriginalName(); // 文件原名
- $realPath = $file->getRealPath(); //临时文件的绝对路径
- $ext = $file->getClientOriginalExtension(); //文件后缀
- $uploadService = new UploadService();
- $upload_setting = $uploadService->getSetting();
- if ($type == 'image') {
- $upload_res = $uploadService->upload($file, $type);
- if (config('app.framework') == 'platform') {
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => $auth_uid,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 1,
- 'module_upload_dir' => '',
- 'group_id' => intval($this->uniacid),
- 'upload_type' => $upload_setting['remote']['type'],
- 'tag_id' => 0
- ];
- \app\platform\modules\application\models\CoreAttach::create($data);
- } else {
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => isset($_W['uid']) ? $_W['uid'] : 1,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 1,
- 'createtime' => TIMESTAMP,
- 'module_upload_dir' => '',
- 'group_id' => 0,
- ];
- CoreAttach::create($data);
- }
- $info = [
- 'name' => $originalName,
- 'ext' => $ext,
- 'filename' => $upload_res['file_name'],
- 'attachment' => $upload_res['relative_path'],
- 'url' => $upload_res['absolute_path'],
- 'is_image' => 1,
- 'filesize' => 'null',
- 'group_id' => intval($this->uniacid),
- 'state' => 'SUCCESS'
- ];
- die(json_encode($info));
- } elseif ($type == 'video') {
- $upload_res = $uploadService->upload($file, $type, 'videos');
- if (config('app.framework') == 'platform') {
- $getID3 = new getID3();
- $ThisFileInfo = $getID3->analyze($realPath); //分析文件,$path为音频文件的地址
- $timeline = $ThisFileInfo['playtime_seconds']; //这个获得的便是音频文件的时长
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => $auth_uid,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 3,
- 'module_upload_dir' => '',
- 'group_id' => intval($this->uniacid),
- 'upload_type' => $upload_setting['remote']['type'],
- 'timeline' => $timeline
- ];
- \app\platform\modules\application\models\CoreAttach::create($data);
- } else {
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => isset($_W['uid']) ? $_W['uid'] : 1,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 3,
- 'createtime' => TIMESTAMP,
- 'module_upload_dir' => '',
- 'group_id' => 0,
- ];
- CoreAttach::create($data);
- }
- $info = [
- 'name' => $originalName,
- 'ext' => $ext,
- 'filename' => $upload_res['file_name'],
- 'attachment' => $upload_res['relative_path'],
- 'url' => $upload_res['absolute_path'],
- 'is_image' => 0,
- 'filesize' => 'null',
- 'group_id' => intval($this->uniacid),
- 'state' => 'SUCCESS'
- ];
- die(json_encode($info));
- } elseif ($type == 'audio') {
- $upload_res = $uploadService->upload($file, $type, 'audios');
- if (config('app.framework') == 'platform') {
- $getID3 = new getID3();
- $ThisFileInfo = $getID3->analyze($realPath); //分析文件,$path为音频文件的地址
- $timeline = $ThisFileInfo['playtime_seconds']; //这个获得的便是音频文件的时长
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => $auth_uid,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 3,
- 'module_upload_dir' => '',
- 'group_id' => intval($this->uniacid),
- 'upload_type' => $upload_setting['remote']['type'],
- 'timeline' => $timeline,
- 'tag_id' => 0
- ];
- \app\platform\modules\application\models\CoreAttach::create($data);
- } else {
- $data = [
- 'uniacid' => $this->uniacid,
- 'uid' => isset($_W['uid']) ? $_W['uid'] : 1,
- 'filename' => safe_gpc_html(htmlspecialchars_decode($originalName, ENT_QUOTES)),
- 'attachment' => $upload_res['relative_path'],
- 'type' => 3,
- 'createtime' => TIMESTAMP,
- 'module_upload_dir' => '',
- 'group_id' => 0,
- 'tag_id' => 0
- ];
- CoreAttach::create($data);
- }
- $info = [
- 'name' => $originalName,
- 'ext' => $ext,
- 'filename' => $upload_res['file_name'],
- 'attachment' => $upload_res['relative_path'],
- 'url' => $upload_res['absolute_path'],
- 'is_image' => 0,
- 'filesize' => 'null',
- 'group_id' => intval($this->uniacid),
- 'state' => 'SUCCESS',
- ];
- die(json_encode($info));
- }
- return true;
- }
- public function jsImage()
- {
- $year = intval(request()->year);
- $month = intval(request()->month);
- $page = max(1, intval(request()->page));
- $page_size = 24;
- if ($page <= 1) {
- $page = 0;
- $offset = $page * $page_size;
- } else {
- $offset = ($page - 1) * $page_size;
- }
- if (config('app.framework') == 'platform') {
- $core_attach = new \app\platform\modules\application\models\CoreAttach();
- $group_id = $this->uniacid;
- $create_time = 'created_at';
- $uid = \Auth::guard('admin')->user()->uid ?: 1;
- } else {
- $core_attach = new CoreAttach;
- $group_id = 0;
- $create_time = 'createtime';
- global $_W;
- $uid = $_W['uid'];
- }
- $core_attach = $core_attach->where(['uniacid'=>$this->uniacid,'group_id'=>$group_id,'type'=>1]);
- if (\YunShop::app()->isfounder !== true) {
- $core_attach = $core_attach->where('uid', $uid);
- }
- if ($year || $month) {
- $start_time = $month ? strtotime("{$year}-{$month}-01") : strtotime("{$year}-1-01");
- $end_time = $month ? strtotime('+1 month', $start_time) : strtotime('+12 month', $start_time);
- $core_attach = $core_attach->whereBetween($create_time, [$start_time, $end_time]);
- }
- $count = $core_attach->count();
- $core_attach = $core_attach->orderby($create_time, 'desc')->offset($offset)->limit($page_size)->get();
- foreach ($core_attach as &$item) {
- $item['url'] = yz_tomedia($item['attachment']);
- $item['attach'] = yz_tomedia($item['attachment']);
- }
- $pager = pagination($count, $page, $page_size,'',$context = array('before' => 5, 'after' => 4, 'isajax' => '1'));
- $result = array('items' => $core_attach, 'pager' => $pager);
- $array = [
- 'message' => [
- 'erron' => 0,
- 'message' => $result
- ],
- 'redirect' => '',
- 'type' => 'ajax'
- ];
- die(json_encode($array));
- }
- }
|