public function buy($price, $extended = false) { global $mysql, $langArray, $item; //资金流动类 require_once ROOT_PATH . '/apps/users/models/transaction_details.class.php'; $logClass = new transaction_details(); require_once ROOT_PATH . '/apps/users/models/users.class.php'; $usersClass = new users(); //获取当前购买用户详细信息 $you = $usersClass->get($_SESSION['user']['user_id']); $deposit = 0; $earning = 0; //用户实际支付金额 $t_pay_price = floatval($price) - floatval($item['your_profit']); $t_pay_price > 0 ? $t_pay_price : ($t_pay_price = 0); //账号余额是否充足 if ($you['deposit'] >= $t_pay_price) { $deposit = $t_pay_price; } else { $deposit = $you['deposit']; $earning = floatval($t_pay_price) - floatval($you['deposit']); } //扣款购买 $mysql->query("\n\t\t\tUPDATE `users`\n\t\t\tSET `deposit` = `deposit` - '" . floatval($deposit) . "',\n\t\t\t\t\t`earning` = `earning` - '" . floatval($earning) . "',\n\t\t\t\t\t`total` = `total` - '" . floatval($t_pay_price) . "'\n\t\t\tWHERE `user_id` = '" . intval($you['user_id']) . "'\n\t\t\tLIMIT 1\n\t\t"); //记录资金流动(uid,type,value,info) if (floatval($t_pay_price) > 0) { $logClass->addRecord(intval($you['user_id']), 'buy', -floatval($t_pay_price), $langArray['item_name'] . ':' . $item['name'] . '(' . $langArray['pay_buy_balance'] . ')'); } $_SESSION['user']['deposit'] = floatval($_SESSION['user']['deposit']) - floatval($deposit); $_SESSION['user']['earning'] = floatval($_SESSION['user']['earning']) - floatval($earning); $_SESSION['user']['total'] = floatval($_SESSION['user']['total']) - floatval($t_pay_price); //对推广用户进行返佣金 if ($you['referal_id'] != '0') { $this->referalMoney(array('price' => $price, 'user_id' => $_SESSION['user']['user_id'], 'owner_id' => $item['user_id'], 'item_id' => $item['id'], 'item_name' => $item['name']), $you); } //打款给作者 $user = $usersClass->get($item['user_id']); require_once ROOT_PATH . '/apps/percents/models/percents.class.php'; $percentsClass = new percents(); //获取用户分成比例(作者) $percent = $percentsClass->getPercentRow($user); $percent = $percent['percent']; //作者所得分成 $receiveMoney = floatval($price) * floatval($percent) / 100; $mysql->query("\n\t\t\tUPDATE `users`\n\t\t\tSET `earning` = `earning` + '" . floatval($receiveMoney) . "',\n\t\t\t\t\t`total` = `total` + '" . floatval($receiveMoney) . "',\n\t\t\t\t\t`sold` = `sold` + '" . floatval($price) . "',\n\t\t\t\t\t`sales` = `sales` + 1\n\t\t\tWHERE `user_id` = '" . intval($user['user_id']) . "'\n\t\t\tLIMIT 1\n\t\t"); //记录资金流动(uid,type,value,info) if (floatval($receiveMoney) > 0) { $logClass->addRecord(intval($user['user_id']), 'sale_income', floatval($receiveMoney), $langArray['item_name'] . ':' . $item['name']); } #添加订单 $mysql->query("\n\t\t\tINSERT INTO `orders` (\n\t\t\t\t`user_id`,\n\t\t\t\t`owner_id`,\n\t\t\t\t`item_id`,\n\t\t\t\t`item_name`,\n\t\t\t\t`price`,\n\t\t\t\t`datetime`,\n\t\t\t\t`receive`,\n\t\t\t\t`paid`,\n\t\t\t\t`paid_datetime`\n\t\t\t)\n\t\t\tVALUES (\n\t\t\t\t'" . intval($_SESSION['user']['user_id']) . "',\n\t\t\t\t'" . intval($item['user_id']) . "',\n\t\t\t\t'" . intval($item['id']) . "',\n\t\t\t\t'" . sql_quote($item['name']) . "',\n\t\t\t\t'" . sql_quote($price) . "',\n\t\t\t\tNOW(),\n\t\t\t\t'" . sql_quote($receiveMoney) . "',\n\t\t\t\t'true',\n\t\t\t\tNOW()\n\t\t\t)\n\t\t"); $mysql->query("\n\t\t\tUPDATE `users`\n\t\t\tSET `buy` = `buy` + 1\n\t\t\tWHERE `user_id` = '" . intval($_SESSION['user']['user_id']) . "'\n\t\t\tLIMIT 1 \n\t\t"); #更新作品 $setQuery = ''; if ($extended) { $setQuery = " `status` = 'extended_buy', "; } $mysql->query("\n\t\t\tUPDATE `items`\n\t\t\tSET `sales` = `sales` + 1,\n\t\t\t\t\t{$setQuery}\n\t\t\t\t\t`earning` = `earning` + '" . sql_quote($price) . "'\n\t\t\tWHERE `id` = '" . intval($item['id']) . "'\n\t\t"); return true; }
$nav['prev']['year'] = date('Y', mktime(0, 0, 0, $_GET['month'] - 1, 1, $_GET['year'])); $nav['next']['month'] = date('m', mktime(0, 0, 0, $_GET['month'] + 1, 1, $_GET['year'])); $nav['next']['year'] = date('Y', mktime(0, 0, 0, $_GET['month'] + 1, 1, $_GET['year'])); if ($nav['prev']['month'] < $registrationDate[1] && $nav['prev']['year'] <= $registrationDate[0]) { $nav['prev']['show'] = 'false'; } else { $nav['prev']['show'] = 'true'; } if ($nav['next']['month'] > date('m') && $nav['next']['year'] >= date('Y')) { $nav['next']['show'] = 'false'; } else { $nav['next']['show'] = 'true'; } abr('nav', $nav); //获取资金流动记录 $logClass = new transaction_details(); $statement = $logClass->getRecord($_SESSION['user']['user_id']); #获取资金记录 //require_once ROOT_PATH.'/apps/items/models/orders.class.php'; //$ordersClass = new orders(); //$statement = $ordersClass->getStatement($_SESSION['user']['user_id'], $_GET['month'], $_GET['year']); abr('statement', $statement); if (isset($_GET['export'])) { header('Content-Type: application/text/x-csv; charset=utf-8; encoding=utf-8'); header('Content-Disposition: attachment; filename="stetement_' . $_GET['month'] . '_' . $_GET['year'] . '.csv"'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header("Content-Transfer-Encoding: binary"); header('Expires: 0'); @ob_clean(); @flush();
public function payoutWithdraw() { global $mysql, $langArray, $user, $data; if (!isset($_POST['payout']) || !is_numeric($_POST['payout']) || $_POST['payout'] < 1) { return $langArray['error_set_valid_sum']; } //判断金额 if ($_POST['payout'] > $user['earning']) { return $langArray['error_not_enought_money_earning']; } //查询该提现申请是否已经处理 $mysql->query("\n\t\t\tSELECT COUNT(`id`) as count\n\t\t\tFROM `withdraw`\n\t\t\tWHERE `id` = '" . intval($data['id']) . "' and `paid`='true'\n\t\t"); $r = $mysql->fetch_array(); if ($r['count'] > 0) { return false; } else { //扣款 $mysql->query("\n\t\t\t\tUPDATE `users`\n\t\t\t\tSET `earning` = `earning` - '" . floatval($_POST['payout']) . "',\n\t\t\t\t\t\t`total` = `total` - '" . floatval($_POST['payout']) . "'\n\t\t\t\tWHERE `user_id` = '" . intval($user['user_id']) . "'\n\t\t\t\tLIMIT 1\n\t\t\t"); //改变状态 $mysql->query("\n\t\t\t\tUPDATE `withdraw`\n\t\t\t\tSET `paid` = 'true',\n\t\t\t\t\t\t`paid_datetime` = NOW()\n\t\t\t\tWHERE `id` = '" . intval($data['id']) . "'\n\t\t\t\tLIMIT 1\n\t\t\t"); //资金流动类 require_once ROOT_PATH . '/apps/users/models/transaction_details.class.php'; $logClass = new transaction_details(); //记录资金流动(uid,type,value,info) if (floatval($_POST['payout']) > 0) { $logClass->addRecord(intval($user['user_id']), 'withdraw', -floatval($_POST['payout']), $langArray['withdraw_method'] . ':' . $data['method']); } return true; } }