UserCenter.php 50 KB

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