UserNetwork.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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, $userTag='', $side){
  159. if(!$userTag||$userTag==''){
  160. $userNetInfo = static::find()->select(['LOCATION_TAG', 'TOP_DEEP'])->where('USER_ID=:USER_ID', ['USER_ID'=>$userId])->asArray()->one();
  161. if (!$userNetInfo || !$userNetInfo['LOCATION_TAG']) {
  162. $sonUserTag = $userTag . ($side=='left' ? '1' : '2');
  163. } else {
  164. $userLocationTag = $userNetInfo['LOCATION_TAG'];
  165. $sonUserTag = $userLocationTag . ($side=='left' ? '1' : '2');
  166. }
  167. }else{
  168. $sonUserTag = $userTag . ($side=='left' ? '1' : '2');
  169. }
  170. $sonUser = static::find()->select('USER_ID, LOCATION_TAG')->where('LOCATION_TAG=:LOCATION_TAG',['LOCATION_TAG'=>$sonUserTag])->asArray()->one();
  171. if(!$sonUser){// 如果没有查到,说明该位置空白,返回上级用户的信息
  172. return substr($sonUserTag, 0, strlen($sonUserTag) - 1);
  173. }else{
  174. return self::getBottomPlace($sonUser['USER_ID'], $sonUser['LOCATION_TAG'], 'left');
  175. }
  176. }
  177. /**
  178. * 获取指定深度的子会员
  179. * @param $userId
  180. * @param $deep
  181. * @param string $orderBy
  182. * @return array
  183. */
  184. public static function getChildrenWithDeep($userId, $deep, $orderBy='TOP_DEEP ASC'){
  185. $userNetInfo = static::find()->select(['LOCATION_TAG', 'TOP_DEEP'])->where('USER_ID=:USER_ID', ['USER_ID'=>$userId])->asArray()->one();
  186. $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();
  187. foreach ($childrenNetInfo as $key => $childNetInfo) {
  188. $childrenNetInfo[$key]['LOCATION'] = substr($childNetInfo['LOCATION_TAG'], strlen($userNetInfo['LOCATION_TAG']), 1);
  189. unset($key, $childNetInfo);
  190. }
  191. unset($userNetInfo);
  192. return $childrenNetInfo;
  193. }
  194. /**
  195. * 获取下一层会员的接点信息
  196. * @param $userId
  197. * @return array|\yii\db\ActiveRecord[]
  198. */
  199. public static function getFirstFloorChildren($userId) {
  200. $childrenNetInfo = static::find()->select(['USER_ID', 'RELATIVE_LOCATION', 'LOCATION_TAG', 'TOP_DEEP'])->where('PARENT_UID=:PARENT_UID', ['PARENT_UID'=>$userId])->asArray()->all();
  201. unset($userNetInfo);
  202. return $childrenNetInfo;
  203. }
  204. /**
  205. * 查看所传父级节点会员是不是所传会员的父级
  206. * @param $userId
  207. * @param $parentUserId
  208. * @param null $periodNum
  209. * @return bool
  210. * @throws \yii\db\Exception
  211. */
  212. public static function isParentUser($userId, $parentUserId, $periodNum = null){
  213. $table = self::getTableNameFromPeriod($periodNum);
  214. $db = $table['db'];
  215. $tableName = $table['tableName'];
  216. $data = $db->createCommand("SELECT PARENT_UIDS FROM {$tableName} WHERE USER_ID=:USER_ID")->bindValues([':USER_ID'=>$userId])->queryOne();
  217. if( !$data ) {
  218. unset($table, $db, $tableName, $data);
  219. return false;
  220. }
  221. $parentListArr = explode(',', $data['PARENT_UIDS']);
  222. unset($table, $db, $tableName, $data);
  223. $existStatus = in_array($parentUserId, $parentListArr);
  224. unset($parentListArr);
  225. return $existStatus;
  226. }
  227. /**
  228. * 获取会员相较于父级的区位
  229. * @param $userId
  230. * @param $parentUserId
  231. * @param $periodNum
  232. * @return mixed|null
  233. */
  234. public static function getLocation($userId, $parentUserId, $periodNum = null){
  235. $table = self::getTableNameFromPeriod($periodNum);
  236. $db = $table['db'];
  237. $tableName = $table['tableName'];
  238. $userNetInfo = $db->createCommand("SELECT LOCATION_TAG FROM $tableName WHERE USER_ID=:USER_ID")->bindValues([':USER_ID'=>$userId])->queryOne();
  239. if( !$userNetInfo || !isset($userNetInfo['LOCATION_TAG']) ) return 0;
  240. $parentNetInfo = $db->createCommand("SELECT LOCATION_TAG FROM $tableName WHERE USER_ID=:USER_ID")->bindValues([':USER_ID'=>$userId])->queryOne();
  241. if( !$parentNetInfo || !isset($parentNetInfo['LOCATION_TAG']) ) return 0;
  242. $location = substr($userNetInfo['LOCATION_TAG'], strlen($parentNetInfo['LOCATION_TAG']), 1);
  243. return $location ? $location : 0;
  244. }
  245. /**
  246. * 获取子会员节点带着总深度和循环的子节点层级关系
  247. * @param $userId
  248. * @param $deep
  249. * @param int $loopedDeep
  250. * @param null $periodNum
  251. * @return mixed
  252. * @throws \yii\base\Exception
  253. * @throws \yii\db\Exception
  254. */
  255. public static function getChildrenWithDeepAndLayer($userId, $deep, $loopedDeep = 1, $periodNum=null){
  256. $allData = self::getChildrenFromPeriod($userId, $periodNum);
  257. if($allData){
  258. $decLevelConfig = Cache::getDecLevelConfig();
  259. $empLevelConfig = Cache::getEmpLevelConfig();
  260. foreach($allData as $key=>$data){
  261. // 获取用户的基本信息
  262. $baseInfo = Info::baseInfo($data['USER_ID'], $periodNum);
  263. $allData[$key] = array_merge($data, [
  264. 'USER_NAME' => $baseInfo['USER_NAME'],
  265. 'TOP_NETWORK_DEEP' => $data['TOP_DEEP'],
  266. 'REAL_NAME' => $baseInfo['REAL_NAME'],
  267. 'DEC_LV_NAME' => $decLevelConfig[$baseInfo['DEC_LV']]['LEVEL_NAME'],
  268. 'EMP_LV_NAME' => isset($empLevelConfig[$baseInfo['EMP_LV']])?$empLevelConfig[$baseInfo['EMP_LV']]['LEVEL_NAME']:'0-Star Director',
  269. 'PERIOD_AT' => $baseInfo['PERIOD_AT'],
  270. ]);
  271. // 获取字节点数量
  272. $childNum = self::firstFloorChildNumFromPeriod($data['USER_ID'], $periodNum);
  273. if($childNum > 0 && $loopedDeep < $deep){
  274. $child = self::getChildrenWithDeepAndLayer($data['USER_ID'], $deep, $loopedDeep + 1, $periodNum);
  275. $leaf = false;
  276. $icon = 'el-icon-user-solid';
  277. }
  278. elseif($childNum > 0){
  279. $child = null;
  280. $leaf = false;
  281. $icon = 'el-icon-user-solid';
  282. }
  283. else {
  284. $child = null;
  285. $leaf = true;
  286. $icon = 'el-icon-user';
  287. }
  288. $allData[$key]['children'] = $child;
  289. $allData[$key]['leaf'] = $leaf;
  290. $allData[$key]['icon'] = $icon;
  291. $allData[$key]['isExpanded'] = false;
  292. $allData[$key]['displayNone'] = 'display-none';
  293. $allData[$key]['RELATIVE_LOCATION'] = $data['RELATIVE_LOCATION'] == 1 ? 'L' : 'R';
  294. }
  295. }
  296. return $allData;
  297. }
  298. /**
  299. * 通过期数获取应该查询哪个表和库
  300. * @param $periodNum
  301. * @return array
  302. */
  303. public static function getTableNameFromPeriod($periodNum = null){
  304. $db = self::getDb();
  305. $tableName = self::tableName();
  306. // if($periodNum !== null){
  307. // // 获取当前期数
  308. // $period = Period::instance();
  309. // $nowPeriodNum = $period->getNowPeriodNum();
  310. // if($nowPeriodNum != $periodNum){
  311. // // 从备份库里找到期数对应的网络
  312. // if(ActiveRecord::isExistsTable('{{%USER_NETWORK_'.$periodNum.'}}', 'dbNetPoint')){
  313. // $db = Yii::$app->dbNetPoint;
  314. // $tableName = '{{%USER_NETWORK_'.$periodNum.'}}';
  315. // }
  316. // }
  317. // }
  318. return [
  319. 'db' => $db,
  320. 'tableName' => $tableName,
  321. ];
  322. }
  323. /**
  324. * 获取指定深度的子会员从指定的期数中
  325. * @param $userId
  326. * @param $periodNum
  327. * @return array|\yii\db\DataReader
  328. * @throws \yii\db\Exception
  329. */
  330. public static function getChildrenFromPeriod($userId, $periodNum=null){
  331. $table = self::getTableNameFromPeriod($periodNum);
  332. $db = $table['db'];
  333. $tableName = $table['tableName'];
  334. return $db->createCommand("SELECT USER_ID,TOP_DEEP,RELATIVE_LOCATION FROM {$tableName} WHERE PARENT_UID=:PARENT_UID")->bindValues([':PARENT_UID'=>$userId])->queryAll();
  335. }
  336. /**
  337. * 获取指定层数的这一层的会员以分页的方式
  338. * @param $userId
  339. * @param $deep
  340. * @param null $periodNum
  341. * @param array $params
  342. * @return array
  343. */
  344. public static function getChildrenInDeepFromPeriodWithPage($userId, $deep, $periodNum=null, $params=[]){
  345. $pageSize = method_exists(\Yii::$app->request,'get')?\Yii::$app->request->get('pageSize', \Yii::$app->params['pageSize']):\Yii::$app->params['pageSize'];
  346. if(isset($params['pageSize'])) $pageSize=$params['pageSize'];
  347. $page = null;
  348. if( isset($params['page']) ) $page=$params['page'];
  349. $orderBy = 'TOP_DEEP ASC, ID ASC';
  350. if( isset($params['orderBy']) ) $orderBy = $params['orderBy'];
  351. $table = self::getTableNameFromPeriod($periodNum);
  352. $db = $table['db'];
  353. $tableName = $table['tableName'];
  354. $userNetInfo = $db->createCommand("SELECT LOCATION_TAG,TOP_DEEP FROM {$tableName} WHERE USER_ID=:USER_ID")->bindValues([':USER_ID'=>$userId])->queryOne();
  355. $userDeep = $userNetInfo['TOP_DEEP'];
  356. $userLocationTag = $userNetInfo['LOCATION_TAG'];
  357. $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}";
  358. $totalCount = $db->createCommand($totalCountSql)->bindValues([':LOCATION_TAG'=>$userLocationTag . '%', ':TOP_DEEP'=>$userDeep + $deep])->queryOne();
  359. $count = $totalCount['TOTAL_COUNT'];
  360. $pagination = new Pagination(['totalCount' => $count]);
  361. $pagination->setPageSize($pageSize);
  362. if( $page !== null ) {
  363. $pagination->setPage($page);
  364. }
  365. $offset = $pagination->offset;
  366. $limit = $pagination->limit;
  367. // $end = $offset + $limit;
  368. $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}";
  369. $lists = $db->createCommand($listSql)->bindValues([':LOCATION_TAG'=>$userLocationTag . '%', ':TOP_DEEP'=>$userDeep + $deep])->queryAll();
  370. return [
  371. 'list' => $lists ? $lists : [],
  372. 'pagination' => $pagination,
  373. 'currentPage'=>$pagination->page,
  374. 'totalPages'=>$pagination->pageCount,
  375. 'totalCount' => $pagination->totalCount,
  376. 'pageSize' => $pagination->pageSize,
  377. ];
  378. }
  379. /**
  380. * 获取所有的上级会员带着分页和期数
  381. * @param $userId
  382. * @param null $periodNum
  383. * @param null $deep
  384. * @return array
  385. */
  386. public static function getAllParentFromPeriodWithPage($userId, $periodNum=null, $deep=null){
  387. $pageSize = method_exists(\Yii::$app->request,'get')?\Yii::$app->request->get('pageSize', \Yii::$app->params['pageSize']):\Yii::$app->params['pageSize'];
  388. $table = self::getTableNameFromPeriod($periodNum);
  389. $db = $table['db'];
  390. $tableName = $table['tableName'];
  391. $sql = "SELECT * FROM {$tableName} WHERE USER_ID=:USER_ID";
  392. $oneData = $db->createCommand($sql)->bindValues([':USER_ID'=>$userId])->queryOne();
  393. $userDeep = $oneData['TOP_DEEP'];
  394. $parentUidsStr = $oneData['PARENT_UIDS'] ?? "";
  395. if( !$parentUidsStr ) return [];
  396. $parentUidsArr = explode(',', $parentUidsStr);
  397. $parentUidsFlip = array_reverse($parentUidsArr);
  398. if ($deep != null) {
  399. $parentUidsFlip = array_slice($parentUidsFlip, 0, $deep);
  400. }
  401. $count = count($parentUidsFlip);
  402. $pagination = new Pagination(['totalCount' => $count]);
  403. $pagination->setPageSize($pageSize);
  404. $offset = $pagination->offset;
  405. $limit = $pagination->limit;
  406. $parentUidList = array_slice($parentUidsFlip, $offset, $limit);
  407. $lists = [];
  408. foreach ($parentUidList as $parentUid) {
  409. $sql = "SELECT * FROM {$tableName} WHERE USER_ID=:USER_ID";
  410. $data = $db->createCommand($sql)->bindValues([':USER_ID' => $parentUid])->queryOne();
  411. if( !$data ) continue;
  412. $data['LOCATION'] = substr($oneData['LOCATION_TAG'], strlen($data['LOCATION_TAG']), 1);
  413. $lists[] = $data;
  414. }
  415. return [
  416. 'list' => $lists ? $lists : [],
  417. 'pagination' => $pagination,
  418. 'currentPage' => $pagination->page,
  419. 'totalPages' => $pagination->pageCount,
  420. 'totalCount' => $pagination->totalCount,
  421. 'pageSize' => $pagination->pageSize,
  422. 'listTopDeep' => $userDeep,
  423. ];
  424. }
  425. /**
  426. * 获取一层下级数量从期数
  427. * @param $userId
  428. * @param null $periodNum
  429. * @return int
  430. */
  431. public static function firstFloorChildNumFromPeriod($userId, $periodNum=null){
  432. $table = self::getTableNameFromPeriod($periodNum);
  433. $db = $table['db'];
  434. $tableName = $table['tableName'];
  435. $count = $db->createCommand("SELECT COUNT(ID) AS ID_COUNT FROM {$tableName} WHERE PARENT_UID=:PARENT_UID")->bindValues([':PARENT_UID'=>$userId])->queryOne();
  436. return intval($count['ID_COUNT']);
  437. }
  438. /**
  439. * 从缓存中获取会员的全部父级(主要用于结算时的处理,能够提高效率不去查库)
  440. * @param $userId
  441. * @return array|mixed
  442. */
  443. public static function getAllParentsFromRedis($userId){
  444. $key = Cache::USER_NETWORK_PARENTS;
  445. $data = Yii::$app->redis->hget($key, $userId);
  446. if(!$data){
  447. $data = [];
  448. self::getParentsWithOffsetFromDbCalc($userId, function($oneData) use(&$data){
  449. $data[] = $oneData;
  450. }, 100);
  451. $data = Json::encode($data);
  452. Yii::$app->redis->hset($key, $userId, $data);
  453. }
  454. return $data ? Json::decode($data) : [];
  455. }
  456. /**
  457. * 判断在某个区位是否存在会员
  458. * @param $userId
  459. * @param $location
  460. * @return bool
  461. */
  462. public static function issetUserInLocation($userId, $location){
  463. $childrenNetList = UserNetwork::find()->select(['LOCATION_TAG'])->where('PARENT_UID=:PARENT_UID', [':PARENT_UID' => $userId])->asArray()->all();
  464. foreach ($childrenNetList as $everyData) {
  465. //取最后一位数
  466. $everyLocation = substr($everyData['LOCATION_TAG'], -1);
  467. if( $everyLocation == $location ) return true;
  468. }
  469. return false;
  470. }
  471. }