Info.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/11/2
  6. * Time: 上午9:16
  7. */
  8. namespace common\helpers\user;
  9. use common\components\ActiveQuery;
  10. use common\components\ActiveRecord;
  11. use common\helpers\Cache;
  12. use common\helpers\Tool;
  13. use common\models\Config;
  14. use common\models\PerfMonth;
  15. use common\models\PerfPeriod;
  16. use common\models\Period;
  17. use common\models\DeclarationLevel;
  18. use common\models\DecRole;
  19. use common\models\EmployLevel;
  20. use common\models\OpenBank;
  21. use common\models\Region;
  22. use common\models\User;
  23. use common\models\UserBonus;
  24. use common\models\UserInfo;
  25. use common\models\UserNetwork;
  26. use common\models\UserRelation;
  27. use common\models\UserSystem;
  28. use common\models\UserWallet;
  29. use yii\base\Exception;
  30. class Info {
  31. /**
  32. * 获取用户ID
  33. * @param $userName
  34. * @return mixed
  35. */
  36. public static function getUserIdByUserName($userName) {
  37. $user = UserInfo::findOneAsArray('USER_NAME=:USER_NAME AND DELETED=0', [':USER_NAME' => $userName], 'USER_ID');
  38. return $user ? $user['USER_ID'] : null;
  39. }
  40. /**
  41. * 获取会员名通过ID
  42. * @param $userId
  43. * @return mixed|null
  44. */
  45. public static function getUserNameByUserId($userId) {
  46. $user = UserInfo::findOneAsArray('USER_ID=:USER_ID AND DELETED=0', [':USER_ID' => $userId], 'USER_NAME');
  47. return $user ? $user['USER_NAME'] : null;
  48. }
  49. /**
  50. * 获取用户EMAIL
  51. * @param $userName
  52. * @return mixed
  53. */
  54. public static function getEmailByUserId($userId) {
  55. $user = UserInfo::findOneAsArray('USER_ID=:USER_ID AND DELETED=0', [':USER_ID' => $userId], 'USER_NAME');
  56. return $user ? $user['EMAIL'] : null;
  57. }
  58. /**
  59. * 获取会员姓名通过ID
  60. * @param $userId
  61. * @return null
  62. */
  63. public static function getUserRealNameByUserId($userId) {
  64. $user = User::findOneAsArray('ID=:ID AND DELETED=0', [':ID' => $userId], 'REAL_NAME');
  65. return $user ? $user['REAL_NAME'] : null;
  66. }
  67. /**
  68. * 获取会员邮箱通过ID
  69. * @param $userId
  70. * @return null
  71. */
  72. public static function getUserEmailByUserId($userId) {
  73. $user = User::findOneAsArray('ID=:ID AND DELETED=0', [':ID' => $userId], 'EMAIL');
  74. return $user ? $user['EMAIL'] : null;
  75. }
  76. /**
  77. * 获取手机号通过ID
  78. * @param $userId
  79. * @return null
  80. */
  81. public static function getUserMobileByUserId($userId) {
  82. $user = User::findOneAsArray('ID=:ID AND DELETED=0', [':ID' => $userId], 'MOBILE');
  83. return $user ? $user['MOBILE'] : null;
  84. }
  85. /**
  86. * 通过用户ID获取用户的编号和名称
  87. * @param $userId
  88. * @return array|null
  89. */
  90. public static function getBaseUserById($userId) {
  91. return User::findOneAsArray('ID=:ID', [':ID' => $userId], 'ID,USER_NAME,REAL_NAME');
  92. }
  93. /**
  94. * 通过用户ID获取用户的编号和名称
  95. * @param $username
  96. * @return array|null
  97. */
  98. public static function getBaseUserByUserName($username) {
  99. return User::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => $username]);
  100. }
  101. /**
  102. * 当前期数的会员信息
  103. * @param $userId
  104. * @return array|\yii\db\ActiveRecord|null
  105. * @throws Exception
  106. */
  107. public static function baseInfoNowPeriod($userId) {
  108. $data = User::find()->where('ID=:ID', [':ID' => $userId])->asArray()->one();
  109. if (!$data) throw new Exception('会员不存在'.$userId);
  110. $infoData = UserInfo::find()->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->select('ZC_PV,CON_UID,REC_UID,CON_NUM,REC_NUM,NETWORK_DEEP,RELATION_DEEP,SYSTEM_ID,REG_TYPE,REG_NAME,CREDIT_CODE,PREMISES,LEGAL_PERSON,CLOSE_LOGIN,IS_BIND_MAIN,HIGHEST_EMP_LV,HIGHEST_EMP_LV_PERIOD,SHOULD_REG_TYPE,IS_SYSTEM_LEADER,ALLOW_TRANSFER,TRANSFER_PROP,IS_GROUP_LEADER,GROUP_LEADER_AT,SHOW_EMP_LV')->asArray()->one();
  111. if ($infoData) {
  112. $data = array_merge($data, $infoData);
  113. }
  114. if (!$data['DEC_LV']) $data['DEC_LV'] = DeclarationLevel::getDefaultLevelId();
  115. if (!$data['LAST_DEC_LV']) $data['LAST_DEC_LV'] = DeclarationLevel::getDefaultLevelId();
  116. if (!$data['EMP_LV']) $data['EMP_LV'] = EmployLevel::getDefaultLevelId();
  117. return $data;
  118. }
  119. /**
  120. * 获取会员信息,通过用户编号
  121. * @param $userId
  122. * @return array|\yii\db\ActiveRecord|null
  123. * @throws Exception
  124. */
  125. public static function baseInfoByUserName($userName) {
  126. $data = User::find()->where('USER_NAME=:USER_NAME', [':USER_NAME' => $userName])->asArray()->one();
  127. if (!$data) throw new Exception('会员不存在:'.$userName);
  128. $userId = $data['ID'];
  129. $infoData = UserInfo::find()
  130. ->where('USER_ID=:USER_ID', [':USER_ID' => $userId])
  131. ->select('ZC_PV,CON_UID,REC_UID,CON_NUM,REC_NUM,NETWORK_DEEP,RELATION_DEEP,SYSTEM_ID,REG_TYPE,REG_NAME,
  132. CREDIT_CODE,PREMISES,LEGAL_PERSON,CLOSE_LOGIN,IS_BIND_MAIN,HIGHEST_EMP_LV,HIGHEST_EMP_LV_PERIOD,
  133. SHOULD_REG_TYPE,IS_SYSTEM_LEADER,ALLOW_TRANSFER,TRANSFER_PROP,IS_GROUP_LEADER,GROUP_LEADER_AT,SHOW_EMP_LV')
  134. ->asArray()
  135. ->one();
  136. if ($infoData) {
  137. $data = array_merge($data, $infoData);
  138. }
  139. if (!$data['DEC_LV']) $data['DEC_LV'] = DeclarationLevel::getDefaultLevelId();
  140. if (!$data['LAST_DEC_LV']) $data['LAST_DEC_LV'] = DeclarationLevel::getDefaultLevelId();
  141. if (!$data['EMP_LV']) $data['EMP_LV'] = EmployLevel::getDefaultLevelId();
  142. return $data;
  143. }
  144. public static function baseInfoZhByUserName($userName) {
  145. $baseInfo = self::baseInfoByUserName($userName);
  146. // 状态处理
  147. $baseInfo['STATUS_NAME'] = \Yii::$app->params['userStatus'][$baseInfo['STATUS']]['label'];
  148. //登录状态
  149. $baseInfo['LOGIN_STATUS_NAME'] = $baseInfo['ALLOW_LOGIN'] == 0 ? '禁止登录' : '允许登录';
  150. // 子公司
  151. $baseInfo['SUB_COM_NAME'] = '';
  152. $baseInfo['PROVINCE_NAME'] = $baseInfo['PROVINCE'] ? Region::getCnName($baseInfo['PROVINCE']) : '';
  153. $baseInfo['CITY_NAME'] = $baseInfo['CITY'] ? Region::getCnName($baseInfo['CITY']) : '';
  154. $baseInfo['COUNTY_NAME'] = $baseInfo['COUNTY'] ? Region::getCnName($baseInfo['COUNTY']) : '';
  155. $baseInfo['BANK_PROVINCE_NAME'] = $baseInfo['BANK_PROVINCE'] ? Region::getCnName($baseInfo['BANK_PROVINCE']) : '';
  156. $baseInfo['BANK_CITY_NAME'] = $baseInfo['BANK_CITY'] ? Region::getCnName($baseInfo['BANK_CITY']) : '';
  157. $baseInfo['BANK_COUNTY_NAME'] = $baseInfo['BANK_COUNTY'] ? Region::getCnName($baseInfo['BANK_COUNTY']) : '';
  158. $baseInfo['OPEN_BANK_NAME'] = $baseInfo['OPEN_BANK'] ? OpenBank::getCnName($baseInfo['OPEN_BANK']) : '';
  159. // 获取会员体系
  160. $baseInfo['SYSTEM_NAME'] = '';
  161. // 获取会员级别名称
  162. $baseInfo['DEC_LV_NAME'] = Cache::getDecLevelConfig()[$baseInfo['DEC_LV']]['LEVEL_NAME'];
  163. $baseInfo['LAST_DEC_LV_NAME'] = Cache::getDecLevelConfig()[$baseInfo['LAST_DEC_LV']]['LEVEL_NAME'];
  164. $baseInfo['EMP_LV_NAME'] = Cache::getEmpLevelConfig()[$baseInfo['EMP_LV']]['LEVEL_NAME'];
  165. $baseInfo['HIGHEST_EMP_LV_NAME'] = '';
  166. // 获取会员报单级别
  167. $baseInfo['DEC_ROLE_NAME'] = '无';
  168. //民族
  169. $baseInfo['NATION_NAME'] = \Yii::$app->params['nation'][$baseInfo['NATION']]['name']??'';
  170. return $baseInfo;
  171. }
  172. /**
  173. * 基本信息
  174. * @param $userId
  175. * @param $periodNum
  176. * @return array|\yii\db\ActiveRecord|null
  177. * @throws Exception
  178. */
  179. public static function baseInfo($userId, $periodNum = null) {
  180. if($periodNum == null){
  181. return self::baseInfoNowPeriod($userId);
  182. } else {
  183. // 获取当前期数
  184. $tableName = '{{%USER_ALL_'.$periodNum.'}}';
  185. if(ActiveRecord::isExistsTable($tableName, 'dbNetPoint')){
  186. if($data = \Yii::$app->dbNetPoint->createCommand("SELECT * FROM $tableName WHERE ID=:ID")->bindValues([':ID'=>$userId])->queryOne()) {
  187. if (!$data['DEC_LV']) $data['DEC_LV'] = DeclarationLevel::getDefaultLevelId();
  188. if (!$data['LAST_DEC_LV']) $data['LAST_DEC_LV'] = DeclarationLevel::getDefaultLevelId();
  189. if (!$data['EMP_LV']) $data['EMP_LV'] = EmployLevel::getDefaultLevelId();
  190. if (!$data['HIGHEST_EMP_LV']) $data['HIGHEST_EMP_LV'] = EmployLevel::getDefaultLevelId();
  191. return $data;
  192. }else{
  193. return self::baseInfoNowPeriod($userId);
  194. }
  195. } else {
  196. return self::baseInfoNowPeriod($userId);
  197. }
  198. }
  199. }
  200. /**
  201. * 基本信息含中文地区和中文子公司
  202. * @param $userId
  203. * @param $periodNum
  204. * @return array|\yii\db\ActiveRecord|null
  205. * @throws Exception
  206. */
  207. public static function baseInfoZh($userId, $periodNum = null) {
  208. $baseInfo = self::baseInfo($userId, $periodNum);
  209. // 状态处理
  210. $baseInfo['STATUS_NAME'] = \Yii::$app->params['userStatus'][$baseInfo['STATUS']]['label'];
  211. //登录状态
  212. $baseInfo['LOGIN_STATUS_NAME'] = $baseInfo['ALLOW_LOGIN'] == 0 ? '禁止登录' : '允许登录';
  213. // 子公司
  214. $baseInfo['SUB_COM_NAME'] = '';
  215. $baseInfo['PROVINCE_NAME'] = $baseInfo['PROVINCE'] ? Region::getCnName($baseInfo['PROVINCE']) : '';
  216. $baseInfo['CITY_NAME'] = $baseInfo['CITY'] ? Region::getCnName($baseInfo['CITY']) : '';
  217. $baseInfo['COUNTY_NAME'] = $baseInfo['COUNTY'] ? Region::getCnName($baseInfo['COUNTY']) : '';
  218. $baseInfo['BANK_PROVINCE_NAME'] = $baseInfo['BANK_PROVINCE'] ? Region::getCnName($baseInfo['BANK_PROVINCE']) : '';
  219. $baseInfo['BANK_CITY_NAME'] = $baseInfo['BANK_CITY'] ? Region::getCnName($baseInfo['BANK_CITY']) : '';
  220. $baseInfo['BANK_COUNTY_NAME'] = $baseInfo['BANK_COUNTY'] ? Region::getCnName($baseInfo['BANK_COUNTY']) : '';
  221. $baseInfo['OPEN_BANK_NAME'] = $baseInfo['OPEN_BANK'] ? OpenBank::getCnName($baseInfo['OPEN_BANK']) : '';
  222. // 获取会员体系
  223. $baseInfo['SYSTEM_NAME'] = '';
  224. // 获取会员级别名称
  225. $baseInfo['DEC_LV_NAME'] = Cache::getDecLevelConfig()[$baseInfo['DEC_LV']]['LEVEL_NAME'];
  226. $baseInfo['LAST_DEC_LV_NAME'] = Cache::getDecLevelConfig()[$baseInfo['LAST_DEC_LV']]['LEVEL_NAME'];
  227. $baseInfo['EMP_LV_NAME'] = Cache::getEmpLevelConfig()[$baseInfo['EMP_LV']]['LEVEL_NAME'];
  228. $baseInfo['HIGHEST_EMP_LV_NAME'] = '';
  229. // 获取会员报单级别
  230. $baseInfo['DEC_ROLE_NAME'] = '无';
  231. //民族
  232. $baseInfo['NATION_NAME'] = \Yii::$app->params['nation'][$baseInfo['NATION']]['name']??'';
  233. return $baseInfo;
  234. }
  235. /**
  236. * 基本信息及余额
  237. * @param $userId
  238. * @param $periodNum
  239. * @return array
  240. */
  241. public static function baseInfoWithBalance($userId, $periodNum = null) {
  242. $baseInfo = self::baseInfoZh($userId, $periodNum);
  243. if ($baseInfo) {
  244. $userBonus = self::BalanceInfo($userId);
  245. }
  246. return array_merge($baseInfo, $userBonus);
  247. }
  248. /**
  249. * 获取余额信息
  250. * @param $userId
  251. * @return array|int[]|null
  252. */
  253. public static function BalanceInfo($userId) {
  254. $userBonus = [
  255. 'BONUS' => 0,
  256. 'BONUS_FREEZE' => 0,
  257. 'CF' => 0,
  258. 'LX' => 0,
  259. 'QY_TOTAL' => 0,
  260. 'YC_TOTAL' => 0,
  261. 'FX_TOTAL' => 0,
  262. 'LS_TOTAL' => 0,
  263. 'CF_TOTAL' => 0,
  264. 'LX_TOTAL' => 0,
  265. 'FL_TOTAL' => 0,
  266. 'BT_TOTAL' => 0,
  267. 'FW_TOTAL' => 0,
  268. 'CASH' => 0,
  269. ];
  270. if ($userBonusResult = UserBonus::findOneAsArray(['USER_ID' => $userId])) {
  271. $userBonus = $userBonusResult;
  272. }
  273. if ($userCashResult = UserWallet::findOneAsArray(['USER_ID' => $userId])) {
  274. $userBonus['CASH'] = $userCashResult['CASH'];
  275. }
  276. return $userBonus;
  277. }
  278. /**
  279. * 基本信息带着网络和节点信息
  280. * @param $userId
  281. * @param $periodNum
  282. * @return array|null|\yii\db\ActiveRecord
  283. */
  284. public static function baseInfoWithNet($userId, $periodNum = null) {
  285. $baseInfo = self::baseInfoZh($userId, $periodNum);
  286. $baseInfo['CON_USER_NAME'] = '';
  287. $baseInfo['CON_REAL_NAME'] = '';
  288. $baseInfo['LOCATION'] = '';
  289. $baseInfo['REC_USER_NAME'] = '';
  290. $baseInfo['REC_REAL_NAME'] = '';
  291. $baseInfo['DEC_USER_NAME'] = '';
  292. $baseInfo['DEC_REAL_NAME'] = '';
  293. $baseInfo['DEC_DEC_LV'] = '';
  294. $baseInfo['DEC_DEC_LV_NAME'] = '';
  295. if ($baseInfo) {
  296. if (isset($baseInfo['CON_UID']) && $baseInfo['CON_UID']) {
  297. // 安置网上级
  298. //$netParentUserInfo = UserNetwork::getFirstParentUserInfo($userId);
  299. $netParentBaseInfo = self::baseInfo($baseInfo['CON_UID']);
  300. $networkParent = UserNetwork::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId]);
  301. //$baseInfo['CON_UID'] = $baseInfo['CON_UID'];
  302. $baseInfo['CON_USER_NAME'] = $netParentBaseInfo['USER_NAME'];
  303. $baseInfo['CON_REAL_NAME'] = $netParentBaseInfo['REAL_NAME'];
  304. $baseInfo['LOCATION'] = $networkParent['RELATIVE_LOCATION'];
  305. }
  306. if (isset($baseInfo['REC_UID']) && $baseInfo['REC_UID']) {
  307. // 推荐网上级
  308. //$relationParentUserInfo = UserRelation::getFirstParentUserInfo($userId);
  309. $relationParentBaseInfo = self::baseInfo($baseInfo['REC_UID']);
  310. //$baseInfo['REC_UID'] = $relationParentUserInfo['USER_ID'];
  311. $baseInfo['REC_USER_NAME'] = $relationParentBaseInfo['USER_NAME'];
  312. $baseInfo['REC_REAL_NAME'] = $relationParentBaseInfo['REAL_NAME'];
  313. }
  314. if (isset($baseInfo['DEC_ID']) && $baseInfo['DEC_ID']) {
  315. $decBaseInfo = self::baseInfoZh($baseInfo['DEC_ID']);
  316. $baseInfo['DEC_USER_NAME'] = $decBaseInfo['USER_NAME'];
  317. $baseInfo['DEC_REAL_NAME'] = $decBaseInfo['REAL_NAME'];
  318. $baseInfo['DEC_DEC_LV'] = $decBaseInfo['DEC_LV'];
  319. $baseInfo['DEC_DEC_LV_NAME'] = $decBaseInfo['DEC_LV_NAME'];
  320. $baseInfo['DEC_DEC_ROLE_NAME'] = $decBaseInfo['DEC_ROLE_NAME'];
  321. $baseInfo['DEC_DEC_ROLE_ID'] = $decBaseInfo['DEC_ROLE_ID'];
  322. }
  323. }
  324. return $baseInfo;
  325. }
  326. /**
  327. * 基本信息含网络和余额
  328. * @param $userId
  329. * @param $periodNum
  330. * @return array
  331. */
  332. public static function baseInfoWithNetAndBalance($userId, $periodNum = null) {
  333. return array_merge(self::baseInfoWithNet($userId), self::BalanceInfo($userId));
  334. }
  335. /**
  336. * 通过用户名获取用户信息从INFO表
  337. * @param $userName
  338. * @return array|null|\yii\db\ActiveRecord
  339. */
  340. public static function getUserByUserNameFromUserInfoTable($userName) {
  341. return UserInfo::findOneAsArray(['USER_NAME' => $userName]);
  342. }
  343. /**
  344. * 获取报单级别
  345. * @param $userId
  346. * @param null $periodNum
  347. * @return mixed
  348. * @throws \yii\db\Exception
  349. */
  350. public static function getDecLv($userId, $periodNum = null) {
  351. if ($periodNum === null) {
  352. $data = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'DEC_LV');
  353. $decLv = $data['DEC_LV'];
  354. } else {
  355. $period = Period::instance();
  356. $yearMonth = $period->getYearMonth($periodNum);
  357. $data = PerfPeriod::find()->yearMonth($yearMonth)->select('LAST_DEC_LV')->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [':USER_ID' => $userId, ':PERIOD_NUM' => $periodNum])->asArray()->one();
  358. $decLv = $data ? $data['LAST_DEC_LV'] : DeclarationLevel::getDefaultLevelId();
  359. }
  360. return $decLv;
  361. }
  362. /**
  363. * 获取聘级
  364. * @param $userId
  365. * @param null $periodNum
  366. * @return mixed
  367. * @throws \yii\db\Exception
  368. */
  369. public static function getEmpLv($userId, $periodNum = null) {
  370. if ($periodNum === null) {
  371. $data = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'EMP_LV');
  372. $empLv = $data['EMP_LV'];
  373. } else {
  374. $period = Period::instance();
  375. $yearMonth = $period->getYearMonth($periodNum);
  376. $data = PerfMonth::find()->yearMonth($yearMonth)->select('LAST_EMP_LV')->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', [':USER_ID' => $userId, ':CALC_MONTH' => $yearMonth])->asArray()->one();
  377. $empLv = $data ? $data['LAST_EMP_LV'] : EmployLevel::getDefaultLevelId();
  378. }
  379. return $empLv;
  380. }
  381. /**
  382. * 获取最高聘级
  383. * @param $userId
  384. * @return mixed
  385. */
  386. public static function getHighEmpLv($userId){
  387. $data = UserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'HIGHEST_EMP_LV');
  388. $empLv = $data ? $data['HIGHEST_EMP_LV'] : EmployLevel::getDefaultLevelId();
  389. return $empLv;
  390. }
  391. /**
  392. * 获取报单级别名称
  393. * @param $userId
  394. * @param null $periodNum
  395. * @return mixed
  396. * @throws \yii\db\Exception
  397. */
  398. public static function getDecLvName($userId, $periodNum = null) {
  399. if (!$decLv = self::getDecLv($userId, $periodNum)) {
  400. $decLv = DeclarationLevel::getDefaultLevelId();
  401. }
  402. return Cache::getDecLevelConfig()[$decLv]['LEVEL_NAME'];
  403. }
  404. /**
  405. * 获取聘级名称
  406. * @param $userId
  407. * @param null $periodNum
  408. * @return mixed
  409. * @throws \yii\db\Exception
  410. */
  411. public static function getEmpLvName($userId, $periodNum = null) {
  412. if (!$empLv = self::getEmpLv($userId, $periodNum)) {
  413. $empLv = EmployLevel::getDefaultLevelId();
  414. }
  415. return Cache::getEmpLevelConfig()[$empLv]['LEVEL_NAME'];
  416. }
  417. /**
  418. * 获取民族对应的代码
  419. * @param $str
  420. * @return int|string
  421. */
  422. public static function getNationCode($str) {
  423. $str = preg_replace('/族$/', '', $str);
  424. $allNation = \Yii::$app->params['nation'];
  425. foreach ($allNation as $key => $nation) {
  426. if ($str . '族' == $nation['name']) {
  427. return $key;
  428. }
  429. }
  430. return 0;
  431. }
  432. /**
  433. * 生成用户名
  434. * @param string $prefix
  435. * @param int $length
  436. * @return string
  437. */
  438. public static function generateUserName(string $prefix = 'HZ', int $length = 10) {
  439. $result = Tool::randomString($length, $prefix).array_rand([0,1,2,3,5,6,7,8,9],1);
  440. if (User::find()->where('USER_NAME=:USER_NAME', [':USER_NAME' => $result])->exists()) {
  441. return self::generateUserName($prefix, $length);
  442. }
  443. return $result;
  444. }
  445. /**
  446. * 新增加的 生成前端姓名里用户名
  447. * @param string $prefix
  448. * @param int $length
  449. * @return string
  450. */
  451. public static function generateWebUserName(string $prefix = 'HZ', int $length = 10) {
  452. $result = Tool::randomString($length, $prefix).array_rand([0,1,2,3,5,6,7,8,9],1);
  453. if (substr($result ,-1) == '4'){
  454. return self::generateWebUserName($prefix, $length);
  455. }
  456. if (User::find()->where('USER_NAME=:USER_NAME', [':USER_NAME' => $result])->exists()) {
  457. return self::generateWebUserName($prefix, $length);
  458. }
  459. return $result;
  460. }
  461. /**
  462. * 定位会员的子公司
  463. * @param $userArea
  464. * @return array|bool
  465. */
  466. public static function location($userArea){
  467. if(!is_array($userArea)){
  468. $userArea = json_decode($userArea, true);
  469. }
  470. if(!$userArea || !isset($userArea[0])){
  471. return false;
  472. }
  473. //获取会员的所在省份
  474. $userProvince = $userArea[0];
  475. $list = [];
  476. if(!$list){
  477. return false;
  478. }
  479. $matched = [];
  480. $userCity = isset($userArea[1]) ? intval($userArea[1]) : 0;
  481. $userCounty = isset($userArea[2]) ? intval($userArea[2]) : 0;
  482. foreach($list as $row){
  483. $manageRange = json_decode($row['MANAGE_RANGE'], true);
  484. foreach($manageRange as $manage){
  485. // $manage = ["370000","371000","371082"] or ["210000",""];
  486. $pro = isset($manage[0]) ? intval($manage[0]) : 0;
  487. $city = isset($manage[1]) ? intval($manage[1]) : 0;
  488. $county = isset($manage[2]) ? intval($manage[2]) : 0;
  489. if($userProvince == $pro && $userCity == $city && $userCounty == $county){
  490. $matched = $row;
  491. break;
  492. }
  493. if($userProvince == $pro && $userCity == $city && $county == 0){
  494. $matched = $row;
  495. break;
  496. }
  497. if($userProvince == $pro && $city == 0 && $county == 0){
  498. $matched = $row;
  499. break;
  500. }
  501. }
  502. }
  503. unset($userCounty, $userCity, $userArea, $userProvince, $list);
  504. return $matched;
  505. }
  506. /**
  507. * 通过id获取身份证号
  508. * @param $userId
  509. * @return null
  510. */
  511. public static function getIdCardByUserId($userId) {
  512. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'ID_CARD');
  513. return $user ? $user['ID_CARD'] : null;
  514. }
  515. /**
  516. * 通过id获取状态
  517. * @param $userId
  518. * @return null
  519. */
  520. public static function getStatusByUserId($userId){
  521. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'STATUS');
  522. return $user ? $user['STATUS'] : null;
  523. }
  524. /**
  525. * 通过id获取期数
  526. * @param $userId
  527. * @return null
  528. */
  529. public static function getPeriodNumByUserId($userId) {
  530. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'PERIOD_AT');
  531. return $user ? $user['PERIOD_AT'] : null;
  532. }
  533. /**
  534. * 是否实名认证
  535. * @param $userId
  536. * @return bool
  537. */
  538. public static function isVerified($userId) {
  539. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'VERIFIED');
  540. if ($user && $user['VERIFIED'] == 1) return true;
  541. return false;
  542. }
  543. /**
  544. * 根据商城设置获取密码
  545. * @param $idCard
  546. * @param $userName
  547. * @param bool $payPwd
  548. * @return bool|string
  549. */
  550. public static function passwordGenerator($idCard,$userName,$payPwd=false) {
  551. $systemConfig = Cache::getSystemConfig();
  552. if($payPwd){
  553. $config = $systemConfig['payPasswordRule'];
  554. }else{
  555. $config = $systemConfig['passwordRule'];
  556. }
  557. $rule = $config['VALUE']; //id_s_6 , id_p_8, user_name 后台设置,分别为身份证的后6位,前8位或者用户名
  558. switch ($rule) {
  559. case 'id_s_6':
  560. $password = substr($idCard, -6);
  561. break;
  562. case 'id_p_8':
  563. $password = substr($idCard, 0, 8);
  564. break;
  565. case 'user_name':
  566. $password = $userName;
  567. break;
  568. default:
  569. $password = '123456';
  570. }
  571. return $password;
  572. }
  573. /**
  574. * 当时会员级别状态等
  575. * @param $userId
  576. * @return array|null
  577. */
  578. public static function getLastInfo($userId){
  579. $data = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'LAST_DEC_LV AS DEC_LV,EMP_LV,STATUS');
  580. return $data;
  581. }
  582. /**
  583. * 是否合作会员
  584. * @param $userId
  585. * @return bool
  586. */
  587. public static function isUnion($userId){
  588. $data = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'IS_UNION');
  589. if ($data && $data['IS_UNION'] == 1) return true;
  590. return false;
  591. }
  592. }