User.php 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\SDK\Dyvmsapi\V20170525\Models\ListCallTaskResponseBody\data;
  4. use app\common\controller\Api;
  5. use app\common\library\Ems;
  6. use app\common\library\Sms;
  7. use fast\Random;
  8. use think\Config;
  9. use think\Validate;
  10. use think\Db;
  11. use wxpay;
  12. /**
  13. * 会员接口
  14. */
  15. class User extends Api
  16. {
  17. protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'registercheck', 'resetpwd', 'changeemail', 'changemobile', 'third', 'getopenid', 'getagreement', 'wxlogin', 'mobileloginregister'];
  18. protected $noNeedRight = '*';
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. if (!Config::get('fastadmin.usercenter')) {
  23. $this->error(__('User center already closed'));
  24. }
  25. }
  26. /**
  27. * 会员中心
  28. */
  29. public function index()
  30. {
  31. $this->success('', ['welcome' => $this->auth->nickname]);
  32. }
  33. /**
  34. * 会员登录
  35. *
  36. * @ApiMethod (POST)
  37. * @param string $account 账号
  38. * @param string $password 密码
  39. */
  40. public function login()
  41. {
  42. $account = $this->request->post('account');
  43. $password = $this->request->post('password');
  44. if (!$account || !$password) {
  45. $this->error(__('Invalid parameters'));
  46. }
  47. $ret = $this->auth->login($account, $password);
  48. if ($ret) {
  49. $data = ['userinfo' => $this->auth->getUserinfo()];
  50. $this->success(__('Logged in successful'), $data);
  51. } else {
  52. $this->error($this->auth->getError());
  53. }
  54. }
  55. /**
  56. * 手机验证码登录
  57. *
  58. * @ApiMethod (POST)
  59. * @param string $mobile 手机号
  60. * @param string $captcha 验证码
  61. */
  62. public function mobilelogin()
  63. {
  64. $mobile = $this->request->post('mobile');
  65. $captcha = $this->request->post('captcha');
  66. if (!$mobile || !$captcha) {
  67. $this->error(__('Invalid parameters'));
  68. }
  69. if (!Validate::regex($mobile, "^1\d{10}$")) {
  70. $this->error(__('Mobile is incorrect'));
  71. }
  72. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  73. $this->error(__('Captcha is incorrect'));
  74. }
  75. $user = \app\common\model\User::getByMobile($mobile);
  76. // if (!$user) {
  77. // $this->error('用户尚未注册');
  78. // }
  79. // if ($user['status'] != 1) {
  80. // $this->error(__('Account is locked'));
  81. // }
  82. if ($user) {
  83. if ($user->status != 1) {
  84. $this->error(__('Account is locked'));
  85. }
  86. //如果已经有账号则直接登录
  87. $ret = $this->auth->direct($user->id);
  88. } else {
  89. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
  90. }
  91. // $ret = $this->auth->direct($user->id);
  92. if ($ret) {
  93. Sms::flush($mobile, 'mobilelogin');
  94. $data = ['userinfo' => $this->auth->getUserinfo()];
  95. $this->success(__('Logged in successful'), $data);
  96. } else {
  97. $this->error($this->auth->getError());
  98. }
  99. }
  100. /**
  101. * 注册会员
  102. *
  103. * @ApiMethod (POST)
  104. * @param string $username 用户名
  105. * @param string $password 密码
  106. * @param string $email 邮箱
  107. * @param string $mobile 手机号
  108. * @param string $code 验证码
  109. */
  110. /*public function register()
  111. {
  112. $mobile = $this->request->post('mobile', '', 'trim'); //手机号
  113. $code = $this->request->post('code', '', 'trim'); //验证码
  114. $password = $this->request->post('password', '' , 'trim'); //密码
  115. $repassword = $this->request->post('repassword', '' , 'trim'); //确认密码
  116. $nickname = $this->request->post('nickname', '', 'trim'); //姓名
  117. $idcard = $this->request->post('idcard', '', 'trim,strip_tags,htmlspecialchars'); //身份证号
  118. $province = $this->request->post('province', '', 'trim'); //省
  119. $city = $this->request->post('city', '', 'trim'); //市
  120. $area = $this->request->post('area', '', 'trim'); //区
  121. $address = $this->request->post('address', '', 'trim'); //详细地址
  122. $recommender = $this->request->post('recommender', '', 'trim'); //推荐人姓名
  123. $recommender_mobile = $this->request->post('recommender_mobile', '', 'trim'); //推荐人手机号
  124. $zimage = $this->request->post('zimage', '', 'trim,strip_tags,htmlspecialchars'); //身份证正面照
  125. $fimage = $this->request->post('fimage', '', 'trim,strip_tags,htmlspecialchars'); //身份证反面照
  126. if (!Validate::regex($mobile, "^1\d{10}$")) {
  127. $this->error(__('Mobile is incorrect'));
  128. }
  129. $count = Db::name('user')->where(['mobile' => $mobile])->count('id');
  130. if ($count) {
  131. $this->error('手机号已被注册');
  132. }
  133. if (iconv_strlen($code, 'utf-8') != config('alisms.length')) {
  134. $this->error(__('Captcha is incorrect'));
  135. }
  136. $ret = Sms::check($mobile, $code, 'register');
  137. if (!$ret) {
  138. $this->error(__('Captcha is incorrect'));
  139. }
  140. if (!$password) {
  141. $this->error('请输入新密码');
  142. }
  143. //验证新密码
  144. if (!Validate::make()->check(['newpassword' => $password], ['newpassword' => 'require|regex:\S{6,30}'])) {
  145. $this->error(__('Password must be 6 to 30 characters'));
  146. }
  147. if (!$repassword) {
  148. $this->error('请再次输入密码');
  149. }
  150. if ($repassword != $password) {
  151. $this->error('两次密码不一致');
  152. }
  153. if (!$nickname) {
  154. $this->error('请输入姓名');
  155. }
  156. if (iconv_strlen($nickname, 'utf-8') > 30) {
  157. $this->error('姓名最多30位');
  158. }
  159. if (!$idcard) {
  160. $this->error('请输入身份证号');
  161. }
  162. if (iconv_strlen($idcard, 'utf-8') != 18) {
  163. $this->error('身份证号错误');
  164. }
  165. if (!$province || !$city || !$area) {
  166. $this->error('请选择养殖场地址');
  167. }
  168. if (!$address) {
  169. $this->error('请输入详细地址');
  170. }
  171. if (iconv_strlen($address, 'utf-8') > 255) {
  172. $this->error('详细地址最多255位');
  173. }
  174. if (!$recommender) {
  175. $this->error('请输入推荐人姓名');
  176. }
  177. if (iconv_strlen($recommender, 'utf-8') > 30) {
  178. $this->error('推荐人姓名最多30位');
  179. }
  180. if (!$recommender_mobile || !is_mobile($recommender_mobile)) {
  181. $this->error('请输入正确推荐人手机号');
  182. }
  183. if (!$zimage || !$fimage) {
  184. $this->error('请上传身份证相关照片');
  185. }
  186. $ip = request()->ip();
  187. $time = time();
  188. $data = [
  189. 'nickname' => $nickname,
  190. 'province' => $province,
  191. 'city' => $city,
  192. 'area' => $area,
  193. 'address' => $address,
  194. 'createtime' => $time
  195. ];
  196. $params = array_merge($data, [
  197. 'mobile' => $mobile,
  198. 'password' => $password,
  199. 'avatar' => '/assets/img/avatar.png',
  200. 'salt' => Random::alnum(),
  201. 'jointime' => $time,
  202. 'joinip' => $ip,
  203. 'logintime' => $time,
  204. 'loginip' => $ip,
  205. 'prevtime' => $time,
  206. 'is_auth' => 1
  207. ]);
  208. $params['password'] = md5(md5($password) . $params['salt']);
  209. //开启事务
  210. Db::startTrans();
  211. $rs = Db::name('user')->insertGetId($params);
  212. if (!$rs) {
  213. Db::rollback();
  214. $this->error('注册失败');
  215. }
  216. $data['user_id'] = $rs;
  217. $data['idcard'] = $idcard;
  218. $data['zimage'] = $zimage;
  219. $data['fimage'] = $fimage;
  220. $data['recommender'] = $recommender;
  221. $data['recommender_mobile'] = $recommender_mobile;
  222. $rt = Db::name('user_auth')->insertGetId($data);
  223. if (!$rt) {
  224. Db::rollback();
  225. $this->error('注册失败');
  226. }
  227. Db::commit();
  228. $ret = $this->auth->login($mobile, $password);
  229. if ($ret) {
  230. $data = ['userinfo' => $this->auth->getUserinfo()];
  231. $this->success(__('Sign up successful'), $data);
  232. } else {
  233. $this->error($this->auth->getError());
  234. }
  235. }*/
  236. //注册第一步验证
  237. public function registercheck()
  238. {
  239. $mobile = $this->request->post('mobile'); //手机号
  240. $code = $this->request->post('code'); //验证码
  241. $password = $this->request->post('password'); //密码
  242. $repassword = $this->request->post('repassword', '' , 'trim'); //确认密码
  243. if (!Validate::regex($mobile, "^1\d{10}$")) {
  244. $this->error(__('Mobile is incorrect'));
  245. }
  246. $count = Db::name('user')->where(['mobile' => $mobile])->count('id');
  247. if (!$count) {
  248. $this->error('手机号已被注册');
  249. }
  250. if (iconv_strlen($code, 'utf-8') != config('alisms.length')) {
  251. $this->error(__('Captcha is incorrect'));
  252. }
  253. $ret = Sms::check($mobile, $code, 'register');
  254. if (!$ret) {
  255. $this->error(__('Captcha is incorrect'));
  256. }
  257. if (!$password) {
  258. $this->error('请输入新密码');
  259. }
  260. //验证新密码
  261. if (!Validate::make()->check(['newpassword' => $password], ['newpassword' => 'require|regex:\S{6,30}'])) {
  262. $this->error(__('Password must be 6 to 30 characters'));
  263. }
  264. if (!$repassword) {
  265. $this->error('请再次输入密码');
  266. }
  267. if ($repassword != $password) {
  268. $this->error('两次密码不一致');
  269. }
  270. $this->success('验证通过');
  271. }
  272. /**
  273. * 退出登录
  274. * @ApiMethod (POST)
  275. */
  276. public function logout()
  277. {
  278. if (!$this->request->isPost()) {
  279. $this->error(__('Invalid parameters'));
  280. }
  281. $this->auth->logout();
  282. $this->success(__('Logout successful'));
  283. }
  284. //查询会员信息
  285. public function getinfo()
  286. {
  287. //检查今日是否登录赠送过成长值
  288. $this->checklogingrowth($this->auth->id);
  289. //检查会员等级
  290. $this->checkviplevel($this->auth->id);
  291. $user = Db::name('user')->find($this->auth->id);
  292. $data['nickname'] = $user['nickname']; //姓名
  293. $data['username'] = $user['username']; //UID
  294. $data['avatar'] = cdnurl($user['avatar']); //头像
  295. $data['mobile'] = $user['mobile']; //手机号
  296. $data['money'] = $user['money']; //余额
  297. $data['realname'] = $user['realname']; //真实姓名
  298. $data['gender'] = $user['gender']; //性别:1=男,2=女
  299. $data['birthday'] = date('Y-m-d', $user['birthday']); //生日
  300. $data['idcard'] = $user['idcard']; //身份证号
  301. $data['passport'] = $user['passport']; //护照号
  302. $data['emergencycontact'] = $user['emergencycontact']; //紧急联系人
  303. $data['contactmobile'] = $user['contactmobile']; //紧急联系方式
  304. $data['outdoorduration'] = $user['outdoorduration']; //户外时长
  305. $data['maxlevel'] = $user['maxlevel']; //实际有效会员ID
  306. $data['viplevel'] = Db::name('vip')->where(['id' => $user['maxlevel']])->value('level'); //会员等级
  307. $data['active_count'] = Db::name('active_order')->where(['user_id' => $this->auth->id, 'status' => 2])->count('id'); //完成活动数量
  308. $data['freenumber'] = $user['freenumber']; //会员免费参加活动次数
  309. $data['invite_no'] = $user['invite_no']; //邀请码
  310. $this->success('会员信息', $data);
  311. }
  312. /**
  313. * 修改会员个人信息
  314. *
  315. * @ApiMethod (POST)
  316. * @param string $avatar 头像地址
  317. * @param string $username 用户名
  318. * @param string $nickname 昵称
  319. * @param string $bio 个人简介
  320. */
  321. public function profile()
  322. {
  323. $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars'); //头像
  324. $nickname = $this->request->post('nickname', '', 'trim'); //昵称
  325. $realname = $this->request->post('realname', '', 'trim'); //真实姓名
  326. $idcard = $this->request->post('idcard', '', 'trim,strip_tags,htmlspecialchars'); //身份证号
  327. $passport = $this->request->post('passport', '', 'trim,strip_tags,htmlspecialchars'); //护照号
  328. $emergencycontact = $this->request->post('emergencycontact', '', 'trim'); //紧急联系人
  329. $contactmobile = $this->request->post('contactmobile', '', 'trim'); //紧急联系方式
  330. $outdoorduration = $this->request->post('outdoorduration', '', 'trim'); //户外时长
  331. $birthday = $this->request->post('birthday', '', 'strtotime'); //生日
  332. $gender = $this->request->post('gender', 0, 'intval'); //性别
  333. $data = [];
  334. if ($avatar) {
  335. if (iconv_strlen($avatar, 'utf-8') > 255) {
  336. $this->error('图片超出范围');
  337. }
  338. $data['avatar'] = $avatar;
  339. }
  340. if ($nickname) {
  341. if (iconv_strlen($nickname, 'utf-8') > 30) {
  342. $this->error('昵称最多30字');
  343. }
  344. $data['nickname'] = $nickname;
  345. }
  346. if ($realname) {
  347. if(iconv_strlen($realname, 'utf-8') > 30) {
  348. $this->error('真实姓名最多30字');
  349. }
  350. $data['realname'] = $realname;
  351. }
  352. if ($idcard) {
  353. if (iconv_strlen($idcard, 'utf-8') != 18) {
  354. $this->error('身份证号错误');
  355. }
  356. $data['idcard'] = $idcard;
  357. }
  358. if ($passport) {
  359. if (iconv_strlen($passport, 'utf-8') > 30) {
  360. $this->error('护照号错误');
  361. }
  362. $data['passport'] = $passport;
  363. }
  364. if ($emergencycontact) {
  365. if(iconv_strlen($emergencycontact, 'utf-8') > 30) {
  366. $this->error('紧急联系人最多30字');
  367. }
  368. $data['emergencycontact'] = $emergencycontact;
  369. }
  370. if ($contactmobile) {
  371. if(!is_mobile($contactmobile)) {
  372. $this->error('请输入正确紧急联系方式');
  373. }
  374. $data['contactmobile'] = $contactmobile;
  375. }
  376. if ($outdoorduration) {
  377. if(iconv_strlen($outdoorduration, 'utf-8') > 50) {
  378. $this->error('户外时长最多50字');
  379. }
  380. $data['outdoorduration'] = $outdoorduration;
  381. }
  382. if ($birthday) {
  383. $data['birthday'] = $birthday;
  384. }
  385. if (in_array($gender, [1, 2])) {
  386. $data['gender'] = $gender;
  387. }
  388. // $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
  389. // if ($username) {
  390. // $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
  391. // if ($exists) {
  392. // $this->error(__('Username already exists'));
  393. // }
  394. // $user->username = $username;
  395. // }
  396. // if ($nickname) {
  397. // $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
  398. // if ($exists) {
  399. // $this->error(__('Nickname already exists'));
  400. // }
  401. // $user->nickname = $nickname;
  402. // }
  403. // $user->avatar = $avatar;
  404. if (!$data) {
  405. $this->error('暂无修改内容');
  406. }
  407. //修改用户表
  408. $rt = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  409. if ($rt === false) {
  410. $this->error('修改失败');
  411. }
  412. $this->success('修改成功');
  413. }
  414. //修改头像
  415. public function changeavatar()
  416. {
  417. $avatar = input('avatar', '', 'trim'); //头像
  418. if (!$avatar) {
  419. $this->error('请上传头像');
  420. }
  421. if (iconv_strlen($avatar, 'utf-8') > 255) {
  422. $this->error('头像长度超出限制');
  423. }
  424. $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('avatar', $avatar);
  425. if (!$rs) {
  426. $this->error('修改失败');
  427. }
  428. $this->success('修改成功');
  429. }
  430. /**
  431. * 修改邮箱
  432. *
  433. * @ApiMethod (POST)
  434. * @param string $email 邮箱
  435. * @param string $captcha 验证码
  436. */
  437. public function changeemail()
  438. {
  439. $user = $this->auth->getUser();
  440. $email = $this->request->post('email');
  441. $captcha = $this->request->post('captcha');
  442. if (!$email || !$captcha) {
  443. $this->error(__('Invalid parameters'));
  444. }
  445. if (!Validate::is($email, "email")) {
  446. $this->error(__('Email is incorrect'));
  447. }
  448. if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
  449. $this->error(__('Email already exists'));
  450. }
  451. $result = Ems::check($email, $captcha, 'changeemail');
  452. if (!$result) {
  453. $this->error(__('Captcha is incorrect'));
  454. }
  455. $verification = $user->verification;
  456. $verification->email = 1;
  457. $user->verification = $verification;
  458. $user->email = $email;
  459. $user->save();
  460. Ems::flush($email, 'changeemail');
  461. $this->success();
  462. }
  463. /**
  464. * 修改手机号
  465. *
  466. * @ApiMethod (POST)
  467. * @param string $mobile 手机号
  468. * @param string $captcha 验证码
  469. */
  470. public function changemobile()
  471. {
  472. $user = $this->auth->getUser();
  473. $code = $this->request->post('code');
  474. $mobile = $this->request->post('mobile');
  475. $captcha = $this->request->post('captcha');
  476. if (!$code || !$mobile || !$captcha) {
  477. $this->error(__('Invalid parameters'));
  478. }
  479. if ($mobile == $user->mobile) {
  480. $this->error('手机号没有改变');
  481. }
  482. $result = Sms::check($user->mobile, $code, 'changeyuanmobile');
  483. if (!$result) {
  484. $this->error(__('Captcha is incorrect'));
  485. }
  486. if (!Validate::regex($mobile, "^1\d{10}$")) {
  487. $this->error(__('Mobile is incorrect'));
  488. }
  489. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  490. $this->error(__('手机号已存在'));
  491. }
  492. $result = Sms::check($mobile, $captcha, 'changemobile');
  493. if (!$result) {
  494. $this->error(__('Captcha is incorrect'));
  495. }
  496. $verification = $user->verification;
  497. $verification->mobile = 1;
  498. $user->verification = $verification;
  499. $user->mobile = $mobile;
  500. $user->save();
  501. Sms::flush($user->mobile, 'changemobile');
  502. Sms::flush($mobile, 'changemobile');
  503. $this->success('修改成功');
  504. }
  505. /**
  506. * 第三方登录
  507. *
  508. * @ApiMethod (POST)
  509. * @param string $platform 平台名称
  510. * @param string $code Code码
  511. */
  512. public function third()
  513. {
  514. $url = url('user/index');
  515. $platform = $this->request->post("platform");
  516. $code = $this->request->post("code");
  517. $config = get_addon_config('third');
  518. if (!$config || !isset($config[$platform])) {
  519. $this->error(__('Invalid parameters'));
  520. }
  521. $app = new \addons\third\library\Application($config);
  522. //通过code换access_token和绑定会员
  523. $result = $app->{$platform}->getUserInfo(['code' => $code]);
  524. if ($result) {
  525. $loginret = \addons\third\library\Service::connect($platform, $result);
  526. if ($loginret) {
  527. $data = [
  528. 'userinfo' => $this->auth->getUserinfo(),
  529. 'thirdinfo' => $result
  530. ];
  531. $this->success(__('Logged in successful'), $data);
  532. }
  533. }
  534. $this->error(__('Operation failed'), $url);
  535. }
  536. /**
  537. * 重置密码
  538. *
  539. * @ApiMethod (POST)
  540. * @param string $mobile 手机号
  541. * @param string $newpassword 新密码
  542. * @param string $captcha 验证码
  543. */
  544. public function resetpwd()
  545. {
  546. $type = 'mobile';//$this->request->post("type");
  547. $mobile = $this->request->post("mobile");
  548. $email = $this->request->post("email");
  549. $newpassword = $this->request->post("newpassword");
  550. $repassword = $this->request->post('repassword', '' , 'trim'); //确认密码
  551. $captcha = $this->request->post("captcha");
  552. if (!$newpassword || !$captcha || !$repassword) {
  553. $this->error(__('Invalid parameters'));
  554. }
  555. //验证Token
  556. if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
  557. $this->error(__('Password must be 6 to 30 characters'));
  558. }
  559. if ($repassword != $newpassword) {
  560. $this->error('两次密码不一致');
  561. }
  562. if ($type == 'mobile') {
  563. if (!Validate::regex($mobile, "^1\d{10}$")) {
  564. $this->error(__('Mobile is incorrect'));
  565. }
  566. $user = \app\common\model\User::getByMobile($mobile);
  567. if (!$user) {
  568. $this->error(__('User not found'));
  569. }
  570. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  571. if (!$ret) {
  572. $this->error(__('Captcha is incorrect'));
  573. }
  574. Sms::flush($mobile, 'resetpwd');
  575. } else {
  576. if (!Validate::is($email, "email")) {
  577. $this->error(__('Email is incorrect'));
  578. }
  579. $user = \app\common\model\User::getByEmail($email);
  580. if (!$user) {
  581. $this->error(__('User not found'));
  582. }
  583. $ret = Ems::check($email, $captcha, 'resetpwd');
  584. if (!$ret) {
  585. $this->error(__('Captcha is incorrect'));
  586. }
  587. Ems::flush($email, 'resetpwd');
  588. }
  589. //模拟一次登录
  590. $this->auth->direct($user->id);
  591. $ret = $this->auth->changepwd($newpassword, '', true);
  592. if ($ret) {
  593. $this->success(__('Reset password successful'));
  594. } else {
  595. $this->error($this->auth->getError());
  596. }
  597. }
  598. /**
  599. * 修改密码
  600. *
  601. * @ApiMethod (POST)
  602. * @param string $captcha 验证码
  603. * @param string $newpassword 新密码
  604. * @param string $repassword 确认密码
  605. */
  606. public function editpwd()
  607. {
  608. $captcha = $this->request->post("captcha", '', 'trim'); //验证码
  609. $newpassword = $this->request->post("newpassword", '' , 'trim'); //新密码
  610. $repassword = $this->request->post('repassword', '' , 'trim'); //确认密码
  611. if (iconv_strlen($captcha, 'utf-8') != config('alisms.length')) {
  612. $this->error(__('Captcha is incorrect'));
  613. }
  614. if (!$newpassword) {
  615. $this->error('请输入新密码');
  616. }
  617. //验证新密码
  618. if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
  619. $this->error(__('Password must be 6 to 30 characters'));
  620. }
  621. if (!$repassword) {
  622. $this->error('请再次输入密码');
  623. }
  624. if ($repassword != $newpassword) {
  625. $this->error('两次密码不一致');
  626. }
  627. // $user = \app\common\model\User::getById($this->auth->id);
  628. // if (!$user) {
  629. // $this->error(__('User not found'));
  630. // }
  631. $ret = Sms::check($this->auth->mobile, $captcha, 'changepwd');
  632. if (!$ret) {
  633. $this->error(__('Captcha is incorrect'));
  634. }
  635. //模拟一次登录
  636. $this->auth->direct($this->auth->id);
  637. $ret = $this->auth->changepwd($newpassword, '', true);
  638. if ($ret) {
  639. Sms::flush($this->auth->mobile, 'changepwd');
  640. $this->success(__('Reset password successful'));
  641. } else {
  642. $this->error($this->auth->getError());
  643. }
  644. }
  645. //查询经营信息
  646. public function get_businessinfo()
  647. {
  648. $data = Db::name('user_business_info')->field('manage, mobile, province, city, area, distribution_channel')
  649. ->where(['user_id' => $this->auth->id])->find();
  650. $this->success('经营信息', $data);
  651. }
  652. //修改经营信息
  653. public function editbusinessinfo()
  654. {
  655. $manage = $this->request->post('manage', '', 'trim'); //采购负责人
  656. $mobile = $this->request->post('mobile', '', 'trim'); //联系方式
  657. $province = $this->request->post('province', '', 'trim'); //省
  658. $city = $this->request->post('city', '', 'trim'); //市
  659. $area = $this->request->post('area', '', 'trim'); //区
  660. $distribution_channel = $this->request->post('distribution_channel', '', 'trim'); //销售渠道
  661. $data = [];
  662. if ($manage) {
  663. if (iconv_strlen($manage, 'utf-8') > 50) {
  664. $this->error('采购负责人最多50字');
  665. }
  666. $data['manage'] = $manage;
  667. }
  668. if ($mobile) {
  669. if (!Validate::regex($mobile, "^1\d{10}$")) {
  670. $this->error(__('Mobile is incorrect'));
  671. }
  672. $data['mobile'] = $mobile;
  673. }
  674. if ($province && $city && $area) {
  675. $data['province'] = $province;
  676. $data['city'] = $city;
  677. $data['area'] = $area;
  678. }
  679. if ($distribution_channel) {
  680. if (iconv_strlen($distribution_channel, 'utf-8') > 255) {
  681. $this->error('销售渠道说明最多50字');
  682. }
  683. $data['distribution_channel'] = $distribution_channel;
  684. }
  685. if (!$data) {
  686. $this->error('暂无修改内容');
  687. }
  688. $count = Db::name('user_business_info')->where(['user_id' => $this->auth->id])->count();
  689. if ($count) {
  690. $data['updatetime'] = time();
  691. $rs = Db::name('user_business_info')->where(['user_id' => $this->auth->id])->setField($data);
  692. } else {
  693. $data['user_id'] = $this->auth->id;
  694. $data['createtime'] = time();
  695. $rs = Db::name('user_business_info')->insertGetId($data);
  696. }
  697. if (!$rs) {
  698. $this->error('修改失败');
  699. }
  700. $this->success('修改成功');
  701. }
  702. //查询猪车信息
  703. public function getpigcar()
  704. {
  705. $data = Db::name('user_pig_car')->where(['user_id' => $this->auth->id])->select();
  706. $data = list_domain_image($data, ['images']);
  707. $this->success('查询猪车信息', $data);
  708. }
  709. /**
  710. * 添加猪车信息
  711. *
  712. *$data = [
  713. [
  714. 'carnumber' => '123',
  715. 'carframenumber' => '344',
  716. 'images' => '123.jpg,234.jpg,345.jpg'
  717. ],
  718. [
  719. 'carnumber' => '123',
  720. 'carframenumber' => '344',
  721. 'images' => '123.jpg,234.jpg,345.jpg'
  722. ],
  723. [
  724. 'carnumber' => '123',
  725. 'carframenumber' => '344',
  726. 'images' => '123.jpg,234.jpg,345.jpg'
  727. ]
  728. ];
  729. *
  730. */
  731. public function addpigcar()
  732. {
  733. $pig_car = input('pig_car', '', 'trim'); //猪车信息json串: carnumber车牌号 carframenumber车架号 images车辆照片
  734. if (!$pig_car) {
  735. $this->error('请添加猪车信息');
  736. }
  737. $pig_car = json_decode($pig_car, true);
  738. if (!$pig_car) {
  739. $this->error('请添加猪车信息');
  740. }
  741. if (count($pig_car) > 9) {
  742. $this->error('一次最多添加9条记录');
  743. }
  744. $_data = [];
  745. foreach ($pig_car as &$v) {
  746. $data = [];
  747. if (!$v['carnumber']) {
  748. $this->error('请输入车牌号');
  749. break;
  750. }
  751. if (iconv_strlen($v['carnumber'], 'utf-8') > 50) {
  752. $this->error('车牌号最多50字');
  753. break;
  754. }
  755. if (!$v['carframenumber']) {
  756. $this->error('请输入车架号');
  757. break;
  758. }
  759. if (iconv_strlen($v['carframenumber'], 'utf-8') > 50) {
  760. $this->error('车架号最多50字');
  761. break;
  762. }
  763. if ($v['images']) {
  764. $image_arr = explode(',', $v['images']);
  765. if (count($image_arr) > 9) {
  766. $this->error('每辆车照片最多9张');
  767. break;
  768. }
  769. $data['images'] = $v['images'];
  770. }
  771. $data['user_id'] = $this->auth->id;
  772. $data['carnumber'] = $v['carnumber'];
  773. $data['carframenumber'] = $v['carframenumber'];
  774. $data['createtime'] = time();
  775. array_push($_data, $data);
  776. }
  777. $rs = Db::name('user_pig_car')->insertAll($_data);
  778. if (!$rs) {
  779. $this->error('添加失败');
  780. }
  781. $this->success('添加成功');
  782. }
  783. //删除猪车信息
  784. public function delpigcar()
  785. {
  786. $id = input('id', 0, 'intval'); //猪车id
  787. if (!$id) {
  788. $this->error('请选择要删除的猪车');
  789. }
  790. $info = Db::name('user_pig_car')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  791. if (!$info) {
  792. $this->error('这不是您的车');
  793. }
  794. $rs = Db::name('user_pig_car')->where(['id' => $id, 'user_id' => $this->auth->id])->delete();
  795. if (!$rs) {
  796. $this->error('删除失败');
  797. }
  798. $this->success('删除成功');
  799. }
  800. //平台介绍
  801. public function getabout()
  802. {
  803. $info = Db::name('platform_info')->field('title, content')->where(['type' => 1])->find();
  804. $this->success('平台介绍', $info);
  805. }
  806. //常见问题
  807. public function problem()
  808. {
  809. $list = Db::name('problem')->field('id, title, content')
  810. ->page($this->page, config('paginate.list_rows'))->order('weigh', 'desc')->select();
  811. $this->success('常见问题', $list);
  812. }
  813. //投诉举报类型
  814. public function complainttype()
  815. {
  816. $list = Db::name('complaint_type')->field('id, name')->where(['pid' => 0])->order('weigh', 'desc')->select();
  817. $list = $this->getchildtype($list);
  818. $this->success('常见问题', $list);
  819. }
  820. //无限级投诉举报类型
  821. public function getchildtype($list = [])
  822. {
  823. $complaint_type = Db::name('complaint_type');
  824. foreach ($list as &$v) {
  825. $child = $complaint_type->field('id, name')->where(['pid' => $v['id']])->order('weigh', 'desc')->select();
  826. if ($child) {
  827. $child = $this->getchildtype($child);
  828. }
  829. $v['child'] = $child;
  830. }
  831. return $list;
  832. }
  833. //投诉举报
  834. public function complaint()
  835. {
  836. $complaint_type = input('complaint_type', '', 'trim'); //投诉类型
  837. $order_sn = input('order_sn', '', 'trim'); //订单号
  838. $be_complaint_user = input('be_complaint_user', '', 'trim'); //被投诉人/单位
  839. $complaint_user = input('complaint_user', '', 'trim'); //投诉人
  840. $mobile = input('mobile', '', 'trim'); //联系电话
  841. $code = input('code', '', 'trim'); //验证码
  842. $content = input('content', '', 'trim'); //情况说明
  843. $images = input('images', '', 'trim'); //附件材料
  844. $data = [];
  845. if (!$complaint_type) {
  846. $this->error('请选择投诉类型');
  847. }
  848. if ($order_sn) {
  849. if (iconv_strlen($order_sn, 'utf-8') > 255) {
  850. $this->error('订单号最多255位');
  851. }
  852. //查询订单
  853. $count = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'order_sn' => $order_sn, 'status' => 1])->count();
  854. if (!$count) {
  855. $this->error('请输入正确中标订单号');
  856. }
  857. }
  858. if (!$be_complaint_user) {
  859. $this->error('请输入被投诉人/单位');
  860. }
  861. if (iconv_strlen($be_complaint_user, 'utf-8') > 50) {
  862. $this->error('被投诉人/单位最多50字');
  863. }
  864. if (!$complaint_user) {
  865. $this->error('请输入投诉人');
  866. }
  867. if (iconv_strlen($complaint_user, 'utf-8') > 50) {
  868. $this->error('投诉人最多50字');
  869. }
  870. if (!is_mobile($mobile)) {
  871. $this->error('请输入正确联系电话');
  872. }
  873. if (iconv_strlen($code, 'utf-8') != config('alisms.length')) {
  874. $this->error(__('Captcha is incorrect'));
  875. }
  876. $ret = Sms::check($mobile, $code, 'complaint');
  877. if (!$ret) {
  878. $this->error(__('Captcha is incorrect'));
  879. }
  880. if (!$content) {
  881. $this->error('请输入情况说明');
  882. }
  883. if (iconv_strlen($content, 'utf-8') > 3000) {
  884. $this->error('情况说明最多3000字');
  885. }
  886. if ($images) {
  887. $image_arr = explode(',', $images);
  888. if (count($image_arr) > 9) {
  889. $this->error('附件照片最多9张');
  890. }
  891. $data['images'] = $images;
  892. }
  893. $data['user_id'] = $this->auth->id;
  894. $data['complaint_type'] = $complaint_type;
  895. $data['order_sn'] = $order_sn;
  896. $data['be_complaint_user'] = $be_complaint_user;
  897. $data['complaint_user'] = $complaint_user;
  898. $data['mobile'] = $mobile;
  899. $data['content'] = $content;
  900. $data['images'] = $images;
  901. $data['createtime'] = time();
  902. $rs = Db::name('complaint')->insertGetId($data);
  903. if (!$rs) {
  904. $this->error('投诉失败');
  905. }
  906. Sms::flush($this->auth->mobile, 'complaint');
  907. $this->success('投诉成功');
  908. }
  909. //评价列表
  910. public function getmarkcomment()
  911. {
  912. $list = Db::name('mark_bid_comment')->where(['user_id' => $this->auth->id])
  913. ->page($this->page, config('paginate.list_rows'))->order('createtime', 'desc')->select();
  914. $list = list_domain_image($list, ['images']);
  915. $mark = Db::name('mark');
  916. $mark_bid = Db::name('mark_bid');
  917. foreach ($list as &$v) {
  918. $v['mark'] = $mark->find($v['mark_id']);
  919. $v['mark'] = info_domain_image($v['mark'], ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']);
  920. $v['order_sn'] = $mark_bid->where(['id' => $v['mark_bid_id']])->value('order_sn');
  921. }
  922. $this->success('评论列表', $list);
  923. }
  924. //评价
  925. public function markcomment()
  926. {
  927. $mark_id = input('mark_id', 0, 'intval'); //招标id
  928. $content = input('content', '', 'trim'); //情况说明
  929. $images = input('images', '', 'trim'); //附件材料
  930. $data = [];
  931. if (!$mark_id) {
  932. $this->error('请选择要评价的数据');
  933. }
  934. $info = Db::name('mark')->find($mark_id);
  935. if (!$info) {
  936. $this->error('招标信息不存在');
  937. }
  938. $bid_id = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'mark_id' => $mark_id, 'status' => 1])->value('id');
  939. if (!$bid_id) {
  940. $this->error('您未中标,暂不能评价');
  941. }
  942. if (!$content) {
  943. $this->error('请输入评价内容');
  944. }
  945. if (iconv_strlen($content, 'utf-8') > 3000) {
  946. $this->error('评价内容最多3000字');
  947. }
  948. if ($images) {
  949. $image_arr = explode(',', $images);
  950. if (count($image_arr) > 9) {
  951. $this->error('照片最多9张');
  952. }
  953. $data['images'] = $images;
  954. }
  955. $data['user_id'] = $this->auth->id;
  956. $data['mark_id'] = $mark_id;
  957. $data['mark_bid_id'] = $bid_id;
  958. $data['content'] = $content;
  959. $data['images'] = $images;
  960. $data['createtime'] = time();
  961. $rs = Db::name('mark_bid_comment')->insertGetId($data);
  962. if (!$rs) {
  963. $this->error('评价失败');
  964. }
  965. $this->success('评价成功');
  966. }
  967. //个人账单列表
  968. public function getcompanymoney()
  969. {
  970. $list = Db::name('company')->field('id, name')->page($this->page, config('paginate.list_rows'))->select();
  971. $company_money_log = Db::name('company_money_log');
  972. foreach ($list as &$v) {
  973. $log = $company_money_log->where(['company_id' => $v['id'], 'user_id' => $this->auth->id])->order('id', 'desc')->find();
  974. if ($log) {
  975. $v['money'] = $log['after'];
  976. $v['can_money'] = $log['after'];
  977. } else {
  978. $v['money'] = '0';
  979. $v['can_money'] = '0';
  980. }
  981. }
  982. $this->success('个人账单列表', $list);
  983. }
  984. //个人账单明细
  985. public function getcompanymoneydetail()
  986. {
  987. $company_id = input('company_id', 0, 'intval'); //公司id
  988. $start_time = input('start_time', 0, 'strtotime'); //开始时间
  989. $end_time = input('end_time', 0, 'strtotime'); //结束时间
  990. if (!$company_id) {
  991. $this->error('参数缺失');
  992. }
  993. $where['company_id'] = $company_id;
  994. $where['user_id'] = $this->auth->id;
  995. if ($start_time && $end_time) {
  996. $where['createtime'] = ['between', [$start_time, $end_time]];
  997. }
  998. $list = Db::name('company_money_log')->field('id, money, memo, createtime')
  999. ->where($where)->page($this->page, config('paginate.list_rows'))->order('id', 'desc')->select();
  1000. foreach ($list as &$v) {
  1001. $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
  1002. }
  1003. $data['income'] = Db::name('company_money_log')->where($where)->where(['money' => ['gt', 0]])->sum('money');
  1004. $data['expend'] = Db::name('company_money_log')->where($where)->where(['money' => ['lt', 0]])->sum('money');
  1005. $data['list'] = $list;
  1006. $this->success('个人账单明细', $data);
  1007. }
  1008. //获取openid
  1009. public function getopenid() {
  1010. //code
  1011. $code = $this->request->param('code', '', 'trim');// code值
  1012. if (!$code) {
  1013. $this->error(__('Invalid parameters'));
  1014. }
  1015. $config = config('wxchatpay');
  1016. $getopenid_url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['app_id'].'&secret='.$config['app_secret'].'&js_code='.$code.'&grant_type=authorization_code';
  1017. $openidInfo = httpRequest($getopenid_url, 'GET');//$this->getJson($getopenid_url);
  1018. $openidInfo = json_decode($openidInfo,true);
  1019. if(!isset($openidInfo['openid'])) {
  1020. $this->error('用户openid获取失败', $openidInfo);
  1021. }
  1022. $this->success('success', $openidInfo);
  1023. }
  1024. //微信登录
  1025. public function wxlogin() {
  1026. $openid = input('openid', '', 'trim');
  1027. if (!$openid) {
  1028. $this->error('参数缺失');
  1029. }
  1030. $user = \app\common\model\User::getByOpenid($openid);
  1031. if (!$user) {
  1032. $this->success('用户尚未注册', ['code' => 5]);
  1033. }
  1034. if ($user['status'] != 1) {
  1035. $this->error(__('Account is locked'));
  1036. }
  1037. $ret = $this->auth->direct($user->id);
  1038. if ($ret) {
  1039. $data = ['userinfo' => $this->auth->getUserinfo()];
  1040. $this->success(__('Logged in successful'), $data);
  1041. } else {
  1042. $this->error($this->auth->getError());
  1043. }
  1044. }
  1045. //注册
  1046. public function register()
  1047. {
  1048. $realname = input('realname', '', 'trim'); //真实姓名
  1049. $height = input('height', 170, 'intval'); //身高
  1050. $weight = input('weight', 60, 'intval'); //体重
  1051. $birthday = $this->request->post('birthday', '', 'strtotime'); //生日
  1052. $province_id = input('province_id', 0, 'intval'); //省id
  1053. $city_id = input('city_id', 0, 'intval'); //市id
  1054. $area_id = input('area_id', 0, 'intval'); //区id
  1055. $mobile = $this->request->post('mobile', '', 'trim'); //手机号
  1056. // $code = $this->request->post('code', '', 'trim'); //验证码
  1057. $idcard = input('idcard', '', 'trim'); //身份证号
  1058. $excel_position = input('excel_position', '', 'trim'); //擅长位置
  1059. // $gender = $this->request->post('gender', 0, 'intval'); //性别:1=男,2=女
  1060. // $invite_no = $this->request->post('invite_no', '', 'trim'); //邀请码
  1061. $openid = $this->request->post('openid', '', 'trim'); //微信openid
  1062. // $nickname = $this->request->post('nickname', '', 'trim'); //微信昵称
  1063. // $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars'); //微信头像
  1064. $openidcount = Db::name('user')->where(['openid' => $openid])->count('id');
  1065. if ($openidcount) {
  1066. $this->error('微信已经注册,请直接登录');
  1067. }
  1068. if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
  1069. $this->error('真实姓名1-30位');
  1070. }
  1071. if ($height <= 0) {
  1072. $this->error('请选择正确身高');
  1073. }
  1074. if ($weight <= 0) {
  1075. $this->error('请选择正确体重');
  1076. }
  1077. if (!$birthday || $birthday >= time()) {
  1078. $this->error('请选择正确生日');
  1079. }
  1080. if (!$province_id || !$city_id || !$area_id) {
  1081. $this->error('请选择地区');
  1082. }
  1083. if (!Validate::regex($mobile, "^1\d{10}$")) {
  1084. $this->error(__('Mobile is incorrect'));
  1085. }
  1086. $count = Db::name('user')->where(['mobile' => $mobile])->count('id');
  1087. if ($count) {
  1088. $this->error('手机号已被注册');
  1089. }
  1090. // if (iconv_strlen($code, 'utf-8') != config('alisms.length')) {
  1091. // $this->error(__('Captcha is incorrect'));
  1092. // }
  1093. // $ret = Sms::check($mobile, $code, 'register');
  1094. // if (!$ret) {
  1095. // $this->error(__('Captcha is incorrect'));
  1096. // }
  1097. // if (!in_array($gender, [1, 2])) {
  1098. // $this->error('请选择性别');
  1099. // }
  1100. // if ($invite_no) {
  1101. // $invite_info = Db::name('user')->where(['invite_no' => $invite_no])->find();
  1102. // if (!$invite_info) {
  1103. // $this->error('邀请码不存在');
  1104. // }
  1105. // }
  1106. if (iconv_strlen($idcard, 'utf-8') != 18) {
  1107. $this->error('请输入正确身份证号');
  1108. }
  1109. if ($excel_position === '' || iconv_strlen($excel_position, 'utf-8') > 30) {
  1110. $this->error('请选择擅长位置');
  1111. }
  1112. // if (!$nickname || !$avatar) {
  1113. // $this->error('参数缺失');
  1114. // }
  1115. // if (iconv_strlen($nickname, 'utf-8') > 30 || iconv_strlen($avatar, 'utf-8') > 255) {
  1116. // $this->error('参数错误');
  1117. // }
  1118. $ip = request()->ip();
  1119. $time = time();
  1120. $data = [
  1121. // 'nickname' => $nickname,
  1122. 'salt' => Random::alnum(),
  1123. 'mobile' => $mobile,
  1124. 'avatar' => config('logo'),//$avatar,
  1125. 'joinip' => $ip,
  1126. 'jointime' => $time,
  1127. 'logintime' => $time,
  1128. 'loginip' => $ip,
  1129. 'prevtime' => $time,
  1130. 'createtime' => $time,
  1131. // 'gender' => $gender,
  1132. 'birthday' => $birthday,
  1133. 'openid' => $openid,
  1134. 'invite_no' => $this->myinvite(),
  1135. 'pre_user_id' => isset($invite_info) ? $invite_info['id'] : 0,
  1136. 'invite_time' => $time,
  1137. 'realname' => $realname,
  1138. 'height' => $height,
  1139. 'weight' => $weight,
  1140. 'province_id' => $province_id,
  1141. 'city_id' => $city_id,
  1142. 'area_id' => $area_id,
  1143. 'idcard' => $idcard,
  1144. 'excel_position' => $excel_position,
  1145. ];
  1146. //开启事务
  1147. Db::startTrans();
  1148. $rs = Db::name('user')->insertGetId($data);
  1149. if (!$rs) {
  1150. Db::rollback();
  1151. $this->error('注册失败');
  1152. }
  1153. //生成uid
  1154. $username = $this->myuid($rs);
  1155. $rt = Db::name('user')->where(['id' => $rs])->setField(['username' => $username, 'nickname' => '球员' . $username]);
  1156. if (!$rt) {
  1157. Db::rollback();
  1158. $this->error('注册失败');
  1159. }
  1160. Db::commit();
  1161. $ret = $this->auth->direct($rs);
  1162. if ($ret) {
  1163. $data = ['userinfo' => $this->auth->getUserinfo()];
  1164. $this->success(__('Sign up successful'), $data);
  1165. } else {
  1166. $this->error($this->auth->getError());
  1167. }
  1168. }
  1169. //生成邀请码
  1170. public function myinvite() {
  1171. $invite = Random::alnum(7);
  1172. $count = Db::name('user')->where(['invite_no' => $invite])->count('id');
  1173. if ($count) {
  1174. $this->myinvite();
  1175. }
  1176. return $invite;
  1177. }
  1178. //生成uid
  1179. public function myuid($id = 0) {
  1180. if (strlen($id) < 8) {
  1181. $username_len = 8 - strlen($id);
  1182. $username = $id . Random::numeric($username_len);
  1183. } else {
  1184. $username = $id;
  1185. }
  1186. $count = Db::name('user')->where(['username' => $username])->count('id');
  1187. if ($count) {
  1188. $this->myuid($id);
  1189. }
  1190. return $username;
  1191. }
  1192. //查询是否有未读消息
  1193. public function getreadsysmsg() {
  1194. $count = Db::name('sys_msg')->where(['user_id' => $this->auth->id, 'is_read' => 0])->count('id');
  1195. $this->success('查询是否有未读消息', $count);
  1196. }
  1197. //消息列表
  1198. public function sysmsg() {
  1199. $list = Db::name('sys_msg')->field('id, title, content, createtime')->where(['user_id' => $this->auth->id])
  1200. ->page($this->page, $this->pagenum)->order('id desc')->select();
  1201. foreach ($list as &$v) {
  1202. $v['createtime'] = date('Y-m-d H:i', $v['createtime']);
  1203. }
  1204. //更改消息状态
  1205. Db::name('sys_msg')->where(['user_id' => $this->auth->id, 'is_read' => 0])->setField('is_read', 1);
  1206. $this->success('消息列表', $list);
  1207. }
  1208. //查询当前会员等级信息
  1209. public function uservip() {
  1210. //更新会员等级
  1211. $this->checkviplevel($this->auth->id);
  1212. //用户信息
  1213. $user = Db::name('user')->find($this->auth->id);
  1214. //会员信息
  1215. $vip_info = Db::name('vip')->find($user['maxlevel']);
  1216. //下一级所需成长值
  1217. $next_vip = Db::name('vip')->where(['id' => ['gt', $user['maxlevel']]])->find();
  1218. if (!$next_vip || $next_vip['id'] == 5) {
  1219. //顶部信息
  1220. $vip_info['vip_desc'] = '已是最高会员';
  1221. //成长值百分比0-100
  1222. $vip_info['growthvalue_percentage'] = 100;
  1223. } else {
  1224. //顶部信息
  1225. $need_growthvalue = $next_vip['growthvalue'] - $user['growthvalue'];
  1226. $vip_info['vip_desc'] = $vip_info['title'] . '还需' . $need_growthvalue . '成长值成为' . $next_vip['title'];
  1227. //成长值百分比0-100
  1228. $vip_info['growthvalue_percentage'] = ceil($user['growthvalue'] / $next_vip['growthvalue'] * 100);
  1229. }
  1230. //体验会员到期时间
  1231. $vip_info['experiencetime'] = $user['experiencetime'] > time() ? date('Y-m-d', $user['experiencetime']) : '';
  1232. //判断是不是生日 1是 0否
  1233. $vip_info['is_birth'] = date('md', time()) == date('md', strtotime($this->auth->birthday)) ? 1: 0;
  1234. $this->success('查询当前会员等级信息', $vip_info);
  1235. }
  1236. //查询所有会员
  1237. public function vip() {
  1238. //更新会员等级
  1239. $this->checkviplevel($this->auth->id);
  1240. //用户信息
  1241. $user = Db::name('user')->find($this->auth->id);
  1242. //会员信息
  1243. $vip_info = Db::name('vip')->find($user['growthlevel']);
  1244. //下一级所需成长值
  1245. $next_vip = Db::name('vip')->where(['id' => ['gt', $user['growthlevel']]])->find();
  1246. if (!$next_vip || $next_vip['id'] == 5) {
  1247. //顶部信息
  1248. $vip_info['vip_desc'] = '已是最高会员';
  1249. //成长值百分比0-100
  1250. $vip_info['growthvalue_percentage'] = 100;
  1251. } else {
  1252. //顶部信息
  1253. $need_growthvalue = $next_vip['growthvalue'] - $user['growthvalue'];
  1254. $vip_info['vip_desc'] = $vip_info['title'] . '还需' . $need_growthvalue . '成长值成为' . $next_vip['title'];
  1255. //成长值百分比0-100
  1256. $vip_info['growthvalue_percentage'] = ceil($user['growthvalue'] / $next_vip['growthvalue'] * 100);
  1257. }
  1258. //所有会员列表
  1259. $where = [];
  1260. if ($this->auth->maxlevel != 5) {
  1261. $where['id'] = ['neq', 5];
  1262. }
  1263. $list = Db::name('vip')->where($where)->select();
  1264. $vip_privilege = Db::name('vip_privilege');
  1265. foreach ($list as $k => &$v) {
  1266. $v['vip_desc'] = ''; //顶部信息
  1267. $v['growthvalue_percentage'] = 0; //成长值百分比0-100
  1268. $v['experiencetime'] = ''; //体验会员到期时间
  1269. if ($v['id'] == $user['maxlevel']) {
  1270. $v['now_level'] = 1; //是否是当前等级 1是 0否
  1271. if ($user['maxlevel'] == $user['experiencelevel'] && $user['experiencetime'] > time()) {
  1272. //实际有效会员ID是体验会员id时, 展示体验会员到期时间
  1273. $v['experiencetime'] = '有效期至' . date('Y-m-d', $user['experiencetime']);
  1274. }
  1275. } else {
  1276. $v['now_level'] = 0;
  1277. }
  1278. if ($v['id'] == $user['growthlevel']) {
  1279. $v = array_merge($v, $vip_info);
  1280. }
  1281. $v['vip_privilege'] = $vip_privilege->field('id, title, desc')
  1282. ->where(['vip_id' => $v['id']])->order('weigh desc')->select();
  1283. }
  1284. $this->success('查询所有会员', $list);
  1285. }
  1286. //意见反馈
  1287. public function feedback() {
  1288. $content = input('content', '', 'trim'); //问题描述
  1289. $images = input('images', '', 'trim'); //反馈图片,最多9张用,拼接
  1290. $mobile = input('mobile', '', 'trim'); //联系电话
  1291. $data = [];
  1292. if (!$content) {
  1293. $this->error('请输入情况说明');
  1294. }
  1295. if (iconv_strlen($content, 'utf-8') > 3000) {
  1296. $this->error('情况说明最多3000字');
  1297. }
  1298. if ($images) {
  1299. $image_arr = explode(',', $images);
  1300. if (count($image_arr) > 9) {
  1301. $this->error('附件照片最多9张');
  1302. }
  1303. $data['images'] = $images;
  1304. }
  1305. if (!is_mobile($mobile)) {
  1306. $this->error('请输入正确联系电话');
  1307. }
  1308. $data['user_id'] = $this->auth->id;
  1309. $data['content'] = $content;
  1310. $data['images'] = $images;
  1311. $data['mobile'] = $mobile;
  1312. $data['createtime'] = time();
  1313. $rs = Db::name('feedback')->insertGetId($data);
  1314. if (!$rs) {
  1315. $this->error('反馈失败');
  1316. }
  1317. $this->success('反馈成功');
  1318. }
  1319. //我的优惠券
  1320. public function mycoupon() {
  1321. $type = input('type', 0, 'intval'); //类型:1未使用 2已使用 3已过期
  1322. if (!in_array($type, [1, 2, 3])) {
  1323. $this->error('参数错误');
  1324. }
  1325. $where['user_id'] = $this->auth->id;
  1326. if ($type == 1) {
  1327. $where['endtime'] = ['egt', time()];
  1328. $where['status'] = 0;
  1329. } elseif ($type == 2) {
  1330. $where['status'] = 1;
  1331. } elseif ($type == 3) {
  1332. $where['endtime'] = ['lt', time()];
  1333. $where['status'] = 0;
  1334. }
  1335. $list = Db::name('user_coupon')->field('id, title, desc, type, money, minmoney, endtime')->where($where)->page($this->page, $this->pagenum)->select();
  1336. foreach ($list as &$v) {
  1337. $v['endtime'] = date('Y-m-d', $v['endtime']);
  1338. }
  1339. $this->success('我的优惠券', $list);
  1340. }
  1341. //充值列表
  1342. public function rechargelist() {
  1343. $list = Db::name('recharge')->field('id, title, price, coupon_id, couponnum')->order('weigh desc')->select();
  1344. $coupon = Db::name('coupon');
  1345. foreach ($list as &$v) {
  1346. $coupon_info = $coupon->find($v['coupon_id']);
  1347. if ($coupon_info) {
  1348. if ($coupon_info['type'] == 1) {
  1349. $v['coupon_title'] = $coupon_info['money'] . '折';
  1350. } else {
  1351. $v['coupon_title'] = $coupon_info['money'] . '元';
  1352. }
  1353. } else {
  1354. $v['coupon_title'] = '';
  1355. }
  1356. }
  1357. $this->success('充值列表', $list);
  1358. }
  1359. //资金明细
  1360. public function usermoneylog() {
  1361. $list = Db::name('user_money_log')->field('id, money, memo, createtime')
  1362. ->where(['user_id' => $this->auth->id])
  1363. ->page($this->page, $this->pagenum)
  1364. ->order('id desc')->select();
  1365. foreach ($list as &$v) {
  1366. $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
  1367. }
  1368. $this->success('资金明细', $list);
  1369. }
  1370. //充值
  1371. public function recharge() {
  1372. $id = input('id', 0, 'intval');
  1373. if (!$id) {
  1374. $this->error('参数缺失');
  1375. }
  1376. $info = Db::name('recharge')->where(['id' => $id])->find();
  1377. if (!$info) {
  1378. $this->error('充值金额不存在');
  1379. }
  1380. if ($info['price'] <= 0) {
  1381. $this->error('充值价格异常');
  1382. }
  1383. //生成支付订单记录
  1384. $rechar_order['user_id'] = $this->auth->id;
  1385. $rechar_order['order_no'] = date('YmdHis', time()) . rand(10000000, 99999999); //微信订单编号
  1386. $rechar_order['money'] = $info['price'];
  1387. $rechar_order['purpose'] = 2; //充值用途:1=支付订单,2=充值,3=开通会员
  1388. $rechar_order['pay_type'] = 'wechat';
  1389. $rechar_order['relation_id'] = $id;
  1390. $rechar_order['createtime'] = time();
  1391. //开始事务
  1392. $result = Db::name('rechar_order')->insertGetId($rechar_order);
  1393. if (!$result) {
  1394. $this->error('网络延迟,请稍后再试');
  1395. }
  1396. //构建支付链接数据
  1397. $wxData['body'] = '充值';
  1398. $wxData['out_trade_no'] = $rechar_order['order_no'];
  1399. $wxData['total_fee'] = $info['price'];
  1400. // $wxData['total_fee'] = 0.01;
  1401. $wxData['openid'] = $this->auth->openid;
  1402. // require_once($_SERVER['DOCUMENT_ROOT'] . '/Plugins/Weixin/WxPay/WxPay.php');
  1403. $wxPay = new wxpay\WxPay(config('wxchatpay'));
  1404. $doResult = $wxPay->WxPayJs($wxData);
  1405. $this->success('微信支付参数返回成功', $doResult);
  1406. }
  1407. //邀请好友顶部信息
  1408. public function invitetop() {
  1409. $data['invite_no'] = $this->auth->invite_no; //邀请码
  1410. $data['invite_count'] = Db::name('user')->where(['pre_user_id' => $this->auth->id])->count('id'); //邀请人数
  1411. $data['coupon_count'] = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'purpose' => ['in', [2, 5]]])->count('id');
  1412. $this->success('邀请好友顶部信息', $data);
  1413. }
  1414. //邀请好友底部列表
  1415. public function invitebottom() {
  1416. $type = input('type', 0, 'intval'); //1邀请的好友 2报名的好友
  1417. if (!in_array($type, [1, 2])) {
  1418. $this->error('参数错误');
  1419. }
  1420. if ($type == 1) {
  1421. $list = Db::name('user')->field('id, avatar, nickname, invite_time')
  1422. ->where(['pre_user_id' => $this->auth->id])->page($this->page, $this->pagenum)->order('id desc')->select();
  1423. } else {
  1424. $invite_ids = Db::name('user')->where(['pre_user_id' => $this->auth->id])->column('id');
  1425. if (!$invite_ids) {
  1426. $this->success('报名好友列表', []);
  1427. }
  1428. $list = Db::name('active_order')->alias('a')
  1429. ->join('hu_user b', 'a.user_id = b.id', 'left')
  1430. ->field('b.id, b.avatar, b.nickname, b.invite_time')
  1431. ->where(['a.user_id' => ['in', $invite_ids]])
  1432. ->page($this->page, $this->pagenum)
  1433. ->order('a.id desc')->select();
  1434. }
  1435. $list = list_domain_image($list, ['avatar']);
  1436. foreach ($list as &$v) {
  1437. $v['invite_time'] = date('Y-m-d', $v['invite_time']);
  1438. }
  1439. $this->success('邀请好友底部列表', $list);
  1440. }
  1441. //我的订单
  1442. public function myorder() {
  1443. $type = input('type', 0, 'intval'); //状态:0=待付款,1=待出行,2=已完成,3=已取消
  1444. if (!in_array($type, [0, 1, 2, 3])) {
  1445. $this->error('参数错误');
  1446. }
  1447. $list = Db::name('active_order')->where(['user_id' => $this->auth->id, 'status' => $type])->page($this->page, $this->pagenum)->order('id desc')->select();
  1448. $active = Db::name('active');
  1449. foreach ($list as &$v) {
  1450. $v['button_status'] = 0;//待出行按钮: 0不展示 1退款 2修改联系人
  1451. $v['active'] = $active->find($v['active_id']);
  1452. $v['active'] = info_domain_image($v['active'], ['image']);
  1453. if ($v['status'] == 1) {
  1454. if ($v['active']['refundendtime'] >= time()) {
  1455. $v['button_status'] = 1;
  1456. } elseif ($v['active']['refundendtime'] < time() && $v['active']['signupendtime'] >= time()) {
  1457. $v['button_status'] = 2;
  1458. }
  1459. }
  1460. if ($v['active']['maxperson'] <= $v['active']['currentperson']) {
  1461. $v['is_full'] = 1; //已报满
  1462. } else {
  1463. $v['is_full'] = 0; //未报满
  1464. }
  1465. }
  1466. $this->success('我的订单', $list);
  1467. }
  1468. //我的订单详情
  1469. public function myorderinfo() {
  1470. $id = input('id', 0, 'intval'); //订单id
  1471. if (!$id) {
  1472. $this->error('参数缺失');
  1473. }
  1474. $info = Db::name('active_order')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1475. if (!$info) {
  1476. $this->error('数据不存在');
  1477. }
  1478. $info['createtime'] = date('Y-m-d H:i:s', $info['createtime']);
  1479. //查询活动信息
  1480. $active = Db::name('active')->find($info['active_id']);
  1481. //待出行按钮: 0不展示 1退款 2修改联系人
  1482. $info['button_status'] = 0;
  1483. if ($info['status'] == 1) {
  1484. if ($active['refundendtime'] >= time()) {
  1485. $info['button_status'] = 1;
  1486. } elseif ($active['refundendtime'] < time() && $active['signupendtime'] >= time()) {
  1487. $info['button_status'] = 2;
  1488. }
  1489. }
  1490. $active = info_domain_image($active, ['image']);
  1491. $active['starttime'] = date('Y-m-d H:i', $active['starttime']);
  1492. $active['endtime'] = date('Y-m-d H:i', $active['endtime']);
  1493. $active['collectiontime'] = date('Y-m-d H:i', $active['collectiontime']);
  1494. $active['signupendtime'] = date('Y-m-d H:i', $active['signupendtime']);
  1495. $active['refundendtime'] = date('Y-m-d H:i', $active['refundendtime']);
  1496. //查询报名人员
  1497. $active_people = Db::name('active_people')->where(['order_id' => $id])->field('id, name, mobile')->select();
  1498. $info['active'] = $active;
  1499. $info['active_people'] = $active_people;
  1500. $this->success('我的订单详情', $info);
  1501. }
  1502. //查看报名人信息
  1503. public function activepeople() {
  1504. $id = input('id', 0, 'intval'); //报名人员id
  1505. if (!$id) {
  1506. $this->error('参数缺失');
  1507. }
  1508. $info = Db::name('active_people')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1509. if (!$info) {
  1510. $this->error('数据不存在');
  1511. }
  1512. $this->success('查看报名人信息', $info);
  1513. }
  1514. //修改报名人信息
  1515. public function modifyactivepeople() {
  1516. $id = input('id', 0, 'intval'); //报名人员id
  1517. $collectionplace = input('collectionplace', '', 'trim'); //集合地点
  1518. $name = input('name', '', 'trim'); //姓名
  1519. $idcard = input('idcard', '', 'trim'); //身份证号
  1520. $mobile = input('mobile', '', 'trim'); //手机号
  1521. $emergencycontact = input('emergencycontact', '', 'trim'); //紧急联系人
  1522. $contactmobile = input('contactmobile', '', 'trim'); //紧急联系方式
  1523. if (!$id) {
  1524. $this->error('参数缺失');
  1525. }
  1526. $info = Db::name('active_people')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1527. if (!$info) {
  1528. $this->error('数据不存在');
  1529. }
  1530. if ($info['status'] == 2) {
  1531. $this->success('订单已经结束');
  1532. }
  1533. if ($info['status'] == 3) {
  1534. $this->success('订单已经取消');
  1535. }
  1536. if ($info['modifystatus'] == 1) {
  1537. $this->error('报名信息正在修改中,请等待后台审核');
  1538. }
  1539. //查询活动状态
  1540. $active = Db::name('active')->find($info['active_id']);
  1541. if (!$active) {
  1542. $this->success('活动不存在或已取消');
  1543. }
  1544. // if ($active['status'] == 1) {
  1545. // $this->error('活动已成行,不能修改信息');
  1546. // }
  1547. if (time() <= $active['refundendtime'] || time() > $active['signupendtime']) {
  1548. $this->error('当前时间段暂不可修改信息');
  1549. }
  1550. //查询是否申请过退款
  1551. $active_refund = Db::name('active_refund')->where(['order_id' => $info['active_id'], 'status' => 0])->count('id');
  1552. if ($active_refund) {
  1553. $this->error('您正在申请退款,暂不可修改信息');
  1554. }
  1555. //检查信息
  1556. if ($collectionplace === '' || iconv_strlen($collectionplace, 'utf-8') > 255) {
  1557. $this->error('请选择集合地点');
  1558. }
  1559. if (!$name || iconv_strlen($name, 'utf-8') > 50) {
  1560. $this->error('请输入正确姓名');
  1561. }
  1562. if (iconv_strlen($idcard, 'utf-8') != 18) {
  1563. $this->error('请输入正确身份证号');
  1564. }
  1565. if (!is_mobile($mobile)) {
  1566. $this->error('请输入正确手机号');
  1567. }
  1568. if (!$emergencycontact || iconv_strlen($emergencycontact, 'utf-8') > 50) {
  1569. $this->error('请输入紧急联系人');
  1570. }
  1571. if (!is_mobile($contactmobile)) {
  1572. $this->error('请输入正确紧急联系人方式');
  1573. }
  1574. //判断是否报名过
  1575. $count = Db::name('active_people')->where(['active_id' => $info['active_id'], 'idcard' => $idcard, 'status' => ['neq', 3]])->count('id');
  1576. if ($count) {
  1577. $this->error('该信息已报名过活动');
  1578. }
  1579. $count2 = Db::name('active_people_modify')->where(['active_id' => $info['active_id'], 'idcard' => $idcard, 'status' => 0])->count('id');
  1580. if ($count2) {
  1581. $this->error('该信息已提交过修改,请等待审核');
  1582. }
  1583. //构建修改数据
  1584. $data = [
  1585. 'active_id' => $info['active_id'],
  1586. 'order_id' => $info['order_id'],
  1587. 'people_id' => $id,
  1588. 'user_id' => $info['user_id'],
  1589. 'collectionplace' => $collectionplace,
  1590. 'name' => $name,
  1591. 'credtype' => $info['credtype'],
  1592. 'idcard' => $idcard,
  1593. 'mobile' => $mobile,
  1594. 'emergencycontact' => $emergencycontact,
  1595. 'contactmobile' => $contactmobile,
  1596. 'insurance' => $info['insurance'],
  1597. 'originalprice' => $info['originalprice'],
  1598. 'vipprice' => $info['vipprice'],
  1599. 'coupon_id' => $info['coupon_id'],
  1600. 'coupontype' => $info['coupontype'],
  1601. 'couponprice' => $info['couponprice'],
  1602. 'is_free' => $info['is_free'],
  1603. 'price' => $info['price'],
  1604. 'is_self' => $info['is_self'],
  1605. 'createtime' => time()
  1606. ];
  1607. //开启事务
  1608. Db::startTrans();
  1609. //添加记录
  1610. $rs = Db::name('active_people_modify')->insertGetId($data);
  1611. if (!$rs) {
  1612. Db::rollback();
  1613. $this->error('修改失败');
  1614. }
  1615. //修改原记录状态
  1616. $rt = Db::name('active_people')->where(['id' => $id, 'modifystatus' => 0])->setField('modifystatus', 1);
  1617. if (!$rt) {
  1618. Db::rollback();
  1619. $this->error('修改失败');
  1620. }
  1621. Db::commit();
  1622. $this->success('修改成功,请等待审核');
  1623. }
  1624. //取消订单
  1625. public function cancelorder() {
  1626. $id = input('id', 0, 'intval'); //订单id
  1627. if (!$id) {
  1628. $this->error('参数缺失');
  1629. }
  1630. $info = Db::name('active_order')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1631. if (!$info) {
  1632. $this->error('数据不存在');
  1633. }
  1634. if ($info['status'] != 0) {
  1635. $this->error('网络延迟,请刷新重试');
  1636. }
  1637. if ($info['createtime'] + 1800 < time()) {
  1638. $this->error('订单超时,系统将自动取消');
  1639. }
  1640. //查询活动是否存在
  1641. $active_info = Db::name('active')->find($info['active_id']);
  1642. if (!$active_info) {
  1643. $this->error('活动不存在');
  1644. }
  1645. //开启事务
  1646. Db::startTrans();
  1647. //修改订单信息
  1648. $rs = Db::name('active_order')->where(['id' => $id, 'status' => 0])->setField('status', 3);
  1649. if (!$rs) {
  1650. Db::rollback();
  1651. $this->error('网络延迟,请稍后再试');
  1652. }
  1653. //修改活动人员
  1654. $rt = Db::name('active_people')->where(['order_id' => $id, 'status' => 0])->setField(['status' => 3, 'modifystatus' => 0]);
  1655. if (!$rt) {
  1656. Db::rollback();
  1657. $this->error('网络延迟,请稍后再试');
  1658. }
  1659. //修改活动人员修改记录
  1660. $res = Db::name('active_people_modify')->where(['order_id' => $id, 'status' => 0])->setField('status', 2);
  1661. if ($res === false) {
  1662. Db::rollback();
  1663. $this->error('网络延迟,请稍后再试');
  1664. }
  1665. //减少活动已报名人数
  1666. $currentperson = $active_info['currentperson'] - $info['number'];
  1667. $active_rs = Db::name('active')->where(['id' => $info['active_id'], 'currentperson' => $active_info['currentperson']])->setField('currentperson', $currentperson);
  1668. if (!$active_rs) {
  1669. Db::rollback();
  1670. $this->error('网络延迟,请稍后再试');
  1671. }
  1672. Db::commit();
  1673. $this->success('修改成功');
  1674. }
  1675. //支付订单
  1676. public function payorder() {
  1677. $id = input('id', 0, 'intval'); //订单id
  1678. if (!$id) {
  1679. $this->error('参数缺失');
  1680. }
  1681. $info = Db::name('active_order')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1682. if (!$info) {
  1683. $this->error('数据不存在');
  1684. }
  1685. if ($info['status'] != 0) {
  1686. $this->error('当前订单状态不能支付');
  1687. }
  1688. if ($info['createtime'] + 1800 < time()) {
  1689. $this->error('订单支付超时,请重新报名');
  1690. }
  1691. //查询活动是否存在
  1692. $active_info = Db::name('active')->find($info['active_id']);
  1693. if (!$active_info) {
  1694. $this->error('活动不存在');
  1695. }
  1696. if ($active_info['status'] == 2) {
  1697. $this->error('活动已经结束');
  1698. }
  1699. if ($active_info['status'] == 3) {
  1700. $this->error('活动已取消');
  1701. }
  1702. $pay_count = Db::name('rechar_order')->where(['user_id' => $this->auth->id, 'purpose' => 1, 'pay_type' => 'wechat', 'relation_id' => $id, 'status' => 1])->count('id');
  1703. if ($pay_count) {
  1704. $this->error('您已成功支付过,请勿重复支付');
  1705. }
  1706. //生成支付订单记录
  1707. $rechar_order['user_id'] = $this->auth->id;
  1708. $rechar_order['order_no'] = date('YmdHis', time()) . rand(10000000, 99999999); //微信订单编号
  1709. $rechar_order['money'] = $info['price'];
  1710. $rechar_order['purpose'] = 1; //充值用途:1=支付订单,2=充值,3=开通会员
  1711. $rechar_order['pay_type'] = 'wechat';
  1712. $rechar_order['relation_id'] = $id;
  1713. $rechar_order['createtime'] = time();
  1714. $result = Db::name('rechar_order')->insertGetId($rechar_order);
  1715. if (!$result) {
  1716. $this->error('网络延迟,请稍后再试');
  1717. }
  1718. //构建支付链接数据
  1719. $wxData['body'] = '报名活动支付';
  1720. $wxData['out_trade_no'] = $rechar_order['order_no'];
  1721. $wxData['total_fee'] = $info['price'];
  1722. // $wxData['total_fee'] = 0.01;
  1723. $wxData['openid'] = $this->auth->openid;
  1724. // require_once($_SERVER['DOCUMENT_ROOT'] . '/Plugins/Weixin/WxPay/WxPay.php');
  1725. $wxPay = new wxpay\WxPay(config('wxchatpay'));
  1726. $doResult = $wxPay->WxPayJs($wxData);
  1727. $this->success('微信支付参数返回成功', $doResult);
  1728. }
  1729. //申请退款
  1730. public function applyrefund() {
  1731. $id = input('id', 0, 'intval'); //订单id
  1732. if (!$id) {
  1733. $this->error('参数缺失');
  1734. }
  1735. $info = Db::name('active_order')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1736. if (!$info) {
  1737. $this->error('数据不存在');
  1738. }
  1739. if ($info['status'] != 1) {
  1740. $this->error('当前订单状态不能退款');
  1741. }
  1742. //查询是否已经申请过
  1743. $count = Db::name('active_refund')->where(['order_id' => $id, 'status' => 0])->count('id');
  1744. if ($count) {
  1745. $this->error('您已申请过退款,请等待后台审核');
  1746. }
  1747. //查询活动是否存在
  1748. $active_info = Db::name('active')->find($info['active_id']);
  1749. if (!$active_info) {
  1750. $this->error('活动不存在');
  1751. }
  1752. if (time() > $active_info['refundendtime']) {
  1753. $this->error('已超过退款截止时间,暂不能退款');
  1754. }
  1755. //用户取消订单每人扣费金额(元)
  1756. $cancelorder_price = config('site.cancelorder');
  1757. if ($cancelorder_price < 0) {
  1758. $this->error('退款手续费异常,请联系管理员');
  1759. }
  1760. //退款金额
  1761. $refundprice = number_format($info['price'] - $cancelorder_price * $info['number'], 2, '.', '');
  1762. $refundprice = $refundprice > 0 ? $refundprice : 0;
  1763. //构建申请数据
  1764. $data = [
  1765. 'active_id' => $info['active_id'],
  1766. 'order_id' => $id,
  1767. 'user_id' => $this->auth->id,
  1768. 'paytype' => $info['paytype'],
  1769. 'price' => $info['price'],
  1770. 'number' => $info['number'],
  1771. 'transaction_id' => $info['transaction_id'],
  1772. 'refund_no' => $info['paytype'] ? date('YmdHis', time()) . rand(10000000, 99999999) : '', //退款单号
  1773. 'refundprice' => $refundprice,
  1774. 'createtime' => time()
  1775. ];
  1776. $rs = Db::name('active_refund')->insertGetId($data);
  1777. if (!$rs) {
  1778. $this->error('申请退款失败');
  1779. }
  1780. $this->success('申请退款成功,请等待审核');
  1781. }
  1782. //////////////////////////////////////////////////////
  1783. //手机号登录/注册
  1784. public function mobileloginregister() {
  1785. $user_token = input('user_token', '', 'trim');
  1786. if (!$user_token) {
  1787. $this->error('参数缺失');
  1788. }
  1789. $url = 'http://' . config('pingtai_ip') . ':8081/bussiness/1.0/hdc/svc/sso/loginUserInfo/cmtokenid/' . $user_token;
  1790. //获取鉴权token
  1791. $sign_bytes = '/1.0/hdc/svc/sso/loginUserInfo/cmtokenid/' . $user_token;
  1792. $hdc_token = base64_encode(hash_hmac('sha256', $sign_bytes, config('pingtai_appkey'), true));
  1793. $header = [
  1794. 'Host:' . config('pingtai_ip') . ':8081',
  1795. 'Content-Type:application/json',
  1796. 'Authorization: HDCAUTH appid="' . config('pingtai_appid') . '",token="' . $hdc_token . '"'
  1797. ];
  1798. $user_info = httpRequest($url, 'GET', '', $header);
  1799. file_put_contents('chen.txt', $user_info, FILE_APPEND);
  1800. $user_info = simplexml_load_string($user_info, 'SimpleXMLElement', LIBXML_NOCDATA);
  1801. $user_info = (array)$user_info;
  1802. if (!$user_info) {
  1803. $this->error('您的网络开小差了~');
  1804. }
  1805. $mobile = isset($user_info['phoneNum']) ? $user_info['phoneNum'] : '';
  1806. if (!$mobile) {
  1807. $mobile = $this->request->post('mobile');
  1808. }
  1809. if (!$mobile) {
  1810. $this->error(__('Invalid parameters'));
  1811. }
  1812. /*$mobile = $this->request->post('mobile');
  1813. if (!$mobile) {
  1814. $this->error(__('Invalid parameters'));
  1815. }
  1816. if (!Validate::regex($mobile, "^1\d{10}$")) {
  1817. $this->error(__('Mobile is incorrect'));
  1818. }*/
  1819. $user = \app\common\model\User::getByMobile($mobile);
  1820. if ($user) {
  1821. if ($user->status != 1) {
  1822. $this->error(__('Account is locked'));
  1823. }
  1824. //如果已经有账号则直接登录
  1825. $ret = $this->auth->direct($user->id);
  1826. } else {
  1827. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
  1828. }
  1829. if ($ret) {
  1830. // $data = ['userinfo' => $this->auth->getUserinfo()];
  1831. $data = $this->auth->getUserinfo();
  1832. $data['hw_ip'] = explode(',', config('site.hw_ip')); //华为播放视频ip
  1833. $data['zx_ip'] = explode(',', config('site.zx_ip')); //中兴播放视频ip
  1834. $data['display'] = '';//不要删 备用字段
  1835. $this->success(__('Logged in successful'), $data);
  1836. } else {
  1837. $this->error($this->auth->getError());
  1838. }
  1839. }
  1840. //查询我的信息
  1841. public function getmyinfo()
  1842. {
  1843. $user = Db::name('user')->find($this->auth->id);
  1844. $data['nickname'] = $user['nickname']; //姓名
  1845. $data['username'] = $user['username']; //UID
  1846. $data['avatar'] = cdnurl($user['avatar']); //头像
  1847. $data['mobile'] = $user['mobile']; //手机号
  1848. $data['money'] = $user['money']; //余额
  1849. $data['realname'] = $user['realname']; //真实姓名
  1850. $data['gender'] = $user['gender']; //性别:1=男,2=女
  1851. $data['birthday'] = date('Y-m-d', $user['birthday']); //生日
  1852. $data['is_vip'] = 0; //vip是否到期:0到期 1未到期
  1853. $data['is_my_vip'] = 0; //健康E家的vip是否到期:0到期 1未到期
  1854. //查询vip是否到期
  1855. $url = 'http://' . config('pay_ip') . '/HDC/bizauth/phone/auth';
  1856. //产品编码集合
  1857. $product_codes = [config('product_code'), '005912cp0028', '005912cp0004', '0002112cp0030', '005911cp0022', '005912cp0051', '005912cp0052', '005912cp0044', '005912cp0047', '0002112cp0031', '005912cp0035', '005912cp0043', '005912cp0034', '005912cp0046', '005912cp0039', '0002112cp0031T1', '0002112cp0031T9', '0002112cp0031T19', '0002112cp0029', '005912cp0002', '0002112cp0031Z39', '005912cp0040', '005912cp0036', '005912cp0021', '005912cp0012', '005912cp0037', '005911cp0001', '005911cp0005', '005911cp0002', '008888cp0004', '2400000560_YRHY', '005912cp0017', '2000012947_ZY', '005912cp0066', '005912cp0067', '005912cp0094', '005912cp0095', '005912cp0121', '005912cp0122', '2000061907ZYYW', '2000061909ZYYW', '2000061908ZYYW','005911cp0138','005911cp0139'];
  1858. $product_codes_count = count($product_codes);
  1859. $i_max = ceil($product_codes_count / 6);
  1860. for ($i = 0; $i < $i_max; $i++) {
  1861. $post_product_codes = array_slice($product_codes, $i * 6, 6);
  1862. $post_data = [
  1863. 'phoneNumber' => $this->auth->mobile,
  1864. 'productCodes' => $post_product_codes,
  1865. 'channel' => '01'
  1866. ];
  1867. $post_data = json_encode($post_data, 320);
  1868. //获取鉴权token
  1869. $sign_bytes = '/bizauth/phone/auth' . $this->base16_encode(md5($post_data));
  1870. // $hdc_token = base64_encode(hash_hmac('sha256', $sign_bytes, config('pay_appkey'), true));
  1871. $hdc_token = hash_hmac('sha256', $sign_bytes, base64_decode(config('pay_appkey')), false);
  1872. $header = [
  1873. 'Host:' . config('pay_ip'),
  1874. 'Content-Type:application/json',
  1875. 'Authorization: HDCAUTH appid="' . config('pay_appid') . '",token="' . $hdc_token . '"'
  1876. ];
  1877. $rs = httpRequest($url, 'POST', $post_data, $header);
  1878. // file_put_contents('chen.txt', $user_info, FILE_APPEND);
  1879. if ($rs) {
  1880. $rs = json_decode($rs, true);
  1881. if ($rs['code'] == '00') {
  1882. foreach ($rs['result'] as &$v) {
  1883. if ($v['isOrder'] == true) {
  1884. $data['is_vip'] = 1;
  1885. if($v['productCode'] == config('product_code')){
  1886. $data['is_my_vip'] = 1; //因为自己的产品码在第一个,所以不用担心被break掉
  1887. }
  1888. break 2;//跳出二重循环
  1889. }
  1890. }
  1891. }
  1892. }
  1893. }
  1894. $update = ['updatetime'=>time()];
  1895. if ($this->auth->is_vip != $data['is_vip']) {
  1896. $update['is_vip'] = $data['is_vip'];
  1897. }
  1898. if ($this->auth->is_my_vip != $data['is_my_vip']) {
  1899. $update['is_my_vip'] = $data['is_my_vip'];
  1900. }
  1901. Db::name('user')->where(['id' => $this->auth->id])->update($update);
  1902. $this->success('信息', $data);
  1903. }
  1904. //关于我们/免责协议/用户协议/隐私政策/段位介绍
  1905. public function getagreement()
  1906. {
  1907. $type = input('type', 0, 'intval');
  1908. if (!in_array($type, [1, 2, 3, 4, 5, 6, 7, 8, 9])) {
  1909. $this->error('参数错误');
  1910. }
  1911. $info = Db::name('platform_info')->field('title, content')->where(['type' => $type])->find();
  1912. $this->success('协议', $info);
  1913. }
  1914. }