MemberController.php 61 KB

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