where('send_start_time', '<', time()) ->where('finish_time', null); } /** * @param int $page * @param int $limit * @param array $where * @return array */ public static function getList(int $page = 1, int $limit = 10, array $where = []): array { $model = new self(); if (isset($where['status']) && $where['status'] != '') $model = $model->where('status', $where['status']); $count = $model->count(); $list = $model->page($page, $limit)->select()->each(function ($item) { $item['body'] = BorrowMoneyProduct::get($item['mid']); })->toArray(); return compact('count', 'list'); } /** * @return UserBorrowMoney */ public static function dayMiningStatusStart() { return self::valid(0)->update(['status' => 1]); } public static function daySend() { //今日已发放矿机 BaseModel::beginTrans(); self::dayMiningStatusStart(); try { $res = true; $list = self::valid()->where(function ($query) { $query->where('next_send_time', date('Y-m-d')) ->whereOr('next_send_time', null); })->select(); if (count($list)) { foreach ($list as $v) { $ratio = $v['ratio']; $year = bcmul(bcdiv($ratio, 100, 4), $v['money'], 8); $year = bcdiv($year, 365, 8); $res = $res && self::bcInc($v['id'], 'all_send', $year, 'id') && (self::where('id', $v['id'])->update(['next_send_time' => date('Y-m-d', strtotime('+1 day'))])); } } if ($res) { BaseModel::commitTrans(); return true; } else return self::setErrorInfo(self::getErrorInfo(), false); } catch (Exception $e) { return self::setErrorInfo($e->getMessage(), true); } } public static function endManege($id, $num) { $info = self::get($id); if (!$info || !$info['status'] == 2) return self::setErrorInfo('理财记录异常'); $minfo = BorrowMoneyProduct::get($info['mid']); $money_type = init_money_type(); $user_money = UserMoney::initialUserMoney($info['uid'], $info['money_type']); $all_money = bcadd($info['money'], $info['all_send'], 8); if ($num >= $all_money) { if ($user_money['money'] < $all_money) { return self::setErrorInfo('还款所需的' . $money_type[$info['money_type']] . '不足'); } return self::where('id', $id)->update(['status' => 2, 'real_finish_time' => time()]) && UserMoney::expendMoney($info['uid'], $info['money_type'], $all_money, 'return_borrow_money', '全额还款' . $minfo['name']); } else { if ($user_money['money'] < $num) { return self::setErrorInfo('还款所需的' . $money_type[$info['money_type']] . '不足'); } if ($num > $info['all_send']) { return self::where('id', $id)->update(['all_send' => bcsub($info['all_send'], $info['all_send'], 8)]) && UserMoney::expendMoney($info['uid'], $info['money_type'], $info['all_send'], 'return_borrow_money_sub', '还款' . $minfo['name'] . '利息' . $num) && self::where('id', $id)->update(['money' => bcsub($info['money'], bcsub($num, $info['all_send'], 8), 8)]) && UserMoney::expendMoney($info['uid'], $info['money_type'], bcsub($num, $info['all_send'], 8), 'return_borrow_money_sub', '还款' . $minfo['name'] . '本金' . $num); } else { return self::where('id', $id)->update(['all_send' => bcsub($info['all_send'], $num)]) && UserMoney::expendMoney($info['uid'], $info['money_type'], $num, 'return_borrow_money_sub', '还款' . $minfo['name'] . '利息' . $num); } } } }