User.php 65 KB

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