Unlockorder.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 解锁微信号和私密视频
  7. */
  8. class Unlockorder extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //解锁微信订单
  13. public function wechataccount(){
  14. //检查用户
  15. $to_user_id = input('to_user_id','');
  16. if(empty($to_user_id)){
  17. $this->error();
  18. }
  19. $to_user_info = Db::name('user')->find($to_user_id);
  20. if(empty($to_user_info)){
  21. $this->error('不存在的用户');
  22. }
  23. //检查防重复解锁
  24. $check_map = [
  25. 'user_id' => $this->auth->id,
  26. 'to_user_id' => $to_user_id,
  27. 'endtime' => ['gt',time()],
  28. ];
  29. $check_repeat = Db::name('order_wechataccount')->where($check_map)->order('id desc')->find();
  30. if(!empty($check_repeat)){
  31. $this->error('尚未过期无需再次解锁');
  32. }
  33. //订单
  34. $price = config('site.unlock_wechataccount');
  35. $price = bcadd(intval($price),0,0);
  36. $data = [
  37. 'user_id' => $this->auth->id,
  38. 'to_user_id' => $to_user_id,
  39. 'createtime' => time(),
  40. 'endtime' => time() + 604800,
  41. 'price' => $price,
  42. ];
  43. Db::startTrans();
  44. $order_id = Db::name('order_wechataccount')->insertGetId($data);
  45. if(!$order_id){
  46. Db::rollback();
  47. $this->error('解锁失败');
  48. }
  49. if($price > 0){
  50. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',$price,71,'解锁:'.$to_user_info['username'],'order_wechataccount',$order_id);
  51. if($wallet_rs['status'] === false){
  52. Db::rollback();
  53. $this->error($wallet_rs['msg']);
  54. }
  55. }
  56. Db::commit();
  57. $this->success('解锁成功');
  58. }
  59. //解锁私密视频订单
  60. public function secretvideo(){
  61. //检查用户
  62. $to_user_id = input('to_user_id','');
  63. if(empty($to_user_id)){
  64. $this->error();
  65. }
  66. $to_user_info = Db::name('user')->find($to_user_id);
  67. if(empty($to_user_info)){
  68. $this->error('不存在的用户');
  69. }
  70. //检查防重复解锁
  71. $check_map = [
  72. 'user_id' => $this->auth->id,
  73. 'to_user_id' => $to_user_id,
  74. 'endtime' => ['gt',time()],
  75. ];
  76. $check_repeat = Db::name('order_secretvideo')->where($check_map)->order('id desc')->find();
  77. if(!empty($check_repeat)){
  78. $this->error('尚未过期无需再次解锁');
  79. }
  80. //订单
  81. $price = config('site.unlock_secretvideo');
  82. $price = bcadd(intval($price),0,0);
  83. $data = [
  84. 'user_id' => $this->auth->id,
  85. 'to_user_id' => $to_user_id,
  86. 'createtime' => time(),
  87. 'endtime' => time() + 604800,
  88. 'price' => $price,
  89. 'type' => 1, //1 金币付费
  90. ];
  91. //年费vip干预,一天只一次
  92. $today_start = strtotime(date('y-m-d'));
  93. $today_end = $today_start + 86399;
  94. $check_free_map = [
  95. 'user_id' => $this->auth->id,
  96. 'to_user_id' => $to_user_id,
  97. 'createtime' => ['between',[$today_start,$today_end]],
  98. 'type' => 2,
  99. ];
  100. $check_free = Db::name('order_secretvideo')->where($check_free_map)->count('id');
  101. //年费vip,且今天没使用过权限,优先使用vip权限
  102. $wallet = model('wallet')->getwallet($this->auth->id);
  103. if($wallet['vip_endtime'] > time() && $wallet['vip_level'] == 30 && $check_free == 0 ){
  104. $data['price'] = 0;
  105. $data['type'] = 2; //2 年vip免费
  106. $data['endtime'] = time(); //立即过期,就看一下
  107. $price = 0;
  108. }
  109. //log
  110. Db::startTrans();
  111. $order_id = Db::name('order_secretvideo')->insertGetId($data);
  112. if(!$order_id){
  113. Db::rollback();
  114. $this->error('解锁失败');
  115. }
  116. if($price > 0){
  117. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',$price,72,'解锁:'.$to_user_info['username'],'order_secretvideo',$order_id);
  118. if($wallet_rs['status'] === false){
  119. Db::rollback();
  120. $this->error($wallet_rs['msg']);
  121. }
  122. }
  123. Db::commit();
  124. $this->success('解锁成功');
  125. }
  126. }