MemberController.php 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  1. <?php
  2. /**
  3. * 会员中心模块
  4. * @author wesmiler
  5. */
  6. namespace app\api\controller;
  7. use app\weixin\model\Advice;
  8. use app\weixin\model\Complain;
  9. use app\weixin\service\FaceAuth;
  10. use app\weixin\service\IdnAuth;
  11. use function AlibabaCloud\Client\value;
  12. use app\weixin\model\AccountLog;
  13. use app\weixin\model\Meals;
  14. use app\weixin\model\Member;
  15. use app\weixin\model\Storage;
  16. use app\weixin\model\UserCollect;
  17. use app\weixin\model\UserContactLog;
  18. use app\weixin\model\UserLog;
  19. use app\weixin\model\UserProfile;
  20. use app\weixin\model\Wechat;
  21. use app\weixin\service\PRedis;
  22. use app\weixin\service\Sms;
  23. use app\weixin\service\Activity;
  24. use app\weixin\validate\MemberValidate;
  25. use think\Db;
  26. class MemberController extends BaseController
  27. {
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. $userStatus = isset($this->userInfo['user_status']) ? intval($this->userInfo['user_status']) : 0;
  32. $freezingChoose = isset($this->userInfo['freezing_choose']) ? intval($this->userInfo['freezing_choose']) : 0;
  33. if ($this->userInfo && $userStatus != 1) {
  34. if ($userStatus == -1) {
  35. showJson(1006, 1016, ['url' => 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg3ODEzNjMzMQ==&scene=124#wechat_redirect']);
  36. }
  37. $uncheck = input('uncheck', 0);
  38. $action = request()->action();
  39. if (!in_array($action, ['getRecommendList']) && (($action == 'getInfo' || $action == 'getHomeInfo') && !$uncheck)) {
  40. showJson(1006, $freezingChoose > 0 ? 1020 + $freezingChoose : 1011, ['url' => url('/weixin/page/custom', '', '', true)]);
  41. }
  42. }
  43. }
  44. /**
  45. * 获取有用户信息
  46. */
  47. public function getInfo()
  48. {
  49. $type = input('type', 0);
  50. $id = input('id', 0); // 当前浏览的用户ID
  51. $userId = $this->userId;
  52. $memberInfo = Member::getInfo(['id' => $userId]);
  53. if ($type == 1) {
  54. Member::visitCount($this->userId, 'center');
  55. } else if ($type == 8) {
  56. Member::visitCount($this->userId, 'home');
  57. }
  58. // 冻结
  59. $userStatus = isset($memberInfo['user_status']) ? intval($memberInfo['user_status']) : 0;
  60. if ((!in_array($type, [1, 8])) && $userStatus != 1 && $type != 1) {
  61. showJson(1006, 2102, ['url' => url('/weixin/page/custom', '', '', true)]);
  62. }
  63. // VIP有效状态和时间
  64. $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0;
  65. $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0;
  66. if ($vipAuth && $vipExpire >= time()) {
  67. $memberInfo['vip_auth'] = 1;
  68. $memberInfo['vip_expire'] = date('Y-m-d', $vipExpire);
  69. if ($vipExpire <= time() + 86400 * 2) {
  70. $memberInfo['vip_expire_near'] = 1;
  71. }
  72. } else {
  73. $memberInfo['vip_auth'] = 0;
  74. $memberInfo['vip_expire'] = '';
  75. $memberInfo['vip_expire_near'] = 0;
  76. }
  77. if ($memberInfo) {
  78. $memberInfo['avatar'] = $memberInfo['avatar'] ? cmf_get_image_preview_url($memberInfo['avatar']) : '';
  79. if (isset($memberInfo['mobile'])) {
  80. $memberInfo['mobile'] = $memberInfo['mobile'] ? formatStr($memberInfo['mobile']) : '';
  81. }
  82. if ($type == 1) {
  83. $memberInfo['collectCount'] = UserCollect::getUserCount($userId, $memberInfo['vip_auth']);
  84. $memberInfo['rechargeCount'] = Member::getRechargeCount($userId);
  85. $memberInfo['messageCount'] = Member::getMessageTotal($userId, ['type' => 1, 'status' => 2]);
  86. $memberInfo['accessCount'] = Member::getAccessCount($userId);
  87. }
  88. if ($type == 2) {
  89. $qrcodeData = Wechat::makeQrcode($userId, $userId);
  90. $memberInfo['qrcode'] = isset($qrcodeData['qrcode']) ? $qrcodeData['qrcode'] : '';
  91. $memberInfo['invite_count'] = Member::getInviteCount($userId);
  92. $memberInfo['profile_complete'] = UserProfile::checkUserProfile($userId) ? 1 : 0;
  93. // $memberInfo['avatar'] = Wechat::loadImage($memberInfo['avatar'],'avatar');
  94. }
  95. if ($type == 3) {
  96. $accountConfig = $siteInfo = cmf_get_option('account_config');
  97. $chargeRate = isset($accountConfig['charge_rate']) ? floatval($accountConfig['charge_rate']) : 0;
  98. $minRecharge = isset($accountConfig['min_recharge']) ? intval($accountConfig['min_recharge']) : 1;
  99. $memberInfo['charge_rate'] = $chargeRate > 0 ? $chargeRate : 1;
  100. $memberInfo['min_recharge'] = $minRecharge ? $minRecharge : 1;
  101. }
  102. // 是否已经认证
  103. if ($type == 2 || $type == 4 || $type == 1) {
  104. $field = 'idcard_check,education_check,position_check';
  105. $authData = UserProfile::where(['userid' => $userId])
  106. ->field($field)
  107. ->find();
  108. $memberInfo['is_auth'] = 0;
  109. $memberInfo['idcard_check'] = isset($authData['idcard_check']) ? intval($authData['idcard_check']) : 0;
  110. $memberInfo['education_check'] = isset($authData['education_check']) ? intval($authData['education_check']) : 0;
  111. $memberInfo['position_check'] = isset($authData['position_check']) ? intval($authData['position_check']) : 0;
  112. if ($memberInfo['idcard_check'] == 2 && $memberInfo['education_check'] == 2 && $memberInfo['position_check'] == 2) {
  113. $memberInfo['is_auth'] = 1;
  114. }
  115. }
  116. // 认证数据
  117. if ($type == 5) {
  118. $field = 'idcard,front_idcard,back_idcard,idcard_fail,idcard_check';
  119. $authData = UserProfile::where(['userid' => $userId])
  120. ->field($field)
  121. ->find();
  122. $authData = $authData ? $authData : [];
  123. $authData['realname'] = isset($memberInfo['real_name']) ? trim($memberInfo['real_name']) : '';
  124. $authData['front_idcard_preview'] = isset($authData['front_idcard']) ? cmf_get_image_preview_url($authData['front_idcard']) : '';
  125. $authData['back_idcard_preview'] = isset($authData['back_idcard']) ? cmf_get_image_preview_url($authData['back_idcard']) : '';
  126. $authData['idcard_check'] = isset($authData['idcard_check']) ? $authData['idcard_check'] : 0;
  127. $memberInfo['authInfo'] = $authData;
  128. }
  129. if ($type == 6) {
  130. $field = 'graduate,education,education_img,education_fail,education_check,education_code,education_type';
  131. $authData = UserProfile::where(['userid' => $userId])
  132. ->field($field)
  133. ->find();
  134. $authData['education_img_preview'] = isset($authData['education_img']) ? cmf_get_image_preview_url($authData['education_img']) : '';
  135. $authData['education_check'] = isset($authData['education_check']) ? $authData['education_check'] : 0;
  136. $memberInfo['authInfo'] = $authData ? $authData : [];
  137. }
  138. if ($type == 7) {
  139. $field = 'company,occupation,position_img,position_fail,position_check,position_type,position_hide';
  140. $authData = UserProfile::where(['userid' => $userId])
  141. ->field($field)
  142. ->find();
  143. $authData['position_img_preview'] = isset($authData['position_img']) ? cmf_get_image_preview_url($authData['position_img']) : '';
  144. $authData['position_check'] = isset($authData['position_check']) ? $authData['position_check'] : 0;
  145. $memberInfo['authInfo'] = $authData ? $authData : [];
  146. }
  147. // 验证是否已经收藏过
  148. $memberInfo['is_collect'] = 0;
  149. if ($id && UserCollect::checkCollect($userId, $id)) {
  150. $memberInfo['is_collect'] = 1;
  151. }
  152. // 收藏剩余有效时间
  153. if (isset($memberInfo['collect_expire'])) {
  154. $memberInfo['collect_expire'] = intval($memberInfo['collect_expire']) - time();
  155. $memberInfo['collect_expire'] = $memberInfo['collect_expire'] > 0 ? $memberInfo['collect_expire'] : 0;
  156. }
  157. if ($type == 8) {
  158. $accountConfig = cmf_get_option('account_config');
  159. $contactPay = isset($accountConfig['contact_pay']) ? intval($accountConfig['contact_pay']) : 0;
  160. $contactPay = $contactPay ? $contactPay : 1;
  161. $memberInfo['contact_pay'] = $contactPay;
  162. $contactRefundPay = isset($accountConfig['apply_refund_pay']) ? intval($accountConfig['apply_refund_pay']) : 0;
  163. $contactRefundPay = $contactRefundPay ? $contactRefundPay : 3;
  164. $memberInfo['contact_refund_pay'] = $contactRefundPay;
  165. $siteConfig = cmf_get_option('site_info');
  166. $contactTime = isset($siteConfig['contact_time']) ? intval($siteConfig['contact_time']) : 1;
  167. $contactTime = $contactTime ? $contactTime * 24 : 24;
  168. $memberInfo['contact_time'] = $contactTime;
  169. }
  170. if($type == 9){
  171. $accountConfig = cmf_get_option('account_config');
  172. $pay = isset($accountConfig['lock_access_pay']) ? intval($accountConfig['lock_access_pay']) : 0;
  173. $pay = $pay ? $pay : 1;
  174. $memberInfo['lock_access_pay'] = $pay;
  175. }
  176. }
  177. showJson(1005, 1001, $memberInfo);
  178. }
  179. /**
  180. * 完善资料
  181. * @throws \think\Exception
  182. * @throws \think\exception\PDOException
  183. */
  184. public function setProfile()
  185. {
  186. try {
  187. $params = input();
  188. $userId = input('uid', 0);
  189. $validate = new MemberValidate();
  190. if (!$validate->scene('reg')->check($params)) {
  191. showJson(1004, $validate->getError());
  192. }
  193. $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  194. $code = isset($params['code']) ? trim($params['code']) : '';
  195. $result = Sms::checkCode($mobile, $code);
  196. if (!$userId && $result !== true) {
  197. showJson(1004, $result);
  198. }
  199. if ($this->userId <= 1) {
  200. showJson(1004, 2009);
  201. }
  202. $sex = isset($params['sex']) ? intval($params['sex']) : 0;
  203. if (!in_array($sex, [1, 2])) {
  204. showJson(1004, 2023);
  205. }
  206. // 头像
  207. $avatar = '';
  208. $wxInfo = session('wxInfo');
  209. $file = request()->file('image');
  210. if ($file) {
  211. $fileData = Storage::uploadImg($file, 'avatar');
  212. $avatar = isset($fileData['file']) ? $fileData['file'] : '';
  213. }
  214. if (empty($avatar)) {
  215. showJson(1004, 3004);
  216. }
  217. $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : '';
  218. $nowAddress = $nowAddress ? explode(' ', $nowAddress) : [];
  219. $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : '';
  220. $homeAddress = $homeAddress ? explode(' ', $homeAddress) : [];
  221. $birthday = isset($params['birthday']) ? strtotime(trim($params['birthday'])) : 0;
  222. $year = $birthday ? date('Y', $birthday) : 0;
  223. $age = $year ? date('Y', time()) - $year : 0;
  224. $profileData = [
  225. 'userid' => $this->userId,
  226. 'height' => isset($params['height']) ? floatval($params['height']) : 0,
  227. 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0,
  228. 'age' => $age,
  229. 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '',
  230. 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '',
  231. 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '',
  232. 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '',
  233. 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '',
  234. 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '',
  235. 'married' => isset($params['married']) ? intval($params['married']) : 0,
  236. 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '',
  237. ];
  238. Db::startTrans();
  239. if (UserProfile::checkProfile($this->userId)) {
  240. $profileData['updated_at'] = date('Y-m-d H:i:s');
  241. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  242. } else {
  243. $res = UserProfile::insertGetId($profileData);
  244. }
  245. if (!$res) {
  246. Db::rollback();
  247. showJson(1004, 2104);
  248. }
  249. $memberData = [
  250. 'real_name' => isset($params['realname']) ? trim($params['realname']) : '',
  251. 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '',
  252. 'mobile' => $mobile,
  253. 'birthday' => $birthday,
  254. 'sex' => $sex,
  255. 'is_reg_profile' => 1,
  256. ];
  257. if ($avatar) {
  258. $memberData['avatar'] = $avatar;
  259. }
  260. //PRedis::set('members:reg:info:' . $this->userId, $memberData, 3600);
  261. if (!Member::saveData(['id' => $this->userId], $memberData)) {
  262. Db::rollback();
  263. showJson(1004, 2104);
  264. }
  265. // 操作日志
  266. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '完善信息注册']);
  267. Db::commit();
  268. // 更新缓存
  269. $userInfo = Member::getInfo(['id' => $this->userId]);
  270. session('userInfo', $userInfo);
  271. showJson(1005, 1008);
  272. } catch (\Exception $exception) {
  273. PRedis::set('members:reg:error:' . $this->userId, $exception, 6 * 3600);
  274. showJson(1004, 2136);
  275. }
  276. }
  277. /**
  278. * 完善资料
  279. * @throws \think\Exception
  280. * @throws \think\exception\PDOException
  281. */
  282. public function setProfileTest()
  283. {
  284. try {
  285. $params = input();
  286. $userId = input('uid', 0);
  287. $validate = new MemberValidate();
  288. PRedis::set('members:reg:params:' . $this->userId, ['info' => $this->userInfo, 'params' => $params], 3600);
  289. if (!$validate->scene('reg')->check($params)) {
  290. showJson(1004, $validate->getError());
  291. }
  292. $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  293. $code = isset($params['code']) ? trim($params['code']) : '';
  294. $result = Sms::checkCode($mobile, $code);
  295. if (!$userId && $result !== true) {
  296. //showJson(1004, $result);
  297. }
  298. if (empty($this->userId)) {
  299. showJson(1004, 2009);
  300. }
  301. $sex = isset($params['sex']) ? intval($params['sex']) : 0;
  302. if (!in_array($sex, [1, 2])) {
  303. showJson(1004, 2023);
  304. }
  305. // 头像
  306. $avatar = '';
  307. $wxInfo = session('wxInfo');
  308. $file = request()->file('image');
  309. if ($file) {
  310. $fileData = Storage::uploadImg($file, 'avatar', false, false);
  311. if (!is_array($fileData)) {
  312. showJson(1004, $fileData ? $fileData : 3004);
  313. }
  314. $avatar = isset($fileData['file']) ? $fileData['file'] : '';
  315. }
  316. if (empty($avatar)) {
  317. showJson(1004, 3004);
  318. }
  319. PRedis::set('members:reg:params2:' . $this->userId, $params, 3600);
  320. $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : '';
  321. $nowAddress = $nowAddress ? explode(' ', $nowAddress) : [];
  322. $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : '';
  323. $homeAddress = $homeAddress ? explode(' ', $homeAddress) : [];
  324. $birthday = isset($params['birthday']) ? strtotime(trim($params['birthday'])) : 0;
  325. $year = $birthday ? date('Y', $birthday) : 0;
  326. $age = $year ? date('Y', time()) - $year : 0;
  327. $profileData = [
  328. 'userid' => $this->userId,
  329. 'height' => isset($params['height']) ? floatval($params['height']) : 0,
  330. 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0,
  331. 'age' => $age,
  332. 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '',
  333. 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '',
  334. 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '',
  335. 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '',
  336. 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '',
  337. 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '',
  338. 'married' => isset($params['married']) ? intval($params['married']) : 0,
  339. 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '',
  340. ];
  341. PRedis::set('members:reg:params3:' . $this->userId, $params, 3600);
  342. Db::startTrans();
  343. PRedis::set('members:reg:profile:' . $this->userId, $profileData, 3600);
  344. if (UserProfile::checkProfile($this->userId)) {
  345. $profileData['updated_at'] = date('Y-m-d H:i:s');
  346. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  347. } else {
  348. $res = UserProfile::insertGetId($profileData);
  349. }
  350. if (!$res) {
  351. Db::rollback();
  352. showJson(1004, 2104);
  353. }
  354. $memberData = [
  355. 'real_name' => isset($params['realname']) ? trim($params['realname']) : '',
  356. 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '',
  357. 'mobile' => $mobile,
  358. 'birthday' => $birthday,
  359. 'sex' => $sex,
  360. 'is_reg_profile' => 1,
  361. ];
  362. if ($avatar) {
  363. $memberData['avatar'] = $avatar;
  364. }
  365. PRedis::set('members:reg:info:' . $this->userId, $memberData, 3600);
  366. if (!Member::saveData(['id' => $this->userId], $memberData)) {
  367. Db::rollback();
  368. showJson(1004, 2104);
  369. }
  370. showJson(1005, 1008);
  371. exit;
  372. // 操作日志
  373. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '完善信息注册']);
  374. Db::commit();
  375. // 更新缓存
  376. $userInfo = Member::getInfo(['id' => $this->userId]);
  377. session('userInfo', $userInfo);
  378. showJson(1005, 1008);
  379. } catch (\Exception $exception) {
  380. PRedis::set('members:reg:error:' . $this->userId, $exception, 6 * 3600);
  381. showJson(1004, 2136);
  382. }
  383. }
  384. /**
  385. * 保存资料
  386. */
  387. public function saveInfo()
  388. {
  389. $params = input();
  390. $validate = new MemberValidate();
  391. if (!$validate->scene('info')->check($params)) {
  392. showJson(1004, $validate->getError());
  393. }
  394. $newMobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  395. $mobile = isset($this->userInfo['mobile']) ? $this->userInfo['mobile'] : '';
  396. if ($newMobile && $newMobile != $mobile) {
  397. $code = isset($params['code']) ? trim($params['code']) : '';
  398. $result = Sms::checkCode($newMobile, $code);
  399. if ($result !== true) {
  400. showJson(1004, $result);
  401. }
  402. // 验证手机号码是否被使用
  403. $id = Member::where(['mobile' => $newMobile])->value('id');
  404. if ($id && $id != $this->userId) {
  405. showJson(1004, 2001);
  406. }
  407. }
  408. $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : '';
  409. $nowAddress = $nowAddress ? explode(' ', $nowAddress) : [];
  410. $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : '';
  411. $homeAddress = $homeAddress ? explode(' ', $homeAddress) : [];
  412. $birthday = isset($params['birthday']) ? strtotime($params['birthday']) : 0;
  413. $year = $birthday ? date('Y', $birthday) : 0;
  414. $age = $year ? date('Y', time()) - $year : 0;
  415. $info = [
  416. 'userid' => $this->userId,
  417. 'age' => $age,
  418. 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0,
  419. 'height' => isset($params['height']) ? floatval($params['height']) : 0,
  420. 'salary' => isset($params['salary']) ? intval($params['salary']) : 0,
  421. 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '',
  422. 'education' => isset($params['education']) ? intval($params['education']) : 0,
  423. 'company' => isset($params['company']) ? trim($params['company']) : '',
  424. 'occupation' => isset($params['occupation']) ? trim($params['occupation']) : '',
  425. 'property' => isset($params['property']) ? intval($params['property']) : 0,
  426. 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '',
  427. 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '',
  428. 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '',
  429. 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '',
  430. 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '',
  431. 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '',
  432. 'married' => isset($params['married']) ? intval($params['married']) : 0,
  433. 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '',
  434. 'qq' => isset($params['qq']) ? trim($params['qq']) : '',
  435. ];
  436. Db::startTrans();
  437. if (UserProfile::checkProfile($this->userId)) {
  438. $profileData['updated_at'] = date('Y-m-d H:i:s');
  439. $res = UserProfile::saveData(['userid' => $this->userId], $info);
  440. } else {
  441. $res = UserProfile::insertGetId($info);
  442. }
  443. if (!$res) {
  444. Db::rollback();
  445. showJson(1004, 2104);
  446. }
  447. $memberData = [
  448. 'real_name' => isset($params['realname']) ? trim($params['realname']) : '',
  449. 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '',
  450. 'birthday' => $birthday,
  451. 'sex' => isset($params['sex']) ? intval($params['sex']) : 0,
  452. ];
  453. if ($newMobile && $mobile != $newMobile) {
  454. $memberData['mobile'] = $newMobile;
  455. }
  456. if (!Member::saveData(['id' => $this->userId], $memberData)) {
  457. Db::rollback();
  458. showJson(1004, 2104);
  459. }
  460. Db::commit();
  461. showJson(1005, 2029);
  462. }
  463. /**
  464. * 获取资料
  465. * @throws \think\db\exception\DataNotFoundException
  466. * @throws \think\db\exception\ModelNotFoundException
  467. * @throws \think\exception\DbException
  468. */
  469. public function getProfile()
  470. {
  471. $info = [];
  472. $type = input('type', 1);
  473. switch ($type) {
  474. case 1:
  475. $photolistArr = [];
  476. $photolist = UserProfile::where(['userid' => $this->userId])->value('photolist');
  477. $photolists = $photolist ? explode(',', $photolist) : [];
  478. $info['photolist'] = $photolist ? $photolist : '';
  479. foreach ($photolists as $k => $val) {
  480. $photolistArr[$k]['file'] = $val;
  481. $photolistArr[$k]['preview'] = $val ? cmf_get_image_preview_url($val) : '';
  482. }
  483. $info['photolists'] = $photolistArr;
  484. break;
  485. default:
  486. $field = 'userid,introduce,introduce_img,brief,brief,family,family_img,hobby,hobby_img,purpose,purpose_img,cause,cause_img,expect,tags,expect_img';
  487. $info = UserProfile::where(['userid' => $this->userId])->field($field)->find();
  488. $info = $info ? $info->toArray() : [];
  489. if (isset($info['introduce_img'])) {
  490. $info['introduce_img_preview'] = $info['introduce_img'] ? cmf_get_image_preview_url($info['introduce_img']) : '';
  491. }
  492. if (isset($info['family_img'])) {
  493. $info['family_img_preview'] = $info['family_img'] ? cmf_get_image_preview_url($info['family_img']) : '';
  494. }
  495. if (isset($info['hobby_img'])) {
  496. $info['hobby_img_preview'] = $info['hobby_img'] ? cmf_get_image_preview_url($info['hobby_img']) : '';
  497. }
  498. if (isset($info['purpose_img'])) {
  499. $info['purpose_img_preview'] = $info['purpose_img'] ? cmf_get_image_preview_url($info['purpose_img']) : '';
  500. }
  501. if (isset($info['cause_img'])) {
  502. $info['cause_img_preview'] = $info['cause_img'] ? cmf_get_image_preview_url($info['cause_img']) : '';
  503. }
  504. if (isset($info['expect_img'])) {
  505. $info['expect_img_preview'] = $info['expect_img'] ? cmf_get_image_preview_url($info['expect_img']) : '';
  506. }
  507. if (isset($info['tags'])) {
  508. $info['tags'] = $info['tags'] ? explode(',', $info['tags']) : [];
  509. }
  510. break;
  511. }
  512. showJson(1005, 1008, $info);
  513. }
  514. /*
  515. * 头像
  516. *
  517. */
  518. public function setAvatar()
  519. {
  520. $avatar = '';
  521. $file = request()->file('image');
  522. if ($file) {
  523. $fileData = Storage::uploadImg($file, 'avatar');
  524. $avatar = isset($fileData['file']) ? $fileData['file'] : '';
  525. }
  526. if (empty($avatar)) {
  527. showJson(1004, 3007);
  528. }
  529. // 保存
  530. $oldAvatar = Member::where(['id' => $this->userId])->value('avatar');
  531. if (!Member::saveData(['id' => $this->userId], ['avatar' => $avatar])) {
  532. showJson(1004, 2030);
  533. }
  534. if (file_exists('upload/' . $oldAvatar)) {
  535. @unlink('upload/' . $oldAvatar);
  536. $paths = explode('_', basename($oldAvatar));
  537. $filename = end($paths);
  538. $filename = 'upload/' . dirname($oldAvatar) . '/' . $filename;
  539. if ($filename && file_exists($filename)) {
  540. @unlink($filename);
  541. }
  542. }
  543. showJson(1005, 2029);
  544. }
  545. /**
  546. * 保存资料
  547. */
  548. public function saveProfile()
  549. {
  550. $info = [];
  551. $img = input('img', '');
  552. $params = input();
  553. // 需要先完成身份认证
  554. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  555. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  556. }
  557. // 学历证明照片
  558. $file = request()->file('image');
  559. if ($file) {
  560. $fileData = Storage::uploadImg($file, 'profile');
  561. $img = isset($fileData['file']) ? $fileData['file'] : '';
  562. $oldImg = isset($params['img']) ? $params['img'] : '';
  563. if ($img && $oldImg) {
  564. @unlink('upload/' . $oldImg);
  565. }
  566. }
  567. if (isset($params['photolist'])) {
  568. $info['photolist'] = trim($params['photolist']);
  569. }
  570. if (isset($params['introduce'])) {
  571. $info['introduce'] = trim($params['introduce']);
  572. $info['introduce_img'] = $img;
  573. }
  574. if (isset($params['family'])) {
  575. $info['family'] = trim($params['family']);
  576. $info['family_img'] = $img;
  577. }
  578. if (isset($params['hobby'])) {
  579. $info['hobby'] = trim($params['hobby']);
  580. $info['hobby_img'] = $img;
  581. }
  582. if (isset($params['purpose'])) {
  583. $info['purpose'] = trim($params['purpose']);
  584. $info['purpose_img'] = $img;
  585. }
  586. if (isset($params['cause'])) {
  587. $info['cause'] = trim($params['cause']);
  588. $info['cause_img'] = $img;
  589. }
  590. if (isset($params['expect'])) {
  591. $info['expect'] = trim($params['expect']);
  592. $info['expect_img'] = $img;
  593. }
  594. // 标签
  595. if (isset($params['tags'])) {
  596. $info['tags'] = trim($params['tags']);
  597. }
  598. if (!UserProfile::saveData(['userid' => $this->userId], $info)) {
  599. showJson(1004, 2030);
  600. }
  601. // 奖励
  602. UserProfile::profileAward($this->userId);
  603. showJson(1005, 2029);
  604. }
  605. /**
  606. * 获取主页信息
  607. */
  608. public function getHomeInfo()
  609. {
  610. $id = input('id', 0);
  611. $cid = input('cid', 0);
  612. $type = input('type', 1);
  613. // 基础信息
  614. $userId = $id ? $id : $this->userId;
  615. $myInfo = Member::getHomeInfo($userId, '', $type);
  616. // 访问记录
  617. if($myInfo && $type == 4){
  618. Member::makeUserAccess($userId, $this->userId);
  619. }
  620. $cUserInfo = [];
  621. $cInfo = [];
  622. if ($cid <= 0 && $id) {
  623. $cid = UserContactLog::where(['user_id' => $this->userId, 'contact_uid' => $id])
  624. ->where('status', 'in', [1, 2, 3])
  625. ->value('id');
  626. if ($cid <= 0) {
  627. $cid = UserContactLog::where(['contact_uid' => $this->userId, 'user_id' => $id])
  628. ->where('status', 'in', [1, 2, 3])
  629. ->value('id');
  630. }
  631. }
  632. if ($cid > 0) {
  633. // 认识记录
  634. $cInfo = UserContactLog::where(['id' => $cid])->where('status', 'in', [1, 2, 3])->field('id,user_id,contact_uid,is_read,status')->find();
  635. $cUid = isset($cInfo['contact_uid']) ? intval($cInfo['contact_uid']) : 0;
  636. $status = isset($cInfo['status']) ? intval($cInfo['status']) : 0;
  637. if ($cUid) {
  638. // 被申请方查看,更新申请微信阅读状态
  639. if ($cUid == $this->userId) {
  640. UserContactLog::where(['id' => $cid])->update(['is_read' => 1]);
  641. }
  642. // 想认识的人的信息
  643. $field = 'm.id,m.user_nickname,m.avatar,m.real_name,up.wechat_code,up.qq';
  644. $cUserInfo = Member::getHomeInfo($cUid, $field, 2);
  645. // 未确认认识的不展示联系方式
  646. if ($status != 2 && $cUserInfo) {
  647. $cUserInfo['wechat_code'] = '';
  648. $cUserInfo['qq'] = '';
  649. }
  650. }
  651. }
  652. //PRedis::set('test:' . $userId, ['homeInfo' => $myInfo, 'cUserInfo' => $cUserInfo, 'cInfo' => $cInfo], 600);
  653. showJson(1005, 1008, ['homeInfo' => $myInfo, 'cUserInfo' => $cUserInfo, 'cInfo' => $cInfo]);
  654. }
  655. /**
  656. * 单身推荐列表
  657. */
  658. public function getRecommendList()
  659. {
  660. $params = input();
  661. $pageSize = input('pageSize', 12);
  662. $type = input('type', 1);
  663. $uid = input('uid', 0);
  664. $refresh = input('refresh', false);
  665. $userId = $uid ? $uid : $this->userId;
  666. if ($type == 1) {
  667. $params['user_id'] = $userId;
  668. $dataList = Member::getRecommendList($params, $pageSize);
  669. Member::visitCount($userId, 'match');
  670. } else {
  671. $dataList = Member::getHeartList($userId, '', $refresh);
  672. Member::visitCount($userId, 'heart');
  673. }
  674. showJson(1005, 1001, $dataList);
  675. }
  676. /**
  677. * 设置隐私
  678. */
  679. public function setPrivacy()
  680. {
  681. $type = input('type', 1);
  682. $value = input('value', 0);
  683. $reset = input('reset', 0);
  684. if (!in_array($type, [1, 2, 3])) {
  685. showJson(1004, 2129);
  686. }
  687. $types = [1 => 'show_graduate', 2 => 'show_company'];
  688. if ($type == 3) {
  689. if ($value == 1) {
  690. if(!UserProfile::checkUserProfile($this->userId)){
  691. showJson(1006,2045, ['url'=> Wechat::makeRedirectUrl(url('/weixin/member/profile','','',true))]);
  692. }
  693. Member::where(['id' => $this->userId, 'user_type' => 2])
  694. ->update(['is_heart' => 1]);
  695. // 操作日志
  696. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => "取消隐身模式"]);
  697. showJson(1005, 2036);
  698. }
  699. $memberInfo = Member::where(['id' => $this->userId, 'user_type' => 2])->field('redheart,is_heart,invisible_time')->find();
  700. $isHeart = isset($memberInfo['is_heart']) ? intval($memberInfo['is_heart']) : 0;
  701. $invisibleTime = isset($memberInfo['invisible_time']) ? intval($memberInfo['invisible_time']) : 0;
  702. if ($reset != 1 && $invisibleTime >= time() - 7 * 24 * 3600) {
  703. showJson(1004, lang('invisible', ['date' => date('Y-m-d', $invisibleTime)]));
  704. }
  705. if ($isHeart == 2 && $value == 0) {
  706. showJson(1004, 2034);
  707. }
  708. // 扣除爱心隐身
  709. Db::startTrans();
  710. if ($reset == 1) {
  711. // 扣除爱心账户
  712. $accountConfig = cmf_get_option('account_config');
  713. $hiddenPay = isset($accountConfig['hidden_pay']) ? intval($accountConfig['hidden_pay']) : 0;
  714. $hiddenPay = $hiddenPay ? $hiddenPay : 10;
  715. $redheart = isset($memberInfo['redheart']) ? intval($memberInfo['redheart']) : 0;
  716. if ($redheart < $hiddenPay) {
  717. showJson(1004, 2137);
  718. }
  719. if (!Member::where(['id' => $this->userId, 'user_type' => 2])->setDec('redheart', $hiddenPay)) {
  720. Db::rollback();
  721. showJson(1004, 2031);
  722. }
  723. // 账户明细
  724. $accountData = [
  725. 'user_id' => $this->userId,
  726. 'type' => 2,
  727. 'account_type' => 1,
  728. 'change_type' => 2,
  729. 'money' => $hiddenPay,
  730. 'balance' => $redheart,
  731. 'remark' => "付费设置隐身模式【{$this->userId}】扣除{$hiddenPay}个爱心",
  732. 'created_at' => date('Y-m-d H:i:s'),
  733. 'status' => 2,
  734. ];
  735. PRedis::set('accounts:privacy:' . $this->userId, $accountData, 600);
  736. if (!AccountLog::insertGetId($accountData)) {
  737. Db::rollback();
  738. return false;
  739. }
  740. }
  741. // 更新设置隐身模式
  742. Member::where(['id' => $this->userId, 'user_type' => 2])
  743. ->update(['is_heart' => 2, 'invisible_time' => time()]);
  744. // 操作日志
  745. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => "设置隐身模式"]);
  746. Db::commit();
  747. showJson(1005, 2035);
  748. } else {
  749. $field = $types[$type];
  750. if (!UserProfile::saveData(['userid' => $this->userId], [$field => $value])) {
  751. showJson(1004, 2131);
  752. }
  753. }
  754. showJson(1005, 2130);
  755. }
  756. /**
  757. * 关注用户
  758. */
  759. public function collect()
  760. {
  761. // 验证
  762. $this->checkUser();
  763. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  764. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  765. }
  766. $id = input('id');
  767. $opType = input('type', 1);
  768. $result = Member::collect($this->userId, $id, $opType);
  769. if ($result === true) {
  770. showJson(1005, $opType == 1 ? 2106 : 2108);
  771. } else {
  772. showJson(1004, $result);
  773. }
  774. }
  775. /**
  776. * 获取关注用户/收藏活动列表
  777. */
  778. public function getCollectList()
  779. {
  780. $params = input();
  781. $pageSize = input('pageSize', 12);
  782. $type = input('type', 1);
  783. $dataList = [];
  784. if ($type == 1) {
  785. $dataList = UserCollect::getUserList($this->userId, $params, $pageSize);
  786. } else if ($type == 2) {
  787. $dataList = UserCollect::getFollowUserList($this->userId, $params, $pageSize);
  788. }
  789. showJson(1005, 1001, $dataList);
  790. }
  791. /**
  792. * 获取申请微信消息列表
  793. */
  794. public function getMessageList()
  795. {
  796. $params = input();
  797. $pageSize = input('pageSize', 12);
  798. $dataList = Member::getMessageList($this->userId, $params, $pageSize);
  799. showJson(1005, 1001, $dataList);
  800. }
  801. /**
  802. * 获取申请微信消息详情
  803. */
  804. public function getMessageInfo()
  805. {
  806. $id = input('id', 0);
  807. $info = Member::getMessageInfo($id, $this->userId);
  808. showJson(1005, 1001, $info);
  809. }
  810. /**
  811. * 认证
  812. */
  813. public function authSubmit()
  814. {
  815. // 验证
  816. $this->checkUser();
  817. $params = input();
  818. $scene = isset($params['scene']) ? trim($params['scene']) : '';
  819. $scene = in_array($scene, ['idcard', 'education', 'position']) ? $scene : 'idcard';
  820. $validate = new MemberValidate();
  821. if (!$validate->scene($scene)->check($params)) {
  822. showJson(1004, $validate->getError());
  823. }
  824. if ($scene != 'idcard' && UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  825. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  826. }
  827. // 处理
  828. switch ($scene) {
  829. case 'idcard': // 身份证认证
  830. $idcard = isset($params['idcard']) ? trim($params['idcard']) : '';
  831. $realname = isset($params['realname'])? trim($params['realname']) : '';
  832. $profileData = [
  833. 'idcard' => $idcard,
  834. 'front_idcard' => isset($params['front_idcard']) ? trim($params['front_idcard']) : '',
  835. 'back_idcard' => isset($params['back_idcard']) ? trim($params['back_idcard']) : '',
  836. 'idcard_check' => 1,
  837. ];
  838. // 验证身份证号是否被使用
  839. $checkId = UserProfile::where(['idcard' => $idcard])
  840. ->where('userid', 'not in', $this->userId)
  841. ->value('id');
  842. if ($checkId) {
  843. showJson(1004, 2128);
  844. }
  845. // 在线验证
  846. $checkData = IdnAuth::check($realname, $idcard);
  847. $code = isset($checkData['code'])? $checkData['code'] : '';
  848. $msg = isset($checkData['msg'])? $checkData['msg'] : '';
  849. if($code != 'success' && (empty($profileData['front_idcard']) || empty($profileData['back_idcard']))){
  850. showJson(1004, $msg? $msg : 2138);
  851. }
  852. // 身份证照片
  853. /*if (empty($profileData['front_idcard'])) {
  854. showJson(1004, 2024);
  855. }
  856. if (empty($profileData['back_idcard'])) {
  857. showJson(1004, 2025);
  858. }*/
  859. Db::startTrans();
  860. if (!Member::saveData(['id' => $this->userId], ['real_name' => $realname])) {
  861. Db::rollback();
  862. showJson(1004, 2026);
  863. }
  864. // 在线验证是否通过
  865. $profileData['idcard_online_check'] = $code == 'success'? 1 : 0;
  866. if (UserProfile::checkProfile($this->userId)) {
  867. $profileData['updated_at'] = date('Y-m-d H:i:s');
  868. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  869. } else {
  870. $res = UserProfile::insertGetId($profileData);
  871. }
  872. if (!$res) {
  873. Db::rollback();
  874. showJson(1004, 2026);
  875. }
  876. // 操作日志
  877. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交身份证认证']);
  878. Db::commit();
  879. showJson(1005, 2027);
  880. break;
  881. case 'education': // 学历认证
  882. $profileData = [
  883. 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '',
  884. 'education' => isset($params['education']) ? trim($params['education']) : '',
  885. 'education_img' => isset($params['education_img']) ? trim($params['education_img']) : '',
  886. 'education_code' => isset($params['education_code']) ? trim($params['education_code']) : '',
  887. 'education_type' => isset($params['education_type']) ? intval($params['education_type']) : 0,
  888. 'education_check' => 1,
  889. ];
  890. $siteInfo = cmf_get_site_info();
  891. $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用';
  892. // 学历证明照片
  893. $file = request()->file('image1');
  894. if ($file) {
  895. $fileData = Storage::uploadImg($file, 'education_img');
  896. $educationImg = isset($fileData['file']) ? $fileData['file'] : '';
  897. $profileData['education_img'] = $waterTxt ? Storage::imageWater($educationImg, $waterTxt) : $educationImg;
  898. }
  899. if (empty($profileData['education_img'])) {
  900. showJson(1004, 2028);
  901. }
  902. Db::startTrans();
  903. if (UserProfile::checkProfile($this->userId)) {
  904. $profileData['updated_at'] = date('Y-m-d H:i:s');
  905. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  906. } else {
  907. $res = UserProfile::insertGetId($profileData);
  908. }
  909. if (!$res) {
  910. Db::rollback();
  911. showJson(1004, 2026);
  912. }
  913. // 操作日志
  914. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交学历认证']);
  915. Db::commit();
  916. showJson(1005, 2027);
  917. break;
  918. case 'position': // 职位认证
  919. $profileData = [
  920. 'company' => isset($params['company']) ? trim($params['company']) : '',
  921. 'occupation' => isset($params['occupation']) ? trim($params['occupation']) : '',
  922. 'position_img' => isset($params['position_img']) ? trim($params['position_img']) : '',
  923. 'position_type' => isset($params['position_type']) ? intval($params['position_type']) : 0,
  924. 'position_hide' => isset($params['position_hide']) ? intval($params['position_hide']) : 0,
  925. 'position_check' => 1,
  926. ];
  927. $siteInfo = cmf_get_site_info();
  928. $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用';
  929. // 职位证明照片
  930. $file = request()->file('image1');
  931. if ($file) {
  932. $fileData = Storage::uploadImg($file, 'position_img', false, false);
  933. $positionImg = isset($fileData['file']) ? $fileData['file'] : '';
  934. $profileData['position_img'] = $waterTxt ? Storage::imageWater($positionImg, $waterTxt) : $positionImg;
  935. }
  936. //PRedis::set('test:auth:' . $this->userId, ['file' => $file, 'data' => $fileData, 'profile' => $profileData], 600);
  937. if (empty($profileData['position_img'])) {
  938. showJson(1004, 2033);
  939. }
  940. Db::startTrans();
  941. if (UserProfile::checkProfile($this->userId)) {
  942. $profileData['updated_at'] = date('Y-m-d H:i:s');
  943. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  944. } else {
  945. $res = UserProfile::insertGetId($profileData);
  946. }
  947. if (!$res) {
  948. Db::rollback();
  949. showJson(1004, 2026);
  950. }
  951. // 操作日志
  952. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交职业认证']);
  953. Db::commit();
  954. showJson(1005, 2027);
  955. break;
  956. }
  957. showJson(1004, 2009);
  958. }
  959. public function authCheck(){
  960. // 验证
  961. $this->checkUser();
  962. $params = input();
  963. $validate = new MemberValidate();
  964. if (!$validate->scene('idcard')->check($params)) {
  965. showJson(1004, $validate->getError());
  966. }
  967. $result = FaceAuth::getToken($this->userId,$params);
  968. $data = isset($result['result'])? $result['result'] : [];
  969. $code = isset($result['code']) && $result['code']? $result['code'] : 'error';
  970. $msg = isset($result['msg']) && $result['msg']? $result['msg'] : '验证错误';
  971. showJson($code, $msg, $data);
  972. }
  973. /**
  974. * 加入怦然心动
  975. */
  976. public function joinHeart()
  977. {
  978. // 验证
  979. $this->checkUser();
  980. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  981. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  982. }
  983. if (!UserProfile::checkUserProfile($this->userId)) {
  984. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  985. }
  986. $isHeart = input('is_heart', 2);
  987. if (!in_array($isHeart, [1, 2])) {
  988. showJson(1004, 2111);
  989. }
  990. $result = Member::where(['id' => $this->userId])
  991. ->update(['updated_at' => date('Y-m-d H:i:s'), 'is_heart' => $isHeart]);
  992. if ($result) {
  993. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => $isHeart == 1 ? '加入怦然心动' : '取消加入怦然心动']);
  994. showJson(1005, $isHeart == 1 ? 5017 : 5019);
  995. } else {
  996. showJson(1004, $isHeart == 1 ? 5018 : 5020);
  997. }
  998. }
  999. /**
  1000. * 设置用户推荐条件
  1001. */
  1002. public function setConditions()
  1003. {
  1004. // 验证
  1005. $this->checkUser();
  1006. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1007. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1008. }
  1009. $params = input();
  1010. PRedis::set('test:conditions:' . $this->userId, $params, 600);
  1011. $res = Member::setMemberConditions($this->userId, $params);
  1012. if ($res) {
  1013. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => '设置推荐条件']);
  1014. showJson(1005, 1008);
  1015. } else {
  1016. showJson(1004, 1009);
  1017. }
  1018. }
  1019. /**
  1020. * 获取推荐条件
  1021. */
  1022. public function getConditions()
  1023. {
  1024. $conditions = Member::getMemberConditions($this->userId);
  1025. showJson(1005, 1008, $conditions);
  1026. }
  1027. /**
  1028. * 获取我的活动列表
  1029. */
  1030. public function getActivityList()
  1031. {
  1032. $params = input();
  1033. $pageSize = input('pageSize', 12);
  1034. $params['user_id'] = $this->userId;
  1035. $dataList = Activity::getMemberActivityList($params, $pageSize);
  1036. showJson(1005, 1001, $dataList);
  1037. }
  1038. /**
  1039. * 爱心充值
  1040. * @throws \think\db\exception\DataNotFoundException
  1041. * @throws \think\db\exception\ModelNotFoundException
  1042. * @throws \think\exception\DbException
  1043. */
  1044. public function doRecharge()
  1045. {
  1046. // 验证
  1047. $this->checkUser();
  1048. $money = input('money', 0);
  1049. $num = input('num', 0);
  1050. if (empty($money) || empty($num)) {
  1051. showJson(1004, 4001);
  1052. }
  1053. $accountConfig = $siteInfo = cmf_get_option('account_config');
  1054. $chargeRate = isset($accountConfig['charge_rate']) ? floatval($accountConfig['charge_rate']) : 0;
  1055. $minRecharge = isset($accountConfig['min_recharge']) ? intval($accountConfig['min_recharge']) : 1;
  1056. if ($minRecharge && $num < $minRecharge) {
  1057. showJson(1004, '最低充值数量为:' . $minRecharge . '个');
  1058. }
  1059. $realMoney = moneyFormat($num * $chargeRate, 2);
  1060. if ($realMoney != $money) {
  1061. showJson(1004, '支付金额计算错误:' . $realMoney);
  1062. }
  1063. $orderSn = makeTradeNo('RH', $this->userId);
  1064. $memberInfo = Member::where(['id' => $this->userId])->field('openid,redheart')->find();
  1065. $redheart = isset($memberInfo['redheart']) ? intval($memberInfo['redheart']) : 0;
  1066. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1067. $log = [
  1068. 'order_sn' => $orderSn,
  1069. 'money' => $num,
  1070. 'pay_money' => $money,
  1071. 'user_id' => $this->userId,
  1072. 'balance' => $redheart,
  1073. 'remark' => "爱心充值:{$num}个,合计:{$money}元",
  1074. 'created_at' => date('Y-m-d H:i:s')
  1075. ];
  1076. $orderId = db('user_recharge_log')->insertGetId($log);
  1077. if ($orderId) {
  1078. // 获取OPENID
  1079. if (empty($openid)) {
  1080. showJson(1004, 2010);
  1081. }
  1082. $order = [
  1083. 'orderNo' => $orderSn,
  1084. 'amount' => $money,
  1085. 'openid' => $openid,
  1086. 'body' => '爱心充值订单支付',
  1087. ];
  1088. $params = Wechat::jsapiUnifiedorder($order, 'recharge');
  1089. PRedis::set('orders:recharge:redheart:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1090. $code = isset($params['code']) ? $params['code'] : '';
  1091. if ($code == 1004) {
  1092. showJson(1004, $params['message']);
  1093. }
  1094. // 更新订单参数
  1095. unset($params['prepay_id']);
  1096. showJson(1005, 4004, $params);
  1097. } else {
  1098. showJson(1004, 4005);
  1099. }
  1100. }
  1101. /**
  1102. * 想认识
  1103. */
  1104. public function doContact()
  1105. {
  1106. // 验证
  1107. $this->checkUser();
  1108. $id = input('id', 0);
  1109. $remark = input('remark', '');
  1110. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1111. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1112. }
  1113. // 完善个人信息
  1114. if (!UserProfile::checkUserProfile($this->userId)) {
  1115. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  1116. }
  1117. // 隐身不可申请
  1118. $type = input('type', 1);
  1119. $isHeart = Member::where(['id' => $this->userId])->value('is_heart');
  1120. if ($isHeart != 1 && $type != 2) {
  1121. showJson(1006, 2037, ['type' => 'check']);
  1122. }
  1123. $res = Member::contactUser($this->userId, $id, $remark);
  1124. if (is_array($res)) {
  1125. showJson(1005, 1008);
  1126. } else if ($res == 2103) {
  1127. $referer = request()->server('HTTP_REFERER');
  1128. $rebackurl = $referer ? $referer : url('/weixin/match/index', '', '', true);
  1129. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/index/entry?rebackurl=' . $rebackurl, '', '', true))]);
  1130. } else if ($res == 2121) {
  1131. showJson(1006, $res ? $res : 1009, ['url' => '/weixin/member/invite']);
  1132. } else {
  1133. showJson(1004, $res ? $res : 1009);
  1134. }
  1135. }
  1136. /**
  1137. * 认识审核确认
  1138. */
  1139. public function contactConfirm()
  1140. {
  1141. // 验证
  1142. $this->checkUser();
  1143. $cid = input('cid', 0);
  1144. $status = input('status', 2);
  1145. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1146. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1147. }
  1148. $res = Member::contactConfirm($this->userId, $cid, $status);
  1149. if (is_array($res)) {
  1150. showJson(1005, 1008);
  1151. } else {
  1152. showJson(1004, $res ? $res : 1009);
  1153. }
  1154. }
  1155. /**
  1156. * 套餐列表
  1157. * @throws \think\db\exception\DataNotFoundException
  1158. * @throws \think\db\exception\ModelNotFoundException
  1159. * @throws \think\exception\DbException
  1160. */
  1161. public function mealList()
  1162. {
  1163. $type = input('type', 0);
  1164. showJson(1005, 1001, Meals::getList($type));
  1165. }
  1166. /**
  1167. * 购买VIP套餐
  1168. * @throws \think\db\exception\DataNotFoundException
  1169. * @throws \think\db\exception\ModelNotFoundException
  1170. * @throws \think\exception\DbException
  1171. */
  1172. public function buyVip()
  1173. {
  1174. // 验证
  1175. $this->checkUser();
  1176. $mealId = input('mealId', 0);
  1177. $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price')->find();
  1178. if (empty($mealId) || empty($mealInfo)) {
  1179. showJson(1004, 7001);
  1180. }
  1181. $mealTime = isset($mealInfo['time']) ? $mealInfo['time'] : 0;
  1182. $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0;
  1183. if (empty($mealTime)) {
  1184. showJson(1004, 7002);
  1185. }
  1186. if (empty($mealPrice)) {
  1187. showJson(1004, 7003);
  1188. }
  1189. $orderSn = makeTradeNo('VP', $this->userId);
  1190. $memberInfo = Member::where(['id' => $this->userId])->field('openid,vip_auth,vip_expire')->find();
  1191. $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0;
  1192. $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0;
  1193. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1194. $expireText = $vipExpire > time() && $vipAuth ? ',原先' . date('Y-m-d H:i:s', $vipExpire) . '到期' : ',原先未开通';
  1195. $log = [
  1196. 'order_sn' => $orderSn,
  1197. 'money' => $mealTime,
  1198. 'type' => 4,
  1199. 'pay_money' => $mealPrice,
  1200. 'user_id' => $this->userId,
  1201. 'balance' => 0,
  1202. 'remark' => "购买VIP套餐[ID:{$mealId}]:会员续费{$mealTime}个月{$expireText}",
  1203. 'created_at' => date('Y-m-d H:i:s')
  1204. ];
  1205. $orderId = db('user_recharge_log')->insertGetId($log);
  1206. if ($orderId) {
  1207. // 获取OPENID
  1208. if (empty($openid)) {
  1209. showJson(1004, 2010);
  1210. }
  1211. $order = [
  1212. 'orderNo' => $orderSn,
  1213. 'amount' => $mealPrice,
  1214. 'openid' => $openid,
  1215. 'body' => $vipAuth ? '续费' . $mealInfo['name'] . '订单支付' : '购买' . $mealInfo['name'] . '订单支付',
  1216. ];
  1217. $params = Wechat::jsapiUnifiedorder($order, 'vip');
  1218. PRedis::set('orders:recharge:vip:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1219. $code = isset($params['code']) ? $params['code'] : '';
  1220. if ($code == 1004) {
  1221. showJson(1004, $params['message']);
  1222. }
  1223. // 更新订单参数
  1224. unset($params['prepay_id']);
  1225. showJson(1005, 7004, $params);
  1226. } else {
  1227. showJson(1004, 7005);
  1228. }
  1229. }
  1230. /**
  1231. * 购买人工服务
  1232. * @throws \think\db\exception\DataNotFoundException
  1233. * @throws \think\db\exception\ModelNotFoundException
  1234. * @throws \think\exception\DbException
  1235. */
  1236. public function handPay()
  1237. {
  1238. // 验证
  1239. $this->checkUser();
  1240. $mealId = input('mealId', 0);
  1241. $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price')->find();
  1242. if (empty($mealId) || empty($mealInfo)) {
  1243. showJson(1004, 7001);
  1244. }
  1245. $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0;
  1246. if (empty($mealPrice)) {
  1247. showJson(1004, 7003);
  1248. }
  1249. $orderSn = makeTradeNo('HP', $this->userId);
  1250. $log = [
  1251. 'order_sn' => $orderSn,
  1252. 'money' => $mealPrice,
  1253. 'type' => 5,
  1254. 'pay_money' => $mealPrice,
  1255. 'user_id' => $this->userId,
  1256. 'balance' => 0,
  1257. 'remark' => "购买人工牵服务[ID:{$mealId}]:支付{$mealPrice}元",
  1258. 'created_at' => date('Y-m-d H:i:s')
  1259. ];
  1260. $orderId = db('user_recharge_log')->insertGetId($log);
  1261. $memberInfo = Member::where(['id' => $this->userId])->field('openid')->find();
  1262. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1263. if ($orderId) {
  1264. // 获取OPENID
  1265. if (empty($openid)) {
  1266. showJson(1004, 2010);
  1267. }
  1268. $order = [
  1269. 'orderNo' => $orderSn,
  1270. 'amount' => $mealPrice,
  1271. 'openid' => $openid,
  1272. 'body' => '购买' . $mealInfo['name'] . '服务订单支付',
  1273. ];
  1274. $params = Wechat::jsapiUnifiedorder($order, 'hand');
  1275. PRedis::set('orders:recharge:hand:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1276. $code = isset($params['code']) ? $params['code'] : '';
  1277. if ($code == 1004) {
  1278. showJson(1004, $params['message']);
  1279. }
  1280. // 更新订单参数
  1281. unset($params['prepay_id']);
  1282. showJson(1005, 7004, $params);
  1283. } else {
  1284. showJson(1004, 7005);
  1285. }
  1286. }
  1287. /**
  1288. * 举报信息提交
  1289. */
  1290. public function complainSubmit()
  1291. {
  1292. $uid = input('uid', 0);
  1293. $type = input('type', 0);
  1294. if (empty($uid)) {
  1295. showJson(1004, 8001);
  1296. }
  1297. if (empty($type)) {
  1298. showJson(1004, 8002);
  1299. }
  1300. // 是否已经提交过
  1301. if (Complain::where(['uid' => $this->userId, 'c_uid' => $uid])->where('created_time', '>=', time() - 7 * 24 * 3600)->value('id')) {
  1302. showJson(1004, 8005);
  1303. }
  1304. // 举报数据
  1305. $params = [
  1306. 'uid' => $this->userId,
  1307. 'c_uid' => $uid,
  1308. 'remark' => htmlspecialchars(input('remark', '')),
  1309. 'type' => $type,
  1310. ];
  1311. // 照片
  1312. $file = request()->file('image');
  1313. if ($file) {
  1314. $fileData = Storage::uploadImg($file, 'complain', false, false);
  1315. $image = isset($fileData['file']) ? $fileData['file'] : '';
  1316. $params['image'] = $image;
  1317. }
  1318. // 保存数据
  1319. if ($id = Complain::saveData($params)) {
  1320. showJson(1005, 8003, $id);
  1321. } else {
  1322. showJson(1004, 8004);
  1323. }
  1324. }
  1325. /**
  1326. * 用户反馈建议提交
  1327. */
  1328. public function adviceSubmit()
  1329. {
  1330. $type = input('type', 0);
  1331. if (empty($type)) {
  1332. showJson(1004, 8009);
  1333. }
  1334. // 是否已经提交过
  1335. if (Advice::where(['uid' => $this->userId, 'type' => $type])->where('created_time', '>=', time() - 3 * 24 * 3600)->value('id')) {
  1336. showJson(1004, 8006);
  1337. }
  1338. // 数据
  1339. $params = [
  1340. 'uid' => $this->userId,
  1341. 'remark' => htmlspecialchars(input('remark', '')),
  1342. 'type' => $type,
  1343. ];
  1344. //
  1345. $file = request()->file('image');
  1346. if ($file) {
  1347. $fileData = Storage::uploadImg($file, 'complain', false, false);
  1348. $image = isset($fileData['file']) ? $fileData['file'] : '';
  1349. $params['image'] = $image;
  1350. }
  1351. // 保存数据
  1352. if ($id = Advice::saveData($params)) {
  1353. showJson(1005, 8007, $id);
  1354. } else {
  1355. showJson(1004, 8008);
  1356. }
  1357. }
  1358. /**
  1359. * @throws \think\db\exception\DataNotFoundException
  1360. * @throws \think\db\exception\ModelNotFoundException
  1361. * @throws \think\exception\DbException
  1362. */
  1363. public function complainList()
  1364. {
  1365. $type = input('type', 2);
  1366. $pageSize = input('pageSize', 30);
  1367. showJson(1005, 1001, Member::getComplainList($type, $pageSize));
  1368. }
  1369. /**
  1370. * 坐标转换地址
  1371. */
  1372. public function getLocationAddress()
  1373. {
  1374. $locationType = 'wgs84ll';
  1375. $apiUrl = config('api.locationApi');
  1376. $siteInfo = $siteInfo = cmf_get_site_info();
  1377. $ak = isset($siteInfo['map_key']) ? trim($siteInfo['map_key']) : '';
  1378. $uid = input('uid', 0);
  1379. $lat = input('lat', '');
  1380. $lng = input('lng', '');
  1381. $type = input('type', 1);
  1382. if (empty($lat) || empty($lng)) {
  1383. showJson(1004, 1002);
  1384. }
  1385. $apiUrl = sprintf($apiUrl, $ak, $locationType, "{$lat},{$lng}");
  1386. $data = cmf_curl_get($apiUrl);
  1387. $data = $data ? json_decode($data, true) : [];
  1388. $data = isset($data['result']) ? $data['result'] : [];
  1389. $addressData = isset($data['addressComponent']) ? $data['addressComponent'] : [];
  1390. $province = isset($addressData['province']) ? $addressData['province'] : '';
  1391. $city = isset($addressData['city']) ? $addressData['city'] : '';
  1392. $district = isset($addressData['district']) ? $addressData['district'] : '';
  1393. $location = isset($data['location']) ? $data['location'] : [];
  1394. $latNew = isset($location['lat']) ? round($location['lat'], 6) : 0;
  1395. $lngNew = isset($location['lng']) ? round($location['lng'], 6) : 0;
  1396. if (empty($data) || empty($latNew) || empty($lngNew)) {
  1397. showJson(1004, 8204);
  1398. }
  1399. // 更新位置数据
  1400. $cacheKey = "cache:location:u_{$this->userId}";
  1401. $updateData = ['lat' => $latNew, 'lng' => $lngNew, 'address' => "{$province},{$city},{$district}"];
  1402. if (!PRedis::get($cacheKey)) {
  1403. Member::where(['id' => $this->userId, 'user_type' => 2])->update($updateData);
  1404. PRedis::set($cacheKey, ['uid' => $this->userId, 'data' => $data, 'update' => $updateData, 'lat' => $latNew, 'lng' => $lngNew, 'date' => date('Y-m-d H:i:s')], 5);
  1405. }
  1406. if ($type == 1 && $uid) {
  1407. $distance = '';
  1408. $userInfo = Member::where(['id' => $uid])->field('lat,lng,address')->find();
  1409. $lat1 = isset($userInfo['lat']) ? $userInfo['lat'] : 0;
  1410. $lng1 = isset($userInfo['lng']) ? $userInfo['lng'] : 0;
  1411. $address = isset($userInfo['address']) ? $userInfo['address'] : '';
  1412. $address = $address ? explode(',', $address) : '';
  1413. $district = isset($address[2]) ? $address[2] : '';
  1414. if ($lat1 > 0 && $lng1 > 0) {
  1415. $distance = getDistance($lngNew, $latNew, $lng1, $lat1, 1);
  1416. $distance = $distance >= 1000 ? round($distance / 1000, 2) . 'km' : ($distance? $distance . 'm' : '');
  1417. }
  1418. showJson(1005, 8202, ['location' => $data, 'distance' => $distance, 'other' => $userInfo, 'address' => $address, 'district' => $district]);
  1419. }
  1420. showJson(1005, 8202, ['location' => $data]);
  1421. }
  1422. /**
  1423. * 注销账号
  1424. * @throws \think\Exception
  1425. * @throws \think\exception\PDOException
  1426. */
  1427. public function logout()
  1428. {
  1429. Member::where(['id' => $this->userId, 'user_type' => 2])
  1430. ->update(['user_status' => -1, 'vip_auth' => 0, 'is_heart' => 0, 'vip_expire' => 0, 'is_reg_profile' => 2, 'is_tuijian' => 0]);
  1431. $cacheKey = "weixin:auth:" . session('openid');
  1432. PRedis::del($cacheKey);
  1433. session('userInfo', null);
  1434. session('openid', null);
  1435. showJson(1005, 1001);
  1436. }
  1437. /**
  1438. * 认证记录
  1439. * @throws \think\Exception\DbException
  1440. */
  1441. public function getAuthNotice(){
  1442. $dataList = \app\weixin\service\Member::getAuthNotices();
  1443. showJson(1005, 1001, $dataList);
  1444. }
  1445. /**
  1446. * 获取用户访问记录
  1447. */
  1448. public function getUserAccess(){
  1449. $pageSize = input('pageSize', 30);
  1450. $dataList = Member::getUserAccess($this->userId, $pageSize);
  1451. showJson(1005, 1001, $dataList);
  1452. }
  1453. /**
  1454. * 解锁访问用户信息
  1455. */
  1456. public function unlock(){
  1457. $uid = input('uid', 0);
  1458. $cuid = input('cuid', 0);
  1459. if(empty($uid) || empty($cuid)){
  1460. showJson(1004,1012);
  1461. }
  1462. if($uid != $this->userId || ($uid == $cuid)){
  1463. showJson(1004,8301);
  1464. }
  1465. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1466. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1467. }
  1468. $res = Member::catchUnlock($uid, $cuid);
  1469. if (is_array($res)) {
  1470. showJson(1005, 8302);
  1471. } else {
  1472. showJson(1004, $res ? $res : 8303);
  1473. }
  1474. }
  1475. }