Commit 8f850ad7 authored by hujun's avatar hujun

新增和编辑客户

parent 161e2500
......@@ -3,7 +3,7 @@
namespace app\api_broker\controller;
use app\api_broker\extend\Basic;
use think\Request;
use app\model\Users;
/**
* Created by PhpStorm.
......@@ -14,13 +14,48 @@ use think\Request;
*/
class Client extends Basic
{
protected $user;
protected $data = [];
protected $code = 200;
protected $msg = '';
function __construct($request = null)
{
parent::__construct($request);
$this->user = new Users();
}
public function selectUser(){
}
/**
* 新增或编辑客户
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function editClient() {
if ($this->params['user_nick'] || $this->params['user_nick'] || $this->params['id']) {
if ($this->request->isPost()) {
if ($this->params['id']) {
$this->data = $this->user->edit($this->params, $this->params['id']);
} else {
$this->data = $this->user->edit($this->params);
if ($this->data == -1) {
$this->code = 101;
$this->msg = '该用户已存在';
}
}
} else {
$this->data = $this->user->getClient($this->params['id']);
}
} else {
$this->code = 101;
$this->msg = 'user_nick or user_phone or id is null';
}
return $this->response($this->code, $this->msg,$this->data);
}
}
......@@ -91,4 +91,59 @@ class Users extends Model
return [ "code" => "101", "msg" => "没有该用户", 'data'=>''];
}
}
/**
* 用户新增和编辑
*
* @param $data
* @param int $id
* @return false|int
*/
public function edit($data, $id = 0) {
$insert_data['user_nick'] = $data['user_nick'];
$insert_data['user_phone'] = $data['user_phone'];
$insert_data['sex'] = $data['sex'];
if ($id) {
$this->save($insert_data,['id'=>$id]);
$return_id = $id;
} else {
$is_exist = $this->where('user_phone',$data['user_phone'])->count();
if (empty($is_exist)) {
$insert_data['referrer_id'] = $data['agents_id'];
$insert_data['agent_id'] = $data['agents_id'];
$insert_data['referrer_source'] = 20;
$insert_data['status'] = -1;
$insert_data['create_time'] = date('Y-m-d H:i:s');
$return_id = $this->save($insert_data);
} else {
$return_id = -1;
}
}
return $return_id;
}
/**
* 跟进id获取客户和经纪人信息
*
* @param $id
* @return array|bool|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getClient($id) {
if ($id) {
$data = $this->field('a.user_nick,a.user_phone,a.sex,b.id as agents_id,b.name,b.phone')->alias('a')
->join('a_agents b','a.agent_id=b.id', 'left')
->where('a.id',$id)->find();
$data['agents'] = $data['name'].'-'.$data['phone'];
unset($data['name']);
unset($data['phone']);
} else {
$data = false;
}
return $data;
}
}
......@@ -213,7 +213,8 @@ Route::group('broker', [
'refund' => [ 'api_broker/OrderLog/refund', [ 'method' => 'get|post' ] ],
'bargain' => [ 'api_broker/OrderLog/bargain', [ 'method' => 'get|post' ] ],
'statusBargain' => [ 'api_broker/OrderLog/statusBargain', [ 'method' => 'get|post' ] ],
'login' => [ 'api_broker/Broker/login', [ 'method' => 'get' ] ],
'login' => [ 'api_broker/Broker/login', [ 'method' => 'get' ] ], //经纪人登陆
'editClient' => [ 'api_broker/Client/editClient', [ 'method' => 'get|post' ] ],//添加和编辑客户
]);
//Route::miss('api/index/miss');//处理错误的url
\ No newline at end of file
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