diff --git a/Application/Admin/Controller/AggregateFinanceSetController.class.php b/Application/Admin/Controller/AggregateFinanceSetController.class.php index 425081ecc..0a0ac2e05 100644 --- a/Application/Admin/Controller/AggregateFinanceSetController.class.php +++ b/Application/Admin/Controller/AggregateFinanceSetController.class.php @@ -8,22 +8,8 @@ use Think\Controller; * @author cz */ class AggregateFinanceSetController extends Controller { - // public $beginTime; - // public $endTime; - // public $date; - // public $nowdata; - // public $UserModel; - // public $ChartModel; - // public $LoginModel; - // public $SpendModel; - // public $PromoteModel; - // public $GameCountModel; - // public $addid; - // public $adddata; - // public $gameid; - // public $gamedata; - // public $reset=false; public $apihost; + public $token = "LYHTQDJS"; public function _initialize(){ $apihost = M("Kv")->field("value")->where("`key` = 'aggregate_finance_api'")->find(); @@ -31,34 +17,130 @@ class AggregateFinanceSetController extends Controller { echo "请先设置请求接口aggregate_finance_api的值".PHP_EOL;die; } $this->apihost = $apihost['value']; - //初始化 - // $this->UserModel =M("User","tab_"); - // $this->LoginModel =M("user_login_record","tab_"); - // $this->SpendModel =M("spend","tab_"); - // $this->PromoteModel =M("promote","tab_"); - // $this->model =M(); - // $this->PromoteCountModel =M("PromoteCount","tab_"); - // $this->GameCountModel =M("GameCount","tab_"); - // $this->nowdata =time(); - - // $group_concat_max_len = M()->execute("SET SESSION group_concat_max_len = 4294967295"); - // echo "set group_concat_max_len ok,beging count".PHP_EOL; - // if(I("reset")) $this->reset = true; - + } + public function setFreeDateCount($begin,$end='') + { + if($end == '') $end = $begin; + //判断日期格式 + $patten = "/^\d{4}[\-](0?[1-9]|1[012])[\-](0?[1-9]|[12][0-9]|3[01])$/"; + if (!preg_match($patten, $begin)) { + die("开始时间格式错误"); + } + if (!preg_match($patten, $end)) { + die("结束时间格式错误"); + } + if(strtotime($end) < strtotime($begin)){ + die("结束时间不能比开始时间小"); + } + if(strtotime($end)+86399-24*3600 > time()){ + die("结束时间不能大于当前"); + } + $starttime = $begin?strtotime($begin):mktime(0,0,0,date('m'),date('d'),date('Y')); + $endtime = $end?strtotime($end)+86399:$starttime+86399; + $datelist = get_date_list($starttime,$endtime,1); + $countdate = count($datelist); + for($i=0;$i<$countdate;$i++){ + $this->setDailyCount($datelist[$i]); + } } - public function setDaliyCount() + public function setDailyCount($stime="now") { - $w = (int)date("w"); - $d = (int)date("d"); - + if($stime=="now"){ + $stime=time(); + }else{ + $stime = strtotime($stime); + } + $nowdate = date("Y-m-d",$stime); + $w = (int)date("w",$stime); + $d = (int)date("d",$stime); + + if($w == 1 || $d == 1){ + if($w == 1){ + echo $nowdate.":".PHP_EOL; + echo "--周结begin".PHP_EOL; + $this->setWeekCount($stime); + } + if($d == 1){ + echo $nowdate.":".PHP_EOL; + echo "--月结&补点begin".PHP_EOL; + $this->setMonthCount($stime); + } + }else{ + echo $nowdate."非周一和月初,无需任何处理".PHP_EOL; + } + } + public function setWeekCount($stime)//进行周结 + { + $begintime = mktime(0,0,0,date('m',$stime),date('d',$stime)-7,date('Y',$stime)); + $endtime = mktime(0,0,0,date('m',$stime),date('d',$stime),date('Y',$stime))-1; + $this->getAndSaveData(0,$begintime,$endtime); + } + public function setMonthCount($stime)//进行周结 + { + $thismonth = date('m',$stime); + $thisyear = date('Y',$stime); + if ($thismonth == 1) { + $lastmonth = 12; + $lastyear = $thisyear - 1; + } else { + $lastmonth = $thismonth - 1; + $lastyear = $thisyear; + } + $lastStartDay = $lastyear . '-' . $lastmonth . '-1'; + $lastEndDay = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay)); + $begintime = strtotime($lastStartDay);//上个月的月初时间戳 + $endtime = strtotime($lastEndDay)+24*3600-1;//上个月的月末时间戳 + //普通月结 + $this->getAndSaveData(1,$begintime,$endtime); + //补点 + $this->getAndSaveData(2,$begintime,$endtime); - $this->setDateCount($begin); } - public function setWeekCount()//进行周结 + protected function getAndSaveData($type,$begintime,$endtime) { - echo $this->apihost; - # code... + $sign = md5($begintime.$endtime.$type.$this->token); + $arr = [ + "begintime"=>$begintime, + "endtime"=>$endtime, + "type"=>$type, + "sign"=>$sign + ]; + $dataurl .= $this->apihost."&".http_build_query($arr); + $html = file_get_contents($dataurl); + $rsp = json_decode($html,true); + var_dump($dataurl); + if($rsp['code'] != 1){ + echo $rsp['error'].PHP_EOL;die; + } + //成功插入 + $Aggregate = M("aggregate_statement","tab_"); + $begintimestr = date("Y-m-d",$begintime); + $endtimestr = date("Y-m-d",$endtime); + if($rsp['count'] > 0){ + //插入数据 + foreach ($rsp['data'] as $k => $v) { + foreach ($v["game_list"] as $ke => &$va) { + $va['begintime'] = $begintimestr; + $va['endtime'] = $endtimestr; + $va['fax_ratio'] = 0; + } + $v["statement_info"] = json_encode($v["game_list"],JSON_UNESCAPED_UNICODE); + unset($v["game_list"]); + $v['begintime'] = $begintime; + $v['endtime'] = $endtime; + $v['create_time'] = time(); + $Aggregate->add($v); + } + } + + if($type == 0){ + echo "----周结统计ok".PHP_EOL; + }elseif($type == 1){ + echo "----月结统计ok".PHP_EOL; + }elseif($type == 2){ + echo "----补点统计ok".PHP_EOL; + } } @@ -85,36 +167,7 @@ class AggregateFinanceSetController extends Controller { - public function setFreeDateCount($begin,$end='') - { - if($end == '') $end = $begin; - //判断日期格式 - $patten = "/^\d{4}[\-](0?[1-9]|1[012])[\-](0?[1-9]|[12][0-9]|3[01])$/"; - if (!preg_match($patten, $begin)) { - die("开始时间格式错误"); - } - if (!preg_match($patten, $end)) { - die("结束时间格式错误"); - } - if(strtotime($end) < strtotime($begin)){ - die("结束时间不能比开始时间小"); - } - if(strtotime($end)+86399 > time()){ - die("结束时间不能包含今日"); - } - if($begin == $end){ - $this->setDateCount($begin); - }else{ - $starttime = $begin?strtotime($begin):mktime(0,0,0,date('m'),date('d')-1,date('Y')); - $endtime = $end?strtotime($end)+86399:$starttime+86399; - $datelist = get_date_list($starttime,$endtime,1); - $countdate = count($datelist); - for($i=0;$i<$countdate;$i++){ - $this->setDateCount($datelist[$i]); - } - } - - } + public function setDateCount($date) { $this->date = $date; diff --git a/Data/update.sql b/Data/update.sql index 3e34bd927..4b7f8a2d7 100644 --- a/Data/update.sql +++ b/Data/update.sql @@ -1622,22 +1622,23 @@ INSERT INTO `platform`.`sys_kv` (`key`, `value`, `type`, `remark`) VALUES ('aggr CREATE TABLE `tab_aggregate_statement` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键', - `statement_type` tinyint(2) DEFAULT '0' COMMENT '对账类型(0-周结,1月结,2补点)', - `company_id` int(11) DEFAULT '0' COMMENT '对账公司id', - `company_name` varchar(60) NOT NULL COMMENT '对账公司名称', + `withdraw_type` tinyint(2) DEFAULT '0' COMMENT '对账类型(0-周结,1月结,2补点)', + `channel_id` int(11) DEFAULT '0' COMMENT '对账公司id', + `channel_name` varchar(60) NOT NULL COMMENT '对账公司名称', `link_phone` varchar(24) DEFAULT NULL COMMENT '对账公司联系人电话', - `statement_begin_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账开始时间', - `statement_end_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账截止时间', + `begintime` int(11) NOT NULL DEFAULT '0' COMMENT '对账开始时间', + `endtime` int(11) NOT NULL DEFAULT '0' COMMENT '对账截止时间', `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建对账单时间', - `statement_money` decimal(10,2) DEFAULT '0.00' COMMENT '对账金额', - `pay_amount` decimal(10,2) DEFAULT '0.00' COMMENT '原始金额合计', + `ratio_money` decimal(10,2) DEFAULT '0.00' COMMENT '对账金额', + `pay_money` decimal(10,2) DEFAULT '0.00' COMMENT '原始金额合计', + `pay_type` tinyint(2) DEFAULT '0' COMMENT '收款方(0-甲方付给乙方,乙方收款;1-乙方付给甲方,甲方收款)', `ext_field` longtext COMMENT '凭证地址', - `first_party_info` longtext NOT NULL COMMENT '甲方相关信息json', - `second_party_info` longtext NOT NULL COMMENT '乙方相关信息json', + `first_party_info` longtext DEFAULT NULL COMMENT '甲方相关信息json', + `second_party_info` longtext DEFAULT NULL COMMENT '乙方相关信息json', `statement_info` longtext NOT NULL COMMENT '订单相关信息json', - `verify_status` tinyint(2) DEFAULT '0' COMMENT '审核状态 0:未审核 1:审核通过 2:审核拒绝', + `verify_status` tinyint(2) DEFAULT '0' COMMENT '审核状态 -1审核拒绝 0:系统生成结算单 1:申请开票 2:审核同意 3:已开票 4:上传收款凭证 5已到账', PRIMARY KEY (`id`), - KEY `statement_type` (`statement_type`) USING BTREE, - KEY `company_id` (`company_id`) USING BTREE, + KEY `withdraw_type` (`withdraw_type`) USING BTREE, + KEY `channel_id` (`channel_id`) USING BTREE, KEY `link_phone` (`link_phone`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='cp/公会对账单'; \ No newline at end of file +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='聚合渠道结算单'; \ No newline at end of file