|
@@ -1,13 +1,17 @@
|
|
<?php
|
|
<?php
|
|
/**
|
|
/**
|
|
- * dfghfdhfgfghfg
|
|
|
|
|
|
+ * 梦想列表
|
|
* @author system
|
|
* @author system
|
|
* @version 1.0
|
|
* @version 1.0
|
|
- * @date 2017-06-01 05:20:51
|
|
|
|
|
|
+ * @date 2017-06-28 14:50:22
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
namespace App\Http\Controllers\Admin\Dream;
|
|
namespace App\Http\Controllers\Admin\Dream;
|
|
use App\Http\Controllers\Admin\Controller;
|
|
use App\Http\Controllers\Admin\Controller;
|
|
|
|
+use App\Models\BaseAttachmentModel;
|
|
|
|
+use App\Models\BaseSettingsModel;
|
|
|
|
+use App\Models\DreamImages;
|
|
|
|
+use App\Models\DreamInfoModel;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use App\Repositories\Base\Criteria\OrderBy;
|
|
use App\Repositories\Base\Criteria\OrderBy;
|
|
use App\Repositories\Dream\Criteria\MultiWhere;
|
|
use App\Repositories\Dream\Criteria\MultiWhere;
|
|
@@ -54,7 +58,8 @@ class InfoController extends Controller
|
|
if($reqeust->method() == 'POST') {
|
|
if($reqeust->method() == 'POST') {
|
|
return $this->_createSave();
|
|
return $this->_createSave();
|
|
}
|
|
}
|
|
- return view('admin.dream.info.edit');
|
|
|
|
|
|
+ $signs = BaseSettingsModel::where('category','sign')->orderBy('id')->get();
|
|
|
|
+ return view('admin.dream.info.edit',compact('signs'));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -62,8 +67,23 @@ class InfoController extends Controller
|
|
*/
|
|
*/
|
|
private function _createSave(){
|
|
private function _createSave(){
|
|
$data = (array) request('data');
|
|
$data = (array) request('data');
|
|
- $id = $this->repository->create($data);
|
|
|
|
|
|
+ $pics = (array) request('pic');
|
|
|
|
+ if (empty($pics)) {
|
|
|
|
+ $url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
|
|
|
|
+ return $this->showWarning('请添加图片',$url);
|
|
|
|
+ }
|
|
|
|
+ $id = DreamInfoModel::insertGetId($data);
|
|
if($id) {
|
|
if($id) {
|
|
|
|
+ $arr = [];
|
|
|
|
+ foreach ($pics['url'] as $pic) {
|
|
|
|
+ $arr[] = [
|
|
|
|
+ 'pic'=>$pic,
|
|
|
|
+ 'dream_id'=>$id,
|
|
|
|
+ 'created_at'=>date("Y-m-d H:i:s"),
|
|
|
|
+ 'updated_at'=>date("Y-m-d H:i:s"),
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ DreamImages::insert($arr);
|
|
$url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
|
|
$url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
|
|
$url[] = array('url'=>U( 'Dream/Info/create'),'title'=>'继续添加');
|
|
$url[] = array('url'=>U( 'Dream/Info/create'),'title'=>'继续添加');
|
|
$this->showMessage('添加成功',$url);
|
|
$this->showMessage('添加成功',$url);
|
|
@@ -81,10 +101,18 @@ class InfoController extends Controller
|
|
*/
|
|
*/
|
|
public function update(Request $reqeust) {
|
|
public function update(Request $reqeust) {
|
|
if($reqeust->method() == 'POST') {
|
|
if($reqeust->method() == 'POST') {
|
|
|
|
+// dd($reqeust->all());
|
|
return $this->_updateSave();
|
|
return $this->_updateSave();
|
|
}
|
|
}
|
|
$data = $this->repository->find($reqeust->get('id'));
|
|
$data = $this->repository->find($reqeust->get('id'));
|
|
- return view('admin.dream.info.edit',compact('data'));
|
|
|
|
|
|
+ $imgs = $data->imgs;
|
|
|
|
+ $arr = [];
|
|
|
|
+ foreach ($imgs as $pic) {
|
|
|
|
+ $arr[] = $pic['pic'];
|
|
|
|
+ }
|
|
|
|
+ $data->imgs = $arr;
|
|
|
|
+ $signs = BaseSettingsModel::where('category','sign')->orderBy('id')->get();
|
|
|
|
+ return view('admin.dream.info.edit',compact('data','signs'));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -92,6 +120,37 @@ class InfoController extends Controller
|
|
*/
|
|
*/
|
|
private function _updateSave() {
|
|
private function _updateSave() {
|
|
$data = (array) request('data');
|
|
$data = (array) request('data');
|
|
|
|
+ $pics = (array) request('pic');
|
|
|
|
+ if (empty($pics)) {
|
|
|
|
+ $url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
|
|
|
|
+ return $this->showWarning('请添加图片',$url);
|
|
|
|
+ }
|
|
|
|
+ $old_data_pics = $this->repository->find(request('id'))->imgs->toArray();
|
|
|
|
+ $old_pics = array_column($old_data_pics,'pic');
|
|
|
|
+ $a = array_diff($pics['url'],$old_pics);
|
|
|
|
+ $b = array_diff($old_pics,$pics['url']);
|
|
|
|
+ if (!empty($a) || !empty($b)) { //有图片变化执行
|
|
|
|
+ // 删除以前图片 重新插入
|
|
|
|
+ if (!empty($b)) {
|
|
|
|
+ foreach ($b as $old_pic){
|
|
|
|
+ if (is_file('.'.$old_pic)) {
|
|
|
|
+ unlink('.'.$old_pic);
|
|
|
|
+ }
|
|
|
|
+ BaseAttachmentModel::where('url',$old_pic)->delete();
|
|
|
|
+ DreamImages::where('pic',$old_pic)->delete();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $arr = []; //插入新的图片
|
|
|
|
+ foreach ($a as $pic) {
|
|
|
|
+ $arr[] = [
|
|
|
|
+ 'pic'=>$pic,
|
|
|
|
+ 'dream_id'=>request('id'),
|
|
|
|
+ 'created_at'=>date('Y-m-d H:i:s'),
|
|
|
|
+ 'updated_at'=>date('Y-m-d H:i:s'),
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ DreamImages::insert($arr);
|
|
|
|
+ }
|
|
$ok = $this->repository->update(request('id'),$data);
|
|
$ok = $this->repository->update(request('id'),$data);
|
|
if($ok) {
|
|
if($ok) {
|
|
$url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
|
|
$url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
|
|
@@ -128,6 +187,17 @@ class InfoController extends Controller
|
|
public function destroy(Request $reqeust) {
|
|
public function destroy(Request $reqeust) {
|
|
$bool = $this->repository->destroy($reqeust->get('id'));
|
|
$bool = $this->repository->destroy($reqeust->get('id'));
|
|
if($bool) {
|
|
if($bool) {
|
|
|
|
+ $old_data_pics = DreamInfoModel::find($reqeust->get('id'))->imgs->toArray();
|
|
|
|
+ $old_pics = array_column($old_data_pics,'pic');
|
|
|
|
+ if (!empty($old_pics)) {
|
|
|
|
+ foreach ($old_pics as $old_pic){
|
|
|
|
+ if (is_file('.'.$old_pic)) {
|
|
|
|
+ unlink('.'.$old_pic);
|
|
|
|
+ }
|
|
|
|
+ BaseAttachmentModel::where('url',$old_pic)->delete();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ DreamImages::where('dream_id',$reqeust->get('id'))->delete();
|
|
return $this->showMessage('操作成功');
|
|
return $this->showMessage('操作成功');
|
|
}else{
|
|
}else{
|
|
return $this->showWarning("操作失败");
|
|
return $this->showWarning("操作失败");
|