· 8 years ago · Feb 18, 2018, 09:18 AM
1<?php
2
3class AdminController extends Controller
4{
5 public $layout='column2';
6 public function actionCreate_category()
7 {
8 $id=$_GET['id'];
9 $model= (new CategoryEx())->findByPk($id);
10 if(!$model)
11 $model=new CategoryEx();
12 if($_GET['category_id'])
13 {
14 $model->category_id=$_GET['category_id'];
15 Yii::app()->user->setFlash('success','You are Adding Category in '. (new CategoryEx())->findByPk($_GET['category_id'])->name);
16 }
17 if($_POST)
18 {
19 $model->attributes=$_POST['CategoryEx'];
20 if($model->validate(['name']))
21 {
22 if($model->save())
23 {
24 Yii::app()->user->setFlash('success','Category is Successfully Saved...');
25 }
26 else
27 {
28 Yii::app()->user->setFlash('error','Error in Saving Category');
29 }
30 }
31 }
32 $this->render('create_category',['model'=>$model]);
33 }
34
35 public function actionSubscription()
36 {
37 $model=new SubscriptionEx();
38 $model->unsetAttributes();
39 $model->attributes=$_GET['SubscriptionEx'];
40 $this->render('subscription', ['model'=>$model]);
41 }
42
43 public function actionUnsub($id)
44 {
45 W::OnError();
46 $return= SubscriptionEx::unsub($id);
47 print_r($return);
48 }
49
50
51
52
53 public function actionFullSummary()
54 {
55 $start_date=$_GET['start_date'];
56 $end_date=$_GET['end_date'];
57 //header('content-type: text/plain');
58 if($start_date and $end_date)
59 {
60 $mongo_start_date=new MongoDate(strtotime($start_date));
61 $mongo_end_date=new MongoDate(strtotime($end_date)+(3600*24));
62 $coll=(new MongoBVlog())->getCollection();
63 $project=[
64 '$project'=>[
65 'res99'=>'$log.D2C_SALPARNI_LOOKATIT_PPU_99.response',
66 'res75'=>'$log.D2C_SALPARNI_LOOKATIT_PPU_75.response',
67 'res49'=>'$log.D2C_SALPARNI_LOOKATIT_PPU_49.response',
68 'res30'=>'$log.D2C_SALPARNI_LOOKATIT_PPU_30.response',
69 'res20'=>'$log.D2C_SALPARNI_LOOKATIT_PPU_20.response',
70 'res10'=>'$log.D2C_SALPARNI_LOOKATIT_PPU_10.response',
71 'res5'=>'$log.D2C_SALPARNI_LOOKATIT_PPU_5.response',
72 'res3'=>'$log.D2C_SALPARNI_LOOKATIT_PPU_3.response',
73 'res2'=>'$log.D2C_SALPARNI_LOOKATIT_PPU_2.response',
74 'res1'=>'$log.D2C_SALPARNI_LOOKATIT_PPU_1.response',
75 ]
76 ];
77 $match=[
78 '$match'=>['time'=>['$gte'=>$mongo_start_date,'$lte'=>$mongo_end_date]],
79
80 ];
81 $group=[
82 '$group'=>[
83 '_id'=>'count',
84 'count'=>['$sum'=>1]
85 ]
86 ];
87 $pipeline_no_bal=[
88 $match,
89 $project,
90
91 [
92 '$match'=>['res1.0'=>'2401']
93 ],
94 $group
95
96 ];
97 $no_bal=$coll->aggregate($pipeline_no_bal);
98
99 $pipeline_no_res=[
100 $match,
101 $project,
102 [
103 '$match'=>[
104 '$or'=>
105 [
106 [
107 'res99'=>''
108 ],
109 [
110 'res75'=>''
111 ],
112 [
113 'res49'=>''
114 ],
115 [
116 'res30'=>''
117 ],
118 [
119 'res20'=>''
120 ],
121 [
122 'res10'=>''
123 ],
124 [
125 'res5'=>''
126 ],
127 [
128 'res3'=>''
129 ],
130 [
131 'res2'=>''
132 ],
133 [
134 'res1'=>''
135 ],
136 ]
137 ]
138 ],
139 $group
140 ];
141
142 $no_res=($coll->aggregate($pipeline_no_res));
143
144 $total_msisdn=$coll->aggregate([
145 $match,
146 [
147 '$group'=>[
148 '_id'=>'$msisdn'
149 ]
150 ],
151 $group
152 ]);
153//
154
155 $mapCode=new MongoCode('function() { var i; for(i in this.log) { if(this.log[i].response[0]=="2000") emit(i,1); } }');
156 $redCode=new MongoCode('function(k,v) { var total=0; for(var i in v) { total+=v[i]; } return total;}');
157 $res= Yii::app()->mongodb->command([
158 'mapreduce'=>'bv_log',
159 'map'=>$mapCode,
160 'reduce'=>$redCode,
161 'query'=>$match['$match'],
162 'out'=>'bv_log_mrtemp'
163 ]);
164 $temp=(Yii::app()->mongodb->bv_log_mrtemp->find());
165 foreach($temp as $v)
166 {
167 $pp[$v['_id']]=$v['value'];
168 }
169
170 $sol_match=$match['$match'];
171 $sol_match['price']=['$gt'=>0];
172
173 $sol= Yii::app()->mongodb->barlist->aggregate(
174 [
175 [
176 '$match'=>$sol_match
177 ],
178 [
179 '$project'=>[
180 'msisdn'=>1,
181 'sol'=>1,
182 ]
183 ],
184 [
185 '$group'=>[
186 '_id'=>'$msisdn',
187 'sol'=>['$first'=>'$sol']
188 ]
189 ],
190 [
191 '$group'=>[
192 '_id'=>'$sol',
193 'count'=>['$sum'=>1]
194 ]
195 ],
196
197 [
198 '$limit'=>21
199 ]
200
201 ])['result'];
202
203
204 }
205 $this->render('fullsummary', ['no_bal'=>$no_bal,'no_res'=>$no_res,'total_msisdn'=>$total_msisdn,'pp'=>$pp,'sol'=>$sol]);
206 }
207
208
209 public function actionMapDir()
210 {
211 if($_POST['submit']=='show-file')
212 {
213 $model=new FileSystemParser($_POST['path']);
214 $model->beginParse();
215 $model->setResults(true);
216 $print='<pre>'.print_r($model->results,1).'</pre>';
217 }
218 elseif($_POST['submit']=='copy-file')
219 {
220 //print_r($_POST);exit;
221 $model=new FileSystemParser($_POST['path']);
222 $model->beginParse();
223 $model->setResults(true);
224 $files=$model->results['files'];
225 $ext=$_POST['extension'];
226 $uniqid= uniqid();
227 $category_id=(int)$_POST['category_id'];
228 foreach ($files as $key => $value) {
229 if(pathinfo($value,PATHINFO_EXTENSION)==$ext)
230 {
231 //echo $value;exit;
232 $thumbPath= str_replace('.'.$ext, '.jpg', $value);
233 //$thumbPath=$value;
234 if(file_exists($thumbPath))
235 {
236 $content=new ContentEx();
237 $content->name= pathinfo($value,PATHINFO_FILENAME);
238 $content->description=$uniqid;
239 $path=Yii::getPathOfAlias('webroot.cms');
240 $id= $this->getNextAutoInc('content');
241 $filename= basename($value);
242 $content->file_path=$filename ;
243 $content->category_id=$category_id;
244 $content_path=$path.'/'. $id.'_'.$filename;
245 $content->created_at= date('Y-m-d H:i:s');
246 $content->updated_at= date('Y-m-d H:i:s');
247 copy($value, $content_path);
248 /* @var $image CUploadedFile */
249 if($content->save())
250 {
251 // redirect to success page
252
253 $thumb_path_a=Yii::getPathOfAlias('webroot.cms.thumb').'/'.$id.'_'.$filename.'.'.$ext;
254 copy($thumbPath,$thumb_path_a);
255 echo $value,"\n";
256
257 }
258 else
259 {
260 print_r($content->errors);
261 exit;
262 }
263 }
264 else
265 {
266 echo $value,"\n";
267 }
268 }
269 }
270 exit;
271 }
272 $this->render('map_dir', ['model'=>$model,'print'=>$print]);
273 }
274
275 public function actionReport2()
276 {
277 $start_date=strtotime(date('Y-m-d')." 00:00:00");
278 $end_date=strtotime(date('Y-m-d')." 23:59:59");
279 if($_GET['start_date'] and $_GET['end_date'])
280 {
281 $start_date= strtotime($_GET['start_date'].' 00:00:00');
282 $end_date= strtotime($_GET['end_date'].' 23:59:59');
283 }
284 $mongo_end_date=new MongoDate($end_date);
285 $mongo_start_date=new MongoDate($start_date);
286 $pid=$_GET['pid'];
287 $match=[
288 '$match'=>[
289 'time'=>[
290 '$gte'=>$mongo_start_date,
291 '$lte'=>$mongo_end_date,
292 ],
293 'type'=>[
294 '$ne'=>'V'
295 ]
296 ]
297 ];
298
299 //print_r($match);exit;
300 $pipeline=[
301 $match,
302 [
303 '$project'=>[
304 '_id'=>1,
305 'product'=>1,
306 'time'=>[
307 '$add'=>['$time',(5.5*3600)*1000]
308 ],
309 'price'=>1,
310 'type'=>1
311
312 ]
313 ],
314 [
315 '$group'=>[
316 '_id'=>[
317 'product'=>'$product',
318 'd'=>['$dayOfMonth'=>'$time'],
319 'm'=>['$month'=>'$time'],
320 'y'=>['$year'=>'$time'],
321 ],
322 'rev'=>['$sum'=>[
323 '$cond'=>[
324 [
325 '$eq'=>[
326 '$type',
327 MongoCampaignLog::TYPE_PARK
328 ]
329 ],
330 0,'$price'
331 ]
332 ] ],
333 'fresh'=>[
334 '$sum'=>
335 [
336 '$cond'=>[
337 [
338 '$eq'=>[
339 '$type',
340 'F'
341 ]
342 ],
343 1,0
344 ]
345 ]
346 ],
347 'zero_balance'=>[
348 '$sum'=>[
349 '$cond'=>[
350 [
351 '$eq'=>[
352 '$type',
353 'P'
354 ]
355 ],
356 1,0
357 ]
358 ]
359 ],
360 'fresh_rev'=>[
361 '$sum'=>
362 [
363 '$cond'=>[
364 [
365 '$eq'=>[
366 '$type',
367 'F'
368 ]
369 ],
370 '$price',0
371 ]
372 ]
373 ],
374 'churn'=>[
375 '$sum'=>
376 [
377 '$cond'=>[
378 [
379 '$eq'=>[
380 '$type',
381 'C'
382 ]
383 ],
384 1,0
385 ]
386 ]
387 ],
388 'renewal'=>[
389 '$sum'=>
390 [
391 '$cond'=>[
392 [
393 '$eq'=>[
394 '$type',
395 'R'
396 ]
397 ],
398 1,0
399 ]
400 ]
401 ],
402 'renewal_rev'=>[
403 '$sum'=>
404 [
405 '$cond'=>[
406 [
407 '$eq'=>[
408 '$type',
409 'R'
410 ]
411 ],
412 '$price',0
413 ]
414 ]
415 ],
416 ]
417 ],
418 [
419 '$sort'=>[
420 '_id'=>-1
421 ]
422 ]
423 ];
424
425 //print_r($pipeline);exit;
426 $pipeline4Hit=[
427 $match,
428 [
429 '$project'=>[
430 'msisdn'=>1,
431 'time'=>[
432 '$add'=>['$time',(5.5*3600)*1000]
433 ],
434 'product_id'=>1
435 ]
436 ],
437 [
438 '$project'=>[
439 'msisdn'=>1,
440 'y'=>[
441 '$substr'=>[
442 ['$year'=>'$time'],0,4
443 ]
444 ],
445 'm'=>[
446 '$substr'=>[
447 ['$month'=>'$time'],0,2
448 ]
449 ],
450 'd'=>[
451 '$substr'=>[
452 ['$dayOfMonth'=>'$time'],0,2
453 ]
454 ],
455 'product_id'=>1
456 ]
457 ],
458 [
459 '$group'=>[
460 '_id'=>[
461 'msisdn'=>'$msisdn',
462 'hit_day'=>[
463 '$concat'=>['$d','-','$m','-','$y','-','$product_id']
464 ],
465 ],
466 'count'=>['$sum'=>1],
467 'uniq_count'=>['$first'=>1]
468 ]
469 ],
470 [
471 '$group'=>[
472 '_id'=>'$_id.hit_day',
473 'total_hit'=>[
474 '$sum'=>'$count'
475 ],
476 'uniq_hit'=>[
477 '$sum'=>'$uniq_count'
478 ]
479 ]
480 ],
481 [
482 '$limit'=>10,
483 ]
484 ];
485
486 if($pid)
487 {
488 $pipeline[0]['$match']['product']=$pid;
489 $pipeline4Hit[0]['$match']['product_id']=$pid;
490 }else
491 {
492 $products=['32','31','29','26'];
493 $pipeline[0]['$match']['product']=['$in'=>$products];
494 $pipeline4Hit[0]['$match']['product_id']=['$in'=>$products];
495 }
496 //print_r($pipeline);exit;
497 $result=(new MongoCampaignLog())->getCollection()->aggregate($pipeline);
498 //echo '<pre>',print_r($result);exit;
499 $hit_result=(new MongoLogReq())->getCollection()->aggregate($pipeline4Hit);
500 //print_r($pipeline4Hit);
501 //print_r($hit_result);exit;
502 $hit_result=$hit_result['result'];
503 $temp_result=$hit_result;
504 unset($hit_result);
505 foreach($temp_result as $v)
506 {
507 $hit_result[$v['_id']]=[
508 'total_hit'=>$v['total_hit'],
509 'uniq_hit'=>$v['uniq_hit'],
510 ];
511 }
512 //print_r($hit_result);
513 //exit;
514 $result=$result['result'];
515 $data=[];
516 foreach($result as $k=>$v)
517 {
518 $data[$k]=$v;
519 $data[$k]['product']=$v['_id']['product'];
520 $data[$k]['productlink']=(new ProductEx())->getProductlink($v['_id']['product']);
521 $date="{$v['_id']['d']}-{$v['_id']['m']}-{$v['_id']['y']}";
522 $data[$k]['date']=$date;
523 $data[$k]['total_hit']="{$hit_result[$date.'-'.$data[$k]['product']]['total_hit']}";
524 $data[$k]['uniq_hit']="{$hit_result[$date.'-'.$data[$k]['product']]['uniq_hit']}";
525 if(in_array($v['_id']['product'], [26,29]) and 1)
526 {
527 $noDate = '21-12-2016';
528 if(strtotime($date) > strtotime($noDate)){
529 $data[$k]['total_hit']=0;
530 $data[$k]['uniq_hit']=0;
531 $data[$k]['fresh']=0;
532 $data[$k]['fresh_rev']=0;
533 $data[$k]['zero_balance']=0;
534 $data[$k]['rev']=$data[$k]['renewal_rev'];
535 }
536 }
537 unset($data[$k]['_id']);
538 }
539 $dataProvider=new CArrayDataProvider($data);
540
541 $this->render('report2', ['dataProvider'=>$dataProvider]);
542 }
543
544
545 public function actionReportY()
546 {
547 $start_date=strtotime(date('Y-m-d')." 00:00:00");
548 $end_date=strtotime(date('Y-m-d')." 23:59:59");
549 if($_GET['start_date'] and $_GET['end_date'])
550 {
551 $start_date= strtotime($_GET['start_date'].' 00:00:00');
552 $end_date= strtotime($_GET['end_date'].' 23:59:59');
553 }
554 $mongo_end_date=new MongoDate($end_date);
555 $mongo_start_date=new MongoDate($start_date);
556 $pid=$_GET['pid'];
557 $match=[
558 '$match'=>[
559 'time'=>[
560 '$gte'=>$mongo_start_date,
561 '$lte'=>$mongo_end_date,
562 ],
563 'type'=>[
564 '$ne'=>'V'
565 ]
566 ]
567 ];
568
569 //print_r($match);exit;
570 $pipeline=[
571 $match,
572 [
573 '$project'=>[
574 '_id'=>1,
575 'product'=>1,
576 'time'=>[
577 '$add'=>['$time',(5.5*3600)*1000]
578 ],
579 'price'=>1,
580 'type'=>1
581
582 ]
583 ],
584 [
585 '$group'=>[
586 '_id'=>[
587 'product'=>'$product',
588 'd'=>['$dayOfMonth'=>'$time'],
589 'm'=>['$month'=>'$time'],
590 'y'=>['$year'=>'$time'],
591 ],
592 'rev'=>['$sum'=>[
593 '$cond'=>[
594 [
595 '$or'=>[
596 ['$eq'=>['$type', MongoCampaignLog::TYPE_PARK]],
597 ['$eq'=>['$type', MongoCampaignLog::TYPE_GRACE]],
598 ['$eq'=>['$type', MongoCampaignLog::TYPE_CANCEL]],
599 ['$eq'=>['$type', MongoCampaignLog::TYPE_SUSPEND]]
600 ]
601 ],
602 0,'$price'
603 ]
604 ] ],
605 'fresh'=>[
606 '$sum'=>
607 [
608 '$cond'=>[
609 [
610 '$eq'=>[
611 '$type',
612 'F'
613 ]
614 ],
615 1,0
616 ]
617 ]
618 ],
619 'zero_balance'=>[
620 '$sum'=>[
621 '$cond'=>[
622 [
623 '$eq'=>[
624 '$type',
625 'P'
626 ]
627 ],
628 1,0
629 ]
630 ]
631 ],
632 'fresh_rev'=>[
633 '$sum'=>
634 [
635 '$cond'=>[
636 [
637 '$eq'=>[
638 '$type',
639 'F'
640 ]
641 ],
642 '$price',0
643 ]
644 ]
645 ],
646 'churn'=>[
647 '$sum'=>
648 [
649 '$cond'=>[
650 [
651 '$eq'=>[
652 '$type',
653 'C'
654 ]
655 ],
656 1,0
657 ]
658 ]
659 ],
660 'renewal'=>[
661 '$sum'=>
662 [
663 '$cond'=>[
664 [
665 '$eq'=>[
666 '$type',
667 'R'
668 ]
669 ],
670 1,0
671 ]
672 ]
673 ],
674 'renewal_rev'=>[
675 '$sum'=>
676 [
677 '$cond'=>[
678 [
679 '$eq'=>[
680 '$type',
681 'R'
682 ]
683 ],
684 '$price',0
685 ]
686 ]
687 ],
688 ]
689 ],
690 [
691 '$sort'=>[
692 '_id'=>-1
693 ]
694 ]
695 ];
696
697 //print_r($pipeline);exit;
698 $pipeline4Hit=[
699 $match,
700 [
701 '$project'=>[
702 'msisdn'=>1,
703 'time'=>[
704 '$add'=>['$time',(5.5*3600)*1000]
705 ],
706 'product_id'=>1
707 ]
708 ],
709 [
710 '$project'=>[
711 'msisdn'=>1,
712 'y'=>[
713 '$substr'=>[
714 ['$year'=>'$time'],0,4
715 ]
716 ],
717 'm'=>[
718 '$substr'=>[
719 ['$month'=>'$time'],0,2
720 ]
721 ],
722 'd'=>[
723 '$substr'=>[
724 ['$dayOfMonth'=>'$time'],0,2
725 ]
726 ],
727 'product_id'=>1
728 ]
729 ],
730 [
731 '$group'=>[
732 '_id'=>[
733 'msisdn'=>'$msisdn',
734 'hit_day'=>[
735 '$concat'=>['$d','-','$m','-','$y','-','$product_id']
736 ],
737 ],
738 'count'=>['$sum'=>1],
739 'uniq_count'=>['$first'=>1]
740 ]
741 ],
742 [
743 '$group'=>[
744 '_id'=>'$_id.hit_day',
745 'total_hit'=>[
746 '$sum'=>'$count'
747 ],
748 'uniq_hit'=>[
749 '$sum'=>'$uniq_count'
750 ]
751 ]
752 ],
753 [
754 '$limit'=>10,
755 ]
756 ];
757
758 if($pid)
759 {
760 $pipeline[0]['$match']['product']=$pid;
761 $pipeline4Hit[0]['$match']['product_id']=$pid;
762 }
763 $result=(new MongoCampaignLog())->getCollection()->aggregate($pipeline);
764 //echo '<pre>',print_r($result);exit;
765 $hit_result=(new MongoLogReq())->getCollection()->aggregate($pipeline4Hit);
766 //print_r($pipeline4Hit);
767 //print_r($hit_result);exit;
768 $hit_result=$hit_result['result'];
769 $temp_result=$hit_result;
770 unset($hit_result);
771 foreach($temp_result as $v)
772 {
773 $hit_result[$v['_id']]=[
774 'total_hit'=>$v['total_hit'],
775 'uniq_hit'=>$v['uniq_hit'],
776 ];
777 }
778 //print_r($hit_result);
779 //exit;
780 $result=$result['result'];
781 $data=[];
782 foreach($result as $k=>$v)
783 {
784
785 $data[$k]=$v;
786 $data[$k]['product']=$v['_id']['product'];
787 $data[$k]['productlink']=(new ProductEx())->getProductlink($v['_id']['product']);
788 $date="{$v['_id']['d']}-{$v['_id']['m']}-{$v['_id']['y']}";
789 $data[$k]['date']=$date;
790 $data[$k]['total_hit']="{$hit_result[$date.'-'.$data[$k]['product']]['total_hit']}";
791 $data[$k]['uniq_hit']="{$hit_result[$date.'-'.$data[$k]['product']]['uniq_hit']}";
792 unset($data[$k]['_id']);
793 }
794 $dataProvider=new CArrayDataProvider($data);
795
796 $this->render('reportx', ['dataProvider'=>$dataProvider]);
797 }
798
799 /**
800 * Revenue Report For view all
801 */
802 public function actionReportX()
803 {
804 $start_date=date('Y-m-d')." 00:00:00";
805 $end_date=date('Y-m-d')." 23:59:59";
806 if($_GET['start_date'] and $_GET['end_date'])
807 {
808 $start_date= $_GET['start_date'].' 00:00:00';
809 $end_date= $_GET['end_date'].' 23:59:59';
810 }else{
811 $_GET['start_date']=date('Y-m-d');
812 $_GET['end_date']=date('Y-m-d');
813 }
814 if(isset($_GET['code']) and $_GET['code']!=''){
815 $code = $_GET['code'];
816 } else {
817 $code = "IN";
818 }
819 $promote='';
820 if(isset($_GET['promote'])){
821 $promote=$_GET['promote'];
822 }
823 $_GET['code']=$code;
824 if($code!="IN"){
825 $getTimeZone= Common::getTimeZoneByCountry($code);
826 $dateT = new DateTime(date('Y-m-d H:i:s'));
827 $dateT->setTimezone(new DateTimeZone($getTimeZone));
828 $offset=($dateT->getOffset()/(60*60));
829 // echo "<pre>";print_r($offset);exit;
830 $endTime=strtotime($end_date)-(($offset-5.5)*3600);
831 $startTime=strtotime($start_date)-(($offset)*3600);
832 $mongo_end_date=new MongoDate($endTime);
833 $mongo_start_date=new MongoDate($startTime);
834 }else{
835 $offset=5.5;
836 $mongo_end_date=new MongoDate(strtotime($end_date));
837 $mongo_start_date=new MongoDate(strtotime($start_date));
838 }
839// $pid=$_GET['pid'];
840 $match=[
841 '$match'=>[
842 'time'=>[
843 '$gte'=>$mongo_start_date,
844 '$lte'=>$mongo_end_date,
845 ],
846 'type'=>[
847 '$ne'=>'V'
848 ]
849 ]
850 ];
851 if(isset($_GET['pid']) and $_GET['pid']!=''){
852 $pids = explode(',', $_GET["pid"]);
853 if(($key = array_search(42, $pids))!==FALSE)
854 $pids[$key]=42;
855 $match['$match']['product']=['$in'=>$pids];
856 }
857// echo "<pre>"; print_r($match);exit;
858 $pipeline=[
859 $match,
860 [
861 '$project'=>[
862 '_id'=>1,
863 'product'=>1,
864 'time'=>[
865 '$add'=>['$time',($offset*3600)*1000]
866 ],
867 'price'=>1,
868 'type'=>1,
869 'cc'=>1
870
871 ]
872 ],
873 [
874 '$group'=>[
875 '_id'=>[
876 'product'=>'$product',
877 'd'=>['$dayOfMonth'=>'$time'],
878 'm'=>['$month'=>'$time'],
879 'y'=>['$year'=>'$time'],
880 ],
881 'rev'=>['$sum'=>[
882 '$cond'=>[
883 [
884 '$or'=>[
885 ['$eq'=>['$type', MongoCampaignLog::TYPE_PARK]],
886 ['$eq'=>['$type', MongoCampaignLog::TYPE_GRACE]],
887 ['$eq'=>['$type', MongoCampaignLog::TYPE_CANCEL]],
888 ['$eq'=>['$type', MongoCampaignLog::TYPE_SUSPEND]]
889 ]
890 ],
891 0,'$price'
892 ]
893 ] ],
894 'fresh'=>[
895 '$sum'=>
896 [
897 '$cond'=>[
898 [
899 '$eq'=>[
900 '$type',
901 'F'
902 ]
903 ],
904 1,0
905 ]
906 ]
907 ],
908 'zero_balance'=>[
909 '$sum'=>[
910 '$cond'=>[
911 [
912 '$eq'=>[
913 '$type',
914 'P'
915 ]
916 ],
917 1,0
918 ]
919 ]
920 ],
921 'grace_user'=>[
922 '$sum'=>[
923 '$cond'=>[
924 [
925 '$eq'=>[
926 '$type',
927 'G'
928 ]
929 ],
930 1,0
931 ]
932 ]
933 ],
934 'suspend'=>[
935 '$sum'=>[
936 '$cond'=>[
937 [
938 '$eq'=>[
939 '$type',
940 'S'
941 ]
942 ],
943 1,0
944 ]
945 ]
946 ],
947 'fresh_rev'=>[
948 '$sum'=>
949 [
950 '$cond'=>[
951 [
952 '$eq'=>[
953 '$type',
954 'F'
955 ]
956 ],
957 '$price',0
958 ]
959 ]
960 ],
961 'pta'=>[
962 '$sum'=>[
963 '$cond'=>[
964 [
965 '$eq'=>[
966 '$type',
967 'PA'
968 ]
969 ],
970 1,0
971 ]
972 ]
973 ],
974 'oi'=>[
975 '$sum'=>[
976 '$cond'=>[
977 [
978 '$eq'=>[
979 '$type',
980 'OI'
981 ]
982 ],
983 1,0
984 ]
985 ]
986 ],
987 'pta_rev'=>[
988 '$sum'=>
989 [
990 '$cond'=>[
991 [
992 '$eq'=>[
993 '$type',
994 'PA'
995 ]
996 ],
997 '$price',0
998 ]
999 ]
1000 ],
1001 'churn'=>[
1002 '$sum'=>
1003 [
1004 '$cond'=>[
1005 [
1006 '$eq'=>[
1007 '$type',
1008 'C'
1009 ]
1010 ],
1011 1,0
1012 ]
1013 ]
1014 ],
1015 'cc_churn'=>[
1016 '$sum'=>[
1017 '$cond'=>[
1018 [
1019 '$eq'=>[
1020 '$cc',
1021 'Y'
1022 ]
1023 ],
1024 1,0
1025 ]
1026 ]
1027 ],
1028 'renewal'=>[
1029 '$sum'=>
1030 [
1031 '$cond'=>[
1032 [
1033 '$eq'=>[
1034 '$type',
1035 'R'
1036 ]
1037 ],
1038 1,0
1039 ]
1040 ]
1041 ],
1042 'renewal_rev'=>[
1043 '$sum'=>
1044 [
1045 '$cond'=>[
1046 [
1047 '$eq'=>[
1048 '$type',
1049 'R'
1050 ]
1051 ],
1052 '$price',0
1053 ]
1054 ]
1055 ],
1056 ]
1057 ],
1058 [
1059 '$sort'=>[
1060 '_id'=>-1
1061 ]
1062 ]
1063 ];
1064
1065 //print_r($pipeline);exit;
1066 $pipelineDay=[
1067 $match,
1068 [
1069 '$match'=>[
1070 'type'=>[
1071 '$in'=>['F','C']
1072 ]
1073 ]
1074 ],
1075 [
1076 '$project'=>[
1077 '_id'=>1,
1078 'product'=>1,
1079 'time'=>[
1080 '$add'=>['$time',($offset*3600)*1000]
1081 ],
1082 'price'=>1,
1083 'type'=>1,
1084 'msisdn'=>1
1085
1086 ]
1087 ],
1088 [
1089 '$sort'=>['type'=>-1]
1090 ],
1091 [
1092 '$group'=>[
1093 '_id'=>[
1094 'product'=>'$product',
1095 'd'=>['$dayOfMonth'=>'$time'],
1096 'm'=>['$month'=>'$time'],
1097 'y'=>['$year'=>'$time'],
1098 'msisdn'=>'$msisdn',
1099 //'type'=>'$type',
1100 ],
1101 //'rev'=>['$sum'=>'$price'],
1102 'ft'=>[
1103 '$first'=>'$type'
1104
1105 ],
1106 'lt'=>['$last'=>'$type']
1107 ],
1108 ],
1109 [
1110 '$project'=>[
1111 '_id'=>1,
1112 'churn'=>[
1113 '$concat'=>['$ft','$lt']
1114 ]
1115 ]
1116 ],
1117 [
1118 '$group'=>[
1119 '_id'=>[
1120 'product'=>'$_id.product',
1121 'd'=>'$_id.d',
1122 'm'=>'$_id.m',
1123 'y'=>'$_id.y',
1124 //'type'=>'$type',
1125 ],
1126 'day_churn'=>[
1127 '$sum'=>[
1128 '$cond'=>[
1129 [
1130 '$eq'=>[
1131 '$churn','FC'
1132 ]
1133 ],1,0
1134 ]
1135 ]
1136 ]
1137 ]
1138 ],
1139 [
1140 '$sort'=>[
1141 '_id'=>-1
1142 ]
1143 ]
1144 ];
1145 if(isset($_GET['pid']) and $_GET['pid']!=''){
1146 unset($match['$match']['product']);
1147 $match['$match']['product_id']=['$in'=>$pids];
1148 }
1149 $pipeline4Hit=[
1150 $match,
1151 [
1152 '$project'=>[
1153 'msisdn'=>1,
1154 'time'=>[
1155 '$add'=>['$time',($offset*3600)*1000]
1156 ],
1157 'product_id'=>1
1158 ]
1159 ],
1160 [
1161 '$project'=>[
1162 'msisdn'=>1,
1163 'y'=>[
1164 '$substr'=>[
1165 ['$year'=>'$time'],0,4
1166 ]
1167 ],
1168 'm'=>[
1169 '$substr'=>[
1170 ['$month'=>'$time'],0,2
1171 ]
1172 ],
1173 'd'=>[
1174 '$substr'=>[
1175 ['$dayOfMonth'=>'$time'],0,2
1176 ]
1177 ],
1178 'product_id'=>1
1179 ]
1180 ],
1181 [
1182 '$group'=>[
1183 '_id'=>[
1184 'msisdn'=>'$msisdn',
1185 'hit_day'=>[
1186 '$concat'=>['$d','-','$m','-','$y','-','$product_id']
1187 ],
1188 ],
1189 'count'=>['$sum'=>1],
1190 'uniq_count'=>['$first'=>1]
1191 ]
1192 ],
1193 [
1194 '$group'=>[
1195 '_id'=>'$_id.hit_day',
1196 'total_hit'=>[
1197 '$sum'=>'$count'
1198 ],
1199 'uniq_hit'=>[
1200 '$sum'=>'$uniq_count'
1201 ]
1202 ]
1203 ]
1204 ];
1205 $options = array("allowDiskUse" => true);
1206 $result=(new MongoCampaignLog())->getCollection()->aggregate($pipeline,$options);
1207 //echo '<pre>',print_r($result);exit;
1208 $hit_result=(new MongoLogReq())->getCollection()->aggregate($pipeline4Hit,$options);
1209
1210 $day_result=(new MongoCampaignLog())->getCollection()->aggregate($pipelineDay,$options);
1211 $dayResult=$day_result['result'];
1212// echo '<pre>';print_r($hit_result);exit;
1213// print_r($pipeline4Hit);
1214// print_r($hit_result);exit;
1215 $hit_result=$hit_result['result'];
1216 $temp_result=$hit_result;
1217 unset($hit_result);
1218 foreach($temp_result as $v)
1219 {
1220 $hit_result[$v['_id']]=[
1221 'total_hit'=>$v['total_hit'],
1222 'uniq_hit'=>$v['uniq_hit'],
1223 ];
1224 }
1225 $result=$result['result'];
1226 $data=[];
1227 //for currency details
1228// $c_map=Yii::app()->mongodb->currency_map;
1229 foreach($result as $k=>$v)
1230 {
1231
1232 $data[$k]=$v;
1233 $data[$k]['product']=$v['_id']['product'];
1234 $data[$k]['productlink']=(new ProductEx())->getProductlink($v['_id']['product']);
1235// $currency=$c_map->findOne(["_id"=>$data[$k]['product']]);
1236// $data[$k]['rev_sgd']=($currency)? round(W::currencyConverter($currency['currency'], 'SGD', $v['rev']),3) : 0;
1237// $data[$k]['rev_inr']=($currency)? round(W::currencyConverter('SGD', 'INR', $data[$k]['rev_sgd']),3) : 0;
1238 $date="{$v['_id']['d']}-{$v['_id']['m']}-{$v['_id']['y']}";
1239 $data[$k]['date']=$date;
1240 $data[$k]['date']= date(W::getDateFormat(), strtotime($data[$k]['date']));
1241 $data[$k]['day_churn']=0;
1242 foreach($dayResult as $dayC){
1243 if($v['_id'] == $dayC['_id']){
1244 $data[$k]['day_churn']= $dayC['day_churn'];
1245 break;
1246 }
1247 }
1248
1249 $data[$k]['total_hit']=(int)"{$hit_result[$date.'-'.$data[$k]['product']]['total_hit']}";
1250 $data[$k]['uniq_hit']=(int)"{$hit_result[$date.'-'.$data[$k]['product']]['uniq_hit']}";
1251 unset($data[$k]['_id']);
1252 if($data[$k]['uniq_hit'] < 10 and $promote=='on'){
1253 unset($data[$k]);
1254 }
1255 }
1256 //for unique data
1257 /* $dataN=[];
1258 foreach ($data as $kk => $vv) {
1259 $flag=TRUE;
1260 foreach ($dataN as $kk2 => $vv2) {
1261 if($vv['product']==$vv2['product']){
1262 $dataN[$kk2]+=$vv2;
1263 $flag=FALSE;
1264 }
1265 }
1266 if($flag)
1267 {
1268 $dataN[]=$vv;
1269 }
1270 }*/
1271// echo "<pre>";print_r($dataN);exit;
1272 // Create a new CSort object
1273 $sort = new CSort();
1274 // One attribute for each column of data
1275 $sort->attributes = array(
1276 'rev',
1277 'date',
1278 'product',
1279 );
1280 // Set the default order
1281 $sort->defaultOrder = array(
1282 'product'=>CSort::SORT_DESC,
1283 );
1284 $dataProvider=new CArrayDataProvider($data, array( 'sort'=>$sort,'pagination'=>FALSE));
1285
1286 $this->render('reportx', ['dataProvider'=>$dataProvider]);
1287 }
1288 /**
1289 * Service ARPU
1290 */
1291 public function actionReportS()
1292 {
1293 ini_set('memory_limit', '512M');
1294 $final_data=[];
1295 $match=[
1296 '$match'=>[
1297 'type'=>[
1298 '$ne'=>MongoCampaignLog::TYPE_VALUEPACK
1299// '$eq'=>MongoCampaignLog::TYPE_CANCEL
1300 ]
1301 ]
1302 ];
1303 if($_GET['start_date'] and $_GET['end_date'])
1304 {
1305 $start_date= strtotime($_GET['start_date'].' 00:00:00');
1306 $end_date= strtotime($_GET['end_date'].' 23:59:59');
1307 $mongo_end_date=new MongoDate($end_date);
1308 $mongo_start_date=new MongoDate($start_date);
1309 $match['$match']['time']=[
1310 '$gte'=>$mongo_start_date,
1311 '$lte'=>$mongo_end_date,
1312 ];
1313 }else{
1314 $start_date=strtotime(date('Y-m')."-01 00:00:00");
1315 $end_date=strtotime(date('Y-m-d')." 23:59:59");
1316 $_GET['start_date']=date('Y-m')."-01";
1317 $_GET['end_date']=date('Y-m-d');
1318 $mongo_end_date=new MongoDate($end_date);
1319 $mongo_start_date=new MongoDate($start_date);
1320 $match['$match']['time']=[
1321 '$gte'=>$mongo_start_date,
1322 '$lte'=>$mongo_end_date,
1323 ];
1324 }
1325 if(isset($_GET['pid']) and $_GET['pid']!=''){
1326 $pids = explode(',', $_GET["pid"]);
1327 if($key = array_search(42, $pids))
1328 $pids[$key]=42;
1329 if($key = array_search(48, $pids))
1330 unset($pids[$key]);
1331
1332 $match['$match']['product']=['$in'=>$pids];
1333 }
1334// print_r($match);exit;
1335 $pipeline=[
1336 $match,
1337 [
1338 '$project'=>[
1339 '_id'=>1,
1340 'time'=>[
1341 '$add'=>['$time',(5.5*3600)*1000]
1342 ],
1343 'product'=>['$substr'=>['$product', 0, -1 ]],
1344 'msisdn'=>['$substr'=>['$msisdn', 0, -1 ]],
1345 'type'=>1,
1346 ]
1347 ],
1348 [
1349 '$group'=>[
1350 '_id'=>['$concat'=>['$product','-','$msisdn','-','$type']],
1351 'product'=>['$first'=>'$product'],
1352 'msisdn'=>['$first'=>'$msisdn'],
1353 'time'=>['$first'=>'$time'],
1354 'is_0bal'=>['$sum'=>[
1355 '$cond'=>[
1356 [
1357 '$or'=>[
1358 ['$eq'=>['$type', MongoCampaignLog::TYPE_PARK]],
1359 ['$eq'=>['$type', MongoCampaignLog::TYPE_GRACE]],
1360 ['$eq'=>['$type', MongoCampaignLog::TYPE_CANCEL]],
1361 ['$eq'=>['$type', MongoCampaignLog::TYPE_SUSPEND]]
1362 ]
1363 ],
1364 1,0
1365 ]
1366 ] ],
1367 ]
1368 ],
1369 [
1370 '$sort'=>[
1371 '_id'=>-1
1372 ]
1373 ]
1374 ];
1375 $result=(new MongoCampaignLog())->getCollection()->aggregate($pipeline,["allowDiskUse" => true]);
1376 $distNumbers=[];
1377 foreach ($result['result'] as $key => $value) {
1378 if($value['is_0bal']==0)
1379 $distNumbers[$value['product']][]=(string)$value['msisdn'];
1380 }
1381// echo '<pre>',print_r($result);print_r($distNumbers);exit;
1382 foreach ($distNumbers as $key => $value) {
1383 $product_id=(string)$key;
1384 if($key==42)
1385 $product_id=(int)$key;
1386// array_
1387 $msisdns = array_values(array_unique($value));
1388// print_r(($msisdns));exit;
1389 $match2=[
1390 '$match'=>[
1391// 'time'=>[
1392// '$gte'=>$mongo_start_date,
1393// '$lte'=>$mongo_end_date,
1394// ],
1395 'type'=>[
1396 '$ne'=>MongoCampaignLog::TYPE_VALUEPACK
1397// '$eq'=>MongoCampaignLog::TYPE_CANCEL
1398 ],
1399 'msisdn'=>[
1400 '$in'=>$msisdns
1401 ],
1402 'product'=>[
1403 '$eq'=>$product_id
1404 ]
1405 ]
1406 ];
1407 if($_GET['start_date'] and $_GET['end_date'])
1408 {
1409 $start_date= strtotime($_GET['start_date'].' 00:00:00');
1410 $end_date= strtotime($_GET['end_date'].' 23:59:59');
1411 $mongo_end_date=new MongoDate($end_date);
1412 $mongo_start_date=new MongoDate($start_date);
1413 $match2['$match']['time']=[
1414 '$gte'=>$mongo_start_date,
1415 '$lte'=>$mongo_end_date,
1416 ];
1417 }
1418 //print_r($match);exit;
1419 $pipeline2=[
1420 $match2,
1421 [
1422 '$project'=>[
1423 '_id'=>1,
1424 'product'=>1,
1425 'time'=>[
1426 '$add'=>['$time',(5.5*3600)*1000]
1427 ],
1428 'price'=>1,
1429 'type'=>1,
1430 'msisdn'=>1,
1431 ]
1432 ],
1433 [
1434 '$group'=>[
1435 '_id'=>'$product',
1436 'tot_ren'=>['$sum'=>[
1437 '$cond'=>[
1438 [
1439 '$or'=>[
1440 ['$eq'=>['$type', MongoCampaignLog::TYPE_PARK]],
1441 ['$eq'=>['$type', MongoCampaignLog::TYPE_GRACE]],
1442 ['$eq'=>['$type', MongoCampaignLog::TYPE_CANCEL]],
1443 ['$eq'=>['$type', MongoCampaignLog::TYPE_SUSPEND]]
1444 ]
1445 ],
1446 0,'$price'
1447 ]
1448 ] ],
1449 ]
1450 ],
1451 [
1452 '$sort'=>[
1453 '_id'=>-1
1454 ]
1455 ]
1456 ];
1457 $result1=(new MongoCampaignLog())->getCollection()->aggregate($pipeline2,["allowDiskUse" => true]);
1458 $data=$result1['result'][0];
1459 $tot_num=count($msisdns);
1460// $tot_num = $tot_num;//-$data['tot_0bal'];
1461 $final_data[]=['product'=>$product_id,'tot_number'=>$tot_num,'tot_amount'=>$data['tot_ren'],'sarpu'=> round($data['tot_ren']/$tot_num,2)];
1462 }
1463// echo '<pre>',print_r($final_data);exit;
1464 $data=$final_data;
1465 foreach($final_data as $k=>$v)
1466 {
1467 $product = (new ProductEx())->findByPk($v['product']);
1468 $data[$k]['productlink']=$product->productlink;
1469 }
1470 // Create a new CSort object
1471 $sort = new CSort();
1472 // One attribute for each column of data
1473 $sort->attributes = array(
1474 'rev',
1475// 'rev_sgd',
1476// 'rev_inr',
1477 'product',
1478 );
1479 // Set the default order
1480 $sort->defaultOrder = array(
1481 'product'=>CSort::SORT_DESC,
1482 );
1483// echo '<pre>',print_r($data);exit;
1484 $dataProvider=new CArrayDataProvider($data, array( 'sort'=>$sort,'pagination'=>FALSE));
1485 $this->render('reports', ['dataProvider'=>$dataProvider]);
1486 }
1487 /**
1488 * Revenue Report for KW
1489 */
1490 public function actionKwreport()
1491 {
1492 $className='SubOoredoo';
1493 $start_date=date('Y-m-d')." 00:00:00";
1494 $end_date=date('Y-m-d')." 23:59:59";
1495 if($_GET['start_date'] and $_GET['end_date'])
1496 {
1497 $start_date= $_GET['start_date'].' 00:00:00';
1498 $end_date= $_GET['end_date'].' 23:59:59';
1499 }else{
1500 $_GET['start_date']=date('Y-m-d');
1501 $_GET['end_date']=date('Y-m-d');
1502 }
1503
1504 $getTimeZone= Common::getTimeZoneByClass($className);
1505 $dateT = new DateTime(date('Y-m-d H:i:s'));
1506 $dateT->setTimezone(new DateTimeZone($getTimeZone));
1507 $offset=($dateT->getOffset()/(60*60));
1508 //previous date
1509 // $start_date=strtoTime(W::setTimeStamp($start_date, $className));
1510 // $end_date=strtoTime(W::setTimeStamp($end_date, $className));
1511
1512 $productList=(new ProductEx())->getProductByClass($className);
1513 //echo "<pre>";print_r($productList);exit;
1514 $endTime=strtotime($end_date)-(($offset-5.5)*3600);
1515 $startTime=strtotime($start_date)-(($offset-5.5)*3600);
1516 $mongo_end_date=new MongoDate($endTime);
1517 $mongo_start_date=new MongoDate($startTime);
1518 $match=[
1519 '$match'=>[
1520 'time'=>[
1521 '$gte'=>$mongo_start_date,
1522 '$lte'=>$mongo_end_date,
1523 ],
1524 'type'=>[
1525 '$ne'=>'V'
1526 ],
1527 'mtype'=>[
1528 '$exists'=>true
1529 ],
1530 'product'=>[
1531 '$in'=>$productList
1532 ]
1533 ]
1534 ];
1535 $pipeline=[
1536 $match,
1537 [
1538 '$project'=>[
1539 '_id'=>1,
1540 'product'=>1,
1541 'mtype'=>1,
1542 'time'=>[
1543 '$add'=>['$time',($offset*3600)*1000]
1544 ],
1545 'price'=>1,
1546 'type'=>1
1547 ]
1548 ],
1549 [
1550 '$group'=>[
1551 '_id'=>[
1552 'product'=>'$product',
1553 'mtype'=>'$mtype',
1554 'd'=>['$dayOfMonth'=>'$time'],
1555 'm'=>['$month'=>'$time'],
1556 'y'=>['$year'=>'$time'],
1557 ],
1558 'rev'=>['$sum'=>'$price'],
1559 'fresh'=>[
1560 '$sum'=>
1561 [
1562 '$cond'=>[
1563 [
1564 '$eq'=>[
1565 '$type',
1566 'F'
1567 ]
1568 ],
1569 1,0
1570 ]
1571 ]
1572 ],
1573 'zero_balance'=>[
1574 '$sum'=>[
1575 '$cond'=>[
1576 [
1577 '$eq'=>[
1578 '$type',
1579 'P'
1580 ]
1581 ],
1582 1,0
1583 ]
1584 ]
1585 ],
1586 'fresh_rev'=>[
1587 '$sum'=>
1588 [
1589 '$cond'=>[
1590 [
1591 '$eq'=>[
1592 '$type',
1593 'F'
1594 ]
1595 ],
1596 '$price',0
1597 ]
1598 ]
1599 ],
1600 'churn'=>[
1601 '$sum'=>
1602 [
1603 '$cond'=>[
1604 [
1605 '$eq'=>[
1606 '$type',
1607 'C'
1608 ]
1609 ],
1610 1,0
1611 ]
1612 ]
1613 ],
1614 'sys_churn'=>[
1615 '$sum'=>
1616 [
1617 '$cond'=>[
1618 [
1619 '$eq'=>[
1620 '$type',
1621 'CH'
1622 ]
1623 ],
1624 1,0
1625 ]
1626 ]
1627 ],
1628 'renewal'=>[
1629 '$sum'=>
1630 [
1631 '$cond'=>[
1632 [
1633 '$eq'=>[
1634 '$type',
1635 'R'
1636 ]
1637 ],
1638 1,0
1639 ]
1640 ]
1641 ],
1642 'renewal_rev'=>[
1643 '$sum'=>
1644 [
1645 '$cond'=>[
1646 [
1647 '$eq'=>[
1648 '$type',
1649 'R'
1650 ]
1651 ],
1652 '$price',0
1653 ]
1654 ]
1655 ],
1656 'park_to_active'=>[
1657 '$sum'=>[
1658 '$cond'=>[
1659 [
1660 '$eq'=>[
1661 '$type',
1662 'PA'
1663 ]
1664 ],
1665 1,0
1666 ]
1667 ]
1668 ],
1669 'pta_rev'=>[
1670 '$sum'=>
1671 [
1672 '$cond'=>[
1673 [
1674 '$eq'=>[
1675 '$type',
1676 'PA'
1677 ]
1678 ],
1679 '$price',0
1680 ]
1681 ]
1682 ],
1683 'suspend_to_active'=>[
1684 '$sum'=>[
1685 '$cond'=>[
1686 [
1687 '$eq'=>[
1688 '$type',
1689 'SA'
1690 ]
1691 ],
1692 1,0
1693 ]
1694 ]
1695 ],
1696 'sta_rev'=>[
1697 '$sum'=>
1698 [
1699 '$cond'=>[
1700 [
1701 '$eq'=>[
1702 '$type',
1703 'SA'
1704 ]
1705 ],
1706 '$price',0
1707 ]
1708 ]
1709 ],
1710 'suspend'=>[
1711 '$sum'=>[
1712 '$cond'=>[
1713 [
1714 '$eq'=>[
1715 '$type',
1716 'S'
1717 ]
1718 ],
1719 1,0
1720 ]
1721 ]
1722 ],
1723 ]
1724 ],
1725 [
1726 '$sort'=>[
1727 '_id'=>-1
1728 ]
1729 ]
1730 ];
1731
1732 $pipelineDay=[
1733 $match,
1734 [
1735 '$match'=>[
1736 'type'=>[
1737 '$in'=>['F','C']
1738 ]
1739 ]
1740 ],
1741 [
1742 '$project'=>[
1743 '_id'=>1,
1744 'product'=>1,
1745 'time'=>[
1746 '$add'=>['$time',($offset*3600)*1000]
1747 ],
1748 'price'=>1,
1749 'type'=>1,
1750 'msisdn'=>1,
1751 'mtype'=>1
1752
1753 ]
1754 ],
1755 [
1756 '$sort'=>['type'=>-1]
1757 ],
1758 [
1759 '$group'=>[
1760 '_id'=>[
1761 'product'=>'$product',
1762 'mtype'=>'$mtype',
1763 'd'=>['$dayOfMonth'=>'$time'],
1764 'm'=>['$month'=>'$time'],
1765 'y'=>['$year'=>'$time'],
1766 'msisdn'=>'$msisdn',
1767 //'type'=>'$type',
1768 ],
1769 //'rev'=>['$sum'=>'$price'],
1770 'ft'=>[
1771 '$first'=>'$type'
1772
1773 ],
1774 'lt'=>['$last'=>'$type']
1775 ],
1776 ],
1777 [
1778 '$project'=>[
1779 '_id'=>1,
1780 'churn'=>[
1781 '$concat'=>['$ft','$lt']
1782 ]
1783 ]
1784 ],
1785 [
1786 '$group'=>[
1787 '_id'=>[
1788 'product'=>'$_id.product',
1789 'mtype'=>'$_id.mtype',
1790 'd'=>'$_id.d',
1791 'm'=>'$_id.m',
1792 'y'=>'$_id.y',
1793 //'type'=>'$type',
1794 ],
1795 'day_churn'=>[
1796 '$sum'=>[
1797 '$cond'=>[
1798 [
1799 '$eq'=>[
1800 '$churn','FC'
1801 ]
1802 ],1,0
1803 ]
1804 ]
1805 ]
1806 ]
1807 ],
1808 [
1809 '$sort'=>[
1810 '_id'=>-1
1811 ]
1812 ]
1813 ];
1814
1815 $result=(new MongoCampaignLog())->getCollection()->aggregate($pipeline);
1816
1817 // $hit_result=(new MongoLogReq())->getCollection()->aggregate($pipeline4Hit);
1818
1819 $day_result=(new MongoCampaignLog())->getCollection()->aggregate($pipelineDay);
1820 $dayResult=$day_result['result'];
1821 //echo '<pre>',print_r($dayResult);exit;
1822 //echo '<pre>',print_r($hit_result);exit;
1823 //print_r($pipeline4Hit);
1824 //print_r($hit_result);exit;
1825 /*$hit_result=$hit_result['result'];
1826 $temp_result=$hit_result;
1827 unset($hit_result);
1828 foreach($temp_result as $v)
1829 {
1830 $hit_result[$v['_id']]=[
1831 'total_hit'=>$v['total_hit'],
1832 'uniq_hit'=>$v['uniq_hit'],
1833 ];
1834 }*/
1835 //print_r($hit_result);
1836 //exit;
1837 $result=$result['result'];
1838 $data=[];
1839 foreach($result as $k=>$v)
1840 {
1841
1842 $data[$k]=$v;
1843 $data[$k]['product']=$v['_id']['product'];
1844 $data[$k]['mtype']=$v['_id']['mtype'];
1845 $date="{$v['_id']['d']}-{$v['_id']['m']}-{$v['_id']['y']}";
1846 $data[$k]['date']=$date;
1847 $data[$k]['date']= date(W::getDateFormat(), strtotime($data[$k]['date']));
1848 $data[$k]['day_churn']=0;
1849 foreach($dayResult as $dayC){
1850 if($v['_id'] == $dayC['_id']){
1851 $data[$k]['day_churn']= $dayC['day_churn'];
1852 break;
1853 }
1854 }
1855
1856 // $data[$k]['total_hit']="{$hit_result[$date.'-'.$data[$k]['product'].'-'.$data[$k]['mtype']]['total_hit']}";
1857 // $data[$k]['uniq_hit']="{$hit_result[$date.'-'.$data[$k]['product'].'-'.$data[$k]['mtype']]['uniq_hit']}";
1858 unset($data[$k]['_id']);
1859 }
1860
1861 // Create a new CSort object
1862 $sort = new CSort();
1863 // One attribute for each column of data
1864 $sort->attributes = array(
1865 'date','product'
1866 );
1867 // Set the default order
1868 $sort->defaultOrder = array(
1869 'date'=>CSort::SORT_DESC,
1870 );
1871 $dataProvider=new CArrayDataProvider($data, array( 'sort'=>$sort));
1872
1873 $this->render('kwreport', ['dataProvider'=>$dataProvider]);
1874 }
1875
1876 /**
1877 * get Hourly revenue report
1878 */
1879 public function actionHrReport()
1880 {
1881 $start_date=strtotime(date('Y-m-d')." 00:00:00");
1882 $end_date=strtotime(date('Y-m-d')." 23:59:59");
1883 $product=$_GET['product_id'];
1884 if($_GET['start_date'] and $_GET['end_date'])
1885 {
1886 $start_date= strtotime($_GET['start_date'].' 00:00:00');
1887 $end_date= strtotime($_GET['end_date'].' 23:59:59');
1888 }
1889 $mongo_end_date=new MongoDate($end_date);
1890 $mongo_start_date=new MongoDate($start_date);
1891 $match=[
1892 '$match'=>[
1893 'time'=>[
1894 '$gte'=>$mongo_start_date,
1895 '$lte'=>$mongo_end_date,
1896 ],
1897 'type'=>[
1898 '$ne'=>'V'
1899 ],
1900
1901 ]
1902 ];
1903 $pipeline=[
1904 $match,
1905 [
1906 '$match'=>[
1907 'product'=> [
1908 '$eq'=> $product
1909 ],
1910 ]
1911 ],
1912 [
1913 '$project'=>[
1914 '_id'=>1,
1915 'product'=>1,
1916 'time'=>[
1917 '$add'=>['$time',(5.5*3600)*1000]
1918 ],
1919 'price'=>1,
1920 'type'=>1
1921
1922 ]
1923 ],
1924 [
1925 '$group'=>[
1926 '_id'=>[
1927 'product'=>'$product',
1928 'd'=>['$dayOfMonth'=>'$time'],
1929 'm'=>['$month'=>'$time'],
1930 'y'=>['$year'=>'$time'],
1931 'h'=>['$hour'=>'$time'],
1932 ],
1933 'rev'=>['$sum'=>'$price'],
1934 'grace'=>[
1935 '$sum'=>
1936 [
1937 '$cond'=>[
1938 [
1939 '$eq'=>[
1940 '$type',
1941 'G'
1942 ]
1943 ],
1944 1,0
1945 ]
1946 ]
1947 ],
1948 'fresh'=>[
1949 '$sum'=>
1950 [
1951 '$cond'=>[
1952 [
1953 '$eq'=>[
1954 '$type',
1955 'F'
1956 ]
1957 ],
1958 1,0
1959 ]
1960 ]
1961 ],
1962 'zero_balance'=>[
1963 '$sum'=>[
1964 '$cond'=>[
1965 [
1966 '$eq'=>[
1967 '$type',
1968 'P'
1969 ]
1970
1971 ],
1972 1,0
1973 ]
1974 ]
1975 ],
1976 'fresh_rev'=>[
1977 '$sum'=>
1978 [
1979 '$cond'=>[
1980 [
1981 '$eq'=>[
1982 '$type',
1983 'F'
1984 ]
1985 ],
1986 '$price',0
1987 ]
1988 ]
1989 ],
1990 'churn'=>[
1991 '$sum'=>
1992 [
1993 '$cond'=>[
1994 [
1995 '$eq'=>[
1996 '$type',
1997 'C'
1998 ]
1999 ],
2000 1,0
2001 ]
2002 ]
2003 ],
2004 'renewal'=>[
2005 '$sum'=>
2006 [
2007 '$cond'=>[
2008 [
2009 '$eq'=>[
2010 '$type',
2011 'R'
2012 ]
2013 ],
2014 1,0
2015 ]
2016 ]
2017 ],
2018 'renewal_rev'=>[
2019 '$sum'=>
2020 [
2021 '$cond'=>[
2022 [
2023 '$eq'=>[
2024 '$type',
2025 'R'
2026 ]
2027 ],
2028 '$price',0
2029 ]
2030 ]
2031 ],
2032 'park_to_active'=>[
2033 '$sum'=>[
2034 '$cond'=>[
2035 [
2036 '$eq'=>[
2037 '$type',
2038 'PA'
2039 ]
2040 ],
2041 1,0
2042 ]
2043 ]
2044 ],
2045 'grace_to_active'=>[
2046 '$sum'=>[
2047 '$cond'=>[
2048 [
2049 '$eq'=>[
2050 '$type',
2051 'GA'
2052 ]
2053 ],
2054 1,0
2055 ]
2056 ]
2057 ],
2058 'pta_rev'=>[
2059 '$sum'=>
2060 [
2061 '$cond'=>[
2062 [
2063 '$eq'=>[
2064 '$type',
2065 'PA'
2066 ]
2067 ],
2068 '$price',0
2069 ]
2070 ]
2071 ],
2072 'suspend_to_active'=>[
2073 '$sum'=>[
2074 '$cond'=>[
2075 [
2076 '$eq'=>[
2077 '$type',
2078 'SA'
2079 ]
2080 ],
2081 1,0
2082 ]
2083 ]
2084 ],
2085 'sta_rev'=>[
2086 '$sum'=>
2087 [
2088 '$cond'=>[
2089 [
2090 '$eq'=>[
2091 '$type',
2092 'SA'
2093 ]
2094 ],
2095 '$price',0
2096 ]
2097 ]
2098 ],
2099 'gta_rev'=>[
2100 '$sum'=>
2101 [
2102 '$cond'=>[
2103 [
2104 '$eq'=>[
2105 '$type',
2106 'GA'
2107 ]
2108 ],
2109 '$price',0
2110 ]
2111 ]
2112 ],
2113 'suspend'=>[
2114 '$sum'=>[
2115 '$cond'=>[
2116 [
2117 '$eq'=>[
2118 '$type',
2119 'S'
2120 ]
2121 ],
2122 1,0
2123 ]
2124 ]
2125 ],
2126 ]
2127 ],
2128 [
2129 '$sort'=>[
2130 '_id'=>-1
2131 ]
2132 ]
2133 ];
2134 $pipeline4Hit=[
2135 $match,
2136 [
2137 '$match'=>[
2138 'product_id'=> [
2139 '$eq'=> $product
2140 ],
2141 ]
2142 ],
2143 [
2144 '$project'=>[
2145 'msisdn'=>1,
2146 'time'=>[
2147 '$add'=>['$time',(5.5*3600)*1000]
2148 ],
2149 'product_id'=>1
2150 ]
2151 ],
2152 [
2153 '$project'=>[
2154 'msisdn'=>1,
2155 'y'=>[
2156 '$substr'=>[
2157 ['$year'=>'$time'],0,4
2158 ]
2159 ],
2160 'm'=>[
2161 '$substr'=>[
2162 ['$month'=>'$time'],0,2
2163 ]
2164 ],
2165 'd'=>[
2166 '$substr'=>[
2167 ['$dayOfMonth'=>'$time'],0,2
2168 ]
2169 ],
2170 'h'=>[
2171 '$substr'=>[
2172 ['$hour'=>'$time'],0,2
2173 ]
2174 ],
2175 'product_id'=>1
2176 ]
2177 ],
2178 [
2179 '$group'=>[
2180 '_id'=>[
2181 'msisdn'=>'$msisdn',
2182 'hit_day'=>[
2183 '$concat'=>['$d','-','$m','-','$y','-','$h','-','$product_id']
2184 ],
2185 ],
2186 'count'=>['$sum'=>1],
2187 'uniq_count'=>['$first'=>1]
2188 ]
2189 ],
2190 [
2191 '$group'=>[
2192 '_id'=>'$_id.hit_day',
2193 'total_hit'=>[
2194 '$sum'=>'$count'
2195 ],
2196 'uniq_hit'=>[
2197 '$sum'=>'$uniq_count'
2198 ]
2199 ]
2200 ],
2201 [
2202 '$limit'=>24,
2203 ]
2204 ];
2205
2206 $pipelineDay=[
2207 $match,
2208 [
2209 '$match'=>[
2210 'type'=>[
2211 '$in'=>['F','C']
2212 ]
2213 ]
2214 ],
2215 [
2216 '$project'=>[
2217 '_id'=>1,
2218 'product'=>1,
2219 'time'=>[
2220 '$add'=>['$time',(5.5*3600)*1000]
2221 ],
2222 'price'=>1,
2223 'type'=>1,
2224 'msisdn'=>1
2225
2226 ]
2227 ],
2228 [
2229 '$sort'=>['type'=>-1]
2230 ],
2231 [
2232 '$group'=>[
2233 '_id'=>[
2234 'product'=>'$product',
2235 'd'=>['$dayOfMonth'=>'$time'],
2236 'm'=>['$month'=>'$time'],
2237 'y'=>['$year'=>'$time'],
2238 'h'=>['$hour'=>'$time'],
2239 'msisdn'=>'$msisdn',
2240 //'type'=>'$type',
2241 ],
2242 //'rev'=>['$sum'=>'$price'],
2243 'ft'=>[
2244 '$first'=>'$type'
2245
2246 ],
2247 'lt'=>['$last'=>'$type']
2248 ],
2249 ],
2250 [
2251 '$project'=>[
2252 '_id'=>1,
2253 'churn'=>[
2254 '$concat'=>['$ft','$lt']
2255 ]
2256 ]
2257 ],
2258 [
2259 '$group'=>[
2260 '_id'=>[
2261 'product'=>'$_id.product',
2262 'd'=>'$_id.d',
2263 'm'=>'$_id.m',
2264 'y'=>'$_id.y',
2265 'h'=>'$_id.h',
2266 //'type'=>'$type',
2267 ],
2268 'day_churn'=>[
2269 '$sum'=>[
2270 '$cond'=>[
2271 [
2272 '$eq'=>[
2273 '$churn','FC'
2274 ]
2275 ],1,0
2276 ]
2277 ]
2278 ]
2279 ]
2280 ],
2281 [
2282 '$sort'=>[
2283 '_id'=>-1
2284 ]
2285 ]
2286 ];
2287 $result=(new MongoCampaignLog())->getCollection()->aggregate($pipeline);
2288 //echo '<pre>',print_r($result);exit;
2289 $hit_result=(new MongoLogReq())->getCollection()->aggregate($pipeline4Hit);
2290
2291 $day_result=(new MongoCampaignLog())->getCollection()->aggregate($pipelineDay);
2292 $dayResult=$day_result['result'];
2293 //echo '<pre>',print_r($hit_result);exit;
2294 //print_r($pipeline4Hit);
2295 // print_r($hit_result);exit;
2296 $hit_result=$hit_result['result'];
2297 $temp_result=$hit_result;
2298 unset($hit_result);
2299 foreach($temp_result as $v)
2300 {
2301 $hit_result[$v['_id']]=[
2302 'total_hit'=>$v['total_hit'],
2303 'uniq_hit'=>$v['uniq_hit'],
2304 ];
2305 }
2306 //print_r($hit_result);
2307 //exit;
2308 $result=$result['result'];
2309 $data=[];
2310 foreach($result as $k=>$v)
2311 {
2312
2313 $data[$k]=$v;
2314 $data[$k]['product']=$v['_id']['product'];
2315 $date="{$v['_id']['d']}-{$v['_id']['m']}-{$v['_id']['y']}";
2316 $data[$k]['hour']=$v['_id']['h'];
2317 $data[$k]['date']=$date;
2318 $data[$k]['date']= date(W::getDateFormat(), strtotime($data[$k]['date']));
2319 $data[$k]['day_churn']=0;
2320 foreach($dayResult as $dayC){
2321 if($v['_id'] == $dayC['_id']){
2322 $data[$k]['day_churn']= $dayC['day_churn'];
2323 break;
2324 }
2325 }
2326
2327 $data[$k]['total_hit']="{$hit_result[$date.'-'.$data[$k]['hour'].'-'.$data[$k]['product']]['total_hit']}";
2328 $data[$k]['uniq_hit']="{$hit_result[$date.'-'.$data[$k]['hour'].'-'.$data[$k]['product']]['uniq_hit']}";
2329 unset($data[$k]['_id']);
2330 }
2331 // echo "<pre>";print_r($data);exit;
2332 // Create a new CSort object
2333 $sort = new CSort();
2334 // One attribute for each column of data
2335 $sort->attributes = array(
2336 'hour',
2337 );
2338 // Set the default order
2339 $sort->defaultOrder = array(
2340 'hour'=>CSort::SORT_DESC,
2341 );
2342 $dataProvider=new CArrayDataProvider($data, array( 'sort'=>$sort, 'pagination'=>false));
2343
2344 $this->render('hr_report', ['dataProvider'=>$dataProvider]);
2345 }
2346
2347 /**
2348 * Currency Report For All
2349 */
2350 public function actionReportC()
2351 {
2352 $start_date=strtotime(date('Y-m')."-01 00:00:00");
2353 $end_date=strtotime(date('Y-m-d')." 23:59:59");
2354 if($_GET['start_date'] and $_GET['end_date'])
2355 {
2356 $start_date= strtotime($_GET['start_date'].' 00:00:00');
2357 $end_date= strtotime($_GET['end_date'].' 23:59:59');
2358 }
2359 else{
2360 $_GET['start_date']=date('Y-m')."-01";
2361 $_GET['end_date']=date('Y-m-d');
2362 }
2363 $mongo_end_date=new MongoDate($end_date);
2364 $mongo_start_date=new MongoDate($start_date);
2365// $pid=$_GET['pid'];
2366 $match=[
2367 '$match'=>[
2368 'time'=>[
2369 '$gte'=>$mongo_start_date,
2370 '$lte'=>$mongo_end_date,
2371 ],
2372 'type'=>[
2373 '$ne'=>'V'
2374 ]
2375 ]
2376 ];
2377
2378 //print_r($match);exit;
2379 $pipeline=[
2380 $match,
2381 [
2382 '$project'=>[
2383 '_id'=>1,
2384 'product'=>1,
2385 'time'=>[
2386 '$add'=>['$time',(5.5*3600)*1000]
2387 ],
2388 'price'=>1,
2389 'type'=>1
2390
2391 ]
2392 ],
2393 [
2394 '$group'=>[
2395 '_id'=>[
2396 'product'=>'$product'
2397 ],
2398 'rev'=>['$sum'=>[
2399 '$cond'=>[
2400 [
2401 '$or'=>[
2402 ['$eq'=>['$type', MongoCampaignLog::TYPE_PARK]],
2403 ['$eq'=>['$type', MongoCampaignLog::TYPE_GRACE]],
2404 ['$eq'=>['$type', MongoCampaignLog::TYPE_CANCEL]],
2405 ['$eq'=>['$type', MongoCampaignLog::TYPE_SUSPEND]]
2406 ]
2407 ],
2408 0,'$price'
2409 ]
2410 ] ],
2411 'fresh'=>[
2412 '$sum'=>
2413 [
2414 '$cond'=>[
2415 [
2416 '$eq'=>[
2417 '$type',
2418 'F'
2419 ]
2420 ],
2421 1,0
2422 ]
2423 ]
2424 ],
2425
2426 'fresh_rev'=>[
2427 '$sum'=>
2428 [
2429 '$cond'=>[
2430 [
2431 '$eq'=>[
2432 '$type',
2433 'F'
2434 ]
2435 ],
2436 '$price',0
2437 ]
2438 ]
2439 ],
2440
2441 'renewal'=>[
2442 '$sum'=>
2443 [
2444 '$cond'=>[
2445 [
2446 '$eq'=>[
2447 '$type',
2448 'R'
2449 ]
2450 ],
2451 1,0
2452 ]
2453 ]
2454 ],
2455 'renewal_rev'=>[
2456 '$sum'=>
2457 [
2458 '$cond'=>[
2459 [
2460 '$eq'=>[
2461 '$type',
2462 'R'
2463 ]
2464 ],
2465 '$price',0
2466 ]
2467 ]
2468 ],
2469 ]
2470 ],
2471 [
2472 '$sort'=>[
2473 '_id'=>-1
2474 ]
2475 ]
2476 ];
2477
2478 $result=(new MongoCampaignLog())->getCollection()->aggregate($pipeline);
2479// echo '<pre>',print_r($result);exit;
2480
2481 $result=$result['result'];
2482 $data=[];
2483 $total=['t_sgd'=>0,'t_inr'=>0];
2484 foreach($result as $k=>$v)
2485 {
2486 $data[$k]=$v;
2487 $data[$k]['product']=$v['_id']['product'];
2488 $product = (new ProductEx())->findByPk($v['_id']['product']);
2489 $data[$k]['productlink']=$product->productlink;
2490 $currency=$product->conf['pro_currency'];
2491 $rev=$v['rev'];
2492 if($product->className=='SubEtisalat')
2493 $rev=$rev/100;
2494 if($product->className=='SubOoredoo')
2495 $rev=$rev/1000;
2496 $sgd=round(W::currencyConverter($currency, 'SGD', $rev),3);
2497 $inr=round(W::currencyConverter('SGD', 'INR', $sgd));
2498 $total['t_sgd']+=$sgd;
2499 $total['t_inr']+=$inr;
2500 $data[$k]['rev_sgd']=($currency)? money_format('%!i',$sgd) : 0;
2501 setlocale(LC_MONETARY, 'en_IN');
2502 $data[$k]['rev_inr']=($currency)? money_format('%!i',$inr) : 0;
2503 $data[$k]['rev']=$rev." ".$currency;
2504 $date="{$v['_id']['d']}-{$v['_id']['m']}-{$v['_id']['y']}";
2505 $data[$k]['date']=$date;
2506 unset($data[$k]['_id']);
2507 }
2508 $total['t_inr']=($total['t_inr'])? money_format('%!i',$total['t_inr']) : 0;
2509 // Create a new CSort object
2510 $sort = new CSort();
2511 // One attribute for each column of data
2512 $sort->attributes = array(
2513 'rev',
2514// 'rev_sgd',
2515// 'rev_inr',
2516 'product',
2517 );
2518 // Set the default order
2519 $sort->defaultOrder = array(
2520 'product'=>CSort::SORT_DESC,
2521 );
2522 $dataProvider=new CArrayDataProvider($data, array( 'sort'=>$sort,'pagination'=>FALSE));
2523
2524 $this->render('currencyreport', ['dataProvider'=>$dataProvider,'total'=>$total]);
2525 }
2526
2527 /**
2528 * Revenue Report For view all
2529 */
2530 public function actionReportMtnza()
2531 {
2532 $start_date=strtotime(date('Y-m-d')." 00:00:00");
2533 $end_date=strtotime(date('Y-m-d')." 23:59:59");
2534 if($_GET['start_date'] and $_GET['end_date'])
2535 {
2536 $start_date= strtotime($_GET['start_date'].' 00:00:00');
2537 $end_date= strtotime($_GET['end_date'].' 23:59:59');
2538 }else{
2539 $_GET['start_date']=date('Y-m-d');
2540 $_GET['end_date']=date('Y-m-d');
2541 }
2542 $mongo_end_date=new MongoDate($end_date);
2543 $mongo_start_date=new MongoDate($start_date);
2544// $refcoll = (new Oxy8SaCb)->getRefCollection();
2545// $msisdns=[];
2546// $records=$refcoll->distinct('msisdn');
2547 $cbColl = Yii::app()->mongodb->callback_log;
2548 $msisdns=[];
2549 $records=$cbColl->distinct('msisdn',['carrier'=>'mtn-za']);
2550 foreach ($records as $refs) {
2551 $msisdns[]=$refs;
2552 }
2553// echo count($msisdns);exit;
2554// print_r($msisdns);exit;
2555// $pid=$_GET['pid'];
2556 $match=[
2557 '$match'=>[
2558 'time'=>[
2559 '$gte'=>$mongo_start_date,
2560 '$lte'=>$mongo_end_date,
2561 ],
2562 'type'=>[
2563 '$ne'=>'V'
2564 ],
2565 'msisdn'=>[
2566 '$in'=>$msisdns
2567 ]
2568 ]
2569 ];
2570
2571 //print_r($match);exit;
2572 $pipeline=[
2573 $match,
2574 [
2575 '$project'=>[
2576 '_id'=>1,
2577 'product'=>1,
2578 'time'=>[
2579 '$add'=>['$time',(5.5*3600)*1000]
2580 ],
2581 'price'=>1,
2582 'type'=>1
2583
2584 ]
2585 ],
2586 [
2587 '$group'=>[
2588 '_id'=>[
2589 'product'=>'$product',
2590 'd'=>['$dayOfMonth'=>'$time'],
2591 'm'=>['$month'=>'$time'],
2592 'y'=>['$year'=>'$time'],
2593 ],
2594 'rev'=>['$sum'=>[
2595 '$cond'=>[
2596 [
2597 '$or'=>[
2598 ['$eq'=>['$type', MongoCampaignLog::TYPE_PARK]],
2599 ['$eq'=>['$type', MongoCampaignLog::TYPE_GRACE]],
2600 ['$eq'=>['$type', MongoCampaignLog::TYPE_CANCEL]],
2601 ['$eq'=>['$type', MongoCampaignLog::TYPE_SUSPEND]]
2602 ]
2603 ],
2604 0,'$price'
2605 ]
2606 ] ],
2607 'fresh'=>[
2608 '$sum'=>
2609 [
2610 '$cond'=>[
2611 [
2612 '$eq'=>[
2613 '$type',
2614 'F'
2615 ]
2616 ],
2617 1,0
2618 ]
2619 ]
2620 ],
2621 'zero_balance'=>[
2622 '$sum'=>[
2623 '$cond'=>[
2624 [
2625 '$eq'=>[
2626 '$type',
2627 'P'
2628 ]
2629 ],
2630 1,0
2631 ]
2632 ]
2633 ],
2634 'grace_user'=>[
2635 '$sum'=>[
2636 '$cond'=>[
2637 [
2638 '$eq'=>[
2639 '$type',
2640 'G'
2641 ]
2642 ],
2643 1,0
2644 ]
2645 ]
2646 ],
2647 'suspend'=>[
2648 '$sum'=>[
2649 '$cond'=>[
2650 [
2651 '$eq'=>[
2652 '$type',
2653 'S'
2654 ]
2655 ],
2656 1,0
2657 ]
2658 ]
2659 ],
2660 'fresh_rev'=>[
2661 '$sum'=>
2662 [
2663 '$cond'=>[
2664 [
2665 '$eq'=>[
2666 '$type',
2667 'F'
2668 ]
2669 ],
2670 '$price',0
2671 ]
2672 ]
2673 ],
2674 'churn'=>[
2675 '$sum'=>
2676 [
2677 '$cond'=>[
2678 [
2679 '$eq'=>[
2680 '$type',
2681 'C'
2682 ]
2683 ],
2684 1,0
2685 ]
2686 ]
2687 ],
2688 'renewal'=>[
2689 '$sum'=>
2690 [
2691 '$cond'=>[
2692 [
2693 '$eq'=>[
2694 '$type',
2695 'R'
2696 ]
2697 ],
2698 1,0
2699 ]
2700 ]
2701 ],
2702 'renewal_rev'=>[
2703 '$sum'=>
2704 [
2705 '$cond'=>[
2706 [
2707 '$eq'=>[
2708 '$type',
2709 'R'
2710 ]
2711 ],
2712 '$price',0
2713 ]
2714 ]
2715 ],
2716 ]
2717 ],
2718 [
2719 '$sort'=>[
2720 '_id'=>-1
2721 ]
2722 ]
2723 ];
2724// echo '<pre>';
2725// print_r($pipeline);exit;
2726 $pipeline4Hit=[
2727 $match,
2728 [
2729 '$project'=>[
2730 'msisdn'=>1,
2731 'time'=>[
2732 '$add'=>['$time',(5.5*3600)*1000]
2733 ],
2734 'product_id'=>1
2735 ]
2736 ],
2737 [
2738 '$project'=>[
2739 'msisdn'=>1,
2740 'y'=>[
2741 '$substr'=>[
2742 ['$year'=>'$time'],0,4
2743 ]
2744 ],
2745 'm'=>[
2746 '$substr'=>[
2747 ['$month'=>'$time'],0,2
2748 ]
2749 ],
2750 'd'=>[
2751 '$substr'=>[
2752 ['$dayOfMonth'=>'$time'],0,2
2753 ]
2754 ],
2755 'product_id'=>1
2756 ]
2757 ],
2758 [
2759 '$group'=>[
2760 '_id'=>[
2761 'msisdn'=>'$msisdn',
2762 'hit_day'=>[
2763 '$concat'=>['$d','-','$m','-','$y','-','$product_id']
2764 ],
2765 ],
2766 'count'=>['$sum'=>1],
2767 'uniq_count'=>['$first'=>1]
2768 ]
2769 ],
2770 [
2771 '$group'=>[
2772 '_id'=>'$_id.hit_day',
2773 'total_hit'=>[
2774 '$sum'=>'$count'
2775 ],
2776 'uniq_hit'=>[
2777 '$sum'=>'$uniq_count'
2778 ]
2779 ]
2780 ]
2781 ];
2782
2783 $pipelineDay=[
2784 $match,
2785 [
2786 '$match'=>[
2787 'type'=>[
2788 '$in'=>['F','C']
2789 ]
2790 ]
2791 ],
2792 [
2793 '$project'=>[
2794 '_id'=>1,
2795 'product'=>1,
2796 'time'=>[
2797 '$add'=>['$time',(5.5*3600)*1000]
2798 ],
2799 'price'=>1,
2800 'type'=>1,
2801 'msisdn'=>1
2802
2803 ]
2804 ],
2805 [
2806 '$sort'=>['type'=>-1]
2807 ],
2808 [
2809 '$group'=>[
2810 '_id'=>[
2811 'product'=>'$product',
2812 'd'=>['$dayOfMonth'=>'$time'],
2813 'm'=>['$month'=>'$time'],
2814 'y'=>['$year'=>'$time'],
2815 'msisdn'=>'$msisdn',
2816 //'type'=>'$type',
2817 ],
2818 //'rev'=>['$sum'=>'$price'],
2819 'ft'=>[
2820 '$first'=>'$type'
2821
2822 ],
2823 'lt'=>['$last'=>'$type']
2824 ],
2825 ],
2826 [
2827 '$project'=>[
2828 '_id'=>1,
2829 'churn'=>[
2830 '$concat'=>['$ft','$lt']
2831 ]
2832 ]
2833 ],
2834 [
2835 '$group'=>[
2836 '_id'=>[
2837 'product'=>'$_id.product',
2838 'd'=>'$_id.d',
2839 'm'=>'$_id.m',
2840 'y'=>'$_id.y',
2841 //'type'=>'$type',
2842 ],
2843 'day_churn'=>[
2844 '$sum'=>[
2845 '$cond'=>[
2846 [
2847 '$eq'=>[
2848 '$churn','FC'
2849 ]
2850 ],1,0
2851 ]
2852 ]
2853 ]
2854 ]
2855 ],
2856 [
2857 '$sort'=>[
2858 '_id'=>-1
2859 ]
2860 ]
2861 ];
2862 $result=(new MongoCampaignLog())->getCollection()->aggregate($pipeline);
2863 //echo '<pre>',print_r($result);exit;
2864 $hit_result=(new MongoLogReq())->getCollection()->aggregate($pipeline4Hit);
2865
2866 $day_result=(new MongoCampaignLog())->getCollection()->aggregate($pipelineDay);
2867 $dayResult=$day_result['result'];
2868 //echo '<pre>',print_r($hit_result);exit;
2869 //print_r($pipeline4Hit);
2870 //print_r($hit_result);exit;
2871 $hit_result=$hit_result['result'];
2872 $temp_result=$hit_result;
2873 unset($hit_result);
2874 foreach($temp_result as $v)
2875 {
2876 $hit_result[$v['_id']]=[
2877 'total_hit'=>$v['total_hit'],
2878 'uniq_hit'=>$v['uniq_hit'],
2879 ];
2880 }
2881 //print_r($hit_result);
2882 //exit;
2883 $result=$result['result'];
2884 $data=[];
2885 //for currency details
2886// $c_map=Yii::app()->mongodb->currency_map;
2887 foreach($result as $k=>$v)
2888 {
2889
2890 $data[$k]=$v;
2891 $data[$k]['product']=$v['_id']['product'];
2892 $data[$k]['productlink']=(new ProductEx())->getProductlink($v['_id']['product']);
2893// $currency=$c_map->findOne(["_id"=>$data[$k]['product']]);
2894// $data[$k]['rev_sgd']=($currency)? round(W::currencyConverter($currency['currency'], 'SGD', $v['rev']),3) : 0;
2895// $data[$k]['rev_inr']=($currency)? round(W::currencyConverter('SGD', 'INR', $data[$k]['rev_sgd']),3) : 0;
2896 $date="{$v['_id']['d']}-{$v['_id']['m']}-{$v['_id']['y']}";
2897 $data[$k]['date']=$date;
2898 $data[$k]['date']= date(W::getDateFormat(), strtotime($data[$k]['date']));
2899 $data[$k]['day_churn']=0;
2900 foreach($dayResult as $dayC){
2901 if($v['_id'] == $dayC['_id']){
2902 $data[$k]['day_churn']= $dayC['day_churn'];
2903 break;
2904 }
2905 }
2906
2907 $data[$k]['total_hit']="{$hit_result[$date.'-'.$data[$k]['product']]['total_hit']}";
2908 $data[$k]['uniq_hit']="{$hit_result[$date.'-'.$data[$k]['product']]['uniq_hit']}";
2909 unset($data[$k]['_id']);
2910 }
2911 // Create a new CSort object
2912 $sort = new CSort();
2913 // One attribute for each column of data
2914 $sort->attributes = array(
2915 'rev',
2916 'date',
2917 'product',
2918 );
2919 // Set the default order
2920 $sort->defaultOrder = array(
2921 'product'=>CSort::SORT_DESC,
2922 );
2923 $dataProvider=new CArrayDataProvider($data, array( 'sort'=>$sort,'pagination'=>FALSE));
2924
2925 $this->render('reportmtnza', ['dataProvider'=>$dataProvider]);
2926 }
2927 public function actionReport3()
2928 {
2929 $this->layout='salparni';
2930 $start_date= mysql_escape_string($_GET['start_date'].' 00:00:00');
2931 $end_date= mysql_escape_string($_GET['end_date'].' 23:59:59');
2932 $product= mysql_escape_string($_GET['product']);
2933 if($start_date and $end_date)
2934 {
2935 $sql="select sum(price) as revenue,count(id) as users, product_id from transaction where created_at>='$start_date' and created_at<='$end_date' and product_id='$product' ";
2936 //echo $sql;
2937 $dataProvider=new CSqlDataProvider($sql);
2938 }
2939 $this->render('report3', ['dataProvider'=>$dataProvider]);
2940 }
2941
2942
2943 public function actionBarList()
2944 {
2945 $date=$_GET['date'];
2946 $product_id=$_GET['product'];
2947 if($date and $product_id)
2948 {
2949 $start_time= strtotime($date.' 00:00:00');
2950 $end_time= strtotime($date.' 23:59:59');
2951 $start_time+=5.5*3600;
2952 $end_time+=5.5*3600;
2953 $pipeline=[
2954 [
2955 '$match'=>[
2956 'product'=>"$product_id",
2957 'time'=>[
2958 '$gte'=>new MongoDate($start_time),
2959 '$lte'=>new MongoDate($end_time)
2960 ]
2961 ]
2962 ],
2963 [
2964 '$group'=>[
2965 '_id'=>'$msisdn',
2966 'circle_restrict'=>[
2967 '$sum'=>
2968 [
2969 '$cond'=>[
2970 [
2971 '$eq'=>[
2972 '$condition.allow_circle',
2973 false
2974 ]
2975 ],
2976 1,0
2977 ]
2978 ]
2979 ],
2980 'danger_restrict'=>[
2981 '$first'=>
2982 [
2983 '$cond'=>[
2984 [
2985 '$eq'=>[
2986 '$condition.allow_danger',
2987 false
2988 ]
2989 ],
2990 1,0
2991 ]
2992 ]
2993 ],
2994 'dnd_restrict'=>[
2995 '$first'=>
2996 [
2997 '$cond'=>[
2998 [
2999 '$eq'=>[
3000 '$condition.allow_dnd',
3001 false
3002 ]
3003 ],
3004 1,0
3005 ]
3006 ]
3007 ],
3008 '_30_day'=>[
3009 '$first'=>
3010 [
3011 '$cond'=>[
3012 [
3013 '$eq'=>[
3014 '$condition.allow_trflag',
3015 false
3016 ]
3017 ],
3018 1,0
3019 ]
3020 ]
3021 ],
3022 'already_sent_to_bot'=>[
3023 '$first'=>
3024 [
3025 '$cond'=>[
3026 [
3027 '$eq'=>[
3028 '$condition.already',
3029 false
3030 ]
3031 ],
3032 1,0
3033 ]
3034 ]
3035 ],
3036 'rand'=>[
3037 '$first'=>[
3038 '$cond'=>[
3039 [
3040 '$eq'=>[
3041 '$condition.rand',
3042 false
3043 ]
3044 ],
3045 0,1
3046 ]
3047 ]
3048 ],
3049 'camp_invalid'=>[
3050 '$first'=>[
3051 '$cond'=>[
3052 [
3053 '$eq'=>[
3054 '$condition.camp',
3055 false
3056 ]
3057 ],
3058 1,0
3059 ]
3060 ]
3061 ],
3062 'camp_valid'=>[
3063 '$first'=>[
3064 '$cond'=>[
3065 [
3066 '$eq'=>[
3067 '$condition.camp',
3068 false
3069 ]
3070 ],
3071 0,1
3072 ]
3073 ]
3074 ],
3075 'to_conv'=>[
3076 '$first'=>
3077 [
3078 '$cond'=>[
3079 [
3080 '$eq'=>[
3081 '$allowed',
3082 'yes'
3083 ]
3084 ],
3085 1,0
3086 ]
3087 ]
3088 ],
3089 'not_conv'=>[
3090 '$first'=>
3091 [
3092 '$cond'=>[
3093 [
3094 '$eq'=>[
3095 '$allowed',
3096 'no'
3097 ]
3098 ],
3099 1,0
3100 ]
3101 ]
3102 ],
3103 'count'=>['$first'=>1]
3104 ]
3105 ],
3106 [
3107 '$group'=>[
3108 '_id'=>'uniq msisdn',
3109 'circle_restrict'=>['$sum'=>'$circle_restrict'],
3110 'danger_restrict'=>['$sum'=>'$danger_restrict'],
3111 'dnd_restrict'=>['$sum'=>'$dnd_restrict'],
3112 '_30_day'=>['$sum'=>'$_30_day'],
3113 'already_sent_to_bot'=>['$sum'=>'$already_sent_to_bot'],
3114 'rand_yes'=>['$sum'=>'$rand'],
3115 'to_conv'=>['$sum'=>'$to_conv'],
3116 'not_conv'=>['$sum'=>'$not_conv'],
3117 'total_msisdn'=>['$sum'=>'$count'],
3118 'camp_invalid'=>['$sum'=>'$camp_invalid'],
3119 //'camp_valid'=>['$sum'=>'$camp_valid'],
3120 ]
3121 ],
3122 [
3123 '$limit'=>10
3124 ]
3125 ];
3126 $result= Yii::app()->mongodb->barlist->aggregate($pipeline);
3127 //print_r($pipeline);
3128 //print_r($result);exit;
3129 $result=$result['result'];
3130 $dataProvider=new CArrayDataProvider($result);
3131 //exit;
3132 }
3133 $this->render('barlist', ['dataProvider'=>$dataProvider]);
3134 }
3135
3136 public function actionAddDanger()
3137 {
3138 if($_POST['msisdn'])
3139 {
3140
3141 $msisdn= explode(',', $_POST['msisdn']);
3142 $reason=$_POST['reason'];
3143 $date= date('Y-m-d H:i:s');
3144 if(!$msisdn)
3145 {
3146 $msisdn=(array)$_POST['msisdn'];
3147 }
3148 foreach ($msisdn as $key => $value) {
3149 $actual_msisdn= trim($value);
3150 if($actual_msisdn=='')
3151 continue;
3152
3153 if(strlen($actual_msisdn)==12)
3154 {
3155 $sql[]="replace into dnd(msisdn,reason,date) values('$actual_msisdn','$reason','$date');";
3156 }
3157 else
3158 {
3159 throw new CHttpException(500,"All msisdn must be 12 digit");
3160 }
3161 }
3162
3163 foreach($sql as $v)
3164 {
3165 Yii::app()->db_dnd->createCommand($v)->execute();
3166 }
3167 Yii::app()->user->setFlash('success',"msisdns Addedd");
3168 }
3169 $this->render('addDanger', []);
3170 }
3171
3172 public function actionView_category()
3173 {
3174 $id=$_GET['id'];
3175 $model=(new Category)->findByPk($id);
3176 if(!$model)
3177 {
3178 throw new CHttpException(404,'Not Found');
3179 }
3180 $this->render('view_category', ['model'=>$model]);
3181 }
3182
3183 /* update category detail...*/
3184 public function actionUpdate_category()
3185 {
3186 $id=isset($_GET['id'])? $_GET['id']: '';
3187 $model= (new CategoryEx())->findByPk($id);
3188 if(!$model){
3189 throw new CHttpException(404,"Record not found.");
3190 }
3191 if(Yii::app()->request->isPostRequest)
3192 {
3193 $model->attributes= $_POST['CategoryEx'];
3194 if($model->validate(['name']))
3195 {
3196 if($model->save() ){
3197 $this->redirect(array('view_category', 'id'=>$model->id));
3198 }
3199
3200 }
3201 }
3202 $this->render('update_category', ['model'=>$model]);
3203 }
3204
3205// public function actionCategoryico()
3206// {
3207// if(isset($_POST))
3208// {
3209//
3210// }
3211// $this->render('categoryico', []);
3212// }
3213
3214
3215
3216
3217 public function actionCategoryico()
3218 {
3219
3220 $model= CategoryIco::model()->findByPk($_POST['category_id1']);
3221 if(!$model)
3222 $model=new CategoryIco;
3223
3224 if($_POST)
3225 {
3226 $model->attributes= $_POST['CategoryIco'];
3227 $model->category_id = $_POST['category_id1'];
3228
3229
3230
3231 $rnd = 'c'.$_POST['category_id1']; // generate random number between 0-9999
3232
3233
3234 $uploadedFile=CUploadedFile::getInstance($model,'category_ico_file');
3235 $fileName = "{$rnd}-{$uploadedFile}"; // random number + file name
3236 $model->category_ico_file = $fileName;
3237
3238 if($model->validate() )
3239 {
3240 if($model->save())
3241 {
3242 Yii::app()->user->setFlash('success','Successfully uploaded');
3243 $uploadedFile->saveAs(Yii::getPathOfAlias('webroot').'/cms/'.$fileName); // image will uplode to rootDirectory/banner/
3244 }
3245 else{
3246 Yii::app()->user->setFlash('error','Error!');
3247 }
3248
3249 }
3250 else
3251 {
3252 Yii::app()->user->setFlash('error','Error validaation!');
3253 }
3254 }
3255
3256 $this->render('categoryico',['model'=>$model]);
3257 }
3258
3259
3260 public function actionTest()
3261 {
3262 print_r([
3263 'circle'=>(new Circle())->getCircleCode('919510608281'),
3264 'isp'=>W::getCarrierId('1.39.61.12'),
3265 'ip'=>W::isip('1.1.1.12'),
3266 ]);
3267 }
3268
3269 public function actionHitReport()
3270 {
3271 $model=new HitReport();
3272 if($_POST['a'])
3273 {
3274 header('Content-Disposition: attachment; filename="report.csv"');
3275 $model->collName=$_POST['coll'];
3276 $model->attrList=$_POST['a'];
3277 $model->date=$_POST['date'];
3278 echo $model->getCSV();
3279 exit;
3280 }
3281 $this->render('hit_report',['model'=>$model]);
3282 }
3283
3284 public function actionj()
3285 {
3286 //W::OnError();
3287 $model=new MongoJSetting();
3288 $model=$model->_getData();
3289 if($_POST['MongoJSetting'])
3290 {
3291 $model->attributes=$_POST['MongoJSetting'];
3292 $model->save();
3293 }
3294 $this->render('j', ['model'=>$model]);
3295 }
3296
3297
3298 public function actionConvReport()
3299 {
3300
3301 }
3302
3303 public function actionList_Danger()
3304 {
3305 $model=new Dang('search');
3306 $model->unsetAttributes(); // clear any default values
3307 if(isset($_GET['Dang']))
3308 $model->attributes=$_GET['Dang'];
3309
3310 $this->render('list_dang',array(
3311 'model'=>$model,
3312 ));
3313 }
3314
3315 public function actionUpdate_Content()
3316 {
3317 $model=new ContentEx();
3318 $model= $model->findByPk($_GET['id']);
3319 if($model->file_path != '')
3320 $model->fileType='file';
3321 else
3322 $model->fileType='link';
3323 if($model==false)
3324 {
3325 throw new CHttpException(404,"Not Found");
3326 }
3327
3328 if(isset($_POST['ContentEx']))
3329 {
3330 //print_r($_FILES);exit;
3331 $thumb=$_FILES['ContentEx']['tmp_name']['thumb_path'];
3332 $model->attributes=$_POST['ContentEx'];
3333 $model->updated_at=date(W::getDatetimeFormat());
3334 if($model->fileType=='file'){
3335 $model->link_path='';
3336 $model->file_path=CUploadedFile::getInstance($model,'file_path');
3337 }else{
3338 $model->file_path='';
3339 }
3340 if(isset($model->file_path->name))
3341 $model->name= str_replace('__filename__', pathinfo($model->file_path->name)['filename'], $model->name);
3342 /* @var $image CUploadedFile */
3343 $cmsPath=Yii::getPathOfAlias('webroot.cms');
3344 if($model->validate())
3345 {
3346 $error=$model->contentUploadValidation($_FILES, $_POST, $cmsPath);
3347 if(empty($error))
3348 {
3349 if($model->save())
3350 {
3351 if($model->fileType =='file'){
3352 $model->file_path->saveAs($cmsPath.'/'.$model->id.'_'.$model->file_path->name);
3353 }
3354 // redirect to success page
3355 if($thumb)
3356 {
3357 if($model->fileType =='file'){
3358 $thumb_path_a=Yii::getPathOfAlias('webroot.cms.thumb').'/'.$model->id.'_'.$model->file_path->name.'.'.$model->file_path->extensionName;
3359 }else{
3360 $thumb_path_a=Yii::getPathOfAlias('webroot.cms.thumb').'/'.$model->id.'_.';
3361 }
3362 move_uploaded_file($thumb, $thumb_path_a);
3363 }
3364 else
3365 {
3366 $model->createThumb($model->file_path,$model);
3367 }
3368 Yii::app()->user->setFlash('success','Content is Successfully Uploaded...');
3369 }else{
3370 Yii::app()->user->setFlash('error','Error in Uploaded Content');
3371 }
3372 }else{
3373 Yii::app()->user->setFlash('error',$error);
3374 }
3375
3376 }
3377 }
3378 /*if($_POST)
3379 {
3380 $model->attributes=$_POST['CategoryEx'];
3381 if($model->validate(['name']))
3382 {
3383 if($model->save())
3384 {
3385 Yii::app()->user->setFlash('success','Content is Successfully Uploaded...');
3386 }
3387 else
3388 {
3389 Yii::app()->user->setFlash('error','Error in Uploaded Content');
3390 }
3391 }
3392 }*/
3393 $this->render('create_content',['model'=>$model]);
3394 }
3395
3396 public function actionTrSummary()
3397 {
3398 $start_date=$_GET['start_date'].' 00:00:00';
3399 $end_date=$_GET['end_date'].' 23:59:59';
3400 if($start_date and $end_date)
3401 {
3402 $sql="select sum(price) as revenue,count(id) as users, product_id from transaction where created_at>='$start_date' and created_at<='$end_date' group by product_id ";
3403 //echo $sql;
3404 $dataProvider=new CSqlDataProvider($sql);
3405 }
3406
3407 $mongo_start_time=new MongoDate(strtotime($start_date));
3408 $mongo_end_time=new MongoDate(strtotime($end_date));
3409
3410 $coll=(new MongoCampaignLog())->getCollection();
3411 $result=$coll->aggregate([
3412 [
3413 '$match'=>[
3414 'time'=>[
3415 '$gte'=>$mongo_start_time,
3416 '$lte'=>$mongo_end_time
3417 ],
3418 'price'=>['$gt'=>0]
3419 ]
3420 ],
3421 [
3422 '$project'=>[
3423 'camp'=>1,
3424 'price'=>1
3425 ]
3426 ],
3427 [
3428 '$group'=>[
3429 '_id'=>'$camp',
3430 'count'=>['$sum'=>1],
3431 'rev'=>['$sum'=>'$price']
3432 ]
3433 ],
3434 [
3435 '$sort'=>[
3436 'count'=>-1
3437 ]
3438 ]
3439 ]);
3440 $campCount=$result['result'];
3441
3442 $result=(new MongoLogReq)->getCollection()->aggregate([
3443 [
3444 '$match'=>[
3445 'time'=>[
3446 '$gte'=>$mongo_start_time,
3447 '$lte'=>$mongo_end_time
3448 ],
3449 //'msisdn'=>['$exists'=>TRUE]
3450 ]
3451 ],
3452 [
3453 '$project'=>[
3454 'msisdn'=>1,
3455 'camp'=>1,
3456 ]
3457 ],
3458 [
3459 '$group'=>[
3460 '_id'=>'$msisdn',
3461 'camp'=>['$first'=>'$camp'],
3462 //'total'=>['$sum'=>1]
3463 ]
3464 ],
3465 [
3466 '$group'=>[
3467 '_id'=>'$camp',
3468 'hit'=>['$sum'=>1],
3469 //'hits'=>['$sum'=>'$total']
3470 ]
3471 ],
3472 [
3473 '$sort'=>['count'=>-1]
3474 ]
3475 ]);
3476 //print_r($campCount);exit;
3477 $clickCamp= $this->convPair($result['result'],$campCount);
3478 usort($clickCamp, function($a, $b) {
3479 return -1*($a['rev'] - $b['rev']);
3480});
3481 $clickCampDP=new CArrayDataProvider($clickCamp);
3482 $this->render('trsummary', [
3483 'dataProvider'=>$dataProvider,
3484 'clickCampDP'=>$clickCampDP
3485 ]);
3486 }
3487 private function convPair($result,$other)
3488 {
3489 $temp=[];
3490
3491 foreach($other as $k=>$v)
3492 {
3493 $temp[$v['_id']]=$v;
3494 unset($temp[$v['_id']]['_id']);
3495 }
3496 //print_r($temp);exit;
3497 $campCount=[];
3498 $i=0;
3499 foreach($result as $v)
3500 {
3501
3502 $campCount[$i]=$v;
3503 if($temp[$v['_id']])
3504 {
3505 foreach($temp[$v['_id']] as $k1=>$v1)
3506 {
3507 $campCount[$i] [$k1]=$v1;
3508 }
3509 }
3510 $i++;
3511 }
3512 //print_r($campCount);exit;
3513 return $campCount;
3514 }
3515
3516
3517 public function actionTransaction()
3518 {
3519 $model=new Transaction();
3520 $model->unsetAttributes();
3521 $model->attributes=$_GET['Transaction'];
3522 $this->render('transaction', ['model'=>$model]);
3523 }
3524
3525
3526
3527 public function actionCategory_map()
3528 {
3529 $name=$_GET['name'];
3530 $model= CategoryMapEx::model('CategoryMapEx')->findByPk($name);
3531 if(!$model)
3532 $model=new CategoryMapEx();
3533
3534 // uncomment the following code to enable ajax-based validation
3535 /*
3536 if(isset($_POST['ajax']) && $_POST['ajax']==='category-map-category_map-form')
3537 {
3538 echo CActiveForm::validate($model);
3539 Yii::app()->end();
3540 }
3541 */
3542
3543 if(isset($_POST['CategoryMapEx']))
3544 {
3545 $model->attributes=$_POST['CategoryMapEx'];
3546 if($model->save())
3547 {
3548 Yii::app()->user->setFlash('success','Category Map is Successfully Uploaded...!');
3549 }
3550 else
3551 {
3552 Yii::app()->user->setFlash('error','Error in Uploaded...!');
3553 }
3554 }
3555 $this->render('category_map',array('model'=>$model));
3556 }
3557
3558 public function actionListMapCategory()
3559 {
3560// $dataProvider=new CActiveDataProvider('CategoryMap');
3561 $model=new CategoryMap();
3562 $this->render('listmapcategory',['model'=>$model]);
3563// $this->render('listmapcategory',['dataProvider'=>$dataProvider]);
3564
3565 }
3566 /*
3567 * View Record of the Map cateory
3568 */
3569 public function actionViewMapCategory()
3570 {
3571 $name=isset($_GET['name'])? $_GET['name']: '';
3572 $model= CategoryMapEx::model()->find('name=:name', array(':name'=> $name));
3573 $this->render('view_map_category',['model'=>$model]);
3574
3575 }
3576
3577 /* Delete the map category...*/
3578 public function actionDeleteMapCategory()
3579 {
3580 $name=isset($_GET['name'])? $_GET['name']: '';
3581 if($name!=''){
3582 $catMapInfo= CategoryMapEx::model()->find('name=:name', array(':name'=> $name));
3583 if($catMapInfo){
3584 if($catMapInfo->delete()){
3585 Yii::app()->user->setFlash('success', 'Deleted "'.$catMapInfo->name.'" successfully');
3586 }
3587 }
3588 }
3589
3590 }
3591
3592
3593 public function actionProduct()
3594 {
3595 if(isset($_GET['id'])){
3596 $id=(int)$_GET['id'];
3597 $model=(new ProductEx())->findByPk($id);
3598 }
3599
3600 if(!($model))
3601 $model=new ProductEx();
3602
3603 //fint the selected value is show
3604
3605// echo "<pre>";
3606// print_r($_POST);exit;
3607
3608 if(isset($_POST['ProductEx']))
3609 {
3610
3611 $model->attributes=$_POST['ProductEx'];
3612 //check the status of String or form base on select
3613 $json=$model->conf_json;
3614 $model->conf_json=$json;
3615
3616 //validtion is proper then it save the databse table in my db
3617 if($model->validate())
3618 {
3619
3620 if($model->save())
3621 {
3622 Yii::app()->user->setFlash('success','Product Successfully Uploaded...');
3623 }
3624 else
3625 {
3626 Yii::app()->user->setFlash('error','Error in Creating Product');
3627 }
3628
3629 }
3630 }
3631 $this->render('product',array('model'=>$model));
3632 }
3633
3634 public function actionProductList()
3635 {
3636// $dataProvider=new CActiveDataProvider('Product');
3637 $product = new Product();
3638 $this->render('product_list',['model'=>$product]);
3639 }
3640
3641 public function actionView_product()
3642 {
3643 $id=(int)$_GET['id'];
3644 $model= Product::model()->findByPk($id);
3645 if(!$model)
3646 {
3647 throw new CHttpException(404,'No Product Found');
3648 }
3649 $ppmodels= ProductPriceEx::model()->findAll('product_id=:pid', [':pid'=>$id]);
3650 $this->render('view_product', ['model'=>$model,'ppmodels'=>$ppmodels]);
3651 }
3652
3653
3654 public function actionProduct_price()
3655 {
3656 $id=(int)$_GET['id'];
3657 $modelP= Product::model()->findByPk($id);
3658 if(!($modelP))
3659 {
3660 throw new CHttpException(404,'Product Not found');
3661 }
3662 $model=new ProductPriceEx();
3663
3664 // uncomment the following code to enable ajax-based validation
3665
3666
3667 if(isset($_POST['price']))
3668 {
3669 $model->deleteAll('product_id=:product_id',[':product_id'=>$id]);
3670 $success=0;$fail=0;
3671 foreach ($_POST['price'] as $k=>$v)
3672 {
3673 $price=$v;
3674 if(!$price)
3675 continue;
3676 $content=$_POST['content'][$k];
3677 $validity=$_POST['validity'][$k];
3678 $eventid=$_POST['eventid'][$k];
3679 $class_name=$_POST['class_name'][$k];
3680 $operator_id=$_POST['operator_id'][$k];
3681 $newobj=new ProductPrice();
3682 $newobj->product_id=$id;
3683 $newobj->price=$price;
3684 $newobj->content=$content;
3685 $newobj->validity=$validity;
3686 $newobj->class_name=$class_name;
3687 $newobj->eventid=$eventid;
3688 $newobj->operator_id=$operator_id;
3689
3690 if($newobj->save())
3691 {
3692 $success++;
3693 }
3694 else
3695 {
3696 $fail++;
3697 }
3698 if($success)
3699 {
3700 Yii::app()->user->setFlash('success',"$success price saved successfully");
3701 }
3702 if($fail)
3703 {
3704 Yii::app()->user->setFlash('error',"$fail failed while saving price");
3705 }
3706 }
3707 }
3708 $criteria=new CDbCriteria();
3709 $criteria->condition='product_id=:product_id';
3710 $criteria->params=[':product_id'=>$id];
3711 $criteria->order='eventid';
3712 $models= ProductPrice::model()->findAll($criteria);
3713 $this->render('product_price',array('model'=>$model,'modelP'=>$modelP,'models'=>$models));
3714 }
3715
3716
3717
3718 public function actionMove_Category()
3719 {
3720 if($_POST)
3721 {
3722 $model= Category::model()->findByPk($_POST['category_id1']);
3723 $model->category_id=$_POST['category_id2'];
3724 $model->save();
3725 }
3726 $this->render('move_category');
3727 }
3728
3729 public function actionPutContent()
3730 {
3731
3732 $model=new ContentEx();
3733 if(isset($_POST['ContentEx']))
3734 {
3735
3736 //print_r($_FILES);exit;
3737 $thumb=$_POST['ContentEx']['thumb_path'];
3738 $model->attributes=$_POST['ContentEx'];
3739 $url=$model->file_path;
3740 $path=Yii::getPathOfAlias('webroot.cms');
3741 $id= $this->getNextAutoInc('content');
3742 $filename=W::filename4url($model->name).'.mp3';
3743 $model->file_path=$filename;
3744 $this->creatMp3FromTube($url, $path.'/'.$id.'_'.$filename);
3745 /* @var $image CUploadedFile */
3746 if($model->save())
3747 {
3748 // redirect to success page
3749 if($thumb)
3750 {
3751 $thumb_path_a=Yii::getPathOfAlias('webroot.cms.thumb').'/'.$id.'_'.$filename.'.mp3';
3752 copy($thumb, $thumb_path_a);
3753 }
3754 else
3755 {
3756 $model->createThumb($model->file_path,$model);
3757 }
3758 }
3759 }
3760 if($_POST)
3761 {
3762 $model->attributes=$_POST['CategoryEx'];
3763 if($model->validate(['name']))
3764 {
3765 if($model->save())
3766 {
3767 Yii::app()->user->setFlash('success','Content is Successfully created');
3768 }
3769 else
3770 {
3771 Yii::app()->user->setFlash('error','Error in Content Category');
3772 }
3773 }
3774 }
3775 if($_GET['category_id'])
3776 {
3777 $model->category_id=$_GET['category_id'];
3778 Yii::app()->user->setFlash('success','You are Adding Content in '. (new CategoryEx())->findByPk($_GET['category_id'])->name);
3779 }
3780
3781 $this->render('putContent',['model'=>$model]);
3782 }
3783
3784
3785 private function creatMp3FromTube($url,$output)
3786 {
3787 ini_set('user_agent', 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16');
3788 $in='/tmp/_file.mp3';
3789 copy($url, $in);
3790 if(filesize($in)<=10000)
3791 {
3792 echo "file not downloaded";
3793 exit;
3794 }
3795 $command="ffmpeg -i $in $output";
3796 exec($command, $out);
3797
3798 return $out;
3799 }
3800 private function getNextAutoInc($tablename)
3801 {
3802 $sql="SHOW TABLE STATUS FROM `tinystar` LIKE '$tablename' ;";
3803 return Yii::app()->db->createCommand($sql)->queryRow()['Auto_increment'];
3804 }
3805
3806
3807 public function actionGet_category()
3808 {
3809 $id=(int)$_GET['id'];
3810 $models= Category::model()->findAll('category_id '.($id?'=:category_id':' is NULL').'',[':category_id'=>$id]);
3811 if(!$models)
3812 Yii::app ()->end ();
3813 $data=(CHtml::listData($models, 'id', 'name'));
3814 echo json_encode($data);
3815 Yii::app()->end();
3816
3817 echo '<select id="selectCategory">';
3818 echo '<option value="">Select</option>';
3819 foreach($data as $k=>$v)
3820 {
3821 echo '<option value="'.$k.'">'.$v.'</option>';
3822 }
3823 echo '</select>';
3824
3825 Yii::app()->end();
3826 }
3827
3828
3829 public function actionCreate_content()
3830 {
3831 $model=new ContentEx();
3832 $error='';
3833 $model->fileType='file';
3834 if(isset($_POST['ContentEx']))
3835 {
3836 // echo "<pre>";print_r($_FILES);exit;
3837 // echo $error;exit;
3838 $thumb=$_FILES['ContentEx']['tmp_name']['thumb_path'];
3839 $model->attributes=$_POST['ContentEx'];
3840 $model->created_at=date(W::getDatetimeFormat());
3841 $model->updated_at=date(W::getDatetimeFormat());
3842 if($model->fileType=='file'){
3843 $model->link_path='';
3844 $model->file_path=CUploadedFile::getInstance($model,'file_path');
3845 }else{
3846 $model->file_path='';
3847 }
3848 if(isset($model->file_path->name))
3849 $model->name= str_replace('__filename__', pathinfo($model->file_path->name)['filename'], $model->name);
3850
3851 $cmsPath=Yii::getPathOfAlias('webroot.cms');
3852 if($model->validate())
3853 {
3854 $error=$model->contentUploadValidation($_FILES, $_POST, $cmsPath);
3855 if(empty($error))
3856 {
3857 if($model->save())
3858 {
3859 if($model->fileType =='file'){
3860 $model->file_path->saveAs($cmsPath.'/'.$model->id.'_'.$model->file_path->name);
3861 }
3862 // redirect to success page
3863 if($thumb)
3864 {
3865 if($model->fileType =='file'){
3866 $thumb_path_a=Yii::getPathOfAlias('webroot.cms.thumb').'/'.$model->id.'_'.$model->file_path->name.'.'.$model->file_path->extensionName;
3867 }else{
3868 $thumb_path_a=Yii::getPathOfAlias('webroot.cms.thumb').'/'.$model->id.'_.';
3869 }
3870 move_uploaded_file($thumb, $thumb_path_a);
3871 }
3872 else
3873 {
3874 $model->createThumb($model->file_path,$model);
3875 }
3876 Yii::app()->user->setFlash('success','Content is Successfully created');
3877 }
3878 }else{
3879 Yii::app()->user->setFlash('error',$error);
3880 }
3881
3882 }
3883 /* @var $image CUploadedFile */
3884 }
3885
3886 /* if($_POST)
3887 {
3888 $model->attributes=$_POST['CategoryEx'];
3889 if($model->validate(['name']))
3890 {
3891 if($model->save())
3892 {
3893 Yii::app()->user->setFlash('success','Content is Successfully created');
3894 }
3895 else
3896 {
3897 Yii::app()->user->setFlash('error','Error in Content Category');
3898 }
3899 }
3900 }*/
3901 if(isset($_GET['category_id']) && $_GET['category_id']!='')
3902 {
3903 $categoryId=(int)$_GET['category_id'];
3904 $model->category_id=$categoryId;
3905 Yii::app()->user->setFlash('category','You are Adding Content in '. (new CategoryEx())->findByPk($categoryId)->name);
3906
3907 }
3908 $this->render('create_content',['model'=>$model]);
3909 }
3910
3911
3912 public function actionDelete_content()
3913 {
3914 $id=(int)$_GET['id'];
3915 $model= ContentEx::model()->findByPk($id);
3916 //$file_path= Yii::getPathOfAlias('webroot.cms').'/'.$model->id.'_'.$model->file_path;
3917 //$thumb_path=Yii::getPathOfAlias('webroot.cms.thumb').'/'.$model->id.'_'.$model->file_path.'.'. pathinfo($model->file_path, PATHINFO_EXTENSION);
3918 $model->status= ContentEx::ST_DEL;
3919 if($model->save())
3920 {
3921// unlink($thumb_path);
3922// unlink($file_path);
3923 $this->redirect(['/admin/list_content']);
3924 }
3925 else{
3926 throw new CHttpException(500,print_r($model->errors,'1'));
3927 }
3928 }
3929
3930 public function actionDelete_category()
3931 {
3932 $id=(int)$_GET['id'];
3933 $model= CategoryEx::model()->findByPk($id);
3934 if($model->categories){
3935 throw new CHttpException(500,"Sub Category Already Exists!... ");
3936 }
3937 else
3938 {
3939 $model->delete();
3940 }
3941 }
3942
3943 public function actionGetLog()
3944 {
3945 $path='/home/wwwlogs';
3946 $msisdn=$_GET['msisdn'];
3947 $date=$_GET['date'];
3948 $host=$_GET['host'];
3949 if($msisdn and $date and $host)
3950 {
3951 $cmd="cat $path/$host/$date.log | grep '$msisdn' | grep -v '/admin'";
3952 header('Content-Disposition: attachment; filename="'.$date.'-'.$msisdn.'-'.$host.'.log"');
3953 exec($cmd, $output);
3954 $op= implode("\n", $output);
3955 echo $op;
3956 exit;
3957 }
3958 $this->render('getlog',['op'=>$op]);
3959 }
3960
3961
3962 public function actionIndex()
3963 {
3964 $this->render('index');
3965 }
3966
3967 public function actionList_category()
3968 {
3969 $model=new Category('search');
3970 $model->unsetAttributes(); // clear any default values
3971 if(isset($_GET['Category']))
3972 $model->attributes=$_GET['Category'];
3973 $this->render('list_category',['model'=>$model]);
3974 }
3975
3976 public function actionlcategory($id=false)
3977 {
3978 if($id)
3979 {
3980 $condition='category_id='.$id;
3981 }
3982 else
3983 {
3984 $condition='category_id is NULL';
3985 }
3986 $dataProvider=new CActiveDataProvider('Category',[
3987 'criteria'=>[
3988 'condition'=>$condition
3989 ]
3990 ]);
3991 $this->render('lcategory', ['dataProvider'=>$dataProvider]);
3992 }
3993
3994 public function actionList_content()
3995 {
3996 $dataProvider=new CActiveDataProvider('Content',[
3997 'criteria'=>[
3998 'condition'=>'status='.Content::ST_Ac.' and file_path not like "%.jpg"'
3999 ]
4000 ]);
4001
4002 $dataProvider->sort->defaultOrder='id desc';
4003 $this->render('list_content',['dataProvider'=>$dataProvider]);
4004 }
4005
4006 public function actionLogin()
4007 {
4008 $this->layout='salparni';
4009 if($_POST)
4010 {
4011 if(trim($_POST['username'])=='' || trim($_POST['password'])=='')
4012 {
4013 Yii::app()->user->setFlash('error', "Please enter username and password.");
4014 }else
4015 {
4016 $username=$_POST['username'];
4017 $model= $this->getUser();
4018 if($model[$username]['pass']==$_POST['password'])
4019 {
4020 Yii::app()->session['ass_user']=$username;
4021 $this->go2Home();
4022 }
4023 else
4024 {
4025 // echo "fail";
4026 Yii::app()->user->setFlash('error', "The username and password you entered don't match.");
4027 }
4028 }
4029 }
4030 $this->render('login');
4031 }
4032
4033 public function go2Home()
4034 {
4035 $model= $this->getUser();
4036 if(Yii::app()->user->returnUrl && Yii::app()->user->returnUrl!= '/')
4037 {
4038 $this->redirect(Yii::app()->user->returnUrl);
4039 }
4040 else if($model[Yii::app()->session['ass_user']]['product']=='all')
4041 {
4042 $this->redirect(['admin/index','_r'=>'no']);
4043 }
4044 else
4045 {
4046 $this->redirect(['manager/index']);
4047// $this->redirect(['admin/report3','_r'=>'no']);
4048 }
4049 }
4050
4051 public function checkLogin()
4052 {
4053 $username= Yii::app()->session['ass_user'];
4054 if(!$username and $this->action->id!='login')
4055 {
4056 Yii::app()->user->returnUrl = Yii::app()->request->requestUri;
4057 $this->redirect(['admin/login']);
4058 }
4059 }
4060
4061
4062
4063
4064 public function filters()
4065 {
4066 return array(
4067
4068
4069 /* array(
4070 'HttpAuthFilter',
4071 //'users'=>array('mask'=>'shakhimaq@123'),
4072 'users'=>array('dmask'=>'Tiny@12'),
4073 'realm'=>'Admin section'
4074
4075 )*/
4076 'login',
4077 'accControl',
4078 'setAdminTheme',
4079 'accessControl', // perform access control for CRUD operations
4080
4081 );
4082 }
4083
4084 public function filterLogin($fc)
4085 {
4086 $this->checkLogin();
4087 $fc->run();
4088 }
4089
4090 public function filteraccControl($fc)
4091 {
4092 $ex_actions=['report3','login','logout'];
4093 if(!in_array($this->action->id, $ex_actions))
4094 {
4095 $model= $this->getUser();
4096 $product=$model[Yii::app()->session['ass_user']]['product'];
4097 $specialaccess=$model[Yii::app()->session['ass_user']]['specialaccess'];
4098 if($specialaccess=='yes'){
4099 $fc->run();
4100 }
4101 if($product!='all'){
4102 echo "access denied";exit;
4103 }
4104 }
4105 elseif($_REQUEST['product'])
4106 {
4107 $product=$_REQUEST['product'];
4108 $model= $this->getUser();
4109 $products=$model[Yii::app()->session['ass_user']]['product'];
4110 if(!in_array($product, $products))
4111 {
4112 echo "access denied";exit;
4113 }
4114 }
4115 $fc->run();
4116 }
4117
4118 public function actionLogOut()
4119 {
4120 Yii::app()->session['ass_user']=false;
4121 Yii::app()->session->clear();
4122 Yii::app()->session->destroy();
4123 $this->checkLogin();
4124 }
4125
4126 // Uncomment the following methods and override them if needed
4127
4128 public function filtersetAdminTheme($filterChain)
4129 {
4130 Yii::app()->theme='blackboot';
4131 $filterChain->run();
4132 }
4133
4134 public static function getUser()
4135 {
4136 $data = MongoAccUser::model()->findAll(array('username' => array('$ne' => NULL)));
4137// $dataProvider = new CArrayDataProvider(iterator_to_array($data, false));
4138
4139 foreach($data as $user) {
4140 $getUserArray[$user->username] = array('pass' =>$user->password,'product' =>$user->product_id,'specialaccess'=> $user->specialaccess);
4141 }
4142// print_r($getUserArray);exit;
4143 return $getUserArray;
4144 }
4145 /*
4146 public function actions()
4147 {
4148 // return external action classes, e.g.:
4149 return array(
4150 'action1'=>'path.to.ActionClass',
4151 'action2'=>array(
4152 'class'=>'path.to.AnotherActionClass',
4153 'propertyName'=>'propertyValue',
4154 ),
4155 );
4156 }
4157 */
4158
4159 /* Method defined for Adding new Users list with product Access Rights
4160 # All listed to Super admin
4161 * @input data- Username,Password,Productid's,Status,
4162 */
4163 public function actionManageAccUser() {
4164 $mongoAccUser = MongoAccUser::model();
4165 if (isset($_POST['MongoAccUser']) && !empty($_POST['MongoAccUser'])) {
4166 $mongoAccUser->attributes = $_POST['MongoAccUser'];
4167 if(isset($_POST['accessAllProduct']) && !empty($_POST['accessAllProduct']))
4168 {
4169 $mongoAccUser->product_id='all';
4170 }
4171 if(isset($_POST['specialAccess']) && !empty($_POST['specialAccess']))
4172 {
4173 $mongoAccUser->specialaccess='yes';
4174 }
4175 else{
4176 $mongoAccUser->specialaccess='';
4177 }
4178 $mongoAccUser->insert();
4179 Yii::app()->user->setFlash('success', 'Access User detail added Successfully!!');
4180 $url = Yii::app()->createUrl('admin/listaccessusers');
4181 $this->redirect($url);
4182 }
4183 $this->render('access_user', ['model' => $mongoAccUser]);
4184 }
4185
4186 /* Method defined for showing Users list with product Access Rights
4187 # All listed to Super admin
4188 */
4189 public function actionlistAccessUsers() {
4190 $data = MongoAccUser::model()->findAll(array('username' => array('$ne' => NULL)));
4191 $dataProvider = new CArrayDataProvider(iterator_to_array($data, false), array(
4192 'id' => 'listaccessusers',
4193 'pagination' => array(
4194 'pageSize' => 10,
4195 ),
4196 ));
4197 $this->render('listaccessuser', ['dataProvider' => $dataProvider]);
4198 }
4199
4200 /* Method defined for Updating Users list with product Access Rights
4201 *All listed to Super admin
4202 * @Input Unique __id of record.
4203 */
4204 public function actionUpdateAccUser() {
4205 $mongoAccUser = MongoAccUser::model()->findOne(array('_id' => new MongoId($_GET['_id'])));
4206 if (isset($_POST['MongoAccUser']) && !empty($_POST['MongoAccUser'])) {
4207 $mongoAccUser->attributes = $_POST['MongoAccUser'];
4208 if(isset($_POST['accessAllProduct']) && !empty($_POST['accessAllProduct']))
4209 {
4210 $mongoAccUser->product_id='all';
4211 }
4212 if(isset($_POST['specialAccess']) && !empty($_POST['specialAccess']))
4213 {
4214 $mongoAccUser->specialaccess='yes';
4215 }
4216 else{
4217 $mongoAccUser->specialaccess='';
4218 }
4219 $mongoAccUser->save();
4220 Yii::app()->user->setFlash('success', 'Access User detail Updated Successfully!!');
4221 $url = Yii::app()->createUrl('admin/listaccessusers');
4222 $this->redirect($url);
4223 }
4224 $this->render('access_user', ['model' => $mongoAccUser]);
4225 }
4226
4227 /* Method defined for Deleting Users list with product Access Rights
4228 * All listed to Super admin
4229 * @Input Unique __id of record.
4230 */
4231 public function actionDeleteAccUser() {
4232 $mongoAccUser = MongoAccUser::model()->findOne(array('_id' => new MongoId($_GET['_id'])));
4233 $mongoAccUser->attributes = $_POST['MongoAccUser'];
4234 $mongoAccUser->delete();
4235 Yii::app()->user->setFlash('success', 'Selected Access User detail deleted Successfully!!');
4236 $url = Yii::app()->createUrl('admin/listaccessusers');
4237 $this->redirect($url);
4238 }
4239
4240 /**************Camp Trasaction Record list, insert start *****************************/
4241
4242 /* Method to add campaign transaction detail...
4243 * All listed to Super admin
4244 */
4245 public function actionCamptransaction()
4246 {
4247 $model=new CampTransaction();
4248// $dataProvider=new CActiveDataProvider('CampTransaction',[
4249// 'sort'=>array(
4250// 'defaultOrder'=>array(
4251// 'campaign'=>false
4252// )
4253// )
4254// ]);
4255 //echo "<pre>";print_r($dataProvider->getData());exit;
4256 $this->render('camp_transaction',['model'=>$model]);
4257 }
4258
4259 /* Create campaign transaction detail...*/
4260 public function actionCreate_camptrn()
4261 {
4262 $model=new CampTransaction();
4263
4264 if(Yii::app()->request->isPostRequest && isset($_POST['CampTransaction']))
4265 {
4266 $model->attributes=$_POST['CampTransaction'];
4267 $model->user = Yii::app()->session['ass_user'];
4268 if($model->save()){
4269 $this->redirect(array('view_camptrn', 'camp'=>$model->campaign));
4270 }
4271 }
4272 $this->render('create_camptrn', ['model'=>$model]);
4273 }
4274 /* update campaign transaction detail...*/
4275 public function actionUpdate_camptrn()
4276 {
4277 $camp=isset($_GET['camp'])? $_GET['camp']: '';
4278 $model=new CampTransaction();
4279 if($camp!=''){
4280 $model= CampTransaction::model()->find('campaign=:camp', array(':camp'=> $camp));
4281 }
4282 if(Yii::app()->request->isPostRequest && isset($_POST['CampTransaction']))
4283 {
4284 $model->attributes=$_POST['CampTransaction'];
4285 if($model->save()){
4286 $this->redirect(array('view_camptrn', 'camp'=>$model->campaign));
4287 }
4288 }
4289 $this->render('create_camptrn', ['model'=>$model]);
4290 }
4291 /* View campaign transaction detail...*/
4292 public function actionView_camptrn()
4293 {
4294 $camp=isset($_GET['camp'])? $_GET['camp']: '';
4295 $campTrnInfo= CampTransaction::model()->find('campaign=:camp', array(':camp'=> $camp));
4296 if(empty($campTrnInfo)){
4297 $this->redirect(array('camptransaction'));
4298 }
4299 $this->render('view_camptrn', ['model'=> $campTrnInfo]);
4300 }
4301
4302 /* Delete campaign transaction detail...*/
4303 public function actionDelete_camptrn()
4304 {
4305 $camp=isset($_GET['camp'])? $_GET['camp']: '';
4306 if($camp!=''){
4307 $campTrnInfo= CampTransaction::model()->find('campaign=:camp', array(':camp'=> $camp));
4308 if($campTrnInfo){
4309 $campTrnInfo->delete();
4310 $this->redirect(array('camptransaction'));
4311 }
4312 }
4313 $this->redirect(array('camptransaction'));
4314
4315 }
4316
4317 /*
4318 * Campaign Transaction Report in details
4319 */
4320 public function actionCamptranlogs()
4321 {
4322
4323 $campaign=(isset($_GET['campaign']))?$_GET['campaign']: '';
4324 $startDate=date('Y-m-d', strtotime ( '-29 days' , strtotime ( date('Y-m-d') ) ));
4325 $endDate=date('Y-m-d');
4326 $startDate= (isset($_GET['start_date'])&& $_GET['start_date']!='')?$_GET['start_date']:$startDate;
4327 $endDate= (isset($_GET['end_date'])&& $_GET['end_date']!='')?$_GET['end_date']:$endDate;
4328
4329 $startDate= strtotime($startDate.' 00:00:00');
4330 $mongo_start_date=new MongoDate($startDate);
4331 $endDate= strtotime($endDate.' 23:59:59');
4332 $mongo_end_date=new MongoDate($endDate);
4333 if($campaign!=''){
4334 $match=[
4335 '$match'=>[
4336 'datetime'=>[
4337 '$gte'=>$mongo_start_date,
4338 '$lte'=>$mongo_end_date,
4339 ],
4340 'camp'=>[
4341 '$eq'=>$campaign
4342 ],
4343 ]
4344 ];
4345 }else{
4346 $match=[
4347 '$match'=>[
4348 'datetime'=>[
4349 '$gte'=>$mongo_start_date,
4350 '$lte'=>$mongo_end_date,
4351 ],
4352 ]
4353 ];
4354 }
4355 $pipeline=[
4356 $match,
4357 /* [
4358 '$group'=>[
4359 '_id'=>[
4360 'camp'=>'$camp',
4361 'd'=>['$dayOfMonth'=>'$datetime'],
4362 'm'=>['$month'=>'$datetime'],
4363 'y'=>['$year'=>'$datetime'],
4364 ],
4365 ]
4366 ],
4367
4368 */
4369 [
4370 '$project'=>[
4371 '_id'=>1,
4372 'camp'=>1,
4373 'token'=>1,
4374 'phone'=>1,
4375 'datetime'=>[
4376 'd'=>['$dayOfMonth'=>'$datetime'],
4377 'm'=>['$month'=>'$datetime'],
4378 'y'=>['$year'=>'$datetime'],
4379 ]
4380 ]
4381 ],
4382 [
4383 '$sort'=>[
4384 '_id'=>-1
4385 ]
4386 ]
4387 ];
4388 $result=(new MongoCampTransaction())->getCollection()->aggregate($pipeline);
4389 //echo '<pre>',print_r($result);exit;
4390 $result=$result['result'];
4391 $data=[];
4392 foreach($result as $k=>$v)
4393 {
4394 $data[$k]=$v;
4395 $date="{$v['datetime']['d']}-{$v['datetime']['m']}-{$v['datetime']['y']}";
4396 $data[$k]['date']=date('d-m-Y',strtotime($date));
4397 unset($data[$k]['datetime']);
4398 }
4399 $campTrasaction=new CampTransaction();
4400 $campaignList=$campTrasaction->getCampaignList();
4401 $dataProvider=new CArrayDataProvider($data,
4402 array(
4403 'sort'=>array(
4404 'attributes'=>array(
4405 '_id', 'camp', 'token', 'phone', 'date',
4406 ),
4407 )
4408 )
4409 );
4410
4411 $this->render('camp_tran_logs', ['dataProvider'=>$dataProvider, 'campaignList'=>$campaignList]);
4412 }
4413 /**************Camp Trasaction Record list, insert end *****************************/
4414
4415 public function actionView_churn()
4416 {
4417 $model = MongoChurn::model()->findOne(array('_id' => new MongoId($_GET['_id'])));
4418 if(!$model)
4419 {
4420 throw new CHttpException(404,'No Product Found');
4421 }
4422 $this->render('view_churn', ['model'=>$model]);
4423 }
4424
4425 public function actionChurnList()
4426 {
4427 $data = MongoChurn::model()->findAll();
4428 $dataProvider = new CArrayDataProvider(iterator_to_array($data, false), array(
4429 'id' => 'churn_list',
4430 'pagination' => array(
4431 'pageSize' => 10,
4432 ),
4433 ));
4434 $this->render('churn_list',['dataProvider'=>$dataProvider]);
4435 }
4436
4437 public function actionChurn()
4438 {
4439 $id=$_GET['_id'];
4440 $mongoChurn = MongoChurn::model()->findOne(array('_id' => new MongoId($_GET['_id'])));
4441 if(!($mongoChurn))
4442 $mongoChurn = MongoChurn::model();
4443
4444 if(isset($_POST['MongoChurn']))
4445 {
4446 $mongoChurn->attributes = $_POST['MongoChurn'];
4447 $mongoChurn->id = 1;
4448 if(!empty($id)){
4449 $mongoChurn->updated_at = date('Y-m-d H:i:s');
4450 $mongoChurn->updated_by = Yii::app()->session['ass_user'];
4451 }else{
4452 $mongoChurn->created_at = date('Y-m-d H:i:s');
4453 $mongoChurn->created_by = Yii::app()->session['ass_user'];
4454 }
4455
4456 if($mongoChurn->save()){
4457 Yii::app()->user->setFlash('success','Churn save Successfully ...');
4458 }
4459 else{
4460 Yii::app()->user->setFlash('error','Error in Creating Churn');
4461 }
4462 }
4463 $this->render('churn',array('model'=>$mongoChurn));
4464 }
4465
4466 public function actionDelete_churn()
4467 {
4468 $mongoChurn = MongoChurn::model()->findOne(array('_id' => new MongoId($_GET['_id'])));
4469 $mongoChurn->attributes = $_POST['MongoChurn'];
4470 $mongoChurn->delete();
4471 Yii::app()->user->setFlash('success', 'Selected Churn detail deleted Successfully!!');
4472 $url = Yii::app()->createUrl('admin/churnlist');
4473 $this->redirect($url);
4474 }
4475
4476 public function actionCapping() {
4477
4478 $id = isset($_GET['_id'])?$_GET['_id']:'';
4479 $mongoCapping = MongoCapping::model()->findOne(array('_id' => new MongoId($_GET['_id'])));
4480 if(!($mongoCapping))
4481 {
4482 $mongoCapping = MongoCapping::model();
4483 $mongoCapping->startdate = date(W::getDateFormat(),time())." 00:00:00";
4484 $mongoCapping->enddate = date(W::getDateFormat(),time())." 23:59:59";
4485 }
4486 if(isset($_POST['MongoCapping']))
4487 {
4488// print_r($_POST['MongoCapping']);exit();
4489 $mongoCapping->attributes = $_POST['MongoCapping'];
4490// $mongoCapping->id = 'ACTIVE';
4491
4492 if($id != ''){
4493 $mongoCapping->updated_at = date('Y-m-d H:i:s');
4494 $mongoCapping->updated_by = Yii::app()->session['ass_user'];
4495 }else{
4496 $mongoCapping->created_at = date('Y-m-d H:i:s');
4497 $mongoCapping->created_by = Yii::app()->session['ass_user'];
4498 }
4499
4500 if($mongoCapping->validate() && $mongoCapping->save())
4501 {
4502 Yii::app()->user->setFlash('success','Capping Saved Successfully ...');
4503 }else
4504 {
4505 Yii::app()->user->setFlash('error','Error in Creating Capping');
4506 }
4507
4508 }
4509 $this->render('capping',array('model'=>$mongoCapping));
4510 }
4511
4512 public function actionCappingList()
4513 {
4514 $dataProvider=new EMongoDataProvider('MongoCapping');
4515 $this->render('capping_list',['dataProvider'=>$dataProvider]);
4516 }
4517
4518 public function actionView_capping()
4519 {
4520 $model = MongoCapping::model()->findOne(array('_id' => new MongoId($_GET['_id'])));
4521 if(!$model)
4522 {
4523 throw new CHttpException(404,'No Product Found');
4524 }
4525 $this->render('view_capping', ['model'=>$model]);
4526 }
4527
4528 public function actionDelete_capping()
4529 {
4530 $mongoCapping = MongoCapping::model()->findOne(array('_id' => new MongoId($_GET['_id'])));
4531 $mongoCapping->attributes = $_POST['MongoCapping'];
4532 $mongoCapping->delete();
4533 Yii::app()->user->setFlash('success', 'Capping detail deleted Successfully!!');
4534 $url = Yii::app()->createUrl('admin/cappinglist');
4535 $this->redirect($url);
4536 }
4537
4538// public function actionConversionreport() {
4539//
4540// $start_date=date('Y-m-d')." 00:00:00";
4541// $end_date=date('Y-m-d')." 23:59:59";
4542// if($_GET['start_date'] and $_GET['end_date'])
4543// {
4544// $start_date= $_GET['start_date'].' 00:00:00';
4545// $end_date= $_GET['end_date'].' 23:59:59';
4546// }else{
4547// $_GET['start_date']=date('Y-m-d');
4548// $_GET['end_date']=date('Y-m-d');
4549// }
4550//
4551// $offset=5.5;
4552// $mongo_end_date=new MongoDate(strtotime($end_date));
4553// $mongo_start_date=new MongoDate(strtotime($start_date));
4554//
4555// $match=[
4556// '$match'=>[
4557// 'time'=>[
4558// '$gte'=>$mongo_start_date,
4559// '$lte'=>$mongo_end_date,
4560// ],
4561// 'type'=>[
4562// '$ne'=>'V'
4563// ],
4564//// 'user'=>Yii::app()->session['ass_user']
4565// ]
4566// ];
4567// if(isset($_GET['pid']) and $_GET['pid']!=''){
4568// $pids = explode(',', $_GET["pid"]);
4569// if(($key = array_search(42, $pids))!==FALSE)
4570// $pids[$key]=42;
4571// $match['$match']['product']=['$in'=>$pids];
4572// }
4573// if(isset($_GET['camp']) and $_GET['camp']!=''){
4574//// $camp = explode(',', $_GET["camp"]);
4575//// if(($key = array_search(42, $camp))!==FALSE)
4576//// $camp[$key]=42;
4577//// if($_GET['camp']=='none'){
4578//// $camp=[null,'none'];
4579//// }
4580//// echo '<pre>';
4581// $camp = $_GET['camp'];
4582//// echo '<pre>';
4583//// print_r($camp);exit;
4584// if(in_array('none',$camp)){
4585//// if (($key = array_search('0', $camp)) !== false) {
4586//// unset($camp[$key]);
4587//// }
4588// array_push($camp,null,'none');
4589//// $camp=[null,'none','asdfg'];
4590// }
4591//// print_r($camp);exit;
4592// $match['$match']['camp']=['$in'=>$camp];
4593// }
4594//// else{
4595////
4596//// $flag='true';
4597//// $camp=(new CampTransaction())->getCampaignUserWiseList($flag);
4598//// $match['$match']['camp']=['$in'=>$camp];
4599//// }
4600//
4601//// echo "<pre>"; print_r($match);exit;
4602// $pipeline=[
4603// $match,
4604// [
4605// '$project'=>[
4606// '_id'=>1,
4607// 'product'=>1,
4608// 'camp'=>1,
4609// 'time'=>[
4610// '$add'=>['$time',($offset*3600)*1000]
4611// ],
4612// 'price'=>1,
4613// 'type'=>1,
4614// 'cc'=>1
4615//
4616// ]
4617// ],
4618// [
4619// '$group'=>[
4620// '_id'=>[
4621// 'product'=>'$product',
4622// 'camp'=>'$camp',
4623// 'd'=>['$dayOfMonth'=>'$time'],
4624// 'm'=>['$month'=>'$time'],
4625// 'y'=>['$year'=>'$time'],
4626// ],
4627// 'rev'=>['$sum'=>[
4628// '$cond'=>[
4629// [
4630// '$or'=>[
4631// ['$eq'=>['$type', MongoCampaignLog::TYPE_PARK]],
4632// ['$eq'=>['$type', MongoCampaignLog::TYPE_GRACE]],
4633// ['$eq'=>['$type', MongoCampaignLog::TYPE_CANCEL]],
4634// ['$eq'=>['$type', MongoCampaignLog::TYPE_SUSPEND]]
4635// ]
4636// ],
4637// 0,'$price'
4638// ]
4639// ] ],
4640// 'fresh'=>[
4641// '$sum'=>
4642// [
4643// '$cond'=>[
4644// [
4645// '$eq'=>[
4646// '$type',
4647// 'F'
4648// ]
4649// ],
4650// 1,0
4651// ]
4652// ]
4653// ],
4654// 'zero_balance'=>[
4655// '$sum'=>[
4656// '$cond'=>[
4657// [
4658// '$eq'=>[
4659// '$type',
4660// 'P'
4661// ]
4662// ],
4663// 1,0
4664// ]
4665// ]
4666// ],
4667// 'grace_user'=>[
4668// '$sum'=>[
4669// '$cond'=>[
4670// [
4671// '$eq'=>[
4672// '$type',
4673// 'G'
4674// ]
4675// ],
4676// 1,0
4677// ]
4678// ]
4679// ],
4680// 'suspend'=>[
4681// '$sum'=>[
4682// '$cond'=>[
4683// [
4684// '$eq'=>[
4685// '$type',
4686// 'S'
4687// ]
4688// ],
4689// 1,0
4690// ]
4691// ]
4692// ],
4693// 'fresh_rev'=>[
4694// '$sum'=>
4695// [
4696// '$cond'=>[
4697// [
4698// '$eq'=>[
4699// '$type',
4700// 'F'
4701// ]
4702// ],
4703// '$price',0
4704// ]
4705// ]
4706// ],
4707// 'pta'=>[
4708// '$sum'=>[
4709// '$cond'=>[
4710// [
4711// '$eq'=>[
4712// '$type',
4713// 'PA'
4714// ]
4715// ],
4716// 1,0
4717// ]
4718// ]
4719// ],
4720// 'pta_rev'=>[
4721// '$sum'=>
4722// [
4723// '$cond'=>[
4724// [
4725// '$eq'=>[
4726// '$type',
4727// 'PA'
4728// ]
4729// ],
4730// '$price',0
4731// ]
4732// ]
4733// ],
4734// 'churn'=>[
4735// '$sum'=>
4736// [
4737// '$cond'=>[
4738// [
4739// '$eq'=>[
4740// '$type',
4741// 'C'
4742// ]
4743// ],
4744// 1,0
4745// ]
4746// ]
4747// ],
4748// 'cc_churn'=>[
4749// '$sum'=>[
4750// '$cond'=>[
4751// [
4752// '$eq'=>[
4753// '$cc',
4754// 'Y'
4755// ]
4756// ],
4757// 1,0
4758// ]
4759// ]
4760// ],
4761// 'renewal'=>[
4762// '$sum'=>
4763// [
4764// '$cond'=>[
4765// [
4766// '$eq'=>[
4767// '$type',
4768// 'R'
4769// ]
4770// ],
4771// 1,0
4772// ]
4773// ]
4774// ],
4775// 'renewal_rev'=>[
4776// '$sum'=>
4777// [
4778// '$cond'=>[
4779// [
4780// '$eq'=>[
4781// '$type',
4782// 'R'
4783// ]
4784// ],
4785// '$price',0
4786// ]
4787// ]
4788// ],
4789// ]
4790// ],
4791// [
4792// '$sort'=>[
4793// '_id'=>-1
4794// ]
4795// ]
4796// ];
4797//
4798// //print_r($pipeline);exit;
4799// $pipelineDay=[
4800// $match,
4801// [
4802// '$match'=>[
4803// 'type'=>[
4804// '$in'=>['F','C']
4805// ]
4806// ]
4807// ],
4808// [
4809// '$project'=>[
4810// '_id'=>1,
4811// 'product'=>1,
4812// 'camp'=>1,
4813// 'time'=>[
4814// '$add'=>['$time',($offset*3600)*1000]
4815// ],
4816// 'price'=>1,
4817// 'type'=>1,
4818// 'msisdn'=>1
4819//
4820// ]
4821// ],
4822// [
4823// '$sort'=>['type'=>-1]
4824// ],
4825// [
4826// '$group'=>[
4827// '_id'=>[
4828// 'product'=>'$product',
4829// 'camp'=>'$camp',
4830// 'd'=>['$dayOfMonth'=>'$time'],
4831// 'm'=>['$month'=>'$time'],
4832// 'y'=>['$year'=>'$time'],
4833// 'msisdn'=>'$msisdn',
4834// //'type'=>'$type',
4835// ],
4836// //'rev'=>['$sum'=>'$price'],
4837// 'ft'=>[
4838// '$first'=>'$type'
4839//
4840// ],
4841// 'lt'=>['$last'=>'$type']
4842// ],
4843// ],
4844// [
4845// '$project'=>[
4846// '_id'=>1,
4847// 'churn'=>[
4848// '$concat'=>['$ft','$lt']
4849// ]
4850// ]
4851// ],
4852// [
4853// '$group'=>[
4854// '_id'=>[
4855// 'product'=>'$_id.product',
4856// 'camp'=>'$_id.camp',
4857// 'd'=>'$_id.d',
4858// 'm'=>'$_id.m',
4859// 'y'=>'$_id.y',
4860// //'type'=>'$type',
4861// ],
4862// 'day_churn'=>[
4863// '$sum'=>[
4864// '$cond'=>[
4865// [
4866// '$eq'=>[
4867// '$churn','FC'
4868// ]
4869// ],1,0
4870// ]
4871// ]
4872// ]
4873// ]
4874// ],
4875// [
4876// '$sort'=>[
4877// '_id'=>-1
4878// ]
4879// ]
4880// ];
4881// if(isset($_GET['pid']) and $_GET['pid']!=''){
4882// unset($match['$match']['product']);
4883// $match['$match']['product_id']=['$in'=>$pids];
4884// }
4885// if(isset($_GET['camp']) and $_GET['camp']!=''){
4886// unset($match['$match']['camp']);
4887// $match['$match']['camp']=['$in'=>$camp];
4888// }
4889// $pipeline4Hit=[
4890// $match,
4891// [
4892// '$project'=>[
4893// 'msisdn'=>1,
4894// 'time'=>[
4895// '$add'=>['$time',($offset*3600)*1000]
4896// ],
4897// 'product_id'=>1,
4898// 'camp'=>1,
4899// ]
4900// ],
4901// [
4902// '$project'=>[
4903// 'msisdn'=>1,
4904// 'y'=>[
4905// '$substr'=>[
4906// ['$year'=>'$time'],0,4
4907// ]
4908// ],
4909// 'm'=>[
4910// '$substr'=>[
4911// ['$month'=>'$time'],0,2
4912// ]
4913// ],
4914// 'd'=>[
4915// '$substr'=>[
4916// ['$dayOfMonth'=>'$time'],0,2
4917// ]
4918// ],
4919// 'product_id'=>1,
4920// 'camp'=>['$substr'=>['$camp',0,100]],
4921// ]
4922// ],
4923// [
4924// '$group'=>[
4925// '_id'=>[
4926// 'msisdn'=>'$msisdn',
4927// 'hit_day'=>[
4928// '$concat'=>['$d','-','$m','-','$y','-','$product_id','-','$camp']
4929// ],
4930// ],
4931// 'count'=>['$sum'=>1],
4932//// 'camp1'=>['$first'=>1],
4933// 'uniq_count'=>['$first'=>1]
4934// ]
4935// ],
4936// [
4937// '$group'=>[
4938// '_id'=>'$_id.hit_day',
4939// 'total_hit'=>[
4940// '$sum'=>'$count'
4941// ],
4942// 'uniq_hit'=>[
4943// '$sum'=>'$uniq_count'
4944// ],
4945//// 'camp'=>'$camp1'
4946// ]
4947// ]
4948// ];
4949// $options = array("allowDiskUse" => true);
4950// $result=(new MongoCampaignLog())->getCollection()->aggregate($pipeline,$options);
4951//// echo '<pre>',print_r($result);exit;
4952// $hit_result=(new MongoLogReq())->getCollection()->aggregate($pipeline4Hit,$options);
4953//
4954// $day_result=(new MongoCampaignLog())->getCollection()->aggregate($pipelineDay,$options);
4955// $dayResult=$day_result['result'];
4956//// echo '<pre>';print_r($hit_result);exit;
4957//// print_r($pipeline4Hit);
4958//// print_r($hit_result);exit;
4959// $hit_result=$hit_result['result'];
4960// $temp_result=$hit_result;
4961// unset($hit_result);
4962// foreach($temp_result as $v)
4963// {
4964//// echo '<pre>';
4965//// print_r($v);exit;
4966// $hit_result[$v['_id']]=[
4967// 'total_hit'=>$v['total_hit'],
4968// 'uniq_hit'=>$v['uniq_hit'],
4969// 'product_id'=>$v['product_id']
4970//
4971// ];
4972// }
4973//
4974// $result=$result['result'];
4975// echo '<pre>';
4976// print_r($hit_result);
4977// print_r($result);
4978// exit;
4979// $data=[];
4980// //for currency details
4981//// $c_map=Yii::app()->mongodb->currency_map;
4982// foreach($result as $k=>$v)
4983// {
4984// $data[$k]=$v;
4985// $data[$k]['product']=$v['_id']['product'];
4986// if($v['_id']['camp']==""){
4987// $data[$k]['camp']='none';
4988// }
4989// else{
4990// $data[$k]['camp']=$v['_id']['camp'];
4991// }
4992// $data[$k]['productlink']=(new ProductEx())->getProductlink($v['_id']['product']);
4993//// $currency=$c_map->findOne(["_id"=>$data[$k]['product']]);
4994//// $data[$k]['rev_sgd']=($currency)? round(W::currencyConverter($currency['currency'], 'SGD', $v['rev']),3) : 0;
4995//// $data[$k]['rev_inr']=($currency)? round(W::currencyConverter('SGD', 'INR', $data[$k]['rev_sgd']),3) : 0;
4996// $date="{$v['_id']['d']}-{$v['_id']['m']}-{$v['_id']['y']}";
4997// $data[$k]['date']=$date;
4998// $data[$k]['date']= date(W::getDateFormat(), strtotime($data[$k]['date']));
4999// $data[$k]['day_churn']=0;
5000// foreach($dayResult as $dayC){
5001// if($v['_id'] == $dayC['_id']){
5002// $data[$k]['day_churn']= $dayC['day_churn'];
5003// break;
5004// }
5005// }
5006// if($data[$k]['camp']=='none'){
5007// $cmp='';
5008// }
5009// else{
5010// $cmp=$data[$k]['camp'];
5011// }
5012//
5013// $T_hit=(int)"{$hit_result[$date.'-'.$data[$k]['product'].'-'.$cmp]['total_hit']}";
5014// $U_hit=(int)"{$hit_result[$date.'-'.$data[$k]['product'].'-'.$cmp]['uniq_hit']}";
5015// if($T_hit>1 and $U_hit>1){
5016// $data[$k]['total_hit']=$T_hit;
5017// $data[$k]['uniq_hit']=$U_hit;
5018// unset($data[$k]['_id']);
5019// }
5020//
5021//
5022//// if($data[$k]['uniq_hit'] < 10 and $promote=='on'){
5023//// unset($data[$k]);
5024//// }
5025// // for Scrubing show in report
5026// $camp_scrubbing = Yii::app()->mongodb->camp_scrubbing_log;
5027// $Data=$camp_scrubbing->count(
5028// [
5029// 'result' =>'SCRUBBED',
5030//// 'product_id' =>$data[$k]['product'],
5031// 'camp' => $data[$k]['camp'],
5032// 'time'=>[
5033// '$gte'=>$mongo_start_date,
5034// '$lte'=>$mongo_end_date,
5035// ],
5036// ]);
5037//
5038// $data[$k]['scrubbed']=$Data;
5039//// echo '<pre>';
5040//// print_r(iterator_to_array($Data,true));
5041//// exit;
5042// }
5043//// foreach($hit_result as $key => $value){
5044//// if($hit_result['']){
5045////
5046//// }
5047//// }
5048//
5049//// $sort->defaultOrder = array(
5050//// 'product'=>CSort::SORT_DESC,
5051//// );
5052//// echo '<pre>';
5053//// print_r($data);
5054//// exit;
5055// $dataProvider=new CArrayDataProvider($data, array('pagination'=>FALSE));
5056//// $model = new MongoCampaignLog();
5057//// $campaignList=(new MongoCampaignLog())->getCampaignList();
5058// $campaignList=(new CampTransaction())->getCampaignList();
5059// $this->render('conversionreport', ['dataProvider'=>$dataProvider,'campaignList'=>$campaignList]);
5060// }
5061
5062 public function actionConversionreport() {
5063
5064 $userData= AdminController::getUser();
5065 $start_date=date('Y-m-d')." 00:00:00";
5066 $end_date=date('Y-m-d')." 23:59:59";
5067 if($_GET['start_date'] and $_GET['end_date'])
5068 {
5069 $start_date= $_GET['start_date'].' 00:00:00';
5070 $end_date= $_GET['end_date'].' 23:59:59';
5071 }else{
5072 $_GET['start_date']=date('Y-m-d');
5073 $_GET['end_date']=date('Y-m-d');
5074 }
5075
5076 $offset=5.5;
5077 $mongo_end_date=new MongoDate(strtotime($end_date));
5078 $mongo_start_date=new MongoDate(strtotime($start_date));
5079
5080 $match=[
5081 '$match'=>[
5082 'time'=>[
5083 '$gte'=>$mongo_start_date,
5084 '$lte'=>$mongo_end_date,
5085 ],
5086 'type'=>[
5087 '$ne'=>'V'
5088 ],
5089// 'user'=>Yii::app()->session['ass_user']
5090 ]
5091 ];
5092 if(isset($_GET['pid']) and $_GET['pid']!=''){
5093 $pids = explode(',', $_GET["pid"]);
5094 if(($key = array_search(42, $pids))!==FALSE)
5095 $pids[$key]=42;
5096 $match['$match']['product']=['$in'=>$pids];
5097 }
5098 if(isset($_GET['camp']) and $_GET['camp']!=''){
5099// $camp = explode(',', $_GET["camp"]);
5100// if(($key = array_search(42, $camp))!==FALSE)
5101// $camp[$key]=42;
5102// if($_GET['camp']=='none'){
5103// $camp=[null,'none'];
5104// }
5105// echo '<pre>';
5106 $camp = $_GET['camp'];
5107// echo '<pre>';
5108// print_r($camp);exit;
5109 if(in_array('none',$camp)){
5110// if (($key = array_search('0', $camp)) !== false) {
5111// unset($camp[$key]);
5112// }
5113 array_push($camp,null,'none');
5114// $camp=[null,'none','asdfg'];
5115 }
5116// print_r($camp);exit;
5117 $match['$match']['camp']=['$in'=>$camp];
5118 }else{
5119
5120 if($userData[Yii::app()->session['ass_user']]['product']!='all'){
5121 //$campaignList=(new CampTransaction())->getCampaignList();
5122
5123 $flag='true';
5124 $camp=(new CampTransaction())->getCampaignUserWiseList($flag);
5125 $match['$match']['camp']=['$in'=>$camp];
5126 }
5127 }
5128
5129// echo "<pre>"; print_r($match);exit;
5130 $pipeline=[
5131 $match,
5132 [
5133 '$project'=>[
5134 '_id'=>1,
5135 'product'=>1,
5136 'camp'=>1,
5137 'time'=>[
5138 '$add'=>['$time',($offset*3600)*1000]
5139 ],
5140 'price'=>1,
5141 'type'=>1,
5142 'cc'=>1
5143
5144 ]
5145 ],
5146 [
5147 '$group'=>[
5148 '_id'=>[
5149 'product'=>'$product',
5150 'camp'=>'$camp',
5151 'd'=>['$dayOfMonth'=>'$time'],
5152 'm'=>['$month'=>'$time'],
5153 'y'=>['$year'=>'$time'],
5154 ],
5155 'rev'=>['$sum'=>[
5156 '$cond'=>[
5157 [
5158 '$or'=>[
5159 ['$eq'=>['$type', MongoCampaignLog::TYPE_PARK]],
5160 ['$eq'=>['$type', MongoCampaignLog::TYPE_GRACE]],
5161 ['$eq'=>['$type', MongoCampaignLog::TYPE_CANCEL]],
5162 ['$eq'=>['$type', MongoCampaignLog::TYPE_SUSPEND]]
5163 ]
5164 ],
5165 0,'$price'
5166 ]
5167 ] ],
5168 'fresh'=>[
5169 '$sum'=>
5170 [
5171 '$cond'=>[
5172 [
5173 '$eq'=>[
5174 '$type',
5175 'F'
5176 ]
5177 ],
5178 1,0
5179 ]
5180 ]
5181 ],
5182 'zero_balance'=>[
5183 '$sum'=>[
5184 '$cond'=>[
5185 [
5186 '$eq'=>[
5187 '$type',
5188 'P'
5189 ]
5190 ],
5191 1,0
5192 ]
5193 ]
5194 ],
5195 'grace_user'=>[
5196 '$sum'=>[
5197 '$cond'=>[
5198 [
5199 '$eq'=>[
5200 '$type',
5201 'G'
5202 ]
5203 ],
5204 1,0
5205 ]
5206 ]
5207 ],
5208 'suspend'=>[
5209 '$sum'=>[
5210 '$cond'=>[
5211 [
5212 '$eq'=>[
5213 '$type',
5214 'S'
5215 ]
5216 ],
5217 1,0
5218 ]
5219 ]
5220 ],
5221 'fresh_rev'=>[
5222 '$sum'=>
5223 [
5224 '$cond'=>[
5225 [
5226 '$eq'=>[
5227 '$type',
5228 'F'
5229 ]
5230 ],
5231 '$price',0
5232 ]
5233 ]
5234 ],
5235 'pta'=>[
5236 '$sum'=>[
5237 '$cond'=>[
5238 [
5239 '$eq'=>[
5240 '$type',
5241 'PA'
5242 ]
5243 ],
5244 1,0
5245 ]
5246 ]
5247 ],
5248 'pta_rev'=>[
5249 '$sum'=>
5250 [
5251 '$cond'=>[
5252 [
5253 '$eq'=>[
5254 '$type',
5255 'PA'
5256 ]
5257 ],
5258 '$price',0
5259 ]
5260 ]
5261 ],
5262 'churn'=>[
5263 '$sum'=>
5264 [
5265 '$cond'=>[
5266 [
5267 '$eq'=>[
5268 '$type',
5269 'C'
5270 ]
5271 ],
5272 1,0
5273 ]
5274 ]
5275 ],
5276 'cc_churn'=>[
5277 '$sum'=>[
5278 '$cond'=>[
5279 [
5280 '$eq'=>[
5281 '$cc',
5282 'Y'
5283 ]
5284 ],
5285 1,0
5286 ]
5287 ]
5288 ],
5289 'renewal'=>[
5290 '$sum'=>
5291 [
5292 '$cond'=>[
5293 [
5294 '$eq'=>[
5295 '$type',
5296 'R'
5297 ]
5298 ],
5299 1,0
5300 ]
5301 ]
5302 ],
5303 'renewal_rev'=>[
5304 '$sum'=>
5305 [
5306 '$cond'=>[
5307 [
5308 '$eq'=>[
5309 '$type',
5310 'R'
5311 ]
5312 ],
5313 '$price',0
5314 ]
5315 ]
5316 ],
5317 ]
5318 ],
5319 [
5320 '$sort'=>[
5321 '_id'=>-1
5322 ]
5323 ]
5324 ];
5325
5326 //print_r($pipeline);exit;
5327 $pipelineDay=[
5328 $match,
5329 [
5330 '$match'=>[
5331 'type'=>[
5332 '$in'=>['F','C']
5333 ]
5334 ]
5335 ],
5336 [
5337 '$project'=>[
5338 '_id'=>1,
5339 'product'=>1,
5340 'camp'=>1,
5341 'time'=>[
5342 '$add'=>['$time',($offset*3600)*1000]
5343 ],
5344 'price'=>1,
5345 'type'=>1,
5346 'msisdn'=>1
5347
5348 ]
5349 ],
5350 [
5351 '$sort'=>['type'=>-1]
5352 ],
5353 [
5354 '$group'=>[
5355 '_id'=>[
5356 'product'=>'$product',
5357 'camp'=>'$camp',
5358 'd'=>['$dayOfMonth'=>'$time'],
5359 'm'=>['$month'=>'$time'],
5360 'y'=>['$year'=>'$time'],
5361 'msisdn'=>'$msisdn',
5362 //'type'=>'$type',
5363 ],
5364 //'rev'=>['$sum'=>'$price'],
5365 'ft'=>[
5366 '$first'=>'$type'
5367
5368 ],
5369 'lt'=>['$last'=>'$type']
5370 ],
5371 ],
5372 [
5373 '$project'=>[
5374 '_id'=>1,
5375 'churn'=>[
5376 '$concat'=>['$ft','$lt']
5377 ]
5378 ]
5379 ],
5380 [
5381 '$group'=>[
5382 '_id'=>[
5383 'product'=>'$_id.product',
5384 'camp'=>'$_id.camp',
5385 'd'=>'$_id.d',
5386 'm'=>'$_id.m',
5387 'y'=>'$_id.y',
5388 //'type'=>'$type',
5389 ],
5390 'day_churn'=>[
5391 '$sum'=>[
5392 '$cond'=>[
5393 [
5394 '$eq'=>[
5395 '$churn','FC'
5396 ]
5397 ],1,0
5398 ]
5399 ]
5400 ]
5401 ]
5402 ],
5403 [
5404 '$sort'=>[
5405 '_id'=>-1
5406 ]
5407 ]
5408 ];
5409 if(isset($_GET['pid']) and $_GET['pid']!=''){
5410 unset($match['$match']['product']);
5411 $match['$match']['product_id']=['$in'=>$pids];
5412 }
5413 if(isset($_GET['camp']) and $_GET['camp']!=''){
5414 unset($match['$match']['camp']);
5415 $match['$match']['camp']=['$in'=>$camp];
5416 }
5417 $pipeline4Hit=[
5418 $match,
5419 [
5420 '$project'=>[
5421 'msisdn'=>1,
5422 'time'=>[
5423 '$add'=>['$time',($offset*3600)*1000]
5424 ],
5425 'product_id'=>1,
5426 'camp'=>1,
5427 ]
5428 ],
5429 [
5430 '$project'=>[
5431 'msisdn'=>1,
5432 'y'=>[
5433 '$substr'=>[
5434 ['$year'=>'$time'],0,4
5435 ]
5436 ],
5437 'm'=>[
5438 '$substr'=>[
5439 ['$month'=>'$time'],0,2
5440 ]
5441 ],
5442 'd'=>[
5443 '$substr'=>[
5444 ['$dayOfMonth'=>'$time'],0,2
5445 ]
5446 ],
5447 'product_id'=>1,
5448// 'camp'=>['$substr'=>['$camp',0,100]],
5449 'camp'=>1
5450 ]
5451 ],
5452 [
5453 '$group'=>[
5454 '_id'=>[
5455 'msisdn'=>'$msisdn',
5456 'hit_day'=>[
5457 '$concat'=>['$d','-','$m','-','$y','-','$product_id','-','$camp']
5458 ],
5459 ],
5460 'count'=>['$sum'=>1],
5461// 'camp1'=>['$first'=>1],
5462 'uniq_count'=>['$first'=>1],
5463 'product_id'=>['$first'=>'$product_id'],
5464 'camp'=>['$first'=>'$camp'],
5465 'd'=>['$first'=>'$d'],
5466 'm'=>['$first'=>'$m'],
5467 'y'=>['$first'=>'$y'],
5468 ]
5469 ],
5470 [
5471 '$group'=>[
5472 '_id'=>'$_id.hit_day',
5473 'total_hit'=>[
5474 '$sum'=>'$count'
5475 ],
5476 'uniq_hit'=>[
5477 '$sum'=>'$uniq_count'
5478 ],
5479 'product_id'=>['$first'=>'$product_id'],
5480 'camp'=>['$first'=>'$camp'],
5481 'd'=>['$first'=>'$d'],
5482 'm'=>['$first'=>'$m'],
5483 'y'=>['$first'=>'$y'],
5484// 'camp'=>'$camp1'
5485 ]
5486 ]
5487 ];
5488 $options = array("allowDiskUse" => true);
5489 $result=(new MongoCampaignLog())->getCollection()->aggregate($pipeline,$options);
5490// echo '<pre>',print_r($result);exit;
5491 $hit_result=(new MongoLogReq())->getCollection()->aggregate($pipeline4Hit,$options);
5492
5493 $day_result=(new MongoCampaignLog())->getCollection()->aggregate($pipelineDay,$options);
5494 $dayResult=$day_result['result'];
5495// echo '<pre>';print_r($hit_result);exit;
5496// print_r($pipeline4Hit);
5497// print_r($hit_result);exit;
5498 $hit_result=$hit_result['result'];
5499 $temp_result=$hit_result;
5500 unset($hit_result);
5501 foreach($temp_result as $v)
5502 {
5503 $hit_result[$v['_id']]=[
5504 'total_hit'=>$v['total_hit'],
5505 'uniq_hit'=>$v['uniq_hit'],
5506 ];
5507 $hit_result_1[]=$v;
5508 }
5509 $result=$result['result'];
5510 $data=[];
5511// echo '<pre>';
5512// print_r($result);
5513// print_r($hit_result);
5514// print_r($hit_result_1);
5515// exit;
5516 //for currency details
5517// $c_map=Yii::app()->mongodb->currency_map;
5518 foreach($result as $k=>$v)
5519 {
5520 $data[$k]=$v;
5521 $data[$k]['product']=$v['_id']['product'];
5522 if($v['_id']['camp']==""){
5523 $data[$k]['camp']='none';
5524 }
5525 else{
5526 $data[$k]['camp']=$v['_id']['camp'];
5527 }
5528 $data[$k]['productlink']=(new ProductEx())->getProductlink($v['_id']['product']);
5529// $currency=$c_map->findOne(["_id"=>$data[$k]['product']]);
5530// $data[$k]['rev_sgd']=($currency)? round(W::currencyConverter($currency['currency'], 'SGD', $v['rev']),3) : 0;
5531// $data[$k]['rev_inr']=($currency)? round(W::currencyConverter('SGD', 'INR', $data[$k]['rev_sgd']),3) : 0;
5532 $date="{$v['_id']['d']}-{$v['_id']['m']}-{$v['_id']['y']}";
5533 $data[$k]['date']=$date;
5534 $data[$k]['date']= date(W::getDateFormat(), strtotime($data[$k]['date']));
5535 $data[$k]['day_churn']=0;
5536 foreach($dayResult as $dayC){
5537 if($v['_id'] == $dayC['_id']){
5538 $data[$k]['day_churn']= $dayC['day_churn'];
5539 break;
5540 }
5541 }
5542 if($data[$k]['camp']=='none'){
5543 $cmp='';
5544 }
5545 else{
5546 $cmp=$data[$k]['camp'];
5547 }
5548 $data[$k]['total_hit']=(int)"{$hit_result[$date.'-'.$data[$k]['product'].'-'.$cmp]['total_hit']}";
5549 $data[$k]['uniq_hit']=(int)"{$hit_result[$date.'-'.$data[$k]['product'].'-'.$cmp]['uniq_hit']}";
5550 unset($data[$k]['_id']);
5551 if($data[$k]['uniq_hit'] < 10 and $promote=='on'){
5552 unset($data[$k]);
5553 }
5554
5555 // for Scrubing show in report
5556 $camp_scrubbing = Yii::app()->mongodb->camp_scrubbing_log;
5557 $Data=$camp_scrubbing->count(
5558 [
5559 'result' =>'SCRUBBED',
5560 'product_id' =>$data[$k]['product'],
5561 'camp' => $data[$k]['camp'],
5562 'time'=>[
5563 '$gte'=>$mongo_start_date,
5564 '$lte'=>$mongo_end_date,
5565 ],
5566 ]);
5567 $data[$k]['scrubbed']=$Data;
5568
5569 }
5570
5571 // for click reccord show
5572 $k=count($data);
5573 $k1=count($data);
5574
5575 $temp_result_1=$hit_result_1;
5576
5577 unset($hit_result_1);
5578 foreach($temp_result_1 as $v1)
5579 {
5580 $hit_result_1[$k]['product']=$v1['product_id'];
5581 if($v1['camp']==""){
5582 $hit_result_1[$k]['camp']='none';
5583 }
5584 else{
5585 $hit_result_1[$k]['camp']=$v1['camp'];
5586 }
5587
5588 $date=$v1['d'].'-'.$v1['m'].'-'.$v1['y'];
5589 $hit_result_1[$k]['date']=date(W::getDateFormat(), strtotime($date));
5590 $k++;
5591 }
5592
5593
5594 foreach ($data as $key => $value) {
5595
5596 $dataArr[$key]['product']=$value['product'];
5597 $dataArr[$key]['camp']=$value['camp'];
5598 $dataArr[$key]['date']=$value['date'];
5599 }
5600
5601 foreach ($hit_result_1 as $key => $value){
5602// echo '<pre>'; print_r($value); //exit;
5603 if((!in_array($value, $dataArr))){
5604// print_r($hit_result);
5605// print_r($value);exit;
5606 if($value['product']!="" or $value['product']!=null){
5607
5608 $product=$value['product'];
5609 if($value['camp']=='none'){
5610 $cp='';
5611 }
5612 else{
5613 $cp=$value['camp'];
5614 }
5615 $newDate=date('d-m-Y', strtotime($value['date']));
5616 //echo $newDate.'-'.$product.'-'.$cp;
5617 $Tot_res=(int)"{$hit_result[$newDate.'-'.$product.'-'.$cp]['total_hit']}";
5618 $Uniq_res=(int)"{$hit_result[$newDate.'-'.$product.'-'.$cp]['uniq_hit']}";
5619 if($Tot_res>0 and $Uniq_res>0){
5620
5621 $data[$k1]['product']=$product;
5622 $data[$k1]['productlink']=(new ProductEx())->getProductlink($product);
5623 $data[$k1]['camp']=$value['camp'];
5624 $data[$k1]['date']=$newDate;
5625 $data[$k1]['total_hit'] = $Tot_res;
5626 $data[$k1]['uniq_hit'] = $Uniq_res;
5627 $k1++;
5628 }
5629 }
5630 }
5631 }
5632// echo '<pre>';
5633// print_r($data);
5634// exit;
5635// $sort->defaultOrder = array(
5636// 'product'=>CSort::SORT_DESC,
5637// );
5638 $dataProvider=new CArrayDataProvider($data, array('pagination'=>FALSE));
5639// $model = new MongoCampaignLog();
5640// $campaignList=(new MongoCampaignLog())->getCampaignList();
5641 $campaignList=(new CampTransaction())->getCampaignUserWiseList();
5642
5643 // for admin
5644 $userData= AdminController::getUser();
5645 if($userData[Yii::app()->session['ass_user']]['product']=='all'){
5646 $campaignList=(new CampTransaction())->getCampaignList();
5647 }
5648
5649 $this->render('conversionreport', ['dataProvider'=>$dataProvider,'campaignList'=>$campaignList]);
5650 }
5651
5652 public function actionhrConvReport() {
5653
5654 $start_date=strtotime(date('Y-m-d')." 00:00:00");
5655 $end_date=strtotime(date('Y-m-d')." 23:59:59");
5656 $product=$_GET['product_id'];
5657 $camp=$_GET['camp'];
5658 if($camp=='none'){
5659 $camp='none';
5660 }
5661 if($_GET['start_date'] and $_GET['end_date'])
5662 {
5663 $start_date= strtotime($_GET['start_date'].' 00:00:00');
5664 $end_date= strtotime($_GET['end_date'].' 23:59:59');
5665 }
5666 $mongo_end_date=new MongoDate($end_date);
5667 $mongo_start_date=new MongoDate($start_date);
5668 $match=[
5669 '$match'=>[
5670 'time'=>[
5671 '$gte'=>$mongo_start_date,
5672 '$lte'=>$mongo_end_date,
5673 ],
5674 'type'=>[
5675 '$ne'=>'V'
5676 ],
5677
5678 ]
5679 ];
5680 $pipeline=[
5681 $match,
5682 [
5683 '$match'=>[
5684 'product'=> [
5685 '$eq'=> $product,
5686 ],
5687 'camp'=>[
5688 '$eq'=> $camp,
5689 ],
5690 ]
5691 ],
5692 [
5693 '$project'=>[
5694 '_id'=>1,
5695 'product'=>1,
5696 'camp'=>1,
5697 'time'=>[
5698 '$add'=>['$time',(5.5*3600)*1000]
5699 ],
5700 'price'=>1,
5701 'type'=>1
5702
5703 ]
5704 ],
5705 [
5706 '$group'=>[
5707 '_id'=>[
5708 'product'=>'$product',
5709 'camp'=>'$camp',
5710 'd'=>['$dayOfMonth'=>'$time'],
5711 'm'=>['$month'=>'$time'],
5712 'y'=>['$year'=>'$time'],
5713 'h'=>['$hour'=>'$time'],
5714 ],
5715 'rev'=>['$sum'=>'$price'],
5716 'grace'=>[
5717 '$sum'=>
5718 [
5719 '$cond'=>[
5720 [
5721 '$eq'=>[
5722 '$type',
5723 'G'
5724 ]
5725 ],
5726 1,0
5727 ]
5728 ]
5729 ],
5730 'fresh'=>[
5731 '$sum'=>
5732 [
5733 '$cond'=>[
5734 [
5735 '$eq'=>[
5736 '$type',
5737 'F'
5738 ]
5739 ],
5740 1,0
5741 ]
5742 ]
5743 ],
5744 'zero_balance'=>[
5745 '$sum'=>[
5746 '$cond'=>[
5747 [
5748 '$eq'=>[
5749 '$type',
5750 'P'
5751 ]
5752
5753 ],
5754 1,0
5755 ]
5756 ]
5757 ],
5758 'fresh_rev'=>[
5759 '$sum'=>
5760 [
5761 '$cond'=>[
5762 [
5763 '$eq'=>[
5764 '$type',
5765 'F'
5766 ]
5767 ],
5768 '$price',0
5769 ]
5770 ]
5771 ],
5772 'churn'=>[
5773 '$sum'=>
5774 [
5775 '$cond'=>[
5776 [
5777 '$eq'=>[
5778 '$type',
5779 'C'
5780 ]
5781 ],
5782 1,0
5783 ]
5784 ]
5785 ],
5786 'renewal'=>[
5787 '$sum'=>
5788 [
5789 '$cond'=>[
5790 [
5791 '$eq'=>[
5792 '$type',
5793 'R'
5794 ]
5795 ],
5796 1,0
5797 ]
5798 ]
5799 ],
5800 'renewal_rev'=>[
5801 '$sum'=>
5802 [
5803 '$cond'=>[
5804 [
5805 '$eq'=>[
5806 '$type',
5807 'R'
5808 ]
5809 ],
5810 '$price',0
5811 ]
5812 ]
5813 ],
5814 'park_to_active'=>[
5815 '$sum'=>[
5816 '$cond'=>[
5817 [
5818 '$eq'=>[
5819 '$type',
5820 'PA'
5821 ]
5822 ],
5823 1,0
5824 ]
5825 ]
5826 ],
5827 'grace_to_active'=>[
5828 '$sum'=>[
5829 '$cond'=>[
5830 [
5831 '$eq'=>[
5832 '$type',
5833 'GA'
5834 ]
5835 ],
5836 1,0
5837 ]
5838 ]
5839 ],
5840 'pta_rev'=>[
5841 '$sum'=>
5842 [
5843 '$cond'=>[
5844 [
5845 '$eq'=>[
5846 '$type',
5847 'PA'
5848 ]
5849 ],
5850 '$price',0
5851 ]
5852 ]
5853 ],
5854 'suspend_to_active'=>[
5855 '$sum'=>[
5856 '$cond'=>[
5857 [
5858 '$eq'=>[
5859 '$type',
5860 'SA'
5861 ]
5862 ],
5863 1,0
5864 ]
5865 ]
5866 ],
5867 'sta_rev'=>[
5868 '$sum'=>
5869 [
5870 '$cond'=>[
5871 [
5872 '$eq'=>[
5873 '$type',
5874 'SA'
5875 ]
5876 ],
5877 '$price',0
5878 ]
5879 ]
5880 ],
5881 'gta_rev'=>[
5882 '$sum'=>
5883 [
5884 '$cond'=>[
5885 [
5886 '$eq'=>[
5887 '$type',
5888 'GA'
5889 ]
5890 ],
5891 '$price',0
5892 ]
5893 ]
5894 ],
5895 'suspend'=>[
5896 '$sum'=>[
5897 '$cond'=>[
5898 [
5899 '$eq'=>[
5900 '$type',
5901 'S'
5902 ]
5903 ],
5904 1,0
5905 ]
5906 ]
5907 ],
5908 ]
5909 ],
5910 [
5911 '$sort'=>[
5912 '_id'=>-1
5913 ]
5914 ]
5915 ];
5916 if($camp=='none'){
5917 $camp=null;
5918 }
5919 $pipeline4Hit=[
5920 $match,
5921 [
5922 '$match'=>[
5923 'product_id'=> [
5924 '$eq'=> $product
5925 ],
5926 'camp'=>[
5927 '$eq'=>$camp,
5928 ],
5929 ]
5930 ],
5931 [
5932 '$project'=>[
5933 'msisdn'=>1,
5934 'time'=>[
5935 '$add'=>['$time',(5.5*3600)*1000]
5936 ],
5937 'product_id'=>1,
5938 'camp'=>['$substr'=>['$camp',0,100]],
5939 ]
5940 ],
5941 [
5942 '$project'=>[
5943 'msisdn'=>1,
5944 'y'=>[
5945 '$substr'=>[
5946 ['$year'=>'$time'],0,4
5947 ]
5948 ],
5949 'm'=>[
5950 '$substr'=>[
5951 ['$month'=>'$time'],0,2
5952 ]
5953 ],
5954 'd'=>[
5955 '$substr'=>[
5956 ['$dayOfMonth'=>'$time'],0,2
5957 ]
5958 ],
5959 'h'=>[
5960 '$substr'=>[
5961 ['$hour'=>'$time'],0,2
5962 ]
5963 ],
5964 'product_id'=>1,
5965 'camp'=>['$substr'=>['$camp',0,100]],
5966 ]
5967 ],
5968 [
5969 '$group'=>[
5970 '_id'=>[
5971 'msisdn'=>'$msisdn',
5972 'hit_day'=>[
5973 '$concat'=>['$d','-','$m','-','$y','-','$h','-','$product_id','-','$camp']
5974 ],
5975 ],
5976 'count'=>['$sum'=>1],
5977 'uniq_count'=>['$first'=>1]
5978 ]
5979 ],
5980 [
5981 '$group'=>[
5982 '_id'=>'$_id.hit_day',
5983 'total_hit'=>[
5984 '$sum'=>'$count'
5985 ],
5986 'uniq_hit'=>[
5987 '$sum'=>'$uniq_count'
5988 ],
5989 ]
5990 ],
5991 [
5992 '$limit'=>24,
5993 ]
5994 ];
5995
5996 $pipelineDay=[
5997 $match,
5998 [
5999 '$match'=>[
6000 'type'=>[
6001 '$in'=>['F','C']
6002 ]
6003 ]
6004 ],
6005 [
6006 '$project'=>[
6007 '_id'=>1,
6008 'product'=>1,
6009 'camp'=>1,
6010 'time'=>[
6011 '$add'=>['$time',(5.5*3600)*1000]
6012 ],
6013 'price'=>1,
6014 'type'=>1,
6015 'msisdn'=>1
6016
6017 ]
6018 ],
6019 [
6020 '$sort'=>['type'=>-1]
6021 ],
6022 [
6023 '$group'=>[
6024 '_id'=>[
6025 'product'=>'$product',
6026 'camp'=>'$camp',
6027 'd'=>['$dayOfMonth'=>'$time'],
6028 'm'=>['$month'=>'$time'],
6029 'y'=>['$year'=>'$time'],
6030 'h'=>['$hour'=>'$time'],
6031 'msisdn'=>'$msisdn',
6032 //'type'=>'$type',
6033 ],
6034 //'rev'=>['$sum'=>'$price'],
6035 'ft'=>[
6036 '$first'=>'$type'
6037
6038 ],
6039 'lt'=>['$last'=>'$type']
6040 ],
6041 ],
6042 [
6043 '$project'=>[
6044 '_id'=>1,
6045 'churn'=>[
6046 '$concat'=>['$ft','$lt']
6047 ]
6048 ]
6049 ],
6050 [
6051 '$group'=>[
6052 '_id'=>[
6053 'product'=>'$_id.product',
6054 'camp'=>'$_id.camp',
6055 'd'=>'$_id.d',
6056 'm'=>'$_id.m',
6057 'y'=>'$_id.y',
6058 'h'=>'$_id.h',
6059 //'type'=>'$type',
6060 ],
6061 'day_churn'=>[
6062 '$sum'=>[
6063 '$cond'=>[
6064 [
6065 '$eq'=>[
6066 '$churn','FC'
6067 ]
6068 ],1,0
6069 ]
6070 ]
6071 ]
6072 ]
6073 ],
6074 [
6075 '$sort'=>[
6076 '_id'=>-1
6077 ]
6078 ]
6079 ];
6080
6081 // for Scrubing show in report
6082 $camp_scrubbing = Yii::app()->mongodb->camp_scrubbing_log;
6083// $product_id=[''];
6084 $pipeline_camp=[
6085 [
6086 '$match'=>[
6087 'result' =>'SCRUBBED',
6088 ]
6089 ],
6090 [
6091 '$project'=>[
6092 'product_id'=>['$substr'=>['$product_id',0,100]],
6093 'camp'=>['$substr'=>['$camp',0,100]],
6094// 'product_id'=>1,
6095// 'camp'=>1,
6096 'time'=>[
6097 '$add'=>['$time',(5.5*3600)*1000]
6098 ],
6099// 'y'=>[
6100// '$substr'=>[
6101// ['$year'=>'$time'],0,4
6102// ]
6103// ],
6104// 'm'=>[
6105// '$substr'=>[
6106// ['$month'=>'$time'],0,2
6107// ]
6108// ],
6109// 'd'=>[
6110// '$substr'=>[
6111// ['$dayOfMonth'=>'$time'],0,2
6112// ]
6113// ],
6114// 'h'=>[
6115// '$substr'=>[
6116// ['$hour'=>'$time'],0,2
6117// ]
6118// ],
6119 ]
6120 ],
6121 [
6122 '$group'=>[
6123 '_id'=>[
6124 'scrubbed'=>[
6125 '$concat'=>['$camp','-','$product_id','-','$time']
6126 ],
6127 ],
6128 'count'=>['$sum'=>1],
6129 ]
6130 ],
6131 [
6132 '$group'=>[
6133 '_id'=>'$_id.scrubbed',
6134 'total_scrubbed'=>[
6135 '$sum'=>'$count'
6136 ],
6137 ]
6138 ],
6139 ];
6140
6141 $SData=$camp_scrubbing->aggregate($pipeline_camp);
6142 $SData=$SData['result'];
6143 $temp_result1=$SData;
6144 unset($SData);
6145
6146 foreach($temp_result1 as $v)
6147 {
6148 echo '<pre>';
6149 print_r($v);
6150 // print_r($v['_id']);
6151 $SData[$v['_id']]=[
6152 'total_scrubbed'=>$v['total_scrubbed'],
6153 ];
6154 exit;
6155 }
6156
6157
6158 $result=(new MongoCampaignLog())->getCollection()->aggregate($pipeline);
6159// echo '<pre>',print_r($result);exit;
6160 $hit_result=(new MongoLogReq())->getCollection()->aggregate($pipeline4Hit);
6161
6162 $day_result=(new MongoCampaignLog())->getCollection()->aggregate($pipelineDay);
6163 $dayResult=$day_result['result'];
6164// echo '<pre>',print_r($hit_result);exit;
6165 //print_r($pipeline4Hit);
6166// print_r($hit_result);exit;
6167 $hit_result=$hit_result['result'];
6168 $temp_result=$hit_result;
6169 unset($hit_result);
6170 foreach($temp_result as $v)
6171 {
6172 $hit_result[$v['_id']]=[
6173 'total_hit'=>$v['total_hit'],
6174 'uniq_hit'=>$v['uniq_hit'],
6175 ];
6176 }
6177// print_r($hit_result);
6178// exit;
6179 $result=$result['result'];
6180 $data=[];
6181 foreach($result as $k=>$v)
6182 {
6183// echo '<pre>';
6184// print_r($v);
6185
6186 $data[$k]=$v;
6187 $data[$k]['product']=$v['_id']['product'];
6188 $data[$k]['camp']=$v['_id']['camp'];
6189 $date="{$v['_id']['d']}-{$v['_id']['m']}-{$v['_id']['y']}";
6190 $data[$k]['hour']=$v['_id']['h'];
6191 $data[$k]['date']=$date;
6192 $data[$k]['date']= date(W::getDateFormat(), strtotime($data[$k]['date']));
6193 $data[$k]['day_churn']=0;
6194 foreach($dayResult as $dayC){
6195 if($v['_id'] == $dayC['_id']){
6196 $data[$k]['day_churn']= $dayC['day_churn'];
6197 break;
6198 }
6199 }
6200// print_r($data[$k]);
6201// exit;
6202 // for hit
6203 if($data[$k]['camp']=='none'){
6204 $cmp='';
6205 }
6206 else{
6207 $cmp=$data[$k]['camp'];
6208 }
6209
6210 $data[$k]['total_hit']="{$hit_result[$date.'-'.$data[$k]['hour'].'-'.$data[$k]['product'].'-'.$cmp]['total_hit']}";
6211 $data[$k]['uniq_hit']="{$hit_result[$date.'-'.$data[$k]['hour'].'-'.$data[$k]['product'].'-'.$cmp]['uniq_hit']}";
6212// $data[$k]['total_hit']="{$hit_result[$date.'-'.$data[$k]['hour'].'-'.$data[$k]['product']]['total_hit']}";
6213// $data[$k]['uniq_hit']="{$hit_result[$date.'-'.$data[$k]['hour'].'-'.$data[$k]['product']]['uniq_hit']}";
6214 unset($data[$k]['_id']);
6215 }
6216 // echo "<pre>";print_r($data);exit;
6217 // Create a new CSort object
6218 $sort = new CSort();
6219 // One attribute for each column of data
6220 $sort->attributes = array(
6221 'hour',
6222 );
6223 // Set the default order
6224 $sort->defaultOrder = array(
6225 'hour'=>CSort::SORT_DESC,
6226 );
6227 $dataProvider=new CArrayDataProvider($data, array( 'sort'=>$sort, 'pagination'=>false));
6228
6229 $this->render('hrconvreport', ['dataProvider'=>$dataProvider]);
6230
6231 }
6232}