Unlockorder.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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)->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)->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,
  90. ];
  91. //年费vip干预
  92. $wallet = model('wallet')->getwallet($this->auth->id);
  93. if($wallet['vip_endtime'] > time() && $wallet['vip_level'] == 30){
  94. $data['price'] = 0;
  95. $data['type'] = 2;
  96. $data['endtime'] = time(); //立即过期,就看一下
  97. $price = 0;
  98. }
  99. //log
  100. Db::startTrans();
  101. $order_id = Db::name('order_secretvideo')->insertGetId($data);
  102. if(!$order_id){
  103. Db::rollback();
  104. $this->error('解锁失败');
  105. }
  106. if($price > 0){
  107. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',$price,72,'解锁:'.$to_user_info['username'],'order_secretvideo',$order_id);
  108. if($wallet_rs['status'] === false){
  109. Db::rollback();
  110. $this->error($wallet_rs['msg']);
  111. }
  112. }
  113. Db::commit();
  114. $this->success('解锁成功');
  115. }
  116. }