public function changeStatus($order_id) { $row = Model_Orders::get($order_id); if (!$row || $row['paid'] == 'true') { return false; //ERROR } $percent = Model_Percents::getPercentRow($row['owner_id']); $percent = $percent['percent']; $receiveMoney = floatval($row['price']) * floatval($percent) / 100; $db = JO_Db::getDefaultAdapter(); $db->update('orders', array('paid' => 'true', 'paid_datetime' => new JO_Db_Expr('NOW()'), 'receive' => $receiveMoney), array('id = ?' => (int) $order_id)); $db->update(Model_Users::getPrefixDB() . 'users', array('earning' => new JO_Db_Expr('earning+' . $receiveMoney), 'total' => new JO_Db_Expr('total+' . $receiveMoney), 'sold' => new JO_Db_Expr('sold+' . $row['price']), 'sales' => new JO_Db_Expr('sales+1')), array('user_id = ?' => $row['owner_id'])); $you = Model_Users::getUser($row['user_id']); #CHECK REFERAL if ($you['referal_id'] != 0) { $row['order_id'] = $order_id; Model_Orders::referalMoney($row, $you); } $db->update(Model_Users::getPrefixDB() . 'users', array('buy' => new JO_Db_Expr('buy+1')), array('user_id = ?' => $row['user_id'])); $toinsert = array('sales' => new JO_Db_Expr('sales+1'), 'earning' => new JO_Db_Expr('earning+' . $row['price'])); #UPDATE ITEM if ($row['extended'] == 'true') { $db->update('users', array('items' => new JO_Db_Expr('items-1')), array('user_id = ?' => $row['user_id'])); $toinsert['status'] = 'extended_buy'; } $db->update('items', $toinsert, array('id = ?' => $row['id'])); return true; }
public function indexAction() { if ($this->session->get('successfu_edite')) { $this->view->successfu_edite = true; $this->session->clear('successfu_edite'); } $reques = $this->getRequest(); $this->view->sort = $reques->getRequest('sort', 'DESC'); $this->view->order = $reques->getRequest('order', 'i.id'); $this->view->page_num = $page = $reques->getRequest('page', 1); $this->view->filter_id = $reques->getQuery('filter_id'); $this->view->filter_username = $reques->getQuery('filter_username'); $this->view->filter_total = $reques->getQuery('filter_total'); $this->view->filter_sales = $reques->getQuery('filter_sales'); $this->view->filter_sold = $reques->getQuery('filter_sold'); $this->view->filter_web_profit2 = $reques->getQuery('filter_web_profit2'); $this->view->filter_commission = $reques->getQuery('filter_commission'); $this->view->filter_items = $reques->getQuery('filter_items'); $this->view->filter_referals = $reques->getQuery('filter_referals'); $this->view->filter_referal_money = $reques->getQuery('filter_referal_money'); $this->view->filter_featured_author = $reques->getQuery('filter_featured_author'); $url = ''; if ($this->view->filter_id) { $url .= '&filter_id=' . $this->view->filter_id; } if ($this->view->filter_username) { $url .= '&filter_username='******'&filter_total=' . $this->view->filter_total; } if ($this->view->filter_sales) { $url .= '&filter_sales=' . $this->view->filter_sales; } if ($this->view->filter_sold) { $url .= '&filter_sold=' . $this->view->filter_sold; } if ($this->view->filter_web_profit2) { $url .= '&filter_web_profit2=' . $this->view->filter_web_profit2; } if ($this->view->filter_commission) { $url .= '&filter_commission=' . $this->view->filter_commission; } if ($this->view->filter_items) { $url .= '&filter_items=' . $this->view->filter_items; } if ($this->view->filter_referals) { $url .= '&filter_referals=' . $this->view->filter_referals; } if ($this->view->filter_referal_money) { $url .= '&filter_referal_money=' . $this->view->filter_referal_money; } if ($this->view->filter_featured_author) { $url .= '&filter_featured_author=' . $this->view->filter_featured_author; } $url1 = ''; if ($this->view->sort) { $url1 .= '&sort=' . $this->view->sort; } if ($this->view->order) { $url1 .= '&order=' . $this->view->order; } $url2 = '&page=' . $page; $data = array('start' => $page * JO_Registry::get('admin_limit') - JO_Registry::get('admin_limit'), 'limit' => JO_Registry::get('admin_limit'), 'sort' => $this->view->sort, 'order' => $this->view->order, 'filter_id' => $this->view->filter_id, 'filter_username' => $this->view->filter_username, 'filter_total' => $this->view->filter_total, 'filter_sales' => $this->view->filter_sales, 'filter_sold' => $this->view->filter_sold, 'filter_web_profit2' => $this->view->filter_web_profit2, 'filter_commission' => $this->view->filter_commission, 'filter_items' => $this->view->filter_items, 'filter_referals' => $this->view->filter_referals, 'filter_referal_money' => $this->view->filter_referal_money, 'filter_featured_author' => $this->view->filter_featured_author); $this->view->users = array(); $users = Model_Users::getUsers($data); $percentsClass = new Model_Percents(); if ($users) { foreach ($users as $user) { if (!isset($user['sum_referals'])) { $user['sum_referals'] = 0; } $user['deposit'] = WM_Currency::format($user['deposit']); $user['earning'] = WM_Currency::format($user['earning']); $user['total'] = WM_Currency::format($user['total']); $user['sold'] = WM_Currency::format($user['sum_price']); $user['has_referral_sum'] = $user['sum_referals']; $user['web_profit'] = WM_Currency::format($user['sum_price'] - $user['sum_receive']); $user['web_profit2'] = WM_Currency::format($user['sum_price'] - $user['sum_receive'] - $user['sum_referals']); $user['referal_money'] = WM_Currency::format($user['sum_referals']); $comision = $percentsClass->getPercentRow($user['user_id']); $user['commission'] = round($comision['percent']); $user['sum'] = Model_Balance::getTotalUserBalanceByType($user['user_id']); $user['referral_sum'] = WM_Currency::format($user['sum_referals']); $user['edit_href'] = $reques->getModule() . '/users/edite/?id=' . $user['user_id'] . $url . $url1 . $url2; $user['balance_href'] = $reques->getModule() . '/users/balance/?id=' . $user['user_id'] . $url . $url1 . $url2; $this->view->users[] = $user; } } $this->view->sort = strtolower($this->view->sort); $this->view->sort_id = $reques->getModule() . '/users/?order=u.user_id&sort=' . ($this->view->sort == 'asc' ? 'DESC' : 'ASC') . $url . $url2; $this->view->sort_username = $reques->getModule() . '/users/?order=u.username&sort=' . ($this->view->sort == 'asc' ? 'DESC' : 'ASC') . $url . $url2; $this->view->sort_total = $reques->getModule() . '/users/?order=u.total&sort=' . ($this->view->sort == 'asc' ? 'DESC' : 'ASC') . $url . $url2; $this->view->sort_sales = $reques->getModule() . '/users/?order=u.sales&sort=' . ($this->view->sort == 'asc' ? 'DESC' : 'ASC') . $url . $url2; $this->view->sort_sold = $reques->getModule() . '/users/?order=u.sold&sort=' . ($this->view->sort == 'asc' ? 'DESC' : 'ASC') . $url . $url2; $this->view->sort_web_profit2 = $reques->getModule() . '/users/?order=u.web_profit2&sort=' . ($this->view->sort == 'asc' ? 'DESC' : 'ASC') . $url . $url2; $this->view->sort_commission = $reques->getModule() . '/users/?order=u.commission&sort=' . ($this->view->sort == 'asc' ? 'DESC' : 'ASC') . $url . $url2; $this->view->sort_items = $reques->getModule() . '/users/?order=u.items&sort=' . ($this->view->sort == 'asc' ? 'DESC' : 'ASC') . $url . $url2; $this->view->sort_referals = $reques->getModule() . '/users/?order=u.referals&sort=' . ($this->view->sort == 'asc' ? 'DESC' : 'ASC') . $url . $url2; $this->view->sort_referal_money = $reques->getModule() . '/users/?order=u.referal_money&sort=' . ($this->view->sort == 'asc' ? 'DESC' : 'ASC') . $url . $url2; $this->view->sort_featured_author = $reques->getModule() . '/users/?order=u.featured_author&sort=' . ($this->view->sort == 'asc' ? 'DESC' : 'ASC') . $url . $url2; $total_records = Model_Users::getTotalUsers($data); $this->view->total_pages = ceil($total_records / JO_Registry::get('admin_limit')); $this->view->total_rows = $total_records; $pagination = new Model_Pagination(); $pagination->setLimit(JO_Registry::get('admin_limit')); $pagination->setPage($page); $pagination->setTotal($total_records); $pagination->setUrl($this->getRequest()->getModule() . '/users/?page={page}' . $url . $url1); $this->view->pagination = $pagination->render(); }
public function indexAction() { $request = $this->getRequest(); $this->view->base_url = $request->getBaseUrl(); #LINKS FOR HEAD PARTS IN BOX $this->view->finance_href = $request->getModule() . '/reports/'; $this->view->sales_href = $request->getModule() . '/orders/'; $this->view->users_href = $request->getModule() . '/users/'; $this->view->approval_href = $request->getModule() . '/queueitems/'; $this->view->queue_href = $request->getModule() . '/queueupdateditems/'; $this->view->contacts_href = $request->getModule() . '/contacts/'; $this->view->gainpayingup_href = $request->getModule() . '/gainpayingup/'; $this->view->tags_href = $request->getModule() . '/tags/?filter_visible=false'; #LOAD ORDERS COUNT $this->view->total = Model_Orders::getSalesStatus(); if ($this->view->total) { $this->view->total['total_f'] = WM_Currency::format($this->view->total['total']); } $ref = Model_Orders::getSalesStatus(" AND `datetime` > '" . date('Y-m') . "-01 00:00:00' ", 'referal'); $sales = Model_Orders::getSalesStatus(" AND `datetime` > '" . date('Y-m') . "-01 00:00:00' "); if ($sales) { if ($ref) { $sales['referal'] = $ref['receive']; } else { $sales['referal'] = 0; } $sales['win'] = floatval($sales['total']) - floatval($sales['receive']) - floatval($sales['referal']); $sales['total_f'] = WM_Currency::format($sales['total']); $sales['receive_f'] = WM_Currency::format($sales['receive']); $sales['referal_f'] = WM_Currency::format($sales['referal']); $sales['win_f'] = WM_Currency::format($sales['win']); } $this->view->sales = $sales; unset($ref); $ref = Model_Orders::getSalesStatus("", 'referal'); $sales = Model_Orders::getSalesStatus(""); if ($sales) { if ($ref) { $sales['referal'] = $ref['receive']; } else { $sales['referal'] = 0; } $sales['win'] = floatval($sales['total']) - floatval($sales['receive']) - floatval($sales['referal']); $sales['total_f'] = WM_Currency::format($sales['total']); $sales['receive_f'] = WM_Currency::format($sales['receive']); $sales['referal_f'] = WM_Currency::format($sales['referal']); $sales['win_f'] = WM_Currency::format($sales['win']); } $this->view->sales2 = $sales; unset($ref); #LOAD USERS COUNT $this->view->users = array(); $this->view->users['month'] = Model_Users::getUsersCount(" `register_datetime` > '" . date('Y-m') . "-01 00:00:00' AND `status` = 'activate' "); $this->view->users['total'] = Model_Users::getUsersCount(" `status` = 'activate' "); $this->view->topAuthors = array(); $topAuthors = Model_Users::getAll(0, 5, " `status` = 'activate' ", "`sales` DESC"); if ($topAuthors) { $percentsClass = new Model_Percents(); foreach ($topAuthors as $user) { $user['deposit'] = WM_Currency::format($user['deposit']); $user['earning'] = WM_Currency::format($user['earning']); $user['total'] = WM_Currency::format($user['total']); $user['sold'] = WM_Currency::format($user['sold']); $user['referal_money'] = WM_Currency::format($user['referal_money']); $comision = $percentsClass->getPercentRow($user['user_id']); $user['commission'] = round($comision['percent']); $user['sum'] = Model_Balance::getTotalUserBalanceByType($user['user_id']); $user['web_profit'] = WM_Currency::format($user['web_profit']); $user['web_profit2'] = WM_Currency::format($user['web_profit2']); $user['has_referral_sum'] = $user['referral_sum']; $user['referral_sum'] = WM_Currency::format($user['referral_sum']); $user['edit_href'] = $request->getModule() . '/users/edite/?id=' . $user['user_id']; $user['balance_href'] = $request->getModule() . '/users/balance/?id=' . $user['user_id']; $this->view->topAuthors[] = $user; } } #LOAD WITHDRAW $this->view->withdraw = array(); $this->view->withdraw['no'] = Model_Deposit::getWithdrawCount(" `paid` = 'false' AND `datetime` > '" . date('Y-m') . "-01 00:00:00' "); if ($this->view->withdraw['no']) { $this->view->withdraw['no']['total_f'] = WM_Currency::format($this->view->withdraw['no']['total']); } $this->view->withdraw['paid'] = Model_Deposit::getWithdrawCount(" `paid` = 'true' AND `paid_datetime` > '" . date('Y-m') . "-01 00:00:00' "); if ($this->view->withdraw['paid']) { $this->view->withdraw['paid']['total_f'] = WM_Currency::format($this->view->withdraw['paid']['total']); } #LOAD THEMES $this->view->items = Model_Items::getItems(array('filter_status' => 'queue', 'start' => 0, 'limit' => 5)); $this->view->updated_items = Model_Items::getItems(array('filter_update' => true, 'start' => 0, 'limit' => 5)); #LOAD LAST REQUEST $this->view->contacts = array(); $contacts = Model_Contacts::getContacts(array('filter_answer_datetime' => '0000-00-00', 'start' => 0, 'limit' => 5)); if ($contacts) { foreach ($contacts as $contact) { $data = new JO_Date($contact['datetime'], 'dd MM yy'); $contact['datetime'] = $data->toString(); $contact['has_response'] = $contact['answer_datetime'] != '0000-00-00 00:00:00'; if ($contact['answer_datetime'] != '0000-00-00 00:00:00') { $data = new JO_Date($contact['answer_datetime'], 'dd MM yy'); $contact['answer_datetime'] = $data->toString(); } else { $contact['answer_datetime'] = ''; } $this->view->contacts[] = $contact; } } #Withdrawals $this->view->withdraws = array(); $withdraws = Model_Users::getWithdraws(array('start' => 0, 'limit' => 5)); if ($withdraws) { foreach ($withdraws as $withdraw) { $withdraw['earning'] = WM_Currency::format($withdraw['earning']); $date = new JO_Date($withdraw['datetime'], 'dd MM yy'); $withdraw['datetime'] = $date->toString(); if ($withdraw['paid'] == 'true') { $date = new JO_Date($withdraw['paid_datetime'], 'dd MM yy'); $withdraw['paid_datetime'] = $date->toString(); } else { $withdraw['paid_datetime'] = ''; } $withdraw['amount'] = WM_Currency::format($withdraw['amount']); $this->view->withdraws[] = $withdraw; } } #TAGS NO ACTIVE $this->view->tags = Model_Tags::getTags(array('filter_visible' => 'false', 'start' => 0, 'limit' => 20)); #DRAW GRAPHCS $referal_sum = Model_Orders::getSalesStatusByDay(" AND `datetime` > '" . date('Y-m') . "-01 00:00:00' ", 'referal'); $sales_sum = Model_Orders::getSalesStatusByDay(" AND `datetime` > '" . date('Y-m') . "-01 00:00:00' "); $referal_money = array(); $sales_money = array(); $user_money = array(); $win_money = array(); $sales_num = array(); $referal_num = array(); $days = array(); // for($i=1; $i<= date('t'); $i++) { // if(isset($referal_sum[date("Y-m-") . sprintf('%02d', $i)])) { // $referal_money[] = number_format($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'], 2, '.', ''); // } else { // $referal_money[] = 0; // } // if(isset($sales_sum[date("Y-m-") . sprintf('%02d', $i)])) { // $sales_money[] = number_format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total'], 2, '.', ''); // $user_money[] = number_format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'], 2, '.', ''); // if(isset($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'])) { // $sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'] = $referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']; // } // if(!isset($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'])) { // $sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'] = 0; // } // $sales_num[] = $sales_sum[date("Y-m-") . sprintf('%02d', $i)]['num']; // $win_money[] = number_format( floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total']) - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']) - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal']), 2, '.', ''); // } else { // $sales_money[] = 0; // $user_money[] = 0; // $win_money[] = 0; // $sales_num[] = 0; // } // $days[] = $i; // } for ($i = 1; $i <= date('t'); $i++) { if (isset($referal_sum[date("Y-m-") . sprintf('%02d', $i)])) { $referal_money[] = array(WM_Currency::format($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']), (double) WM_Currency::format($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'], '', '', false)); } else { $referal_money[] = array(WM_Currency::format(0), 0); } if (isset($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['num'])) { $referal_num[] = array($i, $referal_sum[date("Y-m-") . sprintf('%02d', $i)]['num']); } else { $referal_num[] = array($i, 0); } if (isset($sales_sum[date("Y-m-") . sprintf('%02d', $i)])) { $sales_money[] = array(WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total']), (double) WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total'], '', '', false)); $user_money[] = array(WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']), (double) WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'], '', '', false)); if (isset($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'])) { $sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'] = $referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']; } if (!isset($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'])) { $sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'] = 0; } $sales_num[] = array($i, $sales_sum[date("Y-m-") . sprintf('%02d', $i)]['num']); $win_money[] = array(WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total'] - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']) - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'])), (double) WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total'] - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']) - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal']), '', '', false)); } else { $sales_money[] = array(WM_Currency::format(0), 0); $user_money[] = array(WM_Currency::format(0), 0); $win_money[] = array(WM_Currency::format(0), 0); $sales_num[] = array($i, 0); } $days[] = $i; } $new_array = array(); $new_array[] = array('name' => $this->translate('Total'), 'data' => $sales_money); $new_array[] = array('name' => $this->translate('User\'s profit'), 'data' => $user_money); $new_array[] = array('name' => $this->translate('Net total'), 'data' => $win_money); $new_array[] = array('name' => $this->translate('Referent'), 'data' => $referal_money); $new_array2 = array(); $new_array2[] = array('name' => $this->translate('Referent'), 'data' => $referal_num); $new_array2[] = array('name' => $this->translate('Sales'), 'data' => $sales_num); $this->view->finance_array = JO_Json::encode($new_array); $this->view->sales_array = JO_Json::encode($new_array2); $this->view->days = JO_Json::encode($days); $this->view->currency = WM_Currency::getCurrency(); }