コード例 #1
0
 public function index2Action($maker_id = null)
 {
     if ($maker_id != null) {
         $maker_id = $this->filter->sanitize($maker_id, 'int');
         if ($maker = PMaker::findFirst($maker_id)) {
             $this->view->products = $products = PProductMain::find("maker_id={$maker_id}");
             $this->view->maker = $maker;
             $this->view->count = PProductMain::count("maker_id={$maker_id}");
             if ($this->request->isPost()) {
                 $args = ['main_comment' => ['filter' => FILTER_SANITIZE_STRING], 'title' => ['filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY], 'oldprice' => ['filter' => FILTER_SANITIZE_NUMBER_FLOAT, 'flags' => FILTER_REQUIRE_ARRAY], 'comment' => ['filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY]];
                 $inpData = filter_input_array(INPUT_POST, $args);
                 $main_comment = $inpData['main_comment'];
                 $title = $inpData['title'];
                 $oldprice = $inpData['oldprice'];
                 $comment = $inpData['comment'];
                 $body = "";
                 if (!empty($main_comment)) {
                     $body = "Комментарий: {$main_comment}<br><br>";
                 }
                 $body .= "<table width='100%' border='1' cellpadding='2' cellspacing='1'>";
                 $body .= "<tr><td>ID</td><td>Название</td><td>Старая цена</td><td>Комментарий</td></tr>";
                 foreach ($comment as $product_id => $value) {
                     if (!$value) {
                         continue;
                     }
                     $body .= "<tr>\n                        <td>{$product_id}</td>\n                        <td>{$title[$product_id]}</td>\n                        <td>{$oldprice[$product_id]} {$maker->currencystr}</td>\n                        <td>{$value}</td>\n                      </tr>";
                 }
                 $body .= "</table>";
                 // Compose a message
                 $msg = ['To' => $this->config->emails->usercab2, 'From' => $this->config->POSTMARK->POSTMARK_FROM, 'Subject' => "Комментарии от мастера - {$maker->name}", 'HtmlBody' => "<html><body>{$body}</body></html>"];
                 try {
                     $client = new PostmarkClient($this->config->POSTMARK->POSTMARK_API);
                     $send = $client->sendEmailBatch([$msg]);
                     $this->flash->success('Сохранено!');
                 } catch (PostmarkException $ex) {
                     if ($ex) {
                         $this->flash->error('Произошла ошибка!');
                     }
                 }
             }
         } else {
             $this->flash->error('Мастер с таким ID не найден!');
             $this->response->redirect('usercab/index2');
         }
     }
 }
コード例 #2
0
 public function productsAction()
 {
     $request = $this->request;
     $persistent = $this->persistent;
     // Reset
     $reset = $this->request->getQuery('reset', 'int');
     if (isset($reset)) {
         $persistent->productsParams = null;
     }
     // Persistent parameters
     if (!is_array($persistent->productsParams)) {
         $persistent->productsParams = ['qry' => ['conditions' => "id IS NOT NULL", 'order' => 'id ASC'], 'sort' => ['page' => 1, 'perpage' => 50]];
     }
     $parameters = $persistent->productsParams;
     $parameters['sort']['perpage'] = 50;
     $parameters['sort']['page'] = 1;
     if ($request->getQuery('page', 'int')) {
         $parameters['sort']['page'] = $request->getQuery('page', 'int');
     }
     if ($request->getQuery('perpage', 'int')) {
         $parameters['sort']['perpage'] = $request->getQuery('perpage', 'int');
     }
     // ----------------------------------------
     // Search
     if ($request->isPost()) {
         $parameters['search_cat'] = null;
         $parameters['search_virtcat'] = null;
         $parameters['search_maker'] = null;
         $parameters['search_material'] = null;
         $parameters['search_hold'] = null;
         $parameters['search_id'] = null;
         // Category
         if (!empty($_POST['search_cat'])) {
             $search_cat_get = $request->getPost('search_cat', 'int');
             $parameters['search_cat'] = $search_cat_get;
             $search_cats = PCategory::getCatTree($search_cat_get);
             $search_cat = " AND category_id IN ({$search_cats})";
         } else {
             $search_cat = null;
         }
         // Virtual category
         if (!empty($_POST['search_virtcat'])) {
             $search_virtcat_get = $request->getPost('search_virtcat', 'int');
             $parameters['search_virtcat'] = $search_virtcat_get;
             $search_virtcat = " AND tmaterial_id = {$search_virtcat_get}";
         } else {
             $search_virtcat = null;
         }
         // Maker
         if (!empty($_POST['search_maker'])) {
             $search_maker_get = $request->getPost('search_maker', 'int');
             $parameters['search_maker'] = $search_maker_get;
             $search_maker = " AND maker_id = {$search_maker_get}";
         } else {
             $search_maker = null;
         }
         // Material
         if (!empty($_POST['search_material'])) {
             $search_material_get = $request->getPost('search_material', 'int');
             $parameters['search_material'] = $search_material_get;
             $search_material = " AND cmaterial_id = {$search_material_get}";
         } else {
             $search_material = null;
         }
         // Hold
         if (!empty($_POST['search_hold'])) {
             $search_hold_get = $request->getPost('search_hold', 'int');
             $parameters['search_hold'] = $search_hold_get;
             $search_hold = $search_hold_get == 1 ? " AND hold = 1" : " AND hold = 0";
         } else {
             $search_hold = null;
         }
         // ID
         if (!empty($_POST['search_id'])) {
             $parameters['search_id'] = $request->getPost('search_id', 'string');
             $search_id_get = preg_split('/[,\\s]/', $request->getPost('search_id', 'string'), null, PREG_SPLIT_NO_EMPTY);
             $search_id = join(', ', $search_id_get);
             $search_id = " AND id IN ({$search_id})";
         } else {
             $search_id = null;
         }
         // Search parameters
         $parameters['qry'] = ['conditions' => "id IS NOT NULL\n                    {$search_cat}\n                    {$search_virtcat}\n                    {$search_maker}\n                    {$search_material}\n                    {$search_hold}\n                    {$search_id}"];
     }
     // Other parameters
     $parameters['query_count'] = PProductMain::count($parameters['qry']);
     $parameters['qry']['order'] = "id ASC";
     $parameters['qry']['limit'] = 10000;
     $persistent->productsParams = $parameters;
     //        var_dump($parameters);
     // Find all placements that correspond to set parameters
     $products = PProductMain::find($parameters['qry']);
     // Paginator
     $paginator = new Paginator(["data" => $products, "limit" => $parameters['sort']['perpage'], "page" => $parameters['sort']['page']]);
     $this->view->page = $paginator->getPaginate();
     // Set selected search values
     $this->view->selected_cat = isset($parameters['search_cat']) && !empty($parameters['search_cat']) ? $parameters['search_cat'] : null;
     $this->view->selected_virtcat = isset($parameters['search_virtcat']) && !empty($parameters['search_virtcat']) ? $parameters['search_virtcat'] : null;
     $this->view->selected_maker = isset($parameters['search_maker']) && !empty($parameters['search_maker']) ? $parameters['search_maker'] : null;
     $this->view->selected_material = isset($parameters['search_material']) && !empty($parameters['search_material']) ? $parameters['search_material'] : null;
     $this->view->selected_hold = isset($parameters['search_hold']) && !empty($parameters['search_hold']) ? $parameters['search_hold'] : null;
     $this->view->selected_id = isset($parameters['search_id']) && !empty($parameters['search_id']) ? $parameters['search_id'] : null;
     // Products count (overall or filtered)
     $this->view->products_count = $parameters['query_count'];
     // All categories
     $this->view->cats_list = PCategory::getCatList();
     // All virtual categories
     $virtcats = PCategoryGroup::find(['order' => 'title ASC']);
     foreach ($virtcats as $virtcat) {
         $virtcats_array[$virtcat->id] = $virtcat->title;
     }
     $this->view->virtcats_list = $virtcats_array;
     // All makers
     //        $makers = PMaker::find(["name IS NOT NULL AND isseller=1 AND approved=1 AND banned=0", 'order' => 'name ASC']);
     $makers = PMaker::find(["name IS NOT NULL AND isseller=1", 'order' => 'name ASC']);
     foreach ($makers as $maker) {
         $makers_array[$maker->id] = $maker->name;
     }
     $this->view->makers_list = $makers_array;
     // All materials
     $materials = PProdMaterial::find(['order' => 'title ASC']);
     foreach ($materials as $material) {
         $materials_array[$material->id] = $material->title;
     }
     $this->view->materials_list = $materials_array;
     // Langs stat
     $langs = PProdInfo::count(["coder_status = 5", 'group' => 'lang', 'order' => 'id']);
     foreach ($langs as $lang) {
         $langs_stat[$lang->lang] = $lang->rowcount;
     }
     $this->view->langs_stat = $langs_stat;
     // Check if user can put products on hold
     $this->view->can_hold = AccRoles::findFirst("user_id={$this->auth->id} AND (role_id=5 OR role_id=1000)");
 }
コード例 #3
0
 public function saveBulkAction()
 {
     $this->view->disable();
     if ($this->request->isAjax()) {
         $status = 1;
         $list_of_ids = $this->request->get('list');
         $input = $this->request->get('input');
         $pernum = $this->request->get('pernum');
         $curr = $this->request->get('curr');
         $list_of_ids = json_decode($list_of_ids, true);
         $curr_rate = PCrosscurrency::findFirst("title='{$curr}'")->currencyrate;
         foreach ($list_of_ids as $id) {
             $products = PProductMain::find("id={$id} OR parent={$id}");
             foreach ($products as $product) {
                 $info = "{$product->oneProductPrice} {$product->holdpriceusd} {$product->priceUSD}";
                 if ($pernum == 'number') {
                     // Maker price in maker currency
                     $new_maker_price = round($product->oneProductPrice + $input);
                     // Maker price USD
                     $new_maker_price_usd = round($new_maker_price / $curr_rate, 2);
                     // Export price USD
                     $new_export_price_usd = $this->modelService->calcProductPrice($new_maker_price_usd);
                 } elseif ($pernum == 'percent') {
                     // Maker price in maker currency
                     $new_maker_price = round($product->oneProductPrice + $product->oneProductPrice / 100 * $input);
                     // Maker price USD
                     $new_maker_price_usd = round($new_maker_price / $curr_rate, 2);
                     // Export price USD
                     $new_export_price_usd = $this->modelService->calcProductPrice($new_maker_price_usd);
                 }
                 // Save new prices
                 $product->oneProductPrice = $new_maker_price;
                 $product->holdpriceusd = $new_maker_price_usd;
                 $product->priceUSD = $new_export_price_usd;
                 if (!$product->save()) {
                     $status = 0;
                 } else {
                     $this->modelService->setStat('price_changed', 'priceMaker', 'ru', $product->id, null, $info);
                     $this->modelService->syncElastic(['product_id' => $product->id]);
                 }
             }
         }
         $status == 1 ? $this->flash->success('Цены успешно изменены!') : $this->flash->error('Произошла ошибка при изменении цен!');
         echo $status;
     }
 }
コード例 #4
-1
ファイル: AdvController.php プロジェクト: serge2300/madeheart
 /**
  * Export selected category in Excel
  *
  * @param $category
  * @param $lang
  * @param $currency
  * @param $location
  */
 public function exportAction($category, $lang, $currency, $location)
 {
     $this->view->disable();
     $cats = PCategory::getCatTree($category, $lang);
     $currency = strtoupper($currency);
     $rate = PCrosscurrency::findFirst("title='{$currency}'")->currencyrate;
     $prods = PProductMain::find(["hold = 0\n            AND notforsale = 0\n            AND category_id IN ({$cats})"]);
     //        var_dump($prods->toArray());
     // Create files directory if it doesn't exist
     if (!file_exists(ROOT . "/public/files")) {
         mkdir(ROOT . "/public/files", 0777);
     }
     $rnd = $currency == 'UAH' || $currency == 'RUB' ? 0 : 2;
     $list = [];
     $list[] = ['ID', 'Название', "Цена, {$currency}", "Доставка, {$currency}", 'URL'];
     $i = 1;
     foreach ($prods as $prod) {
         $list[$i] = [$prod->id, htmlspecialchars_decode($prod->getsingleInfo("lang='{$lang}'")->title), round($prod->priceUSD * $rate, $rnd), $this->unitConvert->deliveryCost($prod, $location) * $rate, "https://madeheart.com/{$lang}/{$prod->id}/" . htmlspecialchars_decode($prod->getsingleInfo("lang='{$lang}'")->url) . ".html"];
         $i++;
     }
     //        var_dump($list);
     $random = rand(111111, 999999);
     $csv_file = "files/csv_{$random}.csv";
     $excel_file = "files/excel_{$random}.xls";
     $csv = fopen($csv_file, 'w');
     foreach ($list as $item) {
         fputcsv($csv, $item);
     }
     fclose($csv);
     $excel = new SimpleExcel('csv');
     $excel->parser->loadFile($csv_file);
     $excel->convertTo('xml');
     $excel->writer->saveFile('file', $excel_file);
     readfile($excel_file);
     header('Content-Disposition: attachment; filename=list.xls');
     unlink($csv_file);
     unlink($excel_file);
 }