UserCenter.php 60 KB

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