Commit 6a441a56 authored by rlgy's avatar rlgy

game

parent c546baff
<?php
/**
* Created By Sublime text 3
* User: rlgyzhcn
* Date: 18-08-14
* Time: 上午10:09
*/
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\models\pwallet\GameUser;
class GameController extends BaseController {
/**
* 保存地址与昵称
*/
public function actionSaveAddressAndNickname(){
$post = Yii::$app->request->post();
$address = $post['address']??'';
$nickname = $post['nickname']??'';
if (empty($address) || empty($nickname)) {
return ['code' => -1, 'msg' => '地址和昵称不能为空', 'data' => ''];
}
//判断重复
$count = GameUser::find()->where(['nickname' => $nickname])->count();
if ($count > 0) {
return ['code' => -1, 'msg' => '昵称重复'];
}
// todo 保存
$models = new GameUser();
$models->nickname = $nickname;
$models->address = $address;
if ($models->save()) {
return ['code' => 0, 'msg' => 'Succeed', 'data' => $models->id];
}
return ['code' => -1, 'msg' => 'Failed'];
}
/**
* 根据地址获取昵称
*/
public function actionGetNicknameByAddress(){
$address = Yii::$app->request->post('address', '');
if (empty($address)) {
return ['code' => -1, 'msg' => '地址不能为空', 'data' => ''];
}
//todo 获取地址
$address = GameUser::find()->select(['nickname'])->where(['address' => $address])->one();
if (!empty($address)) {
return ['code' => 0, 'msg'=> 'Succeed', 'data' => $address];
}
return ['code' => -1, 'msg' => 'Failed'];
}
}
\ No newline at end of file
<?php
/**
* Created By Sublime text 3
* User: rlgyzhcn
* Date: 18-08-12
* Time: 下午14:17
*/
namespace common\models\pwallet;
use common\core\BaseActiveRecord;
use Yii;
class GameUser extends BaseActiveRecord{
public static function getDb(){
return Yii::$app->get('db_pwallet');
}
public function formName()
{
return '';
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment