作者 何书鹏
1 个管道 的构建 通过 耗费 10 秒

企业员工记录

@@ -7,6 +7,7 @@ use think\Exception; @@ -7,6 +7,7 @@ use think\Exception;
7 use think\exception\PDOException; 7 use think\exception\PDOException;
8 use app\common\controller\Api; 8 use app\common\controller\Api;
9 use app\mobile\model\CompanyUser; 9 use app\mobile\model\CompanyUser;
  10 +use app\mobile\model\CompanyUserLog;
10 use app\mobile\model\CourseOrder; 11 use app\mobile\model\CourseOrder;
11 use app\mobile\model\CourseAppraise; 12 use app\mobile\model\CourseAppraise;
12 use app\mobile\model\SecretOrder; 13 use app\mobile\model\SecretOrder;
@@ -226,6 +227,14 @@ class Company extends Api @@ -226,6 +227,14 @@ class Company extends Api
226 'title' => '加入企业-成功', 227 'title' => '加入企业-成功',
227 'content' => '您的加入'.$company_name.'企业的申请已通过,该企业的学习自老您都可以免费共享了哦,快去试试吧。' 228 'content' => '您的加入'.$company_name.'企业的申请已通过,该企业的学习自老您都可以免费共享了哦,快去试试吧。'
228 ]); 229 ]);
  230 + // 新增员工记录
  231 + CompanyUserLog::create([
  232 + 'company_id' => $info['company_id'],
  233 + 'user_id' => $info['user_id'],
  234 + 'name' => $info['name'],
  235 + 'mobile' => $info['mobile'],
  236 + 'type' => '1'
  237 + ]);
229 Db::commit(); 238 Db::commit();
230 } catch (PDOException $e) { 239 } catch (PDOException $e) {
231 Db::rollback(); 240 Db::rollback();
@@ -302,6 +311,14 @@ class Company extends Api @@ -302,6 +311,14 @@ class Company extends Api
302 empty($company_user_id) && $this->error('缺少必需参数'); 311 empty($company_user_id) && $this->error('缺少必需参数');
303 $info = CompanyUser::get($company_user_id); 312 $info = CompanyUser::get($company_user_id);
304 empty($info) && $this->error('申请信息不存在'); 313 empty($info) && $this->error('申请信息不存在');
  314 + // 删除员工记录
  315 + CompanyUserLog::create([
  316 + 'company_id' => $info['company_id'],
  317 + 'user_id' => $info['user_id'],
  318 + 'name' => $info['name'],
  319 + 'mobile' => $info['mobile'],
  320 + 'type' => '2'
  321 + ]);
305 $info->delete(); 322 $info->delete();
306 $this->success('移出成功'); 323 $this->success('移出成功');
307 } 324 }
@@ -7,6 +7,7 @@ use app\mobile\model\News; @@ -7,6 +7,7 @@ use app\mobile\model\News;
7 use app\mobile\model\Exam; 7 use app\mobile\model\Exam;
8 use app\mobile\model\UserExam; 8 use app\mobile\model\UserExam;
9 use app\mobile\model\CompanyUser; 9 use app\mobile\model\CompanyUser;
  10 +use app\mobile\model\CompanyUserLog;
10 use app\mobile\model\Message; 11 use app\mobile\model\Message;
11 use app\mobile\model\Statistic; 12 use app\mobile\model\Statistic;
12 use think\Db; 13 use think\Db;
@@ -87,7 +88,7 @@ class Index extends Api @@ -87,7 +88,7 @@ class Index extends Api
87 $banner_list = IndexBanner::order('createtime desc')->field('id,image,url')->select(); 88 $banner_list = IndexBanner::order('createtime desc')->field('id,image,url')->select();
88 // 消息 89 // 消息
89 $message = Message::where('user_id',$this->auth->id)->where('is_read','0')->field('id,title')->find(); 90 $message = Message::where('user_id',$this->auth->id)->where('is_read','0')->field('id,title')->find();
90 - $message = $message ?: []; 91 + $message = $message ?: (Object)[];
91 $this->success('成功',compact('exam_list','banner_list','exam','message')); 92 $this->success('成功',compact('exam_list','banner_list','exam','message'));
92 } 93 }
93 94
@@ -241,22 +242,38 @@ class Index extends Api @@ -241,22 +242,38 @@ class Index extends Api
241 ->where('user_id',$user['id']) 242 ->where('user_id',$user['id'])
242 ->field('status') 243 ->field('status')
243 ->find(); 244 ->find();
244 - if($company_user){  
245 - if($company_user['status'] == '0'){ 245 + if($company_user && $company_user['status'] == '1'){
  246 + $this->error('加入企业成功,请勿重复提交申请');
  247 + }
  248 + Db::startTrans();
  249 + try {
  250 + if($company_user){
246 $company_user->status = '1'; 251 $company_user->status = '1';
247 $company_user->save(); 252 $company_user->save();
248 } 253 }
249 - if($company_user['status'] == '1'){  
250 - $this->error('加入企业成功,请勿重复提交申请');  
251 - } 254 + CompanyUser::create([
  255 + 'user_id' => $user['id'],
  256 + 'company_id' => $company_id,
  257 + 'name' => $user['nickname'],
  258 + 'mobile' => $user['mobile'],
  259 + 'status' => '1'
  260 + ]);
  261 + // 新增员工记录
  262 + CompanyUserLog::create([
  263 + 'company_id' => $company_id,
  264 + 'user_id' => $user['id'],
  265 + 'name' => $user['nickname'],
  266 + 'mobile' => $user['mobile'],
  267 + 'type' => '1'
  268 + ]);
  269 + Db::commit();
  270 + } catch (PDOException $e) {
  271 + Db::rollback();
  272 + $this->error($e->getMessage());
  273 + } catch (Exception $e) {
  274 + Db::rollback();
  275 + $this->error($e->getMessage());
252 } 276 }
253 - CompanyUser::create([  
254 - 'user_id' => $this->auth->id,  
255 - 'company_id' => $company_id,  
256 - 'name' => $user['nickname'],  
257 - 'mobile' => $user['mobile'],  
258 - 'status' => '1'  
259 - ]);  
260 $this->success('加入企业成功'); 277 $this->success('加入企业成功');
261 } 278 }
262 279
  1 +<?php
  2 +namespace app\mobile\model;
  3 +
  4 +use think\Model;
  5 +
  6 +class CompanyUserLog extends Model
  7 +{
  8 + // 表名
  9 + protected $name = 'mobile_company_user_log';
  10 + // 开启自动写入时间戳字段
  11 + protected $autoWriteTimestamp = 'int';
  12 + // 定义时间戳字段名
  13 + protected $createTime = 'createtime';
  14 + protected $updateTime = 'false';
  15 +}