UserCenter.php 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  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\LianLianPay;
  8. use think\cache\driver\Redis;
  9. use think\Db;
  10. use think\Exception;
  11. require_once env('root_path').'application/common/library/llp/src/cfg.php';
  12. /**
  13. * @title 会员个人中心
  14. * @controller UserCenter
  15. * @group base
  16. */
  17. class UserCenter extends Base
  18. {
  19. public function initialize()
  20. {
  21. parent::initialize();
  22. parent::check_login();
  23. }
  24. /**
  25. * @title 获取个人信息
  26. * @desc 个人信息
  27. * @author Gavin
  28. * @url /api/User_center/getUserInfo
  29. * @method POST
  30. * @tag 个人信息
  31. * @header name:Authorization require:1 desc:Token
  32. * @return name:id type:int default:-- desc:ID(邀请ID)
  33. * @return name:phone type:string default:-- desc:手机号
  34. * @return name:name type:string default:-- desc:昵称
  35. * @return name:headimg type:string default:-- desc:头像地址
  36. * @return name:integral type:int default:-- desc:积分
  37. * @return name:snap_card type:int default:-- desc:抢购卡
  38. * @return name:wallet_address type:int default:-- desc:钱包地址
  39. * @return name:true_name type:string default:-- desc:真实姓名
  40. * @return name:id_card type:string default:-- desc:身份证号
  41. * @return name:is_auth type:int default:-- desc:是否认证(0否1是)
  42. * @return name:auth_at type:string default:-- desc:认证时间
  43. * @return name:vip_name type:int default:-- desc:身份
  44. * @return name:bank_num type:string default:-- desc:银行卡号【判断是否绑定银行卡】
  45. * @return name:bank_user type:string default:-- desc:银行卡持有人
  46. * @return name:is_order_no_paid type:string default:-- desc:是否有未支付订单true:有false:没有
  47. * @return name:is_sign type:string default:-- desc:今日是否已经签到true:已签到false:未签到
  48. * @return name:invite_img type:string default:-- desc:邀请二维码
  49. * @return name:invite_address type:string default:-- desc:邀请地址
  50. * @return name:lucky_number type:int default:-- desc:剩余抽奖次数
  51. * @return name:money type:string default:-- desc:余额
  52. * @return name:share_poster type:string default:-- desc:分享海报
  53. */
  54. public function getUserInfo()
  55. {
  56. $uid = $this->uid;
  57. $user_info = Db::name('store_member')
  58. ->field('password,second_password',true)
  59. ->where('id',$uid)
  60. ->find();
  61. if(empty($user_info)) $this->error('用户信息不正确');
  62. $user_info['vip_name'] = '普通会员';
  63. //是否有待支付订单
  64. $order = Db::name('store_order')->where('status',0)->where('is_deleted',0)->where('mid',$uid)->count();
  65. $user_info['is_order_no_paid'] = $order ? true : false;
  66. $user_info['is_sign'] = 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. //生成邀请码
  75. if (!$user_info['invite_img'] || !$user_info['invite_address']){
  76. $code = $user_info['invite_code'];
  77. $invite_img = setintivecode($code);
  78. $invite_address = getintiveaddress($code);
  79. Db::name('store_member')->where('id',$this->uid)->update(['invite_img'=>$invite_img,'invite_address'=>$invite_address]);
  80. }
  81. $user_info['invite_img'] = str_replace('http:','https:',$user_info['invite_img']);
  82. $user_info['share_poster'] = sysconf('share_poster');
  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. $code = input('code');
  99. if(empty($code)) $this->error('参数错误');
  100. $appid = 'wx8e47a12d0a1c007f';
  101. $secret = 'f19bfac2108af3aee75df0a31a1fee1c';
  102. $res = http_get('https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$secret.'&code='.$code.'&grant_type=authorization_code');
  103. $res = json_decode($res,true);
  104. if (isset($res['openid'])){
  105. $update_data['openid'] = $res['openid'];
  106. $update_data['update_at'] = date('Y-m-d H:i:s');
  107. if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){
  108. setMemberInfoHash($this->uid);
  109. $this->success('绑定成功');
  110. }
  111. $this->error('绑定失败');
  112. }else{
  113. $this->error('获取openid失败');
  114. }
  115. }
  116. /**
  117. * @title 编辑个人信息
  118. * @desc 编辑个人信息
  119. * @author Gavin
  120. * @url /api/User_center/updateUserInfo
  121. * @method POST
  122. * @tag 编辑信息
  123. * @header name:Authorization require:1 desc:Token
  124. *
  125. * @param name:name type:string require:0 default:-- desc:姓名
  126. * @param name:headimg type:string require:0 default:-- desc:头像地址
  127. */
  128. public function updateUserInfo()
  129. {
  130. $headimg = input('post.headimg');
  131. $name = trim(input('post.name',''));
  132. if(!$headimg && !$name) $this->error('参数错误');
  133. $update_data= [];
  134. if($name) $update_data['name'] = $name;
  135. if ($headimg) $update_data['headimg'] = $headimg;
  136. if($name){
  137. $check_member = Db::name('store_member')
  138. ->where('name',$name)
  139. ->where('id','<>',$this->uid)
  140. ->count();
  141. if($check_member) $this->error('该用户名已被占用');
  142. }
  143. $update_data['update_at'] = date('Y-m-d H:i:s');
  144. if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){
  145. setMemberInfoHash($this->uid);
  146. $this->success('编辑成功');
  147. }
  148. $this->error('编辑失败');
  149. }
  150. /**
  151. * @title 绑定支付宝
  152. * @desc 绑定支付宝
  153. * @author Gavin
  154. * @url /api/User_center/bind_zfb
  155. * @method POST
  156. * @tag 编辑信息
  157. * @header name:Authorization require:1 desc:Token
  158. *
  159. * @param name:account type:string require:0 default:-- desc:支付宝账号
  160. * @param name:zfb_real_name type:string require:0 default:-- desc:真实姓名
  161. */
  162. public function bind_zfb(){
  163. $account = input('account'); //账号
  164. $real_name = input('real_name'); //真实姓名
  165. if (!$account) $this->error('支付宝账号为空');
  166. if (!$real_name) $this->error('真实姓名为空');
  167. $update_data['zfb_account'] = $account;
  168. $update_data['zfb_real_name'] = $real_name;
  169. $update_data['update_at'] = date('Y-m-d H:i:s');
  170. if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){
  171. setMemberInfoHash($this->uid);
  172. $this->success('绑定成功');
  173. }
  174. $this->error('绑定失败');
  175. }
  176. /**
  177. * @title 绑定【更换绑定】银行卡
  178. * @desc 绑定【更换绑定】银行卡
  179. * @author qc
  180. * @url /api/User_center/bind_bank
  181. * @method POST
  182. * @tag 编辑信息
  183. * @header name:Authorization require:1 desc:Token
  184. *
  185. * @param name:bank_num type:string require:0 default:-- desc:银行卡号
  186. * @param name:bank_user type:string require:0 default:-- desc:姓名
  187. */
  188. public function bind_bank(){
  189. $bank_num = input('bank_num'); //账号
  190. $bank_user = input('bank_user'); //真实姓名
  191. $pay_password = input('pay_password'); //真实姓名
  192. if (!$bank_num) $this->error('银行卡号不能为空');
  193. if (!$bank_user) $this->error('姓名不能为空');
  194. if(check_bankCard($bank_num) != 1) $this->error('银行卡格式错误');
  195. $user_info = Db::name('store_member')->where('id',$this->uid)->find();
  196. if ($user_info['bank_num'] == $bank_num && $user_info['bank_user'] == $bank_user) $this->error('与原绑定信息一致');
  197. $update_data['bank_num'] = $bank_num;
  198. $update_data['bank_user'] = $bank_user;
  199. if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){
  200. setMemberInfoHash($this->uid);
  201. $this->success('绑定成功');
  202. }
  203. $this->error('绑定失败');
  204. }
  205. /**
  206. * @title 实名认证
  207. * @desc 实名认证
  208. * @author Gavin
  209. * @method POST
  210. * @tag 编辑信息
  211. * @url /api/User_center/userCertification
  212. * @header name:Authorization require:1 desc:Token
  213. * @param name:true_name type:string require:1 default:-- desc:真实姓名
  214. * @param name:id_card type:string require:1 default:-- desc:身份证号
  215. */
  216. public function userCertification(){
  217. $true_name = input('post.true_name');
  218. $id_card = input('post.id_card');
  219. if (!$true_name || !$id_card) $this->error('参数错误');
  220. $check_id_card = isCreditNo($id_card);
  221. if (!$check_id_card) $this->error('身份证号格式错误');
  222. $is_auth = Db::table('store_member')->where('id',$this->uid)->value('is_auth');
  223. if($is_auth) $this->error('已认证');
  224. $check = Db::name('store_member')->where('id_card',$id_card)->where('is_deleted',0)->count();
  225. if ($check) $this->error('身份证号已经认证过');
  226. if (!identifyCertification($id_card,$true_name)) $this->error('身份证与姓名验证失败');
  227. 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')])){
  228. setMemberInfoHash($this->uid);
  229. $this->success('认证成功');
  230. }
  231. $this->error('认证失败');
  232. }
  233. /**
  234. * @title 修改密码
  235. * @desc 修改密码
  236. * @author Gavin
  237. * @method POST
  238. * @tag 编辑信息
  239. * @url /api/User_center/updatePass
  240. * @header name:Authorization require:1 desc:Token
  241. * @param name:old_password type:string require:1 default:-- desc:旧密码
  242. * @param name:new_password type:string require:1 default:-- desc:新密码
  243. * @param name:confirm_password type:string require:1 default:-- desc:确认密码
  244. */
  245. public function updatePass()
  246. {
  247. $old_password = input('post.old_password');
  248. $new_password = input('post.new_password');
  249. $confirm_password = input('post.confirm_password');
  250. if (!$old_password || !$new_password || !$confirm_password) $this->error('参数错误');
  251. if ($new_password!=$confirm_password) $this->error('密码与确认密码不一致');
  252. if (!preg_match('/^[0-9a-z]{6,12}$/i',$new_password)) $this->error('密码格式错误,请输入6-12位数字+字母');
  253. $member = Db::name('store_member')->where('id',$this->uid)->find();
  254. if ($member['password']!=md5($old_password)) $this->error('旧密码错误');
  255. $data['password'] = md5($new_password);
  256. $data['update_at'] = date('Y-m-d H:i:s');
  257. if (Db::name('store_member')->where('id',$this->uid)->update($data)){
  258. setMemberInfoHash($this->uid);
  259. $this->success('修改成功');
  260. }
  261. $this->error('修改失败');
  262. }
  263. /**
  264. * @title 修改支付密码
  265. * @desc 修改支付密码
  266. * @author Gavin
  267. * @method POST
  268. * @tag 编辑信息
  269. * @url /api/User_center/updateSecondPass
  270. * @header name:Authorization require:1 desc:Token
  271. * @param name:second_password type:string require:1 default:-- desc:支付密码
  272. * @param name:confirm_second_password type:string require:1 default:-- desc:确认密码
  273. */
  274. public function updateSecondPass()
  275. {
  276. $second_password = input('post.second_password');
  277. $confirm_second_password = input('post.confirm_second_password');
  278. $yzm = input('post.yzm');
  279. if (!$second_password || !$confirm_second_password) $this->error('参数错误');
  280. if ($second_password!=$confirm_second_password) $this->error('密码与确认密码不一致');
  281. if (!preg_match('/^[0-9]{6}$/i',$second_password)) $this->error('支付密码格式错误,请输入6位纯数字');
  282. $member = getMemberInfoHash($this->uid); //获取用户信息
  283. //验证短信验证码
  284. // $time = time()-60;
  285. // $sms = Db::name('store_sms')->where(['mobile' => $member['phone'], 'event' => 'forgetpwd'])
  286. // ->where('createtime','>',$time)
  287. // ->order('id', 'DESC')
  288. // ->find();
  289. // if (!$sms || $sms['code'] != $yzm) $this->error('短信验证码不正确!');
  290. $data['second_password'] = md5($second_password);
  291. $data['update_at'] = date('Y-m-d H:i:s');
  292. if (Db::name('store_member')->where('id',$this->uid)->update($data)){
  293. setMemberInfoHash($this->uid);
  294. $this->success('修改成功');
  295. }
  296. $this->error('修改失败');
  297. }
  298. /**
  299. * @title 我的藏品
  300. * @desc 我的藏品
  301. * @author Gavin
  302. * @method POST
  303. * @tag 编辑信息
  304. * @url /api/User_center/myCollection
  305. * @header name:Authorization require:1 desc:Token
  306. * @param name:type type:int require:0 default:1 desc:类型(0全部1:藏品,3:盲盒)
  307. * @return name:id type:int require:0 default:0 desc:藏品ID
  308. * @return name:tag type:string require:0 default:0 desc:唯一标签
  309. * @return name:name type:string require:0 default:0 desc:藏品名称
  310. * @return name:type type:int default:1 desc:类型(1:藏品,3:盲盒)
  311. * @return name:cover type:string require:0 default:0 desc:藏品图片
  312. * @return name:resale_price type:string require:0 default:0 desc:二级市场挂售价格
  313. * @return name:auth_img type:string require:0 default:0 desc:作者头像
  314. * @return name:auth_name type:string require:0 default:0 desc:作者名称
  315. * @return name:resale_status type:string require:0 default:0 desc:1:未挂售2挂售中3已出售
  316. * @return name:is_destruction type:int require:0 default:0 desc:1:盲盒状态1未开启0已开启
  317. * @return name:send_btn type:int require:0 default:0 desc:是否可以赠送1是0否
  318. * @return name:send_time type:string require:0 default:-- desc:可以赠时间【send_btn=1时为空】
  319. */
  320. public function myCollection(){
  321. $type = input('type',1);
  322. $list = Db::name('store_order_info')
  323. ->where('mid',$this->uid)
  324. ->where('status','neq','2')
  325. ->where('is_destruction',1)
  326. ->where('resale_status',1)
  327. ->when($type,function ($query)use($type){ if($type) $query->where('type',$type);})
  328. ->field('id,c_id,tag,pro_info,resale_status,resale_price,type,is_destruction,create_at')
  329. ->order('id desc')
  330. ->select();
  331. foreach ($list as &$v){
  332. $pro_info = json_decode($v['pro_info'],true);
  333. $v['name'] = $pro_info['name'];
  334. $v['cover'] = $pro_info['cover'];
  335. $v['auth_img'] = $pro_info['auth_img'];
  336. $v['auth_name'] = $pro_info['auth_name'];
  337. $goods_info = Db::name('store_collection')->where('id',$v['c_id'])->find();
  338. $log = Db::name('store_collect_examples_log')->where('order_info_id',$v['id'])->find();
  339. $v['send_btn'] = 1;
  340. $v['send_time'] = '';
  341. if (!$log){
  342. if ($goods_info['one_given_day']!=0) {
  343. $exam_time = strtotime($v['create_at'])+($goods_info['one_given_day']*60*60);
  344. if ($exam_time>time()){
  345. $v['send_btn'] = 0;
  346. $v['send_time'] = date('Y-m-d H:i:s',$exam_time);
  347. }
  348. }
  349. }else{
  350. if ($pro_info['other_given_day']!=0){
  351. $exam_time = strtotime($log['create_at'])+($pro_info['other_given_day']*60*60);
  352. if ($exam_time>time()) {
  353. $v['send_btn'] = 0;
  354. $v['send_time'] = date('Y-m-d H:i:s',$exam_time);
  355. }
  356. }
  357. }
  358. unset($v['pro_info']);
  359. }
  360. $this->success('成功',$list);
  361. }
  362. /**
  363. * @title 我的藏品(折叠)
  364. * @desc 我的藏品
  365. * @author QC
  366. * @method POST
  367. * @tag 编辑信息
  368. * @url /api/User_center/myCollectionGroupBy
  369. * @header name:Authorization require:1 desc:Token
  370. * @return name:num type:int default:0 desc:同组下几个藏品【最小是1】
  371. * @return name:jump_id type:int default:0 desc:同组下最新的收藏记录id[只有一个可以用这个作为跳转详情的id]
  372. * @return name:tag type:string default:0 desc:唯一标签
  373. * @return name:name type:string require:0 default:0 desc:藏品名称
  374. * @return name:cover type:string require:0 default:0 desc:藏品图片
  375. * @return name:auth_img type:string require:0 default:0 desc:作者头像
  376. * @return name:auth_name type:string require:0 default:0 desc:作者名称
  377. * @return name:total_num type:int require:0 default:0 desc:总数
  378. */
  379. public function myCollectionGroupBy(){
  380. $type = input('type',1);
  381. $group_list = Db::name('store_order_info')
  382. ->field('c_id,count(id) num ,max(id) jump_id')
  383. ->where('mid',$this->uid)
  384. ->where('status','neq','2')
  385. ->where('is_destruction',1)
  386. ->where('resale_status',1)
  387. ->when($type,function ($query)use($type){ if($type) $query->where('type',$type);})
  388. ->group('c_id')
  389. ->select();
  390. array_walk($group_list,function (&$val){
  391. $min_info = Db::name('store_order_info')->field('tag,pro_info')->where('id',$val['jump_id'])->find();
  392. $pro_info = json_decode($min_info['pro_info'],true);
  393. $val['tag'] = $min_info['tag'];
  394. $val['name'] = $pro_info['name'];
  395. $val['cover'] = $pro_info['cover'];
  396. $val['auth_img'] = $pro_info['auth_img'];
  397. $val['auth_name'] = $pro_info['auth_name'];
  398. });
  399. $this->success('成功',['list'=>$group_list,'total_num'=>!empty($group_list)?array_sum(array_column($group_list,'num')):0]);
  400. }
  401. /**
  402. * @title 我的藏品(展开)
  403. * @desc 我的藏品(展开)
  404. * @author QC
  405. * @method POST
  406. * @tag 编辑信息
  407. * @url /api/User_center/unfoldCollection
  408. * @header name:Authorization require:1 desc:Token
  409. * @param name:c_id type:int require:0 default:1 desc:myCollectionGroupBy接口的c_id[商品id]
  410. * @return name:id type:int require:0 default:0 desc:藏品ID
  411. * @return name:tag type:string require:0 default:0 desc:唯一标签
  412. * @return name:name type:string require:0 default:0 desc:藏品名称
  413. * @return name:type type:int default:1 desc:类型(1:藏品,3:盲盒)
  414. * @return name:cover type:string require:0 default:0 desc:藏品图片
  415. * @return name:resale_price type:string require:0 default:0 desc:二级市场挂售价格
  416. * @return name:auth_img type:string require:0 default:0 desc:作者头像
  417. * @return name:auth_name type:string require:0 default:0 desc:作者名称
  418. */
  419. public function unfoldCollection()
  420. {
  421. $c_id = input('c_id');
  422. $list = Db::name('store_order_info')
  423. ->field('id,tag,pro_info,resale_status,resale_price,type,is_destruction')
  424. ->where('c_id',$c_id)
  425. ->where('mid',$this->uid)
  426. ->where('status','neq','2')
  427. ->where('is_destruction',1)
  428. ->where('resale_status',1)
  429. ->order('id desc')
  430. ->select();
  431. array_walk($list,function (&$val){
  432. $pro_info = json_decode($val['pro_info'],true);
  433. $val['name'] = $pro_info['name'];
  434. $val['cover'] = $pro_info['cover'];
  435. $val['auth_img'] = $pro_info['auth_img'];
  436. $val['auth_name'] = $pro_info['auth_name'];
  437. unset($val['pro_info']);
  438. });
  439. $this->success('ok',$list);
  440. }
  441. /**
  442. * @title 我的盲盒
  443. * @desc 我的盲盒
  444. * @author Gavin
  445. * @method POST
  446. * @tag 编辑信息
  447. * @url /api/User_center/myBoxCollection
  448. * @header name:Authorization require:1 desc:Token
  449. * @return name:id type:int require:0 default:0 desc:藏品ID
  450. * @return name:tag type:string require:0 default:0 desc:唯一标签
  451. * @return name:name type:string require:0 default:0 desc:藏品名称
  452. * @return name:cover type:string require:0 default:0 desc:藏品图片
  453. * @return name:auth_img type:string require:0 default:0 desc:作者头像
  454. * @return name:auth_name type:string require:0 default:0 desc:作者名称
  455. */
  456. public function myBoxCollection(){
  457. $list = Db::name('store_order_info')
  458. ->where('mid',$this->uid)
  459. ->where('status','neq','2')
  460. ->where('type',3)
  461. ->where('is_destruction',1)
  462. ->where('resale_status',1)
  463. ->field('id,tag,pro_info')
  464. ->order('id desc')
  465. ->select();
  466. foreach ($list as &$v){
  467. $pro_info = json_decode($v['pro_info'],true);
  468. $v['name'] = $pro_info['name'];
  469. $v['cover'] = $pro_info['cover'];
  470. $v['auth_img'] = $pro_info['auth_img'];
  471. $v['auth_name'] = $pro_info['auth_name'];
  472. unset($v['pro_info']);
  473. }
  474. $this->success('成功',$list);
  475. }
  476. /**
  477. * @title 藏品详情
  478. * @desc 藏品详情
  479. * @author Gavin
  480. * @method POST
  481. * @tag 编辑信息
  482. * @url /api/User_center/myCollectionDetail
  483. * @header name:Authorization require:1 desc:Token
  484. * @param name:id type:int require:1 default:-- desc:藏品ID
  485. *
  486. * @return name:id type:int require:0 default:0 desc:藏品ID
  487. * @return name:tag type:string require:0 default:0 desc:唯一标签
  488. * @return name:type type:int require:0 default:1 desc:类型1:藏品,3:盲盒
  489. * @return name:collectors_name type:string require:0 default:0 desc:收藏者
  490. * @return name:collectors_hash type:string require:0 default:0 desc:收藏者hash
  491. * @return name:create_at type:string require:0 default:0 desc:收藏时间
  492. * @return name:company type:string require:0 default:0 desc:流转公司
  493. * @return name:send_btn type:int require:0 default:0 desc:是否可以赠送1是0否
  494. * @return name:send_time type:string require:0 default:-- desc:可以赠时间【send_btn=1时为空】
  495. * @return name:company_hash type:string require:0 default:0 desc:流转公司hash
  496. * @return name:contract_address type:string require:0 default:0 desc:合约地址
  497. * @return name:resale_status type:string require:0 default:0 desc:1:未挂售2挂售中3已出售
  498. * @return name:is_destruction type:int require:0 default:0 desc:1:盲盒状态1未开启0已开启
  499. * @return name:resale_price type:float require:0 default:0 desc:二级市场挂售价格
  500. * @return name:examples_illustrate type:string require:0 default:0 desc:转赠说明
  501. * @return name:sell_illustrate type:string require:0 default:0 desc:寄售须知
  502. * @return name:royalties_rate type:string require:0 default:0 desc:上架版税率【版权税】
  503. * @return name:royalties type:string require:0 default:0 desc:上架版税【版权税】
  504. * @return name:service_fee_rate type:string require:0 default:0 desc:服务费率
  505. * @return name:service_fee type:string require:0 default:0 desc:服务费
  506. * @return name:pro_info@name type:string require:0 default:0 desc:藏品名称
  507. * @return name:pro_info@price type:string require:0 default:0 desc:藏品价格
  508. * @return name:pro_info@label type:string require:0 default:0 desc:藏品标签
  509. * @return name:pro_info@cover type:string require:0 default:0 desc:藏品图片
  510. * @return name:pro_info@auth_img type:string require:0 default:0 desc:作者头像
  511. * @return name:pro_info@auth_name type:string require:0 default:0 desc:作者姓名
  512. * @return name:pro_info@warm_prompt type:string require:0 default:0 desc:温馨提示
  513. * @return name:pro_info@share_img type:string require:0 default:0 desc:分享二维码
  514. */
  515. public function myCollectionDetail(){
  516. $id = input('id');
  517. if (!$id) $this->error('参数错误');
  518. $info = Db::name('store_order_info')
  519. ->where('mid',$this->uid)
  520. ->where('id',$id)
  521. ->find();
  522. if (!$info) $this->error('藏品不存在');
  523. $info['pro_info'] = json_decode($info['pro_info'],true);
  524. if (!isset($info['pro_info']['share_img'])){
  525. //$info['pro_info']['share_img'] = Db::name('store_collection')->where('id',$info['pro_info']['id'])->value('share_img');
  526. }
  527. $info['collectors_name'] = Db::name('store_member')->where('id',$this->uid)->value('name');
  528. $info['collectors_hash'] = $info['collectors_hash']=='' ? "发放中" : $info['collectors_hash'];
  529. $info['collectors_hash_time'] = $info['collectors_hash_time']=='' ? "发放中" : $info['collectors_hash_time'];
  530. $info['examples_illustrate'] = Db::table('system_config')->where('name','examples_illustrate')->value('value');
  531. $info['sell_illustrate'] = Db::table('system_config')->where('name','sell_illustrate')->value('value');
  532. $discount = getMemberServiceCharge($this->uid);// 折扣
  533. $service_fee_rate = Db::table('system_config')->where('name','service_fee')->value('value');
  534. $royalties_rate = Db::table('system_config')->where('name','royalties')->value('value');
  535. $info['service_fee_rate'] = bcmul($service_fee_rate,$discount).'%';
  536. $info['royalties_rate'] =bcmul($royalties_rate,$discount).'%';
  537. $info['service_fee'] = sprintf("%.2f", $info['resale_price'] * (bcmul($service_fee_rate,$discount)/100));
  538. $info['royalties'] = sprintf("%.2f", $info['resale_price'] * (bcmul($royalties_rate,$discount)/100));
  539. $info['contract_address'] = '0c214bcd4f1766fdd6d36f127234fc7e7ba883711e19938777f01523c28e74dc';
  540. $goods_info = Db::name('store_collection')->where('id',$info['c_id'])->find();
  541. $log = Db::name('store_collect_examples_log')->where('order_info_id',$info['id'])->find();
  542. $info['send_btn'] = 1;
  543. $info['send_time'] = '';
  544. if (!$log){
  545. if ($goods_info['one_given_day']!=0) {
  546. $exam_time = strtotime($info['create_at'])+($goods_info['one_given_day']*60*60);
  547. if ($exam_time>time()){
  548. $info['send_btn'] = 0;
  549. $info['send_time'] = date('Y-m-d H:i:s',$exam_time);
  550. }
  551. }
  552. }else{
  553. if ($goods_info['other_given_day']!=0){
  554. $exam_time = strtotime($log['create_at'])+($goods_info['other_given_day']*60*60);
  555. if ($exam_time>time()) {
  556. $info['send_btn'] = 0;
  557. $info['send_time'] = date('Y-m-d H:i:s',$exam_time);
  558. }
  559. }
  560. }
  561. $this->success('成功',$info);
  562. }
  563. /**
  564. * @title 转赠
  565. * @desc 转赠
  566. * @author Gavin
  567. * @method POST
  568. * @tag 编辑信息
  569. * @url /api/User_center/examples
  570. * @header name:Authorization require:1 desc:Token
  571. * @param name:id type:int require:1 default:-- desc:藏品ID
  572. * @param name:phone type:string require:1 default:-- desc:手机号
  573. * @param name:second_password type:int require:1 default:-- desc:支付密码
  574. *
  575. */
  576. public function examples(){
  577. if(time() >= 1665320400 && $this->uid != 3 ){
  578. $this->error('系统升级中,暂停转赠。。。');
  579. }
  580. if (redisSetNx('examples'.$this->uid)){
  581. $id = input('id');
  582. $redis = new Redis([ 'select'=> 2]);
  583. $redis_value = $redis->get('examples'.$this->uid);
  584. if ($redis_value){
  585. $this->error('请求过快,请稍后重试');
  586. }else{
  587. $redis->set('examples'.$this->uid,1,2);
  588. }
  589. $phone = input('phone');
  590. // $wallet_address = input('wallet_address');
  591. $second_password = input('second_password');
  592. if (!$id || !$phone ) $this->error('参数错误');
  593. $info = Db::name('store_order_info')->where('id',$id)->where('mid',$this->uid)->find();
  594. if (!$info) $this->error('藏品不存在');
  595. if ($info['status']==2) $this->error('藏品已转赠');
  596. // if($info['c_id'] == 8) $this->error('持有时间限制,无法转赠');
  597. $member = Db::name('store_member')->where('phone',$phone)->find();
  598. if (!$member) $this->error('转赠用户不存在');
  599. if($member['id'] == $this->uid){
  600. $this->error('自己无法转赠给自己');
  601. }
  602. //防止两两转赠
  603. //if($info['to_mid'] == $member['id']) $this->error('不可相互转赠');
  604. if (!$info['collectors_hash'] && $info['type'] != 3) $this->error('发放中,无法转赠');
  605. $mem = getMemberInfoHash($this->uid);
  606. if ($mem['second_password']!=md5($second_password)) $this->error('密码错误');
  607. $pro_info = Db::name('store_collection')->where('id',$info['c_id'])->find();
  608. $log = Db::name('store_collect_examples_log')
  609. ->where('order_info_id',$id)
  610. ->find();
  611. if (!$log){
  612. if ($pro_info['one_given_day']!=0){
  613. $exam_time = strtotime($info['create_at'])+($pro_info['one_given_day']*60*60);
  614. if ($exam_time>time()) $this->error('持有时间限制,无法转赠');
  615. }
  616. }else{
  617. if ($pro_info['other_given_day']!=0){
  618. $exam_time = strtotime($log['create_at'])+($pro_info['other_given_day']*60*60);
  619. if ($exam_time>time()) $this->error('持有时间限制,无法转赠');
  620. }
  621. }
  622. $com = true;
  623. Db::startTrans();
  624. try {
  625. Db::name('store_order_info')
  626. ->where('id',$id)
  627. ->update(['status'=>2,'over_time'=>date('Y-m-d H:i:s'),'to_mid'=>$member['id'],'verify'=>Db::raw('verify - 1')]);
  628. $to_date = [
  629. 'order_id'=>$info['order_id'],
  630. 'order_no'=>get_order_sn(),
  631. 'tag'=>$info['tag'],
  632. 'mid'=>$member['id'],
  633. 'c_id'=>$info['c_id'],
  634. 'name'=>$pro_info['name'],
  635. 'cover'=>$pro_info['cover'],
  636. 'pro_info'=>$info['pro_info'],
  637. 'status'=>3,
  638. 'type' => $info['type'],
  639. 'to_mid'=>$this->uid,
  640. 'over_time'=>date('Y-m-d H:i:s'),
  641. 'company'=>'象链数藏',
  642. 'company_hash'=>$info['company_hash'],
  643. 'company_hash_time'=>$info['company_hash_time'],
  644. 'ddcid'=>$info['ddcid'],
  645. 'collectors_hash'=>'',
  646. 'collectors_hash_time'=>date('Y-m-d H:i:s')
  647. ];
  648. $new_id = Db::name('store_order_info')->insertGetId($to_date);
  649. $log_date = [
  650. 'order_info_id'=>$new_id,
  651. 'mid'=>$this->uid,
  652. 'to_mid'=>$member['id'],
  653. 'date'=>date('Y-m')
  654. ];
  655. Db::name('store_collect_examples_log')->insert($log_date);
  656. Db::commit();
  657. }catch (\Exception $e){
  658. $com = false;
  659. Db::rollback();
  660. }
  661. if ($com){
  662. if($pro_info['vipid'] > 0){
  663. //转赠成功等级掉级
  664. $otherData = [
  665. 'type' => 2,
  666. 'status' => 0,
  667. 'desc' => '转赠'.$pro_info['name'].'藏品自动掉级',
  668. 'order_table' => 'store_order_info',
  669. 'order_id' => $id,
  670. ];
  671. memberVipChange(0,$this->uid,$otherData);
  672. //转赠成功获赠人等级同步
  673. $otherData = [
  674. 'type' => 2,
  675. 'status' => 1,
  676. 'desc' => '获赠'.$pro_info['name'].'藏品自动同步等级',
  677. 'order_table' => 'store_order_info',
  678. 'order_id' => $new_id,
  679. ];
  680. memberVipChange($pro_info['vipid'],$member['id'],$otherData);
  681. }
  682. $this->success('转赠成功');
  683. }
  684. $this->error('转赠失败');
  685. }else{
  686. $this->error('服务器繁忙');
  687. }
  688. }
  689. /**
  690. * @title 消息列表[公告]
  691. * @desc 消息列表
  692. * @author Gavin
  693. * @method POST
  694. * @tag 编辑信息
  695. * @url /api/User_center/messageList
  696. * @header name:Authorization require:1 desc:Token
  697. *
  698. * @param name:page type:int : default:1 desc:页数
  699. * @param name:page_num type:int : default:20 desc:每页数
  700. *
  701. * @return name:id type:int require:0 default:0 desc:消息ID
  702. * @return name:title type:string require:0 default:0 desc:标题
  703. * @return name:content type:string require:0 default:0 desc:内容【富文本】
  704. * @return name:create_at type:string require:0 default:0 desc:发布时间
  705. * @return name:is_read type:string require:0 default:0 desc:是否查看true:已查看false:未查看
  706. */
  707. public function messageList(){
  708. $count = Db::name('store_message')->where('is_deleted',0)->count();
  709. $list = Db::name('store_message')
  710. ->field('is_deleted,update_at',true)
  711. ->where('is_deleted',0)
  712. ->order('id desc')
  713. ->limit($this->off_set,$this->page_num)
  714. ->select();
  715. // echo Db::name('store_message')->getLastSql();die;
  716. foreach ($list as &$v){
  717. $is_read = Db::name('store_message_read_log')->where('mid',$this->uid)->where('message_id',$v['id'])->count();
  718. $v['is_read'] = $is_read ? true : false;
  719. }
  720. $this->success('成功',compact('count','list'));
  721. }
  722. /**
  723. * @title 点击消息[公告]
  724. * @desc 点击消息,查看消息
  725. * @author Gavin
  726. * @method POST
  727. * @tag 编辑信息
  728. * @url /api/User_center/readMessage
  729. * @header name:Authorization require:1 desc:Token
  730. * @param name:id type:int : default:1 desc:消息ID
  731. * @return name:id type:int require:0 default:0 desc:消息ID
  732. * @return name:title type:string require:0 default:0 desc:标题
  733. * @return name:content type:string require:0 default:0 desc:内容【富文本】
  734. * @return name:create_at type:string require:0 default:0 desc:发布时间
  735. */
  736. public function readMessage(){
  737. $id = input('id');
  738. if (!$id) $this->error('参数错误');
  739. $log = Db::name('store_message_read_log')->where('message_id',$id)->where('mid',$this->uid)->count();
  740. $detail = Db::name('store_message')->field('is_deleted,update_at',true)->where('id',$id)->find();
  741. if (!$log){
  742. $data = [
  743. 'mid'=>$this->uid,
  744. 'message_id'=>$id
  745. ];
  746. Db::name('store_message_read_log')->insert($data);
  747. }
  748. $this->success('成功',['detail'=>$detail]);
  749. }
  750. /**
  751. * @title 人脸认证sign
  752. * @desc 人脸认证sign
  753. * @author Gavin
  754. * @method POST
  755. * @tag 编辑信息
  756. * @url /api/User_center/getFaceSign
  757. * @header name:Authorization require:1 desc:Token
  758. *
  759. *
  760. * @param name:name type:string default:1 desc:姓名
  761. * @param name:idNo type:string default:1 desc:身份证号
  762. *
  763. * @return name:sign type:string require: default:-- desc:签名
  764. *
  765. */
  766. public function getFaceSign(){
  767. $name = input('name');
  768. $idNo = input('idNo');
  769. if (!$name || !$idNo) $this->error('参数错误');
  770. $userId = $this->uid;
  771. //$userId = get32Str();
  772. $data = getfaceid($name,$idNo,$userId);
  773. $this->success('成功',$data);
  774. }
  775. /**
  776. * @title 邀请记录
  777. * @desc 邀请记录
  778. * @author Gavin
  779. * @method POST
  780. * @tag 编辑信息
  781. * @url /api/User_center/invitedRecord
  782. * @header name:Authorization require:1 desc:Token
  783. *
  784. * @param name:page type:int : default:1 desc:页数
  785. * @param name:page_num type:int : default:20 desc:每页数
  786. *
  787. * @return name:id type:int require:0 default:0 desc:用户ID
  788. * @return name:headimg type:string require:0 default:0 desc:头像
  789. * @return name:name type:string require:0 default:0 desc:名称
  790. * @return name:phone type:string require:0 default:0 desc:手机号
  791. * @return name:create_at type:string require:0 default:0 desc:时间
  792. * @return name:is_auth type:int require:0 default:0 desc:是否认证
  793. */
  794. public function invitedRecord(){
  795. $count = Db::name('store_member')->where('pid',$this->uid)->where('is_auth',1)->count();
  796. $list = Db::name('store_member')
  797. ->field('id,headimg,name,phone,create_at,is_auth')
  798. ->where('pid',$this->uid)
  799. ->where('is_auth',1)
  800. ->order('id desc')
  801. ->limit($this->off_set,$this->page_num)
  802. ->select();
  803. foreach ($list as &$v){
  804. $v['phone'] = substr_replace($v['phone'],'****',3,4);
  805. $v['create_at'] = date('Y-m-d',strtotime($v['create_at']));
  806. }
  807. $this->success('成功',compact('count','list'));
  808. }
  809. /**
  810. * @title 邀请排行榜
  811. * @desc 邀请排行榜
  812. * @author Gavin
  813. * @method POST
  814. * @tag 编辑信息
  815. * @url /api/User_center/invitedList
  816. * @header name:Authorization require:1 desc:Token
  817. *
  818. * @param name:page type:int : default:1 desc:页数
  819. * @param name:page_num type:int : default:20 desc:每页数
  820. *
  821. * @return name:count type:int require:0 default:0 desc:人数
  822. * @return name:id type:int require:0 default:0 desc:用户ID
  823. * @return name:headimg type:string require:0 default:0 desc:头像
  824. * @return name:name type:string require:0 default:0 desc:名称
  825. * @return name:phone type:string require:0 default:0 desc:手机号
  826. * @return name:is_auth type:int require:0 default:0 desc:是否认证
  827. * @return name:create_at type:string require:0 default:0 desc:时间
  828. */
  829. public function invitedList(){
  830. //$this->error('新品发售中,暂时停止访问');
  831. $count = Db::name('store_member')->field('pid,count(*) count')->where('pid','>',0)->where('is_auth',1)->group('pid')->order('count desc')->count();
  832. $list = Db::name('store_member')
  833. ->field('pid,count(*) count')
  834. ->where('pid','>',0)
  835. ->where('is_auth',1)
  836. ->where('bank_num is not null')
  837. ->group('pid')
  838. ->order('count desc')
  839. ->limit($this->off_set,$this->page_num)
  840. ->select();
  841. foreach ($list as &$value){
  842. $users_info = Db::name('store_member')->field('headimg,name,is_auth')->where('id',$value['pid'])->find();
  843. $value['name'] = $users_info['name'];
  844. $value['headimg'] = $users_info['headimg'];
  845. $value['is_auth'] = $users_info['is_auth'];
  846. unset($value['pid']);
  847. }
  848. $this->success('成功',compact('count','list'));
  849. }
  850. /**
  851. * @title 签到
  852. * @desc 签到
  853. * @author Gavin
  854. * @method POST
  855. * @tag 编辑信息
  856. * @url /api/User_center/sign
  857. * @header name:Authorization require:1 desc:Token
  858. *
  859. */
  860. public function sign(){
  861. $date = date('Y-m-d');
  862. $log = Db::name('store_member_sign')->where('mid',$this->uid)->where('date',$date)->count();
  863. if ($log) $this->error('今日已签到');
  864. $data = [
  865. 'mid'=>$this->uid,
  866. 'date'=>$date
  867. ];
  868. $com = true;
  869. Db::startTrans();
  870. try {
  871. $id = Db::name('store_member_sign')->insertGetId($data);
  872. $sign_integral = getConfigValue('sign_integral');
  873. if ($sign_integral>0){
  874. memberMoneyChange($sign_integral,1,$this->uid,'签到',1,$id);
  875. }
  876. Db::commit();
  877. }catch (\Exception $e){
  878. $com=false;
  879. Db::rollback();
  880. }
  881. if ($com){
  882. $this->success('签到成功');
  883. }
  884. $this->error('签到失败');
  885. }
  886. /**
  887. * @title 积分记录
  888. * @desc 积分记录
  889. * @author Gavin
  890. * @method POST
  891. * @tag 编辑信息
  892. * @url /api/User_center/integralLog
  893. * @header name:Authorization require:1 desc:Token
  894. *
  895. * @param name:page type:int : default:1 desc:页数
  896. * @param name:page_num type:int : default:20 desc:每页数
  897. *
  898. * @return name:id type:int require:0 default:0 desc:id
  899. * @return name:change type:string require:0 default:0 desc:变动数值
  900. * @return name:title type:string require:0 default:0 desc:标题
  901. * @return name:create_at type:string require:0 default:0 desc:时间
  902. */
  903. public function integralLog(){
  904. $where = [
  905. 'm_id'=>$this->uid,
  906. 'type'=>1
  907. ];
  908. $count = Db::name('store_member_log')->where($where)->count();
  909. $list = Db::name('store_member_log')
  910. ->field('id,pm,change,title,create_at')
  911. ->where($where)
  912. ->order('id desc')
  913. ->limit($this->off_set,$this->page_num)
  914. ->select();
  915. foreach ($list as &$v){
  916. if ($v['pm']==1){
  917. $v['change'] = '+'.$v['change'];
  918. }else{
  919. $v['change'] = '-'.$v['change'];
  920. }
  921. }
  922. $this->success('成功',compact('count','list'));
  923. }
  924. /**
  925. * @title 余额记录
  926. * @desc 余额记录
  927. * @author Gavin
  928. * @method POST
  929. * @tag 编辑信息
  930. * @url /api/User_center/moneyLog
  931. * @header name:Authorization require:1 desc:Token
  932. *
  933. * @param name:page type:int default:1 desc:页数
  934. * @param name:page_num type:int default:20 desc:每页数
  935. * @param name:select_type type:int require:0 default:-1 desc:查询类型[-1全部0减少(支出)1增加(收入),2提现【包含提现申请的减少和拒绝的增加】]
  936. *
  937. * @return name:id type:int require:0 default:0 desc:id
  938. * @return name:change type:string require:0 default:0 desc:变动数值
  939. * @return name:title type:string require:0 default:0 desc:标题
  940. * @return name:create_at type:string require:0 default:0 desc:时间
  941. * @return name:pm type:int require:0 default:0 desc:变更类型[0减少1增加]
  942. * @return name:change_type type:int require:0 default:0 desc:来源1出售佣金2提现3提现拒绝
  943. */
  944. public function moneyLog(){
  945. $select_type = input('select_type',-1);
  946. $where = ['m_id'=>$this->uid, 'type'=>3];
  947. if(in_array($select_type,[0,1]))$where['pm'] = $select_type;
  948. $count = Db::name('store_member_log')->where($where)->when($select_type,function ($query)use($select_type){
  949. if($select_type == 2 ) $query->whereIn('change_type','2,3');
  950. })->count();
  951. $list = Db::name('store_member_log')
  952. ->field('id,pm,change,title,create_at,change_type')
  953. ->where($where)
  954. ->when($select_type,function ($query)use($select_type){
  955. if($select_type == 2 ) $query->whereIn('change_type','2,3');
  956. })->order('id desc')
  957. ->limit($this->off_set,$this->page_num)
  958. ->select();
  959. foreach ($list as &$v){
  960. if ($v['pm']==1){
  961. $v['change'] = '+'.$v['change'];
  962. }else{
  963. $v['change'] = '-'.$v['change'];
  964. }
  965. }
  966. $this->success('成功',compact('count','list'));
  967. }
  968. /**
  969. * @title 系统余额提现
  970. * @desc 提现
  971. * @author Gavin
  972. * @method POST
  973. * @tag 编辑信息
  974. * @url /api/User_center/withdraw
  975. * @header name:Authorization require:1 desc:Token
  976. *
  977. * @param name:money type:int default: desc:提现金额
  978. * @param name:withdraw_type type:string default:bank desc:提现方式:wx[微信],zfb[支付宝],bank[银行卡]
  979. * @param name:pay_password type:string default:wx desc:二级密码
  980. *
  981. */
  982. public function withdraw(){
  983. if(!checkAuth($this->uid)) $this->error('维护中.....');
  984. if (redisSetNx('withdraw'.$this->uid,3)){
  985. $v = getConfigValue('withdraw_switch');
  986. if (!$v) $this->error('维护中,暂时关闭');
  987. $redis = new Redis(['select'=>2]);
  988. $redis_value = $redis->get('withdraw'.$this->uid);
  989. if ($redis_value){
  990. $this->error('请求过快,请稍后重试');
  991. }else{
  992. $redis->set('withdraw'.$this->uid,1,3);
  993. }
  994. $money = input('money');
  995. $withdraw_type = input('withdraw_type','bank');
  996. if($withdraw_type != 'bank') $this->error('提现方式错误'.$withdraw_type);
  997. $pay_password = input('pay_password');
  998. if (!$money) $this->error('参数错误');
  999. $user = Db::name('store_member')->where('id',$this->uid)->find();
  1000. if ($user['money'] < $money) $this->error('余额不足');
  1001. //if ($user['second_password']!=md5($pay_password)) $this->error('密码错误');
  1002. $withdraw_min_price = getConfigValue('withdraw_min_price'); //最小提现金额
  1003. $withdraw_max_price = getConfigValue('withdraw_max_price'); //最大提现金额
  1004. $poundage_proportion = getConfigValue('poundage_proportion'); //手续费百分比
  1005. $discount = getMemberServiceCharge($this->uid);// 折扣
  1006. $poundage_proportion = bcmul($poundage_proportion,$discount);
  1007. if ($money < $withdraw_min_price) $this->error('最低提现'.$withdraw_min_price.'元');
  1008. if ($money > $withdraw_max_price) $this->error('最大提现'.$withdraw_max_price.'元');
  1009. if($withdraw_type=='zfb' && (!$user['zfb_account'] || !$user['zfb_real_name'])) $this->error('请先绑定支付宝');
  1010. if($withdraw_type == 'wx' && !$user['openid']) $this->error('请先绑定微信');
  1011. if($withdraw_type == 'bank' && !$user['bank_num'])$this->error('请先绑定银行卡');
  1012. Db::startTrans();
  1013. try {
  1014. $data['mid'] = $this->uid;
  1015. $data['withdraw_type'] = $withdraw_type;
  1016. $order_no = get_order_sn();
  1017. $data['order_no'] = $order_no;
  1018. $data['price'] = $money;
  1019. $data['poundage_proportion'] = $poundage_proportion;
  1020. $proportion = sprintf("%.2f", $money*($poundage_proportion/100)); //四舍五入保留两位小数点
  1021. $data['proportion'] = $proportion;
  1022. $real_money = $money-$proportion;
  1023. $data['real_money'] = $real_money;
  1024. switch ($withdraw_type){
  1025. case 'wx':
  1026. $data['account_no'] = $user['openid'];
  1027. $data['account_name']=$user['name'];
  1028. break;
  1029. case 'zfb':
  1030. $data['account_no'] = $user['zfb_account'];
  1031. $data['account_name']=$user['zfb_real_name'];
  1032. break;
  1033. case 'bank':
  1034. $data['account_no'] = $user['bank_num'];
  1035. $data['account_name']=$user['bank_user'];
  1036. break;
  1037. }
  1038. $id =Db::name('store_member_withdraw')->insertGetId($data);
  1039. $res = memberMoneyChange($money,3,$this->uid,'余额提现',0,$id,2);
  1040. if(!$res) throw new Exception('提现失败');
  1041. Db::commit();
  1042. }catch (\Exception $e) {
  1043. Db::rollback();
  1044. $this->error($e->getMessage());
  1045. }
  1046. DelRedisSetNx('withdraw'.$this->uid);
  1047. $this->success('提现申请成功,等待审核!');
  1048. }else{
  1049. $this->error('服务器繁忙,请稍后重试');
  1050. }
  1051. }
  1052. /**
  1053. * @title 云钱包余额提现
  1054. * @desc 提现
  1055. * @author Gavin
  1056. * @method POST
  1057. * @tag 编辑信息
  1058. * @url /api/User_center/cloudWalletWithdraw
  1059. * @header name:Authorization require:1 desc:Token
  1060. * @param name:money type:int default: desc:提现金额
  1061. * @param name:cloud_password type:string default:-- desc:云钱包密码
  1062. * @param name:source type:int require:0 default:10 desc:app传10,h5传16
  1063. * @param name:random_key type:string require:0 default:10 desc:random_key
  1064. * @return name:ret_code type:string default:0 desc:请求结果代码[0000:提现申请成功,8889:表示提现申请待确认成功,需要调用提现确认完成提现创单申请,8888:表示提现需要再次信息短信验证码校验]
  1065. * @return name:token type:string default:0 desc:支付授权令牌,有效期30分钟。当交易需要二次验证的时候,需要通过token调用调用交易二次短信验证接口[/api/Cloud_wallet/validationSms]
  1066. * @return name:txn_seqno type:string default:0 desc:商户系统唯一交易流水号,当交易需要二次验证的时候,需要传这个参数[/api/Cloud_wallet/validationSms]
  1067. * @return name:total_amount type:float default:0 desc:订单总金额,当交易需要二次验证的时候,需要传这个参数[/api/Cloud_wallet/validationSms]
  1068. *
  1069. */
  1070. public function cloudWalletWithdraw()
  1071. {
  1072. if(!checkAuth($this->uid)) $this->error('维护中.....');
  1073. if (redisSetNx('cloudWalletWithdraw'.$this->uid,3)){
  1074. $v = getConfigValue('withdraw_switch');
  1075. if (!$v) $this->error('维护中,暂时关闭');
  1076. $redis = new Redis(['select'=>2]);
  1077. $redis_value = $redis->get('cloudWalletWithdraw'.$this->uid);
  1078. if ($redis_value){
  1079. $this->error('请求过快,请稍后重试');
  1080. }else{
  1081. $redis->set('cloudWalletWithdraw'.$this->uid,1,3);
  1082. }
  1083. $money = input('money');
  1084. $withdraw_type = input('withdraw_type','bank');
  1085. if($withdraw_type != 'bank') $this->error('提现方式错误'.$withdraw_type);
  1086. $cloud_password = input('cloud_password');
  1087. $source = input('source');
  1088. $random_key = input('random_key');
  1089. if (!$money) $this->error('参数错误');
  1090. $user = Db::name('store_member')->where('id',$this->uid)->find();
  1091. $withdraw_min_price = getConfigValue('withdraw_min_price'); //最小提现金额
  1092. $withdraw_max_price = getConfigValue('withdraw_max_price'); //最大提现金额
  1093. $poundage_proportion = getConfigValue('poundage_proportion'); //手续费百分比
  1094. $discount = getMemberServiceCharge($this->uid);// 折扣
  1095. $poundage_proportion = bcmul($poundage_proportion,$discount);
  1096. if ($money < $withdraw_min_price) $this->error('最低提现'.$withdraw_min_price.'元');
  1097. if ($money > $withdraw_max_price) $this->error('最大提现'.$withdraw_max_price.'元');
  1098. if($withdraw_type == 'bank' && !$user['bank_num'])$this->error('请先绑定银行卡');
  1099. Db::startTrans();
  1100. try {
  1101. $data['mid'] = $this->uid;
  1102. $data['withdraw_type'] = $withdraw_type;
  1103. $order_no = get_order_sn();
  1104. $data['order_no'] = $order_no;
  1105. $data['price'] = $money;
  1106. $data['poundage_proportion'] = $poundage_proportion;
  1107. $proportion = sprintf("%.2f", $money*($poundage_proportion/100)); //四舍五入保留两位小数点
  1108. $data['proportion'] = $proportion;
  1109. $real_money = $money-$proportion;
  1110. $data['real_money'] = $real_money;
  1111. switch ($withdraw_type){
  1112. case 'bank':
  1113. $data['account_no'] = $user['bank_num'];
  1114. $data['account_name']=$user['bank_user'];
  1115. break;
  1116. }
  1117. Db::name('cloud_wallet_withdraw')->insertGetId($data);
  1118. $risk_item = risk_item($user,'云钱包提现',$source);
  1119. $cloud_res = LianLianPay::cloudWalletWithdrawal($this->uid,$money,$proportion,$user['bank_num'],$cloud_password,$risk_item,$random_key);
  1120. if(!in_array($cloud_res['ret_code'],['0000','8888','8889']) )throw new Exception($cloud_res['ret_msg']);
  1121. Db::commit();
  1122. }catch (\Exception $e) {
  1123. Db::rollback();
  1124. $this->error($e->getMessage());
  1125. }
  1126. DelRedisSetNx('cloudWalletWithdraw'.$this->uid);
  1127. $this->success('提现申请成功,等待审核!',$cloud_res);
  1128. }else{
  1129. $this->error('服务器繁忙,请稍后重试');
  1130. }
  1131. }
  1132. /**
  1133. * @title 打开盲盒
  1134. * @desc 返回值是空就没中奖
  1135. * @author Gavin
  1136. * @method POST
  1137. * @tag 编辑信息
  1138. * @url /api/User_center/openBoxCollection
  1139. * @header name:Authorization require:1 desc:Token
  1140. * @param name:id type:int : default: desc:详情ID
  1141. * @return name:name type:string default: desc:名称
  1142. * @return name:cover type:string default: desc:图片
  1143. * @return name:price type:string default: desc:价格
  1144. * @return name:auth_name type:string default: desc:作者
  1145. * @return name:auth_img type:string default: desc:作者头像
  1146. *
  1147. */
  1148. public function openBoxCollection(){
  1149. //redis原子锁
  1150. if (redisSetNx('openBox'.$this->uid)){
  1151. $id = input('id');
  1152. if (!$id) $this->error('参数错误');
  1153. $info = Db::name('store_order_info')
  1154. ->where('id',$id)
  1155. ->where('mid',$this->uid)
  1156. ->where('status','neq','2')
  1157. ->where('is_destruction',1)
  1158. ->find();
  1159. if (!$info) $this->error('盲盒不存在');
  1160. if ($info['resale_status']!=1) $this->error('盲盒挂售中或已出售');
  1161. $where = 'status = 1 and coll_id = '.$info['c_id'].' and is_del = 1 and residue_num > 0';
  1162. $residue_num_all = Db::name('store_blind_box')->where($where)->sum('residue_num');
  1163. // if($residue_num_all <= 0 )$this->error('对不起,盲盒已没有奖品');
  1164. $com = true;
  1165. Db::startTrans();
  1166. try {
  1167. //销毁
  1168. Db::name('store_order_info')->where('id',$id)->update(['is_destruction'=>0]);
  1169. $win_num = rand(1,$residue_num_all);
  1170. $blind_box_info = Db::name('store_blind_box')->field('id,prize_id,residue_num')->where($where)->select();
  1171. $residue_num = 0;
  1172. $win_prize_id = 0;
  1173. $win_box_id = 0;
  1174. foreach ($blind_box_info as $val) {
  1175. $residue_num += $val['residue_num'];
  1176. if($win_prize_id == 0 && $win_num <= $residue_num){
  1177. $win_prize_id = $val['prize_id'];
  1178. $win_box_id = $val['id'];
  1179. }
  1180. }
  1181. if($win_prize_id){
  1182. $coll_info = getCollectionInfoHash($win_prize_id);
  1183. $json_info = json_encode($coll_info,true);
  1184. $return['name'] = $coll_info['name'];
  1185. $return['cover'] = $coll_info['cover'];
  1186. $return['price'] = $coll_info['price'];
  1187. $return['auth_name'] = $coll_info['auth_name'];
  1188. $return['auth_img'] = $coll_info['auth_img'];
  1189. $data = [
  1190. 'm_id'=>$this->uid,
  1191. 'b_id'=>$win_prize_id,
  1192. 'is_prize'=>1,
  1193. 'name'=>$coll_info['name'],
  1194. 'cover'=>$coll_info['cover'],
  1195. 'info'=>$json_info,
  1196. 'date'=>date('Y-m-d'),
  1197. 'is_free'=>1
  1198. ];
  1199. Db::name('store_blind_box_log')->insert($data);
  1200. //获取排名
  1201. $rank = getRanking($win_prize_id);
  1202. $tag = getTag($win_prize_id,$rank,$coll_info['inventory']);
  1203. saveRanking($win_prize_id);
  1204. $company = '象链数藏';
  1205. $hash = getCompanyHash($win_prize_id);
  1206. $company_hash = $hash['hash'];
  1207. $company_hash_time = $hash['create_at'];
  1208. $tokenid = $hash['tokenid'];
  1209. Db::name('hash')->where('hash',$hash['hash'])->update(['status'=>1]);
  1210. $collectors_hash = '';
  1211. $date = [
  1212. 'order_id'=>0,
  1213. 'order_no'=>get_order_sn(),
  1214. 'tag'=>$tag,
  1215. 'mid'=>$this->uid,
  1216. 'c_id'=>$win_prize_id,
  1217. 'name'=>$coll_info['name'],
  1218. 'cover'=>$coll_info['cover'],
  1219. 'pro_info'=>$json_info,
  1220. 'company'=>$company,
  1221. 'company_hash'=>$company_hash,
  1222. 'company_hash_time'=>$company_hash_time,
  1223. 'ddcid'=>$tokenid,
  1224. 'collectors_hash'=>$collectors_hash,
  1225. // 'collectors_hash_time'=>'',
  1226. 'status'=>1
  1227. ];
  1228. Db::name('store_order_info')->insert($date);
  1229. }
  1230. Db::commit();
  1231. }catch (\Exception $e) {
  1232. $com = false;
  1233. $msg = $e->getMessage();
  1234. Db::rollback();
  1235. }
  1236. if ($com){
  1237. setMemberInfoHash($this->uid);
  1238. //扣减库存
  1239. Db::name('store_blind_box')->where('id',$win_box_id)->setDec('residue_num',1);
  1240. DelRedisSetNx('openBox'.$this->uid);
  1241. $this->success('成功',$win_prize_id ? $return : null);
  1242. }else{
  1243. DelRedisSetNx('openBox'.$this->uid);
  1244. $this->error($msg);
  1245. }
  1246. }else{
  1247. $this->error('请求过快');
  1248. }
  1249. }
  1250. /**
  1251. * @title 验证被更换手机号【更换手机号第一步】
  1252. * @desc 验证已绑定的手机号
  1253. * @author QC
  1254. * @method POST
  1255. * @tag 编辑信息
  1256. * @url /api/User_center/checkPhone
  1257. * @header name:Authorization require:1 desc:Token
  1258. * @param name:phone type:int default: desc:手机号
  1259. * @param name:code type:string default: desc:验证码
  1260. */
  1261. public function checkPhone()
  1262. {
  1263. $phone = input('post.phone');
  1264. $code = input('post.code');
  1265. if(!$phone || !$code) $this->error('参数错误');
  1266. $user_info = Db::name('store_member')->find($this->uid);
  1267. if($user_info['phone'] != $phone) $this->error('已绑定手机号错误');
  1268. // 5 分钟之内的验证码
  1269. $check_code = Db::name('store_sms')
  1270. ->where(['mobile'=>$phone,'event'=>'change','is_use'=>0,'code'=>$code])
  1271. ->where('createtime','>' ,time() - 300)
  1272. ->value('id');
  1273. if(!$check_code) $this->error('验证码错误');
  1274. Db::name('store_sms')->where('id',$check_code)->update(['is_use'=>1]);
  1275. $this->success('验证成功');
  1276. }
  1277. /**
  1278. * @title 更换新的手机号
  1279. * @desc 更换新的手机号
  1280. * @author QC
  1281. * @method POST
  1282. * @tag 更换新的手机号
  1283. * @url /api/User_center/changePhone
  1284. * @header name:Authorization require:1 desc:Token
  1285. * @param name:phone type:int default: desc:手机号
  1286. * @param name:code type:string default: desc:验证码
  1287. */
  1288. public function changePhone()
  1289. {
  1290. $phone = input('post.phone');
  1291. $code = input('post.code');
  1292. if(!$phone || !$code) $this->error('参数错误');
  1293. $user_info = Db::name('store_member')->find($this->uid);
  1294. $check_code = Db::name('store_sms')
  1295. ->where(['mobile'=>$user_info['phone'],'event'=>'change','is_use'=>1])
  1296. ->order('id desc')
  1297. ->find();
  1298. if(!$check_code) $this->error('请验证已绑定手机号');
  1299. if($check_code['createtime'] < time() - 300) $this->error('验证超时,请在5分钟之内更换手机号');
  1300. $check_new = Db::name('store_sms')
  1301. ->where(['mobile'=>$phone,'event'=>'new','is_use'=>0,'code'=>$code])
  1302. ->where('createtime','>' ,time() - 300)
  1303. ->value('id');
  1304. if(!$check_new) $this->error('验证码错误');
  1305. Db::name('store_sms')->where('id',$check_new)->update(['is_use'=>1]);
  1306. Db::name('store_member')->where('id',$this->uid)->update(['phone'=>$phone]);
  1307. setMemberInfoHash($this->uid);
  1308. $this->success('更换成功');
  1309. }
  1310. /**
  1311. * @title 阿里云金融级实名认证初始化
  1312. * @desc 阿里云金融级实名认证初始化
  1313. * @author QC
  1314. * @method POST
  1315. * @tag 编辑信息
  1316. * @url /api/User_center/initFaceVerify
  1317. * @header name:Authorization require:1 desc:Token
  1318. * @param name:name type:string default:1 desc:姓名
  1319. * @param name:id_no type:string default:1 desc:身份证号
  1320. * @param name:MetaInfo type:string default:1 desc:MetaInfo
  1321. * @param name:ReturnUrl type:string default:1 desc:业务页面回跳的目标地址
  1322. * @return name:RequestId type:String default:-- desc:请求ID
  1323. * @return name:Message type:String default:-- desc:返回信息
  1324. * @return name:Code type:String default:-- desc:返返回码:200为成功,其他为失败。【具体的参考阿里云文档】
  1325. * @return name:ResultObject.CertifyId type:String default:-- desc:实人认证唯一标识
  1326. * @return name:ResultObject.CertifyUrl type:String default:-- desc:Web认证URL,认证结束后根据入参ReturnUrl进行进行转赠跳转
  1327. */
  1328. function initFaceVerify(){
  1329. $name = input('name');
  1330. $id_no = input('id_no');
  1331. $MetaInfo = input('MetaInfo');
  1332. $ReturnUrl = input('ReturnUrl');
  1333. $res = Certification::main($name,$id_no,$MetaInfo,$ReturnUrl);
  1334. if(!$res) $this->error('初始化错误');
  1335. $result = json_decode(json_encode($res),true)['body'];
  1336. $result['code'] != 200 ? $this->error($result['message']):$this->success('ok',$result);
  1337. }
  1338. /**
  1339. * @title 保存人脸认证
  1340. * @desc 保存人脸认证
  1341. * @author QC
  1342. * @method POST
  1343. * @tag 编辑信息
  1344. * @url /api/User_center/saveVerify
  1345. * @header name:Authorization require:1 desc:Token
  1346. * @param name:name type:string default:1 desc:姓名
  1347. * @param name:id_no type:string default:1 desc:身份证号
  1348. * @param name:CertifyId type:string default:1 desc:实人认证唯一标识
  1349. */
  1350. function saveVerify()
  1351. {
  1352. $name = input('name');
  1353. $id_no = input('id_no');
  1354. $CertifyId = input('CertifyId');
  1355. if (!$name || !$id_no || !$CertifyId) $this->error('参数错误');
  1356. $check_id_card = isCreditNo($id_no);
  1357. if (!$check_id_card) $this->error('身份证号格式错误');
  1358. $is_auth = Db::table('store_member')->where('id',$this->uid)->value('is_auth');
  1359. if($is_auth) $this->error('已认证');
  1360. $check = Db::name('store_member')->where('id_card',$id_no)->count();
  1361. if ($check) $this->error('身份证号已经认证过');
  1362. // 核验
  1363. $res = Certification::check($CertifyId);
  1364. if(!$res) $this->error('认证失败');
  1365. $result = json_decode(json_encode($res),true)['body'];
  1366. if($result['code'] != 200) $this->error($result['message']);
  1367. Db::table('store_member')->where('id',$this->uid)->update(['is_auth'=>1,'true_name'=>$name,'id_card'=>$id_no,'auth_at'=>date('Y-m-d H:i:s')]);
  1368. setMemberInfoHash($this->uid);
  1369. $this->success('认证成功');
  1370. }
  1371. }