...
|
...
|
@@ -23,7 +23,7 @@ use think\Url; |
|
|
use SmsDemo;
|
|
|
//use think\Route;
|
|
|
/**
|
|
|
* @title 30分钟后发布
|
|
|
* @title 订单修改
|
|
|
* @description 接口说明
|
|
|
* @group 接口分组
|
|
|
*/
|
...
|
...
|
@@ -37,7 +37,27 @@ class ThirdsendController extends HomeBaseController |
|
|
$this->postModel = $postModel;
|
|
|
}
|
|
|
|
|
|
// 查询中介报价
|
|
|
/**
|
|
|
* API返回信息格式函数 ;0失败,1成功,-1需要登录
|
|
|
* @param string $code
|
|
|
* @param string $message
|
|
|
* @param array $data
|
|
|
*/
|
|
|
public function apiResponse($code = '0', $message = '',$data = array(),$nums =0){
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
header('Content-Type:application/json; charset=utf-8');
|
|
|
$result = array(
|
|
|
'code'=>$code,
|
|
|
'message'=>$message,
|
|
|
'data'=>$data,
|
|
|
'nums'=>''.$nums
|
|
|
);
|
|
|
die(json_encode($result,JSON_UNESCAPED_UNICODE));
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 查询中介报价(暂未用)
|
|
|
// $need_id 需求id
|
|
|
public function Offer($user_id,$need_id){
|
|
|
$where_agency['status'] = 2;
|
...
|
...
|
@@ -75,6 +95,478 @@ class ThirdsendController extends HomeBaseController |
|
|
}
|
|
|
}
|
|
|
|
|
|
public function isLogin($token){
|
|
|
$where_member['token'] = $token;
|
|
|
// $where_member['status'] = 1;
|
|
|
$member = Db::name('Member')->where($where_member)->field('id,status')->find();
|
|
|
if($member){
|
|
|
if($member['status'] == 9){
|
|
|
$this->apiResponse('0','您已被拉入黑名单');
|
|
|
}else{
|
|
|
return $member;
|
|
|
}
|
|
|
}else{
|
|
|
$this->apiResponse('-1','请重新登录');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @title 30分钟后发布(sure)(时间为0时调用)
|
|
|
* @description 接口说明
|
|
|
* @author 开发者
|
|
|
* @url /api/portal/Thirdsend/thirdChange
|
|
|
* @method POST
|
|
|
* @param name:token type:int require:1 default: other: desc:token
|
|
|
* @param name:need_id type:int require:1 default: other: desc:需求id
|
|
|
*/
|
|
|
// 30分钟后发布(sure)(时间为0时调用)
|
|
|
// need_id 需求id
|
|
|
public function thirdChange(){
|
|
|
Db::startTrans();
|
|
|
$data = $this->request->param();
|
|
|
$this->isLogin($data['token']);
|
|
|
if(empty($data['need_id'])){
|
|
|
$this->apiResponse('0','需求id不能为空');
|
|
|
}
|
|
|
$where_need['status'] = 2;
|
|
|
$where_need['id'] = $data['need_id'];
|
|
|
$userNeedList = Db::name('UserNeed')->where($where_need)->field('id,pay_time')->find();
|
|
|
$time = time();
|
|
|
if($time < $userNeedList['pay_time']+1800){
|
|
|
$this->apiResponse('0','未到发布时间');
|
|
|
}else{
|
|
|
$where_save['id'] = $data['need_id'];
|
|
|
$save['status'] = 3;
|
|
|
$save['update_time'] = time();
|
|
|
$fianl_save = Db::name('UserNeed')->where($where_save)->update($save);
|
|
|
if($fianl_save){
|
|
|
Db::commit();
|
|
|
$where_return['id'] = $data['need_id'];
|
|
|
$return = Db::name('UserNeed')->where($where_return)->find();
|
|
|
$this->apiResponse('1','成功',$return);
|
|
|
}else{
|
|
|
Db::rollback();
|
|
|
$this->apiResponse('0','失败');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @title 规定时间结束报价(sure)(时间为0时调用)
|
|
|
* @description 接口说明
|
|
|
* @author 开发者
|
|
|
* @url /api/portal/Thirdsend/timeOver
|
|
|
* @method POST
|
|
|
* @param name:token type:int require:1 default: other: desc:token
|
|
|
* @param name:need_id type:int require:1 default: other: desc:需求id
|
|
|
*/
|
|
|
// 规定时间结束报价(sure)(时间为0时调用)
|
|
|
// need_id 需求id
|
|
|
public function timeOver()
|
|
|
{
|
|
|
Db::startTrans();
|
|
|
$data = $this->request->param();
|
|
|
$this->isLogin($data['token']);
|
|
|
if(empty($data['need_id'])){
|
|
|
$this->apiResponse('0','需求id不能为空');
|
|
|
}
|
|
|
// 查询用户发布需求信息
|
|
|
$where_need['status'] = 3;
|
|
|
$where_need['id'] = $data['need_id'];
|
|
|
$userNeedList = Db::name('UserNeed')->where($where_need)->field('id,quotation_time,create_time,pay_time,user_id,pay_money')->find();
|
|
|
if(!$userNeedList){
|
|
|
$this->apiResponse('0','需求状态不正确');
|
|
|
}
|
|
|
$time = time();
|
|
|
// 查询相应报价
|
|
|
$final_time = $userNeedList['pay_time'] + $userNeedList['quotation_time'] * 86400;
|
|
|
// 判断时间是否正确
|
|
|
if ($time >= $final_time) {
|
|
|
// $us_middleid = $uNeedv['id'];
|
|
|
$where_agency['a.status'] = 2;
|
|
|
$where_agency['a.pay_time'] = array('lt', time());
|
|
|
$where_agency['a.need_id'] = $userNeedList['id'];
|
|
|
$where_agency['m.type'] = 2;
|
|
|
$where_agency['m.status'] = 1;
|
|
|
$agency_list = Db::name('Agency')->alias('a')
|
|
|
->where($where_agency)
|
|
|
->join("hp_Member m", 'm.id = a.agency_id')
|
|
|
->field('a.*,m.company')
|
|
|
->select()->toArray();
|
|
|
// 查询品牌企业
|
|
|
$where_brand['status'] = 1;
|
|
|
$band_list = Db::name('Brand')->where($where_brand)->column('name');
|
|
|
$agen_arr = array();
|
|
|
if ($agency_list) {
|
|
|
// 删除十万以内报价
|
|
|
foreach ($agency_list as $tenk=>$tenv){
|
|
|
$ten_money = $tenv['housing_price'] * 10000 + $tenv['assessment_tax'] + $tenv['security_tax'] + $tenv['else_tax'] + $tenv['service_charge'];
|
|
|
if($ten_money > 1000000){
|
|
|
$is_trueMoney[] = $tenv;
|
|
|
}
|
|
|
}
|
|
|
// 判断是否超过三个报价人
|
|
|
if (count($is_trueMoney) >= 3) {
|
|
|
|
|
|
|
|
|
// 查询三人中是否有品牌中介
|
|
|
// 循环匹配品牌企业
|
|
|
foreach ($is_trueMoney as $agencyk => $agencyv) {
|
|
|
foreach ($band_list as $brak => $brav) {
|
|
|
// 判断是否在品牌企业中
|
|
|
if (strstr($brav, $agencyv['company']) !== false) {
|
|
|
// 存在
|
|
|
$agen_money = $agencyv['housing_price'] * 10000 + $agencyv['assessment_tax'] + $agencyv['security_tax'] + $agencyv['else_tax'] + $agencyv['service_charge'];
|
|
|
if (empty($agen_arr)) {
|
|
|
$agen_arr[0]['money'] = $agen_money;
|
|
|
$agen_arr[0]['id'] = $agencyv['id'];
|
|
|
} else {
|
|
|
// 判断大小
|
|
|
if ($agen_money < $agen_arr[0]['money']) {
|
|
|
$agen_arr[0]['money'] = $agen_money;
|
|
|
$agen_arr[0]['id'] = $agencyv['id'];
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 取出前三报价
|
|
|
$money = $agencyv['housing_price'] * 10000 + $agencyv['assessment_tax'] + $agencyv['security_tax'] + $agencyv['else_tax'] + $agencyv['service_charge'];
|
|
|
$money_list[$agencyv['id']] = $money;
|
|
|
}
|
|
|
asort($money_list);
|
|
|
$k = 0;
|
|
|
foreach ($money_list as $mok => $mov) {
|
|
|
$else_changeList[] = $mok;
|
|
|
if ($k < 3) {
|
|
|
$fin_list[$k]['id'] = $mok;
|
|
|
$fin_list[$k]['money'] = $mov;
|
|
|
$fin_arr[] = $mok;
|
|
|
}
|
|
|
$k += 1;
|
|
|
}
|
|
|
if($agen_arr){
|
|
|
if(!in_array($agen_arr[0]['id'],$fin_arr)){
|
|
|
// 品牌中介不在取出三个最低价中
|
|
|
$middle_agen[0] = $agen_arr[0]['id'];
|
|
|
$get_list = array_merge($fin_arr,$middle_agen);
|
|
|
}else{
|
|
|
$get_list = $fin_arr;
|
|
|
}
|
|
|
}
|
|
|
foreach ($else_changeList as $getk=>$getv){
|
|
|
if(in_array($getv,$get_list)){
|
|
|
$change_final['id'] = $getv;
|
|
|
$change_final['status'] = 4;
|
|
|
}else{
|
|
|
$change_final['id'] = $getv;
|
|
|
$change_final['status'] = 3;
|
|
|
}
|
|
|
$agencyModel = new AgencyModel();
|
|
|
$fianl_AgsaveFirst = $agencyModel->isUpdate(true)->save($change_final);
|
|
|
if(!$fianl_AgsaveFirst){
|
|
|
Db::rollback();
|
|
|
}
|
|
|
}
|
|
|
// 报价成功,更改状态
|
|
|
$userSave_statusFirst['id'] = $userNeedList['need_id'];
|
|
|
$userSave_statusFirst['status'] = 5;
|
|
|
$userSave_statusFirst['choose_time'] = time();
|
|
|
$userNeedModel = new UserNeedModel();
|
|
|
$fianl_Ussave = $userNeedModel->isUpdate(true)->save($userSave_statusFirst);
|
|
|
if(!$fianl_Ussave){
|
|
|
Db::rollback();
|
|
|
}
|
|
|
} else {
|
|
|
// 报价小于3人,更改订单状态,报价失败
|
|
|
foreach ($agency_list as $changeka=>$changeva){
|
|
|
$change_final['id'] = $changeva['id'];
|
|
|
$change_final['status'] = 7;
|
|
|
$agencyModel = new AgencyModel();
|
|
|
$fianl_AgsaveNext = $agencyModel->isUpdate(true)->save($change_final);
|
|
|
|
|
|
if(!$fianl_AgsaveNext){
|
|
|
Db::rollback();
|
|
|
}
|
|
|
// 退回中介保证金
|
|
|
$add_a['user_id'] = $changeva['agency_id'];
|
|
|
$add_a['title'] = '报价人数不足';
|
|
|
$add_a['type'] = 1;
|
|
|
$add_a['reason'] = 1;
|
|
|
$add_a['money'] = $changeva['deposit'];
|
|
|
$add_a['create_time'] = time();
|
|
|
$add_a['update_time'] = time();
|
|
|
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
|
|
|
if (!$amoney_id) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
// 用户表增加金额
|
|
|
$where_member['type'] = 2;
|
|
|
$where_member['id'] = $changeva['agency_id'];
|
|
|
$add_money = Db::name('Member')->where($where_member)->setInc('money',$changeva['deposit']);
|
|
|
if (!$add_money) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
$userSave_status['id'] = $userNeedList['id'];
|
|
|
$userSave_status['status'] = 4;
|
|
|
$userNeedModel = new UserNeedModel();
|
|
|
$fianl_Ussave = $userNeedModel->isUpdate(true)->save($userSave_status);
|
|
|
if(!$fianl_Ussave){
|
|
|
Db::rollback();
|
|
|
}
|
|
|
|
|
|
// 退回保证金
|
|
|
// 用户
|
|
|
// 加用户金额明细表
|
|
|
$add_del['need_id'] = $userNeedList['id'];
|
|
|
$add_del['user_id'] = $userNeedList['user_id'];
|
|
|
$add_del['title'] = '报价人数不足';
|
|
|
$add_del['reason'] = 1;
|
|
|
$add_del['type'] = 1;
|
|
|
$add_del['money'] = $userNeedList['pay_money'];
|
|
|
$add_del['create_time'] = time();
|
|
|
$add_del['update_time'] = time();
|
|
|
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
|
|
|
if (!$umoney_id) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
$where_memberNext['type'] = 1;
|
|
|
$where_memberNext['id'] = $userNeedList['user_id'];
|
|
|
$add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']);
|
|
|
if (!$add_moneyNext) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} else {
|
|
|
// 没有报价
|
|
|
$userSave_status['id'] = $userNeedList['id'];
|
|
|
$userSave_status['status'] = 4;
|
|
|
$userNeedModel = new UserNeedModel();
|
|
|
$fianl_Ussave = $userNeedModel->isUpdate(true)->save($userSave_status);
|
|
|
if(!$fianl_Ussave){
|
|
|
Db::rollback();
|
|
|
}
|
|
|
|
|
|
// 退回保证金
|
|
|
// 用户
|
|
|
// 加用户金额明细表
|
|
|
$add_del['need_id'] = $userNeedList['id'];
|
|
|
$add_del['user_id'] = $userNeedList['user_id'];
|
|
|
$add_del['title'] = '报价人数不足';
|
|
|
$add_del['type'] = 1;
|
|
|
$add_del['money'] = $userNeedList['pay_money'];
|
|
|
$add_del['create_time'] = time();
|
|
|
$add_del['update_time'] = time();
|
|
|
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
|
|
|
if (!$umoney_id) {
|
|
|
Db::rollback();
|
|
|
$this->apiResponse('0','金额明细添加失败');
|
|
|
}
|
|
|
$where_memberNext['type'] = 1;
|
|
|
$where_memberNext['id'] = $userNeedList['user_id'];
|
|
|
$add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']);
|
|
|
if (!$add_moneyNext) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
// 插入数据库
|
|
|
// 用户需求表
|
|
|
// 中介报价表
|
|
|
Db::commit();
|
|
|
$where_return['id'] = $data['need_id'];
|
|
|
$return = Db::name('UserNeed')->where($where_return)->find();
|
|
|
$this->apiResponse('1','成功',$return);
|
|
|
}else{
|
|
|
$this->apiResponse('0','时间不正确');
|
|
|
}
|
|
|
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @title 三天用户选择(sure)(时间为0时调用)
|
|
|
* @description 接口说明
|
|
|
* @author 开发者
|
|
|
* @url /api/portal/Thirdsend/choose
|
|
|
* @method POST
|
|
|
* @param name:token type:int require:1 default: other: desc:token
|
|
|
* @param name:need_id type:int require:1 default: other: desc:需求id
|
|
|
*/
|
|
|
// 三天用户选择(sure)(时间为0时调用)
|
|
|
// need_id 需求id
|
|
|
public function choose(){
|
|
|
Db::startTrans();
|
|
|
$data = $this->request->param();
|
|
|
$this->isLogin($data['token']);
|
|
|
if(empty($data['need_id'])){
|
|
|
$this->apiResponse('0','需求id不能为空');
|
|
|
}
|
|
|
// 查询用户发布需求信息
|
|
|
$where_need['status'] = 5;
|
|
|
$where_need['id'] = $data['need_id'];
|
|
|
$userNeedList = Db::name('UserNeed')->where($where_need)->field('id,choose_time,user_id,pay_money,choose_time')->find();
|
|
|
if($userNeedList){
|
|
|
// foreach ($userNeedList as $needk=>$needv) {
|
|
|
if (time() >= ($userNeedList['choose_time'] + 259200)) {
|
|
|
$where_agency['need_id'] = $userNeedList['id'];
|
|
|
$where_agency['status'] = 4;
|
|
|
$agency_list = Db::name('Agency')->where($where_agency)->select()->toArray();
|
|
|
if ($agency_list) {
|
|
|
$where_agencyUpdate['need_id'] = $userNeedList['id'];
|
|
|
$where_agencyUpdate['status'] = 4;
|
|
|
$agency_save['status'] = 8;
|
|
|
$agency_save['update_time'] = time();
|
|
|
$agency_result = Db::name('Agency')->where($where_agencyUpdate)->update($agency_save);
|
|
|
if (!$agency_result) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
}
|
|
|
$where_needUpdate['id'] = $userNeedList['id'];
|
|
|
$needUpdate['status'] = 6;
|
|
|
$need_result = Db::name('UserNeed')->where($where_needUpdate)->update($needUpdate);
|
|
|
if (!$need_result) {
|
|
|
Db::rollback();
|
|
|
} else {
|
|
|
// 加用户金额明细表
|
|
|
$add_del['need_id'] = $userNeedList['id'];
|
|
|
$add_del['user_id'] = $userNeedList['user_id'];
|
|
|
$add_del['title'] = '未选择中介';
|
|
|
$add_del['type'] = 2;
|
|
|
$add_del['money'] = $userNeedList['pay_money'];
|
|
|
$add_del['create_time'] = time();
|
|
|
$add_del['update_time'] = time();
|
|
|
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
|
|
|
if (!$umoney_id) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
// 中介金额明细表
|
|
|
foreach ($agency_list as $agenk=>$agenv){
|
|
|
$add_a['ag_id'] = $agenv['id'];
|
|
|
$add_a['user_id'] = $agenv['agency_id'];
|
|
|
$add_a['title'] = '用户未选择中介';
|
|
|
$add_a['type'] = 1;
|
|
|
$add_a['money'] = $agenv['deposit'];
|
|
|
$add_a['create_time'] = time();
|
|
|
$add_a['update_time'] = time();
|
|
|
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
|
|
|
if (!$amoney_id) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
$where_member['type'] = 2;
|
|
|
$where_member['id'] = $agenv['agency_id'];
|
|
|
$add_money = Db::name('Member')->where($where_member)->setInc('money',$agenv['deposit']);
|
|
|
if (!$add_money) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
// }
|
|
|
Db::commit();
|
|
|
$where_return['id'] = $data['need_id'];
|
|
|
$return = Db::name('UserNeed')->where($where_return)->find();
|
|
|
$this->apiResponse('1','成功',$return);
|
|
|
}else{
|
|
|
$this->apiResponse('0','需求错误');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @title 三天中介确认(时间为0时调用)
|
|
|
* @description 接口说明
|
|
|
* @author 开发者
|
|
|
* @url /api/portal/Thirdsend/threeChoose
|
|
|
* @method POST
|
|
|
* @param name:token type:int require:1 default: other: desc:token
|
|
|
* @param name:need_id type:int require:1 default: other: desc:需求id
|
|
|
*/
|
|
|
// 三天中介确认(时间为0时调用)
|
|
|
// need_id 需求id
|
|
|
public function threeChoose(){
|
|
|
Db::startTrans();
|
|
|
$data = $this->request->param();
|
|
|
$this->isLogin($data['token']);
|
|
|
if(empty($data['need_id'])){
|
|
|
$this->apiResponse('0','需求id不能为空');
|
|
|
}
|
|
|
$where_need['status'] = 7;
|
|
|
$where_need['id'] = $data['need_id'];
|
|
|
$need_list = Db::name('UserNeed')->where($where_need)->field('id,choose_time')->find();
|
|
|
if($need_list){
|
|
|
// foreach ($need_list as $needk=>$needv){
|
|
|
if(time() >= ($need_list['choose_time']+259200)){
|
|
|
$where_agency['status'] = 5;
|
|
|
$where_agency['need_id'] = $need_list['id'];
|
|
|
$agency = Db::name('Agency')->where($where_agency)->find();
|
|
|
// 修改中介报价状态
|
|
|
if($agency){
|
|
|
$where_changeAgency['id'] = $agency['id'];
|
|
|
$changeAgency['status'] = 10;
|
|
|
$changeAgency['update_time'] = time();
|
|
|
$update_a = Db::name('Agency')->where($where_changeAgency)->update($changeAgency);
|
|
|
if(!$update_a){
|
|
|
Db::rollback();
|
|
|
}
|
|
|
}
|
|
|
// 增加中介保证金变化
|
|
|
$add_a['ag_id'] = $agency['id'];
|
|
|
$add_a['user_id'] = $agency['agency_id'];
|
|
|
$add_a['title'] = '中介未确认';
|
|
|
$add_a['type'] = 2;
|
|
|
$add_a['money'] = $agency['deposit'];
|
|
|
$add_a['create_time'] = time();
|
|
|
$add_a['update_time'] = time();
|
|
|
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
|
|
|
if (!$amoney_id) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
// 修改用户需求状态
|
|
|
$where_needChange['id'] = $need_list['id'];
|
|
|
$update_need['status'] = 8;
|
|
|
$update_need['update_time'] = time();
|
|
|
$change_needFinal = Db::name('UserNeed')->where($where_needChange)->update($update_need);
|
|
|
if (!$change_needFinal) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
// 增加用户保证金,余额
|
|
|
$add_del['need_id'] = $need_list['id'];
|
|
|
$add_del['user_id'] = $need_list['user_id'];
|
|
|
$add_del['title'] = '中介未确认';
|
|
|
$add_del['type'] = 1;
|
|
|
$add_del['money'] = $need_list['pay_money'];
|
|
|
$add_del['create_time'] = time();
|
|
|
$add_del['update_time'] = time();
|
|
|
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
|
|
|
if (!$umoney_id) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
$where_member['type'] = 1;
|
|
|
$where_member['id'] = $need_list['user_id'];
|
|
|
$add_money = Db::name('Member')->where($where_member)->setInc('money',$need_list['pay_money']);
|
|
|
if (!$add_money) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
}
|
|
|
// }
|
|
|
Db::commit();
|
|
|
$where_return['id'] = $data['need_id'];
|
|
|
$return = Db::name('UserNeed')->where($where_return)->find();
|
|
|
$this->apiResponse('1','成功',$return);
|
|
|
}else{
|
|
|
$this->apiResponse('0','需求错误');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 30分钟后发布(sure)(分钟执行)
|
...
|
...
|
|