Commit ca7dd1b7 authored by hujun's avatar hujun

新增和编辑楼盘

parent 2bf58a53
......@@ -10,8 +10,72 @@ namespace app\index\controller;
use app\index\extend\Basic;
use app\index\service\OfficeService;
use think\Request;
class OfficeManage extends Basic
{
private $service;
public function __construct(?Request $request = null)
{
parent::__construct($request);
$this->service = new OfficeService();
}
/**
* 新增楼盘
*
* @return \think\Response|\think\response\View
*/
public function add()
{
if (!$this->request->isAjax()) {
return view('office/add');
}
$code = 200;
$result['status'] = $msg = '';
if ($this->request->isPost()) {
$msg = '新增成功';
$result = $this->service->edit($this->params);
}
if ($result['status'] == 'fail') {
$code = 101;
$msg = $result['msg'];
}
return $this->response($code, $msg);
}
/**
* 编辑楼盘
*
* @return \think\Response|\think\response\View
*/
public function edit() {
if (!$this->request->isAjax()) {
return view('office/add');
}
if (empty($this->params['id'])) {
return $this->response(101, '参数错误');
}
$code = 200;
$msg = '';
if ($this->request->isPost()) {
$result = $this->service->edit($this->params);
} else {
$result = $this->service->getOfficeDetail($this->params['id'], 0);
}
if ($result['status'] == 'fail') {
$code = 101;
$msg = $result['msg'];
}
return $this->response($code, $msg, $result['data']);
}
}
\ No newline at end of file
......@@ -9,7 +9,141 @@
namespace app\index\service;
use app\index\validate\OfficeBuildingValidate;
use app\model\GBusinessDistrict;
use app\model\OfficeGBuilding;
use app\model\OfficeGBuildingImg;
class OfficeService
{
private $validate;
private $m_office;
private $m_office_img;
public function __construct()
{
$this->validate = new OfficeBuildingValidate();
$this->m_office = new OfficeGBuilding();
$this->m_office_img = new OfficeGBuildingImg();
}
/**
* 新增或编辑楼盘
*
* @param array $data
* @param int $agent_id 上传人id
* @return mixed
*/
public function edit(array $data, int $agent_id = 0) {
$result['status'] = 'fail';
$result['msg'] = '';
if (isset($data['id'])) {
$scene = 'edit';
} else {
$scene = 'add';
}
$check = $this->validate->scene($scene)->check($data);
if (false === $check) {
$result['msg'] = $this->validate->getError();
return $result;
}
$id = $this->m_office->addOffice($data, $agent_id);
if ($id > 0) {
$result['status'] = 'successful';
} else {
$result['msg'] = '新增或编辑失败!';
}
return $result;
}
/**
* 楼盘详情
*
* @param int $id
* @param int $app
* @return mixed
*/
public function getOfficeDetail(int $id, $app = 0)
{
$result['status'] = 'fail';
$result['msg'] = '';
$check_data['id'] = $id;
$data['slide_show'] = $data['plan'] = $data['exclusive_img'] = [];
$check = $this->validate->scene('detail')->check($check_data);
if (false === $check) {
$result['msg'] = $this->validate->getError();
return $result;
}
try {
$field = 'id,title,address,province,city,disc,business_district_id,type,floor_total,longitude,latitude,intro';
$data = $this->m_office->getFindData($field, ['id'=>$id]);
if ($result) {
$img_data = $this->m_office_img->getListAll('id,img_type,img_name', ['build_id'=>$id]);
if ($app == 0) {
foreach ($img_data as $k => $v) {
switch ($v['img_type']) {
case 1 :
$data['cover'] = $v['img_name'];
break;
case 2 :
$data['slide_show'][$k]['img_name'] = $v['img_name'];
$data['slide_show'][$k]['id'] = $v['id'];
break;
case 3 :
$data['plan'][$k]['img_name'] = $v['img_name'];
$data['plan'][$k]['id'] = $v['id'];
break;
case 4 :
$data['exclusive_img'][$k]['img_name'] = $v['img_name'];
$data['exclusive_img'][$k]['id'] = $v['id'];
}
}
} else {
$file_url = [];
foreach ($img_data as $k => $v) {
$img_url = CK_IMG_URL . 'images/' . $v->img_name;
$file_url['file_name'] = $img_url;
$file_url['save_path'] = $v['img_name'];
switch ($v->img_type) {
case 1 :
$data['cover'] = $file_url;
break;
case 2 :
$data['slide_show'][] = $file_url;
break;
case 3 :
$data['plan'][] = $file_url;
break;
default :
$data['exclusive_img'][] = $file_url;
}
}
}
if (!empty($data['business_district_id'])) {
$business = new GBusinessDistrict();
$data['business_name'] = $business->getValue(['id'=>$data['business_district_id']], 'name');
} else {
$data['business_name'] = "";
}
}
$result['data'] = $data;
$result['status'] = 'successful';
} catch (\Exception $e) {
$result['msg'] = $e->getMessage();
$result['status'] = 'fail';
}
return $result;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: hu jun
* Date: 2018/8/8
* Time: 10:45
*/
namespace app\index\validate;
use think\Validate;
class OfficeBuildingValidate extends Validate
{
protected $rule = [
'id' => 'require|between: 1,99999999999',
'upload_id' => 'require|between: 1,99999999999',
'title' => 'require|length:1,125',
'address' => 'require|length:1,125',
'province' => 'require|length:1,60',
'city' => 'require|length:1,60',
'disc' => 'require|length:1,60',
'type' => 'require',
'status' => 'require|in:[0,1,2]',
'floor_total' => 'require|between:0,9999999999',
'longitude' => 'require|min:1',
'latitude' => 'require|min:1',
'business_district_id' => 'require|between: 1,99999999999',
'intro'=>'require|length:1,255'
];
protected $message = [
'title.require' => '对内楼盘名为必填',
'title.length' => '名称字数在1至125个字',
'address.require' => '楼盘地址为必填',
'address.length' => '地址要在1至255个字',
'province.require' => '省份为必填',
'province.length' => '省份要在1至60个字',
'city.require' => '市为必填',
'city.length' => '对内地址要在1至60个字',
'disc.require' => '区为必填',
'disc.length' => '对内地址要在1至60个字',
'longitude.require' => '无法获取楼盘坐标,请重新修改地址',
'longitude.min' => '楼盘坐标参数错误',
'latitude.require' => '无法获取楼盘坐标,请重新修改地址',
'latitude.min' => '楼盘坐标参数错误',
'business_district_id.require' => '楼盘必选',
'business_district_id.between' => '楼盘参数错误',
'id.require' => '楼盘id必传',
'id.between' => '楼盘id错误',
'upload_id.require' => '上传人id必传',
'upload_id.between' => '上传人id错误',
'intro.require'=>'楼盘简介必填',
'intro.length'=>'楼盘简介要做1至255个字'
];
protected $scene = [
'add' => ['title','address','province','city','disc','type','floor_total','longitude','latitude',
'business_district_id','upload_id','intro'],
'edit' => ['id','title','address','province','city','disc','type','floor_total','longitude','latitude',
'business_district_id','intro'],
'detail' => ['id']
];
}
\ No newline at end of file
{layout name="global/frame_two_tpl" /}
2222
\ No newline at end of file
......@@ -16,4 +16,106 @@ class OfficeGBuilding extends BaseModel
parent::__construct($data);
$this->db_ = Db::name($this->table);
}
/**
* 新增和编辑楼盘
*
* @param array $data
* @param int $agent_id
* @return int|mixed|string
*/
public function addOffice(array $data, int $agent_id = 0)
{
$save_data = [];
//楼盘名称
if (isset($data['title'])) {
$save_data['title'] = htmlspecialchars(trim($data['title']));
}
//省
if (isset($data['province'])) {
$save_data['province'] = $data['province'];
}
//市
if (isset($data['city'])) {
$save_data['city'] = $data['city'];
}
//区
if (isset($data['disc'])) {
$save_data['disc'] = $data['disc'];
}
//商圈id
if (isset($data['business_district_id'])) {
$save_data['business_district_id'] = $data['business_district_id'];
}
//地址
if (isset($data['address'])) {
$save_data['address'] = $data['address'];
}
//1.写字楼 2商住两用 3园区 4.洋房 5联合办公 6厂房
if (isset($data['type'])) {
$save_data['type'] = $data['type'];
}
//状态 0待审批 1有效 2无效
if (isset($data['status'])) {
$save_data['status'] = $data['status'];
}
//楼层总数
if (isset($data['floor_total'])) {
$save_data['floor_total'] = $data['floor_total'];
}
//商铺经度
if (isset($data['longitude'])) {
$save_data['longitude'] = $data['longitude'];
}
//商铺纬度
if (isset($data['latitude'])) {
$save_data['latitude'] = $data['latitude'];
}
//简介
if (isset($data['intro'])) {
$save_data['intro'] = $data['intro'];
}
if (empty($data['id'])) {
$save_data['upload_id'] = $agent_id; //上传人
$save_data['create_time'] = date('Y-m-d H:i:s');
$house_id = $this->db_->insertGetId($save_data);
} else {
try {
$save_data['update_time'] = date('Y-m-d H:i:s');
$this->db_->where('id', $data['id'])->update($save_data);
$house_id = $data['id'];
} catch (\Exception $e) {
$house_id = 0;
}
}
return (int)$house_id;
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getFindData($field, $where) {
$where['is_del'] = 0;
return $this->db_->field($field)
->where($where)
->find();
}
}
<?php
namespace app\model;
use think\Db;
class OfficeGBuildingImg extends BaseModel
{
protected $table = 'office_g_building_img';
private $db_;
public function __construct($data = [])
{
parent::__construct($data);
$this->db_ = Db::name($this->table);
}
/**
* 新增和编辑楼盘图片
*
* @param array $data
* @param int $agent_id
* @return int|mixed|string
*/
public function addOffice(array $data, int $agent_id = 0)
{
$save_data = [];
//楼盘名称
if (isset($data['build_id'])) {
$save_data['build_id'] = $data['build_id'];
}
//图片类型:1列表页封面图,2详情页轮播图,3楼层平面图,4独家合同,5,删除
if (isset($data['img_type'])) {
$save_data['img_type'] = $data['img_type'];
}
//图片名
if (isset($data['img_name'])) {
$save_data['img_name'] = $data['img_name'];
}
if (empty($data['id'])) {
$save_data['create_time'] = date('Y-m-d H:i:s');
$img_id = $this->db_->insertGetId($save_data);
} else {
try {
$save_data['update_time'] = date('Y-m-d H:i:s');
$this->db_->where('id', $data['id'])->update($save_data);
$img_id = $data['id'];
} catch (\Exception $e) {
$img_id = 0;
}
}
return (int)$img_id;
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getFindData($field, $where) {
$where['is_del'] = 0;
return $this->db_->field($field)
->where($where)
->find();
}
/**
* @param $field
* @param $where
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getListAll($field, $where)
{
$where['img_status'] = 0;
return $this->db_->field($field)
->where($where)
->select();
}
}
......@@ -474,6 +474,8 @@ Route::group('index', [
'getFindShopList' => ['index/FindShop/getFindShopList', ['method' => 'POST|GET']],
'getFindShopListIsMy' => ['index/FindShop/getFindShopList', ['method' => 'POST|GET']],
'office_add' => ['index/OfficeManage/add', ['method' => 'GET|POST']],//楼盘字典新增
'office_edit' => ['index/OfficeManage/edit', ['method' => 'GET|POST']],//楼盘字典编辑
]);
......
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