Przeglądaj źródła

pc端,客户管理

lizhen_gitee 8 miesięcy temu
rodzic
commit
5a2c030aac
1 zmienionych plików z 155 dodań i 0 usunięć
  1. 155 0
      application/company/controller/Usercompany.php

+ 155 - 0
application/company/controller/Usercompany.php

@@ -0,0 +1,155 @@
+<?php
+
+namespace app\company\controller;
+
+use app\common\controller\Apic;
+use think\Db;
+/**
+ * 客户管理
+ */
+class Usercompany extends Apic
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['find_user'];
+
+    protected $table = 'user_company';
+
+    public function index(){
+        $list = Db::name($this->table)->alias('a')
+            ->field('a.id,a.projectname,a.starttime,a.endtime,a.weituo,a.fuwujigou,a.header,a.header_mobile,user.nickname as user_nickname,user.mobile as user_mobile')
+            ->join('user','a.user_id = user.id','LEFT')
+            ->where('a.company_id',$this->auth->company_id)
+            ->where('a.deletetime',NULL)
+            ->select();
+
+        $this->success(1,$list);
+    }
+
+    //检索未绑定过的正常用户
+    public function find_user(){
+        $mobile = input('mobile','');
+
+        //检查用户
+        $find = Db::name('user')->field('id as user_id,nickname')->where('mobile',$mobile)->where('status',1)->where('company_id',0)->find();
+
+        //检查客户表
+        if($find){
+            $check = Db::name($this->table)->where('user_id',$find['user_id'])->where('deletetime',NULL)->find();
+            if($check){
+                $find = null;
+            }
+        }
+
+        $this->success(1,$find);
+    }
+
+    public function add(){
+        $user_id = input('user_id',0);
+
+        Db::startTrans();
+        $user_info = Db::name('user')->where('id',$user_id)->lock(true)->find();
+        if(empty($user_info) || $user_info['status'] != 1){
+            Db::rollback();
+            $this->error('不存在的客户');
+        }
+        if($user_info['company_id'] != 0){
+            Db::rollback();
+            $this->error('客户已经被他人绑定');
+        }
+
+        //添加客户
+        $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('添加客户失败,请重新再试');
+        }
+
+        //修改用户
+        $rs_user = Db::name('user')->where('id',$user_id)->update(['company_id'=>$this->auth->company_id]);
+        if($rs_user === false){
+            Db::rollback();
+            $this->error('添加客户失败,请重新再试');
+        }
+
+        Db::commit();
+        $this->success();
+    }
+
+    public function info(){
+        $id = input('id',0);
+        $info = Db::name($this->table)->alias('a')
+            ->field('a.*,user.nickname as user_nickname,user.mobile as user_mobile')
+            ->join('user','a.user_id = user.id','LEFT')
+            ->where('a.id',$id)
+            ->where('a.company_id',$this->auth->company_id)
+            ->find();
+        $info = info_domain_image($info,['image','header_avatar']);
+
+        $this->success(1,$info);
+    }
+
+    public function edit(){
+        $id = input('id',0);
+        $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->find();
+        if(empty($info)){
+            $this->error('没找到该信息,请刷新重试');
+        }
+
+        $data = [
+            'projectname'      => input('projectname',''),
+            'image'            => input('image',''),
+            'starttime'        => input('starttime','','strtotime'),
+            'endtime'          => input('endtime','','strtotime'),
+            'header'           => input('header',''),
+            'header_avatar'    => input('header_avatar',''),
+            'header_mobile'    => input('header_mobile',''),
+            'xiaofang'         => input('xiaofang',''),
+            'xiaofang_mobile'  => input('xiaofang_mobile',''),
+            'weituo'           => input('weituo',''),
+            'fuwujigou'        => input('fuwujigou',''),
+            'weibaofanwei'     => input('weibaofanwei',''),
+        ];
+
+        Db::name($this->table)->where('id',$id)->update($data);
+
+        $this->success();
+    }
+
+    public function del(){
+        $ids = input('ids','');
+        $ids = explode(',',$ids);
+
+        if (empty($ids)) {
+            $this->error();
+        }
+
+        Db::startTrans();
+
+        $user_company = Db::name($this->table)->where('id','IN',$ids)->where('company_id',$this->auth->company_id)->where('deletetime',NULL)->select();
+        if(!empty($user_company)){
+            foreach($user_company as $key => $uc){
+                $rs1 = Db::name($this->table)->where('id',$uc['id'])->update(['deletetime'=>time()]); //软删除
+                $rs2 = Db::name('user')->where('id',$uc['user_id'])->update(['company_id'=>0]);       //用户解除绑定
+                if($rs1 === false || $rs2 === false){
+                    Db::rollback();
+                    $this->error('删除失败');
+                }
+            }
+        }
+        Db::commit();
+        $this->success();
+    }
+
+
+
+
+
+
+}