<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Photo\Admin\Controller; use Illuminate\Routing\Controller; use ModStart\Admin\Auth\AdminPermission; use ModStart\Admin\Concern\HasAdminQuickCRUD; use ModStart\Admin\Layout\AdminCRUDBuilder; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Exception\BizException; use ModStart\Core\Input\InputPackage; use ModStart\Core\Input\Request; use ModStart\Core\Input\Response; use ModStart\Core\Util\FileUtil; use ModStart\Core\Util\ImageUtil; use ModStart\Data\DataManager; use ModStart\Data\Event\DataFileUploadedEvent; use ModStart\Form\Form; use ModStart\Grid\GridFilter; use ModStart\Support\Concern\HasFields; use Module\Photo\Util\PhotoCategoryUtil; use Module\Photo\Util\PhotoUtil; class PhotoController extends Controller { use HasAdminQuickCRUD; protected function crud(AdminCRUDBuilder $a1cww) { $a1cww->init('photo')->field(function ($a1cww) { $a1cww->id('id', 'ID'); $a1cww->select('categoryId', '相册集')->optionModelTree('photo_category', 'id', 'pid', 'name'); $a1cww->text('title', '标题'); $a1cww->image('thumb', '封面'); $a1cww->image('url', '相册源')->listable(false); $a1cww->number('width', '宽度'); $a1cww->number('height', '高度'); $a1cww->display('created_at', L('Created At'))->listable(false); $a1cww->display('updated_at', L('Updated At'))->listable(false); })->gridFilter(function (GridFilter $q81IC) { $q81IC->eq('id', L('ID')); $q81IC->like('title', L('Title')); })->hookDeleting(function (Form $ukDy3) { $ukDy3->item()->each(function ($zEBpl) { DataManager::deleteByPath($zEBpl->thumb); DataManager::deleteByPath($zEBpl->url); }); })->defaultOrder(array('sort', 'asc'))->canSort(true)->canEdit(false)->canAdd(false)->canShow(false)->hookChanged(function (Form $ukDy3) { PhotoUtil::clearCache(); })->title('相册'); } public function upload() { if (Request::isPost()) { goto v7nFz; K4jOL: $q62oK = array(); goto YlIg8; YlIg8: $q62oK['categoryId'] = $fAvwi->getInteger('categoryId'); goto ceV2Q; NdZz5: $JG4tL = array('eventOpt' => array(DataFileUploadedEvent::OPT_IMAGE_COMPRESS_IGNORE => true, DataFileUploadedEvent::OPT_IMAGE_WATERMARK_IGNORE => true)); goto bo4Cd; ceV2Q: $q62oK['title'] = $fAvwi->getTrimString('title'); goto rGKzQ; sOt8p: @unlink($eKi06); goto ZUJCw; JpQkR: BizException::throwsIfResponseError($vvFM4); goto Z23gv; R3bj7: file_put_contents($eKi06, $KB2qL); goto Uxunx; QZGQT: $obXaA = $fAvwi->getTrimString('file'); goto EWTCV; dwqbp: $q62oK['height'] = $fAvwi->getInteger('height'); goto fnUQ3; ZD0Ef: $q62oK['url'] = $mYmng['data']['fullPath']; goto YmZD4; Qkgb7: ModelUtil::update('photo_category', $q62oK['categoryId'], array('photoCount' => ModelUtil::count('photo', array('categoryId' => $q62oK['categoryId'])))); goto ri7yE; ri7yE: PhotoCategoryUtil::clearCache(); goto S5gPH; StZ6t: $KB2qL = FileUtil::safeGetContent($t39ba['data']['path']); goto mgW_4; fnUQ3: $q62oK['size'] = $fAvwi->getInteger('size'); goto QZGQT; YmZD4: $q62oK['sort'] = ModelUtil::max('photo', 'sort', array('categoryId' => $q62oK['categoryId'])) + 1; goto RDfuZ; xEx2h: BizException::throwsIfResponseError($mYmng); goto Kj21F; VK5Rw: file_put_contents($iW0nH, $KB2qL); goto R3bj7; Uxunx: ImageUtil::limitSizeAndDetectOrientation($iW0nH, 10000, 10000); goto aKOb6; v7nFz: AdminPermission::demoCheck(); goto BRN6z; MtrBV: $zBvIU = FileUtil::extension($obXaA); goto UjBwn; bo4Cd: $mYmng = DataManager::upload('image', $q62oK['title'], FileUtil::safeGetContent($iW0nH), null, $JG4tL); goto xEx2h; mgW_4: DataManager::deleteDataTempByPath($obXaA); goto l843B; EWTCV: $t39ba = DataManager::preparePathForLocal($obXaA); goto IYiyA; RDfuZ: ModelUtil::insert('photo', $q62oK); goto Qkgb7; unnje: $eKi06 = FileUtil::generateLocalTempPath($zBvIU); goto VK5Rw; aKOb6: ImageUtil::limitSizeAndDetectOrientation($eKi06, 300, 300); goto NdZz5; l843B: @unlink($t39ba['data']['path']); goto MtrBV; S5gPH: return Response::jsonSuccessData($q62oK); goto tNV5d; BRN6z: $fAvwi = InputPackage::buildFromInput(); goto K4jOL; Z23gv: @unlink($iW0nH); goto sOt8p; Kj21F: $vvFM4 = DataManager::upload('image', $q62oK['title'], FileUtil::safeGetContent($eKi06), null, $JG4tL); goto JpQkR; ZUJCw: $q62oK['thumb'] = $vvFM4['data']['fullPath']; goto ZD0Ef; UjBwn: $iW0nH = FileUtil::generateLocalTempPath($zBvIU); goto unnje; rGKzQ: $q62oK['width'] = $fAvwi->getInteger('width'); goto dwqbp; IYiyA: if (Response::isError($t39ba)) { return Response::jsonError($t39ba['msg']); } goto StZ6t; tNV5d: } return view('module::Photo.View.admin.photo.upload'); } }