Commit b1dba3b5 authored by hujun's avatar hujun

新增办公楼

parent dab364f3
...@@ -10,17 +10,17 @@ namespace app\api_broker\controller; ...@@ -10,17 +10,17 @@ namespace app\api_broker\controller;
use app\index\extend\Basic; use app\index\extend\Basic;
use app\index\service\OfficeService; use app\index\service\OfficeRoomService;
use think\Request; use think\Request;
class OfficeManage extends Basic class OfficeRoom extends Basic
{ {
private $service; private $service;
public function __construct(?Request $request = null) public function __construct(?Request $request = null)
{ {
parent::__construct($request); parent::__construct($request);
$this->service = new OfficeService(); $this->service = new OfficeRoomService();
} }
/** /**
...@@ -75,7 +75,7 @@ class OfficeManage extends Basic ...@@ -75,7 +75,7 @@ class OfficeManage extends Basic
$code = 101; $code = 101;
$msg = $result['msg']; $msg = $result['msg'];
} }
return $this->response($code, $msg, $result['data']); return $this->response($code, $msg, []);
} }
/** /**
......
<?php
/**
* Created by PhpStorm.
* User: HuJun
* Date: 2019/5/30
* Time: 9:57
*/
namespace app\index\service;
use app\index\validate\OfficeBuildingRoomValidate;
use app\model\OfficeGBuildingImg;
use app\model\OfficeGRoom;
class OfficeRoomService
{
private $validate;
private $m_office_room;
private $m_office_img;
private $m_building_stations;
public function __construct()
{
$this->validate = new OfficeBuildingRoomValidate();
$this->m_office_room = new OfficeGRoom();
$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'] = '';
$result['data'] = [];
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_room->addRoom($data, $agent_id);
if ($id > 0) {
if (!empty($data['cover'])) {
$data['cover'] = json_decode($data['cover'], true);
foreach ($data['cover'] as $k=>$v) {
$data['cover'][$k] = stripslashes($v);
}
}
if (!empty($data['slide_show'])) {
$data['slide_show'] = json_decode($data['slide_show'], true);
foreach ($data['slide_show'] as $k=>$v) {
$data['slide_show'][$k] = stripslashes($v);
}
}
if (!empty($data['exclusive_img'])) {
$data['exclusive_img'] = json_decode($data['exclusive_img'], true);
foreach ($data['exclusive_img'] as $k=>$v) {
$data['exclusive_img'][$k] = stripslashes($v);
}
}
$result['status'] = 'successful';
} else {
$result['msg'] = '新增或编辑失败!';
}
return $result;
}
/**
* 楼盘详情
*
* @param int $id
* @param int $app
* @return mixed
*/
public function getOfficeRoomDetail(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', ['building_id'=>$id, 'img_type'=>0]);
if ($app == 0) {
foreach ($img_data as $k => $v) {
$data['building_images'][$k]['img_name'] = $v['img_name'];
$data['building_images'][$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'];
$data['building_images'][] = $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'] = "";
// }
$field_stations = 'a.id,b.line_name,name,distance,b.id as stations_id';
$data['building_stations'] = $this->m_building_stations->getListAll($field_stations, ['a.building_id'=>$id]);
}
$result['data'] = $data;
$result['status'] = 'successful';
} catch (\Exception $e) {
$result['msg'] = $e->getMessage();
$result['status'] = 'fail';
}
return $result;
}
/**
* 删除图片
*
* @param $id
* @param $building_id
* @param $img_status
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function delHouseFile($id, $building_id, $img_status)
{
$data['status'] = 'fail';
$data['msg'] = '';
if (empty($id) || empty($building_id)) {
$data['msg'] = '参数错误';
return $data;
}
$where['building_id'] = $id;
$where['id'] = $id;
$where['img_status'] = $img_status;
$id = $this->m_office_img->getFindData('id', $where);
if (empty($id['id'])) {
$data['msg'] = '没有该文件';
} else {
$this->m_office_img->editData(['img_status' => 1], $id['id'], 'id');
$data['status'] = 200;
$data['msg'] = '删除成功';
}
return $data;
}
}
\ 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 OfficeBuildingRoomValidate 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
...@@ -16,7 +16,173 @@ class OfficeGRoom extends BaseModel ...@@ -16,7 +16,173 @@ class OfficeGRoom extends BaseModel
parent::__construct($data); parent::__construct($data);
$this->db_ = Db::name($this->table); $this->db_ = Db::name($this->table);
} }
public function updateHouseNumByRevocationBargain($room_id){
/**
* 房源状态
*
* @param $room_id
* @param int $is_rent
* @return bool|false|int
*/
public function updateHouseNumByRevocationBargain($room_id, $is_rent = 1)
{
if (empty($room_id)) {
return false;
}
return $this->editData(['is_rent'=>$is_rent], $room_id);
}
/**
* 新增和编辑办公楼
*
* @param array $data
* @param int $agent_id
* @return int|mixed|string
*/
public function addRoom(array $data, int $agent_id)
{
$save_data = [];
//所在楼层
if (isset($data['floor'])) {
$save_data['floor'] = (int)$data['floor'];
}
//门牌号
if (isset($data['room_number'])) {
$save_data['room_number'] = $data['room_number'];
}
//是否已租 0未租 1已租
if (isset($data['is_rent'])) {
$save_data['is_rent'] = $data['is_rent'];
}
//是否独家0否1是
if (isset($data['is_exclusive_type'])) {
$save_data['is_exclusive_type'] = $data['is_exclusive_type'];
}
//租金总价 存分
if (isset($data['price_total'])) {
$save_data['price_total'] = $data['price_total'] * 100;
}
//租金单价 存分
if (isset($data['price'])) {
$save_data['price'] = $data['price'] * 100;
}
//转让费存分
if (isset($data['slotting_fee'])) {
$save_data['slotting_fee'] = $data['slotting_fee'] * 100;
}
//物业管理费
if (isset($data['management_fee'])) {
$save_data['management_fee'] = $data['management_fee'] * 100;
}
//可容纳工位
if (isset($data['station_start'])) {
$save_data['station_start'] = $data['station_start'];
}
//可容纳工位
if (isset($data['station_end'])) {
$save_data['station_end'] = $data['station_end'];
}
//面积
if (isset($data['area'])) {
$save_data['area'] = $data['area'];
}
//所属楼层 1底层 2中层 3高层
if (isset($data['floor_tag'])) {
$save_data['floor_tag'] = $data['floor_tag'];
}
//入住时间
if (isset($data['enter_time'])) {
$save_data['enter_time'] = $data['enter_time'];
}
//付款规则(按月)-付款
if (isset($data['payment_month'])) {
$save_data['payment_month'] = $data['payment_month'];
}
//付款规则(按月)-押金
if (isset($data['deposit_month'])) {
$save_data['deposit_month'] = $data['deposit_month'];
}
//签约年限
if (isset($data['age_limit_start'])) {
$save_data['age_limit_start'] = $data['age_limit_start'];
}
//签约年限
if (isset($data['age_limit_end'])) {
$save_data['age_limit_end'] = $data['age_limit_end'];
}
//是否可注册公司 0 是 1否
if (isset($data['is_register'])) {
$save_data['is_register'] = $data['is_register'];
}
//是否可分割 0 是 1否
if (isset($data['is_partition'])) {
$save_data['is_partition'] = $data['is_partition'];
}
//车位请况
if (isset($data['carport'])) {
$save_data['carport'] = $data['carport'];
}
//免租时间(月) -1面议
if (isset($data['rent_free'])) {
$save_data['rent_free'] = $data['rent_free'];
}
//来源:0无,1网络,2客户介绍,3 朋友介绍,4上门挂牌,5打更新,6驻守,7其它
if (isset($data['source'])) {
$save_data['source'] = $data['source'];
}
//是否对客户展示 0是1否显示在c端用户
if (isset($data['is_show'])) {
$save_data['is_show'] = $data['is_show'];
}
//交付装修 交付装修1毛坯 2现状 3简单装修4精装修
if (isset($data['decoration'])) {
$save_data['decoration'] = $data['decoration'];
}
//商铺标签
if (isset($data['shop_sign'])) {
$save_data['shop_sign'] = $data['shop_sign'];
}
if (empty($data['id'])) {
$save_data['operation_id'] = $agent_id; //上传人
$save_data['create_time'] = date('Y-m-d H:i:s');
$room_id = $this->insertGetId($save_data);
} else {
try {
$save_data['update_time'] = date('Y-m-d H:i:s');
$this->where('id', $data['id'])->update($save_data);
$room_id = $data['id'];
} catch (\Exception $e) {
$room_id = 0;
}
}
return (int)$room_id;
} }
} }
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