1411 lines
50 KiB
PHP
1411 lines
50 KiB
PHP
<?php
|
||
/**
|
||
* Created by PhpStorm.
|
||
* User: zn
|
||
* Date: 2017/5/16
|
||
* Time: 10:37
|
||
*/
|
||
|
||
namespace app\controllers;
|
||
|
||
use common\models\EnjoyPet;
|
||
use common\models\Farm;
|
||
use common\models\Deal;
|
||
use common\models\User;
|
||
use common\models\UserLog;
|
||
use common\models\Smscode;
|
||
use common\modules\qixunpay\vo\Pay;
|
||
use common\modules\achievement\AchievementUtil;
|
||
use common\modules\dailytask\DailyTaskUtil;
|
||
use common\modules\levelgift\LevelGiftUtil;
|
||
use common\modules\levelgift\vo\LevelGift;
|
||
use common\modules\rebate\Rebate;
|
||
use common\modules\rebate\UserRebate;
|
||
use common\modules\safe\SafeUtil;
|
||
use common\modules\systemlog\SystemLogUtil;
|
||
use common\modules\verifyimage\VerifyImageUtil;
|
||
use common\services\ClientMessageServices;
|
||
use common\services\GameConfigServices;
|
||
use common\services\ItemServices;
|
||
use common\services\DealService;
|
||
use common\services\LandService;
|
||
use common\services\MuchangService;
|
||
use common\services\ResultStatusServices;
|
||
use common\services\StatusException;
|
||
use common\services\UserLogService;
|
||
use common\services\UserService;
|
||
use common\utils\EnumUtil;
|
||
use common\utils\MoneyUtil;
|
||
use common\utils\RedisKeyUtil;
|
||
use common\utils\YiiComponentUtil;
|
||
use Yii;
|
||
use yii\rest\Controller;
|
||
|
||
class UserController extends Controller
|
||
{
|
||
public function actionIndex()
|
||
{
|
||
|
||
}
|
||
|
||
public function actionJsapicode()
|
||
{
|
||
die($_COOKIE['introduce_code']);
|
||
date_default_timezone_set('PRC');
|
||
$time=time();
|
||
$jssdk=$this->jssdk($time,478);
|
||
$data['time']=$time;
|
||
$data['jssdk']=$jssdk;
|
||
$data['introduce_code']=$_COOKIE['introduce_code'];
|
||
die(json_encode($data));
|
||
}
|
||
|
||
|
||
/**
|
||
* wap页面用户和密码登录
|
||
*/
|
||
public function actionWaplogin()
|
||
{
|
||
header('Content-Type:application/json; charset=utf-8');
|
||
//获取数据
|
||
$username = $_POST['user'];
|
||
$password = $_POST['password'];
|
||
$type = $_POST['type'];
|
||
$realname = $_POST['realname'];
|
||
$introduceCode = $_POST['introduce_code'];
|
||
$suiji=$this->getrandomstring(64);
|
||
|
||
|
||
//验证
|
||
if (!$username){
|
||
$json = array('code' =>'1001', 'error_msg' =>'用户名不能为空');
|
||
return $json;
|
||
}
|
||
if (!$password){
|
||
$json = array('code' =>'1002', 'error_msg' =>'密码不能为空');
|
||
return $json;
|
||
}
|
||
if($type=='wapregister'){
|
||
if (!$realname){
|
||
$json = array('code' =>'1002', 'error_msg' =>'真实姓名不能为空');
|
||
return $json;
|
||
}
|
||
|
||
//查找用户
|
||
$user = User::findByUsername($username);
|
||
if ($user != null) {
|
||
$json = array('code' =>'1002', 'error_msg' =>'该手机号已存在');
|
||
return $json;
|
||
}
|
||
|
||
//查找推荐人ID
|
||
$introduceUserID = 0;
|
||
$findUser = User::findByIntroduceCode($introduceCode);
|
||
if (!empty($findUser)){ $introduceUserID = $findUser->id;}else{
|
||
$json = array('code' =>'1002', 'error_msg' =>'推荐码不存在');
|
||
return $json;
|
||
}
|
||
$payPassword='123456';
|
||
//新建用户
|
||
$user = new User();
|
||
$user->username = $username;
|
||
//$user->realname = $realname;
|
||
//$user->zfb = $zfb;
|
||
$user->setPassword($password, $payPassword);
|
||
|
||
//初始数据
|
||
UserService::initNewUserDataAndSave($user, $introduceUserID);
|
||
$json = array('code' =>0, 'error_msg' =>'注册成功请登录');
|
||
return $json;
|
||
exit;
|
||
}
|
||
//是否禁用
|
||
if (!empty(User::findIsNotActiveByUsername($username))){
|
||
$json = array('code' =>'1003', 'error_msg' =>'账户被禁用不能为空');
|
||
return $json;
|
||
}
|
||
|
||
//查找用户
|
||
$userDbData = User::findByUsername($username);
|
||
if ($userDbData == null){
|
||
// die($username);
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
|
||
}
|
||
|
||
//登录
|
||
if (!$userDbData->login($password)) {
|
||
$json = array('code' =>'', 'error_msg' =>'登录秘钥获取失败');
|
||
return $json;
|
||
|
||
}else{
|
||
$userDbData->code = $suiji;
|
||
// $userDbData->guid_target = 12;
|
||
if (!$userDbData->save(true, ['code'])){
|
||
$json = array('code' =>'', 'error_msg' =>'登录秘钥获取失败');
|
||
return $json;
|
||
}
|
||
$json = array('code' =>0, 'error_msg' =>$suiji);
|
||
return $json;
|
||
}
|
||
|
||
exit;
|
||
}
|
||
|
||
|
||
/**
|
||
* Code登录
|
||
*/
|
||
public function actionUserinfo()
|
||
{
|
||
//获取数据
|
||
$Code = $_POST['token'];
|
||
|
||
|
||
//验证
|
||
if (!$Code) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
//查找用户
|
||
$userData = User::findOne(['code' => $Code]);
|
||
if ($userData == null) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
if(strlen($userData['avatar'])>5){
|
||
$userData['avatar']= 'http://'.$_SERVER['HTTP_HOST'].$userData['avatar'];
|
||
}else{
|
||
$userData['avatar']= '/farm/resource/assets/icon/head/head'.$userData['avatar'].'.png';
|
||
}
|
||
|
||
$json = array('code' =>0, 'error_msg' =>$userData);
|
||
return $json;
|
||
}
|
||
|
||
/**
|
||
* 获取用户名
|
||
*/
|
||
public function actionRealname()
|
||
{
|
||
//获取数据
|
||
$Code = $_POST['token'];
|
||
|
||
|
||
//验证
|
||
if (!$Code) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
//查找用户
|
||
$userData = User::findOne(['code' => $Code]);
|
||
if ($userData == null) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
$json = array('code' =>0, 'error_msg' =>$userData);
|
||
return $json;
|
||
}
|
||
|
||
/**
|
||
* 获取提现账户
|
||
*/
|
||
public function actionWithdrawinfo()
|
||
{
|
||
//获取数据
|
||
$Code = $_POST['token'];
|
||
|
||
|
||
//验证
|
||
if (!$Code) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
//查找用户
|
||
$userData = User::findOne(['code' => $Code]);
|
||
if(!empty($_POST['dueBank'])){
|
||
$userData->realname = $_POST['accountNumber'];
|
||
$userData->zfb = $_POST['dueBank'];
|
||
if (!$userData->save(true, ['realname','zfb'])){
|
||
$json = array('code' =>'', 'error_msg' =>'更新失败');
|
||
return $json;
|
||
}
|
||
$json = array('code' =>0, 'error_msg' =>$userData);
|
||
return $json;
|
||
}
|
||
|
||
if ($userData == null) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
if ($userData['zfb'] == ''||$userData['realname'] == '') {
|
||
$json = array('code' =>'1004', 'msg' =>'请先绑定提现账户');
|
||
return $json;
|
||
}
|
||
$json = array('code' =>0, 'error_msg' =>$userData);
|
||
return $json;
|
||
}
|
||
|
||
|
||
/**
|
||
* 修改头像
|
||
*/
|
||
public function actionUploadavatar()
|
||
{
|
||
//获取数据
|
||
$Code = $_POST['token'];
|
||
|
||
|
||
//验证
|
||
if (!$Code) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
//查找用户
|
||
$userData = User::findOne(['code' => $Code]);
|
||
if ($userData == null) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
|
||
if(!empty($_POST['data'])){
|
||
$img=$_POST['data'];
|
||
|
||
$jpg='.jpg';
|
||
$time=time();
|
||
$target1 = '../../headimg/'.$time.$jpg;
|
||
$target2 = '/headimg/'.$time.$jpg;
|
||
$base64_body = substr(strstr($img,','),1);
|
||
|
||
$img1 = base64_decode($base64_body);
|
||
$file=file_put_contents($target1, $img1);
|
||
|
||
$userData->avatar = $target2;
|
||
if (!$userData->save(true, ['avatar'])){
|
||
$json = array('code' =>'', 'error_msg' =>'更新失败');
|
||
return $json;
|
||
}
|
||
$json = array('code' =>0, 'error_msg' =>$userData);
|
||
return $json;
|
||
}
|
||
|
||
$json = array('code' =>0, 'error_msg' =>$userData);
|
||
return $json;
|
||
}
|
||
|
||
/**
|
||
* 金币提现
|
||
*/
|
||
public function actionGoldwithdraw()
|
||
{
|
||
//获取数据
|
||
$Code = $_POST['token'];
|
||
|
||
|
||
//验证
|
||
if (!$Code) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
//查找用户
|
||
$userDbData = User::findOne(['code' => $Code]);
|
||
$userID = $userDbData['id'];
|
||
$gem = $_POST['goldnumber'];
|
||
|
||
$rate = GameConfigServices::getCommonNumByID(GameConfigServices::COMMON_GOLD_EXCHANGE_GEM_RATE);
|
||
|
||
// $gem = intval($gold / $rate);//计算兑换钻石
|
||
|
||
// if ($gem == 0) return ClientMessageServices::sendMessage(ResultStatusServices::RS_GOLD_NOT_ENOUGH);
|
||
|
||
//开启事务
|
||
$dbTrans = Yii::$app->db->beginTransaction();
|
||
try {
|
||
|
||
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_GEM, -$gem, 0, SystemLogUtil::FROM_TYPE_GEM_EXCHANGE_GOLD_PAY, []);
|
||
$rs = UserService::checkAndModifyMoney($userID, false,-$gem, 0, $log);
|
||
|
||
if ($rs != ResultStatusServices::RS_OPERATION_SUCCESS){
|
||
$json = array('code' =>'1004', 'error_msg' =>'提现失败');
|
||
return $json;
|
||
}
|
||
/*
|
||
$order_sn=time();
|
||
$money=$gem*100;
|
||
$wxUser = YiiComponentUtil::easywechat()->getUserInfo();
|
||
|
||
$openid = $wxUser->openID;
|
||
// $openid='olv0-whl_Rom9jKpAflpof4_nCtA';
|
||
$result=$this->shanghuzhifu($openid,$money,$order_sn,'钻石提现');
|
||
|
||
if($result['result_code']!='SUCCESS'){
|
||
$rs = UserService::checkAndModifyMoney($userID, false,0, $gem, $log);
|
||
return ClientMessageServices::sendMessage('提现失败,请过会再来提现');
|
||
exit;
|
||
} */
|
||
|
||
// $log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_GEM, $gem, 0, SystemLogUtil::FROM_TYPE_GOLD_EXCHANGE_GEM_GET, []);
|
||
// $rs = UserService::checkAndModifyMoney($userID, true, 0, $gem, $log);
|
||
// if ($rs != ResultStatusServices::RS_OPERATION_SUCCESS) return ClientMessageServices::sendMessage($rs);
|
||
|
||
//记录日志
|
||
//记录日志
|
||
UserLogService::addUserLog($userID, 27, 0, $gem);
|
||
|
||
$success = true;
|
||
} finally {
|
||
if (isset($success))
|
||
$dbTrans->commit();
|
||
else {
|
||
$dbTrans->rollBack();
|
||
Yii::$app->redis->clearDirtyKey();//清除脏缓存数据
|
||
}
|
||
}
|
||
|
||
$json = array('code' =>'0', 'error_msg' =>'提现成功,请等待审核');
|
||
return $json;
|
||
|
||
// return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, User::findById($userID)->genClientData(false));
|
||
}
|
||
|
||
public function actionGettrade(){
|
||
//获取数据
|
||
$Code = $_POST['token'];
|
||
|
||
$id = $_POST['sid'];
|
||
|
||
$page = $_POST['page'];
|
||
|
||
$type = $_POST['type'];
|
||
|
||
$createtime = $_POST['createtime'];
|
||
$endtime = $_POST['endtime'];
|
||
//验证
|
||
if (!$Code) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
|
||
$userData = User::findOne(['code' => $Code]);
|
||
if ($userData == null) {
|
||
$json = array('code' =>'1004', 'msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
$tradeinfo = GameConfigServices::getParamByPath('trade_list.'.$id);
|
||
$itemID=$tradeinfo['itemid'];
|
||
$find=Deal::find()->where(['from_user_id'=>$userData['id']])->offset(($page-1)*10)->limit(10)->orderBy(["id" => SORT_DESC]);
|
||
$deallist=$find->all();
|
||
$dealcount=Deal::find()->where(['from_user_id'=>$userData['id']])->orderBy(["id" => SORT_DESC])->count();
|
||
$data['list']=$deallist;
|
||
$data['total_pages']=ceil($dealcount/10);
|
||
$json = array('code' =>0, 'data' =>$data);
|
||
return $json;
|
||
}
|
||
/**
|
||
* 获取提现账户
|
||
*/
|
||
public function actionWithdrawhistory()
|
||
{
|
||
//获取数据
|
||
$Code = $_POST['token'];
|
||
|
||
|
||
//验证
|
||
if (!$Code) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
//查找用户
|
||
$userData = User::findOne(['code' => $Code]);
|
||
$find = UserLog::find();
|
||
$find->andWhere(['=', 'type',27]);
|
||
$find->andWhere(['=', 'user_id',$userData['id']]);
|
||
$find->limit(10);
|
||
$find->addOrderBy(["id" => SORT_DESC]);
|
||
$dbList = $find->all();
|
||
|
||
$json = array('code' =>0, 'data' =>$dbList);
|
||
return $json;
|
||
}
|
||
|
||
|
||
/**
|
||
* 用户和密码登录
|
||
*/
|
||
public function actionLogin()
|
||
{
|
||
//获取数据
|
||
$username = Yii::$app->request->get('username') ?: Yii::$app->request->get('phone');
|
||
$password = Yii::$app->request->get('password');
|
||
$suiji=$this->getrandomstring(64);
|
||
//验证
|
||
if (!$username) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USERNAME_EMPTY);
|
||
if (!$password) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PASSWORD_EMPTY);
|
||
|
||
//是否禁用
|
||
if (!empty(User::findIsNotActiveByUsername($username))) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_DISABLE);
|
||
|
||
//查找用户
|
||
$userDbData = User::findByUsername($username);
|
||
if ($userDbData == null) return ClientMessageServices::sendMessage(ResultStatusServices::RS_NOT_FIND_USER);
|
||
|
||
//登录
|
||
if (!$userDbData->login($password)) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PASSWORD_ERROR);
|
||
setcookie('introduce_code',$userDbData->id);
|
||
|
||
$userDbData->login_at = time();
|
||
$userDbData->code = $suiji;
|
||
|
||
//保存
|
||
$userDbData->save(true, ['login_at','code']);
|
||
//更新农田信息
|
||
$farmDbData = Farm::findOne(['user_id' => $userDbData->id]);
|
||
LandService::updateAllCropStatus($userDbData->id, $farmDbData->id, $farmDbData->level);
|
||
MuchangService::updateAllCropStatus($userDbData->id);
|
||
//组织返回给客户端的数据
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $userDbData->genClientData());
|
||
}
|
||
|
||
/**
|
||
* 用户注册
|
||
*/
|
||
public function actionRegister()
|
||
{
|
||
//获取数据
|
||
$username = Yii::$app->request->get('username');
|
||
$password = Yii::$app->request->get('password');
|
||
$payPassword = '123456';
|
||
$introduceCode = Yii::$app->request->get('introduce_code');
|
||
$realname = Yii::$app->request->get('realname');
|
||
$zfb = Yii::$app->request->get('zfb');
|
||
$code = Yii::$app->request->get('code');
|
||
if(empty($introduceCode)){
|
||
$introduceCode=465;
|
||
}
|
||
//验证
|
||
if (!$username) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USERNAME_EMPTY);
|
||
if (!$password) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PASSWORD_EMPTY);
|
||
if (!$payPassword) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PASSWORD_EMPTY);
|
||
//if (!$introduceCode) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
||
$cacheCode = Yii::$app->redis->get('code.sendCode.' . $username);
|
||
//die($cacheCode);
|
||
//if (empty($cacheCode) || $cacheCode != $code) return ClientMessageServices::sendMessage('短信验证码不正确');
|
||
|
||
//查找用户
|
||
$user = User::findByUsername($username);
|
||
if ($user != null) return ClientMessageServices::sendMessage(ResultStatusServices::RS_REGISTERED);
|
||
|
||
//查找推荐人ID
|
||
$introduceUserID = 0;
|
||
$findUser = User::findByIntroduceCode($introduceCode);
|
||
if (!empty($findUser)){ $introduceUserID = $findUser->id;}else{return ClientMessageServices::sendMessage('推荐码不存在'); }
|
||
|
||
//新建用户
|
||
$user = new User();
|
||
$user->username = $username;
|
||
//$user->realname = $realname;
|
||
//$user->zfb = $zfb;
|
||
$user->setPassword($password, $payPassword);
|
||
|
||
//初始数据
|
||
UserService::initNewUserDataAndSave($user, $introduceUserID);
|
||
|
||
//组织返回给客户端的数据
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
||
}
|
||
|
||
/**
|
||
* 修改用户信息
|
||
*/
|
||
public function actionModifyUserInfo()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
$nickname = Yii::$app->request->get('nickname');//昵称
|
||
$avatar = Yii::$app->request->get('avatar');//头像
|
||
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
|
||
//验证参数
|
||
if (!$nickname || !$avatar) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
||
|
||
//修改数据
|
||
$userDbData = User::findById($userID);
|
||
if (!$userDbData) return ClientMessageServices::sendMessage(ResultStatusServices::RS_NOT_FIND_USER);
|
||
|
||
if (User::findByNickname($nickname))
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_NICKNAME_DUP);
|
||
|
||
$userDbData->nickname = $nickname;
|
||
$userDbData->avatar = $avatar;
|
||
|
||
//保存
|
||
if (!$userDbData->save(true, ['nickname', 'avatar', 'updated_at']))
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_SAVE_DB_ERROR);
|
||
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
||
}
|
||
|
||
/**
|
||
* 修改用户密码信息
|
||
*/
|
||
public function actionModifyPassword()
|
||
{
|
||
$username = Yii::$app->request->get('phone');
|
||
$password = Yii::$app->request->get('password');
|
||
$password1 = Yii::$app->request->get('password1');
|
||
$payPassword = Yii::$app->request->get('pay_password');
|
||
$smsCode = Yii::$app->request->get('sms_code');//短信验证码
|
||
|
||
// $imageCodeUUID = Yii::$app->request->get('uuid');
|
||
// $imageCode = Yii::$app->request->get('image_code');
|
||
|
||
// if (empty($imageCodeUUID) || empty($imageCode)) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
||
// if (!VerifyImageUtil::validateImageCode($imageCodeUUID, $imageCode)) return ClientMessageServices::sendMessage(ResultStatusServices::RS_IMAGE_CODE_ERROR);
|
||
$cacheCode = Yii::$app->redis->get('code.sendCode.' . $username);
|
||
//die($cacheCode);
|
||
// if (empty($cacheCode) || $cacheCode != $smsCode) return ClientMessageServices::sendMessage('短信验证码不正确');
|
||
$password = trim($password);
|
||
// $payPassword = trim($payPassword);
|
||
|
||
//验证
|
||
if (!$username) return ClientMessageServices::sendMessage('手机号不能为空');
|
||
if (empty($password)) return ClientMessageServices::sendMessage('密码不能为空');
|
||
|
||
// //是否为手机
|
||
// $isPhone = RegexUtil::validatePhone($username);
|
||
// if (!$isPhone) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PHONE_ERROR);
|
||
//
|
||
// //检查验证码
|
||
// if (!SMSServices::validateCode($username, $smsCode)) return ClientMessageServices::sendMessage(ResultStatusServices::RS_CODE_ERROR);
|
||
|
||
//查找用户
|
||
//查找用户
|
||
$userDbData = User::findByUsername($username);
|
||
if ($userDbData == null) return ClientMessageServices::sendMessage(ResultStatusServices::RS_NOT_FIND_USER);
|
||
|
||
//登录
|
||
if (!$userDbData->login($password)) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PASSWORD_ERROR);
|
||
|
||
//if (!$user->validatePayPassword($payPassword)) return ClientMessageServices::sendMessage('交易密码修改失败');
|
||
|
||
$userDbData->setPassword($password1, '111111');
|
||
|
||
if (!$userDbData->save(true, ['password', 'updated_at'])) return ClientMessageServices::sendMessage('密码修改失败');
|
||
|
||
//组织返回给客户端的数据
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
||
}
|
||
|
||
/**
|
||
* 喂养小狗
|
||
*/
|
||
public function actionFeedDog()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
$itemID = Yii::$app->request->get('item_id');//喂养物品ID
|
||
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
|
||
//验证参数
|
||
if (!$itemID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
||
|
||
//获取配置
|
||
$itemConfig = GameConfigServices::getParamByPath('item_list.' . $itemID);
|
||
if (!$itemConfig) return ClientMessageServices::sendMessage(ResultStatusServices::RS_NOT_FIND_IN_CONFIG);
|
||
|
||
//判断物品类型
|
||
if ($itemConfig['type2'] != ItemServices::ITEM_TYPE2_DOG_FOOD)
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_ITEM_TYPE_ERROR);
|
||
|
||
//检查是否使用小狗
|
||
// $userDbData = User::findById($userID);
|
||
//if (empty($userDbData->use_dog_item_id))
|
||
// return ClientMessageServices::sendMessage(ResultStatusServices::RS_DONOT_USE_DOG);
|
||
|
||
//开启事务
|
||
$dbTrans = Yii::$app->db->beginTransaction();
|
||
|
||
try {
|
||
//修改物品
|
||
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_ITEM, $itemID, -1, SystemLogUtil::FROM_TYPE_FEED_DOG, []);
|
||
$rs = ItemServices::checkAndModifyNum($userID, $itemID, false, -1, $log);
|
||
if ($rs != ResultStatusServices::RS_OPERATION_SUCCESS) return ClientMessageServices::sendMessage($rs);
|
||
|
||
//增加小狗时间
|
||
$userDbData = User::findById($userID);
|
||
if (time() > $userDbData->dog_hunger_end_time) {
|
||
$userDbData->dog_hunger_end_time = time() + $itemConfig['effect_id'];
|
||
} else {
|
||
$userDbData->dog_hunger_end_time += $itemConfig['effect_id'];
|
||
}
|
||
if (!$userDbData->save(true, ['dog_hunger_end_time', 'updated_at']))
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_SAVE_DB_ERROR);
|
||
|
||
//记录日志
|
||
UserLogService::addUserLog($userID, EnumUtil::USER_LOG_TYPE_FEED_DOG, $itemID, 0);
|
||
|
||
$success = true;
|
||
} finally {
|
||
if (isset($success))
|
||
$dbTrans->commit();
|
||
else {
|
||
$dbTrans->rollBack();
|
||
Yii::$app->redis->clearDirtyKey();//清除脏缓存数据
|
||
}
|
||
}
|
||
|
||
$data['dog_hunger_end_time'] = $userDbData->dog_hunger_end_time;
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $data);
|
||
}
|
||
|
||
|
||
/**
|
||
* 用户升级
|
||
*/
|
||
public function actionUpgradeLevel()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
|
||
$userDbData = SafeUtil::dbOperate(function ($userID) {
|
||
|
||
//修改数据
|
||
$userDbData = User::findById($userID);
|
||
if (!$userDbData) return ClientMessageServices::sendMessage(ResultStatusServices::RS_NOT_FIND_USER);
|
||
|
||
//达到用户最大等级
|
||
if ($userDbData->level >= GameConfigServices::getMaxPlayerLevel())
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_PLAYER_MAX_LEVEL);
|
||
|
||
$config = GameConfigServices::getParamByPath('player_level.' . $userDbData->level);
|
||
|
||
//扣除金钱
|
||
$gold = $config['gold'];
|
||
$gem = $config['gem'];
|
||
if ($gold > 0) {
|
||
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_GOLD, -$gold, 0, SystemLogUtil::FROM_TYPE_UPGRADE_USER, []);
|
||
MoneyUtil::checkAndModifyRes($userID, false, -$gold, ItemServices::ITEM_TYPE2_GOLD, $log);
|
||
}
|
||
if ($gem > 0) {
|
||
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_GEM, -$gem, 0, SystemLogUtil::FROM_TYPE_UPGRADE_USER, []);
|
||
MoneyUtil::checkAndModifyRes($userID, false, -$gem, ItemServices::ITEM_TYPE2_GEM, $log);
|
||
}
|
||
|
||
return MoneyUtil::addUserExp($userID, (int)$config['add_exp']);
|
||
|
||
}, [$userID]);
|
||
|
||
$returnData['exp'] = $userDbData->exp;
|
||
$returnData['level'] = $userDbData->level;
|
||
$returnData['gold'] = $userDbData->gold;
|
||
$returnData['gem'] = $userDbData->gem;
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取返点用户列表
|
||
*/
|
||
public function actionGetRebateList()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
$level = Yii::$app->request->get('level');//几级返点用户列表,1,2,3
|
||
$offset = Yii::$app->request->get('offset');//偏移
|
||
$count = Yii::$app->request->get('count');//每页多少数据
|
||
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
|
||
if (!isset($offset)) $offset = 0;
|
||
if (!isset($count)) $count = 5;
|
||
|
||
$find = Rebate::find()->where(['be_user_id' => $userID, 'level' => $level])->orderBy(['created_at' => SORT_DESC]);
|
||
|
||
$totalCount = $find->count();
|
||
|
||
$dbDataList = $find->offset($offset)->limit($count)->all();
|
||
$dataList = [];
|
||
foreach ($dbDataList as $dbItem) {
|
||
$data = $dbItem->genClientData();
|
||
|
||
$userDbData = User::findById($dbItem->from_user_id);
|
||
$data['nickname'] = $userDbData->nickname;
|
||
|
||
array_push($dataList, $data);
|
||
}
|
||
|
||
$returnData['offset'] = $offset;
|
||
$returnData['total_count'] = $totalCount;
|
||
$returnData['list'] = $dataList;
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $returnData);
|
||
}
|
||
|
||
/**
|
||
* 金币兑换钻石
|
||
*/
|
||
public function actionGoldExchangeGem()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
$gold = intval(Yii::$app->request->get('gold'));
|
||
|
||
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
$userDbData = User::findById($userID);
|
||
if($userDbData['isjihuo']==0){
|
||
return ClientMessageServices::sendMessage('请先激活账号');
|
||
}
|
||
if ($gold < 0) return ClientMessageServices::sendMessage('兑换数量不正确');
|
||
|
||
$rate = GameConfigServices::getCommonNumByID(GameConfigServices::COMMON_GOLD_EXCHANGE_GEM_RATE);
|
||
|
||
$gem = intval($gold / $rate);//计算兑换钻石
|
||
|
||
if ($gem == 0) return ClientMessageServices::sendMessage('金币不够');
|
||
|
||
|
||
//开启事务
|
||
$dbTrans = Yii::$app->db->beginTransaction();
|
||
try {
|
||
|
||
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_GOLD, -$gold, 0, SystemLogUtil::FROM_TYPE_GOLD_EXCHANGE_GEM_PAY, []);
|
||
$rs = UserService::checkAndModifyMoney($userID, false, -$gold, 0, $log);
|
||
if ($rs != ResultStatusServices::RS_OPERATION_SUCCESS) return ClientMessageServices::sendMessage($rs);
|
||
|
||
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_GEM, $gem, 0, SystemLogUtil::FROM_TYPE_GOLD_EXCHANGE_GEM_GET, []);
|
||
$rs = UserService::checkAndModifyMoney($userID, true, 0, $gem, $log);
|
||
if ($rs != ResultStatusServices::RS_OPERATION_SUCCESS) return ClientMessageServices::sendMessage($rs);
|
||
|
||
//记录日志
|
||
UserLogService::addUserLog($userID, EnumUtil::USER_LOG_TYPE_GOLD_EXCHANGE_GEM_RATE, 0, $gem);
|
||
|
||
$success = true;
|
||
} finally {
|
||
if (isset($success))
|
||
$dbTrans->commit();
|
||
else {
|
||
$dbTrans->rollBack();
|
||
Yii::$app->redis->clearDirtyKey();//清除脏缓存数据
|
||
}
|
||
}
|
||
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, User::findById($userID)->genClientData(false));
|
||
}
|
||
|
||
/**
|
||
* 钻石兑换金币
|
||
*/
|
||
public function actionGemExchangeGold()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
$gem = intval(Yii::$app->request->get('gem'));
|
||
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
$userDbData = User::findById($userID);
|
||
if($userDbData['isjihuo']==0){
|
||
return ClientMessageServices::sendMessage('请先激活账号');
|
||
}
|
||
if ($gem < 0) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
||
|
||
$rate = GameConfigServices::getCommonNumByID(GameConfigServices::COMMON_GEM_EXCHANGE_GOLD_RATE);
|
||
|
||
$gold = intval($gem * $rate);//计算兑换金币
|
||
|
||
if ($gold == 0) return ClientMessageServices::sendMessage(ResultStatusServices::RS_GEM_NOT_ENOUGH);
|
||
|
||
//开启事务
|
||
$dbTrans = Yii::$app->db->beginTransaction();
|
||
try {
|
||
|
||
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_GEM, -$gem, 0, SystemLogUtil::FROM_TYPE_GEM_EXCHANGE_GOLD_PAY, []);
|
||
$rs = UserService::checkAndModifyMoney($userID, false, 0, -$gem, $log);
|
||
if ($rs != ResultStatusServices::RS_OPERATION_SUCCESS) return ClientMessageServices::sendMessage($rs);
|
||
|
||
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_GOLD, $gold, 0, SystemLogUtil::FROM_TYPE_GEM_EXCHANGE_GOLD_GET, []);
|
||
$rs = UserService::checkAndModifyMoney($userID, true, $gold, 0, $log);
|
||
if ($rs != ResultStatusServices::RS_OPERATION_SUCCESS) return ClientMessageServices::sendMessage($rs);
|
||
|
||
//记录日志
|
||
UserLogService::addUserLog($userID, EnumUtil::USER_LOG_TYPE_GOLD_EXCHANGE_GEM_RATE, 0, $gold);
|
||
|
||
$success = true;
|
||
} finally {
|
||
if (isset($success))
|
||
$dbTrans->commit();
|
||
else {
|
||
$dbTrans->rollBack();
|
||
Yii::$app->redis->clearDirtyKey();//清除脏缓存数据
|
||
}
|
||
}
|
||
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, User::findById($userID)->genClientData(false));
|
||
}
|
||
|
||
public function actionGetWxName()
|
||
{
|
||
$beUserID = Yii::$app->request->get('be_user_id');//受赠用户ID
|
||
|
||
if (empty($beUserID)) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PARSE_PARAM_ERROR);
|
||
|
||
//检查受赠用户是否存在
|
||
$user = User::findById($beUserID);
|
||
if (empty($user)) return ClientMessageServices::sendMessage(ResultStatusServices::RS_DEAL_BE_USER_NOT_EXIST);
|
||
|
||
$data['wx_name'] = $user->wx_name;
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $data);
|
||
}
|
||
|
||
public function actionGetCodeImage()
|
||
{
|
||
$uuid = Yii::$app->request->get('uuid');
|
||
|
||
if (empty($uuid)) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
||
|
||
$image = VerifyImageUtil::getImageCode($uuid);
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $image);
|
||
}
|
||
|
||
/**
|
||
* 获取在线礼包
|
||
* @return array
|
||
*/
|
||
public function actionGetOnlineGift()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
|
||
SafeUtil::dbOperate(function ($userID) {
|
||
SafeUtil::redisLockOperate(function ($userID) {
|
||
|
||
$onlineInfo = UserService::updateOnlineInfo($userID);
|
||
|
||
$index = intval($onlineInfo['get_count']) + 1;
|
||
$config = GameConfigServices::getParamByPath('online_gift.' . $index);
|
||
|
||
if (empty($config)) throw new StatusException(ResultStatusServices::RS_CONFIG_ERROR);
|
||
|
||
for ($i = 1; $i <= 4; $i++) {
|
||
if (!isset($config['fruit_id' . $i])) continue;
|
||
MoneyUtil::parseItem($config['fruit_id' . $i], 1, true, $userID, SystemLogUtil::FROM_TYPE_ONLINE_GIFT, ['config' => $config]);
|
||
}
|
||
|
||
$onlineInfo['get_count'] = intval($onlineInfo['get_count']) + 1;
|
||
UserService::saveOnlineInfo($userID, $onlineInfo);
|
||
|
||
// Yii::warning('get');
|
||
// Yii::warning($onlineInfo);
|
||
|
||
//任务记录
|
||
DailyTaskUtil::addTaskCount($userID, DailyTaskUtil::TYPE_GET_ONLINE_GIFT, null, 1);
|
||
|
||
//成就
|
||
AchievementUtil::addCount($userID, AchievementUtil::ID_GET_ONLINE_GIFT, 1);
|
||
|
||
}, [$userID], RedisKeyUtil::lockOnlineGift($userID));
|
||
|
||
}, [$userID]);
|
||
|
||
$user = User::findById($userID);
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $user->genClientData(false));
|
||
}
|
||
|
||
/**
|
||
* 获取等级礼包
|
||
* @return array
|
||
*/
|
||
public function actionGetPlayerLevelGift()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
$giftID = Yii::$app->request->get('gift_id');
|
||
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
|
||
LevelGiftUtil::getLevelGift($userID, $giftID);
|
||
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
||
}
|
||
|
||
public function actionGetPlayerLevelGiftList()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
|
||
$dbList = LevelGift::findAllByUserID($userID);
|
||
$list = [];
|
||
foreach ($dbList as $item) {
|
||
array_push($list, $item->toArray());
|
||
}
|
||
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, ['list' => $list]);
|
||
}
|
||
|
||
public function actionSaveGuid()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
$target = (int)Yii::$app->request->get('target');
|
||
$step = (int)Yii::$app->request->get('step');
|
||
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
|
||
$user = User::findById($userID);
|
||
if (empty($user)) return ClientMessageServices::sendMessage(ResultStatusServices::RS_NOT_FIND_USER);
|
||
|
||
$user->guid_target = $target;
|
||
$user->guid_step = $step;
|
||
if (!$user->save(true, ['guid_target', 'guid_step', 'updated_at'])) return ClientMessageServices::sendMessage(ResultStatusServices::RS_SAVE_DB_ERROR, $user->getErrors());
|
||
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
||
}
|
||
|
||
/**
|
||
* 获取观赏宠物列表
|
||
* @return array
|
||
*/
|
||
public function actionGetEnjoyPetList()
|
||
{
|
||
|
||
//$response = Yii::$app->response;
|
||
//$response->format = Response::FORMAT_JSON;
|
||
//$response->statusCode = 200;
|
||
$userID = Yii::$app->request->get('user_id');
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
$user = EnjoyPet::find()->where(['user_id' => $userID])->all();
|
||
$json = [];
|
||
$i = 0;
|
||
foreach ($user as $key => $value) {
|
||
$json[$i]['id'] = $value->id;
|
||
$json[$i]['user_id'] = $value->user_id;
|
||
$json[$i]['config_id'] = $value->config_id;
|
||
$json[$i]['feed'] = $value->feed;
|
||
$json[$i]['is_out'] = $value->is_out;
|
||
$json[$i]['last_update_time'] = $value->last_update_time;
|
||
$json[$i]['created_at'] = $value->created_at;
|
||
$json[$i]['updated_at'] = $value->updated_at;
|
||
$i++;
|
||
}
|
||
/* $dbList = EnjoyPet::findListByUserID($userID);
|
||
$list = [];
|
||
if ($dbList) {
|
||
foreach ($dbList as $key => $item) {
|
||
$list[][$key] = $item;
|
||
//var_dump($item);
|
||
//$list[] = $item->id;
|
||
//EnjoyPet::updateFeed($item);
|
||
//$list[] = $item->genClientData();
|
||
}
|
||
}*/
|
||
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $json);
|
||
}
|
||
/**
|
||
* 获取推广用户
|
||
* @return array
|
||
*/
|
||
public function actionGetspreadlist()
|
||
{
|
||
//获取数据
|
||
$Code = $_POST['token'];
|
||
|
||
|
||
//验证
|
||
if (!$Code) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
//查找用户
|
||
$userinfo = User::findOne(['code' => $Code]);
|
||
if ($userinfo == null) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
$userData=array();
|
||
$userData['level1']=0;
|
||
$userData['level2']=0;
|
||
$userData['level3']=0;
|
||
$userData['level4']=0;
|
||
$userData['level5']=0;
|
||
$userData['level6']=0;
|
||
$userData['level7']=0;
|
||
$userData['level8']=0;
|
||
|
||
$find = UserRebate::find()->where(['parent_user_id' => $userinfo['id']])->orderBy(['created_at' => SORT_DESC]);
|
||
$totalCount = $find->count();
|
||
//var_dump($userinfo['id']);
|
||
// exit;
|
||
$dbDataList = $find->all();
|
||
|
||
$dataList = [];
|
||
|
||
foreach ($dbDataList as $key => $dbItem) {
|
||
// $data = $dbItem->genClientData();
|
||
|
||
$userDbData = User::findById($dbItem['child_user_id']);
|
||
$dataList[$key]['user'] = $userDbData->username;
|
||
$dataList[$key]['createTime']=$dbItem['created_at'];
|
||
$dataList[$key]['level']=$dbItem['level'].'级会员';
|
||
$dataList[$key]['id']=$dbItem['id'];
|
||
|
||
if($dbItem['level']==1){
|
||
$userData['level1']++;
|
||
}
|
||
if($dbItem['level']==2){
|
||
$userData['level2']++;
|
||
}
|
||
if($dbItem['level']==3){
|
||
$userData['level3']++;
|
||
}
|
||
if($dbItem['level']==4){
|
||
$userData['level4']++;
|
||
}
|
||
if($dbItem['level']==5){
|
||
$userData['level5']++;
|
||
}
|
||
if($dbItem['level']==6){
|
||
$userData['level6']++;
|
||
}
|
||
if($dbItem['level']==7){
|
||
$userData['level7']++;
|
||
}
|
||
if($dbItem['level']==8){
|
||
$userData['level8']++;
|
||
}
|
||
|
||
|
||
}
|
||
$userData['items']=$dataList;
|
||
$json = array('code' =>0, 'data' =>$userData);
|
||
return $json;
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取推广奖励
|
||
* @return array
|
||
*/
|
||
public function actionSpreadlist()
|
||
{
|
||
//获取数据
|
||
$Code = $_POST['token'];
|
||
$page = $_POST['page'];
|
||
$from_user_id = $_POST['fromUId'];
|
||
if(empty($page)){
|
||
$start=0;
|
||
$end=10;
|
||
}else{
|
||
$start=$page*10-10;
|
||
$end=$page*10;
|
||
}
|
||
//验证
|
||
if (!$Code) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
//查找用户
|
||
$userinfo = User::findOne(['code' => $Code]);
|
||
if ($userinfo == null) {
|
||
$json = array('code' =>'1004', 'error_msg' =>'用户不存在');
|
||
return $json;
|
||
}
|
||
$userData=array();
|
||
$userData['total_money']=0;
|
||
$userData['total']=0;
|
||
|
||
$find = Rebate::find()->where(['be_user_id' => $userinfo['id']])->orderBy(['created_at' => SORT_DESC]);
|
||
if(!empty($from_user_id)){
|
||
$find->andWhere(['from_user_id' => $from_user_id]);
|
||
}
|
||
$totalCount = $find->count();
|
||
|
||
$dbDataList = $find->all();
|
||
|
||
$dataList = [];
|
||
|
||
foreach ($dbDataList as $key => $dbItem) {
|
||
if($key>$start && $key <=$end){
|
||
$dataList[$key]['time']=$dbItem['created_at'];
|
||
$dataList[$key]['level']=$dbItem['level'].'级会员';
|
||
$dataList[$key]['from']=$dbItem['from_user_id'];
|
||
$dataList[$key]['gold']=$dbItem['rebate_gold'].'金币';
|
||
|
||
}
|
||
|
||
if($dbItem['rebate_gold']>0){
|
||
$userData['total_money']=$dbItem['rebate_gold']+$userData['total_money'];
|
||
}
|
||
$userData['total']++;
|
||
}
|
||
$userData['list']=$dataList;
|
||
$json = array('code' =>0, 'data' =>$userData);
|
||
return $json;
|
||
|
||
}
|
||
/**
|
||
* 观赏宠物出勤
|
||
* @return array
|
||
*/
|
||
public function actionSetEnjoyPetOut()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
$petID = Yii::$app->request->get('pet_id');
|
||
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
|
||
$pet = EnjoyPet::findByID($petID);
|
||
if (empty($pet) || $pet->user_id != $userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
||
|
||
$oldPet = EnjoyPet::findOutByUserID($userID);
|
||
if (!empty($oldPet)) {
|
||
$oldPet->updateFeed();
|
||
$oldPet->is_out = 0;
|
||
if (!$oldPet->save()) return ClientMessageServices::sendMessage(ResultStatusServices::RS_SAVE_DB_ERROR, $oldPet->getErrors());
|
||
}
|
||
|
||
$pet->updateFeed();
|
||
$pet->is_out = 1;
|
||
if (!$pet->save()) return ClientMessageServices::sendMessage(ResultStatusServices::RS_SAVE_DB_ERROR, $pet->getErrors());
|
||
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $pet->genClientData());
|
||
}
|
||
/**
|
||
* 短信验证
|
||
* @return array
|
||
*/
|
||
|
||
public function actionSendFindPasswordCode(){
|
||
header('content-type:text/html;charset=utf-8');
|
||
$phone = Yii::$app->request->get('phone');
|
||
$code=rand(111111,999999);
|
||
Yii::$app->redis->set('code.sendTime.' . $phone, time(), 6000);
|
||
Yii::$app->redis->set('code.sendCode.' . $phone, $code, 6000);
|
||
$statusStr = array(
|
||
"0" => "短信发送成功",
|
||
"-1" => "参数不全",
|
||
"-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
|
||
"30" => "密码错误",
|
||
"40" => "账号不存在",
|
||
"41" => "余额不足",
|
||
"42" => "帐户已过期",
|
||
"43" => "IP地址限制",
|
||
"50" => "内容含有敏感词"
|
||
);
|
||
$smsapi = "http://api.smsbao.com/";
|
||
$user = "w16567906611"; //短信平台帐号
|
||
$pass = md5("588588"); //短信平台密码
|
||
$content="您的验证码为'$code',请不要告诉别人哦";//要发送的短信内容
|
||
//$phone = "*****";//要发送短信的手机号码
|
||
$sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
|
||
$result =file_get_contents($sendurl) ;
|
||
//echo $statusStr[$result];
|
||
|
||
if($result==0){
|
||
//状态为0,说明短信发送成功
|
||
$data['status']=0;
|
||
}else{
|
||
//状态非0,说明失败
|
||
$msg = $statusStr[$result];
|
||
$data['status']="短信发送失败(".$error_code."):".$msg;
|
||
}
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $data);
|
||
}
|
||
/**
|
||
* 喂养观赏宠物
|
||
* @return array
|
||
*/
|
||
public function actionFeedEnjoyPet()
|
||
{
|
||
$userID = Yii::$app->request->get('user_id');
|
||
$petID = Yii::$app->request->get('pet_id');
|
||
$itemID = Yii::$app->request->get('item_id');
|
||
|
||
if (!$userID) return ClientMessageServices::sendMessage(ResultStatusServices::RS_USER_NOT_LOGIN);//验证登录
|
||
|
||
$pet = SafeUtil::dbOperate(function ($userID, $petID, $itemID) {
|
||
return SafeUtil::redisLockOperate(function ($userID, $petID, $itemID) {
|
||
|
||
$pet = EnjoyPet::findByID($petID);
|
||
|
||
if (empty($pet)) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR);
|
||
|
||
if ($pet->user_id != $userID) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR);
|
||
|
||
$itemConfig = GameConfigServices::getParamByPath('item_list.' . $itemID);
|
||
if (empty($itemConfig)) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR);
|
||
|
||
if ((int)$itemConfig['type2'] != ItemServices::ITEM_TYPE2_DOG_FOOD) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR);
|
||
|
||
$addFeed = (int)$itemConfig['effect_id'];
|
||
if ($addFeed <= 0) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR);
|
||
|
||
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_ITEM, $itemID, -1, SystemLogUtil::FROM_TYPE_FEED_DOG, []);
|
||
MoneyUtil::checkAndModifyNum($userID, $itemID, false, -1, $log);
|
||
|
||
$pet->updateFeed();
|
||
|
||
$pet->feed += $addFeed;
|
||
if (!$pet->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR);
|
||
|
||
//任务记录
|
||
DailyTaskUtil::addTaskCount($userID, DailyTaskUtil::TYPE_FEED_PET, null, 1);
|
||
|
||
return $pet;
|
||
|
||
}, [$userID, $petID, $itemID], RedisKeyUtil::lockPet($petID));
|
||
}, [$userID, $petID, $itemID]);
|
||
|
||
return ClientMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $pet->genClientData());
|
||
}
|
||
|
||
|
||
/**
|
||
* 请求接口返回内容
|
||
* @param string $url [请求的URL地址]
|
||
* @param string $params [请求的参数]
|
||
* @param int $ipost [是否采用POST形式]
|
||
* @return string
|
||
*/
|
||
public function juhecurl($url,$params=false,$ispost=0){
|
||
$httpInfo = array();
|
||
$ch = curl_init();
|
||
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
|
||
curl_setopt( $ch, CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22' );
|
||
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 30 );
|
||
curl_setopt( $ch, CURLOPT_TIMEOUT , 30);
|
||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
|
||
if( $ispost )
|
||
{
|
||
curl_setopt( $ch , CURLOPT_POST , true );
|
||
curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
|
||
curl_setopt( $ch , CURLOPT_URL , $url );
|
||
}
|
||
else
|
||
{
|
||
if($params){
|
||
curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
|
||
}else{
|
||
curl_setopt( $ch , CURLOPT_URL , $url);
|
||
}
|
||
}
|
||
$response = curl_exec( $ch );
|
||
if ($response === FALSE) {
|
||
//echo "cURL Error: " . curl_error($ch);
|
||
return false;
|
||
}
|
||
$httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
|
||
$httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
|
||
curl_close( $ch );
|
||
return $response;
|
||
}
|
||
|
||
public function jssdk($tome,$code){
|
||
$appid = 'wx06e00d57df939b34';
|
||
$secret = '9d79e62d92e359f3b948c462ac89a4cd';
|
||
|
||
|
||
$accesstoken = file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."");//获取access_token
|
||
$token = json_decode($accesstoken); //对JSON格式的字符串进行编码
|
||
$t = get_object_vars($token);//转换成数组
|
||
$access_token = $t['access_token'];//输出access_token
|
||
|
||
$jsapi = file_get_contents("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi");
|
||
$jsapi = json_decode($jsapi);
|
||
$j = get_object_vars($jsapi);
|
||
|
||
|
||
$jsapi = $j['ticket'];//get JSAPI
|
||
|
||
|
||
$noncestr= 'oWSFLy3HKPbwHBtH';
|
||
$jsapi_ticket= $jsapi;
|
||
$timestamp=$tome;
|
||
$url='http://gameback.88t1.cn/home/web/index.html';
|
||
$and = "jsapi_ticket=".$jsapi."&noncestr=".$noncestr."×tamp=".$timestamp."&url=".$url."";
|
||
|
||
//var_dump($and);
|
||
$signature = sha1($and);
|
||
return $signature;
|
||
}
|
||
|
||
|
||
private function shanghuzhifu($openid,$money,$order_sn,$desc){
|
||
$data=array(
|
||
'mch_appid'=>'wx01c634089b6091b9',//商户账号appid
|
||
'mchid'=>'1490412332',//商户号
|
||
'nonce_str'=>rand(11111111,99999999),//随机字符串
|
||
'partner_trade_no'=>$order_sn,//商户订单号
|
||
'openid'=>$openid,//用户openid
|
||
'check_name'=>'NO_CHECK',//校验用户姓名选项,
|
||
're_user_name'=>'',//收款用户姓名
|
||
'amount'=>intval($money),//金额
|
||
'desc'=>$desc,//企业付款描述信息
|
||
'spbill_create_ip'=>'120.79.53.23',//Ip地址
|
||
);
|
||
$secrect_key='32b71e810a77c0f83fcc9c5ad0827391';///这个就是个API密码。32位的。。随便MD5一下就可以了
|
||
$data=array_filter($data);
|
||
ksort($data);
|
||
$str='';
|
||
foreach($data as $k=>$v) {
|
||
$str.=$k.'='.$v.'&';
|
||
}
|
||
$str.='key='.$secrect_key;
|
||
$data['sign']=md5($str);
|
||
$xml=$this->arraytoxml($data);
|
||
// echo $xml;
|
||
file_put_contents('xml.txt', $xml);
|
||
$url='https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
|
||
$res=$this->curl($xml,$url);
|
||
$return=$this->xmltoarray($res);
|
||
return $return;
|
||
}
|
||
private function unicode() {
|
||
$str = uniqid(mt_rand(),1);
|
||
$str=sha1($str);
|
||
return md5($str);
|
||
}
|
||
private function arraytoxml($data){
|
||
$str='<xml>';
|
||
foreach($data as $k=>$v) {
|
||
$str.='<'.$k.'>'.$v.'</'.$k.'>';
|
||
}
|
||
$str.='</xml>';
|
||
return $str;
|
||
}
|
||
private function xmltoarray($xml) {
|
||
//禁止引用外部xml实体
|
||
libxml_disable_entity_loader(true);
|
||
$xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||
$val = json_decode(json_encode($xmlstring),true);
|
||
return $val;
|
||
}
|
||
private function getrandomstring($len,$chars=null){
|
||
if(is_null($chars)){
|
||
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||
}
|
||
mt_srand(1000*(double)time());
|
||
$str = '';
|
||
for($i = 0,$lc = strlen($chars)-1;$i<$len;$i++){
|
||
$str.= $chars[mt_rand(0,$lc)];
|
||
}
|
||
return $str;
|
||
}
|
||
private function curl($param="",$url) {
|
||
|
||
$postUrl = $url;
|
||
$curlPost = $param;
|
||
$ch = curl_init(); //初始化curl
|
||
curl_setopt($ch, CURLOPT_URL,$postUrl); //抓取指定网页
|
||
curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
|
||
curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); // 增加 HTTP Header(头)里的字段
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 终止从服务端进行验证
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||
curl_setopt($ch,CURLOPT_SSLCERT,getcwd().'/cert/apiclient_cert.pem'); //这个是证书的位置绝对路径
|
||
curl_setopt($ch,CURLOPT_SSLKEY,getcwd().'/cert/apiclient_key.pem'); //这个也是证书的位置绝对路径
|
||
file_put_contents('lujing.txt',getcwd().'/cert/apiclient_key.pem');
|
||
$data = curl_exec($ch); //运行curl
|
||
curl_close($ch);
|
||
return $data;
|
||
}
|
||
|
||
}
|