public function createAction() { $this->view->disable(); $status = "OK"; $params = json_decode(file_get_contents('php://input')); $model = Accounts::findFirst("name='{$params->name}'"); if ($model == null) { $model = new Accounts(); $model->group = $params->group; $model->name = $params->name; $model->email = $params->email; $model->pm = $params->pm; $model->save(); } echo json_encode(array("status" => $status)); }
/** * Common function for gathering stats * * @param string $input_role - user role * @param string $selspec - identificator for various types of seller stats (marketplaces, lang) */ private function stats($input_role = null, $selspec = null) { // If there is no role specified this is a regular type of stats (phorocoder, translators, moderators...) $user_roles = $input_role == null ? $this->user_roles : $input_role; $months = $this->months; $days_ru = $this->days_ru; $month_and_year = date('m.Y', time()); // Current month and year // Change month and year to ones selected by user if ($this->request->isPost() && !empty($this->request->getPost('month_and_year', 'string'))) { $month_and_year = $this->request->getPost('month_and_year', 'string'); } $first_day_of_month = strtotime("01.{$month_and_year}"); $first_day_of_next_month = strtotime("01.{$month_and_year} + 1 month"); $num_of_days = (int) (($first_day_of_next_month - $first_day_of_month) / 86400); // Number of days in the month // Array of days in the selected month in unix timestamp for ($i = 1; $i <= $num_of_days; $i++) { $days[] = strtotime("{$i}.{$month_and_year}"); } $days[] = $first_day_of_next_month; // Find stats for a month // photocoder, copywriter/moder, translator/moder if ($input_role == null) { $tasks = new PTasks(); // @todo remove + 7200 !!!!!!!!!!!!!!!! set db server to correct time $sql = "SELECT COUNT(t1.id) AS count, FROM_UNIXTIME(t1.tstart + 7200, '%Y-%m-%d') AS cdate, t1.tstart, t1.trole, t1.tlang, t1.tassignee, t1.tprodid\n FROM p_tasks AS t1\n WHERE t1.tstart BETWEEN {$first_day_of_month} AND {$first_day_of_next_month} AND (t1.tstatus = 3 OR t1.tstatus = 5)\n GROUP BY t1.trole, t1.tlang, t1.tassignee, t1.tprodid, cdate\n ORDER BY t1.tassignee DESC;"; $stats = new Resultset(null, $tasks, $tasks->getReadConnection()->query($sql)); $stats = $stats->toArray(); // seller } elseif ($input_role == 'seller') { $field = "user_id"; if ($selspec == 'mplace') { $field = "marketplace_id"; } // Marketplaces stats if ($selspec == 'lang') { $field = "langcode"; } // Langs stats $tasks = new MPlacement(); $sql = "SELECT COUNT(mp.id) AS count, FROM_UNIXTIME(mp.created + 7200, '%Y-%m-%d') AS cdate, mp.created, mp.user_id, mp.marketplace_id, mp.langcode\n FROM mplacement AS mp\n WHERE mp.created BETWEEN {$first_day_of_month} AND {$first_day_of_next_month}\n GROUP BY mp.{$field}, cdate\n ORDER BY mp.{$field}, cdate"; $stats = new Resultset(null, $tasks, $tasks->getReadConnection()->query($sql)); $stats = $stats->toArray(); } // Find regular sellers and APIs if ($input_role == 'seller' && $selspec == null) { $all_sellers = Accounts::getUsersByRole('seller', false, 'name'); $this->view->regular_sellers = $regular_sellers = preg_grep('/^(?!API)/', $all_sellers); $this->view->api_sellers = $api_sellers = preg_grep('/^API/', $all_sellers); } // All marketplaces if ($input_role == 'seller' && $selspec == 'mplace') { $all_marketplaces = array_column(Marketplace::find(['columns' => 'title, id', 'order' => 'title'])->toArray(), 'title', 'id'); } // All langs if ($input_role == 'seller' && $selspec == 'lang') { $all_langs = array_column(PLangs::find(['columns' => 'alias', 'order' => 'id'])->toArray(), 'alias', 'alias'); } $roles = []; $assignee = []; foreach ($stats as $stat) { // Regular stats if ($input_role == null) { $roles[$stat['trole']][$stat['tlang']][$stat['tassignee']][] = $stat['tstart']; // Seller stats } elseif ($input_role == 'seller' && $selspec == null) { $seller_stats[$stat['user_id']][$stat['cdate']] = (int) $stat['count']; // Seller marketplaces stats } elseif ($input_role == 'seller' && $selspec == 'mplace') { $seller_stats[$stat['marketplace_id']][$stat['cdate']] = (int) $stat['count']; // Seller langs stats } elseif ($input_role == 'seller' && $selspec == 'lang') { $seller_stats[$stat['langcode']][$stat['cdate']] = (int) $stat['count']; } // Link user_id to his name if it's not already linked // Regular stats if ($input_role == null) { if (empty($assignee[$stat['tassignee']])) { if ($acc_name = Accounts::findFirst($stat['tassignee'])) { $assignee[$stat['tassignee']] = $acc_name->name; } } // Seller stats } elseif ($input_role == 'seller' && $selspec == null) { if (empty($assignee[$stat['user_id']])) { foreach ($all_sellers as $seller_id => $seller_name) { if ($stat['user_id'] == $seller_id) { $assignee[$stat['user_id']] = $seller_name; } } } // Seller marketplaces stats } elseif ($input_role == 'seller' && $selspec == 'mplace') { if (empty($assignee[$stat['marketplace_id']])) { foreach ($all_marketplaces as $marketplace_id => $marketplace_name) { if ($stat['marketplace_id'] == $marketplace_id) { $assignee[$stat['marketplace_id']] = $marketplace_name; } } } // Seller langs stats } elseif ($input_role == 'seller' && $selspec == 'lang') { if (empty($assignee[$stat['langcode']])) { foreach ($all_langs as $k => $v) { if ($stat['langcode'] == $v) { $assignee[$stat['langcode']] = $v; } } } } } $day_count = []; $time_array = []; // Regular stats (photocoder, copywriter/moder, translator/moder) if ($input_role == null) { // Array of roles/langs/users/days/tasks foreach ($roles as $role => $langs) { foreach ($langs as $lang => $data) { foreach ($data as $user => $times) { $day_index = 0; foreach ($days as $day) { foreach ($times as $time) { // If task time is between the selected day and the next day if ($time >= $day && $time < $days[$day_index + 1]) { $time_array[$role][$lang][$user][$day][] = $time; } } $day_index++; // Number of user's tasks for a day $day_count[$role][$lang][$user][$day] = !empty($time_array[$role][$lang][$user][$day]) ? count($time_array[$role][$lang][$user][$day]) : null; } } } } // Stats for sellers } elseif ($input_role == 'seller' && $selspec == null) { // Array of users/days/count foreach ($seller_stats as $seller => $seller_info) { foreach ($seller_info as $seller_day => $seller_count) { $day_index = 0; foreach ($days as $day) { $unixts = strtotime($seller_day); if ($unixts == $day) { if (isset($regular_sellers[$seller])) { $time_array['seller'][$seller][$day] = $seller_count; } if (isset($api_sellers[$seller])) { $time_array['api'][$seller][$day] = $seller_count; } } $day_index++; // Number of user's tasks for a day $day_count['seller'][$seller][$day] = !empty($time_array['seller'][$seller][$day]) ? $time_array['seller'][$seller][$day] : null; $day_count['api'][$seller][$day] = !empty($time_array['api'][$seller][$day]) ? $time_array['api'][$seller][$day] : null; } } } // Stats for marketplaces } elseif ($input_role == 'seller' && $selspec == 'mplace') { // Array of marketplaces/days/count foreach ($seller_stats as $seller => $seller_info) { foreach ($seller_info as $seller_day => $seller_count) { $day_index = 0; foreach ($days as $day) { $unixts = strtotime($seller_day); if ($unixts == $day) { $time_array['seller'][$seller][$day] = $seller_count; } $day_index++; // Number of user's tasks for a day $day_count['seller'][$seller][$day] = !empty($time_array['seller'][$seller][$day]) ? $time_array['seller'][$seller][$day] : null; } } } // Stats for seller langs } elseif ($input_role == 'seller' && $selspec == 'lang') { // Array of langs/days/count foreach ($seller_stats as $seller => $seller_info) { foreach ($seller_info as $seller_day => $seller_count) { $day_index = 0; foreach ($days as $day) { $unixts = strtotime($seller_day); if ($unixts == $day) { $time_array['seller'][$seller][$day] = $seller_count; } $day_index++; // Number of user's tasks for a day $day_count['seller'][$seller][$day] = !empty($time_array['seller'][$seller][$day]) ? $time_array['seller'][$seller][$day] : null; } } } } // ------------------------------------------- // Regular stats if ($input_role == null) { $done['photocoder'] = PProductMain::count("hasphoto = 1 AND status >= 3"); $done['copywriter'] = PProdInfo::count("coder_status >= 3 AND lang = 'ru'"); $done['moderatorCopywriting'] = PProdInfo::count("coder_status = 5 AND lang = 'ru'"); $done['translator'] = PProdInfo::count(["coder_status >= 3", 'group' => 'lang', 'order' => 'id']); $done['moderatorTranslating'] = PProdInfo::count(["coder_status = 5", 'group' => 'lang', 'order' => 'id']); $todo['photocoder'] = PProductMain::count("hasphoto = 1 AND status < 3 OR status IS NULL AND hold = 0"); $todo['copywriter'] = $done['photocoder'] - $done['copywriter']; $todo['moderatorCopywriting'] = PProdInfo::count("coder_status = 3 AND lang = 'ru'"); $todo['translator'] = $done['translator']; $todo['moderatorTranslating'] = PProdInfo::count(["coder_status = 3", 'group' => 'lang', 'order' => 'id']); $langs = PProdInfo::count(['group' => 'lang', 'order' => 'id']); foreach ($langs as $lang) { $all_langs[] = $lang->lang; } $this->view->total = PProdInfo::count("coder_status = 5 AND lang = 'ru'"); $this->view->done = $done; $this->view->todo = $todo; $this->view->all_langs = $all_langs; } $this->view->day_count = $day_count; $this->view->days = $days; $this->view->user_roles = $user_roles; $this->view->assignee = $assignee; $this->view->month = $months[substr($month_and_year, 0, 2)]; $this->view->month_and_year = $month_and_year; $this->view->year = substr($month_and_year, 3); $this->view->days_ru = $days_ru; $this->view->total_num_of_placements = MPlacement::count(); }
/** * Get a list of users in a group chat */ public function getChatUsersAction() { $this->ajaxCheck(); $chat_id = $this->request->get('chat_id'); $users = []; foreach (SChats::find(["chat_id={$chat_id}", 'columns' => 'user_id']) as $chat) { $account = Accounts::findFirst(["id={$chat->user_id}", 'columns' => 'id, name']); $users[] = ['id' => $account->id, 'name' => $account->name, 'status' => SOnlineStatus::findFirst($account->id) ? 1 : 0]; } echo json_encode($users); }
public function createInvestAction() { $this->view->disable(); $status = "NG"; $params = json_decode(file_get_contents('php://input')); $model = new SiteInvests(); $model->site_id = $params->site_id; $model->monitor = $params->monitor; $model->acc_name = $params->acc_name; $model->amount = $params->amount; $model->ip = $params->ip; $model->time = $params->time; $model->status = "Invest"; if ($model->save()) { $account = Accounts::findFirst("name='{$params->acc_name}'"); $account->amount -= $params->amount; $account->save(); $status = "OK"; } echo json_encode(array("status" => $status)); }