Info.php 23 KB

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