Commit 6383ecca authored by hujun's avatar hujun

案场联系人

parent eeef527a
......@@ -3,6 +3,8 @@
namespace app\index\controller;
use app\index\extend\Basic;
use app\model\HouseInfos;
use think\Request;
/**
* Description of HouseInfo
*
......@@ -13,7 +15,7 @@ use app\model\HouseInfos;
class HouseInfo extends Basic{
protected $house_infos;
public function __construct() {
public function __construct(Request $request) {
parent::__construct($request);
$this->house_infos = new HouseInfos();
}
......
......@@ -11,8 +11,6 @@ namespace app\index\controller;
use app\index\extend\Basic;
use app\model\GHouses;
use app\model\GHousesExt;
use app\model\GHousesImgs;
use think\Request;
......@@ -42,50 +40,14 @@ class Houses extends Basic
$result['msg'] = '';
$params = $this->request->param();
if ($this->request->isPost()) {
$date = date('Y-m-d H:i:s');
if ($params['id']) {
$params['update_time'] = $date;
}
$this->house->startTrans();
//新增或编辑
if ($params['id'] == '') {
$house_id = $this->house->allowField(true)->save($params);
} else {
$house_id = $this->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->add($params, $house_id);
} else {
$house_img->edit($params, $house_id);
}
/***保存图片 hujun 2018.1.19 end***/
$house_id = $this->house->add($params); //添加或编辑商铺
if ($house_id) {
$this->house->commit();
$return = $this->response($result['code'], $result['msg']);
$return = $this->response($result['code'], $result['msg'],['id',$house_id]);
} else {
$this->house->rollback();
$return = $this->response(101, $result['msg']);
$return = $this->response(101, 'add houses is error');
}
} elseif ($params['id']){
......
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/1/20
* Time: 17:52
*/
namespace app\model;
class ACase extends BaseModel
{
/**
* 添加案场联系人
*
* @param $data
* @return string
* @throws \Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function addCase($data) {
$date = date('Y-m-d H:i:s');
$data = array_unique($data);
$case_arr = array();
$id_str = '';
foreach ($data as $k=>$v) {
$data_arr = explode('-',$v);
if (count($data_arr) == 3) {
$check = $this->field('id')->where([
'name' => $data_arr['1'],
'phone' => $data_arr['2'],
'status' => 0
])->find();
if ($check) {
$id_str .= $check['id'].',';
continue;
} else {
$case_arr[$k]['name'] = $data_arr['1'];
$case_arr[$k]['phone'] = $data_arr['2'];
$case_arr[$k]['create_time'] = $date;
$case_arr[$k]['update_time'] = $date;
}
}
}
$res = $this->saveAll($case_arr);
foreach ($res as $k=>$v) {
$id_str .= $v->id.',';
}
$id_str = rtrim($id_str,',');
return $id_str;
}
}
\ No newline at end of file
......@@ -175,4 +175,66 @@ class GHouses extends BaseModel
->count();
return $data;
}
/**
* 添加和编辑商铺
*
* @param $params
* @return mixed
* @throws \Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function add($params) {
$date = date('Y-m-d H:i:s');
if ($params['id']) {
$params['update_time'] = $date;
} else {
$params['create_time'] = $date;
$params['update_time'] = $date;
}
$case = new ACase();
$case_id = $case->addCase($params['phone']);
$params['case_id'] = $case_id;
//新增或编辑
if ($params['id'] == '') {
$this->allowField(true)->save($params);
$house_id = $this->id;
} else {
$this->allowField(true)->isUpdate(true)->save($params, ['id' => $params['id']]);
$house_id = $this->id;
}
$params['house_id'] = $house_id;
if ($params['start_business_date']) {
$params['start_business_date'] = date('Y-m-d H:i:s' , strtotime($params['start_business_date']));
}
$houses_ext = new GHousesExt();
//新增或编辑根据id
if ($params['id'] == '') {
$houses_ext->allowField(true)->save($params);
} else {
$house_ext_data = $houses_ext->field('id')->where('house_id',$params['id'])->find();
$houses_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->add($params, $house_id);
} else {
$house_img->edit($params, $house_id);
}
/***保存图片 hujun 2018.1.19 end***/
$agents = new GHousesToAgents();
$agents->addAgents($params['agent_data'], $house_id,1);
$agents->addAgents($params['agent_dish'], $house_id,2);
return $house_id;
}
}
......@@ -15,10 +15,10 @@ class GHousesToAgents extends BaseModel
}
/**
* @param $data
* @param $agents_id
* @param $houses_id
* @param $type 案场权限人:0,盘方:1,独家:2
* @return array|false|int
* @return array|false
* @throws \Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
......
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