MemberController.php 64 KB

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