WorkNews.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class WorkNews extends Validate{
  6. protected $rule = [
  7. 'work_type_id' => 'require|gt:0|checkType',
  8. 'content|内容' => 'require|checkContent',
  9. // 'receiver|接收人' => 'require',
  10. ];
  11. protected $message = [
  12. // 'receiver.require' => '未选择接收人',
  13. 'work_type_id.require' => '未选择类型',
  14. 'work_type_id.gt' => '未选择类型',
  15. ];
  16. protected $scene = [
  17. ];
  18. protected function checkType($value,$rule,$data=[]){
  19. if(!in_array($value,[1,2,3,4,5,6,7,8,9,10])){
  20. return '类型错误';
  21. }
  22. return true;
  23. }
  24. protected function checkContent($value,$rule,$data=[]){
  25. $content = json_decode($value,true);
  26. if(!$content){
  27. return '参数错误';
  28. }
  29. $arr = [];
  30. foreach ($content as $k=>$v){
  31. if(!$v['content']){
  32. return '工作内容不能为空';
  33. }
  34. if(!$v['date']){
  35. return '完成时间不能为空';
  36. }
  37. if($v['content'] || $v['date']){
  38. $arr[] = $v;
  39. }
  40. }
  41. if(!$arr){
  42. return '未输入内容';
  43. }
  44. return true;
  45. }
  46. }