123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace app\models\activity;
- use app\models\mining\UserMiningMachine;
- use app\models\system\SystemMoney;
- use app\models\user\User;
- use app\models\user\UserBill;
- use app\models\user\UserMoney;
- use app\Request;
- use Exception;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- /**
- * TODO 文章Model
- * Class Article
- * @package app\models\article
- */
- class Activity extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'activity';
- use ModelTrait;
- /**
- * @param $page
- * @param $limit
- * @return array
- */
- public static function getList($page, $limit): array
- {
- $model = new self();
- $data = $model->page((int)$page, (int)$limit)->select()->each(function ($item) {
- $item['l1'] = $item['l1_money'] . get_money_name($item['l1_money_type']);
- $item['l2'] = $item['l2_money'] . get_money_name($item['l2_money_type']);
- $item['l3'] = $item['l3_money'] . get_money_name($item['l3_money_type']);
- $item['type'] = $item['group_type']?'大公排':'小公排';
- });
- $count = $model->count();
- return compact('data', 'count');
- }
- public static function getDetail($id, $uid = 0)
- {
- $model = new self();
- $info = $model->where('id', $id)->find()->toArray();
- $info['l1_money_type'] = get_money_name($info['l1_money_type']);
- $info['l2_money_type'] = get_money_name($info['l2_money_type']);
- $info['l3_money_type'] = get_money_name($info['l3_money_type']);
- if ($uid) {
- $info['my_joins'] = ActivityJoin::where('uid', $uid)->where('aid', $id)->order('add_time', 'desc')->select();
- $info['my_last_join'] = ActivityJoin::where('uid', $uid)->where('aid', $id)->order('add_time', 'desc')->find();
- $info['income'] = ActivityCheck::where('to_uid', $uid)->where('aid', $id)->where('status', 1)->group('money_type')->field('sum(money) as money,money_type')->select();
- $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();
- $info['expend'] = ActivityCheck::where('uid', $uid)->where('aid', $id)->where('status', 1)->group('money_type')->field('sum(money) as money,money_type')->select();
- $info['join_count'] = ActivityJoin::where('uid', $uid)->where('aid', $id)->count();
- if ($info['my_last_join']) {
- if ($info['my_last_join']['status'] >= 3) {
- $user = User::getUserInfo($uid);
- $gp_point = ActivityJoin::getUpPoint($user, $id, 1);
- $info['next_join'] = [
- 'group_num' => $gp_point,
- 'status' => 1,
- ];
- $up_user = intval(ceil(($gp_point - 1) / $info['explode_num']));
- $uper_info = ActivityJoin::where('aid', $id)->where('group_num', $up_user)->find();
- if (!$uper_info) {
- $info['next_checker'] = ['nickname' => '系统', 'uid' => 0];
- } else {
- $info['next_checker'] = User::getUserInfo($uper_info['uid']);
- }
- } else {
- $gp_point = $info['my_last_join']['group_num'];
- for ($i = 0; $i < $info['my_last_join']['status'] + 1; $i++) {
- $gp_point = intval(ceil(($gp_point - 1) / $info['explode_num']));
- }
- $info['my_last_join']['status'] = $info['my_last_join']['status'] + 1;
- $info['next_join'] = $info['my_last_join'];
- // $info['next_join']['status']++;
- $uper_info = ActivityJoin::where('aid', $id)->where('group_num', $gp_point)->find();
- if (!$uper_info) {
- $info['next_checker'] = ['nickname' => '系统', 'uid' => 0];
- } else {
- $info['next_checker'] = User::getUserInfo($uper_info['uid']);
- }
- }
- } else {
- $user = User::getUserInfo($uid);
- $gp_point = ActivityJoin::getUpPoint($user, $id);
- $info['next_join'] = [
- 'group_num' => $gp_point,
- 'status' => 1,
- ];
- $up_user = intval(ceil(($gp_point - 1) / $info['explode_num']));
- $uper_info = ActivityJoin::where('aid', $id)->where('group_num', $up_user)->find();
- if (!$uper_info) {
- $info['next_checker'] = ['nickname' => '系统', 'uid' => 0];
- } else {
- $info['next_checker'] = User::getUserInfo($uper_info['uid']);
- }
- }
- }
- return $info;
- }
- }
|