Sfoglia il codice sorgente

员工没加管理员的,给加上

lizhen_gitee 1 anno fa
parent
commit
eaee83a9e6

+ 49 - 17
application/admin/controller/CompanyStaff.php

@@ -103,7 +103,7 @@ class CompanyStaff extends Backend
                 //密码和盐
                 if (isset($params['password'])) {
                     if (!Validate::is($params['password'], "/^[\S]{6,30}$/")) {
-                        $this->error(__("Please input correct password"));
+                        $this->error('请输入6-30位密码');
                     }
                     $params['salt'] = Random::alnum();
                     $params['password'] = md5(md5($params['password']) . $params['salt']);
@@ -120,8 +120,8 @@ class CompanyStaff extends Backend
 
                 Db::startTrans();
                 //保存
-                $result = $this->model->allowField(true)->save($params);
-                if ($result == false) {
+                $result = Db::name('company_staff')->insertGetId($params);
+                if (!$result) {
                     Db::rollback();
                     $this->error(__('No rows were inserted'));
                 }
@@ -138,7 +138,7 @@ class CompanyStaff extends Backend
                     'createtime' => time(),
                     'status'     => 'normal',
                     'company_id' => $params['company_id'],
-                    'staff_id'   => $result->id,
+                    'staff_id'   => $result,
                 ];
                 $admin_id = Db::name('admin')->insertGetId($admin);
                 if(!$admin_id){
@@ -192,7 +192,7 @@ class CompanyStaff extends Backend
                 //密码和盐
                 if (isset($params['password'])) {
                     if (!Validate::is($params['password'], "/^[\S]{6,30}$/")) {
-                        $this->error(__("Please input correct password"));
+                        $this->error('请输入6-30位密码');
                     }
                     $params['salt'] = Random::alnum();
                     $params['password'] = md5(md5($params['password']) . $params['salt']);
@@ -215,21 +215,53 @@ class CompanyStaff extends Backend
                 }
 
                 //同步到admin
-                $admin = [
-                    'username' => $params['mobile'],
-                    'nickname' => $params['truename'],
-                    'password' => $params['password'],
-                    'salt'     => $params['salt'],
-                    'mobile'   => $params['mobile'],
-                    'updatetime' => time(),
-                ];
-                $admin_rs = Db::name('admin')->where('staff_id',$ids)->update($admin);
-                if($admin_rs === false){
-                    Db::rollback();
-                    $this->error('修改员工失败');
+                $admin_info = Db::name('admin')->where('staff_id',$ids)->find();
+                if(!empty($admin_info)){
+                    $admin = [
+                        'username' => $params['mobile'],
+                        'nickname' => $params['truename'],
+                        'password' => $params['password'],
+                        'salt'     => $params['salt'],
+                        'mobile'   => $params['mobile'],
+                        'updatetime' => time(),
+                    ];
+                    $admin_rs = Db::name('admin')->where('staff_id',$ids)->update($admin);
+                    if($admin_rs === false){
+                        Db::rollback();
+                        $this->error('修改员工失败');
+                    }
+                }else{
+                    //新增
+                    //同步到admin
+                    $admin = [
+                        'username' => $params['mobile'],
+                        'nickname' => $params['truename'],
+                        'password' => $params['password'],
+                        'salt'     => $params['salt'],
+
+                        'avatar'     => '/assets/img/avatar.png',
+                        'mobile'     => $params['mobile'],
+                        'createtime' => time(),
+                        'status'     => 'normal',
+                        'company_id' => $row['company_id'],
+                        'staff_id'   => $ids,
+                    ];
+                    $admin_id = Db::name('admin')->insertGetId($admin);
+                    if(!$admin_id){
+                        Db::rollback();
+                        $this->error('编辑员工失败');
+                    }
+
+                    //管理员加组
+                    $access[] = [
+                        'uid' => $admin_id,
+                        'group_id' => $params['type'] == 2 ? 8 : 6, //8员工组,6管理组
+                    ];
+                    model('AuthGroupAccess')->saveAll($access);
                 }
 
 
+
             Db::commit();
             $this->success();
         }

+ 1 - 1
application/api/controller/company/Coupon.php

@@ -164,7 +164,7 @@ class Coupon extends Apic
             Db::rollback();
             $this->error('卡券数量不足');
         }
-        if($check['endtime'] <= time()){
+        if($check['endtime'] > 0 && $check['endtime'] <= time()){
             Db::rollback();
             $this->error('卡券已过期');
         }