Platform.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace app\api\controller;
  3. use think\Db;
  4. use fast\Tree;
  5. use app\common\controller\Api;
  6. /**
  7. * 股份 收益 分红
  8. */
  9. class Platform extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. public function index()
  14. {
  15. $config=$this->config();
  16. $configs=config('site');
  17. $map=[];
  18. // $map['ishot']=2;
  19. // $map['endtimesjc']=['>',time()];
  20. // if(input('uid',0)>0){
  21. // $map['uid']=input('uid');
  22. // }
  23. $list = model('Platform')
  24. // ->with('user')
  25. // ->where($map)
  26. ->limit(10)
  27. ->select();
  28. $data=['config'=>$config,'doctor'=>$list];
  29. $this->success('请求成功',$data);
  30. }
  31. public function test(){
  32. $this->success('请求成功');
  33. }
  34. public function user_share_order(){
  35. $map = []; // 初始化$map数组,避免未定义时的错误
  36. if(input('uid', 0) > 0){
  37. // 明确指定uid所属的表(假设主表为video_share)
  38. $map['video_share.uid'] = input('uid');
  39. $count = $this->user_share_count($map['video_share.uid']);
  40. }
  41. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  42. $config = $this->config();
  43. $list = model('VideoShare')
  44. ->with('videolist,user')
  45. ->where($map)
  46. ->limit($offset, $limit)
  47. ->select();
  48. $total = model('VideoShare')
  49. ->with('users')
  50. ->where($map)
  51. ->count();
  52. // var_dump(model('VideoShare')->getLastSql());die();
  53. $data = ['config' => $config, 'doctor' => $list,'total'=>$total,'count' => $count];
  54. $this->success('请求成功', $data);
  55. }
  56. public function user_share_count($uid){ // 统计用户各个短剧的版权数量
  57. $map = []; // 初始化$map数组,避免未定义时的错误
  58. $map['uid'] = $uid;
  59. $timestamp = strtotime("-3 years");
  60. $count = model('VideoShare')
  61. ->where($map)
  62. ->where('createtime','>',$timestamp)
  63. ->group('vid')
  64. ->field('vid,sum(num) as count')
  65. ->select();
  66. return $count;
  67. }
  68. // 查看各平台的收益情况
  69. public function platform_income(){
  70. $map = []; // 初始化查询条件数组
  71. // 修正条件:使用正确的输入参数名 platform_id
  72. if(input('platform_id', 0) > 0){
  73. $map['video_platform_record.platform_id'] = input('platform_id', 0);
  74. }
  75. // vid 条件正确,无需修改
  76. if(input('vid', 0) > 0){
  77. $map['video_platform_record.vid'] = input('vid', 0);
  78. }
  79. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  80. $config = $this->config();
  81. $list = model('VideoPlatformRecord')
  82. ->with('platform,videolist')
  83. ->where($map)
  84. ->limit($offset, $limit)
  85. ->select();
  86. $total = model('VideoPlatformRecord')
  87. ->with('platform,videolist')
  88. ->where($map)
  89. ->count();
  90. $data = ['config' => $config, 'doctor' => $list, 'total' => $total];
  91. $this->success('请求成功', $data);
  92. }
  93. // 每日分配各个短剧在不同平台的收益
  94. public function platform_income_day(){
  95. // 先获取所有短剧在不同平台的收益上下限
  96. $list = model('VideoPlatform')->select();
  97. if($list) {
  98. foreach ($list as $k => $v) {
  99. $randomNumber = mt_rand($v['min'] * 100, $v['max'] * 100) / 100;
  100. $up = [
  101. 'vid' => $v['vid'],
  102. 'platform_id' => $v['platform_id'],
  103. 'num' => $randomNumber,
  104. 'createtime' => time(),
  105. ];
  106. $id = Db::name('VideoPlatformRecord')->insertGetId($up);
  107. }
  108. }
  109. $this->success('分配完成');
  110. }
  111. // 检查过期版权,并扣除贡献值
  112. public function past_copyright(){
  113. // Db::startTrans();
  114. // try {
  115. $list = model('VideoShare')->where('endtime','<',time())->where('type',2)->where('expire',0)->select();
  116. if($list) {
  117. foreach ($list as $k => $v) {
  118. @file_put_contents("quanju.txt", json_encode($v) . "-要扣除的版权\r\n", 8);
  119. $video_user = model('VideoUser')->where('uid',$v['uid'])->where('vid',$v['vid'])->find();
  120. if ($video_user){
  121. // 要过期的版权数量也就是贡献值数量
  122. $share = $video_user['share']-$v['num']; // 扣除版权
  123. $contribution = $video_user['contribution']-$v['num']; //扣除贡献值
  124. if ($share <= 0&&$contribution<=0){
  125. $res1 = model('VideoUser')->where('uid',$v['uid'])->where('vid',$v['vid'])->delete();
  126. }else{
  127. $res1 = model('VideoUser')->where('uid',$v['uid'])->where('vid',$v['vid'])->update(['share'=>$share,'contribution'=>$contribution]);
  128. }
  129. @file_put_contents("quanju.txt", $res1 . "-修改状态\r\n", 8);
  130. // 保存扣除记录
  131. $up = [
  132. 'vid' => $v['vid'],
  133. 'uid' => $v['uid'],
  134. 'link_id' => $v['id'],
  135. 'num' => $v['num'],
  136. 'after' => $contribution,
  137. 'content' => '版权过期,扣除对应贡献值',
  138. 'createtime' => time(),
  139. 'pm' => 1,
  140. ];
  141. $id = Db::name('VideoContributionRecord')->insertGetId($up);
  142. @file_put_contents("quanju.txt", $id . "-记录id\r\n", 8);
  143. $user = model('Videolist')->where('id',$v['vid'])->find();
  144. $user_contribution = $user['share']+$v['num'];
  145. @file_put_contents("quanju.txt", $user_contribution . "-修改后版权\r\n", 8);
  146. $res2 = model('Videolist')->where('id',$v['vid'])->update(['share'=>$user_contribution]);
  147. $res3 = model('VideoShare')->where('id',$v['id'])->update(['expire'=>1]); //修改为已过期
  148. }
  149. }
  150. }
  151. // // 提交事务
  152. // Db::commit();
  153. // } catch (\Exception $e) {
  154. // // 回滚事务
  155. // var_dump($e);
  156. // Db::rollback();
  157. // }
  158. $this->success('检查完成');
  159. }
  160. // 每日分红
  161. public function dividend_day(){
  162. // 获取所有用户贡献值列表
  163. // $list = model('video_user')->select();
  164. $list = model('video_user')->where('contribution','>',0)->column('vid');
  165. var_dump($list);die();
  166. // 获取当前时间
  167. $now = time();
  168. // 获取昨天的日期
  169. $yesterday = strtotime("-1 day", $now);
  170. // 昨天的0点时间戳
  171. $yesterdayStart = strtotime("00:00:00", $yesterday);
  172. $yesterdayEnd = strtotime("12:59:59", $yesterday);
  173. if($list) {
  174. foreach ($list as $k => $v) {
  175. }
  176. }
  177. // 统计该短剧的总版版权数量以及持有版权的用户列表
  178. // 获取昨天该短剧的收益数据
  179. // 给各个用户分红
  180. }
  181. }