123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace app\models\point_plan;
- use app\models\user\User;
- use app\models\user\UserMoney;
- use crmeb\basic\BaseModel;
- use crmeb\traits\ModelTrait;
- use think\Collection;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- class UserPointPlan extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'user_point_plan';
- use ModelTrait;
- public static function is_point($uid)
- {
- return self::where('uid', $uid)
- ->where('status', 1)
- ->find();
- }
- public static function all_point()
- {
- return self::where('status', 1)
- ->column('uid');
- }
- public static function day_release()
- {
- $list = self::where('status', 1)
- ->where('last_release_day', '<>', date('Y-m-d'))
- ->select();
- $res = true;
- BaseModel::beginTrans();
- foreach ($list as $v) {
- if ($v['release_time_now'] < $v['release_time_all']) {
- $day_release = bcdiv(bcmul($v['release_ratio'], $v['buy_num'], 8), $v['release_time_all']);
- $res = $res && UserMoney::incomeMoney($v['uid'], $v['release_money_type'], $day_release, 'release', '节点释放', '节点释放' . ' 第' . ($v['release_time_now'] + 1) . '期');
- $res = $res && self::where('id', $v['id'])
- ->inc('release_time_now', 1)
- ->update();
- $res = $res && self::where('id', $v['id'])
- ->update(['last_release_day' => date('Y-m-d')]);
- }
- }
- BaseModel::checkTrans($res);
- return $res;
- }
- public static function checkPass()
- {
- $list = self::where('status', 0)->select();
- $res = true;
- // BaseModel::beginTrans();
- foreach ($list as $v) {
- $recommend = User::where('spread_uid', $v['uid'])->where('vote_num', '>=', sys_config('vaild_user', 0))->count();
- $group = User::getAllLowUid($v['uid'], false, false, true);
- $plan = PointPlan::get($v['plan_id']);
- if ($recommend >= $plan['recommend_num'] && $group >= $plan['group_num']) {
- $res = $res && self::where('id', $v['id'])->update(['status' => 1, 'pass_time' => time()]);
- }
- }
- // BaseModel::checkTrans($res);
- return $res;
- }
- public static function checkFail()
- {
- $list = self::where('status', 0)->where('exam_time', '<=', time())->select();
- $res = true;
- BaseModel::beginTrans();
- foreach ($list as $v) {
- $res = $res && self::where('id', $v['id'])->update(['status' => 2]);
- }
- BaseModel::checkTrans($res);
- return $res;
- }
- /**
- * @param $where
- * @return array
- */
- public static function getList($where)
- {
- $model = new self();
- if (isset($where['id']) && $where['id'] != '') {
- $model->where('plan_id', $where['id']);
- }
- $count = $model->count();
- $data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
- $item['_status'] = ($item['status'] == 1) ? "考核成功" : (($item['status'] == 2) ? "考核失败" : "考核中");
- $item['user'] = User::getUserInfo($item['uid']);
- $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
- $item['_pass_time'] = $item['pass_time'] ? date('Y-m-d H:i:s', $item['pass_time']) : '--';
- $item['_check_end_time'] = date('Y-m-d H:i:s', $item['check_end_time']);
- });
- return compact('count', 'data');
- }
- }
|