123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Exception;
- use think\Model;
- class SalaryYear extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'user_id' => input('userId/d',0),
- 'have' => input('have/d',0),
- 'year' => input('year','','trim'),
- 'salary' => input('salary/f',0),
- 'bonus' => input('bonus/f',0),
- 'other' => input('other/f',0),
- 'total' => input('total/f',0),
- 'givelectures' => input('givelectures/f',0),
- 'writing' => input('writing/f',0),
- 'consult' => input('consult/f',0),
- 'review' => input('review/f',0),
- 'painting' => input('painting/f',0),
- 'other2' => input('other2/f',0),
- 'total2' => input('total2/f',0),
- ];
- $result = validate('SalaryYear')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('SalaryYear')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- Db::startTrans();
- try{
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- Db::name('salary_year')->where('user_id',$data['user_id'])->update(['default'=>0]);
- $data['default'] = 1;
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- \exception('操作失败');
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- }
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->where('del',0)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- $data = $info->toArray();
- return $data;
- }
- public function lists($page,$size,$name,$year,$userId = 0){
- if($name != ''){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($year != ''){
- $map[] = ['sy.year','=',$year];
- }
- if($userId > 0){
- $map[] = ['sy.user_id','=',$userId];
- }
- $map[] = ['del','=',0];
- $lists = Db::name('salary_year')
- ->alias('sy')
- ->join('user_info ui','ui.user_id = sy.user_id')
- ->where($map)
- ->page($page,$size)
- ->field('sy.*,ui.name')
- ->order('sy.id desc')
- ->select();
- $total = Db::name('salary_year')
- ->alias('sy')
- ->join('user_info ui','ui.user_id = sy.user_id')
- ->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- public function lists2($page,$size,$name,$year,$userId = 0){
- if($name != ''){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($year != ''){
- $map[] = ['sy.year','=',$year];
- }
- if($userId > 0){
- $map[] = ['sy.user_id','=',$userId];
- }
- $map[] = ['del','=',0];
- $map[] = ['default','=',1];
- $lists = Db::name('salary_year')
- ->alias('sy')
- ->join('user_info ui','ui.user_id = sy.user_id')
- ->where($map)
- ->page($page,$size)
- ->field('sy.*,ui.name')
- ->order('sy.id desc')
- ->select();
- $total = Db::name('salary_year')
- ->alias('sy')
- ->join('user_info ui','ui.user_id = sy.user_id')
- ->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- public function del($id){
- $ret = Db::name('salary_year')->where('id',$id)->update(['del'=>1]);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function export($name,$year){
- if($name != ''){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($year != ''){
- $map[] = ['sy.year','=',$year];
- }
- $map[] = ['del','=',0];
- $map[] = ['default','=',1];
- $lists = Db::name('salary_year')
- ->alias('sy')
- ->join('user_info ui','ui.user_id = sy.user_id')
- ->where($map)
- ->field('sy.*,ui.name')
- ->order('sy.id desc')
- ->select();
- foreach ($lists as $k=>$v){
- if($v['have'] == 1){
- $lists[$k]['have_text'] = '无';
- }else{
- $lists[$k]['have_text'] = '有';
- }
- }
- $columns[] = ["title" => "姓名","key" => "name"];
- $columns[] = ["title" => "年份","key" => "year"];
- $columns[] = ["title" => "工资","key" => "salary"];
- $columns[] = ["title" => "奖金","key" => "bonus"];
- $columns[] = ["title" => "其他","key" => "other"];
- $columns[] = ["title" => "合计","key" => "total"];
- $columns[] = ["title" => "有无劳务所得","key" => "haveText"];
- $columns[] = ["title" => "讲学","key" => "givelectures"];
- $columns[] = ["title" => "写作","key" => "writing"];
- $columns[] = ["title" => "咨询","key" => "consult"];
- $columns[] = ["title" => "审稿","key" => "review"];
- $columns[] = ["title" => "书画","key" => "painting"];
- $columns[] = ["title" => "其他","key" => "other2"];
- $columns[] = ["title" => "合计","key" => "total2"];
- $columns[] = ["title" => "创建日期","key" => "createTime"];
- $data = [
- 'columns' => $columns,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- }
|