UserCenter.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\Client\AlibabaCloud;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use app\common\library\AliPay2;
  7. use app\common\library\HuijuKjPay;
  8. use think\cache\driver\Redis;
  9. use think\Db;
  10. use think\facade\Validate;
  11. /**
  12. * @title 会员个人中心
  13. * @controller UserCenter
  14. * @group base
  15. */
  16. class UserCenter extends Base
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize();
  21. // parent::check_login();
  22. }
  23. /**
  24. * @title 获取个人信息
  25. * @desc 个人信息
  26. * @author Gavin
  27. * @url /api/User_center/getUserInfo
  28. * @method POST
  29. * @tag 个人信息
  30. * @header name:Authorization require:1 desc:Token
  31. * @return name:id type:int default:-- desc:ID(邀请ID)
  32. * @return name:phone type:string default:-- desc:手机号
  33. * @return name:name type:string default:-- desc:昵称
  34. * @return name:headimg type:string default:-- desc:头像地址
  35. * @return name:integral type:int default:-- desc:积分
  36. * @return name:snap_card type:int default:-- desc:抢购卡
  37. * @return name:wallet_address type:int default:-- desc:钱包地址
  38. * @return name:true_name type:string default:-- desc:真实姓名
  39. * @return name:id_card type:string default:-- desc:身份证号
  40. * @return name:is_auth type:int default:-- desc:是否认证(0否1是)
  41. * @return name:auth_at type:string default:-- desc:认证时间
  42. * @return name:vip_name type:int default:-- desc:身份
  43. * @return name:is_order_no_paid type:string default:-- desc:是否有未支付订单true:有false:没有
  44. * @return name:is_sign type:string default:-- desc:今日是否已经签到true:已签到false:未签到
  45. * @return name:invite_img type:string default:-- desc:邀请二维码
  46. * @return name:invite_address type:string default:-- desc:邀请地址
  47. * @return name:lucky_number type:int default:-- desc:剩余抽奖次数
  48. * @return name:money type:string default:-- desc:余额
  49. */
  50. public function getUserInfo()
  51. {
  52. parent::check_login();
  53. $uid = $this->uid;
  54. $user_info = Db::name('store_member')
  55. ->field('password,second_password',true)
  56. ->where('id',$uid)
  57. ->find();
  58. if(empty($user_info)) $this->error('用户信息不正确');
  59. $user_info['vip_name'] = $user_info['vip']==1 ? "藏友" : "创世勋章";
  60. //是否有待支付订单
  61. $order = Db::name('store_order')->where('status',0)->where('is_deleted',0)->where('mid',$uid)->count();
  62. $user_info['is_order_no_paid'] = $order ? true : false;
  63. //今日是否签到
  64. $date = date('Y-m-d');
  65. $sign = Db::name('store_member_sign')->where('mid',$uid)->where('date',$date)->count();
  66. $user_info['is_sign'] = $sign ? true : false;
  67. //获取每日免费次数
  68. $free_number = getConfigValue('free_lucky_number');
  69. //获取当日免费抽奖记录
  70. $date = date('Y-m-d');
  71. $now_date_count = Db::name('store_blind_box_log')->where('m_id',$this->uid)->where('date',$date)->where('is_free',0)->count();
  72. $lucky_number = $user_info['lottery_number'] + ($free_number-$now_date_count);
  73. $user_info['lucky_number'] =$lucky_number<=0 ? 0 : $lucky_number;
  74. $user_info['id'] = (string)$user_info['id'];
  75. //生成邀请码
  76. if (!$user_info['invite_img'] || !$user_info['invite_address']){
  77. $code = $user_info['invite_code'];
  78. $invite_img = setintivecode($code);
  79. $invite_address = getintiveaddress($code);
  80. Db::name('store_member')->where('id',$this->uid)->update(['invite_img'=>$invite_img,'invite_address'=>$invite_address]);
  81. }
  82. $user_info['invite_img'] = str_replace('http:','https:',$user_info['invite_img']);
  83. $this->success('获取成功',$user_info);
  84. }
  85. /**
  86. * @title 绑定opendid
  87. * @desc 绑定opendid
  88. * @author Gavin
  89. * @url /api/User_center/bindOpenid
  90. * @method POST
  91. * @tag 编辑信息
  92. * @header name:Authorization require:1 desc:Token
  93. *
  94. * @param name:code type:string require:0 default:-- desc:code
  95. */
  96. public function bindOpenid()
  97. {
  98. parent::check_login();
  99. $code = input('code');
  100. if(empty($code)) $this->error('参数错误');
  101. $appid = getConfigValue('wechat_appid');
  102. $secret = getConfigValue('wechat_appsecret');
  103. $res = http_get('https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$secret.'&code='.$code.'&grant_type=authorization_code');
  104. $res = json_decode($res,true);
  105. if (isset($res['openid'])){
  106. $update_data['openid'] = $res['openid'];
  107. $update_data['update_at'] = date('Y-m-d H:i:s');
  108. if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){
  109. setMemberInfoHash($this->uid);
  110. $this->success('绑定成功');
  111. }
  112. $this->error('绑定失败');
  113. }else{
  114. $this->error('获取openid失败');
  115. }
  116. }
  117. /**
  118. * @title 编辑个人信息
  119. * @desc 编辑个人信息
  120. * @author Gavin
  121. * @url /api/User_center/updateUserInfo
  122. * @method POST
  123. * @tag 编辑信息
  124. * @header name:Authorization require:1 desc:Token
  125. *
  126. * @param name:name type:string require:0 default:-- desc:姓名
  127. * @param name:headimg type:string require:0 default:-- desc:头像地址
  128. */
  129. public function updateUserInfo()
  130. {
  131. parent::check_login();
  132. $headimg = input('post.headimg');
  133. $name = trim(input('post.name',''));
  134. if(!$headimg && !$name) $this->error('参数错误');
  135. $update_data= [];
  136. if($name) $update_data['name'] = $name;
  137. if ($headimg) $update_data['headimg'] = $headimg;
  138. if($name){
  139. $check_member = Db::name('store_member')
  140. ->where('name',$name)
  141. ->where('id','<>',$this->uid)
  142. ->count();
  143. if($check_member) $this->error('该用户名已被占用');
  144. }
  145. $update_data['update_at'] = date('Y-m-d H:i:s');
  146. if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){
  147. setMemberInfoHash($this->uid);
  148. $this->success('编辑成功');
  149. }
  150. $this->error('编辑失败');
  151. }
  152. /**
  153. * @title 绑定支付宝
  154. * @desc 绑定支付宝
  155. * @author Gavin
  156. * @url /api/User_center/bind_zfb
  157. * @method POST
  158. * @tag 编辑信息
  159. * @header name:Authorization require:1 desc:Token
  160. *
  161. * @param name:account type:string require:0 default:-- desc:支付宝账号
  162. * @param name:zfb_real_name type:string require:0 default:-- desc:真实姓名
  163. */
  164. public function bind_zfb(){
  165. parent::check_login();
  166. $this->check_login();
  167. $account = input('account'); //账号
  168. $real_name = input('real_name'); //真实姓名
  169. if (!$account) $this->error('支付宝账号为空');
  170. if (!$real_name) $this->error('真实姓名为空');
  171. $update_data['zfb_account'] = $account;
  172. $update_data['zfb_real_name'] = $real_name;
  173. $update_data['update_at'] = date('Y-m-d H:i:s');
  174. if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){
  175. setMemberInfoHash($this->uid);
  176. $this->success('绑定成功');
  177. }
  178. $this->error('绑定失败');
  179. }
  180. /**
  181. * @title 实名认证
  182. * @desc 实名认证
  183. * @author Gavin
  184. * @method POST
  185. * @tag 编辑信息
  186. * @url /api/User_center/userCertification
  187. * @header name:Authorization require:1 desc:Token
  188. * @param name:true_name type:string require:1 default:-- desc:真实姓名
  189. * @param name:id_card type:string require:1 default:-- desc:身份证号
  190. * @param name:bank_card type:string require:1 default:-- desc:银行卡号
  191. * @param name:bank_mobile type:string require:0 default:-- desc:银行卡预留手机号
  192. */
  193. public function userCertification(){
  194. parent::check_login();
  195. //redis原子锁
  196. if (redisSetNx('userCertification'.$this->uid,2)){
  197. $true_name = input('post.true_name');
  198. $id_card = input('post.id_card');
  199. $bank_card = input('post.bank_card');
  200. $bank_mobile = input('post.bank_mobile');
  201. if (!$true_name || !$id_card || !$bank_card) $this->error('参数错误');
  202. $check_id_card = isCreditNo($id_card);
  203. //获取年龄
  204. $age = getAge($id_card);
  205. // if (!$check_id_card) $this->error('身份证号格式错误');
  206. // if (!checkbank($bank_card)) $this->error('银行卡号格式错误');
  207. if ($age<18 || $age>65) $this->error('年龄不合规');
  208. $is_auth = Db::table('store_member')->where('id',$this->uid)->value('is_auth');
  209. if($is_auth) $this->error('已认证');
  210. $check = Db::name('store_member')->where('id_card',$id_card)->count();
  211. if ($check) $this->error('身份证号已经认证过');
  212. $bank_check = Db::name('store_member')->where('bank_card',$bank_card)->count();
  213. if ($bank_check) $this->error('银行卡号已经使用过');
  214. //二要素
  215. //if (!idcardlingyu($id_card,$true_name)) $this->error('身份证与姓名验证失败');
  216. //四要素
  217. $res = idcardlingyufour($id_card,$true_name,$bank_card,$bank_mobile);
  218. if (!$res['success']) $this->error($res['remark']);
  219. if (Db::table('store_member')->where('id',$this->uid)
  220. ->update(['is_auth'=>1,'true_name'=>$true_name,'id_card'=>$id_card,'bank_card'=>$bank_card,'bank_mobile'=>$bank_mobile,'auth_at'=>date('Y-m-d H:i:s')])){
  221. setMemberInfoHash($this->uid);
  222. $user1 = getMemberInfoHash($this->uid); //获取用户信息
  223. if ($user1['pid']){
  224. $data = [
  225. 'mid'=>$user1['pid'],
  226. 'to_mid'=>$this->uid,
  227. 'create_at'=>date('Y-m-d H:i:s')
  228. ];
  229. Db::name('store_activities_invite_log')->insert($data);
  230. }
  231. pull_new($this->uid);
  232. DelRedisSetNx('userCertification'.$this->uid);
  233. $this->success('认证成功');
  234. }
  235. DelRedisSetNx('userCertification'.$this->uid);
  236. $this->error('认证失败');
  237. }else{
  238. $this->error('请求过快');
  239. }
  240. }
  241. /**
  242. * @title 修改密码
  243. * @desc 修改密码
  244. * @author Gavin
  245. * @method POST
  246. * @tag 编辑信息
  247. * @url /api/User_center/updatePass
  248. * @header name:Authorization require:1 desc:Token
  249. * @param name:old_password type:string require:1 default:-- desc:旧密码
  250. * @param name:new_password type:string require:1 default:-- desc:新密码
  251. * @param name:confirm_password type:string require:1 default:-- desc:确认密码
  252. */
  253. public function updatePass()
  254. {
  255. parent::check_login();
  256. $old_password = input('post.old_password');
  257. $new_password = input('post.new_password');
  258. $confirm_password = input('post.confirm_password');
  259. // $yzm = input('post.yzm');
  260. if (!$old_password || !$new_password || !$confirm_password) $this->error('参数错误');
  261. if ($new_password!=$confirm_password) $this->error('密码与确认密码不一致');
  262. if (!preg_match('/^[0-9a-z]{6,12}$/i',$new_password)) $this->error('密码格式错误,请输入6-12位数字+字母');
  263. $member = Db::name('store_member')->where('id',$this->uid)->find();
  264. //验证短信验证码
  265. // $time = time()-60;
  266. // $sms = Db::name('store_sms')->where(['mobile' => $member['phone'], 'event' => 'forgetpwd'])
  267. // ->where('createtime','>',$time)
  268. // ->order('id', 'DESC')
  269. // ->find();
  270. // if (!$sms || $sms['code'] != $yzm) $this->error('短信验证码不正确!');
  271. if ($member['password']!=md5($old_password)) $this->error('旧密码错误');
  272. $data['password'] = md5($new_password);
  273. $data['update_at'] = date('Y-m-d H:i:s');
  274. if (Db::name('store_member')->where('id',$this->uid)->update($data)){
  275. setMemberInfoHash($this->uid);
  276. $this->success('修改成功');
  277. }
  278. $this->error('修改失败');
  279. }
  280. /**
  281. * @title 修改二级密码
  282. * @desc 修改二级密码
  283. * @author Gavin
  284. * @method POST
  285. * @tag 编辑信息
  286. * @url /api/User_center/updateSecondPass
  287. * @header name:Authorization require:1 desc:Token
  288. * @param name:second_password type:string require:1 default:-- desc:二级密码
  289. * @param name:confirm_second_password type:string require:1 default:-- desc:确认密码
  290. */
  291. public function updateSecondPass()
  292. {
  293. parent::check_login();
  294. $second_password = input('post.second_password');
  295. $confirm_second_password = input('post.confirm_second_password');
  296. $yzm = input('post.yzm');
  297. if (!$second_password || !$confirm_second_password) $this->error('参数错误');
  298. if ($second_password!=$confirm_second_password) $this->error('密码与确认密码不一致');
  299. if (!preg_match('/^[0-9]{6}$/i',$second_password)) $this->error('二级密码格式错误,请输入6位纯数字');
  300. $member = getMemberInfoHash($this->uid); //获取用户信息
  301. //验证短信验证码
  302. $time = time()-60;
  303. $sms = Db::name('store_sms')->where(['mobile' => $member['phone'], 'event' => 'forgetpwd'])
  304. ->where('createtime','>',$time)
  305. ->order('id', 'DESC')
  306. ->find();
  307. if (!$sms || $sms['code'] != $yzm) $this->error('短信验证码不正确!');
  308. $data['second_password'] = md5($second_password);
  309. $data['update_at'] = date('Y-m-d H:i:s');
  310. if (Db::name('store_member')->where('id',$this->uid)->update($data)){
  311. setMemberInfoHash($this->uid);
  312. $this->success('修改成功');
  313. }
  314. $this->error('修改失败');
  315. }
  316. /**
  317. * @title 我的藏品
  318. * @desc 我的藏品
  319. * @author Gavin
  320. * @method POST
  321. * @tag 编辑信息
  322. * @url /api/User_center/myCollection
  323. * @header name:Authorization require:1 desc:Token
  324. *
  325. * @return name:id type:int require:0 default:0 desc:藏品ID
  326. * @return name:tag type:string require:0 default:0 desc:唯一标签
  327. * @return name:name type:string require:0 default:0 desc:藏品名称
  328. * @return name:cover type:string require:0 default:0 desc:藏品图片
  329. * @return name:auth_img type:string require:0 default:0 desc:作者头像
  330. * @return name:auth_name type:string require:0 default:0 desc:作者名称
  331. */
  332. public function myCollection(){
  333. parent::check_login();
  334. $type = input('type');
  335. $where = [
  336. 'mid'=>$this->uid,
  337. 'is_destruction'=>1,
  338. 'resale_status'=>1
  339. ];
  340. $cids = Db::name('store_order_info')->where($where)
  341. ->where('status','neq','2')
  342. ->when($type,function ($query) use ($type){
  343. if ($type==1){
  344. $query->where('type','neq',3);
  345. }else{
  346. $query->where('type',3);
  347. }
  348. })
  349. ->group('c_id')
  350. ->column('c_id');
  351. $arr = [];
  352. foreach ($cids as &$v){
  353. $array['c_id'] = $v;
  354. $array['count'] = Db::name('store_order_info')
  355. ->where($where)
  356. ->when($type,function ($query) use ($type){
  357. if ($type==1){
  358. $query->where('type','neq',3);
  359. }else{
  360. $query->where('type',3);
  361. }
  362. })
  363. ->where('c_id',$v)
  364. ->where('status','neq','2')
  365. ->count();
  366. $info = Db::name('store_order_info')
  367. ->where($where)->where('c_id',$v)
  368. ->limit(1)
  369. ->field('id,name,cover,tag,pro_info')
  370. ->find();
  371. $array['cover'] = $info['cover'];
  372. $array['name'] = $info['name'];
  373. $pro_info = json_decode($info['pro_info'],true);
  374. $array['auth_img'] = $pro_info['auth_img'];
  375. $array['auth_name'] = $pro_info['auth_name'];
  376. $tag = explode('#',$info['tag']);
  377. $tag2 = explode('/',$tag[1]);
  378. $array['tag'] = $tag[0].'#???'.'/'.$tag2[1];
  379. array_push($arr,$array);
  380. }
  381. $this->success('成功',$arr);
  382. $list = Db::name('store_order_info')
  383. ->where('mid',$this->uid)
  384. ->when($type,function ($query) use ($type){
  385. if ($type==1){
  386. $query->where('type','neq',3);
  387. }else{
  388. $query->where('type',3);
  389. }
  390. })
  391. ->where('status','neq','2')
  392. ->where('is_destruction',1)
  393. ->where('resale_status',1)
  394. ->field('id,tag,pro_info,c_id')
  395. ->order('id desc')
  396. ->select();
  397. foreach ($list as &$v){
  398. $pro_info = json_decode($v['pro_info'],true);
  399. $v['name'] = $pro_info['name'];
  400. $v['cover'] = $pro_info['cover'];
  401. $v['auth_img'] = $pro_info['auth_img']? $pro_info['auth_img'] : Db::name('store_collection')->where('id',$v['c_id'])->value('auth_img');
  402. $v['auth_name'] = $pro_info['auth_name'] ? $pro_info['auth_name'] : Db::name('store_collection')->where('id',$v['c_id'])->value('auth_name');
  403. if ($v['tag']){
  404. $tag = explode('#',$v['tag']);
  405. $tag1 = substr($tag[0],0,6);
  406. $v['tag'] = $tag1.'#'.$tag[1];
  407. }
  408. unset($v['pro_info']);
  409. }
  410. $this->success('成功',$list);
  411. }
  412. /**
  413. * @title 藏品列表
  414. * @desc 藏品列表
  415. * @author Gavin
  416. * @method POST
  417. * @tag 编辑信息
  418. * @url /api/User_center/myCollectionList
  419. * @header name:Authorization require:1 desc:Token
  420. *
  421. * @param name:c_id type:string require:1 default:-- desc:藏品ID
  422. *
  423. * @return name:id type:int require:0 default:0 desc:藏品ID
  424. * @return name:tag type:string require:0 default:0 desc:唯一标签
  425. * @return name:name type:string require:0 default:0 desc:藏品名称
  426. * @return name:cover type:string require:0 default:0 desc:藏品图片
  427. * @return name:auth_img type:string require:0 default:0 desc:作者头像
  428. * @return name:auth_name type:string require:0 default:0 desc:作者名称
  429. */
  430. public function myCollectionList(){
  431. parent::check_login();
  432. $c_id = input('c_id');
  433. if (!$c_id) $this->error('参数错误');
  434. $list = Db::name('store_order_info')
  435. ->where('mid',$this->uid)
  436. ->where('status','neq','2')
  437. ->whereIn('type','1,3')
  438. ->where('c_id',$c_id)
  439. ->where('is_destruction',1)
  440. ->where('resale_status',1)
  441. ->field('id,tag,pro_info')
  442. ->order('id desc')
  443. ->select();
  444. foreach ($list as &$v){
  445. $pro_info = json_decode($v['pro_info'],true);
  446. $v['name'] = $pro_info['name'];
  447. $v['cover'] = $pro_info['cover'];
  448. $v['auth_img'] = $pro_info['auth_img'];
  449. $v['auth_name'] = $pro_info['auth_name'];
  450. unset($v['pro_info']);
  451. }
  452. $this->success('成功',$list);
  453. }
  454. /**
  455. * @title 我的盲盒
  456. * @desc 我的盲盒
  457. * @author Gavin
  458. * @method POST
  459. * @tag 编辑信息
  460. * @url /api/User_center/myBoxCollection
  461. * @header name:Authorization require:1 desc:Token
  462. *
  463. * @return name:id type:int require:0 default:0 desc:藏品ID
  464. * @return name:tag type:string require:0 default:0 desc:唯一标签
  465. * @return name:name type:string require:0 default:0 desc:藏品名称
  466. * @return name:cover type:string require:0 default:0 desc:藏品图片
  467. * @return name:auth_img type:string require:0 default:0 desc:作者头像
  468. * @return name:auth_name type:string require:0 default:0 desc:作者名称
  469. */
  470. public function myBoxCollection(){
  471. parent::check_login();
  472. $list = Db::name('store_order_info')
  473. ->where('mid',$this->uid)
  474. ->where('status','neq','2')
  475. ->where('type',3)
  476. ->where('is_destruction',1)
  477. ->where('resale_status',1)
  478. ->field('id,tag,pro_info')
  479. ->order('id desc')
  480. ->select();
  481. foreach ($list as &$v){
  482. $pro_info = json_decode($v['pro_info'],true);
  483. $v['name'] = $pro_info['name'];
  484. $v['cover'] = $pro_info['cover'];
  485. $v['auth_img'] = $pro_info['auth_img'];
  486. $v['auth_name'] = $pro_info['auth_name'];
  487. unset($v['pro_info']);
  488. }
  489. $this->success('成功',$list);
  490. }
  491. /**
  492. * @title 藏品详情
  493. * @desc 藏品详情
  494. * @author Gavin
  495. * @method POST
  496. * @tag 编辑信息
  497. * @url /api/User_center/myCollectionDetail
  498. * @header name:Authorization require:1 desc:Token
  499. * @param name:id type:int require:1 default:-- desc:藏品ID
  500. *
  501. * @return name:id type:int require:0 default:0 desc:藏品ID
  502. * @return name:tag type:string require:0 default:0 desc:唯一标签
  503. * @return name:collectors_name type:string require:0 default:0 desc:收藏者
  504. * @return name:collectors_hash type:string require:0 default:0 desc:收藏者hash
  505. * @return name:create_at type:string require:0 default:0 desc:收藏时间
  506. * @return name:company type:string require:0 default:0 desc:流转公司
  507. * @return name:company_hash type:string require:0 default:0 desc:流转公司hash
  508. * @return name:examples_illustrate type:string require:0 default:0 desc:转赠说明
  509. * @return name:pro_info@name type:string require:0 default:0 desc:藏品名称
  510. * @return name:pro_info@price type:string require:0 default:0 desc:藏品价格
  511. * @return name:pro_info@label type:string require:0 default:0 desc:藏品标签
  512. * @return name:pro_info@cover type:string require:0 default:0 desc:藏品图片
  513. * @return name:pro_info@auth_img type:string require:0 default:0 desc:作者头像
  514. * @return name:pro_info@auth_name type:string require:0 default:0 desc:作者姓名
  515. * @return name:pro_info@warm_prompt type:string require:0 default:0 desc:温馨提示
  516. * @return name:pro_info@share_img type:string require:0 default:0 desc:分享二维码
  517. */
  518. public function myCollectionDetail(){
  519. parent::check_login();
  520. $id = input('id');
  521. if (!$id) $this->error('参数错误');
  522. $info = Db::name('store_order_info')
  523. ->where('mid',$this->uid)
  524. ->where('id',$id)
  525. ->find();
  526. if (!$info) $this->error('藏品不存在');
  527. $info['pro_info'] = json_decode($info['pro_info'],true);
  528. if (!isset($info['pro_info']['share_img'])){
  529. $info['pro_info']['share_img'] = Db::name('store_collection')->where('id',$info['pro_info']['id'])->value('share_img');
  530. }
  531. $issuer = Db::name('store_collection')->where('id',$info['c_id'])->value('issuer');
  532. if (!empty($issuer)){
  533. $info['company'] = $issuer;
  534. }
  535. $info['detail_img'] = $info['pro_info']['detail_img'];
  536. $info['format'] = $info['pro_info']['format'];
  537. $info['collectors_name'] = Db::name('store_member')->where('id',$this->uid)->value('name');
  538. //$info['collectors_hash'] = $info['collectors_hash']=='' ? "发放中" : $info['collectors_hash'];
  539. $info['collectors_hash_time'] = $info['collectors_hash_time']=='' ? "发放中" : $info['collectors_hash_time'];
  540. $info['examples_illustrate'] = Db::table('system_config')->where('name','examples_illustrate')->value('value');
  541. $info['c_id'] = (string)$info['c_id'];
  542. if (!empty($info['tag'])){
  543. $tag = explode('#',$info['tag']);
  544. $tag1 = substr($tag[0],0,6);
  545. $info['tag'] = $tag1.'#'.$tag[1];
  546. }
  547. $info['pro_info']['auth_name'] = $info['pro_info']['auth_name'] ? $info['pro_info']['auth_name'] : Db::name('store_collection')->where('id',$info['c_id'])->value('auth_name');
  548. $info['pro_info']['auth_img'] = $info['pro_info']['auth_img'] ? $info['pro_info']['auth_name'] : Db::name('store_collection')->where('id',$info['c_id'])->value('auth_img');
  549. if ($info['collectors_hash_time']!='0000-00-00 00:00:00'){
  550. $info['create_at'] = $info['collectors_hash_time'];
  551. }
  552. $this->success('成功',$info);
  553. }
  554. /**
  555. * @title 转赠
  556. * @desc 转赠
  557. * @author Gavin
  558. * @method POST
  559. * @tag 编辑信息
  560. * @url /api/User_center/examples
  561. * @header name:Authorization require:1 desc:Token
  562. * @param name:id type:int require:1 default:-- desc:藏品ID
  563. * @param name:phone type:string require:1 default:-- desc:手机号
  564. * @param name:wallet_address type:int require:1 default:-- desc:钱包地址
  565. * @param name:second_password type:int require:1 default:-- desc:二级密码
  566. *
  567. */
  568. public function examples(){
  569. parent::check_login();
  570. //redis原子锁
  571. if (redisSetNx('examples'.$this->uid,2)){
  572. $v = getConfigValue('examples_switch');
  573. if (!$v) $this->error('维护中,暂时关闭');
  574. $id = input('id');
  575. $phone = input('phone');
  576. $wallet_address = input('wallet_address');
  577. $second_password = input('second_password');
  578. if (!$id || !$phone || !$wallet_address) $this->error('参数错误');
  579. $info = Db::name('store_order_info')->where('id',$id)->where('mid',$this->uid)->find();
  580. if (!$info) $this->error('藏品不存在');
  581. if ($info['status']==2) $this->error('藏品已转赠');
  582. $member = Db::name('store_member')->where('phone',$phone)->where('wallet_address',$wallet_address)->find();
  583. if (!$member) $this->error('转赠用户不存在');
  584. if ($member['id']==$this->uid) $this->error('不能转赠给自己');
  585. if (!$info['collectors_hash']) $this->error('发放中,无法转赠');
  586. $mem = getMemberInfoHash($this->uid);
  587. if ($mem['second_password']!=md5($second_password)) $this->error('密码错误');
  588. $pro_info = Db::name('store_collection')->where('id',$info['c_id'])->find();
  589. $log = Db::name('store_collect_examples_log')
  590. ->where('order_info_id',$id)
  591. ->find();
  592. if (!$log){
  593. if ($pro_info['one_given_day']!=0){
  594. $exam_time = strtotime($info['create_at'])+($pro_info['one_given_day']*24*60*60);
  595. if ($exam_time>time()) $this->error('持有时间限制,无法转赠');
  596. }
  597. }else{
  598. if ($pro_info['other_given_day']!=0){
  599. $exam_time = strtotime($log['create_at'])+($pro_info['other_given_day']*24*60*60);
  600. if ($exam_time>time()) $this->error('持有时间限制,无法转赠');
  601. }
  602. }
  603. $com = true;
  604. Db::startTrans();
  605. try {
  606. Db::name('store_order_info')
  607. ->where('id',$id)
  608. ->update(['status'=>2,'over_time'=>date('Y-m-d H:i:s'),'to_mid'=>$member['id']]);
  609. $to_date = [
  610. 'order_id'=>$info['order_id'],
  611. 'order_no'=>get_order_sn(),
  612. 'tag'=>$info['tag'],
  613. 'mid'=>$member['id'],
  614. 'c_id'=>$info['c_id'],
  615. 'name'=>$pro_info['name'],
  616. 'cover'=>$pro_info['cover'],
  617. 'pro_info'=>$info['pro_info'],
  618. 'type'=>$pro_info['type'],
  619. 'status'=>3,
  620. 'to_mid'=>$this->uid,
  621. 'over_time'=>date('Y-m-d H:i:s'),
  622. 'tokenid'=>$info['tokenid'],
  623. 'nfttype'=>$info['nfttype'],
  624. 'nftid'=>$info['nftid'],
  625. 'collectors_hash'=>'',
  626. 'collectors_hash_time'=>date('Y-m-d H:i:s')
  627. ];
  628. $new_id = Db::name('store_order_info')->insertGetId($to_date);
  629. $log_date = [
  630. 'order_info_id'=>$new_id,
  631. 'mid'=>$this->uid,
  632. 'to_mid'=>$member['id'],
  633. 'date'=>date('Y-m')
  634. ];
  635. Db::name('store_collect_examples_log')->insert($log_date);
  636. Db::commit();
  637. }catch (\Exception $e){
  638. $com = false;
  639. Db::rollback();
  640. }
  641. if ($com){
  642. DelRedisSetNx('examples'.$this->uid);
  643. $this->success('转赠成功');
  644. }
  645. DelRedisSetNx('examples'.$this->uid);
  646. $this->error('转赠失败');
  647. }else{
  648. $this->error('请求过快');
  649. }
  650. }
  651. /**
  652. * @title 消息列表
  653. * @desc 消息列表
  654. * @author Gavin
  655. * @method POST
  656. * @tag 编辑信息
  657. * @url /api/User_center/messageList
  658. * @header name:Authorization require:1 desc:Token
  659. *
  660. * @param name:page type:int : default:1 desc:页数
  661. * @param name:page_num type:int : default:20 desc:每页数
  662. *
  663. * @return name:id type:int require:0 default:0 desc:消息ID
  664. * @return name:title type:string require:0 default:0 desc:标题
  665. * @return name:content type:string require:0 default:0 desc:内容
  666. * @return name:create_at type:string require:0 default:0 desc:发布时间
  667. * @return name:is_read type:string require:0 default:0 desc:是否查看true:已查看false:未查看
  668. */
  669. public function messageList(){
  670. $count = Db::name('store_message')->where('is_deleted',0)->count();
  671. $list = Db::name('store_message')
  672. ->field('is_deleted,update_at',true)
  673. ->where('is_deleted',0)
  674. ->order('id desc')
  675. ->limit($this->off_set,$this->page_num)
  676. ->select();
  677. // echo Db::name('store_message')->getLastSql();die;
  678. foreach ($list as &$v){
  679. $is_read = Db::name('store_message_read_log')->where('mid',$this->uid)->where('message_id',$v['id'])->count();
  680. $v['is_read'] = $is_read ? true : false;
  681. }
  682. $this->success('成功',compact('count','list'));
  683. }
  684. /**
  685. * @title 点击消息
  686. * @desc 点击消息,查看消息
  687. * @author Gavin
  688. * @method POST
  689. * @tag 编辑信息
  690. * @url /api/User_center/readMessage
  691. * @header name:Authorization require:1 desc:Token
  692. *
  693. * @param name:id type:int : default:1 desc:消息ID
  694. *
  695. */
  696. public function readMessage(){
  697. $id = input('id');
  698. if (!$id) $this->error('参数错误');
  699. $log = Db::name('store_message_read_log')->where('message_id',$id)->where('mid',$this->uid)->count();
  700. if (!$log){
  701. $data = [
  702. 'mid'=>$this->uid,
  703. 'message_id'=>$id
  704. ];
  705. Db::name('store_message_read_log')->insert($data);
  706. }
  707. $this->success('成功');
  708. }
  709. /**
  710. * @title 人脸认证sign
  711. * @desc 人脸认证sign
  712. * @author Gavin
  713. * @method POST
  714. * @tag 编辑信息
  715. * @url /api/User_center/getFaceSign
  716. * @header name:Authorization require:1 desc:Token
  717. *
  718. *
  719. * @param name:name type:string default:1 desc:姓名
  720. * @param name:idNo type:string default:1 desc:身份证号
  721. *
  722. * @return name:sign type:string require: default:-- desc:签名
  723. *
  724. */
  725. public function getFaceSign(){
  726. parent::check_login();
  727. $name = input('name');
  728. $idNo = input('idNo');
  729. if (!$name || !$idNo) $this->error('参数错误');
  730. $userId = $this->uid;
  731. //$userId = get32Str();
  732. $data = getfaceid($name,$idNo,$userId);
  733. $this->success('成功',$data);
  734. }
  735. /**
  736. * @title 邀请记录
  737. * @desc 邀请记录
  738. * @author Gavin
  739. * @method POST
  740. * @tag 编辑信息
  741. * @url /api/User_center/invitedRecord
  742. * @header name:Authorization require:1 desc:Token
  743. *
  744. * @param name:page type:int : default:1 desc:页数
  745. * @param name:page_num type:int : default:20 desc:每页数
  746. *
  747. * @return name:id type:int require:0 default:0 desc:用户ID
  748. * @return name:headimg type:string require:0 default:0 desc:头像
  749. * @return name:name type:string require:0 default:0 desc:名称
  750. * @return name:create_at type:string require:0 default:0 desc:时间
  751. */
  752. public function invitedRecord(){
  753. parent::check_login();
  754. $count = Db::name('store_member')
  755. ->where('is_auth',1)
  756. ->where('pid',$this->uid)->count();
  757. $list = Db::name('store_member')
  758. ->field('id,headimg,name,create_at,phone,is_auth')
  759. ->where('pid',$this->uid)
  760. //->where('is_auth',1)
  761. ->order('id desc')
  762. ->limit($this->off_set,$this->page_num)
  763. ->select();
  764. foreach ($list as &$v){
  765. $v['phone'] = substr_replace($v['phone'],'****',3,4);
  766. $v['name'] = substr($v['name'],0,16);
  767. $v['create_at'] = date('Y-m-d',strtotime($v['create_at']));
  768. }
  769. $this->success('成功',compact('count','list'));
  770. }
  771. /**
  772. * @title 邀请排行榜
  773. * @desc 邀请排行榜
  774. * @author Gavin
  775. * @method POST
  776. * @tag 编辑信息
  777. * @url /api/User_center/invitedList
  778. * @header name:Authorization require:1 desc:Token
  779. *
  780. * @param name:page type:int : default:1 desc:页数
  781. * @param name:page_num type:int : default:20 desc:每页数
  782. *
  783. * @return name:id type:int require:0 default:0 desc:用户ID
  784. * @return name:headimg type:string require:0 default:0 desc:头像
  785. * @return name:name type:string require:0 default:0 desc:名称
  786. * @return name:phone type:string require:0 default:0 desc:手机号
  787. * @return name:create_at type:string require:0 default:0 desc:时间
  788. */
  789. public function invitedList(){
  790. $count = Db::name('store_member as a')
  791. ->field('a.id,a.name,a.headimg,a.phone,a.pid,(select count(b.id) from store_member as b where b.pid=a.id) as count')
  792. ->group('a.id')
  793. ->having('count>0')
  794. ->count();
  795. $list = Db::name('store_member as a')
  796. ->field('a.id,a.name,a.headimg,a.phone,a.pid,(select count(b.id) from store_member as b where b.pid=a.id) as count')
  797. ->group('a.id')
  798. ->having('count>0')
  799. ->order('count desc')
  800. ->limit($this->off_set,$this->page_num)
  801. ->select();
  802. $this->success('成功',compact('count','list'));
  803. }
  804. /**
  805. * @title 签到
  806. * @desc 签到
  807. * @author Gavin
  808. * @method POST
  809. * @tag 编辑信息
  810. * @url /api/User_center/sign
  811. * @header name:Authorization require:1 desc:Token
  812. *
  813. */
  814. public function sign(){
  815. parent::check_login();
  816. $date = date('Y-m-d');
  817. $log = Db::name('store_member_sign')->where('mid',$this->uid)->where('date',$date)->count();
  818. if ($log) $this->error('今日已签到');
  819. $data = [
  820. 'mid'=>$this->uid,
  821. 'date'=>$date
  822. ];
  823. $com = true;
  824. Db::startTrans();
  825. try {
  826. $id = Db::name('store_member_sign')->insertGetId($data);
  827. $sign_integral = getConfigValue('sign_integral');
  828. if ($sign_integral>0){
  829. memberMoneyChange($sign_integral,1,$this->uid,'签到',1,$id);
  830. }
  831. Db::commit();
  832. }catch (\Exception $e){
  833. $com=false;
  834. Db::rollback();
  835. }
  836. if ($com){
  837. $this->success('签到成功');
  838. }
  839. $this->error('签到失败');
  840. }
  841. /**
  842. * @title 积分记录
  843. * @desc 积分记录
  844. * @author Gavin
  845. * @method POST
  846. * @tag 编辑信息
  847. * @url /api/User_center/integralLog
  848. * @header name:Authorization require:1 desc:Token
  849. *
  850. * @param name:page type:int : default:1 desc:页数
  851. * @param name:page_num type:int : default:20 desc:每页数
  852. *
  853. * @return name:id type:int require:0 default:0 desc:id
  854. * @return name:change type:string require:0 default:0 desc:变动数值
  855. * @return name:title type:string require:0 default:0 desc:标题
  856. * @return name:create_at type:string require:0 default:0 desc:时间
  857. */
  858. public function integralLog(){
  859. parent::check_login();
  860. $where = [
  861. 'm_id'=>$this->uid,
  862. 'type'=>1
  863. ];
  864. $status = input('status');
  865. $count = Db::name('store_member_log')
  866. ->where($where)
  867. ->when($status,function ($query) use ($status){
  868. $pm = $status==1 ? 1 : 0;
  869. $query->where('pm',$pm);
  870. })
  871. ->count();
  872. $list = Db::name('store_member_log')
  873. ->field('id,pm,change,title,create_at')
  874. ->where($where)
  875. ->when($status,function ($query) use ($status){
  876. $pm = $status==1 ? 1 : 0;
  877. $query->where('pm',$pm);
  878. })
  879. ->order('id desc')
  880. ->limit($this->off_set,$this->page_num)
  881. ->select();
  882. foreach ($list as &$v){
  883. if ($v['pm']==1){
  884. $v['change'] = '+'.$v['change'];
  885. }else{
  886. $v['change'] = '-'.$v['change'];
  887. }
  888. }
  889. $this->success('成功',compact('count','list'));
  890. }
  891. /**
  892. * @title 余额记录
  893. * @desc 余额记录
  894. * @author Gavin
  895. * @method POST
  896. * @tag 编辑信息
  897. * @url /api/User_center/moneyLog
  898. * @header name:Authorization require:1 desc:Token
  899. *
  900. * @param name:page type:int : default:1 desc:页数
  901. * @param name:page_num type:int : default:20 desc:每页数
  902. *
  903. * @return name:id type:int require:0 default:0 desc:id
  904. * @return name:change type:string require:0 default:0 desc:变动数值
  905. * @return name:title type:string require:0 default:0 desc:标题
  906. * @return name:create_at type:string require:0 default:0 desc:时间
  907. */
  908. public function moneyLog(){
  909. parent::check_login();
  910. $where = [
  911. 'm_id'=>$this->uid,
  912. 'type'=>3
  913. ];
  914. $count = Db::name('store_member_log')->where($where)->count();
  915. $list = Db::name('store_member_log')
  916. ->field('id,pm,change,title,create_at')
  917. ->where($where)
  918. ->order('id desc')
  919. ->limit($this->off_set,$this->page_num)
  920. ->select();
  921. foreach ($list as &$v){
  922. if ($v['pm']==1){
  923. $v['change'] = '+'.$v['change'];
  924. }else{
  925. $v['change'] = '-'.$v['change'];
  926. }
  927. }
  928. $this->success('成功',compact('count','list'));
  929. }
  930. /**
  931. * @title 提现
  932. * @desc 提现
  933. * @author Gavin
  934. * @method POST
  935. * @tag 编辑信息
  936. * @url /api/User_center/withdraw
  937. * @header name:Authorization require:1 desc:Token
  938. *
  939. * @param name:money type:int : default: desc:提现金额
  940. * @param name:withdraw_type type:int : default: desc:提现方式
  941. *
  942. */
  943. public function withdraw(){
  944. parent::check_login();
  945. //redis原子锁
  946. if (redisSetNx('withdraw'.$this->uid,3)){
  947. $v = getConfigValue('withdraw_switch');
  948. if (!$v) $this->error('维护中,暂时关闭');
  949. $money = input('money');
  950. $withdraw_type = input('withdraw_type','bank');
  951. if (!$money) $this->error('参数错误');
  952. $user = Db::name('store_member')->where('id',$this->uid)->find();
  953. if ($user['money']<$money) $this->error('余额不足');
  954. $withdraw_min_price = getConfigValue('withdraw_min_price'); //最小提现金额
  955. $withdraw_max_price = getConfigValue('withdraw_max_price'); //最大提现金额
  956. $poundage_proportion = getConfigValue('poundage_proportion'); //手续费百分比
  957. if ($money < $withdraw_min_price)
  958. $this->error('最低提现'.$withdraw_min_price.'元');
  959. if ($money > $withdraw_max_price)
  960. $this->error('最大提现'.$withdraw_min_price.'元');
  961. if ($withdraw_type=='zfb'){
  962. if (!$user['zfb_account'] || !$user['zfb_real_name']) $this->error('请先绑定支付宝');
  963. }
  964. if ($withdraw_type=='bank'){
  965. if (!$user['withdraw_name'] || !$user['withdraw_bank_card']) $this->error('请先绑定提现银行卡');
  966. }
  967. $data['mid'] = $this->uid;
  968. $order_no = get_order_sn();
  969. $data['order_no'] = $order_no;
  970. $data['price'] = $money;
  971. $data['name'] = $user['withdraw_name'];
  972. $data['bank_id_card'] = $user['withdraw_bank_card'];
  973. $data['poundage_proportion'] = $poundage_proportion;
  974. $proportion = sprintf("%.2f", $money*($poundage_proportion/100)); //四舍五入保留两位小数点
  975. $data['proportion'] = $proportion;
  976. $real_money = $money-$proportion;
  977. $data['real_money'] = $real_money;
  978. $data['withdraw_type'] = $withdraw_type;
  979. $id =Db::name('store_member_withdraw')->insertGetId($data);
  980. if ($id){
  981. Db::startTrans();
  982. try {
  983. //减少用户余额
  984. $res = memberMoneyChange($money,3,$this->uid,'余额提现',0,$id);
  985. if ($res){
  986. Db::commit();
  987. DelRedisSetNx('withdraw'.$this->uid);
  988. $this->success('提交成功,等待审核');
  989. }else{
  990. Db::rollback();
  991. DelRedisSetNx('withdraw'.$this->uid);
  992. $this->error('提现失败,请稍后重试');
  993. }
  994. }catch (Exception $e) {
  995. Db::rollback();
  996. DelRedisSetNx('withdraw'.$this->uid);
  997. $this->error('提现失败,请稍后重试1');
  998. }
  999. }else{
  1000. DelRedisSetNx('withdraw'.$this->uid);
  1001. $this->error('提现失败,请稍后重试2');
  1002. }
  1003. }else{
  1004. $this->error('请求过快,请稍后重试');
  1005. }
  1006. }
  1007. /**
  1008. * @title 打开盲盒
  1009. * @desc 打开盲盒
  1010. * @author Gavin
  1011. * @method POST
  1012. * @tag 编辑信息
  1013. * @url /api/User_center/openBoxCollection
  1014. * @header name:Authorization require:1 desc:Token
  1015. *
  1016. * @param name:id type:int : default: desc:藏品ID
  1017. *
  1018. */
  1019. public function openBoxCollection(){
  1020. parent::check_login();
  1021. //redis原子锁
  1022. if (redisSetNx('openBox'.$this->uid,3)){
  1023. $id = input('id');
  1024. if (!$id) $this->error('参数错误');
  1025. $info = Db::name('store_order_info')
  1026. ->where('id',$id)
  1027. ->where('status','neq',2)
  1028. ->where('mid',$this->uid)
  1029. ->where('is_destruction',1)
  1030. ->find();
  1031. if (!$info) $this->error('盲盒不存在');
  1032. if ($info['resale_status']!=1) $this->error('盲盒挂售中或已出售');
  1033. $com = true;
  1034. Db::startTrans();
  1035. try {
  1036. //销毁
  1037. Db::name('store_order_info')->where('id',$id)->update(['is_destruction'=>0]);
  1038. checkBoxCollection($info['c_id']);
  1039. $prize_arr = Db::name('store_box')
  1040. ->where('status',1)
  1041. ->where('coll_id',$info['c_id'])
  1042. ->where('is_del',1)
  1043. ->field('id,rate')
  1044. ->select();
  1045. foreach ($prize_arr as $key => $val) {
  1046. $arr[$val['id']] = $val['rate'];//概率数组
  1047. }
  1048. $rid = get_rand($arr); //根据概率获取奖项id
  1049. $pr_info = Db::name('store_box')->where('id',$rid)->field('id,title,prize,is_prize')->find();
  1050. $return = [
  1051. 'is_prize'=>$pr_info['is_prize']
  1052. ];
  1053. $coll_info = getCollectionInfoHash($pr_info['prize']);
  1054. if ($pr_info['is_prize']==1){
  1055. $json_info = json_encode($coll_info,true);
  1056. $return['name'] = $pr_info['title'];
  1057. $return['cover'] = $coll_info['cover'];
  1058. }else{
  1059. $json_info = '';
  1060. $return['name'] = '未中奖';
  1061. $return['cover'] = '';
  1062. }
  1063. $data = [
  1064. 'm_id'=>$this->uid,
  1065. 'b_id'=>$rid,
  1066. 'is_prize'=>$pr_info['is_prize'],
  1067. 'name'=>$return['name'],
  1068. 'cover'=>$return['cover'],
  1069. 'info'=>$json_info,
  1070. 'date'=>date('Y-m-d'),
  1071. 'is_free'=>1
  1072. ];
  1073. Db::name('store_blind_box_log')->insert($data);
  1074. if ($pr_info['is_prize']==1){
  1075. //获取排名
  1076. $rank = getRanking($pr_info['prize'])+1;
  1077. $tag = getTag($pr_info['prize'],$rank,$coll_info['inventory']);
  1078. saveRanking($pr_info['prize']);
  1079. $is_nft = Db::name('hash2')->where('goods_id',$pr_info['prize'])->where('success',1)->find();
  1080. $collectors_hash = '';
  1081. $date = [
  1082. 'order_id'=>0,
  1083. 'order_no'=>get_order_sn(),
  1084. 'tag'=>$tag,
  1085. 'mid'=>$this->uid,
  1086. 'c_id'=>$pr_info['prize'],
  1087. 'name'=>$coll_info['name'],
  1088. 'cover'=>$coll_info['cover'],
  1089. 'pro_info'=>$json_info,
  1090. 'tokenid'=>$is_nft['class_id'],
  1091. 'nfttype'=>$is_nft['operationId'],
  1092. 'collectors_hash'=>$collectors_hash,
  1093. 'collectors_hash_time'=>'',
  1094. 'status'=>4
  1095. ];
  1096. Db::name('store_order_info')->insert($date);
  1097. }
  1098. Db::commit();
  1099. }catch (Exception $e) {
  1100. $com = false;
  1101. Db::rollback();
  1102. }
  1103. if ($com){
  1104. setMemberInfoHash($this->uid);
  1105. if ($pr_info['is_prize']==1){
  1106. //减掉库存
  1107. loseCollectionInventory($pr_info['prize'],1);
  1108. }
  1109. DelRedisSetNx('openBox'.$this->uid);
  1110. $this->success('成功',$return);
  1111. }else{
  1112. DelRedisSetNx('openBox'.$this->uid);
  1113. $this->error('开启失败,请稍后重试');
  1114. }
  1115. }else{
  1116. $this->error('请求过快');
  1117. }
  1118. }
  1119. /**
  1120. * @title 抢购卡列表
  1121. * @desc 抢购卡列表
  1122. * @author Gavin
  1123. * @method POST
  1124. * @tag 编辑信息
  1125. * @url /api/User_center/snapLog
  1126. * @header name:Authorization require:1 desc:Token
  1127. *
  1128. * @param name:page type:int : default:1 desc:页数
  1129. * @param name:page_num type:int : default:20 desc:每页数
  1130. *
  1131. */
  1132. public function snapLog(){
  1133. parent::check_login();
  1134. checksnapcard($this->uid);
  1135. $status = input('status',1);
  1136. $list = Db::name('store_snap_card_log')
  1137. ->where('m_id',$this->uid)
  1138. ->where('is_use',$status)
  1139. ->select();
  1140. foreach ($list as &$v){
  1141. if ($v['type']==2){
  1142. $v['collection_name'] = Db::name('store_collection')->where('id',$v['collection_id'])->value('name');
  1143. }
  1144. }
  1145. $this->success('成功',$list);
  1146. }
  1147. /**
  1148. * @title 签约银行卡发送短信
  1149. * @desc 签约银行卡发送短信
  1150. * @author Gavin
  1151. * @method POST
  1152. * @tag 编辑信息
  1153. * @url /api/User_center/bindCardsms
  1154. * @header name:Authorization require:1 desc:Token
  1155. */
  1156. public function bindCardsms(){
  1157. parent::check_login();
  1158. $name = input('name');
  1159. $id_card_no = input('id_card_no');
  1160. $bank_card_no = input('bank_card_no');
  1161. $mobile = input('mobile');
  1162. if (!$name || !$id_card_no || !$bank_card_no || !$mobile) $this->error('参数错误');
  1163. $check_id_card = isCreditNo($id_card_no);
  1164. if (!$check_id_card) $this->error('身份证号格式错误');
  1165. if (!checkbank($bank_card_no)) $this->error('银行卡号格式错误');
  1166. if (!Validate::regex($mobile, "^1\d{10}$")) $this->error('手机号格式错误');
  1167. $huiju = new HuijuKjPay();
  1168. $result = $huiju->sms($name,$id_card_no,$bank_card_no,$mobile);
  1169. if ($result['resp_codo']=='SUCCESS'){
  1170. if ($result['biz_code']=='JS000000'){
  1171. $data = json_decode($result['data'],true);
  1172. if ($data['order_status']=='P3000'){
  1173. $this->success('发送成功',$result);
  1174. }else{
  1175. $this->error($data['err_msg']);
  1176. }
  1177. }else{
  1178. $this->error($result['biz_msg']);
  1179. }
  1180. }else{
  1181. $this->error('发送失败');
  1182. }
  1183. }
  1184. /**
  1185. * @title 签约银行卡
  1186. * @desc 签约银行卡
  1187. * @author Gavin
  1188. * @method POST
  1189. * @tag 编辑信息
  1190. * @url /api/User_center/bindCard
  1191. * @header name:Authorization require:1 desc:Token
  1192. */
  1193. public function bindCard(){
  1194. parent::check_login();
  1195. $name = input('name');
  1196. $id_card_no = input('id_card_no');
  1197. $bank_card_no = input('bank_card_no');
  1198. $mobile = input('mobile');
  1199. $seckey = input('seckey');
  1200. $mch_order_no = input('mch_order_no');
  1201. $sms_code = input('sms_code');
  1202. if (!$name || !$id_card_no || !$bank_card_no || !$mobile || !$seckey || !$mch_order_no || !$sms_code) $this->error('参数错误');
  1203. $check_id_card = isCreditNo($id_card_no);
  1204. if (!$check_id_card) $this->error('身份证号格式错误');
  1205. if (!checkbank($bank_card_no)) $this->error('银行卡号格式错误');
  1206. if (!Validate::regex($mobile, "^1\d{10}$")) $this->error('手机号格式错误');
  1207. $huiju = new HuijuKjPay();
  1208. $result = $huiju->signing($seckey,$mch_order_no,$sms_code);
  1209. if ($result['resp_codo']=='SUCCESS'){
  1210. if ($result['biz_code']=='JS000000'){
  1211. $data = json_decode($result['data'],true);
  1212. if ($data['order_status']=='P1000'){
  1213. $date = [
  1214. 'hj_pay_name'=>$name,
  1215. 'hj_pay_id_card'=>$id_card_no,
  1216. 'hj_pay_bank_card'=>$bank_card_no,
  1217. 'hj_pay_mobile'=>$mobile,
  1218. 'hj_pay_status'=>1,
  1219. 'hj_pay_time'=>date('Y-m-d H:i:s')
  1220. ];
  1221. if (Db::name('store_member')->where('id',$this->uid)->update($date)){
  1222. setMemberInfoHash($this->uid);
  1223. $this->success('签约成功',$result);
  1224. }else{
  1225. $this->error('签约失败');
  1226. }
  1227. }else{
  1228. $this->error($data['err_msg']);
  1229. }
  1230. }else{
  1231. $this->error($result['biz_msg']);
  1232. }
  1233. }else{
  1234. $this->error('签约失败');
  1235. }
  1236. }
  1237. /**
  1238. * @title 绑定提现银行卡
  1239. * @desc 绑定提现银行卡
  1240. * @author Gavin
  1241. * @url /api/User_center/bind_withdraw_card
  1242. * @method POST
  1243. * @tag 编辑信息
  1244. * @header name:Authorization require:1 desc:Token
  1245. *
  1246. * @param name:withdraw_name type:string require:0 default:-- desc:姓名
  1247. * @param name:withdraw_bank_card type:string require:0 default:-- desc:卡号
  1248. */
  1249. public function bind_withdraw_card(){
  1250. parent::check_login();
  1251. $this->check_login();
  1252. $withdraw_name = input('withdraw_name');
  1253. $withdraw_bank_card = input('withdraw_bank_card');
  1254. if (!$withdraw_name) $this->error('姓名为空');
  1255. if (!$withdraw_bank_card) $this->error('卡号为空');
  1256. if (!checkbank($withdraw_bank_card)) $this->error('银行卡号格式错误');
  1257. $update_data['withdraw_name'] = $withdraw_name;
  1258. $update_data['withdraw_bank_card'] = $withdraw_bank_card;
  1259. $update_data['update_at'] = date('Y-m-d H:i:s');
  1260. if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){
  1261. setMemberInfoHash($this->uid);
  1262. $this->success('绑定成功');
  1263. }
  1264. $this->error('绑定失败');
  1265. }
  1266. }