userinfologic.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-09-27 09:02:06
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-11-19 11:38:38
  7. */
  8. namespace app\index\logic;
  9. use app\index\logic\wxlogic;
  10. use app\index\model\companymodel;
  11. use app\index\model\logmodel;
  12. use app\index\model\userinfomodel;
  13. use app\index\model\workerinfomodel;
  14. use app\index\model\workermodel;
  15. use think\Db;
  16. use think\Log;
  17. class userinfologic
  18. {
  19. private $userinfomodel;
  20. public function __construct()
  21. {
  22. $this->userinfomodel = new userinfomodel();
  23. }
  24. public function getinfobyid($id, $field = '*')
  25. {
  26. $where = ['id' => $id];
  27. $info = $this->userinfomodel->getInfo($where, $field);
  28. return $info;
  29. }
  30. public function getinfobysfzid($sfzid, $field = '*')
  31. {
  32. $where = ['sfzid' => $sfzid];
  33. $info = $this->userinfomodel->getInfo($where, $field);
  34. return $info;
  35. }
  36. public function getinfobyopenid($arr, $field = '*')
  37. {
  38. if (!isset($arr['openid']) || empty($arr['openid'])) {
  39. return backarr(0, "请求错误");
  40. }
  41. $openid = $arr['openid'];
  42. $where = ['openid' => $openid];
  43. $info = $this->userinfomodel->getInfo($where, $field);
  44. if (empty($info)) {
  45. return backarr(0, "无数据");
  46. }
  47. $m_c = new companymodel();
  48. $cinfo = $m_c->getInfo(['userid' => $info['id'], 'isactive' => 1], ['id', 'company']);
  49. $info['company'] = empty($cinfo) ? false : $cinfo;
  50. return backarr(1, "查询成功", $info);
  51. }
  52. /*
  53. * 20211003
  54. * steelxu
  55. * 根据电话号码获取用户消息
  56. */
  57. public function getinfobytelno($telno, $field = '*')
  58. {
  59. $where = ['telno' => $telno];
  60. $info = $this->userinfomodel->getInfo($where, $field);
  61. return $info;
  62. }
  63. public function insertinfo($info)
  64. {
  65. $sfzid = $info['sfzid'];
  66. if (empty($sfzid)) {
  67. return backarr(0, "身份证号无数据");
  68. }
  69. $userinfo = $this->getinfobysfzid($sfzid);
  70. if ($userinfo) {
  71. return backarr(0, "身份证已存在");
  72. }
  73. //$id = $this->userinfomodel->insertData($info);
  74. $id = $this->insertUserInfo($info);
  75. if (!$id) {
  76. return backarr(0, "用户添加失败");
  77. }
  78. return backarr(1, "添加成功", $id);
  79. }
  80. /*
  81. * wj
  82. * 20211002
  83. * edit by steelxu
  84. * upate 改为 update
  85. * 另,使用者注意,此方法仅适用于根据id无条件更新,如有其它条件,需另行写方法
  86. * edit steelxu
  87. * update方法参数顺序
  88. */
  89. public function updateinfobyid($id, $updateData)
  90. {
  91. $where = ['id' => $id];
  92. $result = $this->userinfomodel->where($where)->update($updateData);
  93. return $result;
  94. }
  95. /*
  96. * 20211002
  97. * steelxu5
  98. * 快速发单,用户可不实名认证
  99. * 小程序用户仅通过openid就可以获得帐户
  100. */
  101. public function saveuseronlyopenid($arr)
  102. {
  103. $arr['createtime'] = date('Y-m-d H:i:s');
  104. $id = $this->userinfomodel->insertData($arr);
  105. if (!$id) {
  106. return backarr(0, "用户添加失败");
  107. }
  108. return backarr(1, "添加成功", $id);
  109. }
  110. /*
  111. * 20211003
  112. * steelxu5
  113. * 小程序快速发单,用户不实名认证
  114. * 提交openid 与telno
  115. * 如果user表中telno已存在,则更新openid
  116. * 如果telno 不存在,则创建新用户
  117. * 另外返回时不返回sfzid
  118. * 需要加上头像处理,如果前端处理一并提交头像,服务端已处理20211003
  119. * eidt by steelxu5
  120. * edit in 20211105
  121. * 新注册的用户加上platform
  122. * sdit by steelxu5
  123. * edit in 20211119
  124. * 返回做限制,不能返回所有的数据
  125. */
  126. public function saveuserwithopenidtelno($arr)
  127. {
  128. if (!isset($arr['telno']) || !isset($arr['openid'])) {
  129. return backarr(0, "请求错误");
  130. }
  131. //先检查是否电话号码已存在
  132. $telno = $arr['telno'];
  133. $rinfo = $this->getinfobytelno($telno, 'id,telno,isright,openid'); //20211119 edit by steelxu5
  134. if ($rinfo) {
  135. //根据id更新openid
  136. $rid = $rinfo['id'];
  137. if ($arr['openid'] != $rinfo['openid']) {
  138. $updatearr['openid'] = $arr['openid'];
  139. if (array_key_exists('photourl', $arr)) {
  140. $updatearr['photourl'] = $arr['photourl'];
  141. }
  142. $kd = $this->updateinfobyid($rid, $updatearr);
  143. }
  144. $rinfo = $this->getinfobyid($rid);
  145. if (isset($rinfo['sfzid'])) {
  146. $rinfo['sfzid'] = '';
  147. }
  148. if (isset($rinfo['sfzid'])) {
  149. $rinfo['sfzid'] = '';
  150. }
  151. return backarr(1, "添加成功", $rinfo);
  152. } else {
  153. Db::startTrans();
  154. try {
  155. $arr['createtime'] = date('Y-m-d H:i:s');
  156. $arr['platform'] = '水猫小程序';
  157. $id = $this->userinfomodel->insertData($arr);
  158. if (!$id) {
  159. throw new \Exception("用户添加失败");
  160. }
  161. $uid = $id;
  162. /* $l_w = new wxlogic();
  163. $filename = $uid . '_' . time();
  164. $qrcode = [
  165. 'scene' => 'userid=' . $uid,
  166. 'page' => 'src/views/index/index',
  167. ];
  168. $qrresult = $l_w->getqrcode($qrcode, $filename);
  169. if (1 != $qrresult['status']) {
  170. throw new \Exception($qrresult['msg']);
  171. }
  172. $qrcode = $qrresult['data']['qrcode'];
  173. $updatedata = [
  174. 'qrcode' => $qrcode,
  175. ];
  176. $updaterow = $this->updateinfobyid($uid, $updatedata);
  177. if (1 != $updaterow) {
  178. throw new \Exception("小程序二维码保存错误");
  179. }*/
  180. $rinfo = $this->getinfobyid($id);
  181. if (isset($rinfo['sfzid'])) {
  182. $rinfo['sfzid'] = '';
  183. }
  184. Db::commit();
  185. return backarr(1, "添加成功", $rinfo);
  186. } catch (\Exception $e) {
  187. $msg = $e->getMessage();
  188. log::info($e->getTrace());
  189. Db::rollback();
  190. return backjson(0, $msg);
  191. }
  192. }
  193. }
  194. /*
  195. * 20211031
  196. * 小程序实名认证,通过openid更新其它数据
  197. * steelxu5
  198. */
  199. public function updateinfobyopenid($arr)
  200. {
  201. Db::startTrans();
  202. try {
  203. if (!isset($arr['openid']) || empty($arr['openid'])) {
  204. return backarr(0, "请求错误");
  205. }
  206. $openid = $arr['openid'];
  207. $info = $this->userinfomodel->getInfo(['openid' => $openid]);
  208. if (empty($info)) {
  209. $insertData = ['openid' => $openid];
  210. $userid = $this->insertUserInfo($insertData);
  211. $info = $this->userinfomodel->getInfo(['id' => $userid]);
  212. //throw new \Exception("无用户信息");
  213. }
  214. $sfzid = $arr['sfzid'];
  215. $m_wi = new workerinfomodel();
  216. $wiWhere = ['sfzid' => $sfzid];
  217. $wiinfo = $m_wi->getinfo($wiWhere);
  218. if (empty($wiinfo)) {
  219. $insertData = [];
  220. //工会新建信息 未缴费 value userinfo字段 key workerinfo字段
  221. $insertFiledArr = [
  222. 'sfzid' => 'sfzid',
  223. 'wname' => 'wname',
  224. 'gender' => 'gender',
  225. 'wage' => 'wage',
  226. 'nation' => 'nation',
  227. 'telno' => 'telno',
  228. 'signurl' => 'signurl',
  229. 'frontsfzurl' => 'frontsfzurl',
  230. 'backsfzurl' => 'backsfzurl',
  231. 'city' => 'city',
  232. 'disc' => 'disc',
  233. 'address' => 'address',
  234. ];
  235. foreach ($insertFiledArr as $key => $value) {
  236. if (isset($arr[$value]) && !empty($arr[$value])) {
  237. $insertData[$key] = $arr[$value];
  238. }
  239. }
  240. $insertData['ispass'] = 1;
  241. $insertData['isactive'] = 0;
  242. $labid = $m_wi->insinfo($insertData);
  243. if (empty($labid)) {
  244. throw new \Exception("工会用户添加失败");
  245. }
  246. } else {
  247. $labid = $wiinfo['id'];
  248. }
  249. if (empty($labid)) {
  250. throw new \Exception("无工会用户id");
  251. }
  252. $updatearr['labid'] = $labid;
  253. $updatearr['gender'] = $arr['gender'];
  254. $updatearr['nation'] = $arr['nation'];
  255. $updatearr['address'] = $arr['address'];
  256. $updatearr['backsfzurl'] = $arr['backsfzurl'];
  257. $updatearr['frontsfzurl'] = $arr['frontsfzurl'];
  258. $updatearr['sfzenddate'] = $arr['sfzenddate'];
  259. $updatearr['sfzid'] = $arr['sfzid'];
  260. $updatearr['telno'] = $arr['telno'];
  261. $updatearr['wname'] = $arr['wname'];
  262. if (isset($arr['wage']) && is_numeric($arr['wage']) && !empty($arr['wage'])) {
  263. $updatearr['wage'] = $arr['wage'];
  264. } else {
  265. $age = getGenderByAge($sfzid);
  266. if ($age < 60 && $age > 10) {
  267. $arr['wage'] = $age;
  268. }
  269. $updatearr['wage'] = $arr['wage'];
  270. }
  271. $updatearr['worktype'] = $arr['worktype'];
  272. $where['id'] = $info['id'];
  273. $row = $this->updateUserInfo($where, $updatearr);
  274. if (empty($row)) {
  275. throw new \Exception("更新失败");
  276. }
  277. Db::commit();
  278. return backarr(1, '更新成功', $info['id']);
  279. } catch (\Exception $e) {
  280. Db::rollback();
  281. $msg = $e->getMessage();
  282. return backarr(0, $msg);
  283. }
  284. }
  285. /*
  286. * 20211105
  287. * app实名认证,通过id更新其它数据
  288. * wj
  289. */
  290. public function updateinfobyidforapp($arr)
  291. {
  292. $fillField = ['uid', 'sfzid'];
  293. foreach ($fillField as $key => $value) {
  294. if (!isset($arr[$value]) || empty($arr[$value])) {
  295. return backarr(0, "请求错误");
  296. }
  297. }
  298. $sfzid = $arr['sfzid'];
  299. $uid = $arr['uid'];
  300. $userinfo = $this->getinfobyid($uid);
  301. if (empty($userinfo)) {
  302. return backarr(0, "无用户数据");
  303. }
  304. if (isset($arr['sfzid']) && !empty($arr['sfzid'])) {
  305. $wheresfz = [
  306. 'sfzid' => $arr['sfzid'],
  307. 'id' => ['not in', [$uid]],
  308. ];
  309. $sfzinfo = $this->userinfomodel->getInfo($wheresfz);
  310. if (!empty($sfzinfo)) {
  311. return backarr(0, "身份证已存在");
  312. }
  313. }
  314. if (isset($arr['sfzenddate'])) {
  315. $sfzenddate = getSfzend($arr['sfzenddate']);
  316. if ($sfzenddate) {
  317. $arr['sfzenddate'] = $sfzenddate;
  318. }
  319. }
  320. //年龄
  321. $age = getGenderByAge($sfzid);
  322. if ($age < 60 && $age > 10) {
  323. $arr['wage'] = $age;
  324. }
  325. $arr = array_merge($userinfo->toArray(), $arr);
  326. Db::startTrans();
  327. try {
  328. //工会用户信息
  329. $m_wi = new workerinfomodel();
  330. $wiWhere = ['sfzid' => $sfzid];
  331. $wiinfo = $m_wi->getinfo($wiWhere);
  332. if (empty($wiinfo)) {
  333. $insertData = [];
  334. //工会新建信息 未缴费 value userinfo字段 key workerinfo字段
  335. $insertFiledArr = [
  336. 'sfzid' => 'sfzid',
  337. 'wname' => 'wname',
  338. 'gender' => 'gender',
  339. 'wage' => 'wage',
  340. 'nation' => 'nation',
  341. 'telno' => 'telno',
  342. 'signurl' => 'signurl',
  343. 'frontsfzurl' => 'frontsfzurl',
  344. 'backsfzurl' => 'backsfzurl',
  345. 'city' => 'city',
  346. 'disc' => 'disc',
  347. 'address' => 'address',
  348. ];
  349. foreach ($insertFiledArr as $key => $value) {
  350. if (isset($arr[$value]) && !empty($arr[$value])) {
  351. $insertData[$key] = $arr[$value];
  352. }
  353. }
  354. $insertData['ispass'] = 1;
  355. $insertData['isactive'] = 0;
  356. $labid = $m_wi->insinfo($insertData);
  357. if (empty($labid)) {
  358. throw new \Exception("工会用户添加失败");
  359. }
  360. } else {
  361. $labid = $wiinfo['id'];
  362. }
  363. if (empty($labid)) {
  364. throw new \Exception("无工会用户id");
  365. }
  366. //改用户信息
  367. $updateData = [];
  368. $updateFiledStr = ['gender', 'nation', 'city', 'disc', 'address', 'signurl', 'backsfzurl', 'frontsfzurl', 'sfzenddate', 'sfzid', 'telno', 'wname', 'wage', 'nickname'];
  369. foreach ($updateFiledStr as $key => $value) {
  370. if (isset($arr[$value]) && !empty($arr[$value])) {
  371. if ($userinfo[$value] != $arr[$value]) {
  372. $updateData[$value] = $arr[$value];
  373. }
  374. }
  375. }
  376. $where = ['id' => $uid];
  377. $updateData['labid'] = $labid;
  378. if (isset($updateData['sfzenddate'])) {
  379. $sfzenddate = getSfzend($updateData['sfzenddate']);
  380. if ($sfzenddate) {
  381. $updateData['sfzenddate'] = $sfzenddate;
  382. }
  383. }
  384. $row = $this->updateUserInfo($where, $updateData);
  385. if (empty($row)) {
  386. throw new \Exception("更新失败");
  387. }
  388. Db::commit();
  389. $where = ['id' => $uid];
  390. $field = ['id', 'gender', 'telno', 'wname', 'isactive', 'labid', 'sfzid'];
  391. $info = $this->userinfomodel->getInfo($where, $field);
  392. $info['sfzid'] = empty($info['sfzid']) ? false : true;
  393. return backarr(1, "更新成功", $info);
  394. } catch (\Exception $e) {
  395. Db::rollback();
  396. $msg = $e->getMessage();
  397. return backarr(0, $msg);
  398. }
  399. }
  400. /*
  401. * 20210815
  402. * 身份证查重
  403. * edit by steelxu
  404. * edit 20211031
  405. */
  406. public function checksfzrepeat($arr)
  407. {
  408. $t_gw = new userinfomodel();
  409. $isrepeat = $t_gw->precheckindex($arr);
  410. return $isrepeat;
  411. }
  412. /**
  413. * 添加会员信息
  414. * userinfo worker 统一操作
  415. * wj
  416. * 20211103
  417. */
  418. public function insertUserInfo($info)
  419. {
  420. $m_u = new userinfomodel();
  421. $m_w = new workermodel();
  422. $userDesc = $m_u->gettablefields();
  423. $workerDesc = $m_w->gettablefields();
  424. $userInsertData = [];
  425. $workerInsertData = [];
  426. foreach ($userDesc as $key => $value) {
  427. $field = $value['Field'];
  428. if (isset($info[$field])) {
  429. $userInsertData[$field] = $info[$field];
  430. }
  431. }
  432. foreach ($workerDesc as $key => $value) {
  433. $field = $value['Field'];
  434. if (isset($info[$field])) {
  435. $workerInsertData[$field] = $info[$field];
  436. }
  437. }
  438. $userid = $m_u->insertData($userInsertData);
  439. $workerInsertData['userid'] = $userid;
  440. $workerid = $m_w->insertData($workerInsertData);
  441. return $userid;
  442. }
  443. /**
  444. * 修改会员信息
  445. * userinfo worker 统一操作
  446. * wj
  447. * 20211103
  448. */
  449. public function updateUserInfo($where, $updateData)
  450. {
  451. $m_u = new userinfomodel();
  452. $m_w = new workermodel();
  453. $userinfo = $m_u->getInfo($where);
  454. $workerinfo = $m_w->getInfo(['userid' => $userinfo['id']]);
  455. if (empty($workerinfo)) {
  456. $wid = $m_w->insertData(['userid' => $userinfo['id']]);
  457. $workerinfo = $m_w->getInfo(['id' => $wid]);
  458. }
  459. $userUpdateData = [];
  460. $workerUpdateData = [];
  461. foreach ($updateData as $key => $value) {
  462. if (isset($userinfo[$key])) {
  463. if ($value != $userinfo[$key]) {
  464. $userUpdateData[$key] = $updateData[$key];
  465. }
  466. }
  467. }
  468. foreach ($updateData as $key => $value) {
  469. if (isset($workerinfo[$key])) {
  470. if ($value != $workerinfo[$key]) {
  471. $workerUpdateData[$key] = $updateData[$key];
  472. }
  473. }
  474. }
  475. $userWhere = ['id' => $userinfo['id']];
  476. $workerWhere = ['id' => $workerinfo['id']];
  477. $userRow = $m_u->updateinfo($userWhere, $userUpdateData);
  478. $workerRow = $m_w->updateinfo($workerWhere, $workerUpdateData);
  479. return $userRow;
  480. }
  481. /**
  482. * 根据条件获取用户列表
  483. * 20211118
  484. * wj
  485. */
  486. public function getuserlist($arr)
  487. {
  488. $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
  489. $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
  490. $where = [];
  491. if (isset($arr['wname']) && !empty($arr['wname'])) {
  492. if ('null' == $arr['wname']) {
  493. $where['wname'] = 'NULL';
  494. } elseif (is_string($arr['wname'])) {
  495. $where['wname'] = ['like', '%' . $arr['wname'] . '%'];
  496. }
  497. }
  498. if (isset($arr['telno']) && !empty($arr['telno'])) {
  499. $where['telno'] = ['like', '%' . $arr['telno'] . '%'];
  500. }
  501. if (isset($arr['sfzid']) && !empty($arr['sfzid'])) {
  502. if ('null' == $arr['sfzid']) {
  503. $where['sfzid'] = 'NULL';
  504. } elseif (is_string($arr['sfzid'])) {
  505. $where['sfzid'] = ['like', '%' . $arr['sfzid'] . '%'];
  506. }
  507. }
  508. if (isset($arr['isactive']) && is_numeric($arr['isactive'])) {
  509. if ($arr['isactive']) {
  510. $where['isactive'] = 1;
  511. } else {
  512. $where['isactive'] = 0;
  513. }
  514. }
  515. if (isset($arr['isright']) && is_numeric($arr['isright'])) {
  516. if ($arr['isright']) {
  517. $where['isright'] = 1;
  518. } else {
  519. $where['isright'] = 0;
  520. }
  521. }
  522. $m_u = new userinfomodel();
  523. $count = $m_u->getList($where, 'count');
  524. if ($count < 0) {
  525. return backarr(0, '无数据');
  526. }
  527. $list = $m_u->getList($where, '*', $page, $size, 'id desc');
  528. $data = [
  529. 'list' => $list,
  530. 'count' => $count,
  531. ];
  532. return backarr(1, "查询成功", $data);
  533. }
  534. /**
  535. * 改用户状态
  536. * 20211118
  537. * wj
  538. */
  539. public function updateuserisright($arr)
  540. {
  541. if (
  542. !isset($arr['isright']) ||
  543. !isset($arr['userid']) || empty($arr['userid'])
  544. ) {
  545. return backarr(0, "请求错误");
  546. }
  547. $id = $arr['userid'];
  548. $where = ['id' => $id];
  549. $info = $this->userinfomodel->getInfo($where);
  550. if (empty($info)) {
  551. return backarr(0, "无会员数据");
  552. }
  553. if (empty($arr['isright'])) {
  554. $arr['isright'] = 0;
  555. } else {
  556. $arr['isright'] = 1;
  557. }
  558. $isright = $arr['isright'];
  559. if ($info['isright'] === $isright) {
  560. return backarr(0, "无修改数据");
  561. }
  562. $updateData = [
  563. 'isright' => $isright,
  564. ];
  565. $row = $this->userinfomodel->updateinfo($where, $updateData);
  566. if ($row <= 0) {
  567. return backarr(0, "操作失败");
  568. }
  569. return backarr(1, "操作成功", ['id' => $id]);
  570. }
  571. /***
  572. * 配置用户labid 根据uid
  573. * 20211124
  574. * wj
  575. */
  576. public function setlabidbyuid($arr)
  577. {
  578. if (!isset($arr['uid']) || empty($arr['uid'])) {
  579. return backarr(0, "请求错误");
  580. }
  581. $uid = $arr['uid'];
  582. $userinfo = $this->getinfobyid($uid);
  583. if (empty($userinfo)) {
  584. return backarr(0, "无用户信息");
  585. }
  586. $sfzid = $userinfo['sfzid'];
  587. if (empty($sfzid)) {
  588. return backarr(0, "无用户身份证号");
  589. }
  590. $m_wi = new workerinfomodel();
  591. $wiWhere = ['sfzid' => $sfzid];
  592. $wiinfo = $m_wi->getinfo($wiWhere);
  593. if (empty($wiinfo)) {
  594. $insertData = [];
  595. //工会新建信息 未缴费 value userinfo字段 key workerinfo字段
  596. $insertFiledArr = [
  597. 'sfzid' => 'sfzid',
  598. 'wname' => 'wname',
  599. 'gender' => 'gender',
  600. 'wage' => 'wage',
  601. 'nation' => 'nation',
  602. 'telno' => 'telno',
  603. 'signurl' => 'signurl',
  604. 'frontsfzurl' => 'frontsfzurl',
  605. 'backsfzurl' => 'backsfzurl',
  606. 'city' => 'city',
  607. 'disc' => 'disc',
  608. 'address' => 'address',
  609. ];
  610. foreach ($insertFiledArr as $key => $value) {
  611. if (isset($userinfo[$value]) && !empty($userinfo[$value])) {
  612. $insertData[$key] = $userinfo[$value];
  613. }
  614. }
  615. $insertData['ispass'] = 1;
  616. $insertData['isactive'] = 0;
  617. $labid = $m_wi->insinfo($insertData);
  618. if (empty($labid)) {
  619. return backarr(0, "工会用户添加失败");
  620. }
  621. } else {
  622. $labid = $wiinfo['id'];
  623. }
  624. if (empty($labid)) {
  625. return backarr(0, "无工会用户id");
  626. }
  627. $updateData = [];
  628. if (empty($userinfo['labid'])) {
  629. $updateData['labid'] = $labid;
  630. } else {
  631. if ($labid != $userinfo['labid']) {
  632. $updateData['labid'] = $labid;
  633. }
  634. }
  635. if (empty($updateData)) {
  636. return backarr(1, "操作成功", ['labid' => $uid]);
  637. }
  638. $m_u = new userinfomodel();
  639. $uwhere = ['id' => $uid];
  640. $row = $m_u->updateinfo($uwhere, $updateData);
  641. if (empty($row)) {
  642. return backarr(0, "操作失败");
  643. }
  644. return backarr(1, "操作成功", ['labid' => $labid]);
  645. }
  646. /*
  647. * 20220111
  648. * steelxu5
  649. * 根据uid获得qrcode
  650. */
  651. public function getqrcodebyuid($arr){
  652. if (!isset($arr['userid']) || empty($arr['userid'])) {
  653. return backarr(0, "请求错误");
  654. }
  655. $uid=$arr['userid'];
  656. $t_u=new userinfomodel();
  657. $qrcode=$t_u->selqrcodebyuid($uid);
  658. if($qrcode['qrcode']){
  659. return backarr(1, "请求成功", $qrcode['qrcode']);
  660. }else{
  661. $l_w = new wxlogic();
  662. $filename = $uid . '_' . time();
  663. $qrcode = [
  664. 'scene' => 'userid=' . $uid,
  665. 'page' => 'src/views/subtelno/subtelno',
  666. ];
  667. $qrresult = $l_w->getqrcode($qrcode, $filename);
  668. if (1 != $qrresult['status']) {
  669. throw new \Exception($qrresult['msg']);
  670. }
  671. $qrcode = $qrresult['data']['qrcode'];
  672. $updatedata = [
  673. 'qrcode' => $qrcode,
  674. ];
  675. $updaterow = $this->updateinfobyid($uid, $updatedata);
  676. if (1 != $updaterow) {
  677. throw new \Exception("小程序二维码保存错误");
  678. }
  679. return backarr(1, "请求成功", $qrcode);
  680. }
  681. }
  682. /**
  683. * 改用户可用状态
  684. * 20220111
  685. * wj
  686. */
  687. public function updateuserisactive($arr)
  688. {
  689. if (
  690. !isset($arr['isactive']) ||
  691. !isset($arr['userid']) || empty($arr['userid'])
  692. ) {
  693. return backarr(0, "请求错误");
  694. }
  695. $id = $arr['userid'];
  696. $where = ['id' => $id];
  697. $info = $this->userinfomodel->getInfo($where);
  698. if (empty($info)) {
  699. return backarr(0, "无会员数据");
  700. }
  701. if (empty($arr['isactive'])) {
  702. $arr['isactive'] = 0;
  703. } else {
  704. $arr['isactive'] = 1;
  705. }
  706. $isactive = $arr['isactive'];
  707. if ($info['isactive'] === $isactive) {
  708. return backarr(0, "无修改数据");
  709. }
  710. $updateData = [
  711. 'isactive' => $isactive,
  712. ];
  713. $row = $this->userinfomodel->updateinfo($where, $updateData);
  714. if ($row <= 0) {
  715. return backarr(0, "操作失败");
  716. }
  717. $m_l = new logmodel();
  718. $loginfo['create_date'] = date('Y-m-d H:i:s', time());
  719. $loginfo['json'] = json_encode(['userid' => $id, 'msg' => '用户注销'], 320);
  720. $L_id = $m_l->savelog($loginfo);
  721. return backarr(1, "操作成功", ['id' => $id]);
  722. }
  723. }