| 16773 |
manas |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* AppTransactions Controller
|
|
|
5 |
*
|
|
|
6 |
* @property AppTransaction $AppTransaction
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class AppTransactionsController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
|
|
16 |
public $components = array('Paginator');
|
|
|
17 |
|
|
|
18 |
public function beforeFilter()
|
|
|
19 |
{
|
|
|
20 |
parent::beforeFilter();
|
|
|
21 |
$this->Paginator->settings=array(
|
|
|
22 |
'limit'=>100
|
|
|
23 |
);
|
|
|
24 |
}
|
|
|
25 |
/**
|
|
|
26 |
* index method
|
|
|
27 |
*
|
|
|
28 |
* @return void
|
|
|
29 |
*/
|
|
|
30 |
public function index() {
|
|
|
31 |
$this->AppTransaction->recursive = 0;
|
|
|
32 |
$this->set('appTransactions', $this->Paginator->paginate());
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* view method
|
|
|
37 |
*
|
|
|
38 |
* @throws NotFoundException
|
|
|
39 |
* @param string $id
|
|
|
40 |
* @return void
|
|
|
41 |
*/
|
|
|
42 |
public function view($id = null) {
|
|
|
43 |
if (!$this->AppTransaction->exists($id)) {
|
|
|
44 |
throw new NotFoundException(__('Invalid app transaction'));
|
|
|
45 |
}
|
|
|
46 |
$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
|
|
|
47 |
$this->set('appTransaction', $this->AppTransaction->find('first', $options));
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* add method
|
|
|
52 |
*
|
|
|
53 |
* @return void
|
|
|
54 |
*/
|
|
|
55 |
public function add() {
|
|
|
56 |
if ($this->request->is('post')) {
|
|
|
57 |
$this->AppTransaction->create();
|
|
|
58 |
if ($this->AppTransaction->save($this->request->data)) {
|
|
|
59 |
$this->Session->setFlash(__('The app transaction has been saved.'));
|
|
|
60 |
return $this->redirect(array('action' => 'index'));
|
|
|
61 |
} else {
|
|
|
62 |
$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* edit method
|
|
|
69 |
*
|
|
|
70 |
* @throws NotFoundException
|
|
|
71 |
* @param string $id
|
|
|
72 |
* @return void
|
|
|
73 |
*/
|
|
|
74 |
public function edit($id = null) {
|
|
|
75 |
if (!$this->AppTransaction->exists($id)) {
|
|
|
76 |
throw new NotFoundException(__('Invalid app transaction'));
|
|
|
77 |
}
|
|
|
78 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
79 |
if ($this->AppTransaction->save($this->request->data)) {
|
|
|
80 |
$this->Session->setFlash(__('The app transaction has been saved.'));
|
|
|
81 |
return $this->redirect(array('action' => 'index'));
|
|
|
82 |
} else {
|
|
|
83 |
$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
|
|
|
84 |
}
|
|
|
85 |
} else {
|
|
|
86 |
$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
|
|
|
87 |
$this->request->data = $this->AppTransaction->find('first', $options);
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* delete method
|
|
|
93 |
*
|
|
|
94 |
* @throws NotFoundException
|
|
|
95 |
* @param string $id
|
|
|
96 |
* @return void
|
|
|
97 |
*/
|
|
|
98 |
public function delete($id = null) {
|
|
|
99 |
$this->AppTransaction->id = $id;
|
|
|
100 |
if (!$this->AppTransaction->exists()) {
|
|
|
101 |
throw new NotFoundException(__('Invalid app transaction'));
|
|
|
102 |
}
|
|
|
103 |
$this->request->onlyAllow('post', 'delete');
|
|
|
104 |
if ($this->AppTransaction->delete()) {
|
|
|
105 |
$this->Session->setFlash(__('The app transaction has been deleted.'));
|
|
|
106 |
} else {
|
|
|
107 |
$this->Session->setFlash(__('The app transaction could not be deleted. Please, try again.'));
|
|
|
108 |
}
|
|
|
109 |
return $this->redirect(array('action' => 'index'));
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
/**
|
|
|
113 |
* admin_index method
|
|
|
114 |
*
|
|
|
115 |
* @return void
|
|
|
116 |
*/
|
|
|
117 |
public function admin_index() {
|
|
|
118 |
$this->AppTransaction->recursive = 0;
|
| 16955 |
manas |
119 |
$this->Paginator->settings = array(
|
|
|
120 |
'conditions' => array('payout_description'=>'Approved'),
|
|
|
121 |
'order'=> 'payout_time desc',
|
|
|
122 |
'limit' => '100',
|
|
|
123 |
);
|
|
|
124 |
$this->set('appTransactions', $this->Paginator->paginate());
|
| 16773 |
manas |
125 |
}
|
|
|
126 |
|
| 16955 |
manas |
127 |
public function admin_transactions_all() {
|
|
|
128 |
$this->AppTransaction->recursive = 0;
|
|
|
129 |
$this->Paginator->settings = array(
|
|
|
130 |
'order'=> 'transaction_time desc',
|
|
|
131 |
'limit' => '100',
|
|
|
132 |
);
|
|
|
133 |
$this->set('appTransactions', $this->Paginator->paginate());
|
|
|
134 |
}
|
| 16773 |
manas |
135 |
/**
|
|
|
136 |
* admin_view method
|
|
|
137 |
*
|
|
|
138 |
* @throws NotFoundException
|
|
|
139 |
* @param string $id
|
|
|
140 |
* @return void
|
|
|
141 |
*/
|
|
|
142 |
public function admin_view($id = null) {
|
|
|
143 |
if (!$this->AppTransaction->exists($id)) {
|
|
|
144 |
throw new NotFoundException(__('Invalid app transaction'));
|
|
|
145 |
}
|
|
|
146 |
$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
|
|
|
147 |
$this->set('appTransaction', $this->AppTransaction->find('first', $options));
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
/**
|
|
|
151 |
* admin_add method
|
|
|
152 |
*
|
|
|
153 |
* @return void
|
|
|
154 |
*/
|
|
|
155 |
public function admin_add() {
|
|
|
156 |
if ($this->request->is('post')) {
|
|
|
157 |
$this->AppTransaction->create();
|
|
|
158 |
if ($this->AppTransaction->save($this->request->data)) {
|
|
|
159 |
$this->Session->setFlash(__('The app transaction has been saved.'));
|
|
|
160 |
return $this->redirect(array('action' => 'index'));
|
|
|
161 |
} else {
|
|
|
162 |
$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
/**
|
|
|
168 |
* admin_edit method
|
|
|
169 |
*
|
|
|
170 |
* @throws NotFoundException
|
|
|
171 |
* @param string $id
|
|
|
172 |
* @return void
|
|
|
173 |
*/
|
|
|
174 |
public function admin_edit($id = null) {
|
|
|
175 |
if (!$this->AppTransaction->exists($id)) {
|
|
|
176 |
throw new NotFoundException(__('Invalid app transaction'));
|
|
|
177 |
}
|
|
|
178 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
179 |
if ($this->AppTransaction->save($this->request->data)) {
|
|
|
180 |
$this->Session->setFlash(__('The app transaction has been saved.'));
|
|
|
181 |
return $this->redirect(array('action' => 'index'));
|
|
|
182 |
} else {
|
|
|
183 |
$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
|
|
|
184 |
}
|
|
|
185 |
} else {
|
|
|
186 |
$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
|
|
|
187 |
$this->request->data = $this->AppTransaction->find('first', $options);
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
/**
|
|
|
192 |
* admin_delete method
|
|
|
193 |
*
|
|
|
194 |
* @throws NotFoundException
|
|
|
195 |
* @param string $id
|
|
|
196 |
* @return void
|
|
|
197 |
*/
|
|
|
198 |
public function admin_delete($id = null) {
|
|
|
199 |
$this->AppTransaction->id = $id;
|
|
|
200 |
if (!$this->AppTransaction->exists()) {
|
|
|
201 |
throw new NotFoundException(__('Invalid app transaction'));
|
|
|
202 |
}
|
|
|
203 |
$this->request->onlyAllow('post', 'delete');
|
|
|
204 |
if ($this->AppTransaction->delete()) {
|
|
|
205 |
$this->Session->setFlash(__('The app transaction has been deleted.'));
|
|
|
206 |
} else {
|
|
|
207 |
$this->Session->setFlash(__('The app transaction could not be deleted. Please, try again.'));
|
|
|
208 |
}
|
|
|
209 |
return $this->redirect(array('action' => 'index'));
|
|
|
210 |
}
|
|
|
211 |
|
| 16811 |
manas |
212 |
public function admin_appwise(){
|
| 16773 |
manas |
213 |
$this->AppTransaction->recursive = -1;
|
| 16811 |
manas |
214 |
$type = $this->request->query('date');
|
|
|
215 |
$date_from = $this->request->query('date_from');
|
|
|
216 |
$date_to = $this->request->query('date_to');
|
|
|
217 |
if(!isset($type) && !isset($date_from) && !isset($date_to)){
|
|
|
218 |
$date = date('Y-m-d',time());
|
|
|
219 |
$this->Paginator->settings = array(
|
| 16773 |
manas |
220 |
'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
|
| 16811 |
manas |
221 |
'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
|
| 16873 |
manas |
222 |
'limit' => $this->AppTransaction->find('count',array('group'=>'app_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
|
| 16811 |
manas |
223 |
'order' => 'count desc' ,
|
| 16773 |
manas |
224 |
'group' => 'app_id'
|
| 16811 |
manas |
225 |
);
|
|
|
226 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
227 |
$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by app_id";
|
|
|
228 |
$approved = $this->AppTransaction->query($sql);
|
|
|
229 |
foreach ($approved as $key => $value1) {
|
|
|
230 |
$app_id=$value1['app_transactions']['app_id'];
|
|
|
231 |
$value22=$value1['0']['count(1)'];
|
|
|
232 |
foreach ($approvedCounts as $key2 => $value) {
|
|
|
233 |
if($app_id==$value['AppTransaction']['app_id']){
|
|
|
234 |
$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
|
|
|
235 |
$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
|
|
|
236 |
}
|
|
|
237 |
}
|
| 16773 |
manas |
238 |
}
|
|
|
239 |
}
|
| 16811 |
manas |
240 |
else if($type=='yesterday'){
|
|
|
241 |
$date = date('Y-m-d',time()-86400);
|
|
|
242 |
$this->Paginator->settings = array(
|
|
|
243 |
'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
|
|
|
244 |
'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
|
| 16873 |
manas |
245 |
'limit' => $this->AppTransaction->find('count',array('group'=>'app_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
|
| 16811 |
manas |
246 |
'order' => 'count desc' ,
|
|
|
247 |
'group' => 'app_id'
|
|
|
248 |
);
|
|
|
249 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
250 |
$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by app_id";
|
|
|
251 |
$approved = $this->AppTransaction->query($sql);
|
|
|
252 |
foreach ($approved as $key => $value1) {
|
|
|
253 |
$app_id=$value1['app_transactions']['app_id'];
|
|
|
254 |
$value22=$value1['0']['count(1)'];
|
|
|
255 |
foreach ($approvedCounts as $key2 => $value) {
|
|
|
256 |
if($app_id==$value['AppTransaction']['app_id']){
|
|
|
257 |
$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
|
|
|
258 |
$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
|
|
|
259 |
}
|
|
|
260 |
}
|
|
|
261 |
}
|
|
|
262 |
}else if(isset($date_from) && isset($date_to)){
|
|
|
263 |
$this->Paginator->settings = array(
|
|
|
264 |
'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
|
|
|
265 |
'conditions' => array('Date(AppTransaction.transaction_time) BETWEEN ? AND ?' =>array($date_from, $date_to)),
|
| 16873 |
manas |
266 |
'limit'=> $this->AppTransaction->find(
|
|
|
267 |
'count',array('group'=>'app_id','conditions' =>
|
|
|
268 |
array('Date(AppTransaction.transaction_time) BETWEEN ? AND ?' =>
|
|
|
269 |
array($date_from, $date_to)))),
|
| 16811 |
manas |
270 |
'order' => 'count desc' ,
|
|
|
271 |
'group' => 'app_id'
|
|
|
272 |
);
|
|
|
273 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
274 |
$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time) BETWEEN '$date_from' and '$date_to' and payout_description='Approved' group by app_id";
|
|
|
275 |
$approved = $this->AppTransaction->query($sql);
|
|
|
276 |
foreach ($approved as $key => $value1) {
|
|
|
277 |
$app_id=$value1['app_transactions']['app_id'];
|
|
|
278 |
$value22=$value1['0']['count(1)'];
|
|
|
279 |
foreach ($approvedCounts as $key2 => $value) {
|
|
|
280 |
if($app_id==$value['AppTransaction']['app_id']){
|
|
|
281 |
$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
|
|
|
282 |
$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
|
|
|
283 |
}
|
|
|
284 |
}
|
|
|
285 |
}
|
|
|
286 |
}else{
|
|
|
287 |
$date = date('Y-m-d',time());
|
|
|
288 |
$this->Paginator->settings = array(
|
|
|
289 |
'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
|
|
|
290 |
'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
|
| 16873 |
manas |
291 |
'limit' => $this->AppTransaction->find('count',array('group'=>'app_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
|
| 16811 |
manas |
292 |
'order' => 'count desc' ,
|
|
|
293 |
'group' => 'app_id'
|
|
|
294 |
);
|
|
|
295 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
296 |
$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by app_id";
|
|
|
297 |
$approved = $this->AppTransaction->query($sql);
|
|
|
298 |
foreach ($approved as $key => $value1) {
|
|
|
299 |
$app_id=$value1['app_transactions']['app_id'];
|
|
|
300 |
$value22=$value1['0']['count(1)'];
|
|
|
301 |
foreach ($approvedCounts as $key2 => $value) {
|
|
|
302 |
if($app_id==$value['AppTransaction']['app_id']){
|
|
|
303 |
$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
|
|
|
304 |
$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
|
|
|
305 |
}
|
|
|
306 |
}
|
|
|
307 |
}
|
|
|
308 |
}
|
| 16813 |
manas |
309 |
$totalClicks=0;
|
|
|
310 |
$totalApproved=0;
|
|
|
311 |
foreach ($approvedCounts as $key => $value) {
|
|
|
312 |
$totalClicks+=$value[0]['count'];
|
|
|
313 |
if(!(isset($value['AppTransaction']['approved']))){
|
|
|
314 |
$totalApproved+=0;
|
|
|
315 |
}else{
|
|
|
316 |
$totalApproved+=$value['AppTransaction']['approved'];
|
|
|
317 |
}
|
| 16811 |
manas |
318 |
}
|
| 16873 |
manas |
319 |
$url=$_SERVER['REQUEST_URI'];
|
|
|
320 |
if (strpos($url,'sort') == false) {
|
|
|
321 |
|
|
|
322 |
}else{
|
|
|
323 |
$new1=explode("/sort:", $url);
|
|
|
324 |
$new2=explode("/direction:", $new1[1]);
|
|
|
325 |
$new2=explode("/direction:", $new1[1]);
|
|
|
326 |
$sortType=$new2[0];
|
|
|
327 |
if (strpos($new2[1],'page') == false) {
|
|
|
328 |
$sortDirection=$new2[1];
|
|
|
329 |
}else{
|
|
|
330 |
$new3=explode("/page:", $new2[1]);
|
|
|
331 |
$sortDirection=$new3[0];
|
|
|
332 |
}
|
|
|
333 |
if (strpos($new2[1],'date') == false) {
|
|
|
334 |
$sortDirection=$new2[1];
|
|
|
335 |
}else{
|
|
|
336 |
$new3=explode("?date", $new2[1]);
|
|
|
337 |
$sortDirection=$new3[0];
|
|
|
338 |
}
|
|
|
339 |
if($sortType=='approved' && $sortDirection=='desc'){
|
|
|
340 |
$newApprovedCount = array();
|
|
|
341 |
foreach ($approvedCounts as $key => $row)
|
|
|
342 |
{
|
|
|
343 |
if(!(isset($row['AppTransaction']['approved']))){
|
|
|
344 |
$newApprovedCount[$key]['AppTransaction']['approved']=0;
|
|
|
345 |
}else{
|
|
|
346 |
$newApprovedCount[$key]['AppTransaction']['approved'] = $row['AppTransaction']['approved'];
|
|
|
347 |
}
|
|
|
348 |
}
|
|
|
349 |
array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
|
|
|
350 |
}
|
|
|
351 |
else if($sortType=='approved' && $sortDirection=='asc'){
|
|
|
352 |
$newApprovedCount = array();
|
|
|
353 |
foreach ($approvedCounts as $key => $row)
|
|
|
354 |
{
|
|
|
355 |
if(!(isset($row['AppTransaction']['approved']))){
|
|
|
356 |
$newApprovedCount[$key]['AppTransaction']['approved']=0;
|
|
|
357 |
}else{
|
|
|
358 |
$newApprovedCount[$key]['AppTransaction']['approved'] = $row['AppTransaction']['approved'];
|
|
|
359 |
}
|
|
|
360 |
}
|
|
|
361 |
array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
|
|
|
362 |
}
|
|
|
363 |
else if($sortType=='conversion_percentage' && $sortDirection=='desc'){
|
|
|
364 |
$newApprovedCount = array();
|
|
|
365 |
foreach ($approvedCounts as $key => $row)
|
|
|
366 |
{
|
|
|
367 |
if(!(isset($row['AppTransaction']['conversion_percentage']))){
|
|
|
368 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage']=0;
|
|
|
369 |
}else{
|
|
|
370 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage'] = $row['AppTransaction']['conversion_percentage'];
|
|
|
371 |
}
|
|
|
372 |
}
|
|
|
373 |
array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
|
|
|
374 |
}
|
|
|
375 |
else if($sortType=='conversion_percentage' && $sortDirection=='asc'){
|
|
|
376 |
$newApprovedCount = array();
|
|
|
377 |
foreach ($approvedCounts as $key => $row)
|
|
|
378 |
{
|
|
|
379 |
if(!(isset($row['AppTransaction']['conversion_percentage']))){
|
|
|
380 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage']=0;
|
|
|
381 |
}else{
|
|
|
382 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage'] = $row['AppTransaction']['conversion_percentage'];
|
|
|
383 |
}
|
|
|
384 |
}
|
|
|
385 |
array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
|
|
|
386 |
}
|
|
|
387 |
else if($sortType=='clicks'&& $sortDirection=='asc'){
|
|
|
388 |
$newApprovedCount = array();
|
|
|
389 |
foreach ($approvedCounts as $key => $row){
|
|
|
390 |
$newApprovedCount[$key][0]['count'] = $row[0]['count'];
|
|
|
391 |
}
|
|
|
392 |
array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
|
|
|
393 |
}
|
|
|
394 |
else if($sortType=='clicks'&& $sortDirection=='desc'){
|
|
|
395 |
$newApprovedCount = array();
|
|
|
396 |
foreach ($approvedCounts as $key => $row){
|
|
|
397 |
$newApprovedCount[$key][0]['count'] = $row[0]['count'];
|
|
|
398 |
}
|
|
|
399 |
array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
|
|
|
400 |
}
|
|
|
401 |
}
|
|
|
402 |
|
|
|
403 |
|
| 16813 |
manas |
404 |
$this->set('appTransactions', $approvedCounts);
|
|
|
405 |
$this->set('totalClicks', $totalClicks);
|
|
|
406 |
$this->set('totalApproved', $totalApproved);
|
|
|
407 |
}
|
| 16773 |
manas |
408 |
|
| 16811 |
manas |
409 |
public function admin_retailer(){
|
|
|
410 |
$this->AppTransaction->recursive = -1;
|
|
|
411 |
$type = $this->request->query('date');
|
|
|
412 |
$date_from = $this->request->query('date_from');
|
|
|
413 |
$date_to = $this->request->query('date_to');
|
|
|
414 |
if(!isset($type) && !isset($date_from) && !isset($date_to)){
|
|
|
415 |
$date = date('Y-m-d',time());
|
|
|
416 |
$this->Paginator->settings = array(
|
| 16873 |
manas |
417 |
'fields' => array('AppTransaction.app_id','retailer_id','app_name',
|
|
|
418 |
'COUNT(*) AS count'),
|
| 16811 |
manas |
419 |
'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
|
| 16873 |
manas |
420 |
'limit' => $this->AppTransaction->find('count',array('group'=>'retailer_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
|
|
|
421 |
'order' => 'count desc',
|
| 16811 |
manas |
422 |
'group' => 'retailer_id'
|
|
|
423 |
);
|
|
|
424 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
425 |
$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by retailer_id";
|
|
|
426 |
$approved = $this->AppTransaction->query($sql);
|
|
|
427 |
foreach ($approved as $key => $value1) {
|
|
|
428 |
$app_id=$value1['app_transactions']['retailer_id'];
|
|
|
429 |
$value22=$value1['0']['count(1)'];
|
|
|
430 |
foreach ($approvedCounts as $key2 => $value) {
|
|
|
431 |
if($app_id==$value['AppTransaction']['retailer_id']){
|
|
|
432 |
$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
|
|
|
433 |
$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
|
|
|
434 |
}
|
|
|
435 |
}
|
|
|
436 |
}
|
|
|
437 |
}
|
|
|
438 |
else if($type=='yesterday'){
|
|
|
439 |
$date = date('Y-m-d',time()-86400);
|
|
|
440 |
$this->Paginator->settings = array(
|
|
|
441 |
'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
|
|
|
442 |
'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
|
| 16873 |
manas |
443 |
'limit' => $this->AppTransaction->find('count',array('group'=>'retailer_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
|
|
|
444 |
'order' => 'count desc',
|
| 16811 |
manas |
445 |
'group' => 'retailer_id'
|
|
|
446 |
);
|
|
|
447 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
448 |
$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by retailer_id";
|
|
|
449 |
$approved = $this->AppTransaction->query($sql);
|
|
|
450 |
foreach ($approved as $key => $value1) {
|
|
|
451 |
$app_id=$value1['app_transactions']['retailer_id'];
|
|
|
452 |
$value22=$value1['0']['count(1)'];
|
|
|
453 |
foreach ($approvedCounts as $key2 => $value) {
|
|
|
454 |
if($app_id==$value['AppTransaction']['retailer_id']){
|
|
|
455 |
$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
|
|
|
456 |
$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
|
|
|
457 |
}
|
|
|
458 |
}
|
|
|
459 |
}
|
|
|
460 |
}else if(isset($date_from) && isset($date_to)){
|
|
|
461 |
$this->Paginator->settings = array(
|
|
|
462 |
'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
|
|
|
463 |
'conditions' => array('Date(AppTransaction.transaction_time) BETWEEN ? AND ?' =>array($date_from, $date_to)),
|
| 16873 |
manas |
464 |
'limit'=> $this->AppTransaction->find(
|
|
|
465 |
'count',array('group'=>'retailer_id','conditions' =>
|
|
|
466 |
array('Date(AppTransaction.transaction_time) BETWEEN ? AND ?' =>
|
|
|
467 |
array($date_from, $date_to)))),
|
| 16811 |
manas |
468 |
'order' => 'count desc' ,
|
|
|
469 |
'group' => 'retailer_id'
|
|
|
470 |
);
|
|
|
471 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
472 |
$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time) BETWEEN '$date_from' and '$date_to' and payout_description='Approved' group by retailer_id";
|
|
|
473 |
$approved = $this->AppTransaction->query($sql);
|
|
|
474 |
foreach ($approved as $key => $value1) {
|
|
|
475 |
$app_id=$value1['app_transactions']['retailer_id'];
|
|
|
476 |
$value22=$value1['0']['count(1)'];
|
|
|
477 |
foreach ($approvedCounts as $key2 => $value) {
|
|
|
478 |
if($app_id==$value['AppTransaction']['retailer_id']){
|
|
|
479 |
$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
|
|
|
480 |
$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
|
|
|
481 |
}
|
|
|
482 |
}
|
|
|
483 |
}
|
|
|
484 |
}else{
|
|
|
485 |
$date = date('Y-m-d',time());
|
|
|
486 |
$this->Paginator->settings = array(
|
|
|
487 |
'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
|
|
|
488 |
'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
|
| 16873 |
manas |
489 |
'limit' => $this->AppTransaction->find('count',array('group'=>'retailer_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
|
| 16811 |
manas |
490 |
'order' => 'count desc' ,
|
|
|
491 |
'group' => 'retailer_id'
|
|
|
492 |
);
|
|
|
493 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
494 |
$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by retailer_id";
|
|
|
495 |
$approved = $this->AppTransaction->query($sql);
|
|
|
496 |
foreach ($approved as $key => $value1) {
|
|
|
497 |
$app_id=$value1['app_transactions']['retailer_id'];
|
|
|
498 |
$value22=$value1['0']['count(1)'];
|
|
|
499 |
foreach ($approvedCounts as $key2 => $value) {
|
|
|
500 |
if($app_id==$value['AppTransaction']['retailer_id']){
|
|
|
501 |
$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
|
|
|
502 |
$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
|
|
|
503 |
}
|
|
|
504 |
}
|
|
|
505 |
}
|
|
|
506 |
}
|
| 16813 |
manas |
507 |
$totalClicks=0;
|
|
|
508 |
$totalApproved=0;
|
|
|
509 |
foreach ($approvedCounts as $key => $value) {
|
|
|
510 |
$totalClicks+=$value[0]['count'];
|
|
|
511 |
if(!(isset($value['AppTransaction']['approved']))){
|
|
|
512 |
$totalApproved+=0;
|
|
|
513 |
}else{
|
|
|
514 |
$totalApproved+=$value['AppTransaction']['approved'];
|
|
|
515 |
}
|
| 16773 |
manas |
516 |
}
|
| 16873 |
manas |
517 |
$url=$_SERVER['REQUEST_URI'];
|
|
|
518 |
if (strpos($url,'sort') == false) {
|
|
|
519 |
|
|
|
520 |
}else{
|
|
|
521 |
$new1=explode("/sort:", $url);
|
|
|
522 |
$new2=explode("/direction:", $new1[1]);
|
|
|
523 |
$new2=explode("/direction:", $new1[1]);
|
|
|
524 |
$sortType=$new2[0];
|
|
|
525 |
if (strpos($new2[1],'page') == false) {
|
|
|
526 |
$sortDirection=$new2[1];
|
|
|
527 |
}else{
|
|
|
528 |
$new3=explode("/page:", $new2[1]);
|
|
|
529 |
$sortDirection=$new3[0];
|
|
|
530 |
}
|
|
|
531 |
if (strpos($new2[1],'date') == false) {
|
|
|
532 |
$sortDirection=$new2[1];
|
|
|
533 |
}else{
|
|
|
534 |
$new3=explode("?date", $new2[1]);
|
|
|
535 |
$sortDirection=$new3[0];
|
|
|
536 |
}
|
|
|
537 |
if($sortType=='approved' && $sortDirection=='desc'){
|
|
|
538 |
$newApprovedCount = array();
|
|
|
539 |
foreach ($approvedCounts as $key => $row)
|
|
|
540 |
{
|
|
|
541 |
if(!(isset($row['AppTransaction']['approved']))){
|
|
|
542 |
$newApprovedCount[$key]['AppTransaction']['approved']=0;
|
|
|
543 |
}else{
|
|
|
544 |
$newApprovedCount[$key]['AppTransaction']['approved'] = $row['AppTransaction']['approved'];
|
|
|
545 |
}
|
|
|
546 |
}
|
|
|
547 |
array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
|
|
|
548 |
}
|
|
|
549 |
else if($sortType=='approved' && $sortDirection=='asc'){
|
|
|
550 |
$newApprovedCount = array();
|
|
|
551 |
foreach ($approvedCounts as $key => $row)
|
|
|
552 |
{
|
|
|
553 |
if(!(isset($row['AppTransaction']['approved']))){
|
|
|
554 |
$newApprovedCount[$key]['AppTransaction']['approved']=0;
|
|
|
555 |
}else{
|
|
|
556 |
$newApprovedCount[$key]['AppTransaction']['approved'] = $row['AppTransaction']['approved'];
|
|
|
557 |
}
|
|
|
558 |
}
|
|
|
559 |
array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
|
|
|
560 |
}
|
|
|
561 |
else if($sortType=='conversion_percentage' && $sortDirection=='desc'){
|
|
|
562 |
$newApprovedCount = array();
|
|
|
563 |
foreach ($approvedCounts as $key => $row)
|
|
|
564 |
{
|
|
|
565 |
if(!(isset($row['AppTransaction']['conversion_percentage']))){
|
|
|
566 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage']=0;
|
|
|
567 |
}else{
|
|
|
568 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage'] = $row['AppTransaction']['conversion_percentage'];
|
|
|
569 |
}
|
|
|
570 |
}
|
|
|
571 |
array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
|
|
|
572 |
}
|
|
|
573 |
else if($sortType=='conversion_percentage' && $sortDirection=='asc'){
|
|
|
574 |
$newApprovedCount = array();
|
|
|
575 |
foreach ($approvedCounts as $key => $row)
|
|
|
576 |
{
|
|
|
577 |
if(!(isset($row['AppTransaction']['conversion_percentage']))){
|
|
|
578 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage']=0;
|
|
|
579 |
}else{
|
|
|
580 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage'] = $row['AppTransaction']['conversion_percentage'];
|
|
|
581 |
}
|
|
|
582 |
}
|
|
|
583 |
array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
|
|
|
584 |
}
|
|
|
585 |
else if($sortType=='clicks'&& $sortDirection=='asc'){
|
|
|
586 |
$newApprovedCount = array();
|
|
|
587 |
foreach ($approvedCounts as $key => $row){
|
|
|
588 |
$newApprovedCount[$key][0]['count'] = $row[0]['count'];
|
|
|
589 |
}
|
|
|
590 |
array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
|
|
|
591 |
}
|
|
|
592 |
else if($sortType=='clicks'&& $sortDirection=='desc'){
|
|
|
593 |
$newApprovedCount = array();
|
|
|
594 |
foreach ($approvedCounts as $key => $row){
|
|
|
595 |
$newApprovedCount[$key][0]['count'] = $row[0]['count'];
|
|
|
596 |
}
|
|
|
597 |
array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
|
|
|
598 |
}
|
|
|
599 |
}
|
| 16813 |
manas |
600 |
$this->set('appTransactions', $approvedCounts);
|
|
|
601 |
$this->set('totalClicks', $totalClicks);
|
|
|
602 |
$this->set('totalApproved', $totalApproved);
|
|
|
603 |
}
|
| 16911 |
manas |
604 |
|
|
|
605 |
public function admin_user($retailer_id=null){
|
|
|
606 |
|
|
|
607 |
$this->Paginator->settings = array(
|
|
|
608 |
'fields' => array('AppTransaction.app_id','retailer_id','app_name','transaction_time','count(*) as count'),
|
|
|
609 |
'conditions' => array('retailer_id'=>$retailer_id),
|
|
|
610 |
'group' => 'app_id',
|
|
|
611 |
'order' => 'count desc'
|
|
|
612 |
);
|
|
|
613 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
614 |
$sql="SELECT app_id,count(1) from app_transactions where payout_description='Approved' and retailer_id=$retailer_id group by app_id ";
|
|
|
615 |
$approved = $this->AppTransaction->query($sql);
|
|
|
616 |
foreach ($approved as $key => $value1) {
|
|
|
617 |
$app_id=$value1['app_transactions']['app_id'];
|
|
|
618 |
$value22=$value1['0']['count(1)'];
|
|
|
619 |
foreach ($approvedCounts as $key2 => $value) {
|
|
|
620 |
if($app_id==$value['AppTransaction']['app_id']){
|
|
|
621 |
$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
|
|
|
622 |
$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
|
|
|
623 |
}
|
|
|
624 |
}
|
|
|
625 |
}
|
|
|
626 |
$url=$_SERVER['REQUEST_URI'];
|
|
|
627 |
if (strpos($url,'sort') == false) {
|
|
|
628 |
|
|
|
629 |
}else{
|
|
|
630 |
$new1=explode("/sort:", $url);
|
|
|
631 |
$new2=explode("/direction:", $new1[1]);
|
|
|
632 |
$new2=explode("/direction:", $new1[1]);
|
|
|
633 |
$sortType=$new2[0];
|
|
|
634 |
if (strpos($new2[1],'page') == false) {
|
|
|
635 |
$sortDirection=$new2[1];
|
|
|
636 |
}else{
|
|
|
637 |
$new3=explode("/page:", $new2[1]);
|
|
|
638 |
$sortDirection=$new3[0];
|
|
|
639 |
}
|
|
|
640 |
if (strpos($new2[1],'date') == false) {
|
|
|
641 |
$sortDirection=$new2[1];
|
|
|
642 |
}else{
|
|
|
643 |
$new3=explode("?date", $new2[1]);
|
|
|
644 |
$sortDirection=$new3[0];
|
|
|
645 |
}
|
|
|
646 |
if($sortType=='approved' && $sortDirection=='desc'){
|
|
|
647 |
$newApprovedCount = array();
|
|
|
648 |
foreach ($approvedCounts as $key => $row)
|
|
|
649 |
{
|
|
|
650 |
if(!(isset($row['AppTransaction']['approved']))){
|
|
|
651 |
$newApprovedCount[$key]['AppTransaction']['approved']=0;
|
|
|
652 |
}else{
|
|
|
653 |
$newApprovedCount[$key]['AppTransaction']['approved'] = $row['AppTransaction']['approved'];
|
|
|
654 |
}
|
|
|
655 |
}
|
|
|
656 |
array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
|
|
|
657 |
}
|
|
|
658 |
else if($sortType=='approved' && $sortDirection=='asc'){
|
|
|
659 |
$newApprovedCount = array();
|
|
|
660 |
foreach ($approvedCounts as $key => $row)
|
|
|
661 |
{
|
|
|
662 |
if(!(isset($row['AppTransaction']['approved']))){
|
|
|
663 |
$newApprovedCount[$key]['AppTransaction']['approved']=0;
|
|
|
664 |
}else{
|
|
|
665 |
$newApprovedCount[$key]['AppTransaction']['approved'] = $row['AppTransaction']['approved'];
|
|
|
666 |
}
|
|
|
667 |
}
|
|
|
668 |
array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
|
|
|
669 |
}
|
|
|
670 |
else if($sortType=='conversion_percentage' && $sortDirection=='desc'){
|
|
|
671 |
$newApprovedCount = array();
|
|
|
672 |
foreach ($approvedCounts as $key => $row)
|
|
|
673 |
{
|
|
|
674 |
if(!(isset($row['AppTransaction']['conversion_percentage']))){
|
|
|
675 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage']=0;
|
|
|
676 |
}else{
|
|
|
677 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage'] = $row['AppTransaction']['conversion_percentage'];
|
|
|
678 |
}
|
|
|
679 |
}
|
|
|
680 |
array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
|
|
|
681 |
}
|
|
|
682 |
else if($sortType=='conversion_percentage' && $sortDirection=='asc'){
|
|
|
683 |
$newApprovedCount = array();
|
|
|
684 |
foreach ($approvedCounts as $key => $row)
|
|
|
685 |
{
|
|
|
686 |
if(!(isset($row['AppTransaction']['conversion_percentage']))){
|
|
|
687 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage']=0;
|
|
|
688 |
}else{
|
|
|
689 |
$newApprovedCount[$key]['AppTransaction']['conversion_percentage'] = $row['AppTransaction']['conversion_percentage'];
|
|
|
690 |
}
|
|
|
691 |
}
|
|
|
692 |
array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
|
|
|
693 |
}
|
|
|
694 |
else if($sortType=='clicks'&& $sortDirection=='asc'){
|
|
|
695 |
$newApprovedCount = array();
|
|
|
696 |
foreach ($approvedCounts as $key => $row){
|
|
|
697 |
$newApprovedCount[$key][0]['count'] = $row[0]['count'];
|
|
|
698 |
}
|
|
|
699 |
array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
|
|
|
700 |
}
|
|
|
701 |
else if($sortType=='clicks'&& $sortDirection=='desc'){
|
|
|
702 |
$newApprovedCount = array();
|
|
|
703 |
foreach ($approvedCounts as $key => $row){
|
|
|
704 |
$newApprovedCount[$key][0]['count'] = $row[0]['count'];
|
|
|
705 |
}
|
|
|
706 |
array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
|
|
|
707 |
}
|
|
|
708 |
}
|
|
|
709 |
$this->set('retailerId',$retailer_id) ;
|
|
|
710 |
$this->set('appTransactions',$approvedCounts) ;
|
|
|
711 |
}
|
| 16873 |
manas |
712 |
|
| 16943 |
manas |
713 |
public function admin_pricewise(){
|
|
|
714 |
$this->AppTransaction->recursive = -1;
|
|
|
715 |
$type = $this->request->query('date');
|
|
|
716 |
$date_from = $this->request->query('date_from');
|
|
|
717 |
$date_to = $this->request->query('date_to');
|
|
|
718 |
if(!isset($type) && !isset($date_from) && !isset($date_to)){
|
|
|
719 |
$date = date('Y-m-d',time());
|
|
|
720 |
$this->Paginator->settings = array(
|
| 16952 |
manas |
721 |
'fields' => array('date(transaction_time) as date','sum(offer_price) as offer_price','sum(final_user_payout) as payout_amount'),
|
| 16943 |
manas |
722 |
'conditions' => array('Date(AppTransaction.transaction_time)'=>$date,'payout_description'=>'Approved'),
|
|
|
723 |
);
|
|
|
724 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
725 |
}
|
|
|
726 |
else if($type=='yesterday'){
|
|
|
727 |
$date = date('Y-m-d',time()-86400);
|
|
|
728 |
$this->Paginator->settings = array(
|
| 16952 |
manas |
729 |
'fields' => array('date(transaction_time) as date','sum(offer_price) as offer_price','sum(final_user_payout) as payout_amount'),
|
| 16943 |
manas |
730 |
'conditions' => array('Date(AppTransaction.transaction_time)'=>$date,'payout_description'=>'Approved'),
|
|
|
731 |
);
|
|
|
732 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
733 |
}else if(isset($date_from) && isset($date_to)){
|
|
|
734 |
$this->Paginator->settings = array(
|
| 16952 |
manas |
735 |
'fields' => array('date(transaction_time) as date','sum(offer_price) as offer_price','sum(final_user_payout) as payout_amount'),
|
| 16943 |
manas |
736 |
'conditions' => array('Date(AppTransaction.transaction_time) BETWEEN ? AND ?' =>array($date_from, $date_to),'payout_description'=>'Approved'),
|
| 16952 |
manas |
737 |
'group' => 'Date(transaction_time)',
|
|
|
738 |
'order' => 'date desc',
|
|
|
739 |
'limit' => '50',
|
| 16943 |
manas |
740 |
);
|
|
|
741 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
742 |
}else{
|
|
|
743 |
$date = date('Y-m-d',time());
|
|
|
744 |
$this->Paginator->settings = array(
|
| 16952 |
manas |
745 |
'fields' => array('date(transaction_time) as date','sum(offer_price) as offer_price','sum(final_user_payout) as payout_amount'),
|
| 16943 |
manas |
746 |
'conditions' => array('Date(AppTransaction.transaction_time)'=>$date,'payout_description'=>'Approved'),
|
|
|
747 |
);
|
|
|
748 |
$approvedCounts = $this->Paginator->paginate();
|
|
|
749 |
}
|
|
|
750 |
$totalSum=$this->AppTransaction->find('all',array(
|
|
|
751 |
'fields' => array('sum(offer_price) as total_offer_price','sum(final_user_payout)as total_payout_amount'),
|
|
|
752 |
'conditions' => array('payout_description'=>'Approved')
|
|
|
753 |
));
|
|
|
754 |
$this->set('datewiseTotal',$approvedCounts);
|
|
|
755 |
$this->set('total',$totalSum);
|
|
|
756 |
}
|
|
|
757 |
}
|