Userbak.php 65 KB

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