User.php 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  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. $dsmt = array();
  365. $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');
  366. $d = array_merge($dlz,$dsmt);
  367. $num[] = count($d);
  368. $ymoney[] = sprintf("%01.2f",array_sum(array_column($d,'budget')));
  369. $money[] = sprintf("%01.2f",array_sum(array_column($d,'shouldmoney')));
  370. }
  371. $snuz = $this->fullorder->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
  372. $snuz += $this->fullordersmt->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
  373. $lnuz = $this->fullorder->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待出库
  374. $lnuz += $this->fullordersmt->find_count('dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待出库
  375. $snu = $this->fullorder->find_count('reviewtime = 0 and dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
  376. $snu += $this->fullordersmt->find_count('reviewtime = 0 and dtime >='.($k+24*3600).' and dtime <='.$j.' and ('.rtrim($fgshop,'or').')');//待处理
  377. $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').')');//待出库
  378. $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').')');//待出库
  379. 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;
  380. }
  381. $this->_Template('user_default',$this->data);
  382. }
  383. public function _zzt()
  384. {
  385. if(isset($_SESSION['api']))
  386. {
  387. $user = $this->user->get_api($_SESSION['api']);
  388. $usp = $user;
  389. $fgshop = "";$sid = "";
  390. $user = explode('|',trim($user['shop'],'|'));
  391. foreach ($user as $value)
  392. {
  393. $fgshop .= " shop = ".$value." or";
  394. $sid .= " id = ".$value." or";
  395. }
  396. }
  397. $data = array();$sntime= array();$sndata1 = array();$sndata2 = array();$sndata3 = array();
  398. $sj = array('01','02','03','04','05','06','07','08','09','10','11','12');
  399. for($i=0;$i<3;$i++)
  400. {
  401. foreach ($sj as $v)
  402. {
  403. $sntime[] = date("Y")-2+$i.'-'.$v;
  404. }
  405. }
  406. $pdtime = date('Y-m-d-H',time());
  407. if(is_file("./data/tj/".$pdtime.".txt"))
  408. {
  409. $myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
  410. $bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
  411. fclose($myfile);
  412. $bc = json_decode($bc,true);
  413. $data = $bc['zzt'][0];
  414. $sndata = $bc['zzt'][1];
  415. }
  416. else
  417. {
  418. $i = 0;
  419. foreach ($sj as $k=>$v)
  420. {
  421. $i++;
  422. $dlz1 = $this->fullorder->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  423. $smt1 = $this->fullordersmt->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  424. $m1 = sprintf("%01.2f",array_sum(array_column($dlz1,'shouldmoney'))+array_sum(array_column($smt1,'shouldmoney')));
  425. $dlz2 = $this->fullorder->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  426. $smt2 = $this->fullordersmt->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  427. $m2 = sprintf("%01.2f",array_sum(array_column($dlz2,'shouldmoney'))+array_sum(array_column($smt2,'shouldmoney')));
  428. $dlz3 = $this->fullorder->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  429. $smt3 = $this->fullordersmt->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  430. $m3 = sprintf("%01.2f",array_sum(array_column($dlz3,'shouldmoney'))+array_sum(array_column($smt3,'shouldmoney')));
  431. $sndata1[$i] = $m3;
  432. $sndata2[12+$i] = $m2;
  433. $sndata3[24+$i] = $m1;
  434. $data[] = array($v,$m1,$m2,$m3);
  435. }
  436. }
  437. $time = array(date("Y"),(date("Y")-1),(date("Y")-2));
  438. echo json_encode(array('data'=>$data,'time'=>$time,'sndata'=>$sndata,'sntime'=>$sntime,'success'=>true));exit;
  439. }
  440. //默认页
  441. public function _statistics()
  442. {
  443. /**
  444. $order = $this->order->get_w();
  445. $order = count($order);//查询订单未处理数量
  446. $message = $this->message->get_w();
  447. $message = count($message);//查询留言未处理数量
  448. $this->_Template('default',$this->data);
  449. **/
  450. //date_default_timezone_set("Etc/GMT+8");
  451. $dt = 0;
  452. if(isset($_SESSION['api']))
  453. {
  454. $user = $this->user->get_api($_SESSION['api']);
  455. $usp = $user;
  456. $fgshop = "";$sid = "";
  457. $user = explode('|',trim($user['shop'],'|'));
  458. foreach ($user as $value)
  459. {
  460. 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')
  461. {
  462. $fgshop .= " shop = ".$value." or";
  463. }
  464. $sid .= " id = ".$value." or";
  465. }
  466. }
  467. $post = $this->input->post(NULL, TRUE);
  468. $source = $this->input->post('source',true);
  469. $where = "";
  470. if($source)
  471. {
  472. if($source == '2d')
  473. {
  474. $where = " and source >= '2'";
  475. }
  476. else
  477. {
  478. $where = " and source = '$source'";
  479. }
  480. }
  481. $tm = strtotime(date("Ymd"),time());
  482. $usat = $tm;
  483. if(isset($post['zhcx']))
  484. {
  485. $zdt = $this->input->post('time',true);
  486. $k = $zdt;
  487. $tab = $this->input->post('tab',true);
  488. $pdtime = date('Y-m-d-H',time());
  489. if(is_file("./data/tj/".$pdtime.".txt") && $tab == 1 && $zdt > 172800)
  490. {
  491. $myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
  492. $bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
  493. fclose($myfile);
  494. $bc = json_decode($bc,true);
  495. echo json_encode($bc['zhcx'][$source][$zdt]);exit;
  496. }
  497. else
  498. {
  499. $customer = $this->customer->find_all("shop !=''",'num,zhcx');
  500. $customerkey = array_column($customer,'zhcx');
  501. $customer= array_combine($customerkey,$customer);
  502. $customersmt = $this->customersmt->find_all("shop !=''",'num,zhcx');
  503. $customersmtkey = array_column($customersmt,'zhcx');
  504. $customersmt= array_combine($customersmtkey,$customersmt);
  505. //$start = '2018-10-15';
  506. //$end = '2018-11-26';
  507. //$tim = strtotime($start);
  508. //$day = $time/(3600*24);
  509. if($tab == '1')
  510. {
  511. if($zdt >= 691200)
  512. {
  513. $k = $usat-$k-$k;
  514. $j = $usat;
  515. $n = ($j-$k)/(24*3600);
  516. }
  517. else
  518. {
  519. $n = 2;
  520. $usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
  521. }
  522. }
  523. else
  524. {
  525. $timedata = explode('|',$zdt);
  526. $ktime = strtotime($timedata[0]);
  527. $jtime = strtotime($timedata[1]);
  528. $ktime = $ktime-($jtime-$ktime);
  529. $k = $ktime;
  530. $j = $jtime;
  531. $n = ($j-$k)/(24*3600);
  532. $usat = $jtime;
  533. }
  534. $time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();$ymoney = array();$money = array();
  535. $dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();$zkh = array();
  536. $dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
  537. $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'");
  538. foreach ($ys as $v)
  539. {
  540. $shopdata[$v['id']] = array('id'=>$v['id'],'b'=>$v['type'],'fdl'=>0,'chl'=>0,'num'=>0,'fgl'=>0);
  541. $zkh[$v['id']] = array();
  542. }
  543. for($i=1;$i<$n;$i++)
  544. {
  545. if($n > 13 && $i > $n/2 || $n < 14)
  546. {
  547. $t = $usat-($n*24*60*60)+($i*24*60*60);
  548. $time[] = date('m-d',$t);
  549. $ct = strtotime(date('Ymd',$t));
  550. $ctj = strtotime(date('Ymd',$t+24*3600));
  551. $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');
  552. $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');
  553. $tt = $this->fullordertt->find_all("dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'shop,email');
  554. //数量及金额结束
  555. $sd = array_merge($dlz,$smt,$tt);
  556. $fgldata = array();
  557. foreach ($sd as $v)
  558. {
  559. if(isset($v['email']))
  560. {
  561. if(!isset($fgldata[$v['shop'].'-'.$v['email']]))
  562. {
  563. $fgldata[$v['shop'].'-'.$v['email']] = 0;
  564. }
  565. else
  566. {
  567. $fgldata[$v['shop'].'-'.$v['email']] += 1;
  568. }
  569. $zkh[$v['shop']][$v['email']] = array();
  570. }
  571. else
  572. {
  573. if(!isset($fgldata[$v['shop'].'-'.$v['userid']]))
  574. {
  575. $fgldata[$v['shop'].'-'.$v['userid']] = 0;
  576. }
  577. else
  578. {
  579. $fgldata[$v['shop'].'-'.$v['userid']] += 1;
  580. }
  581. $zkh[$v['shop']][$v['userid']] = array();
  582. }
  583. }
  584. foreach ($sd as $v)
  585. {
  586. $chl = 0;
  587. if(isset($shopdata[$v['shop']]))
  588. {
  589. if(isset($v['email']))
  590. {
  591. if(isset($customer[$v['shop'].'-'.$v['email']]['num']))
  592. {
  593. $fdl = $customer[$v['shop'].'-'.$v['email']]['num']>1?1:0;
  594. }
  595. else
  596. {
  597. $fdl = 0;
  598. }
  599. foreach ($ys as $vv)
  600. {
  601. if($vv['id'] != $v['shop'] && isset($customer[$vv['id'].'-'.$v['email']]))
  602. {
  603. $chl = 1;
  604. }
  605. }
  606. if(isset($fgldata[$v['shop'].'-'.$v['email']]))
  607. {
  608. $fgl = $fgldata[$v['shop'].'-'.$v['email']]>0?1:0;
  609. }
  610. else
  611. {
  612. $fgl = 0;
  613. }
  614. }
  615. else
  616. {
  617. if(isset($customersmt[$v['shop'].'-'.$v['userid']]['num']))
  618. {
  619. $fdl = $customersmt[$v['shop'].'-'.$v['userid']]['num']>1?1:0;
  620. }
  621. else
  622. {
  623. $fdl = 0;
  624. }
  625. foreach ($ys as $vv)
  626. {
  627. if($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'].'-'.$v['userid']]))
  628. {
  629. $chl = 1;
  630. }
  631. }
  632. if(isset($fgldata[$v['shop'].'-'.$v['userid']]))
  633. {
  634. $fgl = $fgldata[$v['shop'].'-'.$v['userid']]>0?1:0;
  635. }
  636. else
  637. {
  638. $fgl = 0;
  639. }
  640. }
  641. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl']+$fdl;
  642. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl']+$chl;
  643. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl']+$fgl;
  644. $shopdata[$v['shop']]['num'] += 1;
  645. }
  646. }
  647. }
  648. }
  649. foreach ($shopdata as $k=>$v)
  650. {
  651. $shopdata[$k]['fdl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['fdl']/$v['num']*100)).'%';
  652. $shopdata[$k]['chl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['chl']/$v['num']*100)).'%';
  653. $shopdata[$k]['fgl'] = count($zkh[$v['id']])=='0'?0:sprintf("%01.2f",($v['fgl']/count($zkh[$v['id']])*100)).'%';
  654. }
  655. $shopdata = array_values($shopdata);
  656. echo @json_encode(array('shopdata'=>$shopdata,'success'=>true));exit;
  657. }
  658. }
  659. if(isset($post['time']))
  660. {
  661. $zdt = $this->input->post('time',true);
  662. $k = $zdt;
  663. $tab = $this->input->post('tab',true);
  664. $pdtime = date('Y-m-d-H',time());
  665. if(is_file("./data/tj/".$pdtime.".txt") && $tab == 1 && $zdt > 172800)//前端改店内需要修改zdt 172800
  666. {
  667. $myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
  668. $bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
  669. fclose($myfile);
  670. $bc = json_decode($bc,true);
  671. echo json_encode($bc['tj'][$source][$zdt]);exit;
  672. }
  673. else
  674. {
  675. //$start = '2018-10-15';
  676. //$end = '2018-11-26';
  677. //$tim = strtotime($start);
  678. //$day = $time/(3600*24);
  679. if($tab == '1')
  680. {
  681. if($zdt >= 691200)
  682. {
  683. $k = $usat-$k-$k;
  684. $j = $usat;
  685. $n = ($j-$k)/(24*3600);
  686. }
  687. else
  688. {
  689. $n = 2;
  690. $usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
  691. }
  692. }
  693. else
  694. {
  695. $timedata = explode('|',$zdt);
  696. $ktime = strtotime($timedata[0]);
  697. $jtime = strtotime($timedata[1]);
  698. $ktime = $ktime-($jtime-$ktime);
  699. $k = $ktime;
  700. $j = $jtime;
  701. $n = ($j-$k)/(24*3600);
  702. $usat = $jtime;
  703. $tm = $jtime;
  704. $zdt = $jtime-$ktime;
  705. }
  706. $time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();$ymoney = array();$money = array();
  707. $dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();$zkh = array();
  708. $dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
  709. $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'");
  710. foreach ($ys as $v)
  711. {
  712. $shopdata[$v['id']] = array('num'=>0,'money'=>0,'tmoney'=>0,'fdl'=>0,'chl'=>0);
  713. }
  714. for($i=1;$i<$n;$i++)
  715. {
  716. //近7天时间
  717. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  718. if($n > 13 && $i > $n/2 || $n < 14)
  719. {
  720. $t = $usat-($n*24*60*60)+($i*24*60*60);
  721. $time[] = date('m-d',$t);
  722. $ct = strtotime(date('Ymd',$t));
  723. $ctj = strtotime(date('Ymd',$t+24*3600));
  724. $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');
  725. $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');
  726. $tt = $this->fullordertt->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');
  727. $ab[] = $dlz;
  728. //数量及金额开始
  729. $dlznum[] = count($dlz);
  730. $smtnum[] = count($smt);
  731. $ttnum[] = count($smt);
  732. $dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
  733. $smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
  734. $ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
  735. /**
  736. //提出退款关闭等信息的实收金额
  737. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  738. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  739. //提出退款关闭等信息的实收金额
  740. **/
  741. //实收金额
  742. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'budget')));
  743. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'budget')));
  744. $ttmss = sprintf("%01.2f",array_sum(array_column($tt,'budget')));
  745. //实收金额
  746. //补/退原额
  747. $dlzbty = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  748. $smtbty = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  749. $ttbty = sprintf("%01.2f",array_sum(array_column($tt,'refundy')));
  750. //补/退原额
  751. $dlzmoney[] = $dlzm;
  752. $smtmoney[] = $smtm;
  753. $ttmoney[] = $ttm;
  754. $dlzsl += count($dlz);
  755. $dlzje += $dlzm;
  756. $smtsl += count($smt);
  757. $smtje += $smtm;
  758. $ttsl += count($tt);
  759. $ttje += $ttm;
  760. /**
  761. //减去的实收金额
  762. $dlzssje += $dlzm+$dlzmss;
  763. $smtssje += $smtm+$smtmss;
  764. **/
  765. //实收和补/退
  766. $dlzssje += $dlzmss+$dlzbty;
  767. $smtssje += $smtmss+$smtbty;
  768. $ttssje += $ttmss+$ttbty;
  769. //数量及金额结束
  770. $sd = array_merge($dlz,$smt,$tt);
  771. foreach ($sd as $v)
  772. {
  773. if(isset($shopdata[$v['shop']]))
  774. {
  775. $shopdata[$v['shop']]['num'] += 1;
  776. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  777. $shopdata[$v['shop']]['tmoney'] += $v['budget']+$v['refundy'];
  778. }
  779. }
  780. }
  781. else if ($n > 13 && $i <= $n/2)
  782. {
  783. $t = $usat-($n*24*60*60)+($i*24*60*60);
  784. $timeold[] = date('m-d',$t);
  785. $ct = strtotime(date('Ymd',$t));
  786. $ctj = strtotime(date('Ymd',$t+24*3600));
  787. $dlz = $this->fullorder->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  788. $smt = $this->fullordersmt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  789. $tt = $this->fullordertt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  790. //数量及金额开始
  791. $dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
  792. $smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
  793. $ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
  794. $dlzmoneyb[] = $dlzm;
  795. $smtmoneyb[] = $smtm;
  796. $ttmoneyb[] = $ttm;
  797. //数量及金额结束
  798. }
  799. }
  800. foreach ($shopdata as $k=>$v)
  801. {
  802. $sn = $this->shop->read($k);
  803. $shopdata[$k]['money'] = sprintf("%01.2f",$v['money']).'$';
  804. $shopdata[$k]['tmoney'] = sprintf("%01.2f",$v['tmoney']).'$';
  805. $shopdata[$k]['bl'] = ($v['num']=='0')?'0$':round($v['money']/$v['num'],2).'$';
  806. $shopdata[$k]['name'] = $sn['shopname'];
  807. $shopdata[$k]['b'] = $sn['type'];
  808. $shopdata[$k]['id'] = $sn['id'];
  809. }
  810. $shopdata = array_values($shopdata);
  811. //$sycp=array();
  812. /**
  813. //根据所选时间产品排行开始
  814. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  815. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  816. **/
  817. /**
  818. //昨日产品排行开始
  819. $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');
  820. $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');
  821. $rows = array_merge($dlzlist,$smtlist);
  822. foreach ($rows as $v)
  823. {
  824. $number = explode('|',trim($v['whlabel'],'|'));
  825. $or = explode(';',trim($v['fpdata'],';'));
  826. $i=0;
  827. foreach ($or as $va)
  828. {
  829. $ord = explode('|',$va);
  830. $orod = explode(',',$ord[0]);
  831. $numberod = explode('-',$number[$i]);
  832. if(!isset($orod[1]))
  833. {
  834. continue;
  835. }
  836. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  837. {
  838. //$sycp[$orod[1]][0] += 1;//统计多少单
  839. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  840. $sycp[$orod[1]][1] += 0;//价格
  841. }
  842. else
  843. {
  844. if(isset($numberod[1]))
  845. {
  846. $typeclass = $this->typeclass->read($orod['0']);
  847. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  848. }
  849. }
  850. $i++;
  851. }
  852. }
  853. arsort($sycp);
  854. $sycp = array_values($sycp);
  855. $sycp = array_slice($sycp,0,10);
  856. //产品排行结束
  857. **/
  858. //当时实时数据结束
  859. 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昨日产品数据
  860. }
  861. }
  862. if(isset($post['sstime']))
  863. {
  864. $shop = $this->input->post('shop',true);
  865. $zdtime = $usat;
  866. //当时实时数据开始
  867. if(!$shop)
  868. {
  869. $sssl = $this->fullorder->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$zdtime." and dtime <= ".strtotime(date('Ymd',$usat+24*3600)).$where,'budget,shouldmoney');
  870. $ssje = $this->fullordersmt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$zdtime." and dtime <= ".strtotime(date('Ymd',$usat+24*3600)).$where,'budget,shouldmoney');
  871. $tje = $this->fullordertt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$zdtime." and dtime <= ".strtotime(date('Ymd',$usat+24*3600)).$where,'budget,shouldmoney');
  872. $sssldlz = count($sssl);
  873. $ssslsmt = count($ssje);
  874. $sssltt = count($tje);
  875. $ssjedlz = sprintf("%01.2f",array_sum(array_column($sssl,'budget')));
  876. $ssjesmt = sprintf("%01.2f",array_sum(array_column($ssje,'budget')));
  877. $ssjett= sprintf("%01.2f",array_sum(array_column($tje,'budget')));
  878. $sssl = $sssldlz+$ssslsmt+$sssltt;
  879. $ssje = $ssjedlz+$ssjesmt+$ssjett;
  880. }
  881. else
  882. {
  883. $sp = $this->shop->read($shop);
  884. $fu = ($sp['type']=='269')?'fullorder':'fullordersmt';
  885. $ss = $this->$fu->find_all("dtime >= ".$zdtime." and dtime <= ".strtotime(date('Ymd',$usat+24*3600))." and shop = '".$shop."'",'budget,shouldmoney');
  886. $sssl = count($ss);
  887. $ssje = sprintf("%01.2f",array_sum(array_column($ss,'budget')));
  888. }
  889. echo @json_encode(array('sstime'=>date('m-d H:i',time()),'sssl'=>$sssl,'ssje'=>sprintf("%.2f",$ssje),'success'=>true));exit;
  890. }
  891. //店铺产品详情
  892. if(isset($post['id']))
  893. {
  894. $tm += 24*3600;
  895. $gshtime = date('Y-m-d 0:0:0',time());
  896. $gshtime = strtotime($gshtime)+24*60*60;
  897. $dpxq=array();
  898. $id = $this->input->post('id',true);
  899. $xqtime = $this->input->post('xqtime',true);
  900. $xqshop = $this->shop->read($id);
  901. if($xqshop['type']=="269")
  902. {
  903. $sid = 'fullorder';
  904. }
  905. else if($xqshop['type']=="270")
  906. {
  907. $sid = 'fullordersmt';
  908. }
  909. else if($xqshop['type']=="1514")
  910. {
  911. $sid = 'fullordertt';
  912. }
  913. if($xqtime > 345600)
  914. {
  915. $rows = $this->$sid->find_all("shop = '".$id."' and dtime >= '".($gshtime-$xqtime)."' and dtime <= '".($gshtime+24*60*60)."'",'whlabel,fpdata,number');
  916. }
  917. else
  918. {
  919. $rows = $this->$sid->find_all("shop = '".$id."' and dtime >= '".($gshtime-$xqtime)."' and dtime <= '".($gshtime+24*60*60-$xqtime)."'",'whlabel,fpdata,number');
  920. }
  921. foreach ($rows as $v)
  922. {
  923. $or = explode('|',ltrim($v['whlabel'],'|'));
  924. for($i=0;$i<count($or);$i++)
  925. {
  926. $orod = explode('-',$or[$i]);
  927. if($orod[0] == '')
  928. {
  929. continue;
  930. }
  931. if(isset($dpxq[$orod[0]]))
  932. {
  933. $dpxq[$orod[0]][0] += $orod[1];//统计多少条
  934. //$dpxq[$orod[0]][0] += 1;//统计多少单
  935. $dpxq[$orod[0]][1] .= $v['number'].';';//价格
  936. }
  937. else
  938. {
  939. $oo = explode(';',rtrim($v['fpdata'],';'));
  940. @$ro = explode('|',$oo[$i]);
  941. if(isset($ro[1]))
  942. {
  943. $dpxq[$orod[0]] = array($orod[1],$v['number'].';',$ro[1]);//统计多少条
  944. //$dpxq[$orod[0]] = array(1,0,$ro[1]);//统计多少单
  945. }
  946. }
  947. }
  948. }
  949. $dpxq = array_values($dpxq);
  950. arsort($dpxq);
  951. $dpxq = array_slice($dpxq,0,9999);
  952. echo @json_encode(array('dpxq'=>$dpxq,'success'=>true));exit;
  953. }
  954. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  955. $this->data['wlshop'] = $wlshop;
  956. $dr = $usat;
  957. $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));
  958. $this->_Template('phone/p_user_statistics',$this->data);
  959. }
  960. /**
  961. public function super_unique($array,$key)//多维删除重复
  962. {
  963. $temp_array = array();
  964. foreach ($array as &$v) {
  965. if (!isset($temp_array[$v[$key]]))
  966. {
  967. $temp_array[$v[$key]] =& $v;
  968. }
  969. }
  970. $array = array_values($temp_array);
  971. return $array;
  972. }
  973. **/
  974. public function _usatime()
  975. {
  976. date_default_timezone_set("Etc/GMT+8");
  977. return time();
  978. }
  979. //数据
  980. public function _rows()
  981. {
  982. $post = $this->input->post(NULL, TRUE);
  983. if(isset($post['shop']))
  984. {
  985. $shop = $this->input->post('shop',true);
  986. $data = $this->shop->find_all('1=1');
  987. $list = array();
  988. foreach ($data as $key=>$value)
  989. {
  990. $t = $this->typeclass->read($value['type']);
  991. $list[] = array('id'=>$value['id'],'title'=>$value['shopname'].' - '.$t['title']);
  992. }
  993. $num = array();
  994. if($shop != "null")
  995. {
  996. $num = $this->user->read($shop);//找出内容
  997. if($num['shop'])
  998. {
  999. $num = explode('|',trim($num['shop'],'|'));//数组化内容
  1000. }
  1001. else
  1002. {
  1003. $num = array();
  1004. }
  1005. }
  1006. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1007. }
  1008. if(isset($post['excelshop']))
  1009. {
  1010. $excelshop = $this->input->post('excelshop',true);
  1011. $data = $this->shop->find_all('1=1');
  1012. $list = array();
  1013. foreach ($data as $key=>$value)
  1014. {
  1015. $t = $this->typeclass->read($value['type']);
  1016. $list[] = array('id'=>$value['id'],'title'=>$value['shopname'].' - '.$t['title']);
  1017. }
  1018. $num = array();
  1019. if($excelshop != "null")
  1020. {
  1021. $num = $this->user->read($excelshop);//找出内容
  1022. if($num['excelshop'])
  1023. {
  1024. $num = explode('|',trim($num['excelshop'],'|'));//数组化内容
  1025. }
  1026. else
  1027. {
  1028. $num = array();
  1029. }
  1030. }
  1031. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1032. }
  1033. if(isset($post['purchase']))
  1034. {
  1035. $purchase = $this->input->post('purchase',true);
  1036. $data = $this->purchase->find_all('1=1');
  1037. $list = array();
  1038. foreach ($data as $key=>$value)
  1039. {
  1040. $list[] = array('id'=>$value['id'],'title'=>$value['title']);
  1041. }
  1042. $num = array();
  1043. if($purchase != "null")
  1044. {
  1045. $num = $this->user->read($purchase);//找出内容
  1046. if($num['purchase'])
  1047. {
  1048. $num = explode('|',trim($num['purchase'],'|'));//数组化内容
  1049. }
  1050. else
  1051. {
  1052. $num = array();
  1053. }
  1054. }
  1055. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1056. }
  1057. if(isset($post['staff']))
  1058. {
  1059. $staff = $this->input->post('staff',true);
  1060. $data = $this->staff->find_all('1=1');
  1061. $list = array();
  1062. foreach ($data as $key=>$value)
  1063. {
  1064. $list[] = array('id'=>$value['id'],'title'=>$value['name']);
  1065. }
  1066. $num = array();
  1067. if($staff != "null")
  1068. {
  1069. $num = $this->user->read($staff);//找出内容
  1070. if($num['staff'])
  1071. {
  1072. $num = explode('|',trim($num['staff'],'|'));//数组化内容
  1073. }
  1074. else
  1075. {
  1076. $num = array();
  1077. }
  1078. }
  1079. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1080. }
  1081. if(isset($post['warehouse']))
  1082. {
  1083. $warehouse = $this->input->post('warehouse',true);
  1084. $data = $this->warehouse->find_all('1=1');
  1085. $list = array();
  1086. foreach ($data as $key=>$value)
  1087. {
  1088. $list[] = array('id'=>$value['id'],'title'=>$value['title']);
  1089. }
  1090. $num = array();
  1091. if($warehouse != "null")
  1092. {
  1093. $num = $this->user->read($warehouse);//找出内容
  1094. if($num['warehouse'])
  1095. {
  1096. $num = explode('|',trim($num['warehouse'],'|'));//数组化内容
  1097. }
  1098. else
  1099. {
  1100. $num = array();
  1101. }
  1102. }
  1103. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1104. }
  1105. if(isset($post['transfer']))
  1106. {
  1107. $transfer = $this->input->post('transfer',true);
  1108. $data = $this->transfer->find_all('1=1');
  1109. $list = array();
  1110. foreach ($data as $key=>$value)
  1111. {
  1112. $list[] = array('id'=>$value['id'],'title'=>$value['title']);
  1113. }
  1114. $num = array();
  1115. if($transfer != "null")
  1116. {
  1117. $num = $this->user->read($transfer);//找出内容
  1118. if($num['transfer'])
  1119. {
  1120. $num = explode('|',trim($num['transfer'],'|'));//数组化内容
  1121. }
  1122. else
  1123. {
  1124. $num = array();
  1125. }
  1126. }
  1127. echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true));
  1128. }
  1129. }
  1130. public function _shopfx()
  1131. {
  1132. $post = $this->input->post(NULL, TRUE);
  1133. if(isset($post['time']))
  1134. {
  1135. $time = $this->input->post('time',true);
  1136. $t = strtotime(date("Ymd",time()+24*3600));//明天0点
  1137. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1138. $sid = '';
  1139. foreach ($shop as $value)
  1140. {
  1141. $sid .= " shop = ".$value['id']." or";
  1142. }
  1143. $sid = " and (".rtrim($sid,'or').")";
  1144. $znum = $this->fullorder->find_count("dtime > '".($t-$time*24*3600)."' and dtime < '".$t."'".$sid);
  1145. $data = array();$list = array();
  1146. $color = array('0'=>'#30546c','1'=>'#61a0a8','2'=>'#c23531','3'=>'#d48265','4'=>'#546570','5'=>'#749f83','6'=>'#bda29a','7'=>'#6e7074','8'=>'#546570');
  1147. $j = 0;
  1148. $zt = array(7=>1,30=>2);
  1149. foreach ($shop as $v)
  1150. {
  1151. $d = $this->fullorder->find_count("shop = '".$v['id']."' and dtime > '".($t-$time*24*3600)."' and dtime < '".$t."' and (state = '207' or state = '216')");
  1152. $wd = $this->allocation->read($zt[$time]);
  1153. $n = json_decode($wd['content'],true);
  1154. $bfb = ($d==0)?0:round(($d / $znum) * 100, 2);
  1155. $data[] = array('value'=>$bfb,'name'=>$v['shopname'].' '.$bfb."%",'itemStyle'=>array('color'=>$color[$j]));
  1156. $n[$v['id']][] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".date("Ymd",time())."' and (state = '207' or state = '216')");
  1157. $t_list = array();
  1158. for($i=0;$i<$time;$i++)
  1159. {
  1160. $t_list[] = date("m-d",time()-($i*24*3600));
  1161. }
  1162. $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).'%');
  1163. $j++;
  1164. }
  1165. $list = (array_reverse($list));
  1166. echo json_encode(array('data'=>($data),'list'=>$list,'t'=>(array_reverse($t_list)),'success'=>true));exit;
  1167. /**
  1168. $time = $this->input->post('time',true);
  1169. $t = strtotime(date("Ymd",time()+24*3600));//明天0点
  1170. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1171. $sid = '';
  1172. foreach ($shop as $value)
  1173. {
  1174. $sid .= " shop = ".$value['id']." or";
  1175. }
  1176. $sid = " and (".rtrim($sid,'or').")";
  1177. $znum = $this->fullorder->find_count("dtime > '".($t-$time*24*3600)."' and dtime < '".$t."'".$sid);
  1178. $data = array();$list = array();
  1179. $color = array('0'=>'#30546c','1'=>'#61a0a8','2'=>'#c23531','3'=>'#d48265','4'=>'#546570','5'=>'#749f83','6'=>'#bda29a','7'=>'#6e7074','8'=>'#546570');
  1180. $j = 0;
  1181. foreach ($shop as $v)
  1182. {
  1183. $d = $this->fullorder->find_count("shop = '".$v['id']."' and dtime > '".($t-$time*24*3600)."' and dtime < '".$t."' and (state = '207' or state = '216')");
  1184. $bfb = ($d==0)?0:round(($d / $znum) * 100, 2);
  1185. $data[] = array('value'=>$bfb,'name'=>$v['shopname'].' '.$bfb."%",'itemStyle'=>array('color'=>$color[$j]));
  1186. $n = array();$t_list = array();
  1187. for($i=0;$i<$time;$i++)
  1188. {
  1189. if($i == 0)
  1190. {
  1191. $s = date("Ymd",time());
  1192. }
  1193. else
  1194. {
  1195. $s = date("Ymd",time()-($i*24*3600));
  1196. }
  1197. $t_list[] = date("m-d",time()-($i*24*3600));
  1198. $n[] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".$s."' and (state = '207' or state = '216')");
  1199. }
  1200. $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).'%');
  1201. $j++;
  1202. }
  1203. $list = (array_reverse($list));
  1204. echo json_encode(array('data'=>($data),'list'=>$list,'t'=>(array_reverse($t_list)),'success'=>true));exit;
  1205. **/
  1206. }
  1207. $this->_Template('phone/p_user_shopfx',$this->data);
  1208. }
  1209. public function _shopfxlist()
  1210. {
  1211. $t = strtotime(date("Ymd",time()));//今天0点
  1212. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1213. $sid = '';
  1214. foreach ($shop as $value)
  1215. {
  1216. $sid .= " shop = ".$value['id']." or";
  1217. }
  1218. $sid = " and (".rtrim($sid,'or').")";
  1219. $zt = array(7,30);
  1220. $this->db->trans_begin();
  1221. foreach ($zt as $key=>$time)
  1222. {
  1223. $data = array();$list = array();
  1224. foreach ($shop as $v)
  1225. {
  1226. $n = array();$t_list = array();
  1227. for($i=1;$i<$time;$i++)
  1228. {
  1229. if($i == 0)
  1230. {
  1231. $s = date("Ymd",time());
  1232. }
  1233. else
  1234. {
  1235. $s = date("Ymd",time()-($i*24*3600));
  1236. }
  1237. $t_list[] = date("m-d",time()-($i*24*3600));
  1238. $n[] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".$s."' and (state = '207' or state = '216')");
  1239. }
  1240. $list[$v['id']] = array_reverse($n);
  1241. }
  1242. $this->allocation->save(array('content'=>json_encode($list)),$key+1);
  1243. }
  1244. if ($this->db->trans_status() === FALSE)
  1245. {
  1246. $this->db->trans_rollback();
  1247. echo 'orver';
  1248. }
  1249. else
  1250. {
  1251. $this->db->trans_commit();
  1252. echo 'ok';
  1253. }
  1254. }
  1255. public function _apple()
  1256. {
  1257. $this->_Template('phone/p_user_apple',$this->data);
  1258. }
  1259. //退出
  1260. public function _tc()
  1261. {
  1262. $this->session->sess_destroy();
  1263. header("Location:/");
  1264. }
  1265. public function _tjadd()
  1266. {
  1267. $pdtime = date('Y-m-d-H',time());
  1268. //if(is_file("./data/tj/".$pdtime.".txt"))
  1269. if(is_file("./data/tj/".$pdtime.".txt"))
  1270. {
  1271. $myfile = fopen("./data/tj/".$pdtime.".txt", "r") or die("Unable to open file!");
  1272. $bc = fread($myfile,filesize("./data/tj/".$pdtime.".txt"));
  1273. fclose($myfile);
  1274. $bc = json_decode($bc,true);
  1275. $zzt = array($bc['zzt'][0],$bc['zzt'][1]);
  1276. }
  1277. else
  1278. {
  1279. /** 暂时不需要了
  1280. //柱状图数据
  1281. $i = 0;
  1282. $data = array();$sndata1 = array();$sndata2 = array();$sndata3 = array();
  1283. $sj = array('01','02','03','04','05','06','07','08','09','10','11','12');
  1284. foreach ($sj as $k=>$v)
  1285. {
  1286. $i++;
  1287. $dlz1 = $this->fullorder->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1288. $smt1 = $this->fullordersmt->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1289. $m1 = sprintf("%01.2f",array_sum(array_column($dlz1,'shouldmoney'))+array_sum(array_column($smt1,'shouldmoney')));
  1290. $dlz2 = $this->fullorder->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1291. $smt2 = $this->fullordersmt->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1292. $m2 = sprintf("%01.2f",array_sum(array_column($dlz2,'shouldmoney'))+array_sum(array_column($smt2,'shouldmoney')));
  1293. $dlz3 = $this->fullorder->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1294. $smt3 = $this->fullordersmt->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1295. $m3 = sprintf("%01.2f",array_sum(array_column($dlz3,'shouldmoney'))+array_sum(array_column($smt3,'shouldmoney')));
  1296. $sndata1[$i] = $m3;
  1297. $sndata2[12+$i] = $m2;
  1298. $sndata3[24+$i] = $m1;
  1299. $data[] = array($v,$m1,$m2,$m3);
  1300. }
  1301. $sndata = array_merge($sndata1,$sndata2,$sndata3);
  1302. $zzt = array($data,$sndata);
  1303. //柱状图结束
  1304. **/
  1305. }
  1306. //详情内容
  1307. $dt = 0;
  1308. $user = $this->user->get_api($_SESSION['api']);
  1309. $usp = $user;
  1310. $fgshop = "";$sid = "";
  1311. $user = explode('|',trim($user['shop'],'|'));
  1312. foreach ($user as $value)
  1313. {
  1314. $fgshop .= " shop = ".$value." or";
  1315. $sid .= " id = ".$value." or";
  1316. }
  1317. $tm = strtotime(date("Ymd"),time());
  1318. $usat = $tm;
  1319. //$molist = array('0','1','2d');
  1320. $molist = array('0','1');
  1321. $zqtime = array(259200,345600,691200,2678400,7862400,31622400);
  1322. //time开始
  1323. $zqtdata = array();
  1324. foreach ($molist as $vval)
  1325. {
  1326. $where = "";
  1327. $source = $vval;
  1328. if($source == '2d')
  1329. {
  1330. $where = " and source >= '2'";
  1331. }
  1332. else if($source != '0')
  1333. {
  1334. $where = " and source = '$source'";
  1335. }
  1336. foreach ($zqtime as $value)
  1337. {
  1338. $zdt = $value;
  1339. $k = $zdt;
  1340. $tab = 1;
  1341. //$start = '2018-10-15';
  1342. //$end = '2018-11-26';
  1343. //$tim = strtotime($start);
  1344. //$day = $time/(3600*24);
  1345. if($tab == '1')
  1346. {
  1347. if($zdt >= 691200)
  1348. {
  1349. $k = $usat-$k-$k;
  1350. $j = $usat;
  1351. $n = ($j-$k)/(24*3600);
  1352. }
  1353. else
  1354. {
  1355. $n = 2;
  1356. $usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
  1357. }
  1358. }
  1359. else
  1360. {
  1361. $timedata = explode('|',$zdt);
  1362. $ktime = strtotime($timedata[0]);
  1363. $jtime = strtotime($timedata[1]);
  1364. $ktime = $ktime-($jtime-$ktime);
  1365. $k = $ktime;
  1366. $j = $jtime;
  1367. $n = ($j-$k)/(24*3600);
  1368. $usat = $jtime;
  1369. $tm = $jtime;
  1370. $zdt = $jtime-$ktime;
  1371. }
  1372. $time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();;$ttnum = array();$ymoney = array();$money = array();$dlzmoney = array();$smtmoney=array();$ttmoney=array();
  1373. $dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();
  1374. $dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
  1375. $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'");
  1376. foreach ($ys as $v)
  1377. {
  1378. $shopdata[$v['id']] = array('num'=>0,'money'=>0,'tmoney'=>0,'fdl'=>0,'chl'=>0);
  1379. }
  1380. for($i=1;$i<$n;$i++)
  1381. {
  1382. //近7天时间
  1383. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1384. if($n > 13 && $i > $n/2 || $n < 14)
  1385. {
  1386. $t = $usat-($n*24*60*60)+($i*24*60*60);
  1387. $time[] = date('m-d',$t);
  1388. $ct = strtotime(date('Ymd',$t));
  1389. $ctj = strtotime(date('Ymd',$t+24*3600));
  1390. $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');
  1391. $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');
  1392. $tt = $this->fullordertt->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');
  1393. $ab[] = $dlz;
  1394. //数量及金额开始
  1395. $dlznum[] = count($dlz);
  1396. $smtnum[] = count($smt);
  1397. $ttnum[] = count($smt);
  1398. $dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
  1399. $smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
  1400. $ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
  1401. /**
  1402. //提出退款关闭等信息的实收金额
  1403. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1404. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1405. //提出退款关闭等信息的实收金额
  1406. **/
  1407. //实收金额
  1408. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'budget')));
  1409. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'budget')));
  1410. $ttmss = sprintf("%01.2f",array_sum(array_column($tt,'budget')));
  1411. //实收金额
  1412. //补/退原额
  1413. $dlzbty = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1414. $smtbty = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1415. $ttbty = sprintf("%01.2f",array_sum(array_column($tt,'refundy')));
  1416. //补/退原额
  1417. $dlzmoney[] = $dlzm;
  1418. $smtmoney[] = $smtm;
  1419. $ttmoney[] = $ttm;
  1420. $dlzsl += count($dlz);
  1421. $dlzje += $dlzm;
  1422. $smtsl += count($smt);
  1423. $smtje += $smtm;
  1424. $ttsl += count($tt);
  1425. $ttje += $ttm;
  1426. /**
  1427. //减去的实收金额
  1428. $dlzssje += $dlzm+$dlzmss;
  1429. $smtssje += $smtm+$smtmss;
  1430. **/
  1431. //实收和补/退
  1432. $dlzssje += $dlzmss+$dlzbty;
  1433. $smtssje += $smtmss+$smtbty;
  1434. $ttssje += $ttmss+$ttbty;
  1435. //数量及金额结束
  1436. $sd = array_merge($dlz,$smt,$tt);
  1437. foreach ($sd as $v)
  1438. {
  1439. if(isset($shopdata[$v['shop']]))
  1440. {
  1441. $shopdata[$v['shop']]['num'] += 1;
  1442. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  1443. $shopdata[$v['shop']]['tmoney'] += $v['budget']+$v['refundy'];
  1444. }
  1445. }
  1446. }
  1447. else if ($n > 13 && $i <= $n/2)
  1448. {
  1449. $t = $usat-($n*24*60*60)+($i*24*60*60);
  1450. $timeold[] = date('m-d',$t);
  1451. $ct = strtotime(date('Ymd',$t));
  1452. $ctj = strtotime(date('Ymd',$t+24*3600));
  1453. $dlz = $this->fullorder->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  1454. $smt = $this->fullordersmt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  1455. $tt = $this->fullordertt->find_all("(".rtrim($fgshop,'or').") and dtime >= ".$ct." and dtime <= ".$ctj.$where,'budget,shouldmoney,shop');
  1456. //数量及金额开始
  1457. $dlzm = sprintf("%01.2f",array_sum(array_column($dlz,'shouldmoney')));
  1458. $smtm = sprintf("%01.2f",array_sum(array_column($smt,'shouldmoney')));
  1459. $ttm = sprintf("%01.2f",array_sum(array_column($tt,'shouldmoney')));
  1460. $dlzmoneyb[] = $dlzm;
  1461. $smtmoneyb[] = $smtm;
  1462. $ttmoneyb[] = $ttm;
  1463. //数量及金额结束
  1464. }
  1465. }
  1466. foreach ($shopdata as $k=>$v)
  1467. {
  1468. $sn = $this->shop->read($k);
  1469. $shopdata[$k]['money'] = sprintf("%01.2f",$v['money']).'$';
  1470. $shopdata[$k]['tmoney'] = sprintf("%01.2f",$v['tmoney']).'$';
  1471. $shopdata[$k]['bl'] = ($v['num']=='0')?'0$':round($v['money']/$v['num'],2).'$';
  1472. $shopdata[$k]['name'] = $sn['shopname'];
  1473. $shopdata[$k]['b'] = $sn['type'];
  1474. $shopdata[$k]['id'] = $sn['id'];
  1475. }
  1476. $shopdata = array_values($shopdata);
  1477. //$sycp=array();
  1478. /**
  1479. //根据所选时间产品排行开始
  1480. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1481. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1482. **/
  1483. /**
  1484. //昨日产品排行开始
  1485. $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');
  1486. $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');
  1487. $rows = array_merge($dlzlist,$smtlist);
  1488. foreach ($rows as $v)
  1489. {
  1490. $number = explode('|',trim($v['whlabel'],'|'));
  1491. $or = explode(';',trim($v['fpdata'],';'));
  1492. $i=0;
  1493. foreach ($or as $va)
  1494. {
  1495. $ord = explode('|',$va);
  1496. $orod = explode(',',$ord[0]);
  1497. $numberod = explode('-',$number[$i]);
  1498. if(!isset($orod[1]))
  1499. {
  1500. continue;
  1501. }
  1502. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  1503. {
  1504. //$sycp[$orod[1]][0] += 1;//统计多少单
  1505. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  1506. $sycp[$orod[1]][1] += 0;//价格
  1507. }
  1508. else
  1509. {
  1510. if(isset($numberod[1]))
  1511. {
  1512. $typeclass = $this->typeclass->read($orod['0']);
  1513. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  1514. }
  1515. }
  1516. $i++;
  1517. }
  1518. }
  1519. arsort($sycp);
  1520. $sycp = array_values($sycp);
  1521. $sycp = array_slice($sycp,0,10);
  1522. //产品排行结束
  1523. **/
  1524. //当时实时数据结束
  1525. $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昨日产品数据
  1526. }
  1527. }
  1528. //time结束
  1529. //zhcx开始
  1530. $zhcxdata = array();
  1531. foreach ($molist as $vval)
  1532. {
  1533. $where = "";
  1534. $source = $vval;
  1535. if($source == '2d')
  1536. {
  1537. $where = " and source >= '2'";
  1538. }
  1539. else if($source != '0')
  1540. {
  1541. $where = " and source = '$source'";
  1542. }
  1543. foreach ($zqtime as $value)
  1544. {
  1545. $zdt = $value;
  1546. $k = $zdt;
  1547. $tab = 1;
  1548. $customer = $this->customer->find_all("shop !=''",'num,zhcx');
  1549. $customerkey = array_column($customer,'zhcx');
  1550. $customer= array_combine($customerkey,$customer);
  1551. $customersmt = $this->customersmt->find_all("shop !=''",'num,zhcx');
  1552. $customersmtkey = array_column($customersmt,'zhcx');
  1553. $customersmt= array_combine($customersmtkey,$customersmt);
  1554. $customertt = $this->customertt->find_all("shop !=''",'num,zhcx');
  1555. $customerttkey = array_column($customertt,'zhcx');
  1556. $customertt= array_combine($customerttkey,$customertt);
  1557. if($tab == '1')
  1558. {
  1559. if($zdt >= 691200)
  1560. {
  1561. $k = $usat-$k-$k;
  1562. $j = $usat;
  1563. $n = ($j-$k)/(24*3600);
  1564. }
  1565. else
  1566. {
  1567. $n = 2;
  1568. $usat = strtotime(date("Ymd"),time())-$k+2*24*3600;
  1569. }
  1570. }
  1571. else
  1572. {
  1573. $timedata = explode('|',$zdt);
  1574. $ktime = strtotime($timedata[0]);
  1575. $jtime = strtotime($timedata[1]);
  1576. $ktime = $ktime-($jtime-$ktime);
  1577. $k = $ktime;
  1578. $j = $jtime;
  1579. $n = ($j-$k)/(24*3600);
  1580. $usat = $jtime;
  1581. }
  1582. $time=array();$timeold=array();$stime=array();$dlznum = array();$smtnum = array();$ttnum = array();$ymoney = array();$money = array();
  1583. $dlzmoneyb=array();$smtmoneyb=array();$ttmoneyb=array();$zkh = array();
  1584. $dlzsl=0;$dlzje=0;$dlzssje=0;$smtsl=0;$smtje=0;$smtssje=0;$ttsl=0;$ttje=0;$ttssje=0;$shopdata = array();
  1585. $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'");
  1586. foreach ($ys as $v)
  1587. {
  1588. $shopdata[$v['id']] = array('id'=>$v['id'],'b'=>$v['type'],'fdl'=>0,'chl'=>0,'num'=>0,'fgl'=>0);
  1589. $zkh[$v['id']] = array();
  1590. }
  1591. for($i=1;$i<$n;$i++)
  1592. {
  1593. if($n > 13 && $i > $n/2 || $n < 14)
  1594. {
  1595. $t = $usat-($n*24*60*60)+($i*24*60*60);
  1596. $time[] = date('m-d',$t);
  1597. $ct = strtotime(date('Ymd',$t));
  1598. $ctj = strtotime(date('Ymd',$t+24*3600));
  1599. $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');
  1600. $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');
  1601. $tt = $this->fullordertt->find_all("dtime >= ".$ct." and dtime <= ".$ctj.$where." and shop != '0' and (".rtrim($fgshop,'or').") and shop != '18' and shop != '19'",'shop,email');
  1602. //数量及金额结束
  1603. $sd = array_merge($dlz,$smt,$tt);
  1604. $fgldata = array();
  1605. foreach ($sd as $v)
  1606. {
  1607. if(isset($v['email']))
  1608. {
  1609. if(!isset($fgldata[$v['shop'].'-'.$v['email']]))
  1610. {
  1611. $fgldata[$v['shop'].'-'.$v['email']] = 0;
  1612. }
  1613. else
  1614. {
  1615. $fgldata[$v['shop'].'-'.$v['email']] += 1;
  1616. }
  1617. $zkh[$v['shop']][$v['email']] = array();
  1618. }
  1619. else
  1620. {
  1621. if(!isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1622. {
  1623. $fgldata[$v['shop'].'-'.$v['userid']] = 0;
  1624. }
  1625. else
  1626. {
  1627. $fgldata[$v['shop'].'-'.$v['userid']] += 1;
  1628. }
  1629. $zkh[$v['shop']][$v['userid']] = array();
  1630. }
  1631. }
  1632. foreach ($sd as $v)
  1633. {
  1634. $chl = 0;
  1635. if(isset($shopdata[$v['shop']]))
  1636. {
  1637. if(isset($v['email']))
  1638. {
  1639. if(isset($customer[$v['shop'].'-'.$v['email']]['num']))
  1640. {
  1641. $fdl = $customer[$v['shop'].'-'.$v['email']]['num']>1?1:0;
  1642. }
  1643. else
  1644. {
  1645. $fdl = 0;
  1646. }
  1647. foreach ($ys as $vv)
  1648. {
  1649. if($vv['id'] != $v['shop'] && isset($customer[$vv['id'].'-'.$v['email']]))
  1650. {
  1651. $chl = 1;
  1652. }
  1653. }
  1654. if(isset($fgldata[$v['shop'].'-'.$v['email']]))
  1655. {
  1656. $fgl = $fgldata[$v['shop'].'-'.$v['email']]>0?1:0;
  1657. }
  1658. else
  1659. {
  1660. $fgl = 0;
  1661. }
  1662. }
  1663. else
  1664. {
  1665. if(isset($customersmt[$v['shop'].'-'.$v['userid']]['num']))
  1666. {
  1667. $fdl = $customersmt[$v['shop'].'-'.$v['userid']]['num']>1?1:0;
  1668. }
  1669. else
  1670. {
  1671. $fdl = 0;
  1672. }
  1673. foreach ($ys as $vv)
  1674. {
  1675. if($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'].'-'.$v['userid']]))
  1676. {
  1677. $chl = 1;
  1678. }
  1679. }
  1680. if(isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1681. {
  1682. $fgl = $fgldata[$v['shop'].'-'.$v['userid']]>0?1:0;
  1683. }
  1684. else
  1685. {
  1686. $fgl = 0;
  1687. }
  1688. }
  1689. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl']+$fdl;
  1690. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl']+$chl;
  1691. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl']+$fgl;
  1692. $shopdata[$v['shop']]['num'] += 1;
  1693. }
  1694. }
  1695. }
  1696. }
  1697. foreach ($shopdata as $k=>$v)
  1698. {
  1699. $shopdata[$k]['fdl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['fdl']/$v['num']*100)).'%';
  1700. $shopdata[$k]['chl'] = $v['num']=='0'?0:sprintf("%01.2f",($v['chl']/$v['num']*100)).'%';
  1701. $shopdata[$k]['fgl'] = count($zkh[$v['id']])=='0'?0:sprintf("%01.2f",($v['fgl']/count($zkh[$v['id']])*100)).'%';
  1702. }
  1703. $shopdata = array_values($shopdata);
  1704. $zhcxdata[$vval][$value] = array('shopdata'=>$shopdata,'success'=>true);
  1705. }
  1706. }
  1707. //zhcx结束
  1708. $myfile = fopen("./data/tj/".$pdtime.".txt", "w") or die("Unable to open file!");
  1709. $txt = json_encode(array('zzt'=>$zzt,'tj'=>$zqtdata,'zhcx'=>$zhcxdata));
  1710. fwrite($myfile, $txt);
  1711. fclose($myfile);
  1712. echo 1;
  1713. }
  1714. }