394 lines
14 KiB
PHP
394 lines
14 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: zn
|
|
* Date: 2017/6/16
|
|
* Time: 14:32
|
|
*/
|
|
|
|
namespace app\controllers;
|
|
|
|
use common\models\EnjoyPet;
|
|
use common\models\Item;
|
|
use common\models\User;
|
|
use common\models\Land;
|
|
use common\models\Muchang;
|
|
use common\models\Farm;
|
|
use common\services\LandService;
|
|
use common\services\MuchangService;
|
|
use common\modules\systemlog\SystemLogUtil;
|
|
use common\modules\vip\vo\Vip;
|
|
use common\modules\rebate\UserRebate;
|
|
use common\services\BackMessageServices;
|
|
use common\services\GameConfigServices;
|
|
use common\services\ResultStatusServices;
|
|
use common\utils\EnumUtil;
|
|
use common\utils\MoneyUtil;
|
|
use common\utils\CommUtil;
|
|
use Yii;
|
|
use yii\rest\Controller;
|
|
|
|
/**
|
|
* 用户详情
|
|
* Class UserDetailController
|
|
* @package app\controllers
|
|
*/
|
|
class UserController extends Controller
|
|
{
|
|
public function actionUserList()
|
|
{
|
|
$userID = Yii::$app->request->get('user_id');
|
|
$nickname = Yii::$app->request->get('nickname');
|
|
$realname = Yii::$app->request->get('realname');
|
|
$current_page = (int)Yii::$app->request->get('page');
|
|
$sort = Yii::$app->request->get('sort');
|
|
$del = Yii::$app->request->get('del');
|
|
//var_dump($realname);exit;
|
|
$find = User::find();
|
|
if (!empty($userID)) $find->andWhere(['id' => $userID]);
|
|
if (!empty($nickname)) $find->andWhere(['like', 'nickname', $nickname]);
|
|
|
|
if (!empty($realname)) $find->andWhere(['like', 'realname', $realname]);
|
|
if ($del) $find->andWhere(['active' => EnumUtil::ACTIVE_NOT]);
|
|
if (!$del) $find->andWhere(['active' => EnumUtil::ACTIVE]);
|
|
|
|
$total = $find->count();
|
|
|
|
$per_page = 12;
|
|
$last_page = ceil($total / $per_page);
|
|
|
|
$find->offset($per_page * ($current_page - 1))->limit($per_page);
|
|
|
|
if (!empty($sort)) {
|
|
list($field, $sortType) = explode("|", $sort);
|
|
if (!empty($field) && !empty($sortType)) {
|
|
$type = SORT_ASC;
|
|
if ($sortType == 'desc') $type = SORT_DESC;
|
|
$find->addOrderBy([$field => $type]);
|
|
}
|
|
}
|
|
|
|
$dbList = $find->all();
|
|
$list = [];
|
|
|
|
foreach ($dbList as $item) {
|
|
$itemData = $item->toArray();
|
|
$vip = Vip::findByUserID($item->id);
|
|
$itemData['vip'] = $vip->level;
|
|
$parent = UserRebate::find()->where(['child_user_id' => $item['id'], 'level' => '1'])->all();
|
|
//var_dump($parent);
|
|
$itemData['parent_id'] = $parent[0]['parent_user_id'];
|
|
array_push($list, $itemData);
|
|
}
|
|
//var_dump($list);exit;
|
|
$returnData['data'] = $list;
|
|
$returnData['total'] = $total;
|
|
$returnData['per_page'] = $per_page;
|
|
$returnData['current_page'] = $current_page;
|
|
$returnData['last_page'] = $last_page;
|
|
return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $returnData);
|
|
}
|
|
|
|
public function actionZhongzhiList()
|
|
{
|
|
$startTime = Yii::$app->request->get('start_time');
|
|
$endTime = Yii::$app->request->get('end_time');
|
|
$user_id = (int)Yii::$app->request->get('user_id');
|
|
$type=Yii::$app->request->get('type');
|
|
$current_page = (int)Yii::$app->request->get('page');
|
|
$sort = Yii::$app->request->get('sort');
|
|
|
|
$find = Land::find();
|
|
$find->andWhere(['>', 'crop_id',0]);
|
|
if (!empty($user_id)){
|
|
$farmDbData = Farm::findOne(['user_id' => $user_id]);
|
|
$find->andWhere(['=', 'farm_id', $farmDbData['id']]);
|
|
}
|
|
|
|
//if (!empty($type)) $find->andWhere(['=', 'type', $type]);
|
|
if (!empty($startTime)) $find->andWhere(['>=', 'crop_start_time', date_create($startTime)->getTimestamp()+3600*24]);
|
|
if (!empty($endTime)) $find->andWhere(['<=', 'crop_gather_time', date_create($endTime)->getTimestamp()+3600*24]);
|
|
|
|
|
|
$total = $find->count();
|
|
|
|
$per_page = 12;
|
|
$last_page = ceil($total / $per_page);
|
|
|
|
$find->offset($per_page * ($current_page - 1))->limit($per_page);
|
|
|
|
if (!empty($sort)) {
|
|
list($field, $sortType) = explode("|", $sort);
|
|
if (!empty($field) && !empty($sortType)) {
|
|
$type = SORT_ASC;
|
|
if ($sortType == 'desc') $type = SORT_DESC;
|
|
$find->addOrderBy([$field => $type]);
|
|
}
|
|
}
|
|
$dbList = $find->all();
|
|
$list = [];
|
|
foreach ($dbList as $item) {
|
|
$itemData = $item->toArray();
|
|
$itemData['crop_start_time'] = CommUtil::formatDate($item->crop_start_time);
|
|
$itemData['crop_gather_time'] = CommUtil::formatDate($item->crop_gather_time);
|
|
$itemData['position'] = $item->position+1;
|
|
$farmDbData = Farm::findOne(['id' => $item->farm_id]);
|
|
$itemData['user_id'] =$farmDbData['user_id'];
|
|
$cropConfig = GameConfigServices::getParamByPath('crop_list.' . $item->crop_id);
|
|
$itemData['crops_name'] =$cropConfig['name'];
|
|
if($item->is_ripe==0){
|
|
$itemData['is_ripe'] ='未成熟';
|
|
}else{
|
|
$itemData['is_ripe'] ='已成熟';
|
|
}
|
|
if($item->has_gather==0){
|
|
$itemData['has_gather'] ='未收割';
|
|
}else{
|
|
$itemData['has_gather'] ='已收割';
|
|
}
|
|
array_push($list, $itemData);
|
|
}
|
|
|
|
$returnData['data'] = $list;
|
|
$returnData['total'] = $total;
|
|
$returnData['per_page'] = $per_page;
|
|
$returnData['current_page'] = $current_page;
|
|
$returnData['last_page'] = $last_page;
|
|
return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $returnData);
|
|
}
|
|
|
|
public function actionYangzhiList()
|
|
{
|
|
$startTime = Yii::$app->request->get('start_time');
|
|
$endTime = Yii::$app->request->get('end_time');
|
|
$user_id = (int)Yii::$app->request->get('user_id');
|
|
$type=Yii::$app->request->get('type');
|
|
$current_page = (int)Yii::$app->request->get('page');
|
|
$sort = Yii::$app->request->get('sort');
|
|
|
|
$find = Muchang::find();
|
|
|
|
if (!empty($user_id)){
|
|
$find->andWhere(['=', 'user_id', $user_id]);
|
|
}
|
|
|
|
//if (!empty($type)) $find->andWhere(['=', 'type', $type]);
|
|
if (!empty($startTime)) $find->andWhere(['>=', 'created_at', date_create($startTime)->getTimestamp()+3600*24]);
|
|
if (!empty($endTime)) $find->andWhere(['<=', 'gather_time', date_create($endTime)->getTimestamp()+3600*24]);
|
|
|
|
|
|
$total = $find->count();
|
|
|
|
$per_page = 12;
|
|
$last_page = ceil($total / $per_page);
|
|
|
|
$find->offset($per_page * ($current_page - 1))->limit($per_page);
|
|
|
|
if (!empty($sort)) {
|
|
list($field, $sortType) = explode("|", $sort);
|
|
if (!empty($field) && !empty($sortType)) {
|
|
$type = SORT_ASC;
|
|
if ($sortType == 'desc') $type = SORT_DESC;
|
|
$find->addOrderBy([$field => $type]);
|
|
}
|
|
}
|
|
$dbList = $find->all();
|
|
$list = [];
|
|
foreach ($dbList as $item) {
|
|
$itemData = $item->toArray();
|
|
$itemData['created_at'] = CommUtil::formatDate($item->created_at);
|
|
$itemData['gather_time'] = CommUtil::formatDate($item->gather_time);
|
|
|
|
$cropConfig = GameConfigServices::getParamByPath('crop_list.' . $item->crop_config_id);
|
|
$itemData['crops_name'] =$cropConfig['name'];
|
|
if($item->is_ripe==0){
|
|
$itemData['is_ripe'] ='未成熟';
|
|
}else{
|
|
$itemData['is_ripe'] ='已成熟';
|
|
}
|
|
if($item->has_gather==0){
|
|
$itemData['has_gather'] ='未收获';
|
|
}else{
|
|
$itemData['has_gather'] ='已收获';
|
|
}
|
|
array_push($list, $itemData);
|
|
}
|
|
|
|
$returnData['data'] = $list;
|
|
$returnData['total'] = $total;
|
|
$returnData['per_page'] = $per_page;
|
|
$returnData['current_page'] = $current_page;
|
|
$returnData['last_page'] = $last_page;
|
|
return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $returnData);
|
|
}
|
|
|
|
public function actionUserEdit()
|
|
{
|
|
$userID = Yii::$app->request->get('user_id');
|
|
$nickname = Yii::$app->request->get('nickname');
|
|
$realname = Yii::$app->request->get('realname');
|
|
$zfb = Yii::$app->request->get('zfb');
|
|
$gold = Yii::$app->request->get('gold');
|
|
$score = Yii::$app->request->get('score');
|
|
// $stone = Yii::$app->request->get('stone');
|
|
// $steel = Yii::$app->request->get('steel');
|
|
$level = Yii::$app->request->get('level');
|
|
// $vip = Yii::$app->request->get('vip');
|
|
|
|
$user = User::findById($userID);
|
|
if (empty($user)) return BackMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
|
|
|
$user->realname = $realname;
|
|
$user->nickname = $nickname;
|
|
$user->gold = $gold;
|
|
$user->score = $score;
|
|
$user->zfb = $zfb;
|
|
// $user->stone = $stone;
|
|
// $user->steel = $steel;
|
|
$user->level = $level;
|
|
// $user->vip = $vip;
|
|
|
|
if (!$user->save()) return BackMessageServices::sendMessage(ResultStatusServices::RS_SAVE_DB_ERROR);
|
|
|
|
return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
|
}
|
|
|
|
/**
|
|
* 禁用用户
|
|
*/
|
|
public function actionUserDel()
|
|
{
|
|
$userID = Yii::$app->request->get('user_id');
|
|
|
|
$user = User::findById($userID);
|
|
if (empty($user)) return BackMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
|
|
|
$user->active = EnumUtil::ACTIVE_NOT;
|
|
if (!$user->save()) return BackMessageServices::sendMessage(ResultStatusServices::RS_SAVE_DB_ERROR);
|
|
|
|
return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
|
}
|
|
|
|
/**
|
|
* 恢复用户
|
|
* @return array
|
|
*/
|
|
public function actionUserRecover()
|
|
{
|
|
$userID = Yii::$app->request->get('user_id');
|
|
|
|
$user = User::findById($userID, false);
|
|
if (empty($user)) return BackMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
|
|
|
$user->active = EnumUtil::ACTIVE;
|
|
if (!$user->save()) return BackMessageServices::sendMessage(ResultStatusServices::RS_SAVE_DB_ERROR);
|
|
|
|
return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
|
}
|
|
|
|
|
|
/**
|
|
*用户道具列表
|
|
*/
|
|
public function actionItemList()
|
|
{
|
|
$userID = Yii::$app->request->get('user_id');
|
|
$current_page = (int)Yii::$app->request->get('page');
|
|
$sort = Yii::$app->request->get('sort');
|
|
|
|
if (empty($userID)) return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
|
|
|
$find = Item::find()->andWhere(['user_id' => $userID]);
|
|
|
|
$total = $find->count();
|
|
|
|
$per_page = 12;
|
|
$last_page = ceil($total / $per_page);
|
|
|
|
$find->offset($per_page * ($current_page - 1))->limit($per_page);
|
|
|
|
if (!empty($sort)) {
|
|
list($field, $sortType) = explode("|", $sort);
|
|
if (!empty($field) && !empty($sortType)) {
|
|
$type = SORT_ASC;
|
|
if ($sortType == 'desc') $type = SORT_DESC;
|
|
$find->addOrderBy([$field => $type]);
|
|
}
|
|
}
|
|
|
|
$dbList = $find->all();
|
|
$list = [];
|
|
foreach ($dbList as $item) {
|
|
array_push($list, $item->toArray());
|
|
}
|
|
|
|
$returnData['data'] = $list;
|
|
$returnData['total'] = $total;
|
|
$returnData['per_page'] = $per_page;
|
|
$returnData['current_page'] = $current_page;
|
|
$returnData['last_page'] = $last_page;
|
|
$returnData['has_user'] = empty(User::findById($userID)) ? false : true;
|
|
return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $returnData);
|
|
}
|
|
|
|
/**
|
|
* 删除物品
|
|
*/
|
|
public function actionItemDel()
|
|
{
|
|
$id = Yii::$app->request->get('id');
|
|
|
|
if (empty($id)) return BackMessageServices::sendMessage(ResultStatusServices::RS_NOT_FIND_IN_DB);
|
|
|
|
$item = Item::findByID($id);
|
|
if (empty($item)) return BackMessageServices::sendMessage(ResultStatusServices::RS_NOT_FIND_IN_DB);
|
|
|
|
$item->delete();
|
|
|
|
return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
|
}
|
|
|
|
/**
|
|
* 编辑道具
|
|
*/
|
|
public function actionItemEdit()
|
|
{
|
|
$userID = Yii::$app->request->get('user_id');
|
|
$itemID = Yii::$app->request->get('item_id');
|
|
$num = (int)Yii::$app->request->get('num');
|
|
|
|
if (empty($userID) || empty($itemID) || $num <= 0) return BackMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
|
|
|
$item = Item::findByUserIDAndItemID($userID, $itemID);
|
|
if (empty($item)) return BackMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
|
|
|
$dis = $num - $item->num;
|
|
$isAdd = false;
|
|
if ($dis == 0) return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
|
|
|
if ($dis > 0) $isAdd = true;
|
|
if ($dis < 0) $isAdd = false;
|
|
|
|
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_ITEM, $itemID, $num, SystemLogUtil::FROM_TYPE_BACKEND, []);
|
|
MoneyUtil::checkAndModifyNum($userID, $itemID, $isAdd, $dis, $log);
|
|
|
|
return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
|
}
|
|
|
|
/**
|
|
* 添加物品
|
|
*/
|
|
public function actionItemAdd()
|
|
{
|
|
$userID = Yii::$app->request->get('user_id');
|
|
$itemID = Yii::$app->request->get('item_id');
|
|
$num = (int)Yii::$app->request->get('num');
|
|
|
|
if (empty($itemID) || empty($userID) || $num <= 0 || empty(User::findById($userID))) return BackMessageServices::sendMessage(ResultStatusServices::RS_PARAM_ERROR);
|
|
|
|
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_ITEM, $itemID, $num, SystemLogUtil::FROM_TYPE_BACKEND, []);
|
|
MoneyUtil::checkAndModifyNum($userID, $itemID, true, $num, $log);
|
|
|
|
return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS);
|
|
}
|
|
} |