UserSalary.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use think\Model;
  7. class UserSalary extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'id' => input('id/d',0),
  12. 'user_id' => input('uid/d',0),
  13. 'status' => input('status/d',0),
  14. 'remark' => input('remark','','trim'),
  15. 'company_id' => input('companyId/d',0),
  16. 'min_tax' => input('minTax/f',0),
  17. 'syjkbx' => input('syjkbx/f',0),
  18. 'ysylbx' => input('ysylbx/f',0),
  19. 'other' => input('other/f',0),
  20. 'donations' => input('donations/f',0),
  21. 'child' => input('child/f',0),
  22. 'performance_bl' => input('performanceBl/f',0),
  23. 'fixed_performance' => input('fixedPerformance/f',0),
  24. 'qtbt' => input('qtbt/f',0),
  25. 'mssr' => input('mssr/f',0),
  26. 'btjson' => input('btjson','','trim')
  27. ];
  28. $result = validate('UserSalary')->check($data,[],'');
  29. if(true !== $result){
  30. HelpHander::error(validate('UserSalary')->getError());
  31. }
  32. $id = $data['id'];
  33. unset($data['id']);
  34. if($id > 0){
  35. $data['update_time'] = date('Y-m-d H:i:s');
  36. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  37. }else{
  38. $data['create_time'] = date('Y-m-d H:i:s');
  39. $ret = $this->allowField(true)->save($data);
  40. }
  41. if(!$ret){
  42. HelpHander::error('操作失败');
  43. }
  44. return true;
  45. }
  46. public function info($id){
  47. $info = $this->where('id',$id)->find();
  48. if(!$info){
  49. HelpHander::error('数据不存在');
  50. }
  51. $data = $info->toArray();
  52. $data['userName'] = Db::name('user_info')->where('user_id',$info['user_id'])->value('name');
  53. return $data;
  54. }
  55. public function lists($page,$size,$orgId,$name,$phone,$status,$companyId){
  56. if($name != ''){
  57. $map[] = ['ui.name','like','%'.$name.'%'];
  58. }
  59. if($phone != ''){
  60. $map[] = ['u.phone','like','%'.$phone.'%'];
  61. }
  62. if($status >= 0){
  63. $map[] = ['ur.status','=',$status];
  64. }
  65. if($companyId > 0){
  66. $map[] = ['ur.company_id','=',$companyId];
  67. }
  68. $map = empty($map)?true:$map;
  69. $lists = Db::name('user_salary')
  70. ->alias('ur')
  71. ->join('user u','u.id = ur.user_id')
  72. ->join('user_info ui','ui.user_id = ur.user_id')
  73. ->where($map)
  74. ->field('ur.*,u.phone,ui.name,ui.gender')
  75. ->page($page,$size)
  76. ->order('id desc')
  77. ->select();
  78. foreach ($lists as $k=>$v){
  79. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  80. }
  81. $total = Db::name('user_salary')
  82. ->alias('ur')
  83. ->join('user u','u.id = ur.user_id')
  84. ->join('user_info ui','ui.user_id = ur.user_id')
  85. ->where($map)->count();
  86. $data = [
  87. 'total' => $total,
  88. 'list' => $lists?$lists:[]
  89. ];
  90. return $data;
  91. }
  92. public function del($id){
  93. $ret = $this->where('id',$id)->delete();
  94. if(!$ret){
  95. HelpHander::error('删除失败');
  96. }
  97. return true;
  98. }
  99. public function changeStatus($id,$enable){
  100. $ret = Db::name('user_salary')->where('id',$id)->setField('status',$enable);
  101. if(!$ret){
  102. HelpHander::error('操作失败');
  103. }
  104. return true;
  105. }
  106. }