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

企业员工记录

... ... @@ -7,6 +7,7 @@ use think\Exception;
use think\exception\PDOException;
use app\common\controller\Api;
use app\mobile\model\CompanyUser;
use app\mobile\model\CompanyUserLog;
use app\mobile\model\CourseOrder;
use app\mobile\model\CourseAppraise;
use app\mobile\model\SecretOrder;
... ... @@ -226,6 +227,14 @@ class Company extends Api
'title' => '加入企业-成功',
'content' => '您的加入'.$company_name.'企业的申请已通过,该企业的学习自老您都可以免费共享了哦,快去试试吧。'
]);
// 新增员工记录
CompanyUserLog::create([
'company_id' => $info['company_id'],
'user_id' => $info['user_id'],
'name' => $info['name'],
'mobile' => $info['mobile'],
'type' => '1'
]);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
... ... @@ -302,6 +311,14 @@ class Company extends Api
empty($company_user_id) && $this->error('缺少必需参数');
$info = CompanyUser::get($company_user_id);
empty($info) && $this->error('申请信息不存在');
// 删除员工记录
CompanyUserLog::create([
'company_id' => $info['company_id'],
'user_id' => $info['user_id'],
'name' => $info['name'],
'mobile' => $info['mobile'],
'type' => '2'
]);
$info->delete();
$this->success('移出成功');
}
... ...
... ... @@ -7,6 +7,7 @@ use app\mobile\model\News;
use app\mobile\model\Exam;
use app\mobile\model\UserExam;
use app\mobile\model\CompanyUser;
use app\mobile\model\CompanyUserLog;
use app\mobile\model\Message;
use app\mobile\model\Statistic;
use think\Db;
... ... @@ -87,7 +88,7 @@ class Index extends Api
$banner_list = IndexBanner::order('createtime desc')->field('id,image,url')->select();
// 消息
$message = Message::where('user_id',$this->auth->id)->where('is_read','0')->field('id,title')->find();
$message = $message ?: [];
$message = $message ?: (Object)[];
$this->success('成功',compact('exam_list','banner_list','exam','message'));
}
... ... @@ -241,22 +242,38 @@ class Index extends Api
->where('user_id',$user['id'])
->field('status')
->find();
if($company_user){
if($company_user['status'] == '0'){
if($company_user && $company_user['status'] == '1'){
$this->error('加入企业成功,请勿重复提交申请');
}
Db::startTrans();
try {
if($company_user){
$company_user->status = '1';
$company_user->save();
}
if($company_user['status'] == '1'){
$this->error('加入企业成功,请勿重复提交申请');
}
CompanyUser::create([
'user_id' => $user['id'],
'company_id' => $company_id,
'name' => $user['nickname'],
'mobile' => $user['mobile'],
'status' => '1'
]);
// 新增员工记录
CompanyUserLog::create([
'company_id' => $company_id,
'user_id' => $user['id'],
'name' => $user['nickname'],
'mobile' => $user['mobile'],
'type' => '1'
]);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
CompanyUser::create([
'user_id' => $this->auth->id,
'company_id' => $company_id,
'name' => $user['nickname'],
'mobile' => $user['mobile'],
'status' => '1'
]);
$this->success('加入企业成功');
}
... ...
<?php
namespace app\mobile\model;
use think\Model;
class CompanyUserLog extends Model
{
// 表名
protected $name = 'mobile_company_user_log';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'false';
}
\ No newline at end of file
... ...