// +---------------------------------------------------------------------- namespace Admin\Controller; use User\Api\UserApi as UserApi; use function GuzzleHttp\Psr7\str; /** * 后台首页控制器 * @author 麦当苗儿 */ class TimingController extends AdminController { public function _initialize(){ } public function caculateDeviceInfo() { $start = strtotime(date("Ymd",time()))-86400; $end = $start+1; // if (I('time')) { // $start = strtotime(I('time')); // $end = $start+1; // } if (I('start')&&I('end')) { $start = strtotime(I('start')); $end = strtotime(I('end'))+1; } else if (I('start')&&!I('end')) { $start = strtotime(I('start')); $end = strtotime(I('start'))+1; } else if (!I('start')&&I('end')) { $start = strtotime(I('end')); $end = strtotime(I('end'))+1; } if ($start>$end) { echo '开始时间不能大于结束时间'; } ini_set('memory_limit','1024M'); // $device = D('DeviceRecord'); // echo 1; for($startTime = $start;$startTime<$end;$startTime=$startTime+86400) { echo date("Y-m-d",$startTime).' 安卓 '; //当日新增设备 $newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>1])->group('unique_code')->select(false); $data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count(); echo $data['new_device'].' '; //当日活跃设备 $data['active_device'] = $this->active(['create_time'=>array('between',[$startTime,$startTime+86399]),'version'=>1]); echo $data['active_device'].' '; $data['time'] = $startTime; $data['version'] = 1; $data['today_new_device'] =json_encode($this->news_on_time(['create_time'=>['between',[$startTime,$startTime+86399]]],'news',5,'time,version','time',1)); // echo M('device_record','tab_')->_sql()."\n"; $data['today_active_device'] =json_encode($this->active_on_time(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>1],'active',5,'time,version')); // echo M('device_record','tab_')->_sql()."\n"; $data['today_model_device'] = json_encode($this->model(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>1])); $data['model'] = json_encode($this->modelDevice(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>1])); $duration = $this->duration(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])]); $newSqls = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->group('unique_code')->select(false); $data['duration7'] = ($duration/M('device_record','tab_')->table('(' . $newSqls . ') as a')->where(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])])->order('create_time')->count())/7; $getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->find(); echo "\n"; if (!$getStatistics) { M('device_statistics','tab_')->add($data); } else { M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->save($data); } echo date("Y-m-d",$startTime).' 苹果 '; //当日新增设备 $newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>2])->group('unique_code')->select(false); $data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count(); echo $data['new_device'].' '; //当日活跃设备 $data['active_device'] = $this->active(['create_time'=>array('between',[$startTime,$startTime+86399]),'version'=>2]); echo $data['active_device'].' '; $data['time'] = $startTime; $data['version'] = 2; $data['today_new_device'] =json_encode($this->news_on_time(['create_time'=>['between',[$startTime,$startTime+86399]]],'news',5,'time,version','time',2)); // echo M('device_record','tab_')->_sql();die(); $data['today_active_device'] =json_encode($this->active_on_time(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2],'active',5,'time,version')); $data['today_model_device'] = json_encode($this->model(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2])); $data['model'] = json_encode($this->modelDevice(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2])); // $duration = $this->duration(['create_time'=>array('between',[$startTime-86400*7,$startTime-1]),'version'=>2]); // $data['duration7'] = ($duration/M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])])->order('create_time')->count())/7; $data['duration7'] = 0; $getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->find(); echo "\n"; if (!$getStatistics) { M('device_statistics','tab_')->add($data); } else { M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->save($data); } } } public function caculateTodayDevice() { $start = strtotime(date("Ymd",time())); $end = $start+1; if (I('start')&&I('end')) { $start = strtotime(I('start')); $end = strtotime(I('end'))+1; } else if (I('start')&&!I('end')) { $start = strtotime(I('start')); $end = strtotime(I('start'))+1; } else if (!I('start')&&I('end')) { $start = strtotime(I('end')); $end = strtotime(I('end'))+1; } if ($start>$end) { echo '开始时间不能大于结束时间'; } ini_set('memory_limit','1024M'); // $device = D('DeviceRecord'); // echo 1; for($startTime = $start;$startTime<$end;$startTime=$startTime+86400) { echo date("Y-m-d",$startTime).' 安卓 '; //当日新增设备 $newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>1])->group('unique_code')->select(false); $data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count(); $data['time'] = $startTime; echo $data['new_device'].' '; $duration = $this->duration(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])]); $newSqls = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->group('unique_code')->select(false); $data['duration7'] = ($duration/M('device_record','tab_')->table('(' . $newSqls . ') as a')->where(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])])->order('create_time')->count())/7; $data['version'] = 1; $getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->find(); echo "\n"; if (!$getStatistics) { M('device_statistics','tab_')->add($data); } else { M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->save($data); } $data['duration7'] = 0; echo date("Y-m-d",$startTime).' 苹果 '; //当日新增设备 $newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>2])->group('unique_code')->select(false); $data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count(); echo $data['new_device'].' '; $data['version'] = 2; $getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->find(); echo "\n"; if (!$getStatistics) { M('device_statistics','tab_')->add($data); } else { M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->save($data); } } } public function duration($map=array()) { return M('device_record','tab_')->where($map)->sum('duration'); } public function active($map=array()) { $sql = M('device_record','tab_')->field('create_time,model,unique_code')->where($map)->select(false); $sql = M('device_record','tab_')->table('(' . $sql . ') as a')->group('unique_code')->order('create_time')->select(false); $sql = "select count(*) as count from ({$sql})t"; $count = M('device_record','tab_')->query($sql); return $count[0]['count']; } public function news_on_time($map=array(),$field='news',$flag=1,$group='time',$order='time',$version = 1) { switch($flag) { case 2:{$dateform = '%Y-%m';};break; case 3:{$dateform = '%Y-%u';};break; case 4:{$dateform = '%Y';};break; case 5:{$dateform = '%Y-%m-%d %H';};break; default:$dateform = '%Y-%m-%d'; } $sql = M('device_record','tab_')->field('min(create_time) as create_time,version,unique_code,id')->where(['version'=>$version])->group('unique_code')->select(false); $news = M('device_record','tab_')->table('(' . $sql . ') as a') ->field('FROM_UNIXTIME(a.create_time, "'.$dateform.'") as '.$group.',group_concat(a.id) as id,group_concat(a.unique_code) as unique_code ,COUNT(a.unique_code) AS '.$field) ->where($map)->group($group)->order($order)->select(); // echo M('device_record','tab_')->_sql();die(); return $news; } public function active_on_time($map=array(),$field='active',$flag=1,$group='time',$order='time') { switch($flag) { case 2:{$dateform = '%Y-%m';};break; case 3:{$dateform = '%Y-%u';};break; case 4:{$dateform = '%Y';};break; case 5:{$dateform = '%Y-%m-%d %H';};break; default:$dateform = '%Y-%m-%d'; } $sql = M('device_record','tab_')->field('create_time,version,unique_code,id')->where($map)->select(false); $mid = M('device_record','tab_')->table('(' . $sql . ') as m')->group('unique_code')->select(false); $active = M('device_record','tab_')->table('(' . $mid . ') as a') ->field('FROM_UNIXTIME(a.create_time, "'.$dateform.'") as '.$group.',group_concat(a.id) as id,group_concat(a.unique_code) as unique_code ,COUNT(a.unique_code) AS '.$field) ->group($group)->order($order)->select(); // echo $this->_sql();die(); return $active; } public function model($map=array()) { $sql = M('device_record','tab_')->field('create_time,model,version,unique_code')->where($map)->select(false); $mid = M('device_record','tab_')->table('(' .$sql. ') as m')->group('unique_code')->select(false); return M('device_record','tab_')->table('(' .$mid. ') as a')->field('a.model,version,count(a.unique_code) as count')->group('model,version')->order('count desc')->select(); } public function modelDevice($map=array()) { $sql = M('device_record','tab_')->field('model,version,unique_code')->where($map)->select(false); $mid = M('device_record','tab_')->table('(' .$sql. ') as m')->group('unique_code')->select(); return $mid; } //格式 starttime 20200229 endtime 20200230 public function setAvailableBalance() { if (strtotime($_GET['endtime'])field("sum(`pay_amount`) as pay_amount,promote_id,promote_account,tab_spend.game_id,tab_spend.game_name,tab_spend.server_id,tab_spend.server_name,CASE WHEN old_value_ratio is NULL THEN 0 ELSE sum(`pay_amount`) * old_value_ratio END as available_balance") ->join('left join tab_resource_verify_config as config on tab_spend.game_id = config.game_id and config.status = 1') ->where(['pay_status'=>1,'pay_way'=>['egt',1],'pay_time'=>['between',[$start,$start+86399]]]) ->group('promote_id,game_id,server_id') ->select(); // dump($data);die(); foreach ($data as $key => $value) { $insert['promote_id'] = $value['promote_id']; $insert['promote_account'] = $value['promote_account']; $insert['game_id'] = $value['game_id']; $insert['game_name'] = $value['game_name']; $insert['available_balance'] = round($value['available_balance'],0); $insert['server_id'] = $value['server_id']; $insert['server_name'] = $value['server_name']; $availableBalanceData = M('promote_game_available_balance','tab_') ->where(['promote_id'=>$value['promote_id'],'game_id'=>$value['game_id'],'server_id'=>$value['server_id']]) ->find(); if (round($value['available_balance'],0) > 0 && !$availableBalanceData) { M('promote_game_available_balance','tab_')->add($insert); } else if (round($value['available_balance'],0) > 0 && $availableBalanceData) { M('promote_game_available_balance','tab_') ->where(['promote_id'=>$value['promote_id'],'game_id'=>$value['game_id'],'server_id'=>$value['server_id']]) ->setInc('available_balance',round($value['available_balance'],0)); } // dump(round($value['available_balance'],0)); } } echo '执行成功'; } public function getTogetherUserAccount() { if (I('user_id','')) { $user_id = I('user_id',''); } else { return false; } $data = M('user','tab_')->field('account')->where(['id'=>$user_id])->find(); // var_dump($data); if (!$data) { return false; } $this->ajaxReturn($data); } public function caculateMarketList() { $map = []; $map['my_time'] = date('Y-m',strtotime('-1 month')); if ($_REQUEST['count_date']) { $map['my_time'] = $_REQUEST['count_date']; } if ($_REQUEST['count_date'] == 'all') { $map['my_time'] = ['neq', date('Y-m',time())]; } $spendMap['tab_spend.pay_status'] = 1; //获取spend表中的数据,同时根据会长id进行group分类 $data = M('Spend','tab_') ->field("FROM_UNIXTIME(pay_time,'%Y-%m') as my_time,sum(pay_amount) as pay_amount,game_id,tab_spend.game_name,SUBSTRING_INDEX(tab_spend.`game_name`,\"(\",1) as game_names,promote_id,promote_account,company_relation,company_belong,CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(`chain`,\"/\",2),\"/\",-1)='' THEN promote_id ELSE SUBSTRING_INDEX(SUBSTRING_INDEX(`chain`,\"/\",2),\"/\",-1) END as root_id,tab_game.ratio,tab_game.relation_game_id,tab_spend.sdk_version ") ->join("left join tab_promote on promote_id = tab_promote.id") ->join("left join tab_game on tab_game.id=tab_spend.game_id") ->where($spendMap) ->group("my_time,game_id,root_id") ->order("my_time Desc") ->select(false); //关联表获取会长账号名 $data = M()->table('('.$data.') as a') ->field("my_time,pay_amount,a.game_id,game_name,game_names,a.promote_id,a.promote_account,a.company_relation,a.company_belong,CASE WHEN root_id is null THEN 0 ELSE root_id END as root_id,CASE WHEN account is null THEN '官方渠道' ELSE account END as account,tab_ratio.ratio as ratio,turnover_ratio,a.ratio as game_ratio,a.sdk_version") ->join("left join tab_promote on root_id = tab_promote.id") ->join("left join tab_promote_game_ratio as tab_ratio on tab_ratio.game_id = a.relation_game_id and tab_ratio.promote_id=root_id and tab_ratio.status=1") ->where($map) ->group("my_time,game_id,root_id") ->order("my_time Desc") ->select(); // dump($data);die(); foreach($data as $key => $value) { echo "{$value['my_time']}-{$value['promote_account']}-{$value['game_name']}:{$value['pay_amount']}\n"; $mytime = $value['my_time']; $nextMonth = date('Y-m',strtotime("$mytime + 1 month")); $game_id = $value['game_id']; $gameInfo = M('game','tab_')->where(['id'=>$game_id])->getField('game_name'); $gameName = substr($gameInfo,0,strpos($gameInfo,'(')); $gameMap['game_name'] = ['like','%'.$gameName.'%']; $gameIdArr = M('game','tab_')->field('id')->where($gameMap)->select(); $gameNameIdArr = []; foreach($gameIdArr as $gameKey => $gameValue){ $gameNameIdArr[] = $gameValue['id']; } $promote_id = $value['promote_id']; $pay_status = 1; $promoteInfo = M('promote','tab_')->where(['id'=>$promote_id])->find(); $level = $promoteInfo['level']; if($promote_id != 0) { $promoteIdArr = []; if ($level == 1) { $rootPromoteId = $promote_id; $promoteIdArr[] = $promote_id; }else { $chain = $promoteInfo['chain']; $chainArr = explode('/',$chain); $rootPromoteId = $chainArr[1]; } $where1['chain'] = array('like', '%/' . $rootPromoteId. '/%'); $promoteIdInfo = M('promote','tab_')->field('id')->where($where1)->select(); foreach($promoteIdInfo as $key2 => $v1) { $promoteIdArr[] = $v1['id']; } $where['promote_id'] = ['in',$promoteIdArr]; if (!$promoteIdArr) { $where['promote_id']= 0; } }else { $where['promote_id'] = 0; } $where['game_id'] = ['in',$gameNameIdArr]; $where['pay_status'] = 1; $begTime = strtotime($mytime); $endTime = strtotime($nextMonth); $where['pay_time'] = ['between',[$begTime,$endTime]]; $spendInfo = M('spend','tab_')->field('pay_amount,pay_way')->where($where)->select(); $initNum = 0; foreach($spendInfo as $key1 => $spendValue) { $pay_way = $spendValue['pay_way']; $channel_rate = $this->getChannelConfig($pay_way) / 100; $initNum += $spendValue['pay_amount'] * $channel_rate; } $data[$key]['pay_amount'] = $value['pay_amount'] - $initNum; $data[$key]['upstream'] = caculateUpstream($value['game_id'],$value['pay_amount']); if ($value['ratio']) { $data[$key]['downstream'] = $value['pay_amount'] * ($value['ratio']*0.01); } else { $data[$key]['downstream'] = $value['pay_amount'] * ($value['game_ratio']*0.01); } $value['turnover_ratio'] = json_decode($value['turnover_ratio'],true); // dd($value); if (is_array($value['turnover_ratio'])) { foreach($value['turnover_ratio'] as $k =>$v) { if(($value['pay_amount']>=$v['turnover']&&$v['instanceof']==1) || $value['pay_amount']>$v['turnover']) { $data[$key]['downstream'] = $value['pay_amount'] * ($v['ratio']*0.01); } } } $data[$key]['highquality'] = number_format(($value['pay_amount'] - $initNum - $data[$key]['upstream']-$data[$key]['downstream']) * (1-0.0672),2,'.',''); if (!$data[$key]['company_belong']) { $data[$key]['company_belong'] = getCompanyBlong(0); } else { $data[$key]['company_belong'] = getCompanyBlong($data[$key]['company_belong']); } $data[$key]['company_relation'] = $data[$key]['company_relation']?'只维护':'自主开发及维护'; } foreach($data as $key => $value) { $is_hav = M('market_balance','tab_')->where(['my_time'=>$value['my_time'], 'game_id'=>$value['game_id'], 'promote_id'=>$value['promote_id'], 'root_id'=>$value['root_id']])->find(); if (!$is_hav) { M('market_balance','tab_')->add($value); } else { M('market_balance','tab_') ->where(['my_time'=>$value['my_time'], 'game_id'=>$value['game_id'], 'promote_id'=>$value['promote_id'], 'root_id'=>$value['root_id']]) ->save(['pay_amount'=>$value['pay_amount'], 'ratio'=>$value['ratio'], 'turnover_ratio'=>$value['turnover_ratio'], 'game_ratio'=>$value['game_ratio'], 'upstream'=>$value['upstream'], 'downstream'=>$value['downstream'], 'highquality'=>$value['highquality']]); } } echo 'success'; // dump($data);die(); } public function getChannelConfig($pay_way = 0,$config=false) { if(!$config) { $payWayName = $this->pay_way_name[$pay_way]; $toolConfig = M('tool','tab_')->where(['name'=>$payWayName])->find(); $config = json_decode($toolConfig['config'],true); if(empty($config['channel_rate'])){ $channel_rate = 0; }else { $channel_rate = $config['channel_rate']; } }else { foreach($this->pay_way_name as $key => $value) { $name = $value; $toolConfig = M('tool','tab_')->where(['name'=>$name])->find(); $config = json_decode($toolConfig['config'],true); if(empty($config['channel_rate'])){ $channel_rate[$key] = 0; }else { $channel_rate[$key] = $config['channel_rate']; } } } return $channel_rate; } public function setPromoteStatistics() { echo "-------------------------------------------------------------\n"; $startTime = strtotime("20190829"); if (I("start_time")=="yesterday") { $startTime = strtotime(date("Y-m-d",strtotime("-1 day"))); } $endTime = time(); if (I("start_time")) { $startTime = strtotime(I("start_time")); } if (I("end_time")) { $endTime = strtotime(I("end_time")); } if ($endTime < $startTime) { echo "错误,开始时间不得大于结束时间";die(); } for($start = $startTime;$start<$endTime;$start=$start+86400) { $map['pay_time'] = ['between', array($start, $start+86399)]; $map['tp1.chain'] = '/'; $map['pay_status'] = 1; $map['promote_id'] = array('egt', 0); $data = M('promote', 'tab_')->alias('tp1') ->field('tp1.account as promote_account,tp1.id as promote_id,floor(sum(pay_amount)*100) as count') ->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') OR tp2.id = tp1.id", 'left') ->join("tab_spend as s on tp2.id = s.promote_id", 'left') ->where($map) ->group('tp1.id') ->order('count desc') ->select(); foreach($data as $key => $value) { $insert['promote_id'] = $value['promote_id']; $insert['promote_account'] = $value['promote_account']; $insert['count'] = $value['count']?$value['count']:0; $insert['time'] = $start; $statisticsData = M("promote_statistics","tab_") ->where(['promote_id'=>$value['promote_id'],'time'=>$start]) ->find(); $date = date("Y-m-d",$start); if ($statisticsData) { M("promote_statistics","tab_") ->where(['promote_id'=>$value['promote_id'],'time'=>$start]) ->save($insert); echo "更新{$value['promote_account']}在{$date}充值:{$value['count']}\n"; } else { M("promote_statistics","tab_")->add($insert); echo "新增{$value['promote_account']}在{$date}充值:{$value['count']}\n"; } } } echo "-------------------------------------------------------------\n"; } public function shiftPromoteStatistics() { $data = M("shift_task")->where(['change_status'=>0,'type'=>2])->select(); $promote_data = []; $change_id = []; foreach ($data as $key => $value) { $promote_data[] = $value['from_promote_id']; $promote_data[] = $value['to_promote_id']; $change_id[] = $value['id']; } $promote_data=array_unique($promote_data); sort($promote_data); if(!$promote_data) { echo "没有数据"; die(); } $chain_data = M("promote","tab_") ->field("id") ->where(['chain'=>'/','id'=>['in',$promote_data]]) ->select(); $chain_data = array_column($chain_data,'id'); $chain_data_secord = M("promote","tab_") ->field("substring_index(chain, '/', 2) as id") ->where(['id'=>['in',$promote_data]]) ->select(); $chain_data_secord = array_column($chain_data_secord,'id'); foreach($chain_data_secord as $k=>$v){ if($v == '/'){ unset($chain_data_secord[$k]); } $chain_data_secord[$k] = substr($chain_data_secord[$k],1,strlen($v)); if ($chain_data_secord[$k] == false) { unset($chain_data_secord[$k]); } // var_dump(strlen($chain_data_secord[$k])); } $data = []; $data = array_merge(array_unique($chain_data),array_unique($chain_data_secord)); $this->PromoteStatistics($data); M("shift_task")->where(['id'=>['in',$change_id]])->save(['change_status'=>1]); // dump($data); // dump(array_unique($chain_data_secord)); } public function PromoteStatistics($promote) { echo "-------------------------------------------------------------\n"; $startTime = strtotime("20190829"); $endTime = time(); if (I("start_time")) { $startTime = strtotime(I("start_time")); } if ($promote) { $map['tp2.id'] = ['in',$promote]; } if (I("end_time")) { $endTime = strtotime(I("end_time")); } if ($endTime < $startTime) { echo "错误,开始时间不得大于结束时间";die(); } for($start = $startTime;$start<$endTime;$start=$start+86400) { $map['pay_time'] = ['between', array($start, $start+86399)]; $map['tp1.chain'] = '/'; $map['pay_status'] = 1; $map['promote_id'] = array('egt', 0); $data = M('promote', 'tab_')->alias('tp1') ->field('tp1.account as promote_account,tp1.id as promote_id,floor(sum(pay_amount)*100) as count') ->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') OR tp2.id = tp1.id", 'left') ->join("tab_spend as s on tp2.id = s.promote_id", 'left') ->where($map) ->group('tp1.id') ->order('count desc') ->select(); foreach($data as $key => $value) { $insert['promote_id'] = $value['promote_id']; $insert['promote_account'] = $value['promote_account']; $insert['count'] = $value['count']?$value['count']:0; $insert['time'] = $start; $statisticsData = M("promote_statistics","tab_") ->where(['promote_id'=>$value['promote_id'],'time'=>$start]) ->find(); $date = date("Y-m-d",$start); if ($statisticsData) { M("promote_statistics","tab_") ->where(['promote_id'=>$value['promote_id'],'time'=>$start]) ->save($insert); echo "更新{$value['promote_account']}在{$date}充值:{$value['count']}\n"; } else { M("promote_statistics","tab_")->add($insert); echo "新增{$value['promote_account']}在{$date}充值:{$value['count']}\n"; } } } echo "-------------------------------------------------------------\n"; } }