| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749 | 
							- <?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);
 
- 			$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);
 
- 			$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();
 
- 		$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";
 
- 			}
 
- 			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 != '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' 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") {
 
- 				$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');
 
- 			$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;
 
- 		//系统报错 提示没有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;
 
- 	}
 
- }
 
 
  |