User.php 65 KB

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