Browse Source

添加客户修改,编辑公司资料修改

lizhen_gitee 8 months ago
parent
commit
dd5da0ecc4

+ 2 - 1
application/company/controller/Maintain.php

@@ -11,7 +11,7 @@ use app\common\model\Maintain as Maintainmodel;
 class Maintain extends Apic
 {
     protected $noNeedLogin = [];
-    protected $noNeedRight = [];
+    protected $noNeedRight = ['index'];
 
     protected $table = 'maintain';
 
@@ -72,6 +72,7 @@ class Maintain extends Apic
         $this->success(1,$rs);
     }
 
+    //列表
     public function lists(){
         $orderno     = input('orderno','');
         $projectname = input('projectname','');

+ 17 - 4
application/company/controller/Usercenter.php

@@ -9,10 +9,23 @@ use think\Db;
  */
 class Usercenter extends Apic
 {
-    protected $noNeedLogin = ['*'];
-    protected $noNeedRight = ['*'];
+    protected $noNeedLogin = [''];
+    protected $noNeedRight = ['company_info'];
 
-    //轮播图
+    //信息维护
+    public function company_info(){
+        $banner = Db::name('banner')->where('company_id',$this->auth->company_id)->column('image');
+        $company = Db::name('company')->field('aboutus_image,aboutus')->where('id',$this->auth->company_id)->find();
+        $rs = [
+            'banner' => one_domain_image(implode(',',$banner)),
+            'aboutus' => $company['aboutus'],
+            'aboutus_image' => localpath_to_netpath($company['aboutus_image']),
+        ];
+
+        $this->success(1,$rs);
+    }
+
+    //设置轮播图,关于我们图
     public function set_banner()
     {
         //轮播图
@@ -39,7 +52,7 @@ class Usercenter extends Apic
         $this->success();
     }
 
-    //编辑关于我们
+    //设置关于我们
     public function set_aboutus()
     {
         $aboutus_image = input('aboutus','');

+ 106 - 1
application/company/controller/Usercompany.php

@@ -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;
+    }