123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- /**
- * GameValidate.php UTF-8
- * 游戏验证
- *
- * @date : 2020/9/14 16:00
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : H5IOS 1.0
- */
- namespace huosdk\h5ios\admin\validate;
- use huolib\constant\CommonConst;
- use huosdk\h5ios\core\model\GameModel;
- use huosdk\h5ios\core\status\GameStatus;
- class GameValidate extends BaseValidate {
- /*场景验证*/
- protected $scene
- = [
- 'add' => ['name', 'cp_id', '__token__'],
- 'edit' => ['id', 'down_cnt', 'icon', 'name', 'cp_id', 'publicity', 'package_url',
- 'description', 'hot_image', 'vip_description', 'fine_image', 'rebate_description',
- 'fine_description', 'single_tag', 'photo_names', 'photo_urls', 'name', '__token__'],
- 'editPackageUrl' => ['id', 'client_id', 'package_url', '__token__'],
- 'editName' => ['id', 'name', '__token__'],
- 'editAppleId' => ['id', 'apple_id', '__token__'],
- 'editCpPaybackUrl' => ['id', 'cp_payback_url', '__token__'],
- 'cp' => ['id', 'cp_id', '__token__'],
- 'link_h5_game' => ['id', '__token__'],
- ];
- /*验证规则*/
- protected $rule
- = [
- 'id' => ['require', 'integer', 'gt:0'],
- 'app_id' => ['require', 'integer', 'egt:0'],
- 'cp_id' => ['require', 'integer', 'egt:0'],
- 'is_online' => ['integer', 'gt:0'],
- 'package_url' => ['url'],
- 'down_cnt' => ['require', 'between:0,100000000'],
- 'classify' => ['require', 'integer', 'gt:0'],
- 'name' => ['require', 'checkNameExist'],
- 'apple_id' => ['integer', 'gt:0', 'checkAppleIdExist'],
- 'parent_id' => ['require', 'integer', 'egt:0', 'checkParentId'],
- 'mg_parent_id' => ['require', 'integer', 'egt:0', 'checkMgParentId'],
- 'cp_payback_url' => ['require', 'url'],
- 'h5_game_id' => ['require', 'integer', 'gt:0'],
- 'client_id' => ['require', 'integer', 'egt:0'],
- ];
- /*错误信息*/
- protected $msg
- = [
- ];
- /**
- * GameValidate
- *
- * @param string $scene 校验场景
- */
- public function __construct($scene = '') {
- $_rule = [];
- switch ($scene) {
- /*设置校验语言字段*/
- case 'add':
- case 'edit':
- // $_lang_code = implode(',', (new LanguageConfModel())->getLangCode());
- // $_rule['lang_code'] = ['require', 'in:'.$_lang_code];
- break;
- }
- $this->msg = [
- 'cp_payback_url.url' => lang('MSG_CP_PAYBACK_URL_ERROR')
- ];
- $this->rule = array_merge($this->rule, $_rule);
- /*如果传入了场景,则设置场景*/
- if (!empty($scene)) {
- $this->scene($scene);
- }
- parent::__construct($this->rule, $this->msg);
- }
- /**
- * 检查核对
- *
- * @param $name
- *
- * @return bool|mixed
- * @author : chengshibin <csb@huosdk.com>
- * @date : 2019/3/5 19:40
- */
- protected function checkNameExist($name) {
- $_is_bt = get_val($this->check_data, 'is_bt', 0);
- $_is_sdk = get_val($this->check_data, 'is_sdk', 0);
- $_classify = get_val($this->check_data, 'classify', 0);
- $_map = [
- 'name' => $name,
- 'classify' => $_classify,
- 'is_bt' => $_is_bt,
- 'is_sdk' => $_is_sdk
- ];
- $_cnt = (new GameModel())->getNameCnt($_map);
- if ($_cnt > CommonConst::CONST_ZERO) {
- $_code = GameStatus::GAME_NAME_EXIST;
- return GameStatus::getMsg($_code);
- }
- return true;
- }
- /**
- * 检查Apple_id是否存在
- *
- * @param int $apple_id 苹果ID
- *
- * @return bool|mixed
- */
- protected function checkAppleIdExist($apple_id) {
- $_id = (new GameModel())->getAppIdByAppleId($apple_id);
- if (!empty($_id)) {
- $_code = GameStatus::GAME_APPLE_ID_EXIST;
- return GameStatus::getMsg($_code);
- }
- return true;
- }
- }
|