count(); $list = $model->page($page, $limit)->select()->toArray(); return compact('count', 'list'); } public static function buyPoroduct($id, $uid, $num) { $info = self::valid()->where('id', $id)->find(); if (!$info) { return self::setErrorInfo('产品已下架或不存在'); } if ($info['personal_limit'] < UserBorrowMoney::where('mid', $id) ->where('uid', $uid) ->where('finish_time', null) ->sum('money') + $num ) { return self::setErrorInfo('借贷上限不足' . $num); } $money_type = init_money_type(); BaseModel::beginTrans(); try { $res1 = UserMoney::incomeMoney($uid, $info['money_type'], $num, 'borrow_money', '借贷', '借贷' . $info['name'] . '*' . $num . $money_type[$info['money_type']]); if ($res1) { $res = UserBorrowMoney::create([ 'uid' => $uid, 'mid' => $id, 'ratio' => $info['ratio'], 'money_type' => $info['money_type'], 'money' => $num, 'add_time' => time(), 'send_start_time' => bcadd(time(), $info['stand_time'] * 3600 * 24), 'status' => $info['stand_time'] == 0 ? 1 : 0, 'next_send_time' => $info['time'] > 0 ? date('Y-m-d', strtotime('+1day')) : null, ]); if (!$res) { return BaseModel::setErrorInfo('贷款失败', true); } } else { return BaseModel::setErrorInfo('放款失败', true); } BaseModel::commitTrans(); return true; } catch (Exception $e) { return BaseModel::setErrorInfo($e->getMessage(), true); } } }