Commit c2dff300 authored by hujun's avatar hujun

商铺验证修改,去除旧方法。

parent 120c157a
......@@ -400,37 +400,7 @@ class Shop extends Basic
*/
public function edit()
{
$result['code'] = 200;
$result['msg'] = '';
$result['data'] = [];
if ($this->request->isPost()) {
$validate = new HouseValidate();
$check = $validate->check($this->params);
if(true !== $check){
return $this->response(101, $validate->getError());
}
$house_id = $this->gHousesModel->app_add($this->params, $this->agentId); //添加或编辑商铺
if ($house_id) {
$result['data']['house_id'] = $house_id['house_id'];
$result['data']['internal_title'] = empty($this->params['internal_title']) ? "" : $this->params['internal_title'];
} else {
$data['code'] = 101;
$data['msg'] = 'Add houses failure';
}
} else {
if (empty($this->params['id'])) {
$result['code'] = 101;
$result['msg'] = 'Id is null';
} else {
//获取商铺详情
$result['data'] = $this->gHousesModel->getHouseById($this->params['id'], 1);
}
}
return $this->response($result['code'], $result['msg'], $result['data']);
return $this->response(101,'请升级最新版本');
}
/**
......@@ -449,7 +419,12 @@ class Shop extends Basic
if ($this->request->isPost()) {
$validate = new HouseValidate();
$check = $validate->check($this->params);
if ($this->params['id']) {
$check = $validate->scene('edit')->check($this->params);
} else {
$check = $validate->check($this->params);
}
if(true !== $check){
return $this->response(101, $validate->getError());
......
......@@ -73,9 +73,13 @@ class HouseValidate extends Validate
'fee_rule.between' => '佣金规则字数为0至500',
'internal_item_advantage.require' => '对内项目优势必填',
'internal_item_advantage.between' => '对内项目优势字数为1至500',
'longitude' => '无法获取商铺坐标,请重新修改地址',
'latitude' => '无法获取商铺坐标,请重新修改地址'
];
protected $scene = [
'edit'=>['internal_title','internal_address','province','city','disc','market_area','shop_area_start','rent_type',
'rent_price','industry_type','shop_type','shop_sign','management_fee','slotting_fee','residue_num','total','is_show',
'fee_rule','internal_item_advantage']
];
}
\ No newline at end of file
......@@ -923,233 +923,6 @@ class GHouses extends BaseModel
/******zw end ************/
/**
* 添加和编辑商铺
*
* @param $params
* @param $agent_id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function app_add($params, $agent_id)
{
$this->startTrans();
if (isset($params['phone'])) {
$case = new ACase();
$case_id = $case->addCase($params['phone']);
$params['case_id'] = $case_id;
}
if (!empty($params['province']) || !empty($params['city']) || !empty($params['disc'])) {
$regions = new Regions();
$code_arr = $regions->getRegionsCodeByName($params['province'], $params['city'], $params['disc']);
$params['code'] = is_array($code_arr) ? implode('##', $code_arr) : '';
}
if (!empty($params['rent_price'])) {
$params['rent_price'] = $params['rent_price'] * 100; //存分
}
if (!empty($params['management_fee'])) {
$params['management_fee'] = $params['management_fee'] * 100; //存分
}
if (!empty($params['slotting_fee'])) {
$params['slotting_fee'] = $params['slotting_fee'] * 100; //存分
}
if (!empty($params['external_slotting_fee'])) {
if ($params['external_slotting_fee'] != -1) {
$params['external_slotting_fee'] = $params['external_slotting_fee'] * 100; //存分
}
}
if (isset($params['internal_title'])) {
$params['internal_title'] = trim($params['internal_title']);
}
//街铺start和end面积一样
if ($params['shop_type'] == 1) {
$params['shop_area_end'] = $params['shop_area_start'];
}
//新增或编辑
if (empty($params['id'])) {
$params['upload_id'] = $agent_id;
$this->allowField(true)->save($params);
$house_id = $this->id;
$result['house_id'] = $this->id;
$result['internal_title'] = $params['internal_title'];
} else {
$house_data = $this->field('id,internal_title,residue_num,total')->where('id', $params['id'])->where('status', '<>', 3)->find();
if (!empty($house_data['id'])) {
//剩余商铺为0下架 todo 如果参数有输入剩余铺数和总铺数,没问题, 但是如果没有传则要考虑上架问题
if (isset($params['residue_num'])) {
if (empty($params['residue_num']) || empty($params['total'])) {
$params['status'] = 2;
} else {
$params['status'] = 1;
}
}
//商铺总数为0下架
if (isset($params['total'])) {
if (empty($params['total'])) {
$params['status'] = 2;
} else {
$params['status'] = 1;
}
}
if (!isset($params["status"])) {
if ($house_data["residue_num"] == 0 || $house_data["total"] == 0) {
$params['status'] = 2;
} else {
$params['status'] = 1;
}
}
/* //剩余商铺为0下架
if (isset($params['residue_num'])) {
if (empty($params['residue_num']) || empty($params['total'])) {
$params['status'] = 2;
} else {
$params['status'] = 1;
}
}
//商铺总数为0下架
if (isset($params['total'])) {
if (empty($params['total'])) {
$params['status'] = 2;
} else {
$params['status'] = 1;
}
}*/
$params['operation_id'] = $params['userId'];
$this->allowField(true)->isUpdate(true)->save($params, [ 'id' => $params['id'] ]);
$house_id = $this->id;
} else {
$house_id = $params['id'];
}
$result['internal_title'] = $house_data['internal_title'];
$result['house_id'] = $house_id;
}
$params['house_id'] = $house_id;
if (isset($params['start_business_date'])) {
$params['start_business_date'] = date('Y-m-d H:i:s', strtotime($params['start_business_date']));
}
if (!empty($params['landlord_phone'])) {
$landlord_phone = [];
//排除没有手机号数据
if (is_array(json_decode($params['landlord_phone'], true))) {
$params['landlord_phone'] = json_decode($params['landlord_phone'], true);
foreach ($params['landlord_phone'] as $k => $v) {
if (!empty($v['phone'])) {
$landlord_phone[$k]['name'] = empty($v['name']) ? '房东' : $v['name'];
$landlord_phone[$k]['phone'] = $v['phone'];
}
}
} else {
//兼容之前逗号隔开的手机号
$params['landlord_phone'] = explode(',', $params['landlord_phone']);
foreach ($params['landlord_phone'] as $key => $val) {
$landlord_phone[$key]['name'] = '房东';
$landlord_phone[$key]['phone'] = $val;
}
}
if (isset($landlord_phone[0]['phone'])) {
$params['landlord_phone'] = json_encode($landlord_phone);
}
}
if (isset($params['landlord_remark'])) {
$params['landlord_remark'] = trim($params['landlord_remark']); //房东备注
}
$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();
//没有数据就新增
if (empty($house_ext_data)) {
$data_ext['house_id'] = $params['house_id'];
$data_ext['fee_rule'] = $params['fee_rule'];
$data_ext['internal_item_advantage'] = $params['internal_item_advantage'];
$data_ext['external_item_advantage'] = $params['external_item_advantage'];
$data_ext['tiny_brochure_url'] = $params['tiny_brochure_url'];
$data_ext['auditorium'] = $params['auditorium'];
$data_ext['traffic'] = $params['traffic'];
$data_ext['agent_start_time'] = $params['agent_start_time'];
$data_ext['agent_end_time'] = $params['agent_end_time'];
$data_ext['enter_num'] = $params['enter_num'];
$data_ext['do_business_date'] = $params['do_business_date'];
$data_ext['start_business_date'] = $params['start_business_date'];
$data_ext['opening_date'] = $params['opening_date'];
$data_ext['sign_rule'] = $params['sign_rule'];
$data_ext['landlord_phone'] = $params['landlord_phone'];
$data_ext['landlord_remark'] = $params['landlord_remark'];
$houses_ext->allowField(true)->save($data_ext);
} else {
$houses_ext->allowField(true)->isUpdate(true)->save($params, [ 'id' => $house_ext_data['id'] ]);
}
}
$agents = new GHousesToAgents();
//权限人
if (isset($params['agent_data'])) {
$agents->addAgents($params['agent_data'], $house_id, 1);
}
//盘方
if (isset($params['agent_dish'])) {
$agents->addAgents($params['agent_dish'], $house_id, 2);
}
//独家方
if (isset($params['exclusive_ids'])) {
$agents->addAgents($params['exclusive_ids'], $house_id, 3);
}
if ($params['image_file']) {
$m_img = new GHousesImgs();
$image_file = json_decode($params['image_file'], true);
$img_data = [];
foreach ($image_file as $k=>$v) {
$img_data[$k]['house_id'] = $result['house_id'];
$img_data[$k]['img_name'] = $v['img_name'];
$img_data[$k]['img_type'] = $v['img_type'];
}
$m_img->addHouseImgAll($img_data);
}
if ($result['house_id'] != NULL) {
$this->commit();
} else {
$this->rollback();
}
return $result;
}
/**
* 添加和编辑商铺
*
......
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