123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace app\index\controller;
- use app\index\validate\UserSalary;
- use think\Db;
- class Salary extends Base
- {
- public function lists(){
- $page = input('page/d',1);
- $length = input('size/d',10);
- $month = input('month','','trim');
- $start = ($page - 1) * $length;
- $map['org_id'] = $this->orgId;
- if($month){
- $map['month'] = $month;
- }
- $list = Db::name('user_salary')
- ->where($map)
- ->limit($start,$length)
- ->order('id desc')
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['name'] = Db::name('user_archives')->where('id',$v['uaid'])->value('name');
- }
- $total = Db::name('user_salary')->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $list?$list:[]
- ];
- ajax_return_ok($data);
- }
- public function add(){
- $data = [
- 'uaid' => input('uaid/d',0),
- 'salary' => input('salary/f',0),
- 'days' => input('days/d',0),
- 'real_days' => input('real_days/d',0),
- 'month' => input('month','','trim'),
- 'jx_money' => input('jx_money/f',0),
- 'gw_money' => input('gw_money/f',0),
- 'jb_money' => input('jb_money/f',0),
- 'hb_money' => input('hb_money/f',0),
- 'jb_days' => input('jb_days/d',0),
- 'cb_money' => input('cb_money/f',0),
- 'caib_money' => input('caib_money/f',0),
- 'jj_money' => input('jj_money/f',0),
- 'kk_money' => input('kk_money/f',0),
- 'tax_money' => input('tax_money/f',0),
- ];
- $data['org_id'] = $this->orgId;
- $validate = new UserSalary();
- if (!$validate->check($data)) {
- ajax_return_error($validate->getError());
- }
- $cqsalary = $data['salary'] * ($data['real_days']/$data['days']);
- $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'];
- $data['real_salary'] = round($real_salary,2);
- if(empty($data['id'])){ // 新增
- unset($data['id']);
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = Db::name('user_salary')->strict(false)->insert($data);
- }else{ // 编辑
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = Db::name('user_salary')->where('id',$data['id'])->strict(false)->update($data);
- }
- if($ret){
- ajax_return_ok();
- }else{
- ajax_return_error('保存失败');
- }
- }
- public function info(){
- $id = input('id/d',0);
- $info = Db::name('user_salary')->where('id',$id)->find();
- if(!$info){
- ajax_return_error('数据不存在');
- }
- ajax_return_ok($info);
- }
- public function del(){
- $id = input('id/d',0);
- $info = Db::name('user_salary')->where('id',$id)->delete();
- if(!$info){
- ajax_return_error('删除失败');
- }
- ajax_return_ok('','删除成功');
- }
- }
|