Salary.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\index\controller;
  3. use app\index\validate\UserSalary;
  4. use think\Db;
  5. class Salary extends Base
  6. {
  7. public function lists(){
  8. $page = input('page/d',1);
  9. $length = input('size/d',10);
  10. $month = input('month','','trim');
  11. $start = ($page - 1) * $length;
  12. $map['org_id'] = $this->orgId;
  13. if($month){
  14. $map['month'] = $month;
  15. }
  16. $list = Db::name('user_salary')
  17. ->where($map)
  18. ->limit($start,$length)
  19. ->order('id desc')
  20. ->select();
  21. foreach ($list as $k=>$v){
  22. $list[$k]['name'] = Db::name('user_archives')->where('id',$v['uaid'])->value('name');
  23. }
  24. $total = Db::name('user_salary')->where($map)->count();
  25. $data = [
  26. 'total' => $total,
  27. 'list' => $list?$list:[]
  28. ];
  29. ajax_return_ok($data);
  30. }
  31. public function add(){
  32. $data = [
  33. 'uaid' => input('uaid/d',0),
  34. 'salary' => input('salary/f',0),
  35. 'days' => input('days/d',0),
  36. 'real_days' => input('real_days/d',0),
  37. 'month' => input('month','','trim'),
  38. 'jx_money' => input('jx_money/f',0),
  39. 'gw_money' => input('gw_money/f',0),
  40. 'jb_money' => input('jb_money/f',0),
  41. 'hb_money' => input('hb_money/f',0),
  42. 'jb_days' => input('jb_days/d',0),
  43. 'cb_money' => input('cb_money/f',0),
  44. 'caib_money' => input('caib_money/f',0),
  45. 'jj_money' => input('jj_money/f',0),
  46. 'kk_money' => input('kk_money/f',0),
  47. 'tax_money' => input('tax_money/f',0),
  48. ];
  49. $data['org_id'] = $this->orgId;
  50. $validate = new UserSalary();
  51. if (!$validate->check($data)) {
  52. ajax_return_error($validate->getError());
  53. }
  54. $cqsalary = $data['salary'] * ($data['real_days']/$data['days']);
  55. $real_salary = $cqsalary + $data['jx_money'] + $data['gw_money'] + $data['jb_money'] + $data['hb_money'] + $data['cb_money'] + $data['caib_money'] + $data['jj_money'] - $data['kk_money'] - $data['tax_money'];
  56. $data['real_salary'] = round($real_salary,2);
  57. if(empty($data['id'])){ // 新增
  58. unset($data['id']);
  59. $data['create_time'] = date('Y-m-d H:i:s');
  60. $ret = Db::name('user_salary')->strict(false)->insert($data);
  61. }else{ // 编辑
  62. $data['update_time'] = date('Y-m-d H:i:s');
  63. $ret = Db::name('user_salary')->where('id',$data['id'])->strict(false)->update($data);
  64. }
  65. if($ret){
  66. ajax_return_ok();
  67. }else{
  68. ajax_return_error('保存失败');
  69. }
  70. }
  71. public function info(){
  72. $id = input('id/d',0);
  73. $info = Db::name('user_salary')->where('id',$id)->find();
  74. if(!$info){
  75. ajax_return_error('数据不存在');
  76. }
  77. ajax_return_ok($info);
  78. }
  79. public function del(){
  80. $id = input('id/d',0);
  81. $info = Db::name('user_salary')->where('id',$id)->delete();
  82. if(!$info){
  83. ajax_return_error('删除失败');
  84. }
  85. ajax_return_ok('','删除成功');
  86. }
  87. }