WorkReport.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class WorkReport extends Validate{
  6. protected $rule = [
  7. 'work_type_id' => 'require|gt:0|checkType',
  8. 'receiver|接收人' => 'require',
  9. ];
  10. protected $message = [
  11. 'receiver.require' => '未选择接收人',
  12. 'work_type_id.require' => '未选择汇报类型',
  13. 'work_type_id.gt' => '未选择汇报类型',
  14. ];
  15. protected $scene = [
  16. ];
  17. protected function checkType($value,$rule,$data=[]){
  18. if(!in_array($value,[1,2,3,4])){
  19. return '类型错误';
  20. }
  21. if($value == 1 || $value == 2 || $value == 3){
  22. if(!$data['month']){
  23. return '未选择月份';
  24. }
  25. }
  26. if($value == 1){
  27. $ret = Db::name('work_report_finance')->where('month',$data['month'])->find();
  28. if($ret){
  29. return '该月份已提交过记录';
  30. }
  31. }
  32. if($value == 2){
  33. if(!$data['work1']){
  34. return '未填写本月工作';
  35. }
  36. if(!$data['work2']){
  37. return '未填写下月计划';
  38. }
  39. }
  40. if($value == 3){
  41. if(!$data['points']){
  42. return '未选择重点工作';
  43. }
  44. }
  45. if($value == 3 || $value == 4){
  46. if(!$data['content']){
  47. return '未填写汇报内容';
  48. }
  49. }
  50. return true;
  51. }
  52. }