· 7 years ago · Dec 05, 2018, 10:22 PM
1<?php
2/*
3* MyUCP
4*/
5
6class ProjectController extends Controller {
7
8 public function view($id) {
9
10 if(empty($this->session->data['user_id']))
11 return view("login");
12
13 model("Project", "User", "Stats", "Log");
14
15 if($project = $this->ProjectModel->getProject($id)){
16 if($project['user_id'] == $this->session->data['user_id']) {
17 $this->data['project'] = $project;
18 } else {
19 return view("errors/404");
20 }
21 } else {
22 return view("errors/404");
23 }
24
25 if($this->request->post['ajax'] == "new_secret") {
26 $secret_key = md5(md5(md5(time().$project['shop_id'])."maksa988"));
27 if($project['user_id'] == $this->session->data['user_id']) {
28 if($this->ProjectModel->set(['shop_secret_key' => $secret_key])->where("shop_id", "=", $id)->update()){
29 $this->LogModel->pushLog("Сгенерирован новый Ñекретный ключ", $this->router->route());
30 $result = ['status' => 'success', 'success' => "Ðовый ключ Ñгенерирован!", "key" => $secret_key];
31 } else {
32 $result = ['status' => 'error', 'error' => "Произошла неизвеÑÑ‚Ð½Ð°Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ°, повторите попытку позже!"];
33 }
34 } else {
35 $result = ['status' => 'error', 'error' => "Произошла неизвеÑÑ‚Ð½Ð°Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ°, повторите попытку позже!"];
36 }
37 $this->LogModel->pushLog("Попытка генерации нового Ñекретного ключа", $this->router->route());
38 return json_encode($result);
39 }
40
41 if($this->request->post['ajax'] == "new_public") {
42 $public_key = md5(md5(md5(time().$project['shop_id'])."maksa988"));
43 $public_key = $public_key{1}.$public_key{2}.$public_key{3}.$public_key{4}.$public_key{5}."-".$project['shop_id'];
44 if($project['user_id'] == $this->session->data['user_id']) {
45 if($this->ProjectModel->set(['shop_public_key' => $public_key])->where("shop_id", "=", $id)->update()){
46 $this->LogModel->pushLog("Сгенерирован новый публичный ключ", $this->router->route());
47 $result = ['status' => 'success', 'success' => "Ðовый ключ Ñгенерирован!", "key" => $public_key];
48 } else {
49 $result = ['status' => 'error', 'error' => "Произошла неизвеÑÑ‚Ð½Ð°Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ°, повторите попытку позже!"];
50 }
51 } else {
52 $result = ['status' => 'error', 'error' => "Произошла неизвеÑÑ‚Ð½Ð°Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ°, повторите попытку позже!"];
53 }
54 $this->LogModel->pushLog("Попытка генерации нового публичного ключа", $this->router->route());
55 return json_encode($result);
56 }
57
58 if($this->request->post['ajax'] == "checkURL") {
59
60 if($this->ProjectModel->checkURL($this->request->post['url'])){
61 $result = ['status' => 'success'];
62 } else {
63 $result = ['status' => 'error'];
64 }
65
66 return json_encode($result);
67 }
68
69 if($this->request->post['ajax'] == "check_request") {
70 $params = [
71 "method" => $this->request->post['method'],
72 "account" => $this->request->post['account'],
73 "sum" => $this->request->post['sum'],
74 "projectId" => $project['shop_id'],
75 "secret_key" => $project['shop_secret_key']
76 ];
77 $answer = $this->ProjectModel->checkURL($project['shop_url'], $params);
78
79 return json_encode($answer);
80 }
81
82 if($this->request->post['generalInfo']) {
83 $shop_name = $this->request->post['shop_name'];
84 $shop_game = $this->request->post['shop_game'];
85 $notif = $this->request->post['notif'];
86 if($project['user_id'] == $this->session->data['user_id']) {
87 if(!empty($shop_name) && !empty($shop_game)) {
88 if($notif == "on") {
89 $notif = 1;
90 } else {
91 $notif = 0;
92 }
93
94 if($this->ProjectModel->set(['shop_name' => $shop_name, 'shop_game' => $shop_game, 'shop_notify' => $notif])->where("shop_id", "=", $id)->update()) {
95 $this->LogModel->pushLog("Изменение оÑновных данных проекта", $this->router->route());
96 $result = ['status' => 'success', 'success' => "Данные уÑпешно Ñохранены!"];
97 } else {
98 $result = ['status' => 'error', 'error' => "Произошла неизвеÑÑ‚Ð½Ð°Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ°, повторите попытку позже!"];
99 }
100 } else {
101 $result = ['status' => 'error', 'error' => "Ð’Ñе Ð¿Ð¾Ð»Ñ Ð¾Ð±Ñзательны к заполнению!"];
102 }
103 } else {
104 $result = ['status' => 'error', 'error' => "Произошла неизвеÑÑ‚Ð½Ð°Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ°, повторите попытку позже!"];
105 }
106 $this->LogModel->pushLog("Попытка Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ Ð¾Ñновных данных проекта", $this->router->route());
107 return json_encode($result);
108 }
109
110 if($this->request->post['otherInfo']) {
111 $shop_url = $this->request->post['shop_url'];
112 $shop_fail_url = $this->request->post['shop_fail_url'];
113 $shop_success_url = $this->request->post['shop_success_url'];
114 if($project['user_id'] == $this->session->data['user_id']) {
115 if(!empty($shop_url) or !empty($shop_fail_url) or !empty($shop_success_url)) {
116 if($this->ProjectModel->set(['shop_url' => $shop_url, 'shop_fail_url' => $shop_fail_url, 'shop_success_url' => $shop_success_url])->where("shop_id", "=", $id)->update()) {
117 $this->LogModel->pushLog("Изменение оÑтальной информации проекта", $this->router->route());
118 $result = ['status' => 'success', 'success' => "Данные уÑпешно Ñохранены!"];
119 } else {
120 $result = ['status' => 'error', 'error' => "Произошла неизвеÑÑ‚Ð½Ð°Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ°, повторите попытку позже!"];
121 }
122 }
123 } else {
124 $result = ['status' => 'error', 'error' => "Произошла неизвеÑÑ‚Ð½Ð°Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ°, повторите попытку позже!"];
125 }
126 $this->LogModel->pushLog("Попытка Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ Ð¾ÑÑтальных данных проекта", $this->router->route());
127 return json_encode($result);
128 }
129
130 if($this->request->post['ajax'] == 'wm_request') {
131
132 $user = $this->UserModel->getUser($this->session->data['user_id']);
133 $wmr_url = "http://passport.webmoney.ru/asp/CertView.asp?purse=".$user['user_wmr'];
134
135 $search_wmid = file_get_contents($wmr_url);
136 $result = explode('" href="https://events.webmoney.ru/user.aspx?', $search_wmid);
137 $wmid = explode('"><img src="/images/events26x26.png" border="0" style="vertical-align:middle;"/></a> <a target="_blank"', $result[1]);
138
139 $wmstatus = explode('<td align="left" valign="top"><img src="../images/bat', $result['2']);
140 $wmcertif = explode('.png" width="57"', $wmstatus[1]);
141
142 if($project['user_id'] == $this->session->data['user_id']) {
143 if($wmcertif[0] == "135" or $wmcertif[0] == "130") {
144 $this->ProjectModel->table("gd_webmoney_requests");
145 $this->ProjectModel->create(['wm_status' => "2", 'user_id' => $this->session->data['user_id'], 'shop_id' => $id, 'wm_certif' => $wmcertif[0], 'wm_wmid' => $wmid[0]]);
146 $this->ProjectModel->table("gd_shops");
147 $this->ProjectModel->set(['shop_webmoney' => 2])->where("shop_id", "=", $id)->update();
148 $this->LogModel->pushLog("УÑпешно ÑÐ¾Ð·Ð´Ð°Ð½Ð½Ð°Ñ Ð·Ð°Ñвка на подключение WM к магазину", $this->router->route());
149 $result = ['status' => 'success', 'success' => "ЗаÑвка в Ð´Ð»Ñ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ Ð¼Ð°Ð³Ð°Ð·Ð¸Ð½Ð° в WM уÑпешно подана.", "type" => "0"];
150 } else {
151 $this->ProjectModel->set(['shop_webmoney' => 4])->where("shop_id", "=", $id)->update();
152 $result = ['status' => 'error', 'error' => "Ðа указанном вами WMR нет перÑонального аттеÑтата!", "type" => "0"];
153 }
154 } else {
155 $result = ['status' => 'error', 'error' => "Произошла неизвеÑÑ‚Ð½Ð°Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ°, повторите попытку позже!"];
156 }
157 $this->LogModel->pushLog("Попытка подачи заÑвки на подключение WM", $this->router->route());
158 return json_encode($result);
159 }
160
161 if($this->request->post['ajax'] == 'paySystem') {
162 if($project['user_id'] == $this->session->data['user_id']) {
163 if($project['shop_status'] == 1) {
164 $systems = ['shop_webmoney', 'shop_yandex', 'shop_qiwi', 'shop_visa', 'shop_master_card', 'shop_robokassa', 'shop_ooopay', 'shop_tinkoff', 'shop_w1', 'shop_payeer', 'shop_okpay', 'shop_zpayment', 'shop_alpha_bank', 'shop_sberbank', 'shop_vtb', 'shop_promsvyazbank', 'shop_rus_standart', 'shop_mts', 'shop_tele2', 'shop_beline', 'shop_terminal_ru', 'shop_terminal_ua', 'shop_mykassa'];
165 $system = $this->request->post['system'];
166 if($system != "webmoney") {
167 if(in_array("shop_".$system, $systems)) {
168 if($project['shop_'.$system]) {
169 $this->ProjectModel->set(['shop_'.$system => 0])->where("shop_id", "=", $id)->update();
170 $result = ['status' => 'success', 'success' => "Метод оплаты отключен!", "type" => "0"];
171 } else {
172 $this->ProjectModel->set(['shop_'.$system => 1])->where("shop_id", "=", $id)->update();
173 $result = ['status' => 'success', 'success' => "Метод оплаты подключен!", "type" => "1"];
174 }
175 $this->LogModel->pushLog("Включен / Отключен метод оплаты", $this->router->route());
176 } else {
177 $result = ['status' => 'error', 'error' => "Произошла неизвеÑÑ‚Ð½Ð°Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ°, повторите попытку позже!"];
178 }
179 } else {
180 $result = ['status' => 'error', 'error' => "Ð”Ð»Ñ Ð¿Ð¾Ð´ÐºÐ»ÑŽÑ‡ÐµÐ½Ð¸Ñ WebMoney обратитеÑÑŒ в поддержку!"];
181 }
182 } else {
183 $result = ['status' => 'error', 'error' => "Проект неодобрен!"];
184 }
185 } else {
186 $result = ['status' => 'error', 'error' => "Произошла неизвеÑÑ‚Ð½Ð°Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ°, повторите попытку позже!"];
187 }
188 $this->LogModel->pushLog("Попытка Ð¾Ñ‚ÐºÐ»ÑŽÑ‡ÐµÐ½Ð¸Ñ / ÐŸÐ¾ÐºÐ´Ð»ÑŽÑ‡ÐµÐ½Ð¸Ñ Ð¼ÐµÑ‚Ð¾Ð´Ð° оплаты", $this->router->route());
189 return json_encode($result);
190 }
191
192 $stats[1] = $this->StatsModel->getShopStatsWeek("1", (int)$id);
193 $stats[2] = $this->StatsModel->getShopStatsWeek("0", (int)$id);
194 $stats[3] = $this->StatsModel->getBalance("today", (int)$id); // $stats[3][0]['sum']
195 $stats[4] = $this->StatsModel->getBalance("week", (int)$id); // $stats[4][0]['sum']
196 $stats[5] = $this->StatsModel->getAllPayments((int)$id); // $stats[4]['total']
197 $this->data['stats'] = $stats;
198 $this->data['cat'] = ["1" => "samp", "2" => "rust", "3" => "cs", "4" => "other", "5" => 'mine'];
199
200 $this->data['items'] = $this->ProjectModel->getItems(array("shop_id" => (int) $id));
201
202 return view("project/view", $this->data);
203 }
204
205 public function addProject($shopid = null) {
206
207 if(empty($this->session->data['user_id']))
208 return view("login");
209
210 model("Project", "User", "Log");
211
212 if($this->request->post['addShop']) {
213 $shop_name = $this->request->post['shop_name'];
214 $shop_domain = $this->request->post['shop_domain'];
215 $shop_game = $this->request->post['shop_game'];
216
217 if(strpos($shop_domain, "http://") or strpos($shop_domain, "https://") or strpos($shop_domain, "/")) {
218 $result = ['status' => 'error', 'error' => 'Домен введен неверно!'];
219 } else {
220 if(!empty($shop_domain) && !empty($shop_name) && $shop_game != 0) {
221 if(!$this->ProjectModel->getProject($shop_domain, 'shop_domain')) {
222 if($shopid = $this->ProjectModel->create(['shop_name' => $shop_name, 'user_id' => $this->session->data['user_id'], 'shop_domain' => $shop_domain, 'shop_game' => $shop_game, 'shop_status' => '3'])) {
223 $public_key = md5(md5(md5(time().$shopid)."maksa988"));
224 $public_key = $public_key{1}.$public_key{2}.$public_key{3}.$public_key{4}.$public_key{5}."-".$shopid;
225 $secret_key = md5(md5(md5(time().$shopid)."maksa988"));
226 $this->ProjectModel->set(['shop_public_key' => $public_key, 'shop_secret_key' => $secret_key])->where("shop_id", "=", $shopid)->update();
227
228 $this->LogModel->pushLog("Добавлен новый проект, пройден первый Ñтап", $this->router->route());
229 $result = ['status' => 'success', 'success' => "Проект уÑпешно добавлен, необходимо пройти Ñтап проверки!"];
230 $result['file'] = $public_key.".txt";
231 $result['code'] = md5($public_key.$shopid);
232 $result['shopid'] = $shopid;
233 } else {
234 $result = ['status' => 'error', 'error' => 'Произошла ошибка при добавлении проекта, повторите попытку позже!'];
235 }
236 } else {
237 $result = ['status' => 'error', 'error' => 'Данный проект уже был добавлен!'];
238 }
239 } else {
240 $result = ['status' => 'error', 'error' => 'Ð’Ñе Ð¿Ð¾Ð»Ñ Ð¾Ð±Ñзательны к заполнению!'];
241 }
242 }
243 $this->LogModel->pushLog("Попытка Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ Ð¿Ñ€Ð¾ÐµÐºÑ‚Ð°", $this->router->route());
244 return json_encode($result);
245 }
246
247 if($this->request->post['checkSite']) {
248 $code = $this->request->post['codeCheck'];
249 $shopid = $this->request->post['shopIDNew'];
250
251 if($shop = $this->ProjectModel->getProject((int) $shopid)) {
252 if($check = @file_get_contents("http://".$shop['shop_domain']."/".$shop['shop_public_key'].".txt")) {
253 if($check == md5($shop['shop_public_key'].$shopid)) {
254 $this->ProjectModel->set(['shop_status' => 0])->where("shop_id", "=", $shopid)->update();
255 $this->LogModel->pushLog("Пройден второй Ñтап провверки Ñайта", $this->router->route());
256 $result = ['status' => 'success', 'success' => 'Проект добавлен!', 'id' => $shopid];
257 } else {
258 $result = ['status' => 'error', 'error' => 'Код в файле неверный!'];
259 }
260 } else {
261 $result = ['status' => 'error', 'error' => 'Файл Ñ ÐºÐ¾Ð´Ð¾Ð¼ не найден!'];
262 }
263 } else {
264 $result = ['status' => 'error', 'error' => 'Произошла ошибка при проверке магазина!'];
265 }
266 $this->LogModel->pushLog("Попытка пройти второй Ñтап проверки", $this->router->route());
267 return json_encode($result);
268 }
269
270 if($shopid){
271 if($shop = $this->ProjectModel->getProject((int) $shopid)) {
272 $this->data['code'] = md5($shop['shop_public_key'].$shopid);
273 $this->data['file'] = $shop['shop_public_key'];
274 $this->data['shop'] = $shop;
275 $this->LogModel->pushLog("Попытка пройти второй Ñтап проверки Ñ Ñтраницы проекта", $this->router->route());
276 } else {
277 return view("errors/404");
278 }
279 }
280
281 return view("project/add", $this->data);
282 }
283}