Info.php 20 KB

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