User.php 65 KB

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