break; default: $orderQuery .= " ASC"; abr('orderDir', 'desc'); } $data = $cms->getAll(START, LIMIT, $whereQuery, $orderQuery); if (is_array($data)) { #加载佣金分成 require_once ROOT_PATH . '/apps/percents/models/percents.class.php'; $percentsClass = new percents(); #加载余额 require_once ROOT_PATH . '/apps/users/models/balance.class.php'; $balanceClass = new balance(); $percents = $percentsClass->getAll(); foreach ($data as $k => $d) { $comision = $percentsClass->getPercentRow($d); $data[$k]['commission'] = $comision['percent']; // if($data[$k]['commission_percent'] < 1) { // foreach($percents as $p) { // if($d['sold'] >= $p['from'] && ($d['sold'] < $p['to'] || $p['to'] == '0')) { // $data[$k]['commission'] = $p['percent']; // break; // } // } // } else { // $data[$k]['commission'] = $data[$k]['commission_percent']; // } $data[$k]['sum'] = $balanceClass->getTotalUserBalanceByType($d['user_id']); } } abr('data', $data);
$text .= '<tr><td>' . $day . '</td><td>' . $r['sale'] . ' ' . $langArray['sales'] . '</td><td>¥' . number_format($r['earning'], 2) . '</td></tr>'; } } die(' jQuery("#month_' . $month . '_' . $year . '_details").html(\'' . $text . '\'); jQuery("#month_' . $month . '_' . $year . '_show").hide(); jQuery("#month_' . $month . '_' . $year . '_hide").show(); '); } $usersClass = new users(); $user = $usersClass->get($_SESSION['user']['user_id']); abr('user', $user); #获取百分比 require_once ROOT_PATH . '/apps/percents/models/percents.class.php'; $percentsClass = new percents(); $percent = $percentsClass->getPercentRow($user); if ($percent['to'] == '0') { $percent['more'] = '-'; } else { $percent['more'] = floatval($percent['to']) - floatval($user['sold']); } abr('percent', $percent); $earnings = array('sales' => 0, 'sales_earning' => 0, 'referal' => 0, 'total' => 0); $maxSales = 0; $earningArr = false; #获取销售金额 $sales = $ordersClass->getAll(" `paid` = 'true' AND `type` = 'buy' AND `owner_id` = '" . intval($user['user_id']) . "' ", "`paid_datetime` ASC"); if (is_array($sales)) { $buff = array(); foreach ($sales as $r) { $date = explode(' ', $r['paid_datetime']);
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; }