12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use app\Request;
- use think\Db;
- use think\Exception;
- use think\Model;
- class UserAnnualLog extends Model
- {
- public function add(){
- $data = [
- 'user_id' => input('uid/d',0),
- 'create_user_id' => input('userId/d',0),
- 'annual_leave' => input('annualLeave/f',0),
- 'org_id' => input('orgId/d',0),
- 'remark' => input('remark','','trim'),
- 'create_time' => date('Y-m-d H:i:s')
- ];
- $result = validate('UserAnnualLog')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('UserAnnualLog')->getError());
- }
- Db::startTrans();
- try{
- $ret = $this->allowField(true)->save($data);
- if(!$ret){
- \exception('操作失败');
- }
- $res = Db::name('user_info')->where('user_id',$data['user_id'])->setField('annual_leave',$data['annual_leave']);
- if(!$res){
- \exception('操作失败');
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- HelpHander::error('操作失败'.$e->getMessage());
- }
- return true;
- }
- public function lists($page,$size,$orgId){
- $map[] = ['org_id','=',$orgId];
- $lists = Db::name('user_annual_log')
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['user_name'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
- $lists[$k]['create_user_name'] = Db::name('user_info')->where('user_id',$v['create_user_id'])->value('name');
- }
- $total = Db::name('user_annual_log')->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists
- ];
- return $data;
- }
- }
|