Commit 3c014fd3d2414f20b7fe8ae412400b225802e91a
1 parent
13b3d93a
delete from DB after complete order + task cli
Showing
4 changed files
with
235 additions
and
1 deletions
Show diff stats
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Alex Savenko | ||
5 | + * Date: 09.12.2016 | ||
6 | + * Time: 13:54 | ||
7 | + */ | ||
8 | + | ||
9 | + | ||
10 | +use Phalcon\DI\FactoryDefault\CLI as CliDI; | ||
11 | +use Phalcon\Cli\Console as ConsoleApp; | ||
12 | +use Phalcon\Loader; | ||
13 | + | ||
14 | + | ||
15 | + | ||
16 | +define( 'PATH_SRC', realpath(__DIR__.'/../').'/' ); | ||
17 | +define( 'ROOT_PATH', realpath(__DIR__.'/../').'/' ); | ||
18 | +define( 'SERVER_NAME', 'semena' ); | ||
19 | + | ||
20 | +$config = require PATH_SRC.'lib/config.php'; | ||
21 | +config::setApp( 'tasks' ); | ||
22 | + | ||
23 | + | ||
24 | + | ||
25 | +/** | ||
26 | + * Регистрируем автозагрузчик, и скажем ему, чтобы зарегистрировал каталог задач | ||
27 | + */ | ||
28 | +$loader = new Loader(); | ||
29 | + | ||
30 | +$loader->registerDirs( | ||
31 | + [ | ||
32 | + PATH_SRC.config::get( 'dirs/controllersDir' ), | ||
33 | + PATH_SRC.config::get( 'dirs/librariesDir' ), | ||
34 | + PATH_SRC.config::get( 'dirs/modelsDir' ), | ||
35 | + ] | ||
36 | +); | ||
37 | + | ||
38 | +$loader->registerNamespaces( | ||
39 | + [ | ||
40 | + 'controllers' => ROOT_PATH.config::get( 'dirs/controllersDir' ), | ||
41 | + 'lib' => ROOT_PATH.config::get( 'dirs/librariesDir' ), | ||
42 | + 'models' => ROOT_PATH.config::get( 'dirs/modelsDir' ), | ||
43 | + ] | ||
44 | +); | ||
45 | + | ||
46 | +$loader->register(); | ||
47 | + | ||
48 | +///////////////////////////////////////////////////////////// | ||
49 | + | ||
50 | + | ||
51 | + | ||
52 | +// Используем стандартный для CLI контейнер зависимостей | ||
53 | +$di = new CliDI(); | ||
54 | + | ||
55 | +$di->set("config", $config); | ||
56 | + | ||
57 | +$di->set( 'cache', function() | ||
58 | +{ | ||
59 | + $cache = new \Phalcon\Cache\Frontend\Data([ | ||
60 | + 'lifetime' => 60, | ||
61 | + ]); | ||
62 | + | ||
63 | + return new \Phalcon\Cache\Backend\Memcache( | ||
64 | + $cache, | ||
65 | + [ | ||
66 | + 'host' => '127.0.0.1', | ||
67 | + 'port' => 11211, | ||
68 | + ] | ||
69 | + ); | ||
70 | +}, true ); | ||
71 | + | ||
72 | +$di->set( 'database', function() | ||
73 | +{ | ||
74 | + $config = | ||
75 | + [ | ||
76 | + 'host' => config::get('global#database/server'), | ||
77 | + 'username' => config::get('global#database/user'), | ||
78 | + 'password' => config::get('global#database/passwd'), | ||
79 | + 'dbname' => config::get('global#database/db'), | ||
80 | + 'schema' => 'public', | ||
81 | + ]; | ||
82 | + | ||
83 | + $database = new \Phalcon\Db\Adapter\Pdo\Postgresql( $config ); | ||
84 | + | ||
85 | + return $database; | ||
86 | + | ||
87 | +}, true ); | ||
88 | + | ||
89 | +$di->set( 'db', function() | ||
90 | +{ | ||
91 | + return new \db(); | ||
92 | +}, true ); | ||
93 | + | ||
94 | +$di->set( 'common', function() | ||
95 | +{ | ||
96 | + return new \common(); | ||
97 | +}, true ); | ||
98 | + | ||
99 | +$di->set('modelsManager', function() { | ||
100 | + return new \Phalcon\Mvc\Model\Manager(); | ||
101 | +}); | ||
102 | + | ||
103 | +$di->set( 'models', function() | ||
104 | +{ | ||
105 | + return new \models(); | ||
106 | +}, true ); | ||
107 | + | ||
108 | +$di->set( 'sendmail', function() | ||
109 | +{ | ||
110 | + return new \sendmail(); | ||
111 | +}, true ); | ||
112 | + | ||
113 | +///////////////////////////////////////////////////////////// | ||
114 | + | ||
115 | + | ||
116 | +// Создаем консольное приложение | ||
117 | +$console = new ConsoleApp(); | ||
118 | + | ||
119 | +$console->setDI($di); | ||
120 | + | ||
121 | +///////////////////////////////////////////////////////////// | ||
122 | + | ||
123 | +/** | ||
124 | + * Определяем консольные аргументы | ||
125 | + */ | ||
126 | +$arguments = []; | ||
127 | + | ||
128 | +foreach ($argv as $k => $arg) { | ||
129 | + if ($k === 1) { | ||
130 | + $arguments["task"] = $arg; | ||
131 | + } elseif ($k === 2) { | ||
132 | + $arguments["action"] = $arg; | ||
133 | + } elseif ($k >= 3) { | ||
134 | + $arguments["params"][] = $arg; | ||
135 | + } | ||
136 | +} | ||
137 | + | ||
138 | + | ||
139 | + | ||
140 | +try { | ||
141 | + $console->handle($arguments); | ||
142 | +} catch (\Phalcon\Exception $e) { | ||
143 | + echo $e->getMessage(); | ||
144 | + | ||
145 | + exit(255); | ||
146 | +} | ||
0 | \ No newline at end of file | 147 | \ No newline at end of file |
src/app/frontend/controllers/MenuController.php
@@ -36,6 +36,7 @@ class MenuController extends \controllers\ControllerBase | @@ -36,6 +36,7 @@ class MenuController extends \controllers\ControllerBase | ||
36 | $cities[strval($c->CityID)] = strval($c->Description); | 36 | $cities[strval($c->CityID)] = strval($c->Description); |
37 | } | 37 | } |
38 | 38 | ||
39 | + // применение скидок, промокода | ||
39 | if ( !empty( $in_cart ) ) | 40 | if ( !empty( $in_cart ) ) |
40 | { | 41 | { |
41 | $cart = $this->common->getCartItems($in_cart, $this->lang_id); | 42 | $cart = $this->common->getCartItems($in_cart, $this->lang_id); |
@@ -63,6 +64,7 @@ class MenuController extends \controllers\ControllerBase | @@ -63,6 +64,7 @@ class MenuController extends \controllers\ControllerBase | ||
63 | $items_ = $cart['items_']; | 64 | $items_ = $cart['items_']; |
64 | } | 65 | } |
65 | 66 | ||
67 | + //оформление заказа | ||
66 | if ( $this->request->isPost() ) | 68 | if ( $this->request->isPost() ) |
67 | { | 69 | { |
68 | $order['email'] = $this->request->getPost('login_email', 'string', NULL ); | 70 | $order['email'] = $this->request->getPost('login_email', 'string', NULL ); |
@@ -204,12 +206,17 @@ class MenuController extends \controllers\ControllerBase | @@ -204,12 +206,17 @@ class MenuController extends \controllers\ControllerBase | ||
204 | $sms_text = "Vash zakaz prinyat. #:".$proposal_number['proposal_number']." V blijayshee vremya menedjer svyajetsya s Vami (044) 581-67-15"; | 206 | $sms_text = "Vash zakaz prinyat. #:".$proposal_number['proposal_number']." V blijayshee vremya menedjer svyajetsya s Vami (044) 581-67-15"; |
205 | $this->sms->sendSMS($order['phone'], $sms_text); | 207 | $this->sms->sendSMS($order['phone'], $sms_text); |
206 | 208 | ||
209 | + //чистим корзину в бд | ||
210 | + if ($this->session->get('isAuth')) { | ||
211 | + $user_id = $this->session->get('id'); | ||
212 | + $this->models->getBasket()->deleteBasket($user_id); | ||
213 | + } | ||
214 | + | ||
207 | // novaposhta | 215 | // novaposhta |
208 | if (!empty($proposal_number['novaposhta_tnn'])) | 216 | if (!empty($proposal_number['novaposhta_tnn'])) |
209 | { | 217 | { |
210 | $order['novaposhta_tnn'] = $proposal_number['novaposhta_tnn']; | 218 | $order['novaposhta_tnn'] = $proposal_number['novaposhta_tnn']; |
211 | } | 219 | } |
212 | - | ||
213 | 220 | ||
214 | if( !empty( $order['email'] ) ) | 221 | if( !empty( $order['email'] ) ) |
215 | { | 222 | { |
1 | +<?php | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by PhpStorm. | ||
5 | + * User: Alex Savenko | ||
6 | + * Date: 09.12.2016 | ||
7 | + * Time: 13:34 | ||
8 | + */ | ||
9 | + | ||
10 | +/** | ||
11 | + * Class BasketTask | ||
12 | + * @property \models $models | ||
13 | + * | ||
14 | + */ | ||
15 | +class BasketTask extends \Phalcon\CLI\Task | ||
16 | +{ | ||
17 | + public static $from = 'Semena subscription <semenainua@gmail.com>'; | ||
18 | + | ||
19 | + public function mainAction(){ | ||
20 | + echo '***main action***'.PHP_EOL; | ||
21 | + echo '@var static $from = '.self::$from.PHP_EOL; | ||
22 | + } | ||
23 | + | ||
24 | + public function sendAction(){ | ||
25 | + | ||
26 | + $subscribers = $this->models->getSubscribe()->getAllData(); | ||
27 | + | ||
28 | + foreach ($subscribers as $subscriber) { | ||
29 | + $id = $subscriber['id']; | ||
30 | + $name = $subscriber['name']; | ||
31 | + $email = $subscriber['email']; | ||
32 | + $date = strtotime($subscriber['date']); | ||
33 | + $greeting_status = $subscriber['greeting']; | ||
34 | + | ||
35 | + $two_days_before = time() - (3600*24*2); | ||
36 | + | ||
37 | + $header = | ||
38 | + 'From: '.self::$from."\n". | ||
39 | + 'Reply-To: '.self::$reply_to."\n". | ||
40 | + 'Return-Path: '.self::$reply_to."\n". | ||
41 | + 'MIME-Version: 1.0'."\n". | ||
42 | + 'Content-type: text/html; charset=UTF-8'."\n". | ||
43 | + 'Content-Transfer-Encoding: 8bit'."\n". | ||
44 | + 'X-Mailer: PHP/' . phpversion(); | ||
45 | + $msg['staus'] = '0'; | ||
46 | + $msg['text'] = ''; | ||
47 | + | ||
48 | + } | ||
49 | + } | ||
50 | + | ||
51 | +} | ||
0 | \ No newline at end of file | 52 | \ No newline at end of file |
src/lib/models/basket.php
@@ -73,6 +73,26 @@ class basket extends \db | @@ -73,6 +73,26 @@ class basket extends \db | ||
73 | 73 | ||
74 | } | 74 | } |
75 | 75 | ||
76 | + /** | ||
77 | + * @param int $user_id | ||
78 | + * @return bool | ||
79 | + */ | ||
80 | + public function deleteUser($user_id) { | ||
81 | + | ||
82 | + return $this->exec( | ||
83 | + ' | ||
84 | + DELETE | ||
85 | + FROM | ||
86 | + public.basket | ||
87 | + WHERE | ||
88 | + user_id = :user_id | ||
89 | + ', | ||
90 | + [ | ||
91 | + 'user_id' => $user_id | ||
92 | + ] | ||
93 | + ); | ||
94 | + | ||
95 | + } | ||
76 | 96 | ||
77 | /** | 97 | /** |
78 | * @param int $user_id | 98 | * @param int $user_id |
@@ -282,4 +302,14 @@ class basket extends \db | @@ -282,4 +302,14 @@ class basket extends \db | ||
282 | 302 | ||
283 | } | 303 | } |
284 | 304 | ||
305 | + /** | ||
306 | + * @param $user_id | ||
307 | + */ | ||
308 | + public function deleteBasket($user_id) { | ||
309 | + | ||
310 | + $this->deleteUser($user_id); | ||
311 | + $this->deleteAllItems($user_id); | ||
312 | + | ||
313 | + } | ||
314 | + | ||
285 | } | 315 | } |
286 | \ No newline at end of file | 316 | \ No newline at end of file |