123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Exception;
- use think\Model;
- class UserSalary extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'user_id' => input('uid/d',0),
- 'status' => input('status/d',0),
- 'remark' => input('remark','','trim'),
- 'company_id' => input('companyId/d',0),
- 'min_tax' => input('minTax/f',0),
- 'syjkbx' => input('syjkbx/f',0),
- 'ysylbx' => input('ysylbx/f',0),
- 'other' => input('other/f',0),
- 'donations' => input('donations/f',0),
- 'child' => input('child/f',0),
- 'performance_bl' => input('performanceBl/f',0),
- 'fixed_performance' => input('fixedPerformance/f',0),
- 'qtbt' => input('qtbt/f',0),
- 'mssr' => input('mssr/f',0),
- 'btjson' => input('btjson','','trim')
- ];
- $result = validate('UserSalary')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('UserSalary')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- $data = $info->toArray();
- $data['userName'] = Db::name('user_info')->where('user_id',$info['user_id'])->value('name');
- return $data;
- }
- public function lists($page,$size,$orgId,$name,$phone,$status,$companyId){
- if($name != ''){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($phone != ''){
- $map[] = ['u.phone','like','%'.$phone.'%'];
- }
- if($status >= 0){
- $map[] = ['ur.status','=',$status];
- }
- if($companyId > 0){
- $map[] = ['ur.company_id','=',$companyId];
- }
- $map = empty($map)?true:$map;
- $lists = Db::name('user_salary')
- ->alias('ur')
- ->join('user u','u.id = ur.user_id')
- ->join('user_info ui','ui.user_id = ur.user_id')
- ->where($map)
- ->field('ur.*,u.phone,ui.name,ui.gender')
- ->page($page,$size)
- ->order('id desc')
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
- }
- $total = Db::name('user_salary')
- ->alias('ur')
- ->join('user u','u.id = ur.user_id')
- ->join('user_info ui','ui.user_id = ur.user_id')
- ->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- public function del($id){
- $ret = $this->where('id',$id)->delete();
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function changeStatus($id,$enable){
- $ret = Db::name('user_salary')->where('id',$id)->setField('status',$enable);
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- }
|