Commit 6df84c14 authored by hujun's avatar hujun

编辑商铺

parent c082d4a3
...@@ -65,6 +65,11 @@ class BusinessDistrict extends Basic ...@@ -65,6 +65,11 @@ class BusinessDistrict extends Basic
} }
} }
/**
* 删除商圈
*
* @return \think\Response
*/
public function del() { public function del() {
$result['code'] = 200; $result['code'] = 200;
$result['msg'] = ''; $result['msg'] = '';
......
...@@ -9,14 +9,153 @@ ...@@ -9,14 +9,153 @@
namespace app\index\controller; namespace app\index\controller;
class Houses use app\index\extend\Basic;
use app\model\GHouses;
use app\model\GHousesExt;
use app\model\GHousesImgs;
class Houses extends Basic
{ {
public function index() { public function index() {
return view('index'); return view('index');
} }
/**
* 新增商铺
*
* @return \think\response\View
* @throws \Exception
* @throws \think\exception\PDOException
*/
public function edit() { public function edit() {
return view('edit'); $result['code'] = 200;
$result['msg'] = '';
if ($this->request->isPost()) {
$params = $this->request->param();
$date = date('Y-m-d H:i:s');
if ($params['id']) {
$params['update_time'] = $date;
} else {
$params['create_time'] = $date;
$params['update_time'] = $date;
}
$house = new GHouses();
$house->startTrans();
//新增或编辑
if ($params['id'] == '') {
$house->allowField(true)->save($params);
} else {
$house->allowField(true)->isUpdate(true)->save($params, ['id' => $params['id']]);
}
$params['house_id'] = $house->id;
$house_ext = new GHousesExt();
if ($params['start_business_date']) {
$params['start_business_date'] = date('Y-m-d H:i:s' , strtotime($params['start_business_date']));
}
//新增或编辑根据id
if ($params['id'] == '') {
$house_ext->allowField(true)->save($params);
} else {
$house_ext_data = $house_ext->field('id')->where('house_id',$params['id'])->find();
$house_ext->allowField(true)->isUpdate(true)->save($params, ['id' => $house_ext_data['id']]);
}
/***保存图片 hujun 2018.1.19 start***/
$house_img = new GHousesImgs();
//新增图片
if ($params['id'] != '') {
//编辑图片
$house_img_data = $house_img->field('id,img_name,img_type')
->where('img_type <> 6 AND house_id = '.$params['id'])
->select();
$count = 0;
foreach ($house_img_data as $k=>$v) {
if ($v->img_type == 1 && $v->img_name == $params['cover']) {
$house_img_edit['0']['id'] = $v->id;
$house_img_edit['0']['img_type'] = 5;
$params['cover'] = 0; //删除重复的数据
$count = 1;
}
foreach ($params['slideshow'] as $kk => $vv) {
if ($v->img_type == 2 && $v->img_name == $vv) {
unset($params['slideshow'][$kk]);
$kk += $count;
$house_img_edit[$kk]['id'] = $v->id;
$house_img_edit[$kk]['img_type'] = 5;
$params['cover'] = 0;
}
}
}
$house_img->isUpdate(true)->saveAll($house_img_edit);
}
$count = 0;
$insert_img = array();
//1列表页封面图
if ($params['cover']) {
$insert_img['0']['house_id'] = $house->id;
$insert_img['0']['img_type'] = 1;
$insert_img['0']['img_name'] = $params['cover'];
$insert_img['0']['create_time'] = $params['create_time'];
$insert_img['0']['update_time'] = $params['update_time'];
$count = count($insert_img) + 1;
}
//2详情页轮播图
if ($params['slideshow']) {
foreach ($params['slideshow'] as $k=>$v) {
$k += $count;
$insert_img[$k]['house_id'] = $house->id;
$insert_img[$k]['img_type'] = 2;
$insert_img[$k]['img_name'] = $v;
$insert_img[$k]['create_time'] = $params['create_time'];
$insert_img[$k]['update_time'] = $params['update_time'];
}
if (count($insert_img) > 0) {
$count = count($insert_img) + 1;
}
}
//3楼层平面图
if ($params['plan']) {
foreach ($params['plan'] as $kk=>$vv) {
$kk += $count;
$insert_img[$kk]['house_id'] = $house->id;
$insert_img[$kk]['img_type'] = 3;
$insert_img[$kk]['img_name'] = $vv;
$insert_img[$kk]['create_time'] = $params['create_time'];
$insert_img[$kk]['update_time'] = $params['update_time'];
}
}
$house_img->saveAll($insert_img);
/***保存图片 hujun 2018.1.19 end***/
if ($house->id && count($house_img) > 0 && $house_ext->id) {
$house->commit();
$return = $this->response($result['code'], $result['msg']);
} else {
$house->rollback();
$return = $this->response(101, $result['msg']);
}
} elseif ($this->request->param('id')){
$house = new GHouses();
$result['data'] = $house->find();
$return = $this->response($result['code'], $result['msg'], $result['data']);
} else {
$return = view('edit');
}
return $return;
} }
public function del() { public function del() {
......
<?php
namespace app\model;
class GHouses extends BaseModel
{
protected $table = 'g_houses';
}
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/1/18
* Time: 17:39
*/
namespace app\model;
class GHousesExt extends BaseModel
{
protected $table = 'g_houses_ext';
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/1/19
* Time: 11:33
*/
namespace app\model;
class GHousesImgs extends BaseModel
{
protected $table = 'g_houses_imgs';
}
\ No newline at end of file
...@@ -81,9 +81,9 @@ Route::group('index', [ ...@@ -81,9 +81,9 @@ Route::group('index', [
'delBusinessDistrict' => ['index/BusinessDistrict/del', ['method' => 'post']], //删除商圈列表 'delBusinessDistrict' => ['index/BusinessDistrict/del', ['method' => 'post']], //删除商圈列表
'BusinessList' => ['index/BusinessDistrict/getBusiness', ['method' => 'get']], //获取商铺列表数据 'BusinessList' => ['index/BusinessDistrict/getBusiness', ['method' => 'get']], //获取商铺列表数据
'houseList' => ['index/Houses/index', ['method' => 'get']], //商铺列表 'houseList' => ['index/Houses/index', ['method' => 'get']], //商铺列表
'houseEdit' => ['index/Houses/edit', ['method' => 'get']], //编辑商铺 'houseEdit' => ['index/Houses/edit', ['method' => 'get|post']], //编辑商铺
'houseDel' => ['index/Houses/del', ['method' => 'get']], //删除商铺 'houseDel' => ['index/Houses/del', ['method' => 'get']], //删除商铺
'regions' => ['index/BusinessDistrict/regions', ['method' => 'get']], //删除商铺 'regions' => ['index/BusinessDistrict/regions', ['method' => 'get']], //获取省市区数据
]); ]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment