Ejemplo n.º 1
0
 public static function dashboardWebService($acc)
 {
     $agent_id = $acc->admin_id;
     $mon = isset($_GET['mon']) ? addslashes($_GET['mon']) : date("n");
     $y = isset($_GET['y']) ? addslashes($_GET['y']) : date("Y");
     $date = new DateTime();
     $date->setDate($y, $mon, 1);
     $ymd = $date->format('Y-m-d');
     $monthNum = $mon;
     $dateObj = DateTime::createFromFormat('!m', $monthNum);
     $monthName = $dateObj->format('F');
     // March
     $sales = AppearSales::calculatePaidSalesCount($agent_id, $mon, $y);
     //                                        pr($sales);
     $lastmon = getFirstDayOfLastMonth($mon, $y, "n");
     $lastyear = getFirstDayOfLastMonth($mon, $y, "Y");
     $lastmonsales = AppearSales::calculatePaidSalesCount($agent_id, $lastmon, $lastyear);
     //revenue
     $rev = AppearSales::calculateRevenueCount($agent_id);
     $paid_count = AppearSales::paidCount($agent_id);
     $target = AppearSales::calculateTarget($paid_count);
     $dateObj = DateTime::createFromFormat('!m', $lastmon);
     $monthNameLast = $dateObj->format('F');
     // March
     $free = AppearSales::calculateFree($agent_id, $mon, $y);
     $json['acc_id'] = $acc->admin_id;
     $json['mon'] = $mon;
     $json['y'] = $y;
     $json['cube']['target']['total'] = $target['total'];
     $json['cube']['target']['nr'] = $target['nr'];
     if ($sales->total == null) {
         $sales->total = 0;
     }
     if ($sales->nr == null) {
         $sales->nr = 0;
     }
     $json['cube']['paidsales']['total'] = $sales->total;
     $json['cube']['paidsales']['nr'] = $sales->nr;
     $json['cube']['paidsales']['mon'] = $mon;
     $json['cube']['paidsales']['y'] = $y;
     if ($lastmonsales->total == null) {
         $lastmonsales->total = 0;
     }
     if ($lastmonsales->nr == null) {
         $lastmonsales->nr = 0;
     }
     $json['cube']['lastmon_paidsales']['total'] = $lastmonsales->total;
     $json['cube']['lastmon_paidsales']['nr'] = $lastmonsales->nr;
     $json['cube']['lastmon_paidsales']['mon'] = $lastmon;
     $json['cube']['lastmon_paidsales']['y'] = $lastyear;
     $json['cube']['freebies']['total'] = $free['total'];
     $json['cube']['freebies']['nr'] = $free['total_free'];
     $json['cube']['freebies']['mon'] = $mon;
     $json['cube']['freebies']['y'] = $y;
     $json['cube']['payout']['total'] = AppearSales::calculatePayout($agent_id, $mon, $y)['total'];
     $json['cube']['payout']['mon'] = $mon;
     $json['cube']['payout']['y'] = $y;
     $json['cube']['revenue']['total'] = AppearSales::calculateRevenue($agent_id);
     $json['cube']['revenue']['paid_nr'] = $paid_count;
     $json['cube']['revenue']['free_nr'] = AppearSales::freeCount($agent_id);
     //get applied banner
     $bm = new BannerModel();
     $arrBm = $bm->getWhere("banner_interval_begin <= {$paid_count} AND banner_interval_end >= {$paid_count} AND banner_active = 1");
     //        pr($arrBm);
     if (count($arrBm) > 0) {
         $selBanner = $arrBm[0];
         $json['banner'][] = array("url" => $selBanner->banner_link_url, "img" => _BPATH . _PHOTOURL . $selBanner->banner_img);
     }
     //get applied level
     $lv = new LevelModel();
     $arrLvl = $lv->getWhere("level_start<={$paid_count} AND level_end>={$paid_count} AND level_active = 1");
     if (count($arrLvl) > 0) {
         $selLvl = $arrLvl[0];
         $json['level'] = array("name" => $selLvl->level_name, "img" => _BPATH . _PHOTOURL . $selLvl->level_img);
     }
     $json['status_code'] = 1;
     $json['status_message'] = "Success";
     echo json_encode($json);
     die;
 }
Ejemplo n.º 2
0
 public function login()
 {
     IMBAuth::checkOAuth();
     $username = addslashes($_POST['username']);
     $password = addslashes($_POST['password']);
     //untuk deviceModel
     $device_id = addslashes($_POST['device_id']);
     $type = addslashes($_POST['type']);
     $acc = new Account();
     $arr = $acc->getWhere("admin_username = '******' OR admin_email ='{$username}'");
     //        pr($arr);
     if (count($arr) > 0) {
         $acc = $arr[0];
         if ($password == $acc->admin_password) {
             $json['status_code'] = 1;
             $json['status_message'] = "Success";
             $json_acc['acc_id'] = $acc->admin_id;
             $json_acc['username'] = $acc->admin_username;
             $json_acc['email'] = $acc->admin_email;
             $json_acc['user_token'] = md5($acc->admin_email . $acc->admin_password);
             $json['account'] = $json_acc;
             //dashboard
             $myid = $acc->admin_id;
             $kom = new KomisiModel();
             $arrKom = $kom->getWhere("komisi_acc_id = '{$myid}'  ORDER BY komisi_app_date ASC");
             $paid = 0;
             $unpaid = 0;
             $total = 0;
             $free = 0;
             $android = 0;
             $androidios = 0;
             $totalpaketbayar = 0;
             $totalpaket = 0;
             foreach ($arrKom as $kom) {
                 if ($kom->komisi_status == 1) {
                     $paid += $kom->komisi_value;
                 } else {
                     $unpaid += $kom->komisi_value;
                 }
                 $total += $kom->komisi_value;
                 if ($kom->komisi_paket_id == 1) {
                     //free
                     $free++;
                 }
                 if ($kom->komisi_paket_id == 2) {
                     //free
                     $android++;
                     $totalpaketbayar++;
                 }
                 if ($kom->komisi_paket_id == 3) {
                     //free
                     $androidios++;
                     $totalpaketbayar++;
                 }
                 $totalpaket++;
             }
             //get applied banner
             $bm = new BannerModel();
             $arrBm = $bm->getWhere("banner_interval_begin <= {$totalpaketbayar} AND banner_interval_end >= {$totalpaketbayar} AND banner_active = 1");
             if (count($arrBm) > 0) {
                 $selBanner = $arrBm[0];
                 $json_banner['banner_img'] = _BPATH . _PHOTOURL . $selBanner->banner_img;
                 $json_banner['banner_link_url'] = $selBanner->banner_link_url;
             }
             //get applied level
             $lv = new LevelModel();
             $arrLvl = $lv->getWhere("level_start<={$totalpaketbayar} AND level_end>={$totalpaketbayar} AND level_active = 1");
             if (count($arrLvl) > 0) {
                 $selLvl = $arrLvl[0];
                 $json_lvl['level_name'] = $selLvl->level_name;
                 $json_lvl['level_img'] = _BPATH . _PHOTOURL . $selLvl->level_img;
             }
             $dashboard['sales_total'] = $totalpaket;
             $dashboard['sales_paid'] = $totalpaketbayar;
             $dashboard['sales_fee'] = $free;
             $dashboard['sales_android'] = $android;
             $dashboard['sales_androidios'] = $androidios;
             $dashboard['money_total'] = $total;
             $dashboard['money_paid'] = $paid;
             $dashboard['money_unpaid'] = $unpaid;
             $dashboard['banner'] = $json_banner;
             $dashboard['level'] = $json_lvl;
             $json['dashboard'] = $dashboard;
             //myapps
             $app2acc = new App2Acc();
             //AND app_active = 1
             $apps = $app2acc->getWhereFromMultipleTable("ac_admin_id = '" . $acc->admin_id . "' AND ac_app_id = app_id ", array("AppAccount"));
             if (count($apps) > 0) {
                 foreach ($apps as $ap) {
                     $rr = array();
                     $rr['app_id'] = $ap->app_id;
                     $rr['app_icon'] = $ap->app_icon;
                     $rr['app_name'] = $ap->app_name;
                     $rr['app_active'] = $ap->app_active;
                     $rr['app_shortdes'] = $ap->app_shortdes;
                     $rr['app_token'] = $ap->app_token;
                     $rr['app_contract_end'] = $ap->app_contract_end;
                     $rr['app_google_play_link'] = $ap->app_google_play_link;
                     $rr['app_google_version'] = $ap->app_google_version;
                     $rr['app_ios_link'] = $ap->app_ios_link;
                     $rr['app_ios_version'] = $ap->app_ios_version;
                     $paket = new Paket();
                     $paket->getByID($ap->app_paket_id);
                     $rr['paket']['paket_id'] = $paket->paket_id;
                     $rr['paket']['paket_name'] = $paket->paket_name;
                     $json['apps'][] = $rr;
                 }
             } else {
                 $json['apps'] = array();
             }
             //update the device id on deviceModelCaps
             $dn = new DeviceModelCapsule();
             $dnquery = new DeviceModelCapsule();
             // langkah 1 , device ID ada device type ada
             $arrs = $dnquery->getWhere("device_id = '{$device_id}' AND device_type = '{$type}'");
             $dn = $arrs[0];
             if ($dn->did == "") {
                 $dn = new DeviceModelCapsule();
                 $dn->device_id = $device_id;
                 $dn->device_type = $type;
                 $dn->acc_id = $acc->admin_id;
                 $dn->firstlogin = leap_mysqldate();
             } else {
                 //kalau device id ada, acc di update
                 $dn->load = 1;
                 $dn->acc_id = $acc->admin_id;
             }
             $dn->dev_lng = addslashes($_POST['lng']);
             $dn->dev_lat = addslashes($_POST['lat']);
             $dn->logindate = leap_mysqldate();
             if ($dn->save()) {
                 $json['save_device_status'] = 1;
             }
             $json['powered_by_link'] = Efiwebsetting::getData("Powered_By_Link_Caps");
             echo json_encode($json);
             die;
         } else {
             $json['status_code'] = 0;
             $json['status_message'] = "Password Mismatched";
             echo json_encode($json);
             die;
         }
     } else {
         $json['status_code'] = 0;
         $json['status_message'] = "User Not Found";
         echo json_encode($json);
         die;
     }
 }