page((int)$page, (int)$limit)->select()->each(function ($item) { $item['_cost'] = ($item['cost'] * 1) . get_money_name($item['cost_money_type']); $item['_bingo'] = ($item['bingo'] * 1) . get_money_name($item['bingo_money_type']); if ($item['ticket_money_type'] != 'LALA') { $money_types = sys_data('money_type'); $origin_ratio = 0; $target_ratio = 0; foreach ($money_types as $v) { if ($v['code'] == $item['ticket_money_type']) { $origin_ratio = $v['usdt_price']; if ($origin_ratio == 0) { $origin_ratio = get_huobi_price($v['code']); } } if ($v['code'] == 'LALA') { $target_ratio = get_lala_ratio(); } } $ratio = bcdiv($origin_ratio, $target_ratio, 14); $item['ticket'] = bcmul($item['ticket'], $ratio, 8); $item['ticket_money_type'] = 'LALA'; } $item['ticket_money_type'] = get_money_name($item['ticket_money_type']); $item['cost_money_type'] = get_money_name($item['cost_money_type']); $item['cost_2_money_type'] = get_money_name($item['cost_2_money_type']); $item['bingo_money_type'] = get_money_name($item['bingo_money_type']); $item['_ticket'] = ($item['ticket'] * 1) . $item['ticket_money_type']; $item['_status'] = $item['status'] ? "正常" : "已关闭"; }); $count = $model->count(); return compact('data', 'count'); } /** * @param $where * @param $page * @param $limit * @return array */ public static function getExchangeList($id, $uid, $page, $limit): array { $model = LalaSpExchange::where('lala_id', $id)->where('uid', $uid); $data = $model->order('add_time desc,id desc')->page((int)$page, (int)$limit)->select()->each(function ($item) { $item['origin_money_type'] = get_money_name($item['origin_money_type']); $item['target_money_type'] = get_money_name($item['target_money_type']); }); $count = $model->count(); return compact('data', 'count'); } /** * @param $uid * @param $id * @return bool * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public static function spExchange($uid, $id): bool { $user_times = LalaPinkJoin::where('uid', $uid)->where('lala_id', $id)->where('status', 1)->where('paid', 1)->count(); $used_times = LalaSpExchange::where('uid', $uid)->where('lala_id', $id)->sum('cost_time'); $used_times += UserMiningMachine::where('uid', $uid)->where('paid', 1)->where('lala_id', $id)->sum('cost_times'); $lala_info = self::validWhere()->where('id', $id)->find(); $user_info = User::getUserInfo($uid); if (!$user_info) return self::setErrorInfo('用户异常'); if (!$lala_info) return self::setErrorInfo('找不到拼购活动'); if (bcsub($user_times, $used_times) < $lala_info['sp_exchange_bingo_time']) { return self::setErrorInfo('剩余幸运值不足,无法兑换'); } BaseModel::beginTrans(); try { $res1 = UserMoney::expendMoney($uid, $lala_info['sp_exchange_origin'], $lala_info['sp_exchange_origin_cost'], 'sp_exchange', '特殊兑换', $lala_info['name'] . '特殊兑换'); if (!$res1) { BaseModel::rollbackTrans(); return self::setErrorInfo(UserMoney::getErrorInfo()); } $res2 = UserMoney::incomeMoney($uid, $lala_info['sp_exchange_target'], $lala_info['sp_exchange_target_get'], 'sp_exchange', '特殊兑换', $lala_info['name'] . '特殊兑换'); // $res2 = SystemMoney::tradeMoney($user_info['site_id'], $uid, $lala_info['sp_exchange_target'], $lala_info['sp_exchange_target_get']); if (!$res2) { BaseModel::rollbackTrans(); return self::setErrorInfo(UserMoney::getErrorInfo()); } $res3 = LalaSpExchange::create([ 'uid' => $uid, 'lala_id' => $id, 'cost_time' => $lala_info['sp_exchange_bingo_time'], 'add_time' => time(), 'origin' => $lala_info['sp_exchange_origin_cost'], 'origin_money_type' => $lala_info['sp_exchange_origin'], 'target' => $lala_info['sp_exchange_target_get'], 'target_money_type' => $lala_info['sp_exchange_target'], ]); if ($res3) { BaseModel::commitTrans(); return true; } else { BaseModel::rollbackTrans(); return self::setErrorInfo('创建记录失败'); } } catch (Exception $e) { BaseModel::rollbackTrans(); return self::setErrorInfo($e->getMessage()); } } }