Activity.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace app\models\activity;
  3. use app\models\mining\UserMiningMachine;
  4. use app\models\system\SystemMoney;
  5. use app\models\user\User;
  6. use app\models\user\UserBill;
  7. use app\models\user\UserMoney;
  8. use app\Request;
  9. use Exception;
  10. use think\db\exception\DataNotFoundException;
  11. use think\db\exception\DbException;
  12. use think\db\exception\ModelNotFoundException;
  13. use crmeb\traits\ModelTrait;
  14. use crmeb\basic\BaseModel;
  15. /**
  16. * TODO 文章Model
  17. * Class Article
  18. * @package app\models\article
  19. */
  20. class Activity extends BaseModel
  21. {
  22. /**
  23. * 数据表主键
  24. * @var string
  25. */
  26. protected $pk = 'id';
  27. /**
  28. * 模型名称
  29. * @var string
  30. */
  31. protected $name = 'activity';
  32. use ModelTrait;
  33. /**
  34. * @param $page
  35. * @param $limit
  36. * @return array
  37. */
  38. public static function getList($page, $limit): array
  39. {
  40. $model = new self();
  41. $data = $model->page((int)$page, (int)$limit)->select()->each(function ($item) {
  42. $item['l1'] = $item['l1_money'] . get_money_name($item['l1_money_type']);
  43. $item['l2'] = $item['l2_money'] . get_money_name($item['l2_money_type']);
  44. $item['l3'] = $item['l3_money'] . get_money_name($item['l3_money_type']);
  45. $item['type'] = $item['group_type']?'大公排':'小公排';
  46. });
  47. $count = $model->count();
  48. return compact('data', 'count');
  49. }
  50. public static function getDetail($id, $uid = 0)
  51. {
  52. $model = new self();
  53. $info = $model->where('id', $id)->find()->toArray();
  54. $info['l1_money_type'] = get_money_name($info['l1_money_type']);
  55. $info['l2_money_type'] = get_money_name($info['l2_money_type']);
  56. $info['l3_money_type'] = get_money_name($info['l3_money_type']);
  57. if ($uid) {
  58. $info['my_joins'] = ActivityJoin::where('uid', $uid)->where('aid', $id)->order('add_time', 'desc')->select();
  59. $info['my_last_join'] = ActivityJoin::where('uid', $uid)->where('aid', $id)->order('add_time', 'desc')->find();
  60. $info['income'] = ActivityCheck::where('to_uid', $uid)->where('aid', $id)->where('status', 1)->group('money_type')->field('sum(money) as money,money_type')->select();
  61. $info['income_lock'] = UserBill::where('uid', $uid)->where('aid', $id)->where('pm', 1)->where('type', 'activity_income')->where('status', 0)->group('category')->field('sum(number) as money,category as money_type')->select();
  62. $info['expend'] = ActivityCheck::where('uid', $uid)->where('aid', $id)->where('status', 1)->group('money_type')->field('sum(money) as money,money_type')->select();
  63. $info['join_count'] = ActivityJoin::where('uid', $uid)->where('aid', $id)->count();
  64. if ($info['my_last_join']) {
  65. if ($info['my_last_join']['status'] >= 3) {
  66. $user = User::getUserInfo($uid);
  67. $gp_point = ActivityJoin::getUpPoint($user, $id, 1);
  68. $info['next_join'] = [
  69. 'group_num' => $gp_point,
  70. 'status' => 1,
  71. ];
  72. $up_user = intval(ceil(($gp_point - 1) / $info['explode_num']));
  73. $uper_info = ActivityJoin::where('aid', $id)->where('group_num', $up_user)->find();
  74. if (!$uper_info) {
  75. $info['next_checker'] = ['nickname' => '系统', 'uid' => 0];
  76. } else {
  77. $info['next_checker'] = User::getUserInfo($uper_info['uid']);
  78. }
  79. } else {
  80. $gp_point = $info['my_last_join']['group_num'];
  81. for ($i = 0; $i < $info['my_last_join']['status'] + 1; $i++) {
  82. $gp_point = intval(ceil(($gp_point - 1) / $info['explode_num']));
  83. }
  84. $info['my_last_join']['status'] = $info['my_last_join']['status'] + 1;
  85. $info['next_join'] = $info['my_last_join'];
  86. // $info['next_join']['status']++;
  87. $uper_info = ActivityJoin::where('aid', $id)->where('group_num', $gp_point)->find();
  88. if (!$uper_info) {
  89. $info['next_checker'] = ['nickname' => '系统', 'uid' => 0];
  90. } else {
  91. $info['next_checker'] = User::getUserInfo($uper_info['uid']);
  92. }
  93. }
  94. } else {
  95. $user = User::getUserInfo($uid);
  96. $gp_point = ActivityJoin::getUpPoint($user, $id);
  97. $info['next_join'] = [
  98. 'group_num' => $gp_point,
  99. 'status' => 1,
  100. ];
  101. $up_user = intval(ceil(($gp_point - 1) / $info['explode_num']));
  102. $uper_info = ActivityJoin::where('aid', $id)->where('group_num', $up_user)->find();
  103. if (!$uper_info) {
  104. $info['next_checker'] = ['nickname' => '系统', 'uid' => 0];
  105. } else {
  106. $info['next_checker'] = User::getUserInfo($uper_info['uid']);
  107. }
  108. }
  109. }
  110. return $info;
  111. }
  112. }