| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754 | <?php defined('BASEPATH') or exit('No direct script access allowed');class User extends Start_Controller{	public function __construct()	{		parent::__construct();		$this->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');		$this->load->_model('Model_fullorderamz', 'fullorderamz');		$this->load->_model("Model_logic_ding","logic_ding");	}	//定义方法的调用规则 获取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()	{		if(empty($_SESSION['api'])){			exit('No direct script access allowed');		}		$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);			$type = $this->input->post('type', 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%' ";			}			if ($type) {				$where  .= " and type = '$type' ";			}			//数据排序			$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);			$info_list = $this->user->find_all($where, 'id,name,userid,power,shoptext,purchasetext,warehousetext,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'] = '正常' . "<br>最后操作时间:<br>" . 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("1 = 1","*","sort asc,id asc");		$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'] = empty($this->input->post('staff', true))?0:$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));			unset($post['id']);			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("1 = 1","*","sort asc,id asc");		$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("1 = 1","*","sort asc,id asc");		$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";			}			if(empty($fgshop)){				$this->logic_ding->sendToDing("用户统计页面的店铺为空,请检查!".json_encode($user));			}		}		$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";				// }				if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {					$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("status = 0  and 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' and id != '56'");				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');						$amz = $this->fullorderamz->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,$amz);						$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;				$amzsl = 0;				$amzje = 0;				$amzssje = 0;				$shopdata = array();				$ys = $this->shop->find_all("status = 0 and 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 != '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' and id != '56'");				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');						$amz = $this->fullorderamz->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);						$amznum[] = count($amz);						$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')));						$amzm = sprintf("%01.2f", array_sum(array_column($amz, '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')));						$amzmss = sprintf("%01.2f", array_sum(array_column($amz, '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')));						$amzbty = sprintf("%01.2f", array_sum(array_column($amz, 'refundy')));						//补/退原额						$dlzmoney[] = $dlzm;						$smtmoney[] = $smtm;						$ttmoney[] = $ttm;						$amzmoney[] = $amzm;						$dlzsl += count($dlz);						$dlzje += $dlzm;						$smtsl += count($smt);						$smtje += $smtm;						$ttsl += count($tt);						$ttje += $ttm;						$amzsl += count($amz);						$amzje += $amzm;						/**				//减去的实收金额				$dlzssje += $dlzm+$dlzmss;				$smtssje += $smtm+$smtmss;						 **/						//实收和补/退						$dlzssje += $dlzmss + $dlzbty;						$smtssje += $smtmss + $smtbty;						$ttssje += $ttmss + $ttbty;						$amzssje += $amzmss + $amzbty;						//数量及金额结束						$sd = array_merge($dlz, $smt, $tt,$amz);						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');						$amz = $this->fullorderamz->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')));						$amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));						$dlzmoneyb[] = $dlzm;						$smtmoneyb[] = $smtm;						$ttmoneyb[] = $ttm;						$amzmoneyb[] = $amzm;						//数量及金额结束					}				}				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,'amznum'=>$amznum ,'dlznum' => $dlznum, 'smtmoney' => $smtmoney, 'ttmoney' => $ttmoney, 'amzmoney'=>$amzmoney,'dlzmoney' => $dlzmoney, 'smtmoneyb' => $smtmoneyb, 'ttmoneyb' => $ttmoneyb,'amzmoneyb' => $amzmoneyb ,'dlzmoneyb' => $dlzmoneyb, 'dlzsl' => $dlzsl, 'dlzje' => number_format($dlzje, 2), 'dlzssje' => number_format($dlzssje, 2), 'smtsl' => $smtsl,'amzsl' => $amzsl ,'ttsl' => $ttsl, 'smtje' => number_format($smtje, 2),'amzje' => number_format($amzje, 2),  'ttje' => number_format($ttje, 2), 'smtssje' => number_format($smtssje, 2),'amzssje' => number_format($amzssje, 2), 'ttssje' => number_format($ttssje, 2), 'zje' => number_format($dlzje + $smtje + $ttje + $amzje, 2), 'zsl' => $dlzsl + $smtsl + $ttsl + $amzsl, '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');				$amzje = $this->fullorderamz->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);				$ssslamz = count($amzje);				$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')));				$ssjeamz = sprintf("%01.2f", array_sum(array_column($amzje, 'budget')));				$sssl = $sssldlz + $ssslsmt + $sssltt + $ssslamz;				$ssje = $ssjedlz + $ssjesmt + $ssjett + $ssjeamz;			} else {				$sp = $this->shop->read($shop);				if($sp['type'] == '1513'){					$fu = 'fullorderamz';				}elseif($sp['type'] == '270'){					$fu = 'fullordersmt';				}elseif($sp['type'] == '1514'){					$fu = 'fullordertt';				}else{					$fu = 'fullorder';				}				//1513				//$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" || $xqshop['type'] ==  "2768") {				$sid = 'fullorder';			} else if ($xqshop['type'] == "270") {				$sid = 'fullordersmt';			} else if ($xqshop['type'] == "1513") {				$sid = 'fullorderamz';			}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 < count($or); $i++) {					$orod = explode('-', $or[$i]);					if ($orod[0] == '') {						continue;					}					if (isset($dpxq[$orod[0]])) {						$dpxq[$orod[0]][0] += $orod[1]; //统计多少条						//$dpxq[$orod[0]][0] += 1;//统计多少单						$dpxq[$orod[0]][1] .= $v['number'] . ';'; //价格					} else {						$oo = explode(';', rtrim($v['fpdata'], ';'));						@$ro = explode('|', $oo[$i]);						if (isset($ro[1])) {							$dpxq[$orod[0]] = array($orod[1], $v['number'] . ';', $ro[1]); //统计多少条							//$dpxq[$orod[0]] = array(1,0,$ro[1]);//统计多少单						}					}				}			}			$dpxq = array_values($dpxq);			arsort($dpxq);			$dpxq = array_slice($dpxq, 0, 9999);			echo @json_encode(array('dpxq' => $dpxq, 'success' => true));			exit;		}		$wlshop = $this->shop->find_all('status = 0  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',"*","px asc");			$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 or type = 2768 )  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 or type = 2768 )  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;		//系统报错 提示没有api下标的键		if(!isset($_SESSION['api'])){			echo "ERROR";			die;		}		$user = $this->user->get_api($_SESSION['api']);		$usp = $user;		$fgshop = "";		$sid = "";		$user = explode('|', trim($user['shop'], '|'));		foreach ($user as $value) {			if(!empty($value)){				$fgshop .= " shop = " . $value . " or";				$sid .= " id = " . $value . " or";			}					}		//为了让下面程序可以执行 给的如果用户没店铺权限 就给一个不存在的店铺		if(empty($fgshop)){			$fgshop = " shop = 0 or";			$sid = 	" id = 0 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;	}}
 |