User.php 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class User extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_user','user');
  7. $this->load->_model('Model_nav','nav');
  8. $this->load->_model('Model_power','power');
  9. $this->load->_model('Model_shop','shop');
  10. $this->load->_model('Model_purchase','purchase');
  11. $this->load->_model('Model_warehouse','warehouse');
  12. $this->load->_model('Model_staff','staff');
  13. $this->load->_model('Model_fullorder','fullorder');
  14. $this->load->_model('Model_fullordertt','fullordertt');
  15. $this->load->_model('Model_fullordersmt','fullordersmt');
  16. $this->load->_model('Model_customer','customer');
  17. $this->load->_model('Model_customersmt','customersmt');
  18. $this->load->_model('Model_typeclass','typeclass');
  19. $this->load->_model('Model_transfer','transfer');
  20. $this->load->_model('Model_typeclass','typeclass');
  21. $this->load->_model('Model_customertt','customertt');
  22. $this->load->_model('Model_allocation','allocation');
  23. }
  24. //定义方法的调用规则 获取URI第二段值
  25. public function _remap($arg,$arg_array)
  26. {
  27. if($arg == 'tc')//退出
  28. {
  29. $this->_tc();
  30. }
  31. else if($arg == 'data')//操作页
  32. {
  33. $this->_data();
  34. }
  35. else if($arg == 'del')//删除
  36. {
  37. $this->_del();
  38. }
  39. else if($arg == 'default')//默认页
  40. {
  41. $this->_default();
  42. }
  43. else if($arg == 'add')//添加
  44. {
  45. $this->_add();
  46. }
  47. else if($arg == 'edit')//修改
  48. {
  49. $this->_edit($arg_array);
  50. }
  51. else if($arg == 'rows')//数据
  52. {
  53. $this->_rows();
  54. }
  55. else if($arg == 'statistics')//数据
  56. {
  57. $this->_statistics();
  58. }
  59. else if($arg == 'apple')//数据
  60. {
  61. $this->_apple();
  62. }
  63. else if($arg == 'zzt')//数据
  64. {
  65. $this->_zzt();
  66. }
  67. else if($arg == 'tjadd')//数据
  68. {
  69. $this->_tjadd();
  70. }
  71. else if($arg == 'shopfx')//店铺分析
  72. {
  73. $this->_shopfx();
  74. }
  75. else if($arg == 'shopfxlist')//店铺分析
  76. {
  77. $this->_shopfxlist();
  78. }
  79. else
  80. {
  81. $this->_index();
  82. }
  83. }
  84. //首页
  85. public function _index()
  86. {
  87. $user = $this->user->get_api($_SESSION['api']);
  88. $this->data['user'] = $user;//登录的用户信息
  89. $power = $this->power->read($user['power']);
  90. $power = $power['powerid'];
  91. //$power = explode('|',trim($power,'|'));字符串转数组
  92. $dataa = $this->nav->find_all('type=1','*','px asc');
  93. $datab = $this->nav->find_all('type=2','*','px asc');
  94. $datac = $this->nav->find_all('type=3','*','sort asc,px desc');
  95. $an = array();
  96. foreach ($dataa as $key=>$value)
  97. {
  98. foreach ($datab as $ke=>$va)
  99. {
  100. if($va['class'] == $value['id'])
  101. {
  102. foreach ($datac as $k=>$v)
  103. {
  104. if($v['class'] == $va['id'])
  105. {
  106. if(strstr($power,'|'.$v['id'].'|')==true)
  107. {
  108. $va['cn'][]=$v;
  109. }
  110. }
  111. }
  112. if(strstr($power,'|'.$va['id'].'|')==true)
  113. {
  114. $value['bn'][]=$va;
  115. }
  116. }
  117. }//循环出二级导航航
  118. if(strstr($power,'|'.$value['id'].'|')==true)
  119. {
  120. $an[] = $value;
  121. }
  122. }
  123. //print_r($an);
  124. $this->data['data'] = $an;
  125. $this->data['ip'] = $this->input->ip_address();
  126. $this->data['power'] = $user['power'];
  127. $this->data['link'] = $user['link'];
  128. if(stripos($_SERVER ['HTTP_HOST'],'a.') !== false)
  129. {
  130. $url = 'b';
  131. }
  132. else
  133. {
  134. $url = 'a';
  135. }
  136. $this->data['url'] = $url;
  137. $this->_Template('user',$this->data);
  138. }
  139. //管理
  140. public function _data()
  141. {
  142. $user = $this->user->get_api($_SESSION['api']);
  143. $post = $this->input->post(NULL, TRUE);
  144. if(isset($post['page']))
  145. {
  146. $page = $this->input->post('page',true);
  147. $perpage = $this->input->post('perpage',true);
  148. $power = $this->input->post('power',true);
  149. $name = $this->input->post('name',true);
  150. $userid = $this->input->post('userid',true);
  151. $where = "own='".$user['own']."'";
  152. if($power)
  153. {
  154. $where .= " and power = '$power'";
  155. }
  156. if($name)
  157. {
  158. $where .= " and name like '%$name%'";
  159. }
  160. if($userid)
  161. {
  162. $where .= " and userid like '%$userid%'";
  163. }
  164. //数据排序
  165. $order_str = "id asc";
  166. if(empty($page))
  167. {
  168. $start = 0;
  169. $perpage = 1;
  170. }
  171. else
  172. {
  173. $start = ($page - 1)*$perpage;
  174. }
  175. //取得信息列表
  176. $info_list = $this->user->find_all($where,'id,name,userid,power,shoptext,purchasetext,warehousetext,stafftext,transfertext,type',$order_str,$start,$perpage);
  177. //格式化数据
  178. foreach ($info_list as $key=>$value)
  179. {
  180. if($value['type'] == 1)
  181. {
  182. $info_list[$key]['type'] = '正常';
  183. }
  184. else
  185. {
  186. $info_list[$key]['type'] = '停用';
  187. }
  188. $power = $this->power->read($value['power']);
  189. $info_list[$key]['power'] = $power['powername'];
  190. }
  191. $total = $this->user->find_count($where);
  192. $pagenum = ceil($total/$perpage);
  193. $over = $total-($start+$perpage);
  194. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  195. echo json_encode($rows);exit;
  196. }
  197. $power = $this->power->find_all();
  198. $this->data['power'] = $power;
  199. $this->_Template('user_data',$this->data);
  200. }
  201. //添加
  202. public function _add()
  203. {
  204. $user = $this->user->get_api($_SESSION['api']);
  205. $post = $this->input->post(NULL, TRUE);
  206. if(isset($post['userid']))
  207. {
  208. $post['userid'] = $this->input->post('userid',true);
  209. $userpass = $this->input->post('userpass',true);
  210. $post['userpass'] = sha1($userpass);
  211. $post['shop'] = $this->input->post('shop',true);
  212. $post['shoptext'] = $this->input->post('shoptext',true);
  213. $post['excelshop'] = $this->input->post('excelshop',true);
  214. $post['excelshoptext'] = $this->input->post('excelshoptext',true);
  215. $post['purchase'] = $this->input->post('purchase',true);
  216. $post['purchasetext'] = $this->input->post('purchasetext',true);
  217. $post['warehouse'] = $this->input->post('warehouse',true);
  218. $post['warehousetext'] = $this->input->post('warehousetext',true);
  219. $post['customer'] = $this->input->post('customer',true);
  220. $post['staff'] = $this->input->post('staff',true);
  221. $post['stafftext'] = $this->input->post('stafftext',true);
  222. $post['power'] = $this->input->post('power',true);
  223. $post['name'] = $this->input->post('name',true);
  224. $post['phone'] = $this->input->post('phone',true);
  225. $post['type'] = $this->input->post('type',true);
  226. $post['html'] = $this->input->post('html',true);
  227. $post['own'] = $user['own'];
  228. $post['api'] = sha1(rand(1000000,9999999));
  229. if($this->user->insert($post))
  230. {
  231. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  232. }
  233. else
  234. {
  235. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  236. }
  237. }
  238. $power = $this->power->find_all();
  239. $this->data['power'] = $power;
  240. $this->_Template('user_add',$this->data);
  241. }
  242. //修改
  243. public function _edit($arg_array)
  244. {
  245. $post = $this->input->post(NULL, TRUE);
  246. if(isset($post['id']))
  247. {
  248. $id = $this->input->post('id',true);
  249. $post['userid'] = $this->input->post('edituserid',true);
  250. $userpass = $this->input->post('edituserpass',true);
  251. $post['shop'] = $this->input->post('shop',true);
  252. $post['shoptext'] = $this->input->post('shoptext',true);
  253. $post['excelshop'] = $this->input->post('excelshop',true);
  254. $post['excelshoptext'] = $this->input->post('excelshoptext',true);
  255. $post['purchase'] = $this->input->post('purchase',true);
  256. $post['purchasetext'] = $this->input->post('purchasetext',true);
  257. $post['warehouse'] = $this->input->post('warehouse',true);
  258. $post['warehousetext'] = $this->input->post('warehousetext',true);
  259. $post['customer'] = $this->input->post('customer',true);
  260. $post['staff'] = $this->input->post('staff',true);
  261. $post['stafftext'] = $this->input->post('stafftext',true);
  262. $post['power'] = $this->input->post('power',true);
  263. $post['name'] = $this->input->post('name',true);
  264. $post['phone'] = $this->input->post('phone',true);
  265. $post['type'] = $this->input->post('type',true);
  266. $post['html'] = $this->input->post('html',true);
  267. $ud = $this->user->read($id);
  268. if($userpass != NULL)
  269. {
  270. $post['userpass'] = sha1($userpass);
  271. $post['api'] = sha1(rand(1000000,9999999));
  272. }
  273. else
  274. {
  275. $post['userpass'] = $ud['userpass'];
  276. }
  277. if($this->user->save($post,$id))
  278. {
  279. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  280. }
  281. else
  282. {
  283. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  284. }
  285. }
  286. $arg_array = $arg_array[0];
  287. $user = $this->user->read($arg_array);
  288. $this->data['user'] = $user;
  289. $power = $this->power->find_all();
  290. $this->data['power'] = $power;
  291. $this->_Template('user_edit',$this->data);
  292. }
  293. //删除
  294. public function _del()
  295. {
  296. $post = $this->input->post(NULL, TRUE);
  297. if(isset($post['s']))
  298. {
  299. $id_arr = $this->input->post('s');
  300. $id_arr = explode(',',$id_arr);
  301. if(!$id_arr)
  302. {
  303. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  304. }
  305. //循环删除记录
  306. foreach ($id_arr as $v)
  307. {
  308. $this->user->remove($v);
  309. }
  310. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  311. }
  312. }
  313. //默认页
  314. public function _default()
  315. {
  316. /**
  317. $order = $this->order->get_w();
  318. $order = count($order);//查询订单未处理数量
  319. $message = $this->message->get_w();
  320. $message = count($message);//查询留言未处理数量
  321. $this->_Template('default',$this->data);
  322. **/
  323. $dt = 0;
  324. if(isset($_SESSION['api']))
  325. {
  326. $user = $this->user->get_api($_SESSION['api']);
  327. $usp = $user;
  328. $fgshop = "";$sid = "";
  329. $user = explode('|',trim($user['shop'],'|'));
  330. foreach ($user as $value)
  331. {
  332. if($value != '18' && $value != '19' && $value != '12' && $value != '13' && $value != '9' && $value != '15' && $value != '27')
  333. {
  334. $fgshop .= " shop = ".$value." or";
  335. }
  336. $sid .= " id = ".$value." or";
  337. }
  338. }
  339. $post = $this->input->post(NULL, TRUE);
  340. if(isset($post['timek']))
  341. {
  342. //$start = '2018-10-15';
  343. //$end = '2018-11-26';
  344. //$tim = strtotime($start);
  345. //$day = $time/(3600*24);
  346. $timek = $this->input->post('timek',true);
  347. $timej = $this->input->post('timej',true);
  348. $k = strtotime($timek)-24*3600;//少一天为增加选择开始天时间
  349. $j = strtotime($timej);
  350. $n = ($j-$k)/(24*3600);
  351. if($n < 1)
  352. {
  353. $n = 1;
  354. }
  355. $time=array();$stime=array();$num = array();$ymoney = array();$money = array();
  356. for($i=1;$i<$n;$i++)
  357. {
  358. //近7天时间
  359. $t = $j-($n*24*60*60)+($i*24*60*60);
  360. $time[] = date('Y-m-d',$t);
  361. $ct = strtotime(date('Ymd',$t));
  362. $ctj = strtotime(date('Ymd',$t+24*3600));
  363. $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');
  364. $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');
  365. $dsmt = array();
  366. $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');
  367. $d = array_merge($dlz,$dsmt,$tt);
  368. $num[] = count($d);
  369. $ymoney[] = sprintf("%01.2f",array_sum(array_column($d,'budget')));
  370. $money[] = sprintf("%01.2f",array_sum(array_column($d,'shouldmoney')));
  371. }
  372. $snuz = $this->fullorder->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
  373. $snuz += $this->fullordersmt->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
  374. $snuz += $this->fullordertt->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
  375. $lnuz = $this->fullorder->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待出库
  376. $lnuz += $this->fullordersmt->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待出库
  377. $lnuz += $this->fullordertt->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待出库
  378. $snu = $this->fullorder->find_count('reviewtime = 0 and dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
  379. $snu += $this->fullordersmt->find_count('reviewtime = 0 and dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
  380. $snu += $this->fullordertt->find_count('reviewtime = 0 and dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
  381. $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').')');//待出库
  382. $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').')');//待出库
  383. $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').')');//待出库
  384. 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;
  385. }
  386. $this->_Template('user_default',$this->data);
  387. }
  388. public function _zzt()
  389. {
  390. exit;
  391. if(isset($_SESSION['api']))
  392. {
  393. $user = $this->user->get_api($_SESSION['api']);
  394. $usp = $user;
  395. $fgshop = "";$sid = "";
  396. $user = explode('|',trim($user['shop'],'|'));
  397. foreach ($user as $value)
  398. {
  399. $fgshop .= " shop = ".$value." or";
  400. $sid .= " id = ".$value." or";
  401. }
  402. }
  403. $data = array();$sntime= array();$sndata1 = array();$sndata2 = array();$sndata3 = array();
  404. $sj = array('01','02','03','04','05','06','07','08','09','10','11','12');
  405. for($i=0;$i<3;$i++)
  406. {
  407. foreach ($sj as $v)
  408. {
  409. $sntime[] = date("Y")-2+$i.'-'.$v;
  410. }
  411. }
  412. $pdtime = date('Y-m-d-H',time());
  413. if(is_file("./data/tj/".$pdtime.".txt"))
  414. {
  415. $myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
  416. $bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
  417. fclose($myfile);
  418. $bc = json_decode($bc,true);
  419. $data = $bc['zzt'][0];
  420. $sndata = $bc['zzt'][1];
  421. }
  422. else
  423. {
  424. $i = 0;
  425. foreach ($sj as $k=>$v)
  426. {
  427. $i++;
  428. $dlz1 = $this->fullorder->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  429. $smt1 = $this->fullordersmt->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  430. $m1 = sprintf("%01.2f",array_sum(array_column($dlz1,'shouldmoney'))+array_sum(array_column($smt1,'shouldmoney')));
  431. $dlz2 = $this->fullorder->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  432. $smt2 = $this->fullordersmt->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  433. $m2 = sprintf("%01.2f",array_sum(array_column($dlz2,'shouldmoney'))+array_sum(array_column($smt2,'shouldmoney')));
  434. $dlz3 = $this->fullorder->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  435. $smt3 = $this->fullordersmt->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  436. $m3 = sprintf("%01.2f",array_sum(array_column($dlz3,'shouldmoney'))+array_sum(array_column($smt3,'shouldmoney')));
  437. $sndata1[$i] = $m3;
  438. $sndata2[12+$i] = $m2;
  439. $sndata3[24+$i] = $m1;
  440. $data[] = array($v,$m1,$m2,$m3);
  441. }
  442. }
  443. $time = array(date("Y"),(date("Y")-1),(date("Y")-2));
  444. echo json_encode(array('data'=>$data,'time'=>$time,'sndata'=>$sndata,'sntime'=>$sntime,'success'=>true));exit;
  445. }
  446. //默认页
  447. public function _statistics()
  448. {
  449. /**
  450. $order = $this->order->get_w();
  451. $order = count($order);//查询订单未处理数量
  452. $message = $this->message->get_w();
  453. $message = count($message);//查询留言未处理数量
  454. $this->_Template('default',$this->data);
  455. **/
  456. //date_default_timezone_set("Etc/GMT+8");
  457. $dt = 0;
  458. if(isset($_SESSION['api']))
  459. {
  460. $user = $this->user->get_api($_SESSION['api']);
  461. $usp = $user;
  462. $fgshop = "";$sid = "";
  463. $user = explode('|',trim($user['shop'],'|'));
  464. foreach ($user as $value)
  465. {
  466. 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')
  467. {
  468. $fgshop .= " shop = ".$value." or";
  469. }
  470. $sid .= " id = ".$value." or";
  471. }
  472. }
  473. $post = $this->input->post(NULL, TRUE);
  474. $source = $this->input->post('source',true);
  475. $where = "";
  476. if($source)
  477. {
  478. if($source == '2d')
  479. {
  480. $where = " and source >= '2'";
  481. }
  482. else
  483. {
  484. $where = " and source = '$source'";
  485. }
  486. }
  487. $tm = strtotime(date("Ymd"),time());
  488. $usat = $tm;
  489. if(isset($post['zhcx']))
  490. {
  491. $zdt = $this->input->post('time',true);
  492. $k = $zdt;
  493. $tab = $this->input->post('tab',true);
  494. $pdtime = date('Y-m-d-H',time());
  495. if(is_file("./data/tj/".$pdtime.".txt") && $tab == 1 && $zdt > 172800)
  496. {
  497. $myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
  498. $bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
  499. fclose($myfile);
  500. $bc = json_decode($bc,true);
  501. echo json_encode($bc['zhcx'][$source][$zdt]);exit;
  502. }
  503. else
  504. {
  505. $customer = $this->customer->find_all("shop !=''",'num,zhcx');
  506. $customerkey = array_column($customer,'zhcx');
  507. $customer= array_combine($customerkey,$customer);
  508. $customersmt = $this->customersmt->find_all("shop !=''",'num,zhcx');
  509. $customersmtkey = array_column($customersmt,'zhcx');
  510. $customersmt= array_combine($customersmtkey,$customersmt);
  511. //$start = '2018-10-15';
  512. //$end = '2018-11-26';
  513. //$tim = strtotime($start);
  514. //$day = $time/(3600*24);
  515. if($tab == '1')
  516. {
  517. if($zdt >= 691200)
  518. {
  519. $k = $usat-$k-$k;
  520. $j = $usat;
  521. $n = ($j-$k)/(24*3600);
  522. }
  523. else
  524. {
  525. $n = 2;
  526. $usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
  527. }
  528. }
  529. else
  530. {
  531. $timedata = explode('|',$zdt);
  532. $ktime = strtotime($timedata[0]);
  533. $jtime = strtotime($timedata[1]);
  534. $ktime = $ktime-($jtime-$ktime);
  535. $k = $ktime;
  536. $j = $jtime;
  537. $n = ($j-$k)/(24*3600);
  538. $usat = $jtime;
  539. }
  540. $time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();$ymoney = array();$money = array();
  541. $dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();$zkh = array();
  542. $dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
  543. //$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'");
  544. $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' and id != '57' and id != '60' and id != '61' and id != '62' and id != '63' and id != '64' ");
  545. foreach ($ys as $v)
  546. {
  547. $shopdata[$v['id']] = array('id'=>$v['id'],'b'=>$v['type'],'fdl'=>0,'chl'=>0,'num'=>0,'fgl'=>0);
  548. $zkh[$v['id']] = array();
  549. }
  550. for($i=1;$i<$n;$i++)
  551. {
  552. if($n > 13 && $i > $n/2 || $n < 14)
  553. {
  554. $t = $usat-($n*24*60*60)+($i*24*60*60);
  555. $time[] = date('m-d',$t);
  556. $ct = strtotime(date('Ymd',$t));
  557. $ctj = strtotime(date('Ymd',$t+24*3600));
  558. $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');
  559. $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');
  560. $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');
  561. //数量及金额结束
  562. $sd = array_merge($dlz,$smt,$tt);
  563. $fgldata = array();
  564. foreach ($sd as $v)
  565. {
  566. if(isset($v['email']))
  567. {
  568. if(!isset($fgldata[$v['shop'].'-'.$v['email']]))
  569. {
  570. $fgldata[$v['shop'].'-'.$v['email']] = 0;
  571. }
  572. else
  573. {
  574. $fgldata[$v['shop'].'-'.$v['email']] += 1;
  575. }
  576. $zkh[$v['shop']][$v['email']] = array();
  577. }
  578. else
  579. {
  580. if(!isset($fgldata[$v['shop'].'-'.$v['userid']]))
  581. {
  582. $fgldata[$v['shop'].'-'.$v['userid']] = 0;
  583. }
  584. else
  585. {
  586. $fgldata[$v['shop'].'-'.$v['userid']] += 1;
  587. }
  588. $zkh[$v['shop']][$v['userid']] = array();
  589. }
  590. }
  591. foreach ($sd as $v)
  592. {
  593. $chl = 0;
  594. if(isset($shopdata[$v['shop']]))
  595. {
  596. if(isset($v['email']))
  597. {
  598. if(isset($customer[$v['shop'].'-'.$v['email']]['num']))
  599. {
  600. $fdl = $customer[$v['shop'].'-'.$v['email']]['num']>1?1:0;
  601. }
  602. else
  603. {
  604. $fdl = 0;
  605. }
  606. foreach ($ys as $vv)
  607. {
  608. if($vv['id'] != $v['shop'] && isset($customer[$vv['id'].'-'.$v['email']]))
  609. {
  610. $chl = 1;
  611. }
  612. }
  613. if(isset($fgldata[$v['shop'].'-'.$v['email']]))
  614. {
  615. $fgl = $fgldata[$v['shop'].'-'.$v['email']]>0?1:0;
  616. }
  617. else
  618. {
  619. $fgl = 0;
  620. }
  621. }
  622. else
  623. {
  624. if(isset($customersmt[$v['shop'].'-'.$v['userid']]['num']))
  625. {
  626. $fdl = $customersmt[$v['shop'].'-'.$v['userid']]['num']>1?1:0;
  627. }
  628. else
  629. {
  630. $fdl = 0;
  631. }
  632. foreach ($ys as $vv)
  633. {
  634. if($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'].'-'.$v['userid']]))
  635. {
  636. $chl = 1;
  637. }
  638. }
  639. if(isset($fgldata[$v['shop'].'-'.$v['userid']]))
  640. {
  641. $fgl = $fgldata[$v['shop'].'-'.$v['userid']]>0?1:0;
  642. }
  643. else
  644. {
  645. $fgl = 0;
  646. }
  647. }
  648. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl']+$fdl;
  649. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl']+$chl;
  650. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl']+$fgl;
  651. $shopdata[$v['shop']]['num'] += 1;
  652. }
  653. }
  654. }
  655. }
  656. foreach ($shopdata as $k=>$v)
  657. {
  658. $shopdata[$k]['fdl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['fdl']/$v['num']*100)).'%';
  659. $shopdata[$k]['chl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['chl']/$v['num']*100)).'%';
  660. $shopdata[$k]['fgl'] = count($zkh[$v['id']])=='0'?0:sprintf("%01.2f",($v['fgl']/count($zkh[$v['id']])*100)).'%';
  661. }
  662. $shopdata = array_values($shopdata);
  663. echo @json_encode(array('shopdata'=>$shopdata,'success'=>true));exit;
  664. }
  665. }
  666. if(isset($post['time']))
  667. {
  668. $zdt = $this->input->post('time',true);
  669. $k = $zdt;
  670. $tab = $this->input->post('tab',true);
  671. $pdtime = date('Y-m-d-H',time());
  672. if(is_file("./data/tj/".$pdtime.".txt") && $tab == 1 && $zdt > 172800)//前端改店内需要修改zdt 172800
  673. {
  674. $myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
  675. $bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
  676. fclose($myfile);
  677. $bc = json_decode($bc,true);
  678. echo json_encode($bc['tj'][$source][$zdt]);exit;
  679. }
  680. else
  681. {
  682. //$start = '2018-10-15';
  683. //$end = '2018-11-26';
  684. //$tim = strtotime($start);
  685. //$day = $time/(3600*24);
  686. if($tab == '1')
  687. {
  688. if($zdt >= 691200)
  689. {
  690. $k = $usat-$k-$k;
  691. $j = $usat;
  692. $n = ($j-$k)/(24*3600);
  693. }
  694. else
  695. {
  696. $n = 2;
  697. $usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
  698. }
  699. }
  700. else
  701. {
  702. $timedata = explode('|',$zdt);
  703. $ktime = strtotime($timedata[0]);
  704. $jtime = strtotime($timedata[1]);
  705. $ktime = $ktime-($jtime-$ktime);
  706. $k = $ktime;
  707. $j = $jtime;
  708. $n = ($j-$k)/(24*3600);
  709. $usat = $jtime;
  710. $tm = $jtime;
  711. $zdt = $jtime-$ktime;
  712. }
  713. $time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();$ymoney = array();$money = array();
  714. $dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();$zkh = array();
  715. $dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
  716. $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'");
  717. foreach ($ys as $v)
  718. {
  719. $shopdata[$v['id']] = array('num'=>0,'money'=>0,'tmoney'=>0,'fdl'=>0,'chl'=>0);
  720. }
  721. for($i=1;$i<$n;$i++)
  722. {
  723. //近7天时间
  724. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  725. if($n > 13 && $i > $n/2 || $n < 14)
  726. {
  727. $t = $usat-($n*24*60*60)+($i*24*60*60);
  728. $time[] = date('m-d',$t);
  729. $ct = strtotime(date('Ymd',$t));
  730. $ctj = strtotime(date('Ymd',$t+24*3600));
  731. $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');
  732. $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');
  733. $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');
  734. $ab[] = $dlz;
  735. //数量及金额开始
  736. $dlznum[] = count($dlz);
  737. $smtnum[] = count($smt);
  738. $ttnum[] = count($smt);
  739. $dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
  740. $smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
  741. $ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
  742. /**
  743. //提出退款关闭等信息的实收金额
  744. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  745. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  746. //提出退款关闭等信息的实收金额
  747. **/
  748. //实收金额
  749. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'budget')));
  750. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'budget')));
  751. $ttmss = sprintf("%01.2f",array_sum(array_column($tt,'budget')));
  752. //实收金额
  753. //补/退原额
  754. $dlzbty = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  755. $smtbty = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  756. $ttbty = sprintf("%01.2f",array_sum(array_column($tt,'refundy')));
  757. //补/退原额
  758. $dlzmoney[] = $dlzm;
  759. $smtmoney[] = $smtm;
  760. $ttmoney[] = $ttm;
  761. $dlzsl += count($dlz);
  762. $dlzje += $dlzm;
  763. $smtsl += count($smt);
  764. $smtje += $smtm;
  765. $ttsl += count($tt);
  766. $ttje += $ttm;
  767. /**
  768. //减去的实收金额
  769. $dlzssje += $dlzm+$dlzmss;
  770. $smtssje += $smtm+$smtmss;
  771. **/
  772. //实收和补/退
  773. $dlzssje += $dlzmss+$dlzbty;
  774. $smtssje += $smtmss+$smtbty;
  775. $ttssje += $ttmss+$ttbty;
  776. //数量及金额结束
  777. $sd = array_merge($dlz,$smt,$tt);
  778. foreach ($sd as $v)
  779. {
  780. if(isset($shopdata[$v['shop']]))
  781. {
  782. $shopdata[$v['shop']]['num'] += 1;
  783. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  784. $shopdata[$v['shop']]['tmoney'] += $v['budget']+$v['refundy'];
  785. }
  786. }
  787. }
  788. else if ($n > 13 && $i <= $n/2)
  789. {
  790. $t = $usat-($n*24*60*60)+($i*24*60*60);
  791. $timeold[] = date('m-d',$t);
  792. $ct = strtotime(date('Ymd',$t));
  793. $ctj = strtotime(date('Ymd',$t+24*3600));
  794. $dlz = $this->fullorder->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  795. $smt = $this->fullordersmt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  796. $tt = $this->fullordertt->find_all("state != 217 and (".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  797. //数量及金额开始
  798. $dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
  799. $smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
  800. $ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
  801. $dlzmoneyb[] = $dlzm;
  802. $smtmoneyb[] = $smtm;
  803. $ttmoneyb[] = $ttm;
  804. //数量及金额结束
  805. }
  806. }
  807. foreach ($shopdata as $k=>$v)
  808. {
  809. $sn = $this->shop->read($k);
  810. $shopdata[$k]['money'] = sprintf("%01.2f",$v['money']).'$';
  811. $shopdata[$k]['tmoney'] = sprintf("%01.2f",$v['tmoney']).'$';
  812. $shopdata[$k]['bl'] = ($v['num']=='0')?'0$':round($v['money']/$v['num'],2).'$';
  813. $shopdata[$k]['name'] = $sn['shopname'];
  814. $shopdata[$k]['b'] = $sn['type'];
  815. $shopdata[$k]['id'] = $sn['id'];
  816. }
  817. $shopdata = array_values($shopdata);
  818. //$sycp=array();
  819. /**
  820. //根据所选时间产品排行开始
  821. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  822. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  823. **/
  824. /**
  825. //昨日产品排行开始
  826. $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');
  827. $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');
  828. $rows = array_merge($dlzlist,$smtlist);
  829. foreach ($rows as $v)
  830. {
  831. $number = explode('|',trim($v['whlabel'],'|'));
  832. $or = explode(';',trim($v['fpdata'],';'));
  833. $i=0;
  834. foreach ($or as $va)
  835. {
  836. $ord = explode('|',$va);
  837. $orod = explode(',',$ord[0]);
  838. $numberod = explode('-',$number[$i]);
  839. if(!isset($orod[1]))
  840. {
  841. continue;
  842. }
  843. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  844. {
  845. //$sycp[$orod[1]][0] += 1;//统计多少单
  846. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  847. $sycp[$orod[1]][1] += 0;//价格
  848. }
  849. else
  850. {
  851. if(isset($numberod[1]))
  852. {
  853. $typeclass = $this->typeclass->read($orod['0']);
  854. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  855. }
  856. }
  857. $i++;
  858. }
  859. }
  860. arsort($sycp);
  861. $sycp = array_values($sycp);
  862. $sycp = array_slice($sycp,0,10);
  863. //产品排行结束
  864. **/
  865. //当时实时数据结束
  866. echo @json_encode(array('time'=>$time,'timeold'=>$timeold,'smtnum'=>$smtnum,'ttnum'=>$ttnum,'dlznum'=>$dlznum,'smtmoney'=>$smtmoney,'ttmoney'=>$ttmoney,'dlzmoney'=>$dlzmoney,'smtmoneyb'=>$smtmoneyb,'ttmoneyb'=>$ttmoneyb,'dlzmoneyb'=>$dlzmoneyb,'dlzsl'=>$dlzsl,'dlzje'=>number_format($dlzje,2),'dlzssje'=>number_format($dlzssje,2),'smtsl'=>$smtsl,'ttsl'=>$ttsl,'smtje'=>number_format($smtje,2),'ttje'=>number_format($ttje,2),'smtssje'=>number_format($smtssje,2),'ttssje'=>number_format($ttssje,2),'zje'=>number_format($dlzje+$smtje+$ttje,2),'zsl'=>$dlzsl+$smtsl+$ttsl,'shopdata'=>$shopdata,'success'=>true));exit;//,'sycp'=>$sycp昨日产品数据
  867. }
  868. }
  869. if(isset($post['sstime']))
  870. {
  871. $shop = $this->input->post('shop',true);
  872. $zdtime = $usat;
  873. //当时实时数据开始
  874. if(!$shop)
  875. {
  876. $sssl = $this->fullorder->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$zdtime." and dtime <= ".strtotime(date('Ymd',$usat+24*3600)).$where,'budget,shouldmoney');
  877. $ssje = $this->fullordersmt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$zdtime." and dtime <= ".strtotime(date('Ymd',$usat+24*3600)).$where,'budget,shouldmoney');
  878. $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');
  879. $sssldlz = count($sssl);
  880. $ssslsmt = count($ssje);
  881. $sssltt = count($tje);
  882. $ssjedlz = sprintf("%01.2f",array_sum(array_column($sssl,'budget')));
  883. $ssjesmt = sprintf("%01.2f",array_sum(array_column($ssje,'budget')));
  884. $ssjett= sprintf("%01.2f",array_sum(array_column($tje,'budget')));
  885. $sssl = $sssldlz+$ssslsmt+$sssltt;
  886. $ssje = $ssjedlz+$ssjesmt+$ssjett;
  887. }
  888. else
  889. {
  890. $sp = $this->shop->read($shop);
  891. $fu = ($sp['type']=='269')?'fullorder':'fullordersmt';
  892. $ss = $this->$fu->find_all("dtime >= ".$zdtime." and dtime <= ".strtotime(date('Ymd',$usat+24*3600))." and shop = '".$shop."'",'budget,shouldmoney');
  893. $sssl = count($ss);
  894. $ssje = sprintf("%01.2f",array_sum(array_column($ss,'budget')));
  895. }
  896. echo @json_encode(array('sstime'=>date('m-d H:i',time()),'sssl'=>$sssl,'ssje'=>sprintf("%.2f",$ssje),'success'=>true));exit;
  897. }
  898. //店铺产品详情
  899. if(isset($post['id']))
  900. {
  901. $tm += 24*3600;
  902. $gshtime = date('Y-m-d 0:0:0',time());
  903. $gshtime = strtotime($gshtime)+24*60*60;
  904. $dpxq=array();
  905. $id = $this->input->post('id',true);
  906. $xqtime = $this->input->post('xqtime',true);
  907. $xqshop = $this->shop->read($id);
  908. if($xqshop['type']=="269")
  909. {
  910. $sid = 'fullorder';
  911. }
  912. else if($xqshop['type']=="270")
  913. {
  914. $sid = 'fullordersmt';
  915. }
  916. else if($xqshop['type']=="1514")
  917. {
  918. $sid = 'fullordertt';
  919. }
  920. if($xqtime > 345600)
  921. {
  922. $rows = $this->$sid->find_all("shop = '".$id."' and dtime >= '".($gshtime-$xqtime)."' and dtime <= '".($gshtime+24*60*60)."'",'whlabel,fpdata,number');
  923. }
  924. else
  925. {
  926. $rows = $this->$sid->find_all("shop = '".$id."' and dtime >= '".($gshtime-$xqtime)."' and dtime <= '".($gshtime+24*60*60-$xqtime)."'",'whlabel,fpdata,number');
  927. }
  928. foreach ($rows as $v)
  929. {
  930. $or = explode('|',ltrim($v['whlabel'],'|'));
  931. for($i=0;$i<count($or);$i++)
  932. {
  933. $orod = explode('-',$or[$i]);
  934. if($orod[0] == '')
  935. {
  936. continue;
  937. }
  938. if(isset($dpxq[$orod[0]]))
  939. {
  940. $dpxq[$orod[0]][0] += $orod[1];//统计多少条
  941. //$dpxq[$orod[0]][0] += 1;//统计多少单
  942. $dpxq[$orod[0]][1] .= $v['number'].';';//价格
  943. }
  944. else
  945. {
  946. $oo = explode(';',rtrim($v['fpdata'],';'));
  947. @$ro = explode('|',$oo[$i]);
  948. if(isset($ro[1]))
  949. {
  950. $dpxq[$orod[0]] = array($orod[1],$v['number'].';',$ro[1]);//统计多少条
  951. //$dpxq[$orod[0]] = array(1,0,$ro[1]);//统计多少单
  952. }
  953. }
  954. }
  955. }
  956. $dpxq = array_values($dpxq);
  957. arsort($dpxq);
  958. $dpxq = array_slice($dpxq,0,9999);
  959. echo @json_encode(array('dpxq'=>$dpxq,'success'=>true));exit;
  960. }
  961. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  962. $this->data['wlshop'] = $wlshop;
  963. $dr = $usat;
  964. $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));
  965. $this->_Template('phone/p_user_statistics',$this->data);
  966. }
  967. /**
  968. public function super_unique($array,$key)//多维删除重复
  969. {
  970. $temp_array = array();
  971. foreach ($array as &$v) {
  972. if (!isset($temp_array[$v[$key]]))
  973. {
  974. $temp_array[$v[$key]] =& $v;
  975. }
  976. }
  977. $array = array_values($temp_array);
  978. return $array;
  979. }
  980. **/
  981. public function _usatime()
  982. {
  983. date_default_timezone_set("Etc/GMT+8");
  984. return time();
  985. }
  986. //数据
  987. public function _rows()
  988. {
  989. $post = $this->input->post(NULL, TRUE);
  990. if(isset($post['shop']))
  991. {
  992. $shop = $this->input->post('shop',true);
  993. $data = $this->shop->find_all('1=1');
  994. $list = array();
  995. foreach ($data as $key=>$value)
  996. {
  997. $t = $this->typeclass->read($value['type']);
  998. $list[] = array('id'=>$value['id'],'title'=>$value['shopname'].' - '.$t['title']);
  999. }
  1000. $num = array();
  1001. if($shop != "null")
  1002. {
  1003. $num = $this->user->read($shop);//找出内容
  1004. if($num['shop'])
  1005. {
  1006. $num = explode('|',trim($num['shop'],'|'));//数组化内容
  1007. }
  1008. else
  1009. {
  1010. $num = array();
  1011. }
  1012. }
  1013. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1014. }
  1015. if(isset($post['excelshop']))
  1016. {
  1017. $excelshop = $this->input->post('excelshop',true);
  1018. $data = $this->shop->find_all('1=1');
  1019. $list = array();
  1020. foreach ($data as $key=>$value)
  1021. {
  1022. $t = $this->typeclass->read($value['type']);
  1023. $list[] = array('id'=>$value['id'],'title'=>$value['shopname'].' - '.$t['title']);
  1024. }
  1025. $num = array();
  1026. if($excelshop != "null")
  1027. {
  1028. $num = $this->user->read($excelshop);//找出内容
  1029. if($num['excelshop'])
  1030. {
  1031. $num = explode('|',trim($num['excelshop'],'|'));//数组化内容
  1032. }
  1033. else
  1034. {
  1035. $num = array();
  1036. }
  1037. }
  1038. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1039. }
  1040. if(isset($post['purchase']))
  1041. {
  1042. $purchase = $this->input->post('purchase',true);
  1043. $data = $this->purchase->find_all('1=1');
  1044. $list = array();
  1045. foreach ($data as $key=>$value)
  1046. {
  1047. $list[] = array('id'=>$value['id'],'title'=>$value['title']);
  1048. }
  1049. $num = array();
  1050. if($purchase != "null")
  1051. {
  1052. $num = $this->user->read($purchase);//找出内容
  1053. if($num['purchase'])
  1054. {
  1055. $num = explode('|',trim($num['purchase'],'|'));//数组化内容
  1056. }
  1057. else
  1058. {
  1059. $num = array();
  1060. }
  1061. }
  1062. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1063. }
  1064. if(isset($post['staff']))
  1065. {
  1066. $staff = $this->input->post('staff',true);
  1067. $data = $this->staff->find_all('1=1');
  1068. $list = array();
  1069. foreach ($data as $key=>$value)
  1070. {
  1071. $list[] = array('id'=>$value['id'],'title'=>$value['name']);
  1072. }
  1073. $num = array();
  1074. if($staff != "null")
  1075. {
  1076. $num = $this->user->read($staff);//找出内容
  1077. if($num['staff'])
  1078. {
  1079. $num = explode('|',trim($num['staff'],'|'));//数组化内容
  1080. }
  1081. else
  1082. {
  1083. $num = array();
  1084. }
  1085. }
  1086. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1087. }
  1088. if(isset($post['warehouse']))
  1089. {
  1090. $warehouse = $this->input->post('warehouse',true);
  1091. $data = $this->warehouse->find_all('1=1');
  1092. $list = array();
  1093. foreach ($data as $key=>$value)
  1094. {
  1095. $list[] = array('id'=>$value['id'],'title'=>$value['title']);
  1096. }
  1097. $num = array();
  1098. if($warehouse != "null")
  1099. {
  1100. $num = $this->user->read($warehouse);//找出内容
  1101. if($num['warehouse'])
  1102. {
  1103. $num = explode('|',trim($num['warehouse'],'|'));//数组化内容
  1104. }
  1105. else
  1106. {
  1107. $num = array();
  1108. }
  1109. }
  1110. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1111. }
  1112. if(isset($post['transfer']))
  1113. {
  1114. $transfer = $this->input->post('transfer',true);
  1115. $data = $this->transfer->find_all('1=1');
  1116. $list = array();
  1117. foreach ($data as $key=>$value)
  1118. {
  1119. $list[] = array('id'=>$value['id'],'title'=>$value['title']);
  1120. }
  1121. $num = array();
  1122. if($transfer != "null")
  1123. {
  1124. $num = $this->user->read($transfer);//找出内容
  1125. if($num['transfer'])
  1126. {
  1127. $num = explode('|',trim($num['transfer'],'|'));//数组化内容
  1128. }
  1129. else
  1130. {
  1131. $num = array();
  1132. }
  1133. }
  1134. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1135. }
  1136. }
  1137. public function _shopfx()
  1138. {
  1139. $post = $this->input->post(NULL, TRUE);
  1140. if(isset($post['time']))
  1141. {
  1142. $time = $this->input->post('time',true);
  1143. $t = strtotime(date("Ymd",time()+24*3600));//明天0点
  1144. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1145. $sid = '';
  1146. foreach ($shop as $value)
  1147. {
  1148. $sid .= " shop = ".$value['id']." or";
  1149. }
  1150. $sid = " and (".rtrim($sid,'or').")";
  1151. $znum = $this->fullorder->find_count("dtime > '".($t-$time*24*3600)."' and dtime < '".$t."'".$sid);
  1152. $data = array();$list = array();
  1153. $color = array('0'=>'#30546c','1'=>'#61a0a8','2'=>'#c23531','3'=>'#d48265','4'=>'#546570','5'=>'#749f83','6'=>'#bda29a','7'=>'#6e7074','8'=>'#546570');
  1154. $j = 0;
  1155. $zt = array(7=>1,30=>2);
  1156. foreach ($shop as $v)
  1157. {
  1158. $d = $this->fullorder->find_count("shop = '".$v['id']."' and dtime > '".($t-$time*24*3600)."' and dtime < '".$t."' and (state = '207' or state = '216')");
  1159. $wd = $this->allocation->read($zt[$time]);
  1160. $n = json_decode($wd['content'],true);
  1161. $bfb = ($d==0)?0:round(($d / $znum) * 100, 2);
  1162. $data[] = array('value'=>$bfb,'name'=>$v['shopname'].' '.$bfb."%",'itemStyle'=>array('color'=>$color[$j]));
  1163. $n[$v['id']][] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".date("Ymd",time())."' and (state = '207' or state = '216')");
  1164. $t_list = array();
  1165. for($i=0;$i<$time;$i++)
  1166. {
  1167. $t_list[] = date("m-d",time()-($i*24*3600));
  1168. }
  1169. $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).'%');
  1170. $j++;
  1171. }
  1172. $list = (array_reverse($list));
  1173. echo json_encode(array('data'=>($data),'list'=>$list,'t'=>(array_reverse($t_list)),'success'=>true));exit;
  1174. /**
  1175. $time = $this->input->post('time',true);
  1176. $t = strtotime(date("Ymd",time()+24*3600));//明天0点
  1177. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1178. $sid = '';
  1179. foreach ($shop as $value)
  1180. {
  1181. $sid .= " shop = ".$value['id']." or";
  1182. }
  1183. $sid = " and (".rtrim($sid,'or').")";
  1184. $znum = $this->fullorder->find_count("dtime > '".($t-$time*24*3600)."' and dtime < '".$t."'".$sid);
  1185. $data = array();$list = array();
  1186. $color = array('0'=>'#30546c','1'=>'#61a0a8','2'=>'#c23531','3'=>'#d48265','4'=>'#546570','5'=>'#749f83','6'=>'#bda29a','7'=>'#6e7074','8'=>'#546570');
  1187. $j = 0;
  1188. foreach ($shop as $v)
  1189. {
  1190. $d = $this->fullorder->find_count("shop = '".$v['id']."' and dtime > '".($t-$time*24*3600)."' and dtime < '".$t."' and (state = '207' or state = '216')");
  1191. $bfb = ($d==0)?0:round(($d / $znum) * 100, 2);
  1192. $data[] = array('value'=>$bfb,'name'=>$v['shopname'].' '.$bfb."%",'itemStyle'=>array('color'=>$color[$j]));
  1193. $n = array();$t_list = array();
  1194. for($i=0;$i<$time;$i++)
  1195. {
  1196. if($i == 0)
  1197. {
  1198. $s = date("Ymd",time());
  1199. }
  1200. else
  1201. {
  1202. $s = date("Ymd",time()-($i*24*3600));
  1203. }
  1204. $t_list[] = date("m-d",time()-($i*24*3600));
  1205. $n[] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".$s."' and (state = '207' or state = '216')");
  1206. }
  1207. $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).'%');
  1208. $j++;
  1209. }
  1210. $list = (array_reverse($list));
  1211. echo json_encode(array('data'=>($data),'list'=>$list,'t'=>(array_reverse($t_list)),'success'=>true));exit;
  1212. **/
  1213. }
  1214. $this->_Template('phone/p_user_shopfx',$this->data);
  1215. }
  1216. public function _shopfxlist()
  1217. {
  1218. $t = strtotime(date("Ymd",time()));//今天0点
  1219. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1220. $sid = '';
  1221. foreach ($shop as $value)
  1222. {
  1223. $sid .= " shop = ".$value['id']." or";
  1224. }
  1225. $sid = " and (".rtrim($sid,'or').")";
  1226. $zt = array(7,30);
  1227. $this->db->trans_begin();
  1228. foreach ($zt as $key=>$time)
  1229. {
  1230. $data = array();$list = array();
  1231. foreach ($shop as $v)
  1232. {
  1233. $n = array();$t_list = array();
  1234. for($i=1;$i<$time;$i++)
  1235. {
  1236. if($i == 0)
  1237. {
  1238. $s = date("Ymd",time());
  1239. }
  1240. else
  1241. {
  1242. $s = date("Ymd",time()-($i*24*3600));
  1243. }
  1244. $t_list[] = date("m-d",time()-($i*24*3600));
  1245. $n[] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".$s."' and (state = '207' or state = '216')");
  1246. }
  1247. $list[$v['id']] = array_reverse($n);
  1248. }
  1249. $this->allocation->save(array('content'=>json_encode($list)),$key+1);
  1250. }
  1251. if ($this->db->trans_status() === FALSE)
  1252. {
  1253. $this->db->trans_rollback();
  1254. echo 'orver';
  1255. }
  1256. else
  1257. {
  1258. $this->db->trans_commit();
  1259. echo 'ok';
  1260. }
  1261. }
  1262. public function _apple()
  1263. {
  1264. $this->_Template('phone/p_user_apple',$this->data);
  1265. }
  1266. //退出
  1267. public function _tc()
  1268. {
  1269. $this->session->sess_destroy();
  1270. header("Location:/");
  1271. }
  1272. public function _tjadd()
  1273. {
  1274. $pdtime = date('Y-m-d-H',time());
  1275. //if(is_file("./data/tj/".$pdtime.".txt"))
  1276. if(is_file("./data/tj/".$pdtime.".txt"))
  1277. {
  1278. $myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
  1279. $bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
  1280. fclose($myfile);
  1281. $bc = json_decode($bc,true);
  1282. $zzt = array($bc['zzt'][0],$bc['zzt'][1]);
  1283. }
  1284. else
  1285. {
  1286. /** 暂时不需要了
  1287. //柱状图数据
  1288. $i = 0;
  1289. $data = array();$sndata1 = array();$sndata2 = array();$sndata3 = array();
  1290. $sj = array('01','02','03','04','05','06','07','08','09','10','11','12');
  1291. foreach ($sj as $k=>$v)
  1292. {
  1293. $i++;
  1294. $dlz1 = $this->fullorder->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1295. $smt1 = $this->fullordersmt->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1296. $m1 = sprintf("%01.2f",array_sum(array_column($dlz1,'shouldmoney'))+array_sum(array_column($smt1,'shouldmoney')));
  1297. $dlz2 = $this->fullorder->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1298. $smt2 = $this->fullordersmt->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1299. $m2 = sprintf("%01.2f",array_sum(array_column($dlz2,'shouldmoney'))+array_sum(array_column($smt2,'shouldmoney')));
  1300. $dlz3 = $this->fullorder->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1301. $smt3 = $this->fullordersmt->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1302. $m3 = sprintf("%01.2f",array_sum(array_column($dlz3,'shouldmoney'))+array_sum(array_column($smt3,'shouldmoney')));
  1303. $sndata1[$i] = $m3;
  1304. $sndata2[12+$i] = $m2;
  1305. $sndata3[24+$i] = $m1;
  1306. $data[] = array($v,$m1,$m2,$m3);
  1307. }
  1308. $sndata = array_merge($sndata1,$sndata2,$sndata3);
  1309. $zzt = array($data,$sndata);
  1310. //柱状图结束
  1311. **/
  1312. }
  1313. //详情内容
  1314. $dt = 0;
  1315. $user = $this->user->get_api($_SESSION['api']);
  1316. $usp = $user;
  1317. $fgshop = "";$sid = "";
  1318. $user = explode('|',trim($user['shop'],'|'));
  1319. foreach ($user as $value)
  1320. {
  1321. $fgshop .= " shop = ".$value." or";
  1322. $sid .= " id = ".$value." or";
  1323. }
  1324. $tm = strtotime(date("Ymd"),time());
  1325. $usat = $tm;
  1326. //$molist = array('0','1','2d');
  1327. $molist = array('0','1');
  1328. $zqtime = array(259200,345600,691200,2678400,7862400,31622400);
  1329. //time开始
  1330. $zqtdata = array();
  1331. foreach ($molist as $vval)
  1332. {
  1333. $where = "";
  1334. $source = $vval;
  1335. if($source == '2d')
  1336. {
  1337. $where = " and source >= '2'";
  1338. }
  1339. else if($source != '0')
  1340. {
  1341. $where = " and source = '$source'";
  1342. }
  1343. foreach ($zqtime as $value)
  1344. {
  1345. $zdt = $value;
  1346. $k = $zdt;
  1347. $tab = 1;
  1348. //$start = '2018-10-15';
  1349. //$end = '2018-11-26';
  1350. //$tim = strtotime($start);
  1351. //$day = $time/(3600*24);
  1352. if($tab == '1')
  1353. {
  1354. if($zdt >= 691200)
  1355. {
  1356. $k = $usat-$k-$k;
  1357. $j = $usat;
  1358. $n = ($j-$k)/(24*3600);
  1359. }
  1360. else
  1361. {
  1362. $n = 2;
  1363. $usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
  1364. }
  1365. }
  1366. else
  1367. {
  1368. $timedata = explode('|',$zdt);
  1369. $ktime = strtotime($timedata[0]);
  1370. $jtime = strtotime($timedata[1]);
  1371. $ktime = $ktime-($jtime-$ktime);
  1372. $k = $ktime;
  1373. $j = $jtime;
  1374. $n = ($j-$k)/(24*3600);
  1375. $usat = $jtime;
  1376. $tm = $jtime;
  1377. $zdt = $jtime-$ktime;
  1378. }
  1379. $time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();;$ttnum = array();$ymoney = array();$money = array();$dlzmoney = array();$smtmoney=array();$ttmoney=array();
  1380. $dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();
  1381. $dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
  1382. $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'");
  1383. foreach ($ys as $v)
  1384. {
  1385. $shopdata[$v['id']] = array('num'=>0,'money'=>0,'tmoney'=>0,'fdl'=>0,'chl'=>0);
  1386. }
  1387. for($i=1;$i<$n;$i++)
  1388. {
  1389. //近7天时间
  1390. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1391. if($n > 13 && $i > $n/2 || $n < 14)
  1392. {
  1393. $t = $usat-($n*24*60*60)+($i*24*60*60);
  1394. $time[] = date('m-d',$t);
  1395. $ct = strtotime(date('Ymd',$t));
  1396. $ctj = strtotime(date('Ymd',$t+24*3600));
  1397. $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');
  1398. $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');
  1399. $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');
  1400. $ab[] = $dlz;
  1401. //数量及金额开始
  1402. $dlznum[] = count($dlz);
  1403. $smtnum[] = count($smt);
  1404. $ttnum[] = count($smt);
  1405. $dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
  1406. $smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
  1407. $ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
  1408. /**
  1409. //提出退款关闭等信息的实收金额
  1410. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1411. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1412. //提出退款关闭等信息的实收金额
  1413. **/
  1414. //实收金额
  1415. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'budget')));
  1416. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'budget')));
  1417. $ttmss = sprintf("%01.2f",array_sum(array_column($tt,'budget')));
  1418. //实收金额
  1419. //补/退原额
  1420. $dlzbty = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1421. $smtbty = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1422. $ttbty = sprintf("%01.2f",array_sum(array_column($tt,'refundy')));
  1423. //补/退原额
  1424. $dlzmoney[] = $dlzm;
  1425. $smtmoney[] = $smtm;
  1426. $ttmoney[] = $ttm;
  1427. $dlzsl += count($dlz);
  1428. $dlzje += $dlzm;
  1429. $smtsl += count($smt);
  1430. $smtje += $smtm;
  1431. $ttsl += count($tt);
  1432. $ttje += $ttm;
  1433. /**
  1434. //减去的实收金额
  1435. $dlzssje += $dlzm+$dlzmss;
  1436. $smtssje += $smtm+$smtmss;
  1437. **/
  1438. //实收和补/退
  1439. $dlzssje += $dlzmss+$dlzbty;
  1440. $smtssje += $smtmss+$smtbty;
  1441. $ttssje += $ttmss+$ttbty;
  1442. //数量及金额结束
  1443. $sd = array_merge($dlz,$smt,$tt);
  1444. foreach ($sd as $v)
  1445. {
  1446. if(isset($shopdata[$v['shop']]))
  1447. {
  1448. $shopdata[$v['shop']]['num'] += 1;
  1449. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  1450. $shopdata[$v['shop']]['tmoney'] += $v['budget']+$v['refundy'];
  1451. }
  1452. }
  1453. }
  1454. else if ($n > 13 && $i <= $n/2)
  1455. {
  1456. $t = $usat-($n*24*60*60)+($i*24*60*60);
  1457. $timeold[] = date('m-d',$t);
  1458. $ct = strtotime(date('Ymd',$t));
  1459. $ctj = strtotime(date('Ymd',$t+24*3600));
  1460. $dlz = $this->fullorder->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  1461. $smt = $this->fullordersmt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  1462. $tt = $this->fullordertt->find_all("state != 217 and (".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  1463. //数量及金额开始
  1464. $dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
  1465. $smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
  1466. $ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
  1467. $dlzmoneyb[] = $dlzm;
  1468. $smtmoneyb[] = $smtm;
  1469. $ttmoneyb[] = $ttm;
  1470. //数量及金额结束
  1471. }
  1472. }
  1473. foreach ($shopdata as $k=>$v)
  1474. {
  1475. $sn = $this->shop->read($k);
  1476. $shopdata[$k]['money'] = sprintf("%01.2f",$v['money']).'$';
  1477. $shopdata[$k]['tmoney'] = sprintf("%01.2f",$v['tmoney']).'$';
  1478. $shopdata[$k]['bl'] = ($v['num']=='0')?'0$':round($v['money']/$v['num'],2).'$';
  1479. $shopdata[$k]['name'] = $sn['shopname'];
  1480. $shopdata[$k]['b'] = $sn['type'];
  1481. $shopdata[$k]['id'] = $sn['id'];
  1482. }
  1483. $shopdata = array_values($shopdata);
  1484. //$sycp=array();
  1485. /**
  1486. //根据所选时间产品排行开始
  1487. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1488. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1489. **/
  1490. /**
  1491. //昨日产品排行开始
  1492. $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');
  1493. $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');
  1494. $rows = array_merge($dlzlist,$smtlist);
  1495. foreach ($rows as $v)
  1496. {
  1497. $number = explode('|',trim($v['whlabel'],'|'));
  1498. $or = explode(';',trim($v['fpdata'],';'));
  1499. $i=0;
  1500. foreach ($or as $va)
  1501. {
  1502. $ord = explode('|',$va);
  1503. $orod = explode(',',$ord[0]);
  1504. $numberod = explode('-',$number[$i]);
  1505. if(!isset($orod[1]))
  1506. {
  1507. continue;
  1508. }
  1509. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  1510. {
  1511. //$sycp[$orod[1]][0] += 1;//统计多少单
  1512. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  1513. $sycp[$orod[1]][1] += 0;//价格
  1514. }
  1515. else
  1516. {
  1517. if(isset($numberod[1]))
  1518. {
  1519. $typeclass = $this->typeclass->read($orod['0']);
  1520. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  1521. }
  1522. }
  1523. $i++;
  1524. }
  1525. }
  1526. arsort($sycp);
  1527. $sycp = array_values($sycp);
  1528. $sycp = array_slice($sycp,0,10);
  1529. //产品排行结束
  1530. **/
  1531. //当时实时数据结束
  1532. $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昨日产品数据
  1533. }
  1534. }
  1535. //time结束
  1536. //zhcx开始
  1537. $zhcxdata = array();
  1538. foreach ($molist as $vval)
  1539. {
  1540. $where = "";
  1541. $source = $vval;
  1542. if($source == '2d')
  1543. {
  1544. $where = " and source >= '2'";
  1545. }
  1546. else if($source != '0')
  1547. {
  1548. $where = " and source = '$source'";
  1549. }
  1550. foreach ($zqtime as $value)
  1551. {
  1552. $zdt = $value;
  1553. $k = $zdt;
  1554. $tab = 1;
  1555. //$customer = $this->customer->find_all("shop !=''",'num,zhcx');
  1556. //$customerkey = array_column($customer,'zhcx');
  1557. //$customer= array_combine($customerkey,$customer);
  1558. //$customersmt = $this->customersmt->find_all("shop !=''",'num,zhcx');
  1559. //$customersmtkey = array_column($customersmt,'zhcx');
  1560. //$customersmt= array_combine($customersmtkey,$customersmt);
  1561. //$customertt = $this->customertt->find_all("shop !=''",'num,zhcx');
  1562. //$customerttkey = array_column($customertt,'zhcx');
  1563. //$customertt= array_combine($customerttkey,$customertt);
  1564. if($tab == '1')
  1565. {
  1566. if($zdt >= 691200)
  1567. {
  1568. $k = $usat-$k-$k;
  1569. $j = $usat;
  1570. $n = ($j-$k)/(24*3600);
  1571. }
  1572. else
  1573. {
  1574. $n = 2;
  1575. $usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
  1576. }
  1577. }
  1578. else
  1579. {
  1580. $timedata = explode('|',$zdt);
  1581. $ktime = strtotime($timedata[0]);
  1582. $jtime = strtotime($timedata[1]);
  1583. $ktime = $ktime-($jtime-$ktime);
  1584. $k = $ktime;
  1585. $j = $jtime;
  1586. $n = ($j-$k)/(24*3600);
  1587. $usat = $jtime;
  1588. }
  1589. $time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();$ttnum = array();$ymoney = array();$money = array();
  1590. $dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();$zkh = array();
  1591. $dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
  1592. $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'");
  1593. foreach ($ys as $v)
  1594. {
  1595. $shopdata[$v['id']] = array('id'=>$v['id'],'b'=>$v['type'],'fdl'=>0,'chl'=>0,'num'=>0,'fgl'=>0);
  1596. $zkh[$v['id']] = array();
  1597. }
  1598. for($i=1;$i<$n;$i++)
  1599. {
  1600. if($n > 13 && $i > $n/2 || $n < 14)
  1601. {
  1602. $t = $usat-($n*24*60*60)+($i*24*60*60);
  1603. $time[] = date('m-d',$t);
  1604. $ct = strtotime(date('Ymd',$t));
  1605. $ctj = strtotime(date('Ymd',$t+24*3600));
  1606. $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');
  1607. $dlzemail = $this->fullorder->find_all("dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'shop,email');
  1608. $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');
  1609. $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');
  1610. //数量及金额结束
  1611. $sd = array_merge($dlz,$smt,$tt);
  1612. $fgldata = array();
  1613. foreach ($sd as $v)
  1614. {
  1615. /**
  1616. $array = array(
  1617. 0 => array('email' => 123, 'id' => 1),
  1618. 1 => array('email' => 321, 'id' => 2),
  1619. 2 => array('email' => 123, 'id' => 3),
  1620. 3 => array('email' => 123, 'id' => 3)
  1621. );
  1622. // 使用 array_filter 筛选满足多个条件的元素
  1623. $result = array_filter($array, function($item) {
  1624. return $item['email'] === 123 && $item['id'] === 3;
  1625. });
  1626. // 计算满足条件的数量
  1627. $count = count($result);
  1628. echo "满足条件 (email = 123 且 id = 3) 的数量是:$count";
  1629. **/
  1630. /** 独立站查customer方法 弃用
  1631. if(isset($v['email']))
  1632. {
  1633. if(!isset($fgldata[$v['shop'].'-'.$v['email']]))
  1634. {
  1635. $fgldata[$v['shop'].'-'.$v['email']] = 0;
  1636. }
  1637. else
  1638. {
  1639. $fgldata[$v['shop'].'-'.$v['email']] += 1;
  1640. }
  1641. $zkh[$v['shop']][$v['email']] = array();
  1642. }
  1643. **/
  1644. /** 速卖通
  1645. else
  1646. {
  1647. if(!isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1648. {
  1649. $fgldata[$v['shop'].'-'.$v['userid']] = 0;
  1650. }
  1651. else
  1652. {
  1653. $fgldata[$v['shop'].'-'.$v['userid']] += 1;
  1654. }
  1655. $zkh[$v['shop']][$v['userid']] = array();
  1656. }
  1657. **/
  1658. }
  1659. foreach ($sd as $v)
  1660. {
  1661. //避免由于作用域引起的问题
  1662. $tmp_v = $v;
  1663. $fdl_result = array_filter($dlz, function($item) use($tmp_v)
  1664. {
  1665. if(!isset($item['email'])||!isset($tmp_v['email'])||!isset($item['shop'])){
  1666. return false;
  1667. }else{
  1668. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1669. }
  1670. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1671. });
  1672. $fdl = count($fdl_result) > 1?1:0;//返单
  1673. $chl_result = array_filter($dlz, function($item) use($tmp_v)
  1674. {
  1675. if(!isset($item['email'])||!isset($tmp_v['email'])||!isset($item['shop'])){
  1676. return false;
  1677. }else{
  1678. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1679. }
  1680. //return $item['email'] === $tmp_v['email'] && $item['shop'] !== $tmp_v['email'];
  1681. });
  1682. $chl = count($chl_result) > 1?1:0;//重合
  1683. $fgl_result = array_filter($dlzemail, function($item) use($tmp_v)
  1684. {
  1685. if(!isset($item['email'])||!isset($tmp_v['email'])||!isset($item['shop'])){
  1686. return false;
  1687. }else{
  1688. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1689. }
  1690. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1691. });
  1692. $fgl = count($fgl_result) > 1?1:0;//复购
  1693. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl']+$fdl;
  1694. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl']+$chl;
  1695. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl']+$fgl;
  1696. $shopdata[$v['shop']]['num'] += 1;
  1697. /**
  1698. $chl = 0;
  1699. if(isset($shopdata[$v['shop']]))
  1700. {
  1701. if(isset($v['email']))
  1702. {
  1703. if(isset($customer[$v['shop'].'-'.$v['email']]['num']))
  1704. {
  1705. $fdl = $customer[$v['shop'].'-'.$v['email']]['num']>1?1:0;
  1706. }
  1707. else
  1708. {
  1709. $fdl = 0;
  1710. }
  1711. foreach ($ys as $vv)
  1712. {
  1713. if($vv['id'] != $v['shop'] && isset($customer[$vv['id'].'-'.$v['email']]))
  1714. {
  1715. $chl = 1;
  1716. }
  1717. }
  1718. if(isset($fgldata[$v['shop'].'-'.$v['email']]))
  1719. {
  1720. $fgl = $fgldata[$v['shop'].'-'.$v['email']]>0?1:0;
  1721. }
  1722. else
  1723. {
  1724. $fgl = 0;
  1725. }
  1726. }
  1727. else
  1728. {
  1729. if(isset($customersmt[$v['shop'].'-'.$v['userid']]['num']))
  1730. {
  1731. $fdl = $customersmt[$v['shop'].'-'.$v['userid']]['num']>1?1:0;
  1732. }
  1733. else
  1734. {
  1735. $fdl = 0;
  1736. }
  1737. foreach ($ys as $vv)
  1738. {
  1739. if($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'].'-'.$v['userid']]))
  1740. {
  1741. $chl = 1;
  1742. }
  1743. }
  1744. if(isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1745. {
  1746. $fgl = $fgldata[$v['shop'].'-'.$v['userid']]>0?1:0;
  1747. }
  1748. else
  1749. {
  1750. $fgl = 0;
  1751. }
  1752. }
  1753. }
  1754. **/
  1755. }
  1756. }
  1757. }
  1758. foreach ($shopdata as $k=>$v)
  1759. {
  1760. $shopdata[$k]['fdl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['fdl']/$v['num']*100)).'%';
  1761. $shopdata[$k]['chl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['chl']/$v['num']*100)).'%';
  1762. $shopdata[$k]['fgl'] = count($zkh[$v['id']])=='0'?0:sprintf("%01.2f",($v['fgl']/count($zkh[$v['id']])*100)).'%';
  1763. }
  1764. $shopdata = array_values($shopdata);
  1765. $zhcxdata[$vval][$value] = array('shopdata'=>$shopdata,'success'=>true);
  1766. }
  1767. }
  1768. //zhcx结束
  1769. $myfile = fopen("./data/tj/".$pdtime.".txt", "w") or die("Unable to open file!");
  1770. $txt = json_encode(array('zzt'=>$zzt,'tj'=>$zqtdata,'zhcx'=>$zhcxdata));
  1771. fwrite($myfile, $txt);
  1772. fclose($myfile);
  1773. echo 1;
  1774. }
  1775. }