UserCenter.php 47 KB

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