GameValidate.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * GameValidate.php UTF-8
  4. * 游戏验证
  5. *
  6. * @date : 2020/9/14 16:00
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : H5IOS 1.0
  11. */
  12. namespace huosdk\h5ios\admin\validate;
  13. use huolib\constant\CommonConst;
  14. use huosdk\h5ios\core\model\GameModel;
  15. use huosdk\h5ios\core\status\GameStatus;
  16. class GameValidate extends BaseValidate {
  17. /*场景验证*/
  18. protected $scene
  19. = [
  20. 'add' => ['name', 'cp_id', '__token__'],
  21. 'edit' => ['id', 'down_cnt', 'icon', 'name', 'cp_id', 'publicity', 'package_url',
  22. 'description', 'hot_image', 'vip_description', 'fine_image', 'rebate_description',
  23. 'fine_description', 'single_tag', 'photo_names', 'photo_urls', 'name', '__token__'],
  24. 'editPackageUrl' => ['id', 'client_id', 'package_url', '__token__'],
  25. 'editName' => ['id', 'name', '__token__'],
  26. 'editAppleId' => ['id', 'apple_id', '__token__'],
  27. 'editCpPaybackUrl' => ['id', 'cp_payback_url', '__token__'],
  28. 'cp' => ['id', 'cp_id', '__token__'],
  29. 'link_h5_game' => ['id', '__token__'],
  30. ];
  31. /*验证规则*/
  32. protected $rule
  33. = [
  34. 'id' => ['require', 'integer', 'gt:0'],
  35. 'app_id' => ['require', 'integer', 'egt:0'],
  36. 'cp_id' => ['require', 'integer', 'egt:0'],
  37. 'is_online' => ['integer', 'gt:0'],
  38. 'package_url' => ['url'],
  39. 'down_cnt' => ['require', 'between:0,100000000'],
  40. 'classify' => ['require', 'integer', 'gt:0'],
  41. 'name' => ['require', 'checkNameExist'],
  42. 'apple_id' => ['integer', 'gt:0', 'checkAppleIdExist'],
  43. 'parent_id' => ['require', 'integer', 'egt:0', 'checkParentId'],
  44. 'mg_parent_id' => ['require', 'integer', 'egt:0', 'checkMgParentId'],
  45. 'cp_payback_url' => ['require', 'url'],
  46. 'h5_game_id' => ['require', 'integer', 'gt:0'],
  47. 'client_id' => ['require', 'integer', 'egt:0'],
  48. ];
  49. /*错误信息*/
  50. protected $msg
  51. = [
  52. ];
  53. /**
  54. * GameValidate
  55. *
  56. * @param string $scene 校验场景
  57. */
  58. public function __construct($scene = '') {
  59. $_rule = [];
  60. switch ($scene) {
  61. /*设置校验语言字段*/
  62. case 'add':
  63. case 'edit':
  64. // $_lang_code = implode(',', (new LanguageConfModel())->getLangCode());
  65. // $_rule['lang_code'] = ['require', 'in:'.$_lang_code];
  66. break;
  67. }
  68. $this->msg = [
  69. 'cp_payback_url.url' => lang('MSG_CP_PAYBACK_URL_ERROR')
  70. ];
  71. $this->rule = array_merge($this->rule, $_rule);
  72. /*如果传入了场景,则设置场景*/
  73. if (!empty($scene)) {
  74. $this->scene($scene);
  75. }
  76. parent::__construct($this->rule, $this->msg);
  77. }
  78. /**
  79. * 检查核对
  80. *
  81. * @param $name
  82. *
  83. * @return bool|mixed
  84. * @author : chengshibin <csb@huosdk.com>
  85. * @date : 2019/3/5 19:40
  86. */
  87. protected function checkNameExist($name) {
  88. $_is_bt = get_val($this->check_data, 'is_bt', 0);
  89. $_is_sdk = get_val($this->check_data, 'is_sdk', 0);
  90. $_classify = get_val($this->check_data, 'classify', 0);
  91. $_map = [
  92. 'name' => $name,
  93. 'classify' => $_classify,
  94. 'is_bt' => $_is_bt,
  95. 'is_sdk' => $_is_sdk
  96. ];
  97. $_cnt = (new GameModel())->getNameCnt($_map);
  98. if ($_cnt > CommonConst::CONST_ZERO) {
  99. $_code = GameStatus::GAME_NAME_EXIST;
  100. return GameStatus::getMsg($_code);
  101. }
  102. return true;
  103. }
  104. /**
  105. * 检查Apple_id是否存在
  106. *
  107. * @param int $apple_id 苹果ID
  108. *
  109. * @return bool|mixed
  110. */
  111. protected function checkAppleIdExist($apple_id) {
  112. $_id = (new GameModel())->getAppIdByAppleId($apple_id);
  113. if (!empty($_id)) {
  114. $_code = GameStatus::GAME_APPLE_ID_EXIST;
  115. return GameStatus::getMsg($_code);
  116. }
  117. return true;
  118. }
  119. }