0
0

CleanPlanRecord.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class CleanPlanRecord extends Validate{
  6. protected $rule = [
  7. 'start|开始日期' => 'require',
  8. 'end|结束日期' => 'require|checkEnd',
  9. 'forms|任务项' => 'require',
  10. 'addrs|地点' => 'require',
  11. 'form_id|任务项' => 'require',
  12. 'address_id|地点' => 'require',
  13. 'user' => 'require'
  14. ];
  15. protected $message = [
  16. 'user.require' => '未选择人员'
  17. ];
  18. protected $scene = [
  19. 'add' => ['start','end','forms','addrs'],
  20. 'edit' => ['start','end','form_id','address_id','user']
  21. ];
  22. protected function checkEnd($value, $rule, $data=[]){
  23. if($data['start'] > $data['end']){
  24. return '开始日期不能大于结束日期';
  25. }
  26. if(!$data['plan_id']){
  27. return '参数错误';
  28. }
  29. $smonth = date('Y-m',strtotime($data['start']));
  30. $emonth = date('Y-m',strtotime($data['end']));
  31. if($smonth != $emonth){
  32. return '日期不能跨月';
  33. }
  34. $pinfo = Db::name('clean_plan')->where('id',$data['plan_id'])->where('del',0)->find();
  35. if(!$pinfo){
  36. return '月计不存在';
  37. }
  38. if($smonth != $pinfo['month']){
  39. return '日期不能跨月';
  40. }
  41. return true;
  42. }
  43. }