MemberController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <?php
  2. /**
  3. * MemberController.php UTF-8
  4. * h5 wap 用户
  5. *
  6. * @date : 2018/4/27 18:03
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : liuhongliang <lhl@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace h5wap\wap\controller;
  13. use cmf\lib\Upload;
  14. use h5wap\common\controller\V2BaseController;
  15. use huo\controller\address\Address;
  16. use huo\controller\member\Member;
  17. use huo\controller\member\MemCache;
  18. use huo\controller\sign\Sign;
  19. use huolib\sms\Sms;
  20. use huolib\sms\SmsType;
  21. use huolib\status\CommonStatus;
  22. use huolib\status\IdentifyStatus;
  23. use huolib\status\MemberStatus;
  24. use huolib\tool\StrUtils;
  25. use huoIdentify\controller\Identify;
  26. class MemberController extends V2BaseController {
  27. /**
  28. * h5wap个人中心
  29. * http://doc.1tsdk.com/138?page_id=3124
  30. *
  31. * 【域名】/wap/user/index
  32. *
  33. * @return mixed
  34. */
  35. public function index() {
  36. $_data = (new Member())->getMemInfo($this->mem_id);
  37. $_data['encrypt_real_name'] = StrUtils::encryptName($_data['real_name']);
  38. $_data['encrypt_id_card'] = StrUtils::encryptIdCard($_data['id_card']);
  39. $_data['encrypt_mobile'] = StrUtils::encryptPhone($_data['mobile']);
  40. $_data['encrypt_alipay_account'] = StrUtils::encryptName($_data['alipay_account']);
  41. $_rdata['userinfo'] = $_data;
  42. $this->assign('userinfo', $_rdata['userinfo']);
  43. $_sign_conf = (new Sign())->getSignConf();
  44. $_sign_list['count'] = count($_sign_conf);
  45. $_sign_list['list'] = $_sign_conf;
  46. $this->assign('sign_list', $_sign_list);
  47. return $this->fetch('user/index');
  48. }
  49. /**
  50. * H5WAP登陆页
  51. * http://doc.1tsdk.com/138?page_id=3268
  52. *
  53. * 【域名】/wap/user/login
  54. *
  55. */
  56. public function login() {
  57. $_back_url = $this->request->server('HTTP_REFERER');
  58. $this->assign('back_url', $_back_url);
  59. return $this->fetch('user/login');
  60. }
  61. public function address() {
  62. $_list = (new Address())->getMemAddress($this->mem_id);
  63. $this->assign('list', $_list);
  64. return $this->fetch('user/address');
  65. }
  66. public function addAddress() {
  67. return $this->fetch('user/add_address');
  68. }
  69. public function addAddressPost() {
  70. $address['mem_id'] = $this->mem_id;
  71. $address['consignee'] = $this->request->param('consignee/s', '');
  72. $address['mobile'] = $this->request->param('mobile/s', '');
  73. $address['country'] = $this->request->param('country/d', 0);
  74. $address['province'] = $this->request->param('province/d', 0);
  75. $address['city'] = $this->request->param('city/d', 0);
  76. $address['district'] = $this->request->param('district/d', 0);
  77. $address['town'] = $this->request->param('town/d', 0);
  78. $address['address'] = $this->request->param('address/s', '');
  79. $address['zipcode'] = $this->request->param('zipcode/s', '');
  80. $address['is_default'] = $this->request->param('is_default/s', '');
  81. $_res = (new Address())->addAddress($address);
  82. if (!$_res) {
  83. $_rdata = [
  84. 'code' => CommonStatus::INNER_ERROR,
  85. 'msg' => CommonStatus::getMsg(CommonStatus::INNER_ERROR),
  86. 'data' => [],
  87. ];
  88. } else {
  89. $_rdata = [
  90. 'code' => CommonStatus::NO_ERROR,
  91. 'msg' => CommonStatus::getMsg(CommonStatus::NO_ERROR),
  92. 'data' => [],
  93. ];
  94. }
  95. $this->returnData($_rdata);
  96. }
  97. public function editAddressPost() {
  98. $address['mem_id'] = $this->mem_id;
  99. $id = $this->request->param('id/s', '');
  100. $address['consignee'] = $this->request->param('consignee/s', '');
  101. $address['mobile'] = $this->request->param('mobile/s', '');
  102. $address['country'] = $this->request->param('country/d', 0);
  103. $address['province'] = $this->request->param('province/d', 0);
  104. $address['city'] = $this->request->param('city/d', 0);
  105. $address['district'] = $this->request->param('district/d', 0);
  106. $address['town'] = $this->request->param('town/d', 0);
  107. $address['address'] = $this->request->param('address/s', '');
  108. $address['zipcode'] = $this->request->param('zipcode/s', '');
  109. $address['is_default'] = $this->request->param('is_default/s', '');
  110. $_res = (new Address())->editMemAddress($id, $address);
  111. if (!$_res) {
  112. $_rdata = [
  113. 'code' => CommonStatus::INNER_ERROR,
  114. 'msg' => CommonStatus::getMsg(CommonStatus::INNER_ERROR),
  115. 'data' => [],
  116. ];
  117. } else {
  118. $_rdata = [
  119. 'code' => CommonStatus::NO_ERROR,
  120. 'msg' => CommonStatus::getMsg(CommonStatus::NO_ERROR),
  121. 'data' => [],
  122. ];
  123. }
  124. $this->returnData($_rdata);
  125. }
  126. public function getAddressDetail() {
  127. $id = $this->request->param('id/s', '');
  128. $_detail = (new Address())->getAddressDetail($id);
  129. $_rdata = [
  130. 'code' => CommonStatus::NO_ERROR,
  131. 'msg' => CommonStatus::getMsg(CommonStatus::NO_ERROR),
  132. 'data' => $_detail,
  133. ];
  134. $this->returnData($_rdata);
  135. }
  136. public function deleteAddress() {
  137. $id = $this->request->param('id/s', '');
  138. $_res = (new Address())->deleteAddress($id);
  139. if (!$_res) {
  140. $_rdata = [
  141. 'code' => CommonStatus::INNER_ERROR,
  142. 'msg' => CommonStatus::getMsg(CommonStatus::INNER_ERROR),
  143. 'data' => [],
  144. ];
  145. } else {
  146. $_rdata = [
  147. 'code' => CommonStatus::NO_ERROR,
  148. 'msg' => CommonStatus::getMsg(CommonStatus::NO_ERROR),
  149. 'data' => [],
  150. ];
  151. }
  152. $this->returnData($_rdata);
  153. }
  154. /***
  155. * 绑定支付宝页面
  156. */
  157. public function bindAlipay() {
  158. $_mem_data = MemCache::ins()->getInfoById($this->mem_id);
  159. $_real_name = get_val($_mem_data, 'real_name', '');
  160. $_id_card = get_val($_mem_data, 'id_card', '');
  161. $_mobile = get_val($_mem_data, 'mobile', '');
  162. $_alipay_account = get_val($_mem_data, 'alipay_account', '');
  163. $_data = [
  164. 'real_name' => StrUtils::encryptName($_real_name),
  165. 'id_card' => StrUtils::encryptIdCard($_id_card),
  166. 'mobile' => StrUtils::encryptPhone($_mobile),
  167. 'real_mobile' => $_mobile,
  168. 'alipay_account' => StrUtils::encryptIdCard($_alipay_account),
  169. ];
  170. $this->assign('data', $_data);
  171. return $this->fetch('user/bind_alipay');
  172. }
  173. /**
  174. * 绑定支付宝提交页面
  175. */
  176. public function bindAlipayPost() {
  177. $_param = $this->request->post();
  178. $_alipay_account = get_val($_param, 'alipay_account', '');
  179. if (empty($_alipay_account)) {
  180. $_code = MemberStatus::INVALID_PARAMS;
  181. $this->error(IdentifyStatus::getMsg($_code), [], $_code);
  182. }
  183. /* 检查支付宝是否绑定别的玩家 */
  184. $_id = (new Member())->getMemIdByAlipayAccount($_alipay_account);
  185. if (!empty($_id) && $_id != $this->mem_id) {
  186. $_code = MemberStatus::ALIPAY_IS_BIND;
  187. $this->error(IdentifyStatus::getMsg($_code), [], $_code);
  188. }
  189. // $_mobile = get_val($_param, 'mobile', '');
  190. // $_sms_code = get_val($_param, 'sms_code', '');
  191. // $_mem_data = MemCache::ins()->getInfoById($this->mem_id);
  192. // /* 校验手机验证码 */
  193. // if (empty($_mem_data['mobile']) && empty($_mobile)) {
  194. // $_code = MemberStatus::PHONE_EMPTY;
  195. // $this->error(IdentifyStatus::getMsg($_code), [], $_code);
  196. // }
  197. // /* 校验短信是否正确 */
  198. // $_sms_rs = (new Sms())->check($_mobile, $_sms_code, SmsType::SMS_ID_VERIFY);
  199. // if (MemberStatus::NO_ERROR != $_sms_rs['code']) {
  200. // $this->error($_sms_rs['code'], [], $_sms_rs['msg']);
  201. // }
  202. // $_real_name = get_val($_param, 'real_name', '');
  203. // $_id_card = get_val($_param, 'id_card', '');
  204. // /* 未实名则需要校验 校验证件号是否输入 */
  205. // if (empty($_mem_data['real_name'])) {
  206. // if (empty($_real_name) || empty($_id_card)) {
  207. // $_code = IdentifyStatus::IDENTIFY_INFO_ERROR;
  208. // $this->error(IdentifyStatus::getMsg($_code), [], $_code);
  209. // }
  210. // $_rs = (new \huoIdentify\controller\Identify())->updateIdentify($this->mem_id, 1, $_real_name, $_id_card);
  211. // if (IdentifyStatus::NO_ERROR != $_rs['code']) {
  212. // $this->returnData($_rs);
  213. // }
  214. // }
  215. $_mem_data['alipay_account'] = $_alipay_account;
  216. // if (empty($_mem_data['mobile'])) {
  217. // $_mem_data['mobile'] = $_mobile;
  218. // }
  219. $_rs = MemCache::ins()->updateMem($this->mem_id, $_mem_data);
  220. if (false === $_rs) {
  221. $_code = IdentifyStatus::INNER_ERROR;
  222. $this->error(IdentifyStatus::getMsg($_code), [], $_code);
  223. }
  224. $_code = IdentifyStatus::NO_ERROR;
  225. $this->success(IdentifyStatus::getMsg($_code), [], $_code);
  226. }
  227. /**
  228. * 修改用户头像
  229. * http://doc.1tsdk.com/138?page_id=3541
  230. * 【域名】/user/avatar/update
  231. */
  232. public function updateAvatar() {
  233. $_avatar = $this->request->param('avatar/s', '');
  234. if (empty($_avatar)) {
  235. $_code = CommonStatus::INVALID_PARAMS;
  236. $this->error(CommonStatus::getMsg($_code), [], $_code);
  237. }
  238. $_rdata = (new Member())->updateAvatar($this->mem_id, $_avatar);
  239. return $this->returnData($_rdata);
  240. }
  241. /**
  242. * 修改昵称
  243. * http://doc.1tsdk.com/138?page_id=3274
  244. * 【域名】/cfloat/user/nickname/update
  245. */
  246. public function updateNickname() {
  247. $_data = $this->request->param();
  248. $result = $this->validate(
  249. $_data, [
  250. 'nickname' => 'require|chsDash|max:32',
  251. ], [
  252. 'nickname.require' => lang('nickname is null'),
  253. 'nickname.chsDash' => '昵称只能是汉字、字母、数字和下划线_及破折号-',
  254. 'nickname.max' => lang('nickname Up to 32 characters'),
  255. ]
  256. );
  257. if (true !== $result) {
  258. $this->error($result, [], CommonStatus::INVALID_PARAMS);
  259. }
  260. $_nickname = get_val($_data, 'nickname');
  261. $_rs = (new Member())->updateNickname($this->mem_id, $_nickname);
  262. if (MemberStatus::NO_ERROR != $_rs['code']) {
  263. $this->error($_rs['msg'], [], $_rs['code']);
  264. }
  265. $this->success($_rs['msg'], [], $_rs['code']);
  266. }
  267. /**
  268. * 修改密码
  269. * http://doc.1tsdk.com/138?page_id=3373
  270. * 【域名】/cfloat/user/passwd/update
  271. */
  272. public function updatePwd() {
  273. $_data = $this->request->param();
  274. $_status = get_val($_data, 'status', 2);
  275. if (1 == $_status) {
  276. $result = $this->validate(
  277. $_data, [
  278. 'newpwd' => 'require|length:6,32',
  279. ], [
  280. 'newpwd.require' => lang('newpwd is null'),
  281. 'newpwd.length' => lang('newpwd length is 6~32 characters'),
  282. ]
  283. );
  284. if (true !== $result) {
  285. $this->error($result, [], CommonStatus::INVALID_PARAMS);
  286. }
  287. $_newpwd = get_val($_data, 'newpwd');
  288. $_mem_class = new Member();
  289. $_rs = $_mem_class->updatePassword($this->mem_id, $_newpwd);
  290. if (is_numeric($_rs)) {
  291. $_code = $_rs;
  292. } elseif (false !== $_rs) {
  293. $_code = MemberStatus::NO_ERROR;
  294. } else {
  295. $_code = MemberStatus::UNKNOWN_ERROR;
  296. }
  297. $this->success(MemberStatus::getMsg($_code), [], $_code);
  298. }
  299. $result = $this->validate(
  300. $_data, [
  301. 'oldpwd' => 'require',
  302. 'newpwd' => 'require|length:6,32',
  303. ], [
  304. 'oldpwd.require' => lang('oldpwd is null'),
  305. 'newpwd.require' => lang('newpwd is null'),
  306. 'newpwd.length' => lang('newpwd length is 6~32 characters'),
  307. ]
  308. );
  309. if (true !== $result) {
  310. $this->error($result, [], CommonStatus::INVALID_PARAMS);
  311. }
  312. $_oldpwd = get_val($_data, 'oldpwd');
  313. $_newpwd = get_val($_data, 'newpwd');
  314. $_mem_class = new Member();
  315. $_rs = $_mem_class->updatePwd($this->mem_id, $_oldpwd, $_newpwd);
  316. if (MemberStatus::NO_ERROR != $_rs['code']) {
  317. $this->error($_rs['msg'], [], $_rs['code']);
  318. }
  319. $this->success($_rs['msg'], [], $_rs['code']);
  320. }
  321. /**
  322. * H5浮点获取用户信息
  323. * http://doc.1tsdk.com/138?page_id=3207
  324. * 【域名】/float/user/detail
  325. */
  326. public function detail() {
  327. $_mem_id = $this->mem_id;
  328. $_rdata = (new Member())->getMemInfo($_mem_id);
  329. $_game_rq = $this->setGameData();
  330. $_device_rq = $this->setDeviceData();
  331. $_auth_info = (new Identify())->getMemIdentifyInfo(
  332. $_game_rq->getHAppId(), $this->mem_id, $_device_rq->getDeviceId()
  333. );
  334. $_rdata['url'] = get_val($_auth_info, 'url', '');
  335. $_rdata['auth_info'] = get_val($_auth_info, 'auth_info', null);
  336. $siteInfo = cmf_get_site_info();
  337. $_rdata['wap_app_down_url'] = get_val($siteInfo, 'wap_app_down_url', '');
  338. $_code = MemberStatus::NO_ERROR;
  339. $this->success(MemberStatus::getMsg($_code), $_rdata);
  340. }
  341. }