Info.php 20 KB

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