AndroidSdk.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: cqingt
  5. * Date: 2018/6/27
  6. * Time: 10:19
  7. */
  8. namespace app\admin\validate;
  9. use app\common\library\ValidateExtend;
  10. use think\Db;
  11. class AndroidSdk extends ValidateExtend
  12. {
  13. protected $rule = [
  14. 'version' => 'require|checkVersion',
  15. 'num' => 'require|positiveInteger',
  16. 'filename' => 'require',
  17. 'content' => 'checkContent',
  18. ];
  19. protected $message = [
  20. 'version.require' => '版本号不能为空',
  21. 'version.checkVersion' => '版本号不能比上一个版本小',
  22. 'num.require' => '构造号不能为空',
  23. 'num.positiveInteger'=> '构造号只能是大于0的整数',
  24. 'filename.require' => '文件地址不能为空',
  25. 'content' => '更新内容超过500字',
  26. 'action.require' => '名称不能为空',
  27. 'action.unique' => '同样的记录已经存在!',
  28. ];
  29. protected $scene = [
  30. 'add' => ['version', 'num', 'content'],
  31. 'edit' => [ 'num','content'],
  32. ];
  33. /**
  34. * 检测更新内容字数,500以内
  35. * @param $value
  36. * @return boolean
  37. */
  38. public function checkContent($value)
  39. {
  40. return mb_strlen($value) <= 500;
  41. }
  42. /**
  43. * 检测版本号是否比上一个版本小
  44. * @param $value
  45. * @return bool
  46. */
  47. public function checkVersion($value)
  48. {
  49. $lastVersion = Db::name('nw_android_sdk_config')->order('id', 'desc')->value('version');
  50. return version_compare($value, $lastVersion) == 1;
  51. }
  52. }