54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: zn
|
|
* Date: 2017/6/2
|
|
* Time: 10:49
|
|
*/
|
|
|
|
namespace common\services;
|
|
|
|
|
|
use common\models\Farm;
|
|
use common\models\Land;
|
|
use common\utils\EnumUtil;
|
|
use yii\base\Object;
|
|
|
|
/**
|
|
* 好友之间交互
|
|
* Class InteractionService
|
|
* @package common\services
|
|
*/
|
|
class InteractionService extends Object
|
|
{
|
|
|
|
/**
|
|
* 获取能否进行交互的状态
|
|
* @param $fromUserID
|
|
* @param $beUserID
|
|
* @return bool
|
|
*/
|
|
public static function canInteraction($fromUserID, $beUserID)
|
|
{
|
|
$farmDbData = Farm::findRedis($beUserID);
|
|
if (!$farmDbData || intval($fromUserID) <= 0 || intval($beUserID) <= 0 || intval($fromUserID) == intval($beUserID))
|
|
return false;
|
|
|
|
//更新农田数据
|
|
LandService::updateAllCropStatus($beUserID, $farmDbData->id, $farmDbData->level);
|
|
|
|
//获取农田数据,判断能否有交互
|
|
for ($i = 0; $i <= EnumUtil::LAND_MAX_POSITION; $i++) {
|
|
$landDbData = Land::findRedis($farmDbData->id, $i);
|
|
if (!$landDbData) continue;
|
|
|
|
$typeList = LandService::getLandInteractionType($fromUserID, $beUserID, $landDbData);
|
|
|
|
//只有偷菜才有手
|
|
if (in_array(EnumUtil::INTERACTION_TYPE_STEAL, $typeList)) return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|