AssetValidate.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\validate\asset;
  15. use app\common\validate\BaseValidate;
  16. use app\common\model\asset\AssetInfo;
  17. /**
  18. * 资产管理验证
  19. * Class ArticleValidate
  20. * @package app\adminapi\validate\article
  21. */
  22. class AssetValidate extends BaseValidate
  23. {
  24. protected $rule = [
  25. 'id' => 'require|checkAssetInfo',
  26. 'name' => 'require|length:1,255',
  27. 'images' => 'require',
  28. 'address' => 'require',
  29. 'contacts' => 'require',
  30. 'mobile' => 'require',
  31. 'status' => 'in:0,1',
  32. ];
  33. protected $message = [
  34. 'id.require' => '资产id不能为空',
  35. 'name.require' => '资产名称不能为空',
  36. 'name.length' => '资产名称长度须在1-255位字符',
  37. 'images.require' => '资产图片不能为空',
  38. 'address.require' => '资产地址不能为空',
  39. 'contacts.require' => '资产联系人不能为空',
  40. 'mobile.require' => '联系方式不能为空',
  41. ];
  42. /**
  43. * @notes 添加场景
  44. * @return ArticleValidate
  45. * @author heshihu
  46. * @date 2022/2/22 9:57
  47. */
  48. public function sceneAdd()
  49. {
  50. return $this->remove(['id'])
  51. ->remove('id','require|checkAssetInfo');
  52. }
  53. /**
  54. * @notes 详情场景
  55. * @return ArticleValidate
  56. * @author heshihu
  57. * @date 2022/2/22 10:15
  58. */
  59. public function sceneDetail()
  60. {
  61. return $this->only(['id']);
  62. }
  63. /**
  64. * @notes 更改状态场景
  65. * @return ArticleValidate
  66. * @author heshihu
  67. * @date 2022/2/22 10:18
  68. */
  69. public function sceneStatus()
  70. {
  71. return $this->only(['id', 'status']);
  72. }
  73. public function sceneEdit()
  74. {
  75. }
  76. /**
  77. * @notes 删除场景
  78. * @return ArticleValidate
  79. * @author heshihu
  80. * @date 2022/2/22 10:17
  81. */
  82. public function sceneDelete()
  83. {
  84. return $this->only(['id']);
  85. }
  86. /**
  87. * @notes 检查指定资讯是否存在
  88. * @param $value
  89. * @return bool|string
  90. * @author heshihu
  91. * @date 2022/2/22 10:11
  92. */
  93. public function checkAssetInfo($value)
  94. {
  95. $article = AssetInfo::findOrEmpty($value);
  96. if ($article->isEmpty()) {
  97. return '资产不存在';
  98. }
  99. return true;
  100. }
  101. }