|
@@ -4,6 +4,8 @@ namespace app\company\controller;
|
|
|
|
|
|
use app\common\controller\Apic;
|
|
|
use think\Db;
|
|
|
+use app\common\model\User as Usermodel;
|
|
|
+use think\Exception;
|
|
|
/**
|
|
|
* 客户管理
|
|
|
*/
|
|
@@ -69,7 +71,7 @@ class Usercompany extends Apic
|
|
|
$this->success(1,$find);
|
|
|
}
|
|
|
|
|
|
- public function add(){
|
|
|
+ public function add_old(){
|
|
|
$user_id = input('user_id',0);
|
|
|
|
|
|
Db::startTrans();
|
|
@@ -108,6 +110,70 @@ class Usercompany extends Apic
|
|
|
$this->success();
|
|
|
}
|
|
|
|
|
|
+ //检查手机号
|
|
|
+ public function check_mobile(){
|
|
|
+ $mobile = input('mobile','');
|
|
|
+ if(empty($mobile)){
|
|
|
+ $this->error();
|
|
|
+ }
|
|
|
+
|
|
|
+ //检查用户
|
|
|
+ $find = Db::name('user')->where('mobile',$mobile)->find();
|
|
|
+ if($find){
|
|
|
+ $this->error('该手机号已被注册客户');
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加客户
|
|
|
+ public function add(){
|
|
|
+ $mobile = input('mobile','');
|
|
|
+ if(empty($mobile)){
|
|
|
+ $this->error('手机号必填');
|
|
|
+ }
|
|
|
+
|
|
|
+ //检查用户
|
|
|
+ $find = Db::name('user')->where('mobile',$mobile)->find();
|
|
|
+ if($find){
|
|
|
+ $this->error('该手机号已被注册客户');
|
|
|
+ }
|
|
|
+
|
|
|
+ //注册到用户表
|
|
|
+ $nickname = input('nickname','');
|
|
|
+ if(empty($nickname)){
|
|
|
+ $this->error('客户名必填');
|
|
|
+ }
|
|
|
+ $extend = [
|
|
|
+ 'nickname' => $nickname,
|
|
|
+ 'company_id' => $this->auth->company_id,
|
|
|
+ ];
|
|
|
+ $register_rs = $this->register($mobile,$extend);
|
|
|
+ if($register_rs === false){
|
|
|
+ $this->error('添加客户失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $user_id = $register_rs;
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ //添加客户
|
|
|
+ $data = [
|
|
|
+ 'user_id' => $user_id,
|
|
|
+ 'header' => input('header',''),
|
|
|
+ 'starttime' => input('starttime','','strtotime'),
|
|
|
+ 'endtime' => input('endtime','','strtotime'),
|
|
|
+ 'company_id' => $this->auth->company_id,
|
|
|
+ ];
|
|
|
+ $uc_id = Db::name($this->table)->insertGetId($data);
|
|
|
+ if(!$uc_id){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('添加客户失败,请重新再试');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
+
|
|
|
public function info(){
|
|
|
$id = input('id',0);
|
|
|
$info = Db::name($this->table)->alias('a')
|
|
@@ -175,7 +241,46 @@ class Usercompany extends Apic
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //来自app\common\library\register
|
|
|
+
|
|
|
+ public function register($mobile = '', $extend = [])
|
|
|
+ {
|
|
|
+ $ip = request()->ip();
|
|
|
+ $time = time();
|
|
|
|
|
|
+ $data = [
|
|
|
+ 'mobile' => $mobile,
|
|
|
+ 'avatar' => config('user_default_avatar'),
|
|
|
+ ];
|
|
|
+ $params = array_merge($data, [
|
|
|
+ 'jointime' => $time,
|
|
|
+ 'joinip' => $ip,
|
|
|
+ 'logintime' => $time,
|
|
|
+ 'loginip' => $ip,
|
|
|
+ 'prevtime' => $time,
|
|
|
+ 'status' => 1
|
|
|
+ ]);
|
|
|
+ $params = array_merge($params, $extend);
|
|
|
+
|
|
|
+ //账号注册时需要开启事务,避免出现垃圾数据
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $user = Usermodel::create($params, true);
|
|
|
+
|
|
|
+ $this->_user = Usermodel::get($user->id);
|
|
|
+ $this->_user->username = 'u' . (10000 + $user->id);
|
|
|
+ $this->_user->save();
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ return $user->id;
|
|
|
+ } catch (Exception $e) {
|
|
|
+
|
|
|
+ Db::rollback();
|
|
|
+// return $e->getMessage();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|