LlUserClass.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. namespace bizHd\ll\classes;
  3. use common\components\noticeUtil;
  4. use common\components\util;
  5. use Yii;
  6. use bizHd\base\classes\BaseClass;
  7. class LlUserClass extends BaseClass
  8. {
  9. public static $baseFile = '\bizHd\ll\models\LlUser';
  10. public static function addMobile($user, $mobile)
  11. {
  12. }
  13. public static function addWx($user, $wx)
  14. {
  15. }
  16. public static function addNo($user, $no)
  17. {
  18. }
  19. public static function getInfo($id, $sensitive = true)
  20. {
  21. $user = LlUserClass::getById($id, true);
  22. if (empty($user)) {
  23. util::fail('没有找到失信人员信息');
  24. }
  25. $name = $user->name ?? '';
  26. $firstDate = $user->firstDate ?? '';
  27. $lastDate = $user->lastDate ?? '';
  28. $breakNum = $user->breakNum ?? 0;
  29. $breakAmount = $user->breakAmount ?? 0;
  30. $mobileRes = LlMobileClass::getAllByCondition(['userId' => $id], null, '*');
  31. $mobileList = [];
  32. if (!empty($mobileRes)) {
  33. foreach ($mobileRes as $key => $val) {
  34. $mobile = $val['mobile'] ?? '';
  35. if (empty($mobile)) {
  36. continue;
  37. }
  38. if ($sensitive) {
  39. $mobile = substr_replace($mobile, '****', 3, 4);
  40. }
  41. $mobileList[] = $mobile;
  42. }
  43. }
  44. $wxRes = LlWxClass::getAllByCondition(['userId' => $id], null, '*');
  45. $wxList = [];
  46. if (!empty($wxRes)) {
  47. foreach ($wxRes as $key => $val) {
  48. $wx = $val['wx'] ?? '';
  49. if (empty($wx)) {
  50. continue;
  51. }
  52. if ($sensitive) {
  53. $wxNum = strlen($wx);
  54. $num = ceil($wxNum / 3);
  55. $str = '';
  56. for ($i = 1; $i <= $num; $i++) {
  57. $str .= '*';
  58. }
  59. $wx = substr_replace($wx, $str, -$num);
  60. }
  61. $wxList[] = $wx;
  62. }
  63. }
  64. $noRes = LlNoClass::getAllByCondition(['userId' => $id], null, '*');
  65. $noList = [];
  66. if (!empty($noRes)) {
  67. foreach ($noRes as $key => $val) {
  68. $no = $val['no'] ?? '';
  69. if (empty($no)) {
  70. continue;
  71. }
  72. if ($sensitive) {
  73. $no = substr_replace($no, '*********', 6, 9);
  74. }
  75. $noList[] = $no;
  76. }
  77. }
  78. $userInfo = [
  79. 'name' => $name,
  80. 'mobileList' => $mobileList,
  81. 'wxList' => $wxList,
  82. 'noList' => $noList,
  83. 'firstDate' => $firstDate,
  84. 'lastDate' => $lastDate,
  85. 'breakNum' => $breakNum,
  86. 'breakAmount' => $breakAmount,
  87. ];
  88. return $userInfo;
  89. }
  90. public static function getUserList($where, $sensitive = true)
  91. {
  92. $order = 'addTime DESC';
  93. $data = self::getList('*', $where, $order);
  94. $totalUserNum = self::getCount($where);
  95. $data['totalUserNum'] = $totalUserNum;
  96. if (isset($data['list']) && $data['list']) {
  97. foreach ($data['list'] as $key => $val) {
  98. if ($sensitive) {
  99. $mobile = $val['mobile'] ?? '';
  100. if (!empty($mobile)) {
  101. $mobile = substr_replace($mobile, '****', 3, 4);
  102. }
  103. $data['list'][$key]['mobile'] = $mobile;
  104. $wx = $val['wx'] ?? '';
  105. if (!empty($wx)) {
  106. $wxNum = strlen($wx);
  107. $num = ceil($wxNum / 3);
  108. $str = '';
  109. for ($i = 1; $i <= $num; $i++) {
  110. $str .= '*';
  111. }
  112. $wx = substr_replace($wx, $str, -$num);
  113. }
  114. $data['list'][$key]['wx'] = $wx;
  115. $no = $val['no'] ?? '';
  116. if (!empty($no)) {
  117. $no = substr_replace($no, '*********', 6, 9);
  118. }
  119. $data['list'][$key]['no'] = $no;
  120. }
  121. }
  122. }
  123. return $data;
  124. }
  125. public static function replaceUser($userInfo, $shop)
  126. {
  127. $shopId = $shop->id ?? '';
  128. $shopMobile = $shop->mobile ?? '';
  129. $shopFullName = $shop->merchantName . ' ' . $shop->shopName;
  130. $userId = 0;
  131. $baseId = 0;
  132. $thatDate = $userInfo['date'] ?? '';
  133. $name = $userInfo['name'] ?? '';
  134. $no = $userInfo['no'] ?? '';
  135. $noRes = LlNoClass::getByCondition(['no' => $no], true);
  136. if (!empty($noRes)) {
  137. $userId = $noRes->userId ?? 0;
  138. $baseId = $noRes->baseId ?? 0;
  139. }
  140. $mobile = $userInfo['mobile'] ?? '';
  141. $mobileRes = LlMobileClass::getByCondition(['mobile' => $mobile], true);
  142. if (!empty($mobileRes) && empty($userId)) {
  143. $userId = $mobileRes->userId ?? 0;
  144. $baseId = $mobileRes->baseId ?? 0;
  145. }
  146. $wx = $userInfo['wx'] ?? '';
  147. $wxRes = LlWxClass::getByCondition(['wx' => $wx], true);
  148. if (!empty($wxRes) && empty($userId)) {
  149. $userId = $wxRes->userId ?? 0;
  150. $baseId = $wxRes->baseId ?? 0;
  151. }
  152. if (!empty($userId)) {
  153. $user = self::getById($userId, true);
  154. } else {
  155. $userInfo['firstDate'] = $thatDate;
  156. $userInfo['lastDate'] = $thatDate;
  157. $user = self::add($userInfo, true);
  158. }
  159. if (!empty($baseId)) {
  160. $base = LlBaseClass::getById($baseId, true);
  161. if (empty($base)) {
  162. noticeUtil::push("用户提供的老赖信息,有baseId:{$baseId}但没base信息,提借者:{$shopId} {$shopMobile} {$shopFullName}", '15280215347');
  163. util::fail('用户信息有问题,请联系客服,baseId:' . $baseId);
  164. }
  165. if (!empty($no) && $no != $base->no) {
  166. noticeUtil::push("用户提供的老赖身份证号是{$no},但baseId:{$baseId}的身份证号是另个:{$base->no},提借者:{$shopId} {$shopMobile} {$shopFullName}", '15280215347');
  167. util::fail('请提身份证号有问题,请联系客服');
  168. }
  169. } else {
  170. $base = null;
  171. if (!empty($no)) {
  172. $base = LlBaseClass::getByCondition(['no' => $no], true);
  173. if (empty($base)) {
  174. $baseData = ['no' => $no, 'name' => $name, 'firstDate' => $thatDate, 'lastDate' => $thatDate];
  175. $base = LlBaseClass::add($baseData, true);
  176. }
  177. }
  178. }
  179. $userId = $user->id ?? 0;
  180. $baseId = $base->id ?? 0;
  181. if (!empty($wx)) {
  182. $wxRes = LlWxClass::getByCondition(['wx' => $wx], true);
  183. if (empty($wxRes)) {
  184. $wxRes = LlWxClass::add(['wx' => $wx], true);
  185. }
  186. $wxRes->baseId = $baseId;
  187. $wxRes->userId = $userId;
  188. $wxRes->save();
  189. }
  190. if (!empty($mobile)) {
  191. $mobileRes = LlMobileClass::getByCondition(['mobile' => $mobile], true);
  192. if (empty($mobileRes)) {
  193. $mobileRes = LlMobileClass::add(['mobile' => $mobile], true);
  194. }
  195. $mobileRes->baseId = $baseId;
  196. $mobileRes->userId = $userId;
  197. $mobileRes->save();
  198. }
  199. if (!empty($no)) {
  200. $noRes = LlNoClass::getByCondition(['no' => $no], true);
  201. if (empty($noRes)) {
  202. $noRes = LlNoClass::add(['no' => $no], true);
  203. }
  204. $noRes->baseId = $baseId;
  205. $noRes->userId = $userId;
  206. $noRes->save();
  207. }
  208. return $user;
  209. }
  210. }