MemberController.php 79 KB

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