MemberController.php 75 KB

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