SalaryRecord.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class SalaryRecord extends Validate{
  6. protected $rule = [
  7. 'type' => 'require|in:1,2,3,4,5,6,7,8,9',
  8. 'month' => 'require|checkMonth',
  9. 'users' => 'require|checkUser',
  10. ];
  11. protected $message = [
  12. 'type.require' => '参数错误',
  13. 'type.in' => '参数错误',
  14. 'users.require' => '没有要发工资的人员',
  15. ];
  16. protected $scene = [
  17. ];
  18. protected function checkUser($value,$rule,$data=[]){
  19. $users = json_decode($value,true);
  20. if(!is_array($users)){
  21. return '未选择用户';
  22. }
  23. if($data['type'] != 1 && $data['type'] != 2){
  24. return true;
  25. }
  26. foreach ($users as $k=>$v){
  27. $users[$k]['psmoney'] = (float)$v['psmoney'];
  28. $users[$k]['pwmoney'] = (float)$v['pwmoney'];
  29. $users[$k]['fixedPerformance'] = (float)$v['fixedPerformance'];
  30. $users[$k]['psmonth'] = (float)$v['psmonth'];
  31. }
  32. foreach ($users as $k=>$v){
  33. // foreach ($v as $key=>$val){
  34. // if(strpos($key,'subsidies') !== false && $val < 0){
  35. // return '金额不能为负';
  36. // }
  37. // }
  38. $should_total = $v['psmoney'] + $v['pwmoney'] + $v['fixedPerformance'] + $v['psmonth'];
  39. $ret = Db::name('salary_record_log')
  40. ->alias('srl')
  41. ->join('salary_record sr','sr.id = srl.salary_record_id')
  42. ->where('sr.month',$data['month'])
  43. ->where('sr.del',0)
  44. ->whereRaw('srl.gwgz > 0 OR srl.xjgz > 0 OR srl.jcjx > 0 OR srl.yjx > 0')
  45. ->where('srl.user_id',$v['userId'])
  46. ->find();
  47. if($should_total > 0){// 发基本工资(只能发一次)
  48. if($ret){
  49. return $v['name'].'已发过本月基本工资';
  50. }
  51. }else{
  52. if(!$ret){
  53. return $v['name'].'未发过本月基本工资不能先发补助';
  54. }
  55. }
  56. }
  57. return true;
  58. }
  59. protected function checkMonth($value,$rule,$data=[])
  60. {
  61. // $map[] = ['month','=',$data['month']];
  62. $map[] = ['del','=',0];
  63. $map[] = ['type','=',$data['type']];
  64. $map[] = ['status','in',[0,1,3]];
  65. $info = Db::name('salary_record')->where($map)->find();
  66. if($info){
  67. return '有正在处理的工资未发放';
  68. }
  69. return true;
  70. }
  71. }