Commit 31e089d6cf18be4c62f8467b474bf05281cbe649
1 parent
28a7aba8
status
Showing
2 changed files
with
60 additions
and
7 deletions
Show diff stats
src/app/backend/controllers/DiscountController.php
@@ -116,6 +116,7 @@ class DiscountController extends Controller | @@ -116,6 +116,7 @@ class DiscountController extends Controller | ||
116 | return $this->response->redirect([ 'for' => 'admin_login' ]); | 116 | return $this->response->redirect([ 'for' => 'admin_login' ]); |
117 | 117 | ||
118 | } | 118 | } |
119 | + | ||
119 | $this->models->getDiscount()->deleteData($id); | 120 | $this->models->getDiscount()->deleteData($id); |
120 | 121 | ||
121 | return $this->response->redirect([ 'for' => 'discount_index' ]); | 122 | return $this->response->redirect([ 'for' => 'discount_index' ]); |
@@ -210,4 +211,29 @@ class DiscountController extends Controller | @@ -210,4 +211,29 @@ class DiscountController extends Controller | ||
210 | ]); | 211 | ]); |
211 | 212 | ||
212 | } | 213 | } |
214 | + | ||
215 | + public function switchAction($id) { | ||
216 | + | ||
217 | + if( !$this->session->get('isAdminAuth') ) { | ||
218 | + | ||
219 | + return $this->response->redirect([ 'for' => 'admin_login' ]); | ||
220 | + | ||
221 | + } | ||
222 | + | ||
223 | + $status = $this->models->getDiscount()->getStatus($id); | ||
224 | + | ||
225 | + if ($status == 1) { | ||
226 | + | ||
227 | + $this->models->getDiscount()->updateData(['status' => 0], $id); | ||
228 | + | ||
229 | + } | ||
230 | + elseif ($status == 0) { | ||
231 | + | ||
232 | + $this->models->getDiscount()->updateData(['status' => 1], $id); | ||
233 | + | ||
234 | + } | ||
235 | + | ||
236 | + return $this->response->redirect([ 'for' => 'discount_index' ]); | ||
237 | + | ||
238 | + } | ||
213 | } | 239 | } |
214 | \ No newline at end of file | 240 | \ No newline at end of file |
src/lib/models/discount.php
@@ -33,7 +33,7 @@ class discount extends \db | @@ -33,7 +33,7 @@ class discount extends \db | ||
33 | 33 | ||
34 | 34 | ||
35 | /** | 35 | /** |
36 | - * Get discount with `id`=$id | 36 | + * Get discount |
37 | * @param $id | 37 | * @param $id |
38 | * @return array | 38 | * @return array |
39 | */ | 39 | */ |
@@ -53,6 +53,28 @@ class discount extends \db | @@ -53,6 +53,28 @@ class discount extends \db | ||
53 | ); | 53 | ); |
54 | } | 54 | } |
55 | 55 | ||
56 | + /** | ||
57 | + * Get discount indication status | ||
58 | + * @param $id | ||
59 | + * @return array | ||
60 | + */ | ||
61 | + public function getStatus($id) { | ||
62 | + | ||
63 | + return $this->get( | ||
64 | + ' | ||
65 | + SELECT status | ||
66 | + FROM public.discount | ||
67 | + WHERE | ||
68 | + id = :id | ||
69 | + ', | ||
70 | + [ | ||
71 | + 'id' => $id | ||
72 | + ], | ||
73 | + -1 | ||
74 | + ); | ||
75 | + | ||
76 | + } | ||
77 | + | ||
56 | 78 | ||
57 | /** | 79 | /** |
58 | * Get actual discount | 80 | * Get actual discount |
@@ -79,7 +101,7 @@ class discount extends \db | @@ -79,7 +101,7 @@ class discount extends \db | ||
79 | 101 | ||
80 | 102 | ||
81 | /** | 103 | /** |
82 | - * Delete discount with `id`=$id | 104 | + * Delete discount |
83 | * @param $id | 105 | * @param $id |
84 | * @return bool | 106 | * @return bool |
85 | */ | 107 | */ |
@@ -115,7 +137,8 @@ class discount extends \db | @@ -115,7 +137,8 @@ class discount extends \db | ||
115 | discount, | 137 | discount, |
116 | description, | 138 | description, |
117 | start_date, | 139 | start_date, |
118 | - end_date | 140 | + end_date, |
141 | + status | ||
119 | ) | 142 | ) |
120 | VALUES | 143 | VALUES |
121 | ( | 144 | ( |
@@ -123,7 +146,8 @@ class discount extends \db | @@ -123,7 +146,8 @@ class discount extends \db | ||
123 | :discount, | 146 | :discount, |
124 | :description, | 147 | :description, |
125 | :start_date, | 148 | :start_date, |
126 | - :end_date | 149 | + :end_date, |
150 | + :status | ||
127 | ) | 151 | ) |
128 | RETURNING id | 152 | RETURNING id |
129 | ', | 153 | ', |
@@ -132,7 +156,8 @@ class discount extends \db | @@ -132,7 +156,8 @@ class discount extends \db | ||
132 | 'discount' => $data['discount'], | 156 | 'discount' => $data['discount'], |
133 | 'description' => $data['description'], | 157 | 'description' => $data['description'], |
134 | 'start_date' => $data['start_date'], | 158 | 'start_date' => $data['start_date'], |
135 | - 'end_date' => $data['end_date'] | 159 | + 'end_date' => $data['end_date'], |
160 | + 'status' => $data['status'] | ||
136 | ], | 161 | ], |
137 | -1 | 162 | -1 |
138 | ); | 163 | ); |
@@ -141,7 +166,7 @@ class discount extends \db | @@ -141,7 +166,7 @@ class discount extends \db | ||
141 | } | 166 | } |
142 | 167 | ||
143 | /** | 168 | /** |
144 | - * Update discount with `id`=$id | 169 | + * Update discount |
145 | * @param $data | 170 | * @param $data |
146 | * @param $id | 171 | * @param $id |
147 | * @return bool | 172 | * @return bool |
@@ -158,7 +183,8 @@ class discount extends \db | @@ -158,7 +183,8 @@ class discount extends \db | ||
158 | discount = :discount, | 183 | discount = :discount, |
159 | description = :description, | 184 | description = :description, |
160 | start_date = :start_date, | 185 | start_date = :start_date, |
161 | - end_date = :end_date | 186 | + end_date = :end_date, |
187 | + status = :status | ||
162 | WHERE | 188 | WHERE |
163 | id = :id | 189 | id = :id |
164 | ', | 190 | ', |
@@ -168,6 +194,7 @@ class discount extends \db | @@ -168,6 +194,7 @@ class discount extends \db | ||
168 | 'description' => $data['description'], | 194 | 'description' => $data['description'], |
169 | 'start_date' => $data['start_date'], | 195 | 'start_date' => $data['start_date'], |
170 | 'end_date' => $data['end_date'], | 196 | 'end_date' => $data['end_date'], |
197 | + 'status' => $data['status'], | ||
171 | 'id' => $id | 198 | 'id' => $id |
172 | ] | 199 | ] |
173 | ); | 200 | ); |