UserNetwork.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. <?php
  2. namespace common\models;
  3. use common\components\ActiveRecord;
  4. use common\helpers\Cache;
  5. use common\helpers\NetPoint;
  6. use common\helpers\user\Info;
  7. use common\helpers\user\Perf;
  8. use Exception;
  9. use Yii;
  10. use yii\data\Pagination;
  11. use yii\helpers\Json;
  12. /**
  13. * This is the model class for table "{{%USER_NETWORK}}".
  14. *
  15. * @property string $ID
  16. * @property string $USER_ID 会员ID
  17. * @property string $PARENT_UID 相对上级会员ID
  18. * @property int $LOCATION_TAG 网体标记
  19. * @property int $RELATIVE_LOCATION 相对上级会员区位
  20. * @property string $TOP_UID 顶端会员ID
  21. * @property string $PARENT_UIDS 所有上级ID
  22. * @property int $TOP_DEEP 距离顶端会员深度
  23. * @property int $CREATED_AT 创建时间
  24. * @property int $UPDATED_AT 更新时间
  25. */
  26. class UserNetwork extends \common\components\ActiveRecord
  27. {
  28. /**
  29. * @inheritdoc
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%USER_NETWORK_NEW}}';
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['USER_ID', 'PARENT_UID', 'LOCATION', 'TOP_UID', 'TOP_DEEP', 'CREATED_AT'], 'required'],
  42. [['TOP_DEEP', 'PERIOD_NUM', 'RELATIVE_LOCATION', 'CREATED_AT', 'UPDATED_AT'], 'integer'],
  43. [['ID', 'USER_ID', 'PARENT_UID', 'TOP_UID'], 'string', 'max' => 32],
  44. [['ID'], 'unique'],
  45. ];
  46. }
  47. /**
  48. * @inheritdoc
  49. */
  50. public function attributeLabels()
  51. {
  52. return [
  53. 'ID' => 'ID',
  54. 'USER_ID' => '会员ID',
  55. 'PARENT_UID' => '相对上级会员ID',
  56. 'LOCATION_TAG' => '网体标记',
  57. 'RELATIVE_LOCATION' => '相对父级的区位',
  58. 'TOP_UID' => '顶端会员ID',
  59. 'TOP_DEEP' => '距离顶端会员深度',
  60. 'PARENT_UIDS' => '所有上级ID',
  61. 'CREATED_AT' => '创建时间',
  62. 'UPDATED_AT' => '更新时间',
  63. ];
  64. }
  65. /**
  66. * 获取一层下级数量
  67. * @param $userId
  68. * @return int|string
  69. */
  70. public static function firstFloorChildNum($userId){
  71. return intval(UserInfo::find()->where('CON_UID=:CON_UID AND DELETED=0', [':CON_UID'=>$userId])->count());
  72. }
  73. /**
  74. * 分页获取上级会员
  75. * @param $userId
  76. * @param $offset
  77. * @param $limit
  78. * @param string $orderBy
  79. * @param bool $isSlaves
  80. * @param string $db
  81. * @return array|\yii\db\ActiveRecord[]
  82. */
  83. public static function getParentsWithOffset($userId, $offset, $limit, $orderBy='DESC', $isSlaves = false, $db = 'db'){
  84. $userNetInfo = static::find($isSlaves, $db)->select(['TOP_DEEP', 'PARENT_UIDS', 'LOCATION_TAG'])->where('USER_ID=:USER_ID', ['USER_ID'=>$userId])->asArray()->one();
  85. if( !$userNetInfo ) return [];
  86. $parentUidsStr = $userNetInfo['PARENT_UIDS'];
  87. if( !$parentUidsStr ) return [];
  88. $parentUidsArr = explode(',', $parentUidsStr);
  89. unset($parentUidsStr);
  90. if( $orderBy === 'DESC' ) {
  91. $parentUidsArr = array_reverse($parentUidsArr);
  92. }
  93. if( !$parentUidsArr ) return [];
  94. $pageParentUids = array_slice($parentUidsArr, $offset, $limit);
  95. unset($parentUidsArr);
  96. $parentList = [];
  97. foreach ($pageParentUids as $parentUid) {
  98. try {
  99. $parentNetInfo = static::find($isSlaves, $db)->select(['TOP_DEEP', 'LOCATION_TAG'])->where('USER_ID=:USER_ID', ['USER_ID'=>$parentUid])->asArray()->one();
  100. $parentList[] = [
  101. 'USER_ID' => $userId,
  102. 'TOP_DEEP' => $userNetInfo['TOP_DEEP'],
  103. 'PARENT_UID' => $parentUid,
  104. 'PARENT_DEEP' => $parentNetInfo['TOP_DEEP'],
  105. // 'LOCATION_TAG' => $userNetInfo['LOCATION_TAG'],
  106. // 'PARENT_LOCATION_TAG' => $parentNetInfo['LOCATION_TAG'],
  107. 'LOCATION' => substr($userNetInfo['LOCATION_TAG'], strlen($parentNetInfo['LOCATION_TAG']), 1),
  108. ];
  109. } catch (Exception $e) {
  110. $file_name = date('Y-m-d', time()).'_usernetwork.php_error.log';
  111. file_put_contents($file_name, var_export([
  112. '$parentUid' => $parentUid,
  113. '$userId' => $userId,
  114. 'error' => $e->getMessage()
  115. ],true), FILE_APPEND);
  116. }
  117. unset($parentUid, $parentNetInfo);
  118. }
  119. unset($pageParentUids, $userNetInfo);
  120. return $parentList;
  121. }
  122. /**
  123. * 分页获取上级会员结算库
  124. * @param $userId
  125. * @param $callbackFunc
  126. * @param $limit
  127. * @param int $offset
  128. * @param string $orderBy
  129. */
  130. public static function getParentsWithOffsetFromDbCalc($userId, $callbackFunc, $limit, $offset = 0, $orderBy='DESC'){
  131. $allData = self::getParentsWithOffset($userId, $offset, $limit, $orderBy, false, 'dbCalc');
  132. if($allData){
  133. foreach($allData as $data){
  134. $callbackFunc($data);
  135. unset($data);
  136. }
  137. unset($allData);
  138. self::getParentsWithOffsetFromDbCalc($userId, $callbackFunc, $limit, $offset + $limit);
  139. }
  140. }
  141. /**
  142. * 获取上一级父级的会员信息
  143. * @param $userId
  144. * @return array|null
  145. */
  146. public static function getFirstParentUserInfo($userId){
  147. $oneUserInfo = UserInfo::findOneAsArray(['USER_ID'=>$userId]);
  148. if($oneUserInfo['CON_UID']){
  149. return UserInfo::findOneAsArray(['USER_ID'=>$oneUserInfo['CON_UID']]);
  150. } else {
  151. return null;
  152. }
  153. }
  154. /*
  155. * 从指定会员id和左右,获取最底层会员
  156. *
  157. */
  158. public static function getBottomPlace($userId, $side){
  159. $userNetInfo = static::find()->select(['LOCATION_TAG', 'TOP_DEEP'])->where('USER_ID=:USER_ID', ['USER_ID'=>$userId])->asArray()->one();
  160. $userLocationTag = $userNetInfo['LOCATION_TAG'];
  161. $sonUserTag = $userLocationTag . ($side=='left' ? '1' : '2');
  162. $sonUser = static::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG',['LOCATION_TAG'=>$sonUserTag])->asArray()->one();
  163. if(!$sonUser){// 如果没有查到,说明该位置空白,返回上级用户的信息
  164. $placeParentTag = substr($sonUserTag, 0, strlen($sonUserTag) - 1);
  165. return $placeParentTag;
  166. }else{
  167. return self::getBottomPlace($sonUser['USER_ID'], 'left');
  168. }
  169. }
  170. /**
  171. * 获取指定深度的子会员
  172. * @param $userId
  173. * @param $deep
  174. * @param string $orderBy
  175. * @return array
  176. */
  177. public static function getChildrenWithDeep($userId, $deep, $orderBy='TOP_DEEP ASC'){
  178. $userNetInfo = static::find()->select(['LOCATION_TAG', 'TOP_DEEP'])->where('USER_ID=:USER_ID', ['USER_ID'=>$userId])->asArray()->one();
  179. $childrenNetInfo = static::find()->select(['USER_ID', 'LOCATION_TAG', 'TOP_DEEP'])->where('LOCATION_TAG LIKE :LOCATION_TAG AND TOP_DEEP<=:TOP_DEEP', ['LOCATION_TAG'=>$userNetInfo['LOCATION_TAG'] . '%', 'TOP_DEEP'=>$userNetInfo['TOP_DEEP'] + $deep])->orderBy($orderBy)->asArray()->all();
  180. foreach ($childrenNetInfo as $key => $childNetInfo) {
  181. $childrenNetInfo[$key]['LOCATION'] = substr($childNetInfo['LOCATION_TAG'], strlen($userNetInfo['LOCATION_TAG']), 1);
  182. unset($key, $childNetInfo);
  183. }
  184. unset($userNetInfo);
  185. return $childrenNetInfo;
  186. }
  187. /**
  188. * 获取下一层会员的接点信息
  189. * @param $userId
  190. * @return array|\yii\db\ActiveRecord[]
  191. */
  192. public static function getFirstFloorChildren($userId) {
  193. $childrenNetInfo = static::find()->select(['USER_ID', 'RELATIVE_LOCATION', 'LOCATION_TAG', 'TOP_DEEP'])->where('PARENT_UID=:PARENT_UID', ['PARENT_UID'=>$userId])->asArray()->all();
  194. unset($userNetInfo);
  195. return $childrenNetInfo;
  196. }
  197. /**
  198. * 查看所传父级节点会员是不是所传会员的父级
  199. * @param $userId
  200. * @param $parentUserId
  201. * @param null $periodNum
  202. * @return bool
  203. * @throws \yii\db\Exception
  204. */
  205. public static function isParentUser($userId, $parentUserId, $periodNum = null){
  206. $table = self::getTableNameFromPeriod($periodNum);
  207. $db = $table['db'];
  208. $tableName = $table['tableName'];
  209. $data = $db->createCommand("SELECT PARENT_UIDS FROM {$tableName} WHERE USER_ID=:USER_ID")->bindValues([':USER_ID'=>$userId])->queryOne();
  210. if( !$data ) {
  211. unset($table, $db, $tableName, $data);
  212. return false;
  213. }
  214. $parentListArr = explode(',', $data['PARENT_UIDS']);
  215. unset($table, $db, $tableName, $data);
  216. $existStatus = in_array($parentUserId, $parentListArr);
  217. unset($parentListArr);
  218. return $existStatus;
  219. }
  220. /**
  221. * 获取会员相较于父级的区位
  222. * @param $userId
  223. * @param $parentUserId
  224. * @param $periodNum
  225. * @return mixed|null
  226. */
  227. public static function getLocation($userId, $parentUserId, $periodNum = null){
  228. $table = self::getTableNameFromPeriod($periodNum);
  229. $db = $table['db'];
  230. $tableName = $table['tableName'];
  231. $userNetInfo = $db->createCommand("SELECT LOCATION_TAG FROM $tableName WHERE USER_ID=:USER_ID")->bindValues([':USER_ID'=>$userId])->queryOne();
  232. if( !$userNetInfo || !isset($userNetInfo['LOCATION_TAG']) ) return 0;
  233. $parentNetInfo = $db->createCommand("SELECT LOCATION_TAG FROM $tableName WHERE USER_ID=:USER_ID")->bindValues([':USER_ID'=>$userId])->queryOne();
  234. if( !$parentNetInfo || !isset($parentNetInfo['LOCATION_TAG']) ) return 0;
  235. $location = substr($userNetInfo['LOCATION_TAG'], strlen($parentNetInfo['LOCATION_TAG']), 1);
  236. return $location ? $location : 0;
  237. }
  238. /**
  239. * 获取子会员节点带着总深度和循环的子节点层级关系
  240. * @param $userId
  241. * @param $deep
  242. * @param int $loopedDeep
  243. * @param null $periodNum
  244. * @return mixed
  245. * @throws \yii\base\Exception
  246. * @throws \yii\db\Exception
  247. */
  248. public static function getChildrenWithDeepAndLayer($userId, $deep, $loopedDeep = 1, $periodNum=null){
  249. $allData = self::getChildrenFromPeriod($userId, $periodNum);
  250. if($allData){
  251. $decLevelConfig = Cache::getDecLevelConfig();
  252. $empLevelConfig = Cache::getEmpLevelConfig();
  253. $crownLevelConfig = Cache::getStarCrownLevelConfig();
  254. foreach($allData as $key=>$data){
  255. // 获取用户的基本信息
  256. $baseInfo = Info::baseInfo($data['USER_ID'], $periodNum);
  257. $allData[$key] = array_merge($data, [
  258. 'USER_NAME' => $baseInfo['USER_NAME'],
  259. 'TOP_NETWORK_DEEP' => $data['TOP_DEEP'],
  260. 'REAL_NAME' => $baseInfo['REAL_NAME'],
  261. 'DEC_LV_NAME' => $decLevelConfig[$baseInfo['DEC_LV']]['LEVEL_NAME'],
  262. 'EMP_LV_NAME' => isset($empLevelConfig[$baseInfo['EMP_LV']])?$empLevelConfig[$baseInfo['EMP_LV']]['LEVEL_NAME']:'',
  263. 'CROWN_LV_NAME' => isset($crownLevelConfig[$baseInfo['CROWN_LV']])?$crownLevelConfig[$baseInfo['CROWN_LV']]['LEVEL_NAME']:'',
  264. // 'MOBILE' => $baseInfo['MOBILE'],
  265. 'PERIOD_AT' => $baseInfo['PERIOD_AT'],
  266. ]);
  267. // 获取字节点数量
  268. $childNum = self::firstFloorChildNumFromPeriod($data['USER_ID'], $periodNum);
  269. if($childNum > 0 && $loopedDeep < $deep){
  270. $child = self::getChildrenWithDeepAndLayer($data['USER_ID'], $deep, $loopedDeep + 1, $periodNum);
  271. $leaf = false;
  272. $icon = 'el-icon-user-solid';
  273. }
  274. elseif($childNum > 0){
  275. $child = null;
  276. $leaf = false;
  277. $icon = 'el-icon-user-solid';
  278. }
  279. else {
  280. $child = null;
  281. $leaf = true;
  282. $icon = 'el-icon-user';
  283. }
  284. $allData[$key]['children'] = $child;
  285. $allData[$key]['leaf'] = $leaf;
  286. $allData[$key]['icon'] = $icon;
  287. $allData[$key]['isExpanded'] = false;
  288. $allData[$key]['displayNone'] = 'display-none';
  289. $allData[$key]['RELATIVE_LOCATION'] = $data['RELATIVE_LOCATION'] == 1 ? 'L' : 'R';
  290. }
  291. }
  292. return $allData;
  293. }
  294. /**
  295. * 通过期数获取应该查询哪个表和库
  296. * @param $periodNum
  297. * @return array
  298. */
  299. public static function getTableNameFromPeriod($periodNum = null){
  300. $db = self::getDb();
  301. $tableName = self::tableName();
  302. // if($periodNum !== null){
  303. // // 获取当前期数
  304. // $period = Period::instance();
  305. // $nowPeriodNum = $period->getNowPeriodNum();
  306. // if($nowPeriodNum != $periodNum){
  307. // // 从备份库里找到期数对应的网络
  308. // if(ActiveRecord::isExistsTable('{{%USER_NETWORK_'.$periodNum.'}}', 'dbNetPoint')){
  309. // $db = Yii::$app->dbNetPoint;
  310. // $tableName = '{{%USER_NETWORK_'.$periodNum.'}}';
  311. // }
  312. // }
  313. // }
  314. return [
  315. 'db' => $db,
  316. 'tableName' => $tableName,
  317. ];
  318. }
  319. /**
  320. * 获取指定深度的子会员从指定的期数中
  321. * @param $userId
  322. * @param $periodNum
  323. * @return array|\yii\db\DataReader
  324. * @throws \yii\db\Exception
  325. */
  326. public static function getChildrenFromPeriod($userId, $periodNum=null){
  327. $table = self::getTableNameFromPeriod($periodNum);
  328. $db = $table['db'];
  329. $tableName = $table['tableName'];
  330. return $db->createCommand("SELECT USER_ID,TOP_DEEP,RELATIVE_LOCATION FROM {$tableName} WHERE PARENT_UID=:PARENT_UID")->bindValues([':PARENT_UID'=>$userId])->queryAll();
  331. }
  332. /**
  333. * 获取指定层数的这一层的会员以分页的方式
  334. * @param $userId
  335. * @param $deep
  336. * @param null $periodNum
  337. * @param array $params
  338. * @return array
  339. */
  340. public static function getChildrenInDeepFromPeriodWithPage($userId, $deep, $periodNum=null, $params=[]){
  341. $pageSize = method_exists(\Yii::$app->request,'get')?\Yii::$app->request->get('pageSize', \Yii::$app->params['pageSize']):\Yii::$app->params['pageSize'];
  342. if(isset($params['pageSize'])) $pageSize=$params['pageSize'];
  343. $page = null;
  344. if( isset($params['page']) ) $page=$params['page'];
  345. $orderBy = 'TOP_DEEP ASC, ID ASC';
  346. if( isset($params['orderBy']) ) $orderBy = $params['orderBy'];
  347. $table = self::getTableNameFromPeriod($periodNum);
  348. $db = $table['db'];
  349. $tableName = $table['tableName'];
  350. $userNetInfo = $db->createCommand("SELECT LOCATION_TAG,TOP_DEEP FROM {$tableName} WHERE USER_ID=:USER_ID")->bindValues([':USER_ID'=>$userId])->queryOne();
  351. $userDeep = $userNetInfo['TOP_DEEP'];
  352. $userLocationTag = $userNetInfo['LOCATION_TAG'];
  353. $totalCountSql = "SELECT COUNT(ID) AS TOTAL_COUNT FROM {$tableName} WHERE LOCATION_TAG LIKE :LOCATION_TAG AND TOP_DEEP<=:TOP_DEEP AND INSTR(`PARENT_UIDS`,'{$userId}')>0 ORDER BY {$orderBy}";
  354. $totalCount = $db->createCommand($totalCountSql)->bindValues([':LOCATION_TAG'=>$userLocationTag . '%', ':TOP_DEEP'=>$userDeep + $deep])->queryOne();
  355. $count = $totalCount['TOTAL_COUNT'];
  356. $pagination = new Pagination(['totalCount' => $count]);
  357. $pagination->setPageSize($pageSize);
  358. if( $page !== null ) {
  359. $pagination->setPage($page);
  360. }
  361. $offset = $pagination->offset;
  362. $limit = $pagination->limit;
  363. // $end = $offset + $limit;
  364. $listSql = "SELECT * FROM $tableName WHERE LOCATION_TAG LIKE :LOCATION_TAG AND TOP_DEEP<=:TOP_DEEP AND INSTR(`PARENT_UIDS`,'{$userId}')>0 ORDER BY {$orderBy} LIMIT {$limit} OFFSET {$offset}";
  365. $lists = $db->createCommand($listSql)->bindValues([':LOCATION_TAG'=>$userLocationTag . '%', ':TOP_DEEP'=>$userDeep + $deep])->queryAll();
  366. return [
  367. 'list' => $lists ? $lists : [],
  368. 'pagination' => $pagination,
  369. 'currentPage'=>$pagination->page,
  370. 'totalPages'=>$pagination->pageCount,
  371. 'totalCount' => $pagination->totalCount,
  372. 'pageSize' => $pagination->pageSize,
  373. ];
  374. }
  375. /**
  376. * 获取所有的上级会员带着分页和期数
  377. * @param $userId
  378. * @param null $periodNum
  379. * @param null $deep
  380. * @return array
  381. */
  382. public static function getAllParentFromPeriodWithPage($userId, $periodNum=null, $deep=null){
  383. $pageSize = method_exists(\Yii::$app->request,'get')?\Yii::$app->request->get('pageSize', \Yii::$app->params['pageSize']):\Yii::$app->params['pageSize'];
  384. $table = self::getTableNameFromPeriod($periodNum);
  385. $db = $table['db'];
  386. $tableName = $table['tableName'];
  387. $sql = "SELECT * FROM {$tableName} WHERE USER_ID=:USER_ID";
  388. $oneData = $db->createCommand($sql)->bindValues([':USER_ID'=>$userId])->queryOne();
  389. $userDeep = $oneData['TOP_DEEP'];
  390. $parentUidsStr = $oneData['PARENT_UIDS'] ?? "";
  391. if( !$parentUidsStr ) return [];
  392. $parentUidsArr = explode(',', $parentUidsStr);
  393. $parentUidsFlip = array_reverse($parentUidsArr);
  394. if ($deep != null) {
  395. $parentUidsFlip = array_slice($parentUidsFlip, 0, $deep);
  396. }
  397. $count = count($parentUidsFlip);
  398. $pagination = new Pagination(['totalCount' => $count]);
  399. $pagination->setPageSize($pageSize);
  400. $offset = $pagination->offset;
  401. $limit = $pagination->limit;
  402. $parentUidList = array_slice($parentUidsFlip, $offset, $limit);
  403. $lists = [];
  404. foreach ($parentUidList as $parentUid) {
  405. $sql = "SELECT * FROM {$tableName} WHERE USER_ID=:USER_ID";
  406. $data = $db->createCommand($sql)->bindValues([':USER_ID' => $parentUid])->queryOne();
  407. if( !$data ) continue;
  408. $data['LOCATION'] = substr($oneData['LOCATION_TAG'], strlen($data['LOCATION_TAG']), 1);
  409. $lists[] = $data;
  410. }
  411. return [
  412. 'list' => $lists ? $lists : [],
  413. 'pagination' => $pagination,
  414. 'currentPage' => $pagination->page,
  415. 'totalPages' => $pagination->pageCount,
  416. 'totalCount' => $pagination->totalCount,
  417. 'pageSize' => $pagination->pageSize,
  418. 'listTopDeep' => $userDeep,
  419. ];
  420. }
  421. /**
  422. * 获取一层下级数量从期数
  423. * @param $userId
  424. * @param null $periodNum
  425. * @return int
  426. */
  427. public static function firstFloorChildNumFromPeriod($userId, $periodNum=null){
  428. $table = self::getTableNameFromPeriod($periodNum);
  429. $db = $table['db'];
  430. $tableName = $table['tableName'];
  431. $count = $db->createCommand("SELECT COUNT(ID) AS ID_COUNT FROM {$tableName} WHERE PARENT_UID=:PARENT_UID")->bindValues([':PARENT_UID'=>$userId])->queryOne();
  432. return intval($count['ID_COUNT']);
  433. }
  434. /**
  435. * 从缓存中获取会员的全部父级(主要用于结算时的处理,能够提高效率不去查库)
  436. * @param $userId
  437. * @return array|mixed
  438. */
  439. public static function getAllParentsFromRedis($userId){
  440. $key = Cache::USER_NETWORK_PARENTS;
  441. $data = Yii::$app->redis->hget($key, $userId);
  442. if(!$data){
  443. $data = [];
  444. self::getParentsWithOffsetFromDbCalc($userId, function($oneData) use(&$data){
  445. $data[] = $oneData;
  446. }, 100);
  447. $data = Json::encode($data);
  448. Yii::$app->redis->hset($key, $userId, $data);
  449. }
  450. return $data ? Json::decode($data) : [];
  451. }
  452. /**
  453. * 判断在某个区位是否存在会员
  454. * @param $userId
  455. * @param $location
  456. * @return bool
  457. */
  458. public static function issetUserInLocation($userId, $location){
  459. $childrenNetList = UserNetwork::find()->select(['LOCATION_TAG'])->where('PARENT_UID=:PARENT_UID', [':PARENT_UID' => $userId])->asArray()->all();
  460. foreach ($childrenNetList as $everyData) {
  461. //取最后一位数
  462. $everyLocation = substr($everyData['LOCATION_TAG'], -1);
  463. if( $everyLocation == $location ) return true;
  464. }
  465. return false;
  466. }
  467. }