RegisterController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 老猫 <thinkcmf@126.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\love\controller;
  12. use app\common\Constant;
  13. use app\common\Fun;
  14. use app\common\Wechat;
  15. use app\love\model\ActiveModel;
  16. use app\love\model\UserAuthModel;
  17. use app\love\model\UserMatingModel;
  18. use app\love\model\UserModel;
  19. use cmf\controller\HomeBaseController;
  20. use think\facade\Request;
  21. class RegisterController extends HomeBaseController
  22. {
  23. public function initialize()
  24. {
  25. parent::initialize();
  26. /*$user_id = cmf_get_current_user_id();
  27. if (!empty($user_id)) {
  28. $user = UserModel::get($user_id);
  29. if ($user['user_status'] > 0 && $user['is_complete'] == 1) {
  30. $this->redirect(url('/'));
  31. }
  32. }*/
  33. //分享页面
  34. $wx_api_sign = Wechat::instance()->getJsSign(Request::url(true));
  35. $this->assign('domain', $this->request->domain());
  36. $this->assign('wx_api_sign', json_encode($wx_api_sign));
  37. }
  38. /**
  39. * 禁用
  40. */
  41. public function ban()
  42. {
  43. return $this->fetch();
  44. }
  45. public function marry()
  46. {
  47. return $this->fetch();
  48. }
  49. public function audit()
  50. {
  51. return $this->fetch();
  52. }
  53. public function idcard()
  54. {
  55. $user = UserModel::get(cmf_get_current_user_id());
  56. if ($this->request->isPost()) {
  57. $idcard = $this->request->post('idcard');
  58. if (empty($idcard)) {
  59. $this->error('请输入身份证号');
  60. }
  61. $auth = UserAuthModel::where('idcard', $idcard)->find();
  62. if (empty($auth)) {
  63. $this->error('抱歉,您不在注册列表中,如需注册请联系妇联');
  64. }
  65. $user->realname = $auth['name'];
  66. $user->idcard = $auth['idcard'];
  67. $user->mobile = $auth['mobile'];
  68. $user->company = $auth['company'];
  69. $user->company = $auth['company'];
  70. $user->marry = $auth['marry'];
  71. $user->sex = Fun::getSexByIdCard($auth['idcard']);
  72. $user->birthday = strtotime(Fun::getBirthDayByIdCard($auth['idcard']));
  73. $user->check_status = 2;
  74. $user->create_time = time();
  75. $user->save();
  76. $this->success('操作成功');
  77. } else {
  78. if (!empty($user['idcard'])) {
  79. $this->redirect(url('intro'));
  80. }
  81. return $this->fetch();
  82. }
  83. }
  84. /**
  85. * 活动说明
  86. */
  87. public function active()
  88. {
  89. $id = $this->request->param('id', 0);
  90. $active = ActiveModel::get($id);
  91. $active['start_time'] = date('m-d', $active['start_time']);
  92. $active['end_time'] = date('m-d', $active['end_time']);
  93. $active['main_image'] = cmf_get_image_preview_url($active['main_image']);
  94. $this->assign('active', $active);
  95. return $this->fetch();
  96. }
  97. /**
  98. * 性别
  99. */
  100. public function sex()
  101. {
  102. $user = UserModel::get(cmf_get_current_user_id());
  103. if ($this->request->isPost()) {
  104. $value = $this->request->post('sex');
  105. if (empty($user['sex'])) {
  106. $user->sex = $value;
  107. $user->save();
  108. }
  109. $this->success('');
  110. } else {
  111. if (!empty($user['sex'])) {
  112. $this->redirect(url('intro'));
  113. }
  114. return $this->fetch();
  115. }
  116. }
  117. /**
  118. * 部门
  119. */
  120. public function department()
  121. {
  122. $user = UserModel::get(cmf_get_current_user_id());
  123. if ($this->request->isPost()) {
  124. $value = $this->request->post('department');
  125. if (empty($user['department'])) {
  126. $user->department = $value;
  127. $user->save();
  128. }
  129. $this->success('');
  130. } else {
  131. $this->assign('department', Constant::DEPARTMENT);
  132. return $this->fetch();
  133. }
  134. }
  135. /**
  136. * 头像
  137. */
  138. public function intro()
  139. {
  140. if ($this->request->isPost()) {
  141. $value = $this->request->post();
  142. $value['avatar'] = $value['main_image_thumb'];
  143. UserModel::update($value, ['id' => cmf_get_current_user_id()], ['avatar', 'main_image', 'main_image_thumb', 'signature']);
  144. $this->success('');
  145. } else {
  146. $user = UserModel::get(cmf_get_current_user_id());
  147. $this->assign('user', $user);
  148. return $this->fetch();
  149. }
  150. }
  151. /**
  152. * 健康码
  153. */
  154. public function healthCode()
  155. {
  156. if ($this->request->isPost()) {
  157. $value = $this->request->post();
  158. UserModel::update($value, ['id' => cmf_get_current_user_id()], ['health_code']);
  159. $this->success('');
  160. } else {
  161. $user = UserModel::get(cmf_get_current_user_id());
  162. $this->assign('user', $user);
  163. return $this->fetch();
  164. }
  165. }
  166. /**
  167. * 个人资料
  168. */
  169. public function profile()
  170. {
  171. if ($this->request->isPost()) {
  172. $value = $this->request->post();
  173. $value['user_nickname'] = $value['realname'];
  174. $value['birthday'] = strtotime($value['birthday']);
  175. UserModel::update($value, ['id' => cmf_get_current_user_id()]);
  176. $this->success('');
  177. } else {
  178. $user = UserModel::get(cmf_get_current_user_id());
  179. $user['birthday'] = date('Y-m-d', $user['birthday']);
  180. unset($user['user_pass']);
  181. $this->assign('user', json_encode($user));
  182. $data = [
  183. 'marry' => Constant::MARRY,
  184. 'high' => Constant::HIGH,
  185. 'weight' => Constant::WEIGHT,
  186. 'education' => Constant::EDUCATION,
  187. 'income' => Constant::INCOME,
  188. 'nation' => Constant::NATION,
  189. 'smoke' => Constant::SMOKE,
  190. 'drink' => Constant::DRINK,
  191. 'family' => Constant::FAMILY,
  192. 'tinyint' => Constant::TINYINT,
  193. ];
  194. foreach ($data as &$v) {
  195. $v = json_encode($v);
  196. unset($v);
  197. }
  198. return $this->fetch('', $data);
  199. }
  200. }
  201. /**
  202. * 择偶要求
  203. */
  204. public function cond()
  205. {
  206. if ($this->request->isPost()) {
  207. $param = $this->request->post();
  208. UserMatingModel::update($param, ['user_id' => cmf_get_current_user_id()]);
  209. UserModel::update(['is_complete' => 1, 'id' => cmf_get_current_user_id()]);
  210. $user = UserModel::get(cmf_get_current_user_id());
  211. session('user', $user->toArray());
  212. $this->success('操作成功');
  213. } else {
  214. $mating = UserMatingModel::get(['user_id' => cmf_get_current_user_id()]);
  215. $this->assign('mating', $mating);
  216. $education = Constant::EDUCATION;
  217. $education[] = '无要求';
  218. $data = [
  219. 'min_age' => Constant::MIN_AGE,
  220. 'max_age' => Constant::MAX_AGE,
  221. 'min_high' => Constant::MIN_HIGH,
  222. 'max_high' => Constant::MAX_HIGH,
  223. 'min_weight' => Constant::MIN_WEIGHT,
  224. 'max_weight' => Constant::MAX_WEIGHT,
  225. 'native' => Constant::NATIVE,
  226. 'education' => $education,
  227. 'income' => Constant::COND_INCOME,
  228. 'smoke' => Constant::SMOKE,
  229. 'drink' => Constant::DRINK,
  230. 'tinyint' => Constant::COND_TINYINT,
  231. ];
  232. foreach ($data as &$v) {
  233. $v = json_encode($v);
  234. unset($v);
  235. }
  236. return $this->fetch('', $data);
  237. }
  238. }
  239. // public function t1()
  240. // {
  241. // $auth = UserAuthModel::all();
  242. // $num = 0;
  243. // foreach ($auth as $v) {
  244. // $birth = strtotime(Fun::getBirthDayByIdCard($v['idcard']));
  245. // $check = UserModel::where('mobile',$v['mobile'])->find();
  246. // if (!empty($check) && $check->birthday != $birth) {
  247. // $check->birthday = $birth;
  248. // $check->save();
  249. // $num++;
  250. // }
  251. // }
  252. //
  253. // return $num;
  254. // }
  255. /**
  256. * 健康码上传
  257. */
  258. public function codeUpload()
  259. {
  260. $file = $this->request->post('file');
  261. $ext = pathinfo($this->request->post('name'))['extension'];
  262. if (!in_array($ext, ['jpg', 'jpeg', 'png'])) {
  263. $this->error('文件后缀必须为jpg,jpeg,png');
  264. }
  265. if ($file) {
  266. //创建目录
  267. $upload_dir = WEB_ROOT . 'upload/health_code';
  268. if (!is_dir($upload_dir)) {
  269. @mkdir($upload_dir);
  270. }
  271. $upload_dir = $upload_dir . '/' . date('Ymd');
  272. if (!is_dir($upload_dir)) {
  273. @mkdir($upload_dir);
  274. }
  275. //保存文件
  276. $file_name = $this->_file_name($ext);
  277. $file_path = $upload_dir . '/' . $file_name;
  278. $is_upload = $this->_base64_image_content($file, $file_path);
  279. if (!$is_upload) {
  280. $this->error('上传失败,请重新上传');
  281. }
  282. $main_image = cmf_get_user_avatar_url('health_code' . '/' . date('Ymd') . '/' . $file_name);
  283. $this->result([
  284. 'health_code' => cmf_get_user_avatar_url($main_image),
  285. ], 1);
  286. } else {
  287. $this->error('请上传文件');
  288. }
  289. }
  290. /**
  291. * 图片上传
  292. */
  293. public function imageUpload()
  294. {
  295. $file = $this->request->post('file');
  296. $ext = pathinfo($this->request->post('name'))['extension'];
  297. if (!in_array($ext, ['jpg', 'jpeg', 'png'])) {
  298. $this->error('文件后缀必须为jpg,jpeg,png');
  299. }
  300. if ($file) {
  301. //创建目录
  302. $upload_dir = WEB_ROOT . 'upload/image';
  303. if (!is_dir($upload_dir)) {
  304. @mkdir($upload_dir);
  305. }
  306. $upload_dir = $upload_dir . '/' . date('Ymd');
  307. if (!is_dir($upload_dir)) {
  308. @mkdir($upload_dir);
  309. }
  310. //保存文件
  311. $file_name = $this->_file_name($ext);
  312. $file_path = $upload_dir . '/' . $file_name;
  313. $is_upload = $this->_base64_image_content($file, $file_path);
  314. if (!$is_upload) {
  315. $this->error('上传失败,请重新上传');
  316. }
  317. //缩略图
  318. $thumb_file = $this->_file_name($ext);
  319. $image = \think\Image::open($file_path);
  320. $image->thumb(220, 270)->save($upload_dir . '/' . $thumb_file);
  321. $main_image = cmf_get_user_avatar_url('image' . '/' . date('Ymd') . '/' . $file_name);
  322. $main_image_thumb = cmf_get_user_avatar_url('image' . '/' . date('Ymd') . '/' . $thumb_file);
  323. $this->result([
  324. 'main_image' => $main_image,
  325. 'main_image_thumb' => $main_image_thumb,
  326. ], 1);
  327. } else {
  328. $this->error('请上传文件');
  329. }
  330. }
  331. private function _file_name($ext)
  332. {
  333. //生成随机文件名
  334. //定义一个包含大小写字母数字的字符串
  335. $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  336. //把字符串分割成数组
  337. $newchars = str_split($chars);
  338. //打乱数组
  339. shuffle($newchars);
  340. //从数组中随机取出15个字符
  341. $chars_key = array_rand($newchars, 15);
  342. //把取出的字符重新组成字符串
  343. $fnstr = '';
  344. for ($i = 0; $i < 15; $i++) {
  345. $fnstr .= $newchars[$chars_key[$i]];
  346. }
  347. //输出文件名并做MD5加密
  348. return md5($fnstr . microtime(true) * 1000) . '.' . $ext;
  349. }
  350. private function _base64_image_content($base64_image_content, $file_path)
  351. {
  352. //匹配出图片的格式
  353. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
  354. if (file_put_contents($file_path, base64_decode(str_replace($result[1], '', $base64_image_content)))) {
  355. return true;
  356. } else {
  357. return false;
  358. }
  359. } else {
  360. return false;
  361. }
  362. }
  363. }