FinanceLog.php 767 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class FinanceLog extends Validate{
  6. protected $rule = [
  7. 'income|收入' => 'require|egt:0',
  8. 'expenditure|支出' => 'require|egt:0',
  9. 'day|日期' => 'require|date|checkUnique',
  10. ];
  11. protected $message = [
  12. ];
  13. protected $scene = [
  14. ];
  15. protected function checkUnique($value,$rule,$data=[])
  16. {
  17. $info = Db::name('finance_log')->where('day',$value)->where('org_id',$data['org_id'])->find();
  18. if($data['id'] <= 0 && $info){
  19. return '日期已被使用';
  20. }
  21. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  22. return '日期已被使用';
  23. }
  24. return true;
  25. }
  26. }