예제 #1
0
 /**
  * 更新权限
  * 
  *
  **/
 public function modifyParterPermission($group_id, $total_default_permission, $default_permission, $PartnerIds)
 {
     echo "<pre>";
     $oPartnerApp = new Config_Partner_App();
     $oApp = new Config_App();
     $permission_arr = array('default' => array(), 'app_default' => array(), 'list' => array());
     //留下全局默认权限数组
     if (is_array($total_default_permission)) {
         foreach ($total_default_permission as $key => $value) {
             $t_d = explode("_", $value);
             if (count($t_d) == 2) {
                 $permission_arr['default'][$t_d[0]][$t_d[1]] = 1;
             }
         }
     }
     //留下各游戏默认权限数组
     if (is_array($default_permission)) {
         foreach ($default_permission as $key => $value) {
             $t_a = explode("_", $value);
             if (count($t_a) == 3) {
                 //如果全局已经默认,则无需再记录
                 if (!isset($permission_arr['default'][$t_a[1]][$t_a[2]])) {
                     $permission_arr['app_default'][$t_a[0]][$t_a[1]][$t_a[2]] = 1;
                 }
             }
         }
     }
     $partner_info = array();
     //留下零散合作商权限数组
     if (isset($PartnerIds)) {
         foreach ($PartnerIds as $key => $value) {
             $t_p = explode("_", $value);
             if (count($t_p) == 2) {
                 $arr = array($t_p[1], $t_p[0]);
                 //获取合作商基本信息
                 $p = $oPartnerApp->getRow($arr, 'AreaId');
                 //判断合作商类型
                 if ($t_p[1] == 1) {
                     $partner_type = 1;
                 } else {
                     $partner_type = 2;
                 }
                 $partner_info[$t_p[0]][$t_p[1]] = array('partner_type' => $partner_type, 'AreaId' => $p['AreaId']);
                 //如果全局已经默认,则无需再记录
                 if (!isset($permission_arr['default'][$p['AreaId']][$partner_type])) {
                     //如果指定游戏已经默认,则无需再记录
                     if (!isset($permission_arr['app_default'][$t_p[0]][$p['AreaId']][$partner_type])) {
                         $permission_arr['list'][$t_p[0]][$t_p[1]] = 1;
                     }
                 }
             }
         }
     }
     //获取原有的权限
     $sql = "select PartnerId,AppId,partner_type,AreaId from {$this->table} where group_id = ?";
     $permission_now = $this->db->getAll($sql, $group_id);
     if ($permission_now) {
         foreach ($permission_now as $key => $value) {
             if ($value['AppId'] == 0) {
                 //如果原来有现在没有则标记删除
                 if (!isset($permission_arr['default'][$value['AreaId']][$value['partner_type']])) {
                     $permission_arr['default'][$value['AreaId']][$value['partner_type']] = 0;
                     //删除权限明细中的相关
                     foreach ($permission_arr['list'] as $AppId => $partner_data) {
                         foreach ($partner_data as $PartnerId => $data) {
                             $arr = array($PartnerId, $AppId);
                             $p = $partner_info[$AppId][$PartnerId];
                             if ($value['AreaId'] == $p['AreaId'] && $value['partner_type'] == $p['partner_type']) {
                                 unset($permission_arr['list'][$AppId][$PartnerId]);
                             }
                         }
                     }
                 } else {
                     unset($permission_arr['default'][$value['AreaId']][$value['partner_type']]);
                 }
             } else {
                 if ($value['PartnerId'] == 0) {
                     //如果原来有现在没有则标记删除
                     if (!isset($permission_arr['app_default'][$value['AppId']][$value['AreaId']][$value['partner_type']])) {
                         $permission_arr['app_default'][$value['AppId']][$value['AreaId']][$value['partner_type']] = 0;
                         //删除权限明细中的相关
                         if (isset($permission_arr['list'][$value['AppId']])) {
                             foreach ($permission_arr['list'][$value['AppId']] as $PartnerId => $data) {
                                 $arr = array($PartnerId, $value['AppId']);
                                 $p = $partner_info[$value['AppId']][$PartnerId];
                                 if ($value['AreaId'] == $p['AreaId'] && $value['partner_type'] == $p['partner_type']) {
                                     if (isset($permission_arr['list'][$value['AppId']][$PartnerId])) {
                                         unset($permission_arr['list'][$value['AppId']][$PartnerId]);
                                     }
                                 }
                             }
                         }
                     } else {
                         unset($permission_arr['app_default'][$value['AppId']][$value['AreaId']][$value['partner_type']]);
                     }
                 } else {
                     //如果原来有现在没有则标记删除
                     if (!isset($permission_arr['list'][$value['AppId']][$value['PartnerId']])) {
                         $permission_arr['list'][$value['AppId']][$value['PartnerId']] = 0;
                     } else {
                         unset($permission_arr['list'][$value['AppId']][$value['PartnerId']]);
                     }
                 }
             }
         }
     }
     //写入数据库
     if (isset($permission_arr['default'])) {
         foreach ($permission_arr['default'] as $AreaId => $partner) {
             if (is_array($partner)) {
                 foreach ($partner as $partner_type => $to_do) {
                     if ($to_do == 0) {
                         $this->DelDefaultPermission($group_id, $AreaId, $partner_type);
                     } else {
                         $this->InsDefaultPermission($group_id, $AreaId, $partner_type);
                     }
                 }
             }
         }
     }
     //写入数据库
     if (isset($permission_arr['app_default'])) {
         foreach ($permission_arr['app_default'] as $AppId => $app) {
             foreach ($app as $AreaId => $partner) {
                 if (is_array($partner)) {
                     foreach ($partner as $partner_type => $to_do) {
                         if ($to_do == 0) {
                             $this->DelAppDefaultPermission($group_id, $AppId, $AreaId, $partner_type);
                         } else {
                             $this->InsAppDefaultPermission($group_id, $AppId, $AreaId, $partner_type);
                         }
                     }
                 }
             }
         }
     }
     //写入数据库
     if (isset($permission_arr['list'])) {
         foreach ($permission_arr['list'] as $AppId => $app) {
             foreach ($app as $PartnerId => $to_do) {
                 if ($to_do == 0) {
                     $this->DelPermission($group_id, $AppId, $PartnerId);
                 } else {
                     $this->InsPermission($group_id, $AppId, $PartnerId, $partner_info[$AppId][$PartnerId]['AreaId'], $partner_info[$AppId][$PartnerId]['partner_type']);
                 }
             }
         }
     }
 }
예제 #2
0
파일: Pay.php 프로젝트: eappl/prototype
 public function getPayDay($StartDate, $EndDate, $PassageId, $oWherePartnerPermission)
 {
     //查询列
     $select_fields = array('PayUser' => 'count(distinct(AcceptUserId))', 'PayCount' => 'count(*)', 'TotalCoin' => 'sum(Coin)', 'TotalAmount' => 'sum(Amount)', 'Date' => "from_unixtime(PayTime,'%Y-%m-%d')", 'AppId', 'PartnerId');
     //分类统计列
     $group_fields = array('Date', 'AppId', 'PartnerId');
     //初始化查询条件
     $whereStartDate = $StartDate ? " PayTime >= '" . strtotime($StartDate) . "' " : "";
     $whereEndDate = $EndDate ? " PayTime <= '" . (strtotime($EndDate) + 86400 - 1) . "' " : "";
     $wherePassage = $PassageId ? " PassageId = " . $PassageId . " " : "";
     $whereCondition = array($whereStartDate, $whereEndDate, $oWherePartnerPermission, $wherePassage);
     //生成查询列
     $fields = Base_common::getSqlFields($select_fields);
     //生成分类汇总列
     $groups = Base_common::getGroupBy($group_fields);
     //生成条件列
     $where = Base_common::getSqlWhere($whereCondition);
     $date = $StartDate;
     //初始化结果数组
     $StatArr['TotalData'] = array('TotalCoin' => 0, 'TotalAmount' => 0, 'PayUser' => 0, 'PayCount' => 0, 'ConvertedAmount' => 0);
     do {
         $StatArr['PayDate'][$date] = array('Total' => array('TotalCoin' => 0, 'TotalAmount' => 0, 'PayUser' => 0, 'PayCount' => 0, 'ConvertedAmount' => 0));
         $date = date("Y-m-d", strtotime($date) + 86400);
     } while (strtotime($date) <= strtotime($EndDate));
     $DateStart = date("Ym", strtotime($StartDate));
     $DateEnd = date("Ym", strtotime($EndDate));
     $DateList = array();
     $Date = $StartDate;
     do {
         $D = date("Ym", strtotime($Date));
         $DateList[] = $D;
         $Date = date("Y-m-d", strtotime("{$Date} +1 month"));
     } while ($D != $DateEnd);
     $oPartnerApp = new Config_Partner_App();
     $oArea = new Config_Area();
     foreach ($DateList as $key => $value) {
         $table_name = Base_Widget::getDbTable($this->table_date) . "_" . $value;
         $sql = "SELECT  {$fields} FROM {$table_name} as log where 1 " . $where . $groups;
         $PayDateArr = $this->db->getAll($sql);
         if (is_array($PayDateArr)) {
             foreach ($PayDateArr as $key => $Stat) {
                 if (!isset($PartnerAppList[$Stat['AppId']][$Stat['PartnerId']])) {
                     $PartnerAppList[$Stat['AppId']][$Stat['PartnerId']] = $oPartnerApp->getRow(array($Stat['PartnerId'], $Stat['AppId']));
                 }
                 if (!isset($AreaList[$PartnerAppList[$Stat['AppId']][$Stat['PartnerId']]['AreaId']])) {
                     $AreaList[$PartnerAppList[$Stat['AppId']][$Stat['PartnerId']]['AreaId']] = $oArea->getRow($PartnerAppList[$Stat['AppId']][$Stat['PartnerId']]['AreaId']);
                 }
                 $currency_rate = $AreaList[$PartnerAppList[$Stat['AppId']][$Stat['PartnerId']]['AreaId']]['currency_rate'];
                 //累加数据
                 if (isset($StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']])) {
                     $StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']]['PayCount'] += $Stat['PayCount'];
                     $StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']]['PayUser'] += $Stat['PayUser'];
                     $StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']]['TotalCoin'] += $Stat['TotalCoin'];
                     $StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']]['TotalAmount'] += $Stat['TotalAmount'];
                     $StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']]['ConvertedAmount'] += $Stat['TotalAmount'] * $currency_rate;
                 } else {
                     $StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']] = array('TotalCoin' => 0, 'TotalAmount' => 0, 'PayCount' => 0, 'PayUser' => 0, 'ConvertedAmount' => 0);
                     $StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']]['PayCount'] += $Stat['PayCount'];
                     $StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']]['PayUser'] += $Stat['PayUser'];
                     $StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']]['TotalCoin'] += $Stat['TotalCoin'];
                     $StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']]['TotalAmount'] += $Stat['TotalAmount'];
                     $StatArr['PayDate'][$Stat['Date']]['Detail'][$Stat['AppId']][$Stat['PartnerId']]['ConvertedAmount'] += $Stat['TotalAmount'] * $currency_rate;
                 }
                 $StatArr['PayDate'][$Stat['Date']]['Total']['PayCount'] += $Stat['PayCount'];
                 $StatArr['PayDate'][$Stat['Date']]['Total']['PayUser'] += $Stat['PayUser'];
                 $StatArr['PayDate'][$Stat['Date']]['Total']['ConvertedAmount'] += $Stat['TotalAmount'] * $currency_rate;
                 $StatArr['TotalData']['PayCount'] += $Stat['PayCount'];
                 $StatArr['TotalData']['ConvertedAmount'] += $Stat['TotalAmount'] * $currency_rate;
             }
             $StatArr['TotalData']['AmountPerPay'] = $StatArr['TotalData']['PayCount'] ? $StatArr['TotalData']['ConvertedAmount'] / $StatArr['TotalData']['PayCount'] : 0;
         }
     }
     return $StatArr;
 }