Commit 0dde21e6 authored by zhuwei's avatar zhuwei

收藏或取消收藏客户2收藏或取消收藏商铺

parent a418d5f0
<?php
namespace app\api_broker\controller;
/**
* Created by PhpStorm.
* User: zhuwei
* Date: 2018/7/4
* Time: 下午3:25
*/
use app\api_broker\extend\Basic;
use app\model\ACollectHouse;
use think\Request;
class CollectHouse extends Basic
{
protected $aCollectHouse;
public function __construct($request = null)
{
parent::__construct($request);
$this->aCollectHouse = new ACollectHouse();
}
/**
* 收藏或取消收藏商铺
* User: 朱伟
* Date: 2018-07-04
* Time: 15:35:40
*/
public function addCollectHouse(){
$params = $this->params;
/*$params = array(
"agents_id" => 1,
"house_id" => 4,
"status" => 2,
);*/
if (!isset($params["agents_id"]) or !isset($params["house_id"]) or !isset($params["status"])) {
return $this->response("101", "请求参数错误");
}
//先判断是否已经存在数据
$field = 'id,status';
$get_params['agents_id'] = $params["agents_id"];
$get_params['house_id'] = $params["house_id"];
$res = $this->aCollectHouse->getCollectHouse($field,$get_params);
if($res){//如果存在
if($res[0]['status'] != $params["status"] ){//如果存在-并且状态一致 不作处理 不一致则更新状态
$insert["id"] = $res[0]['id'];
$insert["status"] = $params["status"];
$res = $this->aCollectHouse->updateCollectHouse($insert);//int(1)
}else{
$res = true ;
}
}else{//不存在则新增数据
$insert["agents_id"] = $params['agents_id'];
$insert["house_id"] = $params['house_id'];
$insert["status"] = 1;
$res = $this->aCollectHouse->saveCollectHouse($insert);//int(1)
}
if ($res) {
return $this->response("200", "成功");
} else {
return $this->response("101", "失败");
}
}
}
\ No newline at end of file
<?php
namespace app\api_broker\controller;
/**
* Created by PhpStorm.
* User: zhuwei
* Date: 2018/7/4
* Time: 下午3:25
*/
use app\api_broker\extend\Basic;
use app\model\ACollectUser;
use think\Request;
class CollectUser extends Basic
{
protected $aCollectUser;
public function __construct($request = null)
{
parent::__construct($request);
$this->aCollectUser = new ACollectUser();
}
/**
* 收藏或取消收藏客户
* User: 朱伟
* Date: 2018-07-04
* Time: 15:35:40
*/
public function addCollectUser()
{
$params = $this->params;
/*$params = array(
"agents_id" => 2,
"user_id" => 3,
"status" => 2,
);*/
if (!isset($params["agents_id"]) or !isset($params["user_id"]) or !isset($params["status"])) {
return $this->response("101", "请求参数错误");
}
//先判断是否已经存在数据
$field = 'id,status';
$get_params['agents_id'] = $params["agents_id"];
$get_params['user_id'] = $params["user_id"];
$res = $this->aCollectUser->getCollectUser($field,$get_params);
if($res){//如果存在
if($res[0]['status'] != $params["status"] ){//如果存在-并且状态一致 不作处理 不一致则更新状态
$insert["id"] = $res[0]['id'];
$insert["status"] = $params["status"];
$res = $this->aCollectUser->updateCollectUser($insert);//int(1)
}else{
$res = true ;
}
}else{//不存在则新增数据
$insert["agents_id"] = $params['agents_id'];
$insert["user_id"] = $params['user_id'];
$insert["status"] = 1;
$res = $this->aCollectUser->saveCollectUser($insert);//int(1)
}
if ($res) {
return $this->response("200", "成功");
} else {
return $this->response("101", "失败");
}
}
}
\ No newline at end of file
<?php
namespace app\model;
use think\Db;
use think\Model;
class ACollectHouse extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'a_collect_house';
public function saveCollectHouse($data) {
$time = date("Y-m-d h:i:sa", time());
$data['create_time'] = $time;
$data['update_time'] = $time;
return $this->insert($data);
}
/**
* 查询数据
* 朱伟 2018-07-04
*/
public function getCollectHouse($field,$params)
{
$result = Db::table($this->table)
->field($field)
//->alias('a')
->where($params)
->select();
//dump($this->getLastSql());
return $result;
}
/**
* 更新数据
* 朱伟 2018-07-04
*/
public function updateCollectHouse($params)
{
$result = $this->update($params);
//dump($this->getLastSql());
return $result;
}
}
<?php
namespace app\model;
use think\Db;
use think\Model;
class ACollectUser extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'a_collect_user';
public function saveCollectUser($data) {
$time = date("Y-m-d h:i:sa", time());
$data['create_time'] = $time;
$data['update_time'] = $time;
return $this->insert($data);
}
/**
* 查询数据
* 朱伟 2018-07-04
*/
public function getCollectUser($field,$params)
{
$result = Db::table($this->table)
->field($field)
//->alias('a')
->where($params)
->select();
//dump($this->getLastSql());
return $result;
}
/**
* 更新数据
* 朱伟 2018-07-04
*/
public function updateCollectUser($params)
{
$result = $this->update($params);
//dump($this->getLastSql());
return $result;
}
}
......@@ -501,6 +501,9 @@ Route::group('broker', [
'getComment' => [ 'api_broker/news/getComment', [ 'method' => 'GET' ] ], //商学院评论列表
'commentNews' => [ 'api_broker/news/commentNews', [ 'method' => 'POST' ] ], //评论商学院文章
'addCollectUser' => [ 'api_broker/CollectUser/addCollectUser', [ 'method' => 'POST|GET' ] ], //监督执行列表 朱伟 2018-06-15
'addCollectHouse' => [ 'api_broker/CollectHouse/addCollectHouse', [ 'method' => 'POST|GET' ] ], //新增-监督执行 朱伟 2018-06-20
]);
......
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