MemberController.php 57 KB

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