| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- /**
- * api 游戏启动时设备信息收集控制器
- */
- namespace app\api\controller\v1;
- use app\api\controller\Api;
- use think\Db;
- class Startup extends Api
- {
-
- /**
- * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
- */
- public function _initialize()
- {
- parent::_initialize();
- }
-
- /**
- * 平台币劵列表
- * return array
- */
- public function index()
- {
- $game_id = $this->input('gameid'); //游戏ID
- $channel_id = $this->input('channel_id'); //渠道ID
- $imei = trim($this->input('imeil')); //手机imei码
- $os_version = trim($this->input('os_version')); //操作系统版本
-
-
- $checkResult = $this->validate($this->input,
- [
- ['gameid', 'require|positiveInteger', '游戏id不能为空|游戏ID必须为整型'],
- ['channel_id', 'require|positiveInteger', '渠道ID不能为空|渠道ID必须为整型'],
- ['imeil', 'require', '手机imei码不能为空|手机imei码不能超过40个字符'],
- ['platform', 'require|integer|in:0,1', '手机类型不能为空|手机类型必须为整型|手机类型参数错误'],
- ['phone_brand', 'max:40', '手机品牌不能超过40个字符'],
- ['phone_model', 'max:100', '手机型号不能超过100个字符'],
- ['os_version', 'max:50', '系统版本不能超过50个字符'],
- ]);
-
- if (true !== $checkResult) {
- $this->jsonResult('', 0, $checkResult);
- }
-
- //如果当天该设备记录不存在时
- if(!Db::table('nw_startup_devices')->where(['game_id'=>$game_id,'channel_id'=>$channel_id,'imei'=>$imei,'create_time'=>['>=',strtotime(date('Y-m-d'))]])->find())
- {
- // 启动事务
- Db::startTrans();
-
- try{
- $startupData['game_id'] = $game_id;
- $startupData['channel_id'] = $this->input('channel_id');
- $startupData['imei'] = $imei;
- $startupData['ip'] = request()->ip();
- $startupData['create_time'] = NOW_TIMESTAMP;
-
- //游戏启动时设备信息表
- Db::table('nw_startup_devices')->insert($startupData);
-
- //设备信息记录不存在时
- if(!Db::table('nw_devices')->where(['game_id'=>$game_id,'imei'=>$imei,'os_version'=>$os_version])->find())
- {
- $devicesData['game_id'] = $game_id;
- $devicesData['platform'] = $this->input('platform');
- $devicesData['imei'] = $imei;
- $devicesData['phone_brand'] = $this->input('phone_brand');
- $devicesData['phone_model'] = $this->input('phone_model');
- $devicesData['os_version'] = $os_version;
- $devicesData['update_time'] = NOW_TIMESTAMP;
- $devicesData['create_time'] = NOW_TIMESTAMP;
-
- Db::table('nw_devices')->insert($devicesData);
- }
-
- // 提交事务
- Db::commit();
-
- } catch (\Exception $e) {
- // 回滚事务
- Db::rollback();
-
- $this->jsonResult('', 0, '设备信息保存失败'.$e->getMessage());
- }
-
- $this->jsonResult('', 1, '设备信息保存成功');
- }
-
- $this->jsonResult('', 0, '今日,游戏启动时设备信息收集已经收集');
- }
- }
|