load->library('session');
$this->load->_model('Model_user','user');
$this->load->_model('Model_nav','nav');
$this->load->_model('Model_power','power');
$this->load->_model('Model_shop','shop');
$this->load->_model('Model_purchase','purchase');
$this->load->_model('Model_warehouse','warehouse');
$this->load->_model('Model_staff','staff');
$this->load->_model('Model_fullorder','fullorder');
$this->load->_model('Model_fullordertt','fullordertt');
$this->load->_model('Model_fullordersmt','fullordersmt');
$this->load->_model('Model_customer','customer');
$this->load->_model('Model_customersmt','customersmt');
$this->load->_model('Model_typeclass','typeclass');
$this->load->_model('Model_transfer','transfer');
$this->load->_model('Model_typeclass','typeclass');
$this->load->_model('Model_customertt','customertt');
$this->load->_model('Model_allocation','allocation');
}
//定义方法的调用规则 获取URI第二段值
public function _remap($arg,$arg_array)
{
if($arg == 'tc')//退出
{
$this->_tc();
}
else if($arg == 'data')//操作页
{
$this->_data();
}
else if($arg == 'del')//删除
{
$this->_del();
}
else if($arg == 'default')//默认页
{
$this->_default();
}
else if($arg == 'add')//添加
{
$this->_add();
}
else if($arg == 'edit')//修改
{
$this->_edit($arg_array);
}
else if($arg == 'rows')//数据
{
$this->_rows();
}
else if($arg == 'statistics')//数据
{
$this->_statistics();
}
else if($arg == 'apple')//数据
{
$this->_apple();
}
else if($arg == 'zzt')//数据
{
$this->_zzt();
}
else if($arg == 'tjadd')//数据
{
$this->_tjadd();
}
else if($arg == 'shopfx')//店铺分析
{
$this->_shopfx();
}
else if($arg == 'shopfxlist')//店铺分析
{
$this->_shopfxlist();
}
else
{
$this->_index();
}
}
//首页
public function _index()
{
$user = $this->user->get_api($_SESSION['api']);
$this->data['user'] = $user;//登录的用户信息
$power = $this->power->read($user['power']);
$power = $power['powerid'];
//$power = explode('|',trim($power,'|'));字符串转数组
$dataa = $this->nav->find_all('type=1','*','px asc');
$datab = $this->nav->find_all('type=2','*','px asc');
$datac = $this->nav->find_all('type=3','*','sort asc,px desc');
$an = array();
foreach ($dataa as $key=>$value)
{
foreach ($datab as $ke=>$va)
{
if($va['class'] == $value['id'])
{
foreach ($datac as $k=>$v)
{
if($v['class'] == $va['id'])
{
if(strstr($power,'|'.$v['id'].'|')==true)
{
$va['cn'][]=$v;
}
}
}
if(strstr($power,'|'.$va['id'].'|')==true)
{
$value['bn'][]=$va;
}
}
}//循环出二级导航航
if(strstr($power,'|'.$value['id'].'|')==true)
{
$an[] = $value;
}
}
//print_r($an);
$this->data['data'] = $an;
$this->data['ip'] = $this->input->ip_address();
$this->data['power'] = $user['power'];
$this->data['link'] = $user['link'];
if(stripos($_SERVER ['HTTP_HOST'],'a.') !== false)
{
$url = 'b';
}
else
{
$url = 'a';
}
$this->data['url'] = $url;
$this->_Template('user',$this->data);
}
//管理
public function _data()
{
$user = $this->user->get_api($_SESSION['api']);
$post = $this->input->post(NULL, TRUE);
if(isset($post['page']))
{
$page = $this->input->post('page',true);
$perpage = $this->input->post('perpage',true);
$power = $this->input->post('power',true);
$name = $this->input->post('name',true);
$userid = $this->input->post('userid',true);
$where = "own='".$user['own']."'";
if($power)
{
$where .= " and power = '$power'";
}
if($name)
{
$where .= " and name like '%$name%'";
}
if($userid)
{
$where .= " and userid like '%$userid%'";
}
//数据排序
$order_str = "id asc";
if(empty($page))
{
$start = 0;
$perpage = 1;
}
else
{
$start = ($page - 1)*$perpage;
}
//取得信息列表
$info_list = $this->user->find_all($where,'id,name,userid,power,shoptext,purchasetext,warehousetext,stafftext,transfertext,type,lasttime',$order_str,$start,$perpage);
//格式化数据
foreach ($info_list as $key=>$value)
{
if($value['type'] == 1)
{
if(empty($value['lasttime'])){
$info_list[$key]['type'] = '正常';
}else{
$info_list[$key]['type'] = '正常'."
最后操作时间:
".date("Y-m-d",$value['lasttime']);
}
}
else
{
$info_list[$key]['type'] = '停用';
}
$power = $this->power->read($value['power']);
$info_list[$key]['power'] = $power['powername'];
unset($info_list[$key]['lasttime']);
}
$total = $this->user->find_count($where);
$pagenum = ceil($total/$perpage);
$over = $total-($start+$perpage);
$rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
echo json_encode($rows);exit;
}
$power = $this->power->find_all();
$this->data['power'] = $power;
$this->_Template('user_data',$this->data);
}
//添加
public function _add()
{
$user = $this->user->get_api($_SESSION['api']);
$post = $this->input->post(NULL, TRUE);
if(isset($post['userid']))
{
$post['userid'] = $this->input->post('userid',true);
$userpass = $this->input->post('userpass',true);
$post['userpass'] = sha1($userpass);
$post['shop'] = $this->input->post('shop',true);
$post['shoptext'] = $this->input->post('shoptext',true);
$post['excelshop'] = $this->input->post('excelshop',true);
$post['excelshoptext'] = $this->input->post('excelshoptext',true);
$post['purchase'] = $this->input->post('purchase',true);
$post['purchasetext'] = $this->input->post('purchasetext',true);
$post['warehouse'] = $this->input->post('warehouse',true);
$post['warehousetext'] = $this->input->post('warehousetext',true);
$post['customer'] = $this->input->post('customer',true);
$post['staff'] = $this->input->post('staff',true);
$post['stafftext'] = $this->input->post('stafftext',true);
$post['power'] = $this->input->post('power',true);
$post['name'] = $this->input->post('name',true);
$post['phone'] = $this->input->post('phone',true);
$post['type'] = $this->input->post('type',true);
$post['html'] = $this->input->post('html',true);
$post['own'] = $user['own'];
$post['api'] = sha1(rand(1000000,9999999));
if($this->user->insert($post))
{
echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
}
}
$power = $this->power->find_all();
$this->data['power'] = $power;
$this->_Template('user_add',$this->data);
}
//修改
public function _edit($arg_array)
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['id']))
{
$id = $this->input->post('id',true);
$post['userid'] = $this->input->post('edituserid',true);
$userpass = $this->input->post('edituserpass',true);
$post['shop'] = $this->input->post('shop',true);
$post['shoptext'] = $this->input->post('shoptext',true);
$post['excelshop'] = $this->input->post('excelshop',true);
$post['excelshoptext'] = $this->input->post('excelshoptext',true);
$post['purchase'] = $this->input->post('purchase',true);
$post['purchasetext'] = $this->input->post('purchasetext',true);
$post['warehouse'] = $this->input->post('warehouse',true);
$post['warehousetext'] = $this->input->post('warehousetext',true);
$post['customer'] = $this->input->post('customer',true);
$post['staff'] = $this->input->post('staff',true);
$post['stafftext'] = $this->input->post('stafftext',true);
$post['power'] = $this->input->post('power',true);
$post['name'] = $this->input->post('name',true);
$post['phone'] = $this->input->post('phone',true);
$post['type'] = $this->input->post('type',true);
$post['html'] = $this->input->post('html',true);
$ud = $this->user->read($id);
if($userpass != NULL)
{
$post['userpass'] = sha1($userpass);
$post['api'] = sha1(rand(1000000,9999999));
}
else
{
$post['userpass'] = $ud['userpass'];
}
if($this->user->save($post,$id))
{
echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
}
}
$arg_array = $arg_array[0];
$user = $this->user->read($arg_array);
$this->data['user'] = $user;
$power = $this->power->find_all();
$this->data['power'] = $power;
$this->_Template('user_edit',$this->data);
}
//删除
public function _del()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['s']))
{
$id_arr = $this->input->post('s');
$id_arr = explode(',',$id_arr);
if(!$id_arr)
{
echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
}
//循环删除记录
foreach ($id_arr as $v)
{
$this->user->remove($v);
}
echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
}
}
//默认页
public function _default()
{
/**
$order = $this->order->get_w();
$order = count($order);//查询订单未处理数量
$message = $this->message->get_w();
$message = count($message);//查询留言未处理数量
$this->_Template('default',$this->data);
**/
$dt = 0;
if(isset($_SESSION['api']))
{
$user = $this->user->get_api($_SESSION['api']);
$usp = $user;
$fgshop = "";$sid = "";
$user = explode('|',trim($user['shop'],'|'));
foreach ($user as $value)
{
if($value != '18' && $value != '19' && $value != '12' && $value != '13' && $value != '9' && $value != '15' && $value != '27')
{
$fgshop .= " shop = ".$value." or";
}
$sid .= " id = ".$value." or";
}
}
$post = $this->input->post(NULL, TRUE);
if(isset($post['timek']))
{
//$start = '2018-10-15';
//$end = '2018-11-26';
//$tim = strtotime($start);
//$day = $time/(3600*24);
$timek = $this->input->post('timek',true);
$timej = $this->input->post('timej',true);
$k = strtotime($timek)-24*3600;//少一天为增加选择开始天时间
$j = strtotime($timej);
$n = ($j-$k)/(24*3600);
if($n < 1)
{
$n = 1;
}
$time=array();$stime=array();$num = array();$ymoney = array();$money = array();
for($i=1;$i<$n;$i++)
{
//近7天时间
$t = $j-($n*24*60*60)+($i*24*60*60);
$time[] = date('Y-m-d',$t);
$ct = strtotime(date('Ymd',$t));
$ctj = strtotime(date('Ymd',$t+24*3600));
$dlz = $this->fullorder->find_all("dtime >= ".$ct." and dtime <= ".$ctj." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'budget,shouldmoney');
$tt = $this->fullordertt->find_all("dtime >= ".$ct." and dtime <= ".$ctj." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'budget,shouldmoney');
$dsmt = array();
$dsmt = $this->fullordersmt->find_all("dtime >= ".$ct." and dtime <= ".$ctj." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'budget,shouldmoney');
$d = array_merge($dlz,$dsmt,$tt);
$num[] = count($d);
$ymoney[] = sprintf("%01.2f",array_sum(array_column($d,'budget')));
$money[] = sprintf("%01.2f",array_sum(array_column($d,'shouldmoney')));
}
$snuz = $this->fullorder->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
$snuz += $this->fullordersmt->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
$snuz += $this->fullordertt->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
$lnuz = $this->fullorder->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待出库
$lnuz += $this->fullordersmt->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待出库
$lnuz += $this->fullordertt->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待出库
$snu = $this->fullorder->find_count('reviewtime = 0 and dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
$snu += $this->fullordersmt->find_count('reviewtime = 0 and dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
$snu += $this->fullordertt->find_count('reviewtime = 0 and dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
$lnu = $this->fullorder->find_count('printtime != 0 and librarytime = 0 and libraryconfirm = 2 and dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待出库
$lnu += $this->fullordersmt->find_count('printtime != 0 and librarytime = 0 and libraryconfirm = 2 and dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待出库
$lnu += $this->fullordertt->find_count('printtime != 0 and librarytime = 0 and libraryconfirm = 2 and dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待出库
echo @json_encode(array('time'=>$time,'num'=>$num,'ymoney'=>$ymoney,'money'=>$money,'snu'=>$snu,'lnu'=>$lnu,'snuz'=>sprintf("%.0f",$snu/$snuz*100).'%','lnuz'=>sprintf("%.0f",$lnu/$lnuz*100).'%','success'=>true));exit;
}
$this->_Template('user_default',$this->data);
}
public function _zzt()
{
exit;
if(isset($_SESSION['api']))
{
$user = $this->user->get_api($_SESSION['api']);
$usp = $user;
$fgshop = "";$sid = "";
$user = explode('|',trim($user['shop'],'|'));
foreach ($user as $value)
{
$fgshop .= " shop = ".$value." or";
$sid .= " id = ".$value." or";
}
}
$data = array();$sntime= array();$sndata1 = array();$sndata2 = array();$sndata3 = array();
$sj = array('01','02','03','04','05','06','07','08','09','10','11','12');
for($i=0;$i<3;$i++)
{
foreach ($sj as $v)
{
$sntime[] = date("Y")-2+$i.'-'.$v;
}
}
$pdtime = date('Y-m-d-H',time());
if(is_file("./data/tj/".$pdtime.".txt"))
{
$myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
$bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
fclose($myfile);
$bc = json_decode($bc,true);
$data = $bc['zzt'][0];
$sndata = $bc['zzt'][1];
}
else
{
$i = 0;
foreach ($sj as $k=>$v)
{
$i++;
$dlz1 = $this->fullorder->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
$smt1 = $this->fullordersmt->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
$m1 = sprintf("%01.2f",array_sum(array_column($dlz1,'shouldmoney'))+array_sum(array_column($smt1,'shouldmoney')));
$dlz2 = $this->fullorder->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
$smt2 = $this->fullordersmt->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
$m2 = sprintf("%01.2f",array_sum(array_column($dlz2,'shouldmoney'))+array_sum(array_column($smt2,'shouldmoney')));
$dlz3 = $this->fullorder->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
$smt3 = $this->fullordersmt->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
$m3 = sprintf("%01.2f",array_sum(array_column($dlz3,'shouldmoney'))+array_sum(array_column($smt3,'shouldmoney')));
$sndata1[$i] = $m3;
$sndata2[12+$i] = $m2;
$sndata3[24+$i] = $m1;
$data[] = array($v,$m1,$m2,$m3);
}
}
$time = array(date("Y"),(date("Y")-1),(date("Y")-2));
echo json_encode(array('data'=>$data,'time'=>$time,'sndata'=>$sndata,'sntime'=>$sntime,'success'=>true));exit;
}
//默认页
public function _statistics()
{
/**
$order = $this->order->get_w();
$order = count($order);//查询订单未处理数量
$message = $this->message->get_w();
$message = count($message);//查询留言未处理数量
$this->_Template('default',$this->data);
**/
//date_default_timezone_set("Etc/GMT+8");
$dt = 0;
if(isset($_SESSION['api']))
{
$user = $this->user->get_api($_SESSION['api']);
$usp = $user;
$fgshop = "";$sid = "";
$user = explode('|',trim($user['shop'],'|'));
foreach ($user as $value)
{
if($value != '18' && $value != '19' && $value != '12' && $value != '13' && $value != '9' && $value != '15' && $value != '27' && $value != '28' && $value != '29' && $value != '30' && $value != '21' && $value != '34')
{
$fgshop .= " shop = ".$value." or";
}
$sid .= " id = ".$value." or";
}
}
$post = $this->input->post(NULL, TRUE);
$source = $this->input->post('source',true);
$where = "";
if($source)
{
if($source == '2d')
{
$where = " and source >= '2'";
}
else
{
$where = " and source = '$source'";
}
}
$tm = strtotime(date("Ymd"),time());
$usat = $tm;
if(isset($post['zhcx']))
{
$zdt = $this->input->post('time',true);
$k = $zdt;
$tab = $this->input->post('tab',true);
$pdtime = date('Y-m-d-H',time());
if(is_file("./data/tj/".$pdtime.".txt") && $tab == 1 && $zdt > 172800)
{
$myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
$bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
fclose($myfile);
$bc = json_decode($bc,true);
echo json_encode($bc['zhcx'][$source][$zdt]);exit;
}
else
{
$customer = $this->customer->find_all("shop !=''",'num,zhcx');
$customerkey = array_column($customer,'zhcx');
$customer= array_combine($customerkey,$customer);
$customersmt = $this->customersmt->find_all("shop !=''",'num,zhcx');
$customersmtkey = array_column($customersmt,'zhcx');
$customersmt= array_combine($customersmtkey,$customersmt);
//$start = '2018-10-15';
//$end = '2018-11-26';
//$tim = strtotime($start);
//$day = $time/(3600*24);
if($tab == '1')
{
if($zdt >= 691200)
{
$k = $usat-$k-$k;
$j = $usat;
$n = ($j-$k)/(24*3600);
}
else
{
$n = 2;
$usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
}
}
else
{
$timedata = explode('|',$zdt);
$ktime = strtotime($timedata[0]);
$jtime = strtotime($timedata[1]);
$ktime = $ktime-($jtime-$ktime);
$k = $ktime;
$j = $jtime;
$n = ($j-$k)/(24*3600);
$usat = $jtime;
}
$time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();$ymoney = array();$money = array();
$dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();$zkh = array();
$dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
$ys = $this->shop->find_all("type != '0' and id != '18' and id != '19' and id != '12' and id != '13' and id != '9' and id != '15' and id != '27' and id != '28' and id != '29' and id != '30' and id != '21' and id != '34'");
foreach ($ys as $v)
{
$shopdata[$v['id']] = array('id'=>$v['id'],'b'=>$v['type'],'fdl'=>0,'chl'=>0,'num'=>0,'fgl'=>0);
$zkh[$v['id']] = array();
}
for($i=1;$i<$n;$i++)
{
if($n > 13 && $i > $n/2 || $n < 14)
{
$t = $usat-($n*24*60*60)+($i*24*60*60);
$time[] = date('m-d',$t);
$ct = strtotime(date('Ymd',$t));
$ctj = strtotime(date('Ymd',$t+24*3600));
$dlz = $this->fullorder->find_all("dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'shop,email');
$smt = $this->fullordersmt->find_all("dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'shop,userid');
$tt = $this->fullordertt->find_all("state != 217 and dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'shop,email');
//数量及金额结束
$sd = array_merge($dlz,$smt,$tt);
$fgldata = array();
foreach ($sd as $v)
{
if(isset($v['email']))
{
if(!isset($fgldata[$v['shop'].'-'.$v['email']]))
{
$fgldata[$v['shop'].'-'.$v['email']] = 0;
}
else
{
$fgldata[$v['shop'].'-'.$v['email']] += 1;
}
$zkh[$v['shop']][$v['email']] = array();
}
else
{
if(!isset($fgldata[$v['shop'].'-'.$v['userid']]))
{
$fgldata[$v['shop'].'-'.$v['userid']] = 0;
}
else
{
$fgldata[$v['shop'].'-'.$v['userid']] += 1;
}
$zkh[$v['shop']][$v['userid']] = array();
}
}
foreach ($sd as $v)
{
$chl = 0;
if(isset($shopdata[$v['shop']]))
{
if(isset($v['email']))
{
if(isset($customer[$v['shop'].'-'.$v['email']]['num']))
{
$fdl = $customer[$v['shop'].'-'.$v['email']]['num']>1?1:0;
}
else
{
$fdl = 0;
}
foreach ($ys as $vv)
{
if($vv['id'] != $v['shop'] && isset($customer[$vv['id'].'-'.$v['email']]))
{
$chl = 1;
}
}
if(isset($fgldata[$v['shop'].'-'.$v['email']]))
{
$fgl = $fgldata[$v['shop'].'-'.$v['email']]>0?1:0;
}
else
{
$fgl = 0;
}
}
else
{
if(isset($customersmt[$v['shop'].'-'.$v['userid']]['num']))
{
$fdl = $customersmt[$v['shop'].'-'.$v['userid']]['num']>1?1:0;
}
else
{
$fdl = 0;
}
foreach ($ys as $vv)
{
if($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'].'-'.$v['userid']]))
{
$chl = 1;
}
}
if(isset($fgldata[$v['shop'].'-'.$v['userid']]))
{
$fgl = $fgldata[$v['shop'].'-'.$v['userid']]>0?1:0;
}
else
{
$fgl = 0;
}
}
$shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl']+$fdl;
$shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl']+$chl;
$shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl']+$fgl;
$shopdata[$v['shop']]['num'] += 1;
}
}
}
}
foreach ($shopdata as $k=>$v)
{
$shopdata[$k]['fdl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['fdl']/$v['num']*100)).'%';
$shopdata[$k]['chl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['chl']/$v['num']*100)).'%';
$shopdata[$k]['fgl'] = count($zkh[$v['id']])=='0'?0:sprintf("%01.2f",($v['fgl']/count($zkh[$v['id']])*100)).'%';
}
$shopdata = array_values($shopdata);
echo @json_encode(array('shopdata'=>$shopdata,'success'=>true));exit;
}
}
if(isset($post['time']))
{
$zdt = $this->input->post('time',true);
$k = $zdt;
$tab = $this->input->post('tab',true);
$pdtime = date('Y-m-d-H',time());
if(is_file("./data/tj/".$pdtime.".txt") && $tab == 1 && $zdt > 172800)//前端改店内需要修改zdt 172800
{
$myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
$bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
fclose($myfile);
$bc = json_decode($bc,true);
echo json_encode($bc['tj'][$source][$zdt]);exit;
}
else
{
//$start = '2018-10-15';
//$end = '2018-11-26';
//$tim = strtotime($start);
//$day = $time/(3600*24);
if($tab == '1')
{
if($zdt >= 691200)
{
$k = $usat-$k-$k;
$j = $usat;
$n = ($j-$k)/(24*3600);
}
else
{
$n = 2;
$usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
}
}
else
{
$timedata = explode('|',$zdt);
$ktime = strtotime($timedata[0]);
$jtime = strtotime($timedata[1]);
$ktime = $ktime-($jtime-$ktime);
$k = $ktime;
$j = $jtime;
$n = ($j-$k)/(24*3600);
$usat = $jtime;
$tm = $jtime;
$zdt = $jtime-$ktime;
}
$time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();$ymoney = array();$money = array();
$dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();$zkh = array();
$dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
$ys = $this->shop->find_all("type != '0' and id != '16' and id != '17' and id != '18' and id != '19' and id != '20' and id != '12' and id != '13' and id != '8' and id != '10' and id != '11' and id != '13' and id != '22' and id != '23' and id != '24' and id != '25' and id != '26' and id != '9' and id != '15' and id != '27' and id != '28' and id != '29' and id != '30' and id != '21' and id != '34'");
foreach ($ys as $v)
{
$shopdata[$v['id']] = array('num'=>0,'money'=>0,'tmoney'=>0,'fdl'=>0,'chl'=>0);
}
for($i=1;$i<$n;$i++)
{
//近7天时间
//$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
if($n > 13 && $i > $n/2 || $n < 14)
{
$t = $usat-($n*24*60*60)+($i*24*60*60);
$time[] = date('m-d',$t);
$ct = strtotime(date('Ymd',$t));
$ctj = strtotime(date('Ymd',$t+24*3600));
$dlz = $this->fullorder->find_all("dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'budget,shouldmoney,shop,number,refundy,budget,email,refundy');
$smt = $this->fullordersmt->find_all("dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'budget,shouldmoney,shop,refundy,userid,budget,refundy');
$tt = $this->fullordertt->find_all("state != 217 and dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'budget,shouldmoney,shop,number,refundy,budget,email,refundy');
$ab[] = $dlz;
//数量及金额开始
$dlznum[] = count($dlz);
$smtnum[] = count($smt);
$ttnum[] = count($smt);
$dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
$smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
$ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
/**
//提出退款关闭等信息的实收金额
$dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
$smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
//提出退款关闭等信息的实收金额
**/
//实收金额
$dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'budget')));
$smtmss = sprintf("%01.2f",array_sum(array_column($smt,'budget')));
$ttmss = sprintf("%01.2f",array_sum(array_column($tt,'budget')));
//实收金额
//补/退原额
$dlzbty = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
$smtbty = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
$ttbty = sprintf("%01.2f",array_sum(array_column($tt,'refundy')));
//补/退原额
$dlzmoney[] = $dlzm;
$smtmoney[] = $smtm;
$ttmoney[] = $ttm;
$dlzsl += count($dlz);
$dlzje += $dlzm;
$smtsl += count($smt);
$smtje += $smtm;
$ttsl += count($tt);
$ttje += $ttm;
/**
//减去的实收金额
$dlzssje += $dlzm+$dlzmss;
$smtssje += $smtm+$smtmss;
**/
//实收和补/退
$dlzssje += $dlzmss+$dlzbty;
$smtssje += $smtmss+$smtbty;
$ttssje += $ttmss+$ttbty;
//数量及金额结束
$sd = array_merge($dlz,$smt,$tt);
foreach ($sd as $v)
{
if(isset($shopdata[$v['shop']]))
{
$shopdata[$v['shop']]['num'] += 1;
$shopdata[$v['shop']]['money'] += $v['shouldmoney'];
$shopdata[$v['shop']]['tmoney'] += $v['budget']+$v['refundy'];
}
}
}
else if ($n > 13 && $i <= $n/2)
{
$t = $usat-($n*24*60*60)+($i*24*60*60);
$timeold[] = date('m-d',$t);
$ct = strtotime(date('Ymd',$t));
$ctj = strtotime(date('Ymd',$t+24*3600));
$dlz = $this->fullorder->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
$smt = $this->fullordersmt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
$tt = $this->fullordertt->find_all("state != 217 and (".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
//数量及金额开始
$dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
$smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
$ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
$dlzmoneyb[] = $dlzm;
$smtmoneyb[] = $smtm;
$ttmoneyb[] = $ttm;
//数量及金额结束
}
}
foreach ($shopdata as $k=>$v)
{
$sn = $this->shop->read($k);
$shopdata[$k]['money'] = sprintf("%01.2f",$v['money']).'$';
$shopdata[$k]['tmoney'] = sprintf("%01.2f",$v['tmoney']).'$';
$shopdata[$k]['bl'] = ($v['num']=='0')?'0$':round($v['money']/$v['num'],2).'$';
$shopdata[$k]['name'] = $sn['shopname'];
$shopdata[$k]['b'] = $sn['type'];
$shopdata[$k]['id'] = $sn['id'];
}
$shopdata = array_values($shopdata);
//$sycp=array();
/**
//根据所选时间产品排行开始
$dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
$smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
**/
/**
//昨日产品排行开始
$dlzlist = $this->fullorder->find_all("fpdata != '' and dtime >= '".strtotime(date("Ymd",time()-86400))."' and dtime <= '".strtotime(date("Ymd",time()))."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
$smtlist = $this->fullordersmt->find_all("fpdata != '' and dtime >= '".strtotime(date("Ymd",time()-86400))."' and dtime <= '".strtotime(date("Ymd",time()))."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
$rows = array_merge($dlzlist,$smtlist);
foreach ($rows as $v)
{
$number = explode('|',trim($v['whlabel'],'|'));
$or = explode(';',trim($v['fpdata'],';'));
$i=0;
foreach ($or as $va)
{
$ord = explode('|',$va);
$orod = explode(',',$ord[0]);
$numberod = explode('-',$number[$i]);
if(!isset($orod[1]))
{
continue;
}
if(isset($sycp[$orod[1]]) && isset($numberod[1]))
{
//$sycp[$orod[1]][0] += 1;//统计多少单
$sycp[$orod[1]][0] += $numberod[1];//统计多少条
$sycp[$orod[1]][1] += 0;//价格
}
else
{
if(isset($numberod[1]))
{
$typeclass = $this->typeclass->read($orod['0']);
$sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
}
}
$i++;
}
}
arsort($sycp);
$sycp = array_values($sycp);
$sycp = array_slice($sycp,0,10);
//产品排行结束
**/
//当时实时数据结束
echo @json_encode(array('time'=>$time,'timeold'=>$timeold,'smtnum'=>$smtnum,'ttnum'=>$ttnum,'dlznum'=>$dlznum,'smtmoney'=>$smtmoney,'ttmoney'=>$ttmoney,'dlzmoney'=>$dlzmoney,'smtmoneyb'=>$smtmoneyb,'ttmoneyb'=>$ttmoneyb,'dlzmoneyb'=>$dlzmoneyb,'dlzsl'=>$dlzsl,'dlzje'=>number_format($dlzje,2),'dlzssje'=>number_format($dlzssje,2),'smtsl'=>$smtsl,'ttsl'=>$ttsl,'smtje'=>number_format($smtje,2),'ttje'=>number_format($ttje,2),'smtssje'=>number_format($smtssje,2),'ttssje'=>number_format($ttssje,2),'zje'=>number_format($dlzje+$smtje+$ttje,2),'zsl'=>$dlzsl+$smtsl+$ttsl,'shopdata'=>$shopdata,'success'=>true));exit;//,'sycp'=>$sycp昨日产品数据
}
}
if(isset($post['sstime']))
{
$shop = $this->input->post('shop',true);
$zdtime = $usat;
//当时实时数据开始
if(!$shop)
{
$sssl = $this->fullorder->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$zdtime." and dtime <= ".strtotime(date('Ymd',$usat+24*3600)).$where,'budget,shouldmoney');
$ssje = $this->fullordersmt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$zdtime." and dtime <= ".strtotime(date('Ymd',$usat+24*3600)).$where,'budget,shouldmoney');
$tje = $this->fullordertt->find_all("state != 217 and (".rtrim($fgshop,'or').") and dtime >= ".$zdtime." and dtime <= ".strtotime(date('Ymd',$usat+24*3600)).$where,'budget,shouldmoney');
$sssldlz = count($sssl);
$ssslsmt = count($ssje);
$sssltt = count($tje);
$ssjedlz = sprintf("%01.2f",array_sum(array_column($sssl,'budget')));
$ssjesmt = sprintf("%01.2f",array_sum(array_column($ssje,'budget')));
$ssjett= sprintf("%01.2f",array_sum(array_column($tje,'budget')));
$sssl = $sssldlz+$ssslsmt+$sssltt;
$ssje = $ssjedlz+$ssjesmt+$ssjett;
}
else
{
$sp = $this->shop->read($shop);
$fu = ($sp['type']=='269')?'fullorder':'fullordersmt';
$ss = $this->$fu->find_all("dtime >= ".$zdtime." and dtime <= ".strtotime(date('Ymd',$usat+24*3600))." and shop = '".$shop."'",'budget,shouldmoney');
$sssl = count($ss);
$ssje = sprintf("%01.2f",array_sum(array_column($ss,'budget')));
}
echo @json_encode(array('sstime'=>date('m-d H:i',time()),'sssl'=>$sssl,'ssje'=>sprintf("%.2f",$ssje),'success'=>true));exit;
}
//店铺产品详情
if(isset($post['id']))
{
$tm += 24*3600;
$gshtime = date('Y-m-d 0:0:0',time());
$gshtime = strtotime($gshtime)+24*60*60;
$dpxq=array();
$id = $this->input->post('id',true);
$xqtime = $this->input->post('xqtime',true);
$xqshop = $this->shop->read($id);
if($xqshop['type']=="269")
{
$sid = 'fullorder';
}
else if($xqshop['type']=="270")
{
$sid = 'fullordersmt';
}
else if($xqshop['type']=="1514")
{
$sid = 'fullordertt';
}
if($xqtime > 345600)
{
$rows = $this->$sid->find_all("shop = '".$id."' and dtime >= '".($gshtime-$xqtime)."' and dtime <= '".($gshtime+24*60*60)."'",'whlabel,fpdata,number');
}
else
{
$rows = $this->$sid->find_all("shop = '".$id."' and dtime >= '".($gshtime-$xqtime)."' and dtime <= '".($gshtime+24*60*60-$xqtime)."'",'whlabel,fpdata,number');
}
foreach ($rows as $v)
{
$or = explode('|',ltrim($v['whlabel'],'|'));
for($i=0;$i$dpxq,'success'=>true));exit;
}
$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
$this->data['wlshop'] = $wlshop;
$dr = $usat;
$this->data['dr'] = array(date("m-d",$dr),date("m-d",$dr-24*3600),date("m-d",$dr-2*24*3600),date("m-d",$dr-3*24*3600));
$this->_Template('phone/p_user_statistics',$this->data);
}
/**
public function super_unique($array,$key)//多维删除重复
{
$temp_array = array();
foreach ($array as &$v) {
if (!isset($temp_array[$v[$key]]))
{
$temp_array[$v[$key]] =& $v;
}
}
$array = array_values($temp_array);
return $array;
}
**/
public function _usatime()
{
date_default_timezone_set("Etc/GMT+8");
return time();
}
//数据
public function _rows()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['shop']))
{
$shop = $this->input->post('shop',true);
$data = $this->shop->find_all('1=1');
$list = array();
foreach ($data as $key=>$value)
{
$t = $this->typeclass->read($value['type']);
$list[] = array('id'=>$value['id'],'title'=>$value['shopname'].' - '.$t['title']);
}
$num = array();
if($shop != "null")
{
$num = $this->user->read($shop);//找出内容
if($num['shop'])
{
$num = explode('|',trim($num['shop'],'|'));//数组化内容
}
else
{
$num = array();
}
}
echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
}
if(isset($post['excelshop']))
{
$excelshop = $this->input->post('excelshop',true);
$data = $this->shop->find_all('1=1');
$list = array();
foreach ($data as $key=>$value)
{
$t = $this->typeclass->read($value['type']);
$list[] = array('id'=>$value['id'],'title'=>$value['shopname'].' - '.$t['title']);
}
$num = array();
if($excelshop != "null")
{
$num = $this->user->read($excelshop);//找出内容
if($num['excelshop'])
{
$num = explode('|',trim($num['excelshop'],'|'));//数组化内容
}
else
{
$num = array();
}
}
echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
}
if(isset($post['purchase']))
{
$purchase = $this->input->post('purchase',true);
$data = $this->purchase->find_all('1=1');
$list = array();
foreach ($data as $key=>$value)
{
$list[] = array('id'=>$value['id'],'title'=>$value['title']);
}
$num = array();
if($purchase != "null")
{
$num = $this->user->read($purchase);//找出内容
if($num['purchase'])
{
$num = explode('|',trim($num['purchase'],'|'));//数组化内容
}
else
{
$num = array();
}
}
echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
}
if(isset($post['staff']))
{
$staff = $this->input->post('staff',true);
$data = $this->staff->find_all('1=1');
$list = array();
foreach ($data as $key=>$value)
{
$list[] = array('id'=>$value['id'],'title'=>$value['name']);
}
$num = array();
if($staff != "null")
{
$num = $this->user->read($staff);//找出内容
if($num['staff'])
{
$num = explode('|',trim($num['staff'],'|'));//数组化内容
}
else
{
$num = array();
}
}
echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
}
if(isset($post['warehouse']))
{
$warehouse = $this->input->post('warehouse',true);
$data = $this->warehouse->find_all('1=1');
$list = array();
foreach ($data as $key=>$value)
{
$list[] = array('id'=>$value['id'],'title'=>$value['title']);
}
$num = array();
if($warehouse != "null")
{
$num = $this->user->read($warehouse);//找出内容
if($num['warehouse'])
{
$num = explode('|',trim($num['warehouse'],'|'));//数组化内容
}
else
{
$num = array();
}
}
echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
}
if(isset($post['transfer']))
{
$transfer = $this->input->post('transfer',true);
$data = $this->transfer->find_all('1=1');
$list = array();
foreach ($data as $key=>$value)
{
$list[] = array('id'=>$value['id'],'title'=>$value['title']);
}
$num = array();
if($transfer != "null")
{
$num = $this->user->read($transfer);//找出内容
if($num['transfer'])
{
$num = explode('|',trim($num['transfer'],'|'));//数组化内容
}
else
{
$num = array();
}
}
echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
}
}
public function _shopfx()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['time']))
{
$time = $this->input->post('time',true);
$t = strtotime(date("Ymd",time()+24*3600));//明天0点
$shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
$sid = '';
foreach ($shop as $value)
{
$sid .= " shop = ".$value['id']." or";
}
$sid = " and (".rtrim($sid,'or').")";
$znum = $this->fullorder->find_count("dtime > '".($t-$time*24*3600)."' and dtime < '".$t."'".$sid);
$data = array();$list = array();
$color = array('0'=>'#30546c','1'=>'#61a0a8','2'=>'#c23531','3'=>'#d48265','4'=>'#546570','5'=>'#749f83','6'=>'#bda29a','7'=>'#6e7074','8'=>'#546570');
$j = 0;
$zt = array(7=>1,30=>2);
foreach ($shop as $v)
{
$d = $this->fullorder->find_count("shop = '".$v['id']."' and dtime > '".($t-$time*24*3600)."' and dtime < '".$t."' and (state = '207' or state = '216')");
$wd = $this->allocation->read($zt[$time]);
$n = json_decode($wd['content'],true);
$bfb = ($d==0)?0:round(($d / $znum) * 100, 2);
$data[] = array('value'=>$bfb,'name'=>$v['shopname'].' '.$bfb."%",'itemStyle'=>array('color'=>$color[$j]));
$n[$v['id']][] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".date("Ymd",time())."' and (state = '207' or state = '216')");
$t_list = array();
for($i=0;$i<$time;$i++)
{
$t_list[] = date("m-d",time()-($i*24*3600));
}
$list[] = array('name'=>$v['shopname'],'type'=>'bar','data'=>$n[$v['id']],'label'=>array('show'=>true,'position'=>'right'),'itemStyle'=>array('color'=>$color[$j]),'barWidth'=>round((1/(count($shop)+2)) * 100, 2).'%');
$j++;
}
$list = (array_reverse($list));
echo json_encode(array('data'=>($data),'list'=>$list,'t'=>(array_reverse($t_list)),'success'=>true));exit;
/**
$time = $this->input->post('time',true);
$t = strtotime(date("Ymd",time()+24*3600));//明天0点
$shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
$sid = '';
foreach ($shop as $value)
{
$sid .= " shop = ".$value['id']." or";
}
$sid = " and (".rtrim($sid,'or').")";
$znum = $this->fullorder->find_count("dtime > '".($t-$time*24*3600)."' and dtime < '".$t."'".$sid);
$data = array();$list = array();
$color = array('0'=>'#30546c','1'=>'#61a0a8','2'=>'#c23531','3'=>'#d48265','4'=>'#546570','5'=>'#749f83','6'=>'#bda29a','7'=>'#6e7074','8'=>'#546570');
$j = 0;
foreach ($shop as $v)
{
$d = $this->fullorder->find_count("shop = '".$v['id']."' and dtime > '".($t-$time*24*3600)."' and dtime < '".$t."' and (state = '207' or state = '216')");
$bfb = ($d==0)?0:round(($d / $znum) * 100, 2);
$data[] = array('value'=>$bfb,'name'=>$v['shopname'].' '.$bfb."%",'itemStyle'=>array('color'=>$color[$j]));
$n = array();$t_list = array();
for($i=0;$i<$time;$i++)
{
if($i == 0)
{
$s = date("Ymd",time());
}
else
{
$s = date("Ymd",time()-($i*24*3600));
}
$t_list[] = date("m-d",time()-($i*24*3600));
$n[] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".$s."' and (state = '207' or state = '216')");
}
$list[] = array('name'=>$v['shopname'],'type'=>'bar','data'=>array_reverse($n),'label'=>array('show'=>true,'position'=>'right'),'itemStyle'=>array('color'=>$color[$j]),'barWidth'=>round((1/(count($shop)+2)) * 100, 2).'%');
$j++;
}
$list = (array_reverse($list));
echo json_encode(array('data'=>($data),'list'=>$list,'t'=>(array_reverse($t_list)),'success'=>true));exit;
**/
}
$this->_Template('phone/p_user_shopfx',$this->data);
}
public function _shopfxlist()
{
$t = strtotime(date("Ymd",time()));//今天0点
$shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
$sid = '';
foreach ($shop as $value)
{
$sid .= " shop = ".$value['id']." or";
}
$sid = " and (".rtrim($sid,'or').")";
$zt = array(7,30);
$this->db->trans_begin();
foreach ($zt as $key=>$time)
{
$data = array();$list = array();
foreach ($shop as $v)
{
$n = array();$t_list = array();
for($i=1;$i<$time;$i++)
{
if($i == 0)
{
$s = date("Ymd",time());
}
else
{
$s = date("Ymd",time()-($i*24*3600));
}
$t_list[] = date("m-d",time()-($i*24*3600));
$n[] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".$s."' and (state = '207' or state = '216')");
}
$list[$v['id']] = array_reverse($n);
}
$this->allocation->save(array('content'=>json_encode($list)),$key+1);
}
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
echo 'orver';
}
else
{
$this->db->trans_commit();
echo 'ok';
}
}
public function _apple()
{
$this->_Template('phone/p_user_apple',$this->data);
}
//退出
public function _tc()
{
$this->session->sess_destroy();
header("Location:/");
}
public function _tjadd()
{
$pdtime = date('Y-m-d-H',time());
//if(is_file("./data/tj/".$pdtime.".txt"))
if(is_file("./data/tj/".$pdtime.".txt"))
{
$myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
$bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
fclose($myfile);
$bc = json_decode($bc,true);
$zzt = array($bc['zzt'][0],$bc['zzt'][1]);
}
else
{
/** 暂时不需要了
//柱状图数据
$i = 0;
$data = array();$sndata1 = array();$sndata2 = array();$sndata3 = array();
$sj = array('01','02','03','04','05','06','07','08','09','10','11','12');
foreach ($sj as $k=>$v)
{
$i++;
$dlz1 = $this->fullorder->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
$smt1 = $this->fullordersmt->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
$m1 = sprintf("%01.2f",array_sum(array_column($dlz1,'shouldmoney'))+array_sum(array_column($smt1,'shouldmoney')));
$dlz2 = $this->fullorder->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
$smt2 = $this->fullordersmt->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
$m2 = sprintf("%01.2f",array_sum(array_column($dlz2,'shouldmoney'))+array_sum(array_column($smt2,'shouldmoney')));
$dlz3 = $this->fullorder->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
$smt3 = $this->fullordersmt->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
$m3 = sprintf("%01.2f",array_sum(array_column($dlz3,'shouldmoney'))+array_sum(array_column($smt3,'shouldmoney')));
$sndata1[$i] = $m3;
$sndata2[12+$i] = $m2;
$sndata3[24+$i] = $m1;
$data[] = array($v,$m1,$m2,$m3);
}
$sndata = array_merge($sndata1,$sndata2,$sndata3);
$zzt = array($data,$sndata);
//柱状图结束
**/
}
//详情内容
$dt = 0;
$user = $this->user->get_api($_SESSION['api']);
$usp = $user;
$fgshop = "";$sid = "";
$user = explode('|',trim($user['shop'],'|'));
foreach ($user as $value)
{
$fgshop .= " shop = ".$value." or";
$sid .= " id = ".$value." or";
}
$tm = strtotime(date("Ymd"),time());
$usat = $tm;
//$molist = array('0','1','2d');
$molist = array('0','1');
$zqtime = array(259200,345600,691200,2678400,7862400,31622400);
//time开始
$zqtdata = array();
foreach ($molist as $vval)
{
$where = "";
$source = $vval;
if($source == '2d')
{
$where = " and source >= '2'";
}
else if($source != '0')
{
$where = " and source = '$source'";
}
foreach ($zqtime as $value)
{
$zdt = $value;
$k = $zdt;
$tab = 1;
//$start = '2018-10-15';
//$end = '2018-11-26';
//$tim = strtotime($start);
//$day = $time/(3600*24);
if($tab == '1')
{
if($zdt >= 691200)
{
$k = $usat-$k-$k;
$j = $usat;
$n = ($j-$k)/(24*3600);
}
else
{
$n = 2;
$usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
}
}
else
{
$timedata = explode('|',$zdt);
$ktime = strtotime($timedata[0]);
$jtime = strtotime($timedata[1]);
$ktime = $ktime-($jtime-$ktime);
$k = $ktime;
$j = $jtime;
$n = ($j-$k)/(24*3600);
$usat = $jtime;
$tm = $jtime;
$zdt = $jtime-$ktime;
}
$time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();;$ttnum = array();$ymoney = array();$money = array();$dlzmoney = array();$smtmoney=array();$ttmoney=array();
$dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();
$dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
$ys = $this->shop->find_all("type != '0' and id != '16' and id != '17' and id != '18' and id != '19' and id != '20' and id != '12' and id != '13' and id != '8' and id != '10' and id != '11' and id != '13' and id != '22' and id != '23' and id != '24' and id != '25' and id != '26' and id != '9' and id != '15' and id != '27' and id != '28' and id != '29' and id != '30' and id != '21' and id != '34'");
foreach ($ys as $v)
{
$shopdata[$v['id']] = array('num'=>0,'money'=>0,'tmoney'=>0,'fdl'=>0,'chl'=>0);
}
for($i=1;$i<$n;$i++)
{
//近7天时间
//$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
if($n > 13 && $i > $n/2 || $n < 14)
{
$t = $usat-($n*24*60*60)+($i*24*60*60);
$time[] = date('m-d',$t);
$ct = strtotime(date('Ymd',$t));
$ctj = strtotime(date('Ymd',$t+24*3600));
$dlz = $this->fullorder->find_all("dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'budget,shouldmoney,shop,number,refundy,budget,email,refundy');
$smt = $this->fullordersmt->find_all("dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'budget,shouldmoney,shop,refundy,userid,budget,refundy');
$tt = $this->fullordertt->find_all("state != 217 and dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'budget,shouldmoney,shop,number,refundy,budget,email,refundy');
$ab[] = $dlz;
//数量及金额开始
$dlznum[] = count($dlz);
$smtnum[] = count($smt);
$ttnum[] = count($smt);
$dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
$smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
$ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
/**
//提出退款关闭等信息的实收金额
$dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
$smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
//提出退款关闭等信息的实收金额
**/
//实收金额
$dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'budget')));
$smtmss = sprintf("%01.2f",array_sum(array_column($smt,'budget')));
$ttmss = sprintf("%01.2f",array_sum(array_column($tt,'budget')));
//实收金额
//补/退原额
$dlzbty = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
$smtbty = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
$ttbty = sprintf("%01.2f",array_sum(array_column($tt,'refundy')));
//补/退原额
$dlzmoney[] = $dlzm;
$smtmoney[] = $smtm;
$ttmoney[] = $ttm;
$dlzsl += count($dlz);
$dlzje += $dlzm;
$smtsl += count($smt);
$smtje += $smtm;
$ttsl += count($tt);
$ttje += $ttm;
/**
//减去的实收金额
$dlzssje += $dlzm+$dlzmss;
$smtssje += $smtm+$smtmss;
**/
//实收和补/退
$dlzssje += $dlzmss+$dlzbty;
$smtssje += $smtmss+$smtbty;
$ttssje += $ttmss+$ttbty;
//数量及金额结束
$sd = array_merge($dlz,$smt,$tt);
foreach ($sd as $v)
{
if(isset($shopdata[$v['shop']]))
{
$shopdata[$v['shop']]['num'] += 1;
$shopdata[$v['shop']]['money'] += $v['shouldmoney'];
$shopdata[$v['shop']]['tmoney'] += $v['budget']+$v['refundy'];
}
}
}
else if ($n > 13 && $i <= $n/2)
{
$t = $usat-($n*24*60*60)+($i*24*60*60);
$timeold[] = date('m-d',$t);
$ct = strtotime(date('Ymd',$t));
$ctj = strtotime(date('Ymd',$t+24*3600));
$dlz = $this->fullorder->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
$smt = $this->fullordersmt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
$tt = $this->fullordertt->find_all("state != 217 and (".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
//数量及金额开始
$dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
$smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
$ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
$dlzmoneyb[] = $dlzm;
$smtmoneyb[] = $smtm;
$ttmoneyb[] = $ttm;
//数量及金额结束
}
}
foreach ($shopdata as $k=>$v)
{
$sn = $this->shop->read($k);
$shopdata[$k]['money'] = sprintf("%01.2f",$v['money']).'$';
$shopdata[$k]['tmoney'] = sprintf("%01.2f",$v['tmoney']).'$';
$shopdata[$k]['bl'] = ($v['num']=='0')?'0$':round($v['money']/$v['num'],2).'$';
$shopdata[$k]['name'] = $sn['shopname'];
$shopdata[$k]['b'] = $sn['type'];
$shopdata[$k]['id'] = $sn['id'];
}
$shopdata = array_values($shopdata);
//$sycp=array();
/**
//根据所选时间产品排行开始
$dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
$smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
**/
/**
//昨日产品排行开始
$dlzlist = $this->fullorder->find_all("fpdata != '' and dtime >= '".strtotime(date("Ymd",time()-86400))."' and dtime <= '".strtotime(date("Ymd",time()))."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
$smtlist = $this->fullordersmt->find_all("fpdata != '' and dtime >= '".strtotime(date("Ymd",time()-86400))."' and dtime <= '".strtotime(date("Ymd",time()))."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
$rows = array_merge($dlzlist,$smtlist);
foreach ($rows as $v)
{
$number = explode('|',trim($v['whlabel'],'|'));
$or = explode(';',trim($v['fpdata'],';'));
$i=0;
foreach ($or as $va)
{
$ord = explode('|',$va);
$orod = explode(',',$ord[0]);
$numberod = explode('-',$number[$i]);
if(!isset($orod[1]))
{
continue;
}
if(isset($sycp[$orod[1]]) && isset($numberod[1]))
{
//$sycp[$orod[1]][0] += 1;//统计多少单
$sycp[$orod[1]][0] += $numberod[1];//统计多少条
$sycp[$orod[1]][1] += 0;//价格
}
else
{
if(isset($numberod[1]))
{
$typeclass = $this->typeclass->read($orod['0']);
$sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
}
}
$i++;
}
}
arsort($sycp);
$sycp = array_values($sycp);
$sycp = array_slice($sycp,0,10);
//产品排行结束
**/
//当时实时数据结束
$zqtdata[$vval][$value] = array('time'=>$time,'timeold'=>$timeold,'smtnum'=>$smtnum,'ttnum'=>$ttnum,'dlznum'=>$dlznum,'smtmoney'=>$smtmoney,'ttmoney'=>$ttmoney,'dlzmoney'=>$dlzmoney,'smtmoneyb'=>$smtmoneyb,'ttmoneyb'=>$ttmoneyb,'dlzmoneyb'=>$dlzmoneyb,'dlzsl'=>$dlzsl,'dlzje'=>number_format($dlzje,2),'dlzssje'=>number_format($dlzssje,2),'smtsl'=>$smtsl,'ttsl'=>$ttsl,'smtje'=>number_format($smtje,2),'ttje'=>number_format($ttje,2),'smtssje'=>number_format($smtssje,2),'ttssje'=>number_format($ttssje,2),'zje'=>number_format($dlzje+$smtje+$ttje,2),'zsl'=>$dlzsl+$smtsl+$ttsl,'shopdata'=>$shopdata,'cs'=>$n,'success'=>true);//,'sycp'=>$sycp昨日产品数据
}
}
//time结束
//zhcx开始
$zhcxdata = array();
foreach ($molist as $vval)
{
$where = "";
$source = $vval;
if($source == '2d')
{
$where = " and source >= '2'";
}
else if($source != '0')
{
$where = " and source = '$source'";
}
foreach ($zqtime as $value)
{
$zdt = $value;
$k = $zdt;
$tab = 1;
//$customer = $this->customer->find_all("shop !=''",'num,zhcx');
//$customerkey = array_column($customer,'zhcx');
//$customer= array_combine($customerkey,$customer);
//$customersmt = $this->customersmt->find_all("shop !=''",'num,zhcx');
//$customersmtkey = array_column($customersmt,'zhcx');
//$customersmt= array_combine($customersmtkey,$customersmt);
//$customertt = $this->customertt->find_all("shop !=''",'num,zhcx');
//$customerttkey = array_column($customertt,'zhcx');
//$customertt= array_combine($customerttkey,$customertt);
if($tab == '1')
{
if($zdt >= 691200)
{
$k = $usat-$k-$k;
$j = $usat;
$n = ($j-$k)/(24*3600);
}
else
{
$n = 2;
$usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
}
}
else
{
$timedata = explode('|',$zdt);
$ktime = strtotime($timedata[0]);
$jtime = strtotime($timedata[1]);
$ktime = $ktime-($jtime-$ktime);
$k = $ktime;
$j = $jtime;
$n = ($j-$k)/(24*3600);
$usat = $jtime;
}
$time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();$ttnum = array();$ymoney = array();$money = array();
$dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();$zkh = array();
$dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
$ys = $this->shop->find_all("type != '0' and id != '18' and id != '19' and id != '12' and id != '13' and id != '9' and id != '15' and id != '27' and id != '28' and id != '29' and id != '30' and id != '21' and id != '34'");
foreach ($ys as $v)
{
$shopdata[$v['id']] = array('id'=>$v['id'],'b'=>$v['type'],'fdl'=>0,'chl'=>0,'num'=>0,'fgl'=>0);
$zkh[$v['id']] = array();
}
for($i=1;$i<$n;$i++)
{
if($n > 13 && $i > $n/2 || $n < 14)
{
$t = $usat-($n*24*60*60)+($i*24*60*60);
$time[] = date('m-d',$t);
$ct = strtotime(date('Ymd',$t));
$ctj = strtotime(date('Ymd',$t+24*3600));
$dlz = $this->fullorder->find_all("dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'shop,email');
$dlzemail = $this->fullorder->find_all("dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'shop,email');
$smt = $this->fullordersmt->find_all("dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'shop,userid');
$tt = $this->fullordertt->find_all("state != 217 and dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'shop,email');
//数量及金额结束
$sd = array_merge($dlz,$smt,$tt);
$fgldata = array();
foreach ($sd as $v)
{
/**
$array = array(
0 => array('email' => 123, 'id' => 1),
1 => array('email' => 321, 'id' => 2),
2 => array('email' => 123, 'id' => 3),
3 => array('email' => 123, 'id' => 3)
);
// 使用 array_filter 筛选满足多个条件的元素
$result = array_filter($array, function($item) {
return $item['email'] === 123 && $item['id'] === 3;
});
// 计算满足条件的数量
$count = count($result);
echo "满足条件 (email = 123 且 id = 3) 的数量是:$count";
**/
/** 独立站查customer方法 弃用
if(isset($v['email']))
{
if(!isset($fgldata[$v['shop'].'-'.$v['email']]))
{
$fgldata[$v['shop'].'-'.$v['email']] = 0;
}
else
{
$fgldata[$v['shop'].'-'.$v['email']] += 1;
}
$zkh[$v['shop']][$v['email']] = array();
}
**/
/** 速卖通
else
{
if(!isset($fgldata[$v['shop'].'-'.$v['userid']]))
{
$fgldata[$v['shop'].'-'.$v['userid']] = 0;
}
else
{
$fgldata[$v['shop'].'-'.$v['userid']] += 1;
}
$zkh[$v['shop']][$v['userid']] = array();
}
**/
}
foreach ($sd as $v)
{
//避免由于作用域引起的问题
$tmp_v = $v;
$fdl_result = array_filter($dlz, function($item) use($tmp_v)
{
if(!isset($item['email'])||!isset($tmp_v['email'])||!isset($item['shop'])){
return false;
}else{
return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
}
//return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
});
$fdl = count($fdl_result) > 1?1:0;//返单
$chl_result = array_filter($dlz, function($item) use($tmp_v)
{
if(!isset($item['email'])||!isset($tmp_v['email'])||!isset($item['shop'])){
return false;
}else{
return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
}
//return $item['email'] === $tmp_v['email'] && $item['shop'] !== $tmp_v['email'];
});
$chl = count($chl_result) > 1?1:0;//重合
$fgl_result = array_filter($dlzemail, function($item) use($tmp_v)
{
if(!isset($item['email'])||!isset($tmp_v['email'])||!isset($item['shop'])){
return false;
}else{
return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
}
//return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
});
$fgl = count($fgl_result) > 1?1:0;//复购
$shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl']+$fdl;
$shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl']+$chl;
$shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl']+$fgl;
$shopdata[$v['shop']]['num'] += 1;
/**
$chl = 0;
if(isset($shopdata[$v['shop']]))
{
if(isset($v['email']))
{
if(isset($customer[$v['shop'].'-'.$v['email']]['num']))
{
$fdl = $customer[$v['shop'].'-'.$v['email']]['num']>1?1:0;
}
else
{
$fdl = 0;
}
foreach ($ys as $vv)
{
if($vv['id'] != $v['shop'] && isset($customer[$vv['id'].'-'.$v['email']]))
{
$chl = 1;
}
}
if(isset($fgldata[$v['shop'].'-'.$v['email']]))
{
$fgl = $fgldata[$v['shop'].'-'.$v['email']]>0?1:0;
}
else
{
$fgl = 0;
}
}
else
{
if(isset($customersmt[$v['shop'].'-'.$v['userid']]['num']))
{
$fdl = $customersmt[$v['shop'].'-'.$v['userid']]['num']>1?1:0;
}
else
{
$fdl = 0;
}
foreach ($ys as $vv)
{
if($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'].'-'.$v['userid']]))
{
$chl = 1;
}
}
if(isset($fgldata[$v['shop'].'-'.$v['userid']]))
{
$fgl = $fgldata[$v['shop'].'-'.$v['userid']]>0?1:0;
}
else
{
$fgl = 0;
}
}
}
**/
}
}
}
foreach ($shopdata as $k=>$v)
{
$shopdata[$k]['fdl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['fdl']/$v['num']*100)).'%';
$shopdata[$k]['chl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['chl']/$v['num']*100)).'%';
$shopdata[$k]['fgl'] = count($zkh[$v['id']])=='0'?0:sprintf("%01.2f",($v['fgl']/count($zkh[$v['id']])*100)).'%';
}
$shopdata = array_values($shopdata);
$zhcxdata[$vval][$value] = array('shopdata'=>$shopdata,'success'=>true);
}
}
//zhcx结束
$myfile = fopen("./data/tj/".$pdtime.".txt", "w") or die("Unable to open file!");
$txt = json_encode(array('zzt'=>$zzt,'tj'=>$zqtdata,'zhcx'=>$zhcxdata));
fwrite($myfile, $txt);
fclose($myfile);
echo 1;
}
}