User.php 65 KB

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