Usertwo.php 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776
  1. <?php defined('BASEPATH') or exit('No direct script access allowed');
  2. class Usertwo extends Start_Controller
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. $this->load->library('session');
  8. $this->load->_model('Model_user', 'user');
  9. $this->load->_model('Model_nav', 'nav');
  10. $this->load->_model('Model_power', 'power');
  11. $this->load->_model('Model_shop', 'shop');
  12. $this->load->_model('Model_purchase', 'purchase');
  13. $this->load->_model('Model_warehouse', 'warehouse');
  14. $this->load->_model('Model_staff', 'staff');
  15. $this->load->_model('Model_fullorder', 'fullorder');
  16. $this->load->_model('Model_fullordertt', 'fullordertt');
  17. $this->load->_model('Model_fullordersmt', 'fullordersmt');
  18. $this->load->_model('Model_customer', 'customer');
  19. $this->load->_model('Model_customersmt', 'customersmt');
  20. $this->load->_model('Model_typeclass', 'typeclass');
  21. $this->load->_model('Model_transfer', 'transfer');
  22. $this->load->_model('Model_typeclass', 'typeclass');
  23. $this->load->_model('Model_customertt', 'customertt');
  24. $this->load->_model('Model_allocation', 'allocation');
  25. $this->load->_model('Model_fullorderamz', 'fullorderamz');
  26. $this->load->_model("Model_logic_ding","logic_ding");
  27. }
  28. //定义方法的调用规则 获取URI第二段值
  29. public function _remap($arg, $arg_array)
  30. {
  31. if ($arg == 'tc') //退出
  32. {
  33. $this->_tc();
  34. } else if ($arg == 'data') //操作页
  35. {
  36. $this->_data();
  37. } else if ($arg == 'del') //删除
  38. {
  39. $this->_del();
  40. } else if ($arg == 'default') //默认页
  41. {
  42. $this->_default();
  43. } else if ($arg == 'add') //添加
  44. {
  45. $this->_add();
  46. } else if ($arg == 'edit') //修改
  47. {
  48. $this->_edit($arg_array);
  49. } else if ($arg == 'rows') //数据
  50. {
  51. $this->_rows();
  52. } else if ($arg == 'statistics') //数据
  53. {
  54. $this->_statistics();
  55. } else if ($arg == 'apple') //数据
  56. {
  57. $this->_apple();
  58. } else if ($arg == 'zzt') //数据
  59. {
  60. $this->_zzt();
  61. } else if ($arg == 'tjadd') //数据
  62. {
  63. $this->_tjadd();
  64. } else if ($arg == 'shopfx') //店铺分析
  65. {
  66. $this->_shopfx();
  67. } else if ($arg == 'shopfxlist') //店铺分析
  68. {
  69. $this->_shopfxlist();
  70. }else if($arg == 'statistics_hb'){
  71. $this->_statistics_hb();
  72. }else if($arg == 'statistics_tb'){
  73. $this->_statistics_tb();
  74. }
  75. else if($arg == 'user_lvceshi'){
  76. $this->_user_lvceshi();
  77. }
  78. else {
  79. $this->_index();
  80. }
  81. }
  82. //首页
  83. public function _index()
  84. {
  85. if(empty($_SESSION['api'])){
  86. exit('No direct script access allowed');
  87. }
  88. $user = $this->user->get_api($_SESSION['api']);
  89. $this->data['user'] = $user; //登录的用户信息
  90. $power = $this->power->read($user['power']);
  91. $power = $power['powerid'];
  92. //$power = explode('|',trim($power,'|'));字符串转数组
  93. $dataa = $this->nav->find_all('type=1', '*', 'px asc');
  94. $datab = $this->nav->find_all('type=2', '*', 'px asc');
  95. $datac = $this->nav->find_all('type=3', '*', 'sort asc,px desc');
  96. $an = array();
  97. foreach ($dataa as $key => $value) {
  98. foreach ($datab as $ke => $va) {
  99. if ($va['class'] == $value['id']) {
  100. foreach ($datac as $k => $v) {
  101. if ($v['class'] == $va['id']) {
  102. if (strstr($power, '|' . $v['id'] . '|') == true) {
  103. $va['cn'][] = $v;
  104. }
  105. }
  106. }
  107. if (strstr($power, '|' . $va['id'] . '|') == true) {
  108. $value['bn'][] = $va;
  109. }
  110. }
  111. } //循环出二级导航航
  112. if (strstr($power, '|' . $value['id'] . '|') == true) {
  113. $an[] = $value;
  114. }
  115. }
  116. //print_r($an);
  117. $this->data['data'] = $an;
  118. $this->data['ip'] = $this->input->ip_address();
  119. $this->data['power'] = $user['power'];
  120. $this->data['link'] = $user['link'];
  121. if (stripos($_SERVER['HTTP_HOST'], 'a.') !== false) {
  122. $url = 'b';
  123. } else {
  124. $url = 'a';
  125. }
  126. $this->data['url'] = $url;
  127. $this->_Template('user', $this->data);
  128. }
  129. //管理
  130. public function _data()
  131. {
  132. $user = $this->user->get_api($_SESSION['api']);
  133. $post = $this->input->post(NULL, TRUE);
  134. if (isset($post['page'])) {
  135. $page = $this->input->post('page', true);
  136. $perpage = $this->input->post('perpage', true);
  137. $power = $this->input->post('power', true);
  138. $name = $this->input->post('name', true);
  139. $userid = $this->input->post('userid', true);
  140. $type = $this->input->post('type', true);
  141. $where = "own='" . $user['own'] . "'";
  142. if ($power) {
  143. $where .= " and power = '$power' ";
  144. }
  145. if ($name) {
  146. $where .= " and name like '%$name%' ";
  147. }
  148. if ($userid) {
  149. $where .= " and userid like '%$userid%' ";
  150. }
  151. if ($type) {
  152. $where .= " and type = '$type' ";
  153. }
  154. //数据排序
  155. $order_str = "id asc";
  156. if (empty($page)) {
  157. $start = 0;
  158. $perpage = 1;
  159. } else {
  160. $start = ($page - 1) * $perpage;
  161. }
  162. //取得信息列表
  163. //$info_list = $this->user->find_all($where,'id,name,userid,power,shoptext,purchasetext,warehousetext,stafftext,transfertext,type,lasttime',$order_str,$start,$perpage);
  164. $info_list = $this->user->find_all($where, 'id,name,userid,power,shoptext,purchasetext,warehousetext,transfertext,type,lasttime', $order_str, $start, $perpage);
  165. //格式化数据
  166. foreach ($info_list as $key => $value) {
  167. if ($value['type'] == 1) {
  168. if (empty($value['lasttime'])) {
  169. $info_list[$key]['type'] = '正常';
  170. } else {
  171. $info_list[$key]['type'] = '正常' . "<br>最后操作时间:<br>" . date("Y-m-d", $value['lasttime']);
  172. }
  173. } else {
  174. $info_list[$key]['type'] = '停用';
  175. }
  176. $power = $this->power->read($value['power']);
  177. $info_list[$key]['power'] = $power['powername'];
  178. unset($info_list[$key]['lasttime']);
  179. }
  180. $total = $this->user->find_count($where);
  181. $pagenum = ceil($total / $perpage);
  182. $over = $total - ($start + $perpage);
  183. $rows = array('total' => $total, 'over' => $over, 'pagenum' => $pagenum, 'rows' => ($info_list));
  184. echo json_encode($rows);
  185. exit;
  186. }
  187. $power = $this->power->find_all("1 = 1","*","sort asc,id asc");
  188. $this->data['power'] = $power;
  189. $this->_Template('user_data', $this->data);
  190. }
  191. //添加
  192. public function _add()
  193. {
  194. $user = $this->user->get_api($_SESSION['api']);
  195. $post = $this->input->post(NULL, TRUE);
  196. if (isset($post['userid'])) {
  197. $post['userid'] = $this->input->post('userid', true);
  198. $userpass = $this->input->post('userpass', true);
  199. $post['userpass'] = sha1($userpass);
  200. $post['shop'] = $this->input->post('shop', true);
  201. $post['shoptext'] = $this->input->post('shoptext', true);
  202. $post['excelshop'] = $this->input->post('excelshop', true);
  203. $post['excelshoptext'] = $this->input->post('excelshoptext', true);
  204. $post['purchase'] = $this->input->post('purchase', true);
  205. $post['purchasetext'] = $this->input->post('purchasetext', true);
  206. $post['warehouse'] = $this->input->post('warehouse', true);
  207. $post['warehousetext'] = $this->input->post('warehousetext', true);
  208. $post['customer'] = $this->input->post('customer', true);
  209. $post['staff'] = empty($this->input->post('staff', true))?0:$this->input->post('staff', true);
  210. $post['stafftext'] = $this->input->post('stafftext', true);
  211. $post['power'] = $this->input->post('power', true);
  212. $post['name'] = $this->input->post('name', true);
  213. $post['phone'] = $this->input->post('phone', true);
  214. $post['type'] = $this->input->post('type', true);
  215. $post['html'] = $this->input->post('html', true);
  216. $post['own'] = $user['own'];
  217. $post['api'] = sha1(rand(1000000, 9999999));
  218. unset($post['id']);
  219. if ($this->user->insert($post)) {
  220. echo json_encode(array('msg' => '添加成功', 'success' => true));
  221. exit;
  222. } else {
  223. echo json_encode(array('msg' => '添加失败,请重试', 'success' => false));
  224. exit;
  225. }
  226. }
  227. $power = $this->power->find_all("1 = 1","*","sort asc,id asc");
  228. $this->data['power'] = $power;
  229. $this->_Template('user_add', $this->data);
  230. }
  231. //修改
  232. public function _edit($arg_array)
  233. {
  234. $post = $this->input->post(NULL, TRUE);
  235. if (isset($post['id'])) {
  236. $id = $this->input->post('id', true);
  237. $post['userid'] = $this->input->post('edituserid', true);
  238. $userpass = $this->input->post('edituserpass', true);
  239. $post['shop'] = $this->input->post('shop', true);
  240. $post['shoptext'] = $this->input->post('shoptext', true);
  241. $post['excelshop'] = $this->input->post('excelshop', true);
  242. $post['excelshoptext'] = $this->input->post('excelshoptext', true);
  243. $post['purchase'] = $this->input->post('purchase', true);
  244. $post['purchasetext'] = $this->input->post('purchasetext', true);
  245. $post['warehouse'] = $this->input->post('warehouse', true);
  246. $post['warehousetext'] = $this->input->post('warehousetext', true);
  247. $post['customer'] = $this->input->post('customer', true);
  248. $post['staff'] = $this->input->post('staff', true);
  249. $post['stafftext'] = $this->input->post('stafftext', true);
  250. $post['power'] = $this->input->post('power', true);
  251. $post['name'] = $this->input->post('name', true);
  252. $post['phone'] = $this->input->post('phone', true);
  253. $post['type'] = $this->input->post('type', true);
  254. $post['html'] = $this->input->post('html', true);
  255. $ud = $this->user->read($id);
  256. if ($userpass != NULL) {
  257. $post['userpass'] = sha1($userpass);
  258. $post['api'] = sha1(rand(1000000, 9999999));
  259. } else {
  260. $post['userpass'] = $ud['userpass'];
  261. }
  262. if ($this->user->save($post, $id)) {
  263. echo json_encode(array('msg' => '修改成功', 'success' => true));
  264. exit;
  265. } else {
  266. echo json_encode(array('msg' => '修改失败,请重试', 'success' => false));
  267. exit;
  268. }
  269. }
  270. $arg_array = $arg_array[0];
  271. $user = $this->user->read($arg_array);
  272. $this->data['user'] = $user;
  273. $power = $this->power->find_all("1 = 1","*","sort asc,id asc");
  274. $this->data['power'] = $power;
  275. $this->_Template('user_edit', $this->data);
  276. }
  277. //删除
  278. public function _del()
  279. {
  280. $post = $this->input->post(NULL, TRUE);
  281. if (isset($post['s'])) {
  282. $id_arr = $this->input->post('s');
  283. $id_arr = explode(',', $id_arr);
  284. if (!$id_arr) {
  285. echo json_encode(array('msg' => '参数错误!', 'success' => false));
  286. exit;
  287. }
  288. //循环删除记录
  289. foreach ($id_arr as $v) {
  290. $this->user->remove($v);
  291. }
  292. echo json_encode(array('del' => $id_arr, 'msg' => '删除记录成功!', 'success' => true));
  293. }
  294. }
  295. //默认页
  296. public function _default()
  297. {
  298. /**
  299. $order = $this->order->get_w();
  300. $order = count($order);//查询订单未处理数量
  301. $message = $this->message->get_w();
  302. $message = count($message);//查询留言未处理数量
  303. $this->_Template('default',$this->data);
  304. **/
  305. $dt = 0;
  306. if (isset($_SESSION['api'])) {
  307. $user = $this->user->get_api($_SESSION['api']);
  308. $usp = $user;
  309. $fgshop = "";
  310. $sid = "";
  311. $user = explode('|', trim($user['shop'], '|'));
  312. foreach ($user as $value) {
  313. if ($value != '18' && $value != '19' && $value != '12' && $value != '13' && $value != '9' && $value != '15' && $value != '27') {
  314. $fgshop .= " shop = " . $value . " or";
  315. }
  316. $sid .= " id = " . $value . " or";
  317. }
  318. if(empty($fgshop)){
  319. $this->logic_ding->sendToDing("用户统计页面的店铺为空,请检查!".json_encode($user));
  320. }
  321. }
  322. $post = $this->input->post(NULL, TRUE);
  323. if (isset($post['timek'])) {
  324. //$start = '2018-10-15';
  325. //$end = '2018-11-26';
  326. //$tim = strtotime($start);
  327. //$day = $time/(3600*24);
  328. $timek = $this->input->post('timek', true);
  329. $timej = $this->input->post('timej', true);
  330. $k = strtotime($timek) - 24 * 3600; //少一天为增加选择开始天时间
  331. $j = strtotime($timej);
  332. $n = ($j - $k) / (24 * 3600);
  333. if ($n < 1) {
  334. $n = 1;
  335. }
  336. $time = array();
  337. $stime = array();
  338. $num = array();
  339. $ymoney = array();
  340. $money = array();
  341. for ($i = 1; $i < $n; $i++) {
  342. //近7天时间
  343. $t = $j - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  344. $time[] = date('Y-m-d', $t);
  345. $ct = strtotime(date('Ymd', $t));
  346. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  347. $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');
  348. $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');
  349. $dsmt = array();
  350. $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');
  351. $d = array_merge($dlz, $dsmt, $tt);
  352. $num[] = count($d);
  353. $ymoney[] = sprintf("%01.2f", array_sum(array_column($d, 'budget')));
  354. $money[] = sprintf("%01.2f", array_sum(array_column($d, 'shouldmoney')));
  355. }
  356. $snuz = $this->fullorder->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  357. $snuz += $this->fullordersmt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  358. $snuz += $this->fullordertt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  359. $lnuz = $this->fullorder->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待出库
  360. $lnuz += $this->fullordersmt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待出库
  361. $lnuz += $this->fullordertt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待出库
  362. $snu = $this->fullorder->find_count('reviewtime = 0 and dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  363. $snu += $this->fullordersmt->find_count('reviewtime = 0 and dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  364. $snu += $this->fullordertt->find_count('reviewtime = 0 and dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  365. $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') . ')'); //待出库
  366. $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') . ')'); //待出库
  367. $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') . ')'); //待出库
  368. 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));
  369. exit;
  370. }
  371. $this->_Template('user_default', $this->data);
  372. }
  373. public function _zzt()
  374. {
  375. exit;
  376. if (isset($_SESSION['api'])) {
  377. $user = $this->user->get_api($_SESSION['api']);
  378. $usp = $user;
  379. $fgshop = "";
  380. $sid = "";
  381. $user = explode('|', trim($user['shop'], '|'));
  382. foreach ($user as $value) {
  383. $fgshop .= " shop = " . $value . " or";
  384. $sid .= " id = " . $value . " or";
  385. }
  386. }
  387. $data = array();
  388. $sntime = array();
  389. $sndata1 = array();
  390. $sndata2 = array();
  391. $sndata3 = array();
  392. $sj = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
  393. for ($i = 0; $i < 3; $i++) {
  394. foreach ($sj as $v) {
  395. $sntime[] = date("Y") - 2 + $i . '-' . $v;
  396. }
  397. }
  398. $pdtime = date('Y-m-d-H', time());
  399. if (is_file("./data/tj/" . $pdtime . ".txt")) {
  400. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  401. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  402. fclose($myfile);
  403. $bc = json_decode($bc, true);
  404. $data = $bc['zzt'][0];
  405. $sndata = $bc['zzt'][1];
  406. } else {
  407. $i = 0;
  408. foreach ($sj as $k => $v) {
  409. $i++;
  410. $dlz1 = $this->fullorder->find_all("gtime > '" . date("Y") . $v . "00' and gtime < '" . date("Y") . $v . "32'", 'shouldmoney');
  411. $smt1 = $this->fullordersmt->find_all("gtime > '" . date("Y") . $v . "00' and gtime < '" . date("Y") . $v . "32'", 'shouldmoney');
  412. $m1 = sprintf("%01.2f", array_sum(array_column($dlz1, 'shouldmoney')) + array_sum(array_column($smt1, 'shouldmoney')));
  413. $dlz2 = $this->fullorder->find_all("gtime > '" . (date("Y") - 1) . $v . "00' and gtime < '" . (date("Y") - 1) . $v . "32'", 'shouldmoney');
  414. $smt2 = $this->fullordersmt->find_all("gtime > '" . (date("Y") - 1) . $v . "00' and gtime < '" . (date("Y") - 1) . $v . "32'", 'shouldmoney');
  415. $m2 = sprintf("%01.2f", array_sum(array_column($dlz2, 'shouldmoney')) + array_sum(array_column($smt2, 'shouldmoney')));
  416. $dlz3 = $this->fullorder->find_all("gtime > '" . (date("Y") - 2) . $v . "00' and gtime < '" . (date("Y") - 2) . $v . "32'", 'shouldmoney');
  417. $smt3 = $this->fullordersmt->find_all("gtime > '" . (date("Y") - 2) . $v . "00' and gtime < '" . (date("Y") - 2) . $v . "32'", 'shouldmoney');
  418. $m3 = sprintf("%01.2f", array_sum(array_column($dlz3, 'shouldmoney')) + array_sum(array_column($smt3, 'shouldmoney')));
  419. $sndata1[$i] = $m3;
  420. $sndata2[12 + $i] = $m2;
  421. $sndata3[24 + $i] = $m1;
  422. $data[] = array($v, $m1, $m2, $m3);
  423. }
  424. }
  425. $time = array(date("Y"), (date("Y") - 1), (date("Y") - 2));
  426. echo json_encode(array('data' => $data, 'time' => $time, 'sndata' => $sndata, 'sntime' => $sntime, 'success' => true));
  427. exit;
  428. }
  429. //默认页
  430. public function _statistics_bak()
  431. {
  432. /**
  433. $order = $this->order->get_w();
  434. $order = count($order);//查询订单未处理数量
  435. $message = $this->message->get_w();
  436. $message = count($message);//查询留言未处理数量
  437. $this->_Template('default',$this->data);
  438. **/
  439. //date_default_timezone_set("Etc/GMT+8");
  440. $dt = 0;
  441. if (isset($_SESSION['api'])) {
  442. $user = $this->user->get_api($_SESSION['api']);
  443. $usp = $user;
  444. $fgshop = "";
  445. $sid = "";
  446. $user = explode('|', trim($user['shop'], '|'));
  447. foreach ($user as $value) {
  448. // 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')
  449. // {
  450. // $fgshop .= " shop = ".$value." or";
  451. // }
  452. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56,48])) {
  453. $fgshop .= " shop = " . $value . " or";
  454. }
  455. $sid .= " id = " . $value . " or";
  456. }
  457. }
  458. $post = $this->input->post(NULL, TRUE);
  459. $source = $this->input->post('source', true);
  460. $where = "";
  461. if ($source) {
  462. if ($source == '2d') {
  463. $where = " and source >= '2'";
  464. } else {
  465. $where = " and source = '$source'";
  466. }
  467. }
  468. $tm = strtotime(date("Ymd"), time());
  469. $usat = $tm;
  470. if (isset($post['zhcx'])) {
  471. $zdt = $this->input->post('time', true);
  472. $k = $zdt;
  473. $tab = $this->input->post('tab', true);
  474. $pdtime = date('Y-m-d-H', time());
  475. if (is_file("./data/tj/" . $pdtime . ".txt") && $tab == 1 && $zdt > 172800) {
  476. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  477. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  478. fclose($myfile);
  479. $bc = json_decode($bc, true);
  480. echo json_encode($bc['zhcx'][$source][$zdt]);
  481. exit;
  482. } else {
  483. $customer = $this->customer->find_all("shop !=''", 'num,zhcx');
  484. $customerkey = array_column($customer, 'zhcx');
  485. $customer = array_combine($customerkey, $customer);
  486. $customersmt = $this->customersmt->find_all("shop !=''", 'num,zhcx');
  487. $customersmtkey = array_column($customersmt, 'zhcx');
  488. $customersmt = array_combine($customersmtkey, $customersmt);
  489. //$start = '2018-10-15';
  490. //$end = '2018-11-26';
  491. //$tim = strtotime($start);
  492. //$day = $time/(3600*24);
  493. if ($tab == '1') {
  494. if ($zdt >= 691200) {
  495. $k = $usat - $k - $k;
  496. $j = $usat;
  497. $n = ($j - $k) / (24 * 3600);
  498. } else {
  499. $n = 2;
  500. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  501. }
  502. } else {
  503. $timedata = explode('|', $zdt);
  504. $ktime = strtotime($timedata[0]);
  505. $jtime = strtotime($timedata[1]);
  506. $ktime = $ktime - ($jtime - $ktime);
  507. $k = $ktime;
  508. $j = $jtime;
  509. $n = ($j - $k) / (24 * 3600);
  510. $usat = $jtime;
  511. }
  512. $time = array();
  513. $timeold = array();
  514. $stime = array();
  515. $dlznum = array();
  516. $smtnum = array();
  517. $ymoney = array();
  518. $money = array();
  519. $dlzmoneyb = array();
  520. $smtmoneyb = array();
  521. $ttmoneyb = array();
  522. $zkh = array();
  523. $dlzsl = 0;
  524. $dlzje = 0;
  525. $dlzssje = 0;
  526. $smtsl = 0;
  527. $smtje = 0;
  528. $smtssje = 0;
  529. $ttsl = 0;
  530. $ttje = 0;
  531. $ttssje = 0;
  532. $shopdata = array();
  533. $ys = $this->shop->find_all("status = 0 and 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' and id != '56' and id != '48'","*",'px asc');
  534. foreach ($ys as $v) {
  535. $shopdata[$v['id']] = array('id' => $v['id'], 'b' => $v['type'], 'fdl' => 0, 'chl' => 0, 'num' => 0, 'fgl' => 0);
  536. $zkh[$v['id']] = array();
  537. }
  538. for ($i = 1; $i < $n; $i++) {
  539. if ($n > 13 && $i > $n / 2 || $n < 14) {
  540. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  541. $time[] = date('m-d', $t);
  542. $ct = strtotime(date('Ymd', $t));
  543. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  544. $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');
  545. $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');
  546. $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');
  547. $amz = $this->fullorderamz->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');
  548. //数量及金额结束
  549. $sd = array_merge($dlz, $smt, $tt,$amz);
  550. $fgldata = array();
  551. foreach ($sd as $v) {
  552. if (isset($v['email'])) {
  553. if (!isset($fgldata[$v['shop'] . '-' . $v['email']])) {
  554. $fgldata[$v['shop'] . '-' . $v['email']] = 0;
  555. } else {
  556. $fgldata[$v['shop'] . '-' . $v['email']] += 1;
  557. }
  558. $zkh[$v['shop']][$v['email']] = array();
  559. } else {
  560. if (!isset($fgldata[$v['shop'] . '-' . $v['userid']])) {
  561. $fgldata[$v['shop'] . '-' . $v['userid']] = 0;
  562. } else {
  563. $fgldata[$v['shop'] . '-' . $v['userid']] += 1;
  564. }
  565. $zkh[$v['shop']][$v['userid']] = array();
  566. }
  567. }
  568. foreach ($sd as $v) {
  569. $chl = 0;
  570. if (isset($shopdata[$v['shop']])) {
  571. if (isset($v['email'])) {
  572. if (isset($customer[$v['shop'] . '-' . $v['email']]['num'])) {
  573. $fdl = $customer[$v['shop'] . '-' . $v['email']]['num'] > 1 ? 1 : 0;
  574. } else {
  575. $fdl = 0;
  576. }
  577. foreach ($ys as $vv) {
  578. if ($vv['id'] != $v['shop'] && isset($customer[$vv['id'] . '-' . $v['email']])) {
  579. $chl = 1;
  580. }
  581. }
  582. if (isset($fgldata[$v['shop'] . '-' . $v['email']])) {
  583. $fgl = $fgldata[$v['shop'] . '-' . $v['email']] > 0 ? 1 : 0;
  584. } else {
  585. $fgl = 0;
  586. }
  587. } else {
  588. if (isset($customersmt[$v['shop'] . '-' . $v['userid']]['num'])) {
  589. $fdl = $customersmt[$v['shop'] . '-' . $v['userid']]['num'] > 1 ? 1 : 0;
  590. } else {
  591. $fdl = 0;
  592. }
  593. foreach ($ys as $vv) {
  594. if ($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'] . '-' . $v['userid']])) {
  595. $chl = 1;
  596. }
  597. }
  598. if (isset($fgldata[$v['shop'] . '-' . $v['userid']])) {
  599. $fgl = $fgldata[$v['shop'] . '-' . $v['userid']] > 0 ? 1 : 0;
  600. } else {
  601. $fgl = 0;
  602. }
  603. }
  604. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl'] + $fdl;
  605. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl'] + $chl;
  606. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl'] + $fgl;
  607. $shopdata[$v['shop']]['num'] += 1;
  608. }
  609. }
  610. }
  611. }
  612. foreach ($shopdata as $k => $v) {
  613. $shopdata[$k]['fdl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['fdl'] / $v['num'] * 100)) . '%';
  614. $shopdata[$k]['chl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['chl'] / $v['num'] * 100)) . '%';
  615. $shopdata[$k]['fgl'] = count($zkh[$v['id']]) == '0' ? 0 : sprintf("%01.2f", ($v['fgl'] / count($zkh[$v['id']]) * 100)) . '%';
  616. }
  617. $shopdata = array_values($shopdata);
  618. echo @json_encode(array('shopdata' => $shopdata, 'success' => true));
  619. exit;
  620. }
  621. }
  622. if (isset($post['time'])) {
  623. $zdt = $this->input->post('time', true);
  624. $k = $zdt;
  625. $tab = $this->input->post('tab', true);
  626. $pdtime = date('Y-m-d-H', time());
  627. // if (is_file("./data/tj/" . $pdtime . ".txt") && $tab == 1 && $zdt > 172800) //前端改店内需要修改zdt 172800
  628. // {
  629. // $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  630. // $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  631. // fclose($myfile);
  632. // $bc = json_decode($bc, true);
  633. // echo json_encode($bc['tj'][$source][$zdt]);
  634. // exit;
  635. // } else {
  636. //$start = '2018-10-15';
  637. //$end = '2018-11-26';
  638. //$tim = strtotime($start);
  639. //$day = $time/(3600*24);
  640. if ($tab == '1') {
  641. if ($zdt >= 691200) {
  642. $k = $usat - $k - $k;
  643. $j = $usat;
  644. $n = ($j - $k) / (24 * 3600);
  645. } else {
  646. $n = 2;
  647. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  648. }
  649. } else {
  650. $timedata = explode('|', $zdt);
  651. $ktime = strtotime($timedata[0]);
  652. $jtime = strtotime($timedata[1]);
  653. $ktime = $ktime - ($jtime - $ktime);
  654. $k = $ktime;
  655. $j = $jtime;
  656. $n = ($j - $k) / (24 * 3600);
  657. $usat = $jtime;
  658. $tm = $jtime;
  659. $zdt = $jtime - $ktime;
  660. }
  661. $time = array();
  662. $timeold = array();
  663. $stime = array();
  664. $dlznum = array();
  665. $smtnum = array();
  666. $ymoney = array();
  667. $money = array();
  668. $dlzmoneyb = array();
  669. $smtmoneyb = array();
  670. $ttmoneyb = array();
  671. $zkh = array();
  672. $dlzsl = 0;
  673. $dlzje = 0;
  674. $dlzssje = 0;
  675. $smtsl = 0;
  676. $smtje = 0;
  677. $smtssje = 0;
  678. $ttsl = 0;
  679. $ttje = 0;
  680. $ttssje = 0;
  681. $amzsl = 0;
  682. $amzje = 0;
  683. $amzssje = 0;
  684. $shopdata = array();
  685. $ys = $this->shop->find_all("status = 0 and 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 != '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' and id != '56' and id != '48'","*",'px asc');
  686. foreach ($ys as $v) {
  687. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  688. }
  689. for ($i = 1; $i < $n; $i++) {
  690. //近7天时间
  691. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  692. if ($n > 13 && $i > $n / 2 || $n < 14) {
  693. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  694. $time[] = date('m-d', $t);
  695. $ct = strtotime(date('Ymd', $t));
  696. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  697. $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');
  698. $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');
  699. $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');
  700. $amz = $this->fullorderamz->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');
  701. $ab[] = $dlz;
  702. //数量及金额开始
  703. $dlznum[] = count($dlz);
  704. $smtnum[] = count($smt);
  705. $ttnum[] = count($smt);
  706. $amznum[] = count($amz);
  707. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  708. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  709. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  710. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  711. /**
  712. //提出退款关闭等信息的实收金额
  713. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  714. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  715. //提出退款关闭等信息的实收金额
  716. **/
  717. //实收金额
  718. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  719. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  720. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  721. $amzmss = sprintf("%01.2f", array_sum(array_column($amz, 'budget')));
  722. //实收金额
  723. //补/退原额
  724. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  725. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  726. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  727. $amzbty = sprintf("%01.2f", array_sum(array_column($amz, 'refundy')));
  728. //补/退原额
  729. $dlzmoney[] = $dlzm;
  730. $smtmoney[] = $smtm;
  731. $ttmoney[] = $ttm;
  732. $amzmoney[] = $amzm;
  733. $dlzsl += count($dlz);
  734. $dlzje += $dlzm;
  735. $smtsl += count($smt);
  736. $smtje += $smtm;
  737. $ttsl += count($tt);
  738. $ttje += $ttm;
  739. $amzsl += count($amz);
  740. $amzje += $amzm;
  741. /**
  742. //减去的实收金额
  743. $dlzssje += $dlzm+$dlzmss;
  744. $smtssje += $smtm+$smtmss;
  745. **/
  746. //实收和补/退
  747. $dlzssje += $dlzmss + $dlzbty;
  748. $smtssje += $smtmss + $smtbty;
  749. $ttssje += $ttmss + $ttbty;
  750. $amzssje += $amzmss + $amzbty;
  751. //数量及金额结束
  752. $sd = array_merge($dlz, $smt, $tt,$amz);
  753. foreach ($sd as $v) {
  754. if (isset($shopdata[$v['shop']])) {
  755. $shopdata[$v['shop']]['num'] += 1;
  756. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  757. $shopdata[$v['shop']]['tmoney'] += $v['budget'] + $v['refundy'];
  758. }
  759. }
  760. } else if ($n > 13 && $i <= $n / 2) {
  761. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  762. $timeold[] = date('m-d', $t);
  763. $ct = strtotime(date('Ymd', $t));
  764. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  765. $dlz = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  766. $smt = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  767. $tt = $this->fullordertt->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  768. $amz = $this->fullorderamz->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  769. //数量及金额开始
  770. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  771. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  772. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  773. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  774. $dlzmoneyb[] = $dlzm;
  775. $smtmoneyb[] = $smtm;
  776. $ttmoneyb[] = $ttm;
  777. $amzmoneyb[] = $amzm;
  778. //数量及金额结束
  779. }
  780. }
  781. foreach ($shopdata as $k => $v) {
  782. $sn = $this->shop->read($k);
  783. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  784. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  785. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  786. $shopdata[$k]['name'] = $sn['shopname'];
  787. $shopdata[$k]['b'] = $sn['type'];
  788. $shopdata[$k]['id'] = $sn['id'];
  789. }
  790. $shopdata = array_values($shopdata);
  791. //$sycp=array();
  792. /**
  793. //根据所选时间产品排行开始
  794. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  795. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  796. **/
  797. /**
  798. //昨日产品排行开始
  799. $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');
  800. $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');
  801. $rows = array_merge($dlzlist,$smtlist);
  802. foreach ($rows as $v)
  803. {
  804. $number = explode('|',trim($v['whlabel'],'|'));
  805. $or = explode(';',trim($v['fpdata'],';'));
  806. $i=0;
  807. foreach ($or as $va)
  808. {
  809. $ord = explode('|',$va);
  810. $orod = explode(',',$ord[0]);
  811. $numberod = explode('-',$number[$i]);
  812. if(!isset($orod[1]))
  813. {
  814. continue;
  815. }
  816. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  817. {
  818. //$sycp[$orod[1]][0] += 1;//统计多少单
  819. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  820. $sycp[$orod[1]][1] += 0;//价格
  821. }
  822. else
  823. {
  824. if(isset($numberod[1]))
  825. {
  826. $typeclass = $this->typeclass->read($orod['0']);
  827. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  828. }
  829. }
  830. $i++;
  831. }
  832. }
  833. arsort($sycp);
  834. $sycp = array_values($sycp);
  835. $sycp = array_slice($sycp,0,10);
  836. //产品排行结束
  837. **/
  838. //当时实时数据结束
  839. echo @json_encode(array('time' => $time, 'timeold' => $timeold, 'smtnum' => $smtnum, 'ttnum' => $ttnum,'amznum'=>$amznum ,'dlznum' => $dlznum, 'smtmoney' => $smtmoney, 'ttmoney' => $ttmoney, 'amzmoney'=>$amzmoney,'dlzmoney' => $dlzmoney, 'smtmoneyb' => $smtmoneyb, 'ttmoneyb' => $ttmoneyb,'amzmoneyb' => $amzmoneyb ,'dlzmoneyb' => $dlzmoneyb, 'dlzsl' => $dlzsl, 'dlzje' => number_format($dlzje, 2), 'dlzssje' => number_format($dlzssje, 2), 'smtsl' => $smtsl,'amzsl' => $amzsl ,'ttsl' => $ttsl, 'smtje' => number_format($smtje, 2),'amzje' => number_format($amzje, 2), 'ttje' => number_format($ttje, 2), 'smtssje' => number_format($smtssje, 2),'amzssje' => number_format($amzssje, 2), 'ttssje' => number_format($ttssje, 2), 'zje' => number_format($dlzje + $smtje + $ttje + $amzje, 2), 'zsl' => $dlzsl + $smtsl + $ttsl + $amzsl, 'shopdata' => $shopdata, 'success' => true));
  840. exit; //,'sycp'=>$sycp昨日产品数据
  841. }
  842. //}
  843. if (isset($post['sstime'])) {
  844. $shop = $this->input->post('shop', true);
  845. $zdtime = $usat;
  846. //当时实时数据开始
  847. if (!$shop) {
  848. $sssl = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  849. $ssje = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  850. $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');
  851. $amzje = $this->fullorderamz->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  852. $sssldlz = count($sssl);
  853. $ssslsmt = count($ssje);
  854. $sssltt = count($tje);
  855. $ssslamz = count($amzje);
  856. $ssjedlz = sprintf("%01.2f", array_sum(array_column($sssl, 'budget')));
  857. $ssjesmt = sprintf("%01.2f", array_sum(array_column($ssje, 'budget')));
  858. $ssjett = sprintf("%01.2f", array_sum(array_column($tje, 'budget')));
  859. $ssjeamz = sprintf("%01.2f", array_sum(array_column($amzje, 'budget')));
  860. $sssl = $sssldlz + $ssslsmt + $sssltt + $ssslamz;
  861. $ssje = $ssjedlz + $ssjesmt + $ssjett + $ssjeamz;
  862. } else {
  863. $sp = $this->shop->read($shop);
  864. if($sp['type'] == '1513'){
  865. $fu = 'fullorderamz';
  866. }elseif($sp['type'] == '270'){
  867. $fu = 'fullordersmt';
  868. }elseif($sp['type'] == '1514'){
  869. $fu = 'fullordertt';
  870. }else{
  871. $fu = 'fullorder';
  872. }
  873. //1513
  874. //$fu = ($sp['type'] == '269') ? 'fullorder' : 'fullordersmt';
  875. $ss = $this->$fu->find_all("dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . " and shop = '" . $shop . "'", 'budget,shouldmoney');
  876. $sssl = count($ss);
  877. $ssje = sprintf("%01.2f", array_sum(array_column($ss, 'budget')));
  878. }
  879. echo @json_encode(array('sstime' => date('m-d H:i', time()), 'sssl' => $sssl, 'ssje' => sprintf("%.2f", $ssje), 'success' => true));
  880. exit;
  881. }
  882. //店铺产品详情
  883. if (isset($post['id'])) {
  884. $tm += 24 * 3600;
  885. $gshtime = date('Y-m-d 0:0:0', time());
  886. $gshtime = strtotime($gshtime) + 24 * 60 * 60;
  887. $dpxq = array();
  888. $id = $this->input->post('id', true);
  889. $xqtime = $this->input->post('xqtime', true);
  890. $xqshop = $this->shop->read($id);
  891. if ($xqshop['type'] == "269" || $xqshop['type'] == "2768") {
  892. $sid = 'fullorder';
  893. } else if ($xqshop['type'] == "270") {
  894. $sid = 'fullordersmt';
  895. } else if ($xqshop['type'] == "1513") {
  896. $sid = 'fullorderamz';
  897. }else if ($xqshop['type'] == "1514") {
  898. $sid = 'fullordertt';
  899. }
  900. if ($xqtime > 345600) {
  901. $rows = $this->$sid->find_all("shop = '" . $id . "' and dtime >= '" . ($gshtime - $xqtime) . "' and dtime <= '" . ($gshtime + 24 * 60 * 60) . "'", 'whlabel,fpdata,number');
  902. } else {
  903. $rows = $this->$sid->find_all("shop = '" . $id . "' and dtime >= '" . ($gshtime - $xqtime) . "' and dtime <= '" . ($gshtime + 24 * 60 * 60 - $xqtime) . "'", 'whlabel,fpdata,number');
  904. }
  905. foreach ($rows as $v) {
  906. $or = explode('|', ltrim($v['whlabel'], '|'));
  907. for ($i = 0; $i < count($or); $i++) {
  908. $orod = explode('-', $or[$i]);
  909. if ($orod[0] == '') {
  910. continue;
  911. }
  912. if (isset($dpxq[$orod[0]])) {
  913. $dpxq[$orod[0]][0] += $orod[1]; //统计多少条
  914. //$dpxq[$orod[0]][0] += 1;//统计多少单
  915. $dpxq[$orod[0]][1] .= $v['number'] . ';'; //价格
  916. } else {
  917. $oo = explode(';', rtrim($v['fpdata'], ';'));
  918. @$ro = explode('|', $oo[$i]);
  919. if (isset($ro[1])) {
  920. $dpxq[$orod[0]] = array($orod[1], $v['number'] . ';', $ro[1]); //统计多少条
  921. //$dpxq[$orod[0]] = array(1,0,$ro[1]);//统计多少单
  922. }
  923. }
  924. }
  925. }
  926. $dpxq = array_values($dpxq);
  927. arsort($dpxq);
  928. $dpxq = array_slice($dpxq, 0, 9999);
  929. echo @json_encode(array('dpxq' => $dpxq, 'success' => true));
  930. exit;
  931. }
  932. $wlshop = $this->shop->find_all('status = 0 and ' . rtrim($sid, 'or'));
  933. $this->data['wlshop'] = $wlshop;
  934. $dr = $usat;
  935. $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));
  936. $this->_Template('phone/p_user_statistics_two', $this->data);
  937. }
  938. //默认页
  939. public function _statistics()
  940. {
  941. /**
  942. $order = $this->order->get_w();
  943. $order = count($order);//查询订单未处理数量
  944. $message = $this->message->get_w();
  945. $message = count($message);//查询留言未处理数量
  946. $this->_Template('default',$this->data);
  947. **/
  948. //date_default_timezone_set("Etc/GMT+8");
  949. $dt = 0;
  950. if (isset($_SESSION['api'])) {
  951. $user = $this->user->get_api($_SESSION['api']);
  952. $usp = $user;
  953. $fgshop = "";
  954. $sid = "";
  955. $user = explode('|', trim($user['shop'], '|'));
  956. foreach ($user as $value) {
  957. // 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')
  958. // {
  959. // $fgshop .= " shop = ".$value." or";
  960. // }
  961. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56,48])) {
  962. $fgshop .= " shop = " . $value . " or";
  963. }
  964. $sid .= " id = " . $value . " or";
  965. }
  966. }
  967. $post = $this->input->post(NULL, TRUE);
  968. $source = $this->input->post('source', true);
  969. $where = "";
  970. if ($source) {
  971. if ($source == '2d') {
  972. $where = " and source >= '2'";
  973. } else {
  974. $where = " and source = '$source'";
  975. }
  976. }
  977. $tm = strtotime(date("Ymd"), time());
  978. $usat = $tm;
  979. if (isset($post['zhcx'])) {
  980. $zdt = $this->input->post('time', true);
  981. $k = $zdt;
  982. $tab = $this->input->post('tab', true);
  983. $pdtime = date('Y-m-d-H', time());
  984. if (is_file("./data/tj/" . $pdtime . ".txt") && $tab == 1 && $zdt > 172800) {
  985. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  986. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  987. fclose($myfile);
  988. $bc = json_decode($bc, true);
  989. echo json_encode($bc['zhcx'][$source][$zdt]);
  990. exit;
  991. } else {
  992. $customer = $this->customer->find_all("shop !=''", 'num,zhcx');
  993. $customerkey = array_column($customer, 'zhcx');
  994. $customer = array_combine($customerkey, $customer);
  995. $customersmt = $this->customersmt->find_all("shop !=''", 'num,zhcx');
  996. $customersmtkey = array_column($customersmt, 'zhcx');
  997. $customersmt = array_combine($customersmtkey, $customersmt);
  998. //$start = '2018-10-15';
  999. //$end = '2018-11-26';
  1000. //$tim = strtotime($start);
  1001. //$day = $time/(3600*24);
  1002. if ($tab == '1') {
  1003. if ($zdt >= 691200) {
  1004. $k = $usat - $k - $k;
  1005. $j = $usat;
  1006. $n = ($j - $k) / (24 * 3600);
  1007. } else {
  1008. $n = 2;
  1009. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  1010. }
  1011. } else {
  1012. $timedata = explode('|', $zdt);
  1013. $ktime = strtotime($timedata[0]);
  1014. $jtime = strtotime($timedata[1]);
  1015. $ktime = $ktime - ($jtime - $ktime);
  1016. $k = $ktime;
  1017. $j = $jtime;
  1018. $n = ($j - $k) / (24 * 3600);
  1019. $usat = $jtime;
  1020. }
  1021. $time = array();
  1022. $timeold = array();
  1023. $stime = array();
  1024. $dlznum = array();
  1025. $smtnum = array();
  1026. $ymoney = array();
  1027. $money = array();
  1028. $dlzmoneyb = array();
  1029. $smtmoneyb = array();
  1030. $ttmoneyb = array();
  1031. $zkh = array();
  1032. $dlzsl = 0;
  1033. $dlzje = 0;
  1034. $dlzssje = 0;
  1035. $smtsl = 0;
  1036. $smtje = 0;
  1037. $smtssje = 0;
  1038. $ttsl = 0;
  1039. $ttje = 0;
  1040. $ttssje = 0;
  1041. $shopdata = array();
  1042. $ys = $this->shop->find_all("status = 0 and 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' and id != '56' and id != '48'","*",'px asc');
  1043. foreach ($ys as $v) {
  1044. $shopdata[$v['id']] = array('id' => $v['id'], 'b' => $v['type'], 'fdl' => 0, 'chl' => 0, 'num' => 0, 'fgl' => 0);
  1045. $zkh[$v['id']] = array();
  1046. }
  1047. for ($i = 1; $i < $n; $i++) {
  1048. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1049. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1050. $time[] = date('m-d', $t);
  1051. $ct = strtotime(date('Ymd', $t));
  1052. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1053. $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');
  1054. $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');
  1055. $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');
  1056. $amz = $this->fullorderamz->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');
  1057. //数量及金额结束
  1058. $sd = array_merge($dlz, $smt, $tt,$amz);
  1059. $fgldata = array();
  1060. foreach ($sd as $v) {
  1061. if (isset($v['email'])) {
  1062. if (!isset($fgldata[$v['shop'] . '-' . $v['email']])) {
  1063. $fgldata[$v['shop'] . '-' . $v['email']] = 0;
  1064. } else {
  1065. $fgldata[$v['shop'] . '-' . $v['email']] += 1;
  1066. }
  1067. $zkh[$v['shop']][$v['email']] = array();
  1068. } else {
  1069. if (!isset($fgldata[$v['shop'] . '-' . $v['userid']])) {
  1070. $fgldata[$v['shop'] . '-' . $v['userid']] = 0;
  1071. } else {
  1072. $fgldata[$v['shop'] . '-' . $v['userid']] += 1;
  1073. }
  1074. $zkh[$v['shop']][$v['userid']] = array();
  1075. }
  1076. }
  1077. foreach ($sd as $v) {
  1078. $chl = 0;
  1079. if (isset($shopdata[$v['shop']])) {
  1080. if (isset($v['email'])) {
  1081. if (isset($customer[$v['shop'] . '-' . $v['email']]['num'])) {
  1082. $fdl = $customer[$v['shop'] . '-' . $v['email']]['num'] > 1 ? 1 : 0;
  1083. } else {
  1084. $fdl = 0;
  1085. }
  1086. foreach ($ys as $vv) {
  1087. if ($vv['id'] != $v['shop'] && isset($customer[$vv['id'] . '-' . $v['email']])) {
  1088. $chl = 1;
  1089. }
  1090. }
  1091. if (isset($fgldata[$v['shop'] . '-' . $v['email']])) {
  1092. $fgl = $fgldata[$v['shop'] . '-' . $v['email']] > 0 ? 1 : 0;
  1093. } else {
  1094. $fgl = 0;
  1095. }
  1096. } else {
  1097. if (isset($customersmt[$v['shop'] . '-' . $v['userid']]['num'])) {
  1098. $fdl = $customersmt[$v['shop'] . '-' . $v['userid']]['num'] > 1 ? 1 : 0;
  1099. } else {
  1100. $fdl = 0;
  1101. }
  1102. foreach ($ys as $vv) {
  1103. if ($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'] . '-' . $v['userid']])) {
  1104. $chl = 1;
  1105. }
  1106. }
  1107. if (isset($fgldata[$v['shop'] . '-' . $v['userid']])) {
  1108. $fgl = $fgldata[$v['shop'] . '-' . $v['userid']] > 0 ? 1 : 0;
  1109. } else {
  1110. $fgl = 0;
  1111. }
  1112. }
  1113. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl'] + $fdl;
  1114. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl'] + $chl;
  1115. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl'] + $fgl;
  1116. $shopdata[$v['shop']]['num'] += 1;
  1117. }
  1118. }
  1119. }
  1120. }
  1121. foreach ($shopdata as $k => $v) {
  1122. $shopdata[$k]['fdl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['fdl'] / $v['num'] * 100)) . '%';
  1123. $shopdata[$k]['chl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['chl'] / $v['num'] * 100)) . '%';
  1124. $shopdata[$k]['fgl'] = count($zkh[$v['id']]) == '0' ? 0 : sprintf("%01.2f", ($v['fgl'] / count($zkh[$v['id']]) * 100)) . '%';
  1125. }
  1126. $shopdata = array_values($shopdata);
  1127. echo @json_encode(array('shopdata' => $shopdata, 'success' => true));
  1128. exit;
  1129. }
  1130. }
  1131. if (isset($post['time'])) {
  1132. $zdt = $this->input->post('time', true);
  1133. $k = $zdt;
  1134. $tab = $this->input->post('tab', true);
  1135. $pdtime = date('Y-m-d-H', time());
  1136. // if (is_file("./data/tj/" . $pdtime . ".txt") && $tab == 1 && $zdt > 172800) //前端改店内需要修改zdt 172800
  1137. // {
  1138. // $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  1139. // $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  1140. // fclose($myfile);
  1141. // $bc = json_decode($bc, true);
  1142. // echo json_encode($bc['tj'][$source][$zdt]);
  1143. // exit;
  1144. // } else {
  1145. //$start = '2018-10-15';
  1146. //$end = '2018-11-26';
  1147. //$tim = strtotime($start);
  1148. //$day = $time/(3600*24);
  1149. if ($tab == '1') {
  1150. $this->_statistics_sjc($fgshop,$zdt,$where,$k,$usat);
  1151. } else {
  1152. $this->_statistics_sjd($fgshop,$zdt,$where,$k,$usat);
  1153. }
  1154. }
  1155. //}
  1156. if (isset($post['sstime'])) {
  1157. $shop = $this->input->post('shop', true);
  1158. $zdtime = $usat;
  1159. //当时实时数据开始
  1160. if (!$shop) {
  1161. $sssl = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  1162. $ssje = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  1163. $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');
  1164. $amzje = $this->fullorderamz->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  1165. $sssldlz = count($sssl);
  1166. $ssslsmt = count($ssje);
  1167. $sssltt = count($tje);
  1168. $ssslamz = count($amzje);
  1169. $ssjedlz = sprintf("%01.2f", array_sum(array_column($sssl, 'budget')));
  1170. $ssjesmt = sprintf("%01.2f", array_sum(array_column($ssje, 'budget')));
  1171. $ssjett = sprintf("%01.2f", array_sum(array_column($tje, 'budget')));
  1172. $ssjeamz = sprintf("%01.2f", array_sum(array_column($amzje, 'budget')));
  1173. $sssl = $sssldlz + $ssslsmt + $sssltt + $ssslamz;
  1174. $ssje = $ssjedlz + $ssjesmt + $ssjett + $ssjeamz;
  1175. } else {
  1176. $sp = $this->shop->read($shop);
  1177. if($sp['type'] == '1513'){
  1178. $fu = 'fullorderamz';
  1179. }elseif($sp['type'] == '270'){
  1180. $fu = 'fullordersmt';
  1181. }elseif($sp['type'] == '1514'){
  1182. $fu = 'fullordertt';
  1183. }else{
  1184. $fu = 'fullorder';
  1185. }
  1186. //1513
  1187. //$fu = ($sp['type'] == '269') ? 'fullorder' : 'fullordersmt';
  1188. $ss = $this->$fu->find_all("dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . " and shop = '" . $shop . "'", 'budget,shouldmoney');
  1189. $sssl = count($ss);
  1190. $ssje = sprintf("%01.2f", array_sum(array_column($ss, 'budget')));
  1191. }
  1192. echo @json_encode(array('sstime' => date('m-d H:i', time()), 'sssl' => $sssl, 'ssje' => sprintf("%.2f", $ssje), 'success' => true));
  1193. exit;
  1194. }
  1195. //店铺产品详情
  1196. if (isset($post['id'])) {
  1197. $tm += 24 * 3600;
  1198. $gshtime = date('Y-m-d 0:0:0', time());
  1199. $gshtime = strtotime($gshtime) + 24 * 60 * 60;
  1200. $dpxq = array();
  1201. $id = $this->input->post('id', true);
  1202. $xqtime = $this->input->post('xqtime', true);
  1203. $xqshop = $this->shop->read($id);
  1204. if ($xqshop['type'] == "269" || $xqshop['type'] == "2768") {
  1205. $sid = 'fullorder';
  1206. } else if ($xqshop['type'] == "270") {
  1207. $sid = 'fullordersmt';
  1208. } else if ($xqshop['type'] == "1513") {
  1209. $sid = 'fullorderamz';
  1210. }else if ($xqshop['type'] == "1514") {
  1211. $sid = 'fullordertt';
  1212. }
  1213. if ($xqtime > 345600) {
  1214. $rows = $this->$sid->find_all("shop = '" . $id . "' and dtime >= '" . ($gshtime - $xqtime) . "' and dtime <= '" . ($gshtime + 24 * 60 * 60) . "'", 'whlabel,fpdata,number');
  1215. } else {
  1216. $rows = $this->$sid->find_all("shop = '" . $id . "' and dtime >= '" . ($gshtime - $xqtime) . "' and dtime <= '" . ($gshtime + 24 * 60 * 60 - $xqtime) . "'", 'whlabel,fpdata,number');
  1217. }
  1218. foreach ($rows as $v) {
  1219. $or = explode('|', ltrim($v['whlabel'], '|'));
  1220. for ($i = 0; $i < count($or); $i++) {
  1221. $orod = explode('-', $or[$i]);
  1222. if ($orod[0] == '') {
  1223. continue;
  1224. }
  1225. if (isset($dpxq[$orod[0]])) {
  1226. $dpxq[$orod[0]][0] += $orod[1]; //统计多少条
  1227. //$dpxq[$orod[0]][0] += 1;//统计多少单
  1228. $dpxq[$orod[0]][1] .= $v['number'] . ';'; //价格
  1229. } else {
  1230. $oo = explode(';', rtrim($v['fpdata'], ';'));
  1231. @$ro = explode('|', $oo[$i]);
  1232. if (isset($ro[1])) {
  1233. $dpxq[$orod[0]] = array($orod[1], $v['number'] . ';', $ro[1]); //统计多少条
  1234. //$dpxq[$orod[0]] = array(1,0,$ro[1]);//统计多少单
  1235. }
  1236. }
  1237. }
  1238. }
  1239. $dpxq = array_values($dpxq);
  1240. arsort($dpxq);
  1241. $dpxq = array_slice($dpxq, 0, 9999);
  1242. echo @json_encode(array('dpxq' => $dpxq, 'success' => true));
  1243. exit;
  1244. }
  1245. $wlshop = $this->shop->find_all('status = 0 and ' . rtrim($sid, 'or'));
  1246. $this->data['wlshop'] = $wlshop;
  1247. $dr = $usat;
  1248. $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));
  1249. $this->_Template('phone/p_user_statistics_two', $this->data);
  1250. }
  1251. //统计的时间戳
  1252. protected function _statistics_sjc($fgshop,$zdt,$where,$k,$usat){
  1253. if ($zdt >= 691200) {
  1254. $k = $usat - $k - $k;
  1255. $j = $usat;
  1256. $n = ($j - $k) / (24 * 3600);
  1257. $usat = $usat + 24 * 3600;
  1258. } else {
  1259. $n = 2;
  1260. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  1261. }
  1262. $time = array();
  1263. $timeold = array();
  1264. $stime = array();
  1265. $dlznum = array();
  1266. $smtnum = array();
  1267. $ymoney = array();
  1268. $money = array();
  1269. $dlzmoneyb = array();
  1270. $smtmoneyb = array();
  1271. $ttmoneyb = array();
  1272. $zkh = array();
  1273. $dlzsl = 0;
  1274. $dlzje = 0;
  1275. $dlzssje = 0;
  1276. $smtsl = 0;
  1277. $smtje = 0;
  1278. $smtssje = 0;
  1279. $ttsl = 0;
  1280. $ttje = 0;
  1281. $ttssje = 0;
  1282. $amzsl = 0;
  1283. $amzje = 0;
  1284. $amzssje = 0;
  1285. $shopdata = array();
  1286. $ys = $this->shop->find_all("status = 0 and 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 != '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' and id != '56' and id != '48'","*",'px asc');
  1287. foreach ($ys as $v) {
  1288. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  1289. }
  1290. for ($i = 1; $i < $n; $i++) {
  1291. //近7天时间
  1292. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1293. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1294. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1295. $time[] = date('m-d', $t);
  1296. $ct = strtotime(date('Ymd', $t));
  1297. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1298. //var_dump(date("Y-m-d H:i:s",$ct)."=================".date("Y-m-d H:i:s",$ctj));
  1299. $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');
  1300. $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');
  1301. $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');
  1302. $amz = $this->fullorderamz->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');
  1303. $ab[] = $dlz;
  1304. //数量及金额开始
  1305. $dlznum[] = count($dlz);
  1306. $smtnum[] = count($smt);
  1307. $ttnum[] = count($smt);
  1308. $amznum[] = count($amz);
  1309. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1310. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1311. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1312. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  1313. /**
  1314. //提出退款关闭等信息的实收金额
  1315. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1316. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1317. //提出退款关闭等信息的实收金额
  1318. **/
  1319. //实收金额
  1320. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  1321. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  1322. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  1323. $amzmss = sprintf("%01.2f", array_sum(array_column($amz, 'budget')));
  1324. //实收金额
  1325. //补/退原额
  1326. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  1327. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  1328. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  1329. $amzbty = sprintf("%01.2f", array_sum(array_column($amz, 'refundy')));
  1330. //补/退原额
  1331. $dlzmoney[] = $dlzm;
  1332. $smtmoney[] = $smtm;
  1333. $ttmoney[] = $ttm;
  1334. $amzmoney[] = $amzm;
  1335. $dlzsl += count($dlz);
  1336. $dlzje += $dlzm;
  1337. $smtsl += count($smt);
  1338. $smtje += $smtm;
  1339. $ttsl += count($tt);
  1340. $ttje += $ttm;
  1341. $amzsl += count($amz);
  1342. $amzje += $amzm;
  1343. /**
  1344. //减去的实收金额
  1345. $dlzssje += $dlzm+$dlzmss;
  1346. $smtssje += $smtm+$smtmss;
  1347. **/
  1348. //实收和补/退
  1349. $dlzssje += $dlzmss + $dlzbty;
  1350. $smtssje += $smtmss + $smtbty;
  1351. $ttssje += $ttmss + $ttbty;
  1352. $amzssje += $amzmss + $amzbty;
  1353. //数量及金额结束
  1354. $sd = array_merge($dlz, $smt, $tt,$amz);
  1355. foreach ($sd as $v) {
  1356. if (isset($shopdata[$v['shop']])) {
  1357. $shopdata[$v['shop']]['num'] += 1;
  1358. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  1359. $shopdata[$v['shop']]['tmoney'] += $v['budget'] + $v['refundy'];
  1360. }
  1361. }
  1362. } else if ($n > 13 && $i <= $n / 2) {
  1363. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1364. $timeold[] = date('m-d', $t);
  1365. $ct = strtotime(date('Ymd', $t));
  1366. $ctj = strtotime(date('Ymd', $t + 24 * 3600)) ;
  1367. //var_dump(date("Y-m-d H:i:s",$ct)."------------------------".date("Y-m-d H:i:s",$ctj));
  1368. $dlz = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1369. $smt = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1370. $tt = $this->fullordertt->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1371. $amz = $this->fullorderamz->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1372. //数量及金额开始
  1373. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1374. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1375. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1376. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  1377. $dlzmoneyb[] = $dlzm;
  1378. $smtmoneyb[] = $smtm;
  1379. $ttmoneyb[] = $ttm;
  1380. $amzmoneyb[] = $amzm;
  1381. //数量及金额结束
  1382. }
  1383. }
  1384. foreach ($shopdata as $k => $v) {
  1385. $sn = $this->shop->read($k);
  1386. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  1387. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  1388. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  1389. $shopdata[$k]['name'] = $sn['shopname'];
  1390. $shopdata[$k]['b'] = $sn['type'];
  1391. $shopdata[$k]['id'] = $sn['id'];
  1392. }
  1393. $shopdata = array_values($shopdata);
  1394. //$sycp=array();
  1395. /**
  1396. //根据所选时间产品排行开始
  1397. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1398. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1399. **/
  1400. /**
  1401. //昨日产品排行开始
  1402. $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');
  1403. $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');
  1404. $rows = array_merge($dlzlist,$smtlist);
  1405. foreach ($rows as $v)
  1406. {
  1407. $number = explode('|',trim($v['whlabel'],'|'));
  1408. $or = explode(';',trim($v['fpdata'],';'));
  1409. $i=0;
  1410. foreach ($or as $va)
  1411. {
  1412. $ord = explode('|',$va);
  1413. $orod = explode(',',$ord[0]);
  1414. $numberod = explode('-',$number[$i]);
  1415. if(!isset($orod[1]))
  1416. {
  1417. continue;
  1418. }
  1419. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  1420. {
  1421. //$sycp[$orod[1]][0] += 1;//统计多少单
  1422. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  1423. $sycp[$orod[1]][1] += 0;//价格
  1424. }
  1425. else
  1426. {
  1427. if(isset($numberod[1]))
  1428. {
  1429. $typeclass = $this->typeclass->read($orod['0']);
  1430. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  1431. }
  1432. }
  1433. $i++;
  1434. }
  1435. }
  1436. arsort($sycp);
  1437. $sycp = array_values($sycp);
  1438. $sycp = array_slice($sycp,0,10);
  1439. //产品排行结束
  1440. **/
  1441. //当时实时数据结束
  1442. echo @json_encode(array('time' => $time, 'timeold' => $timeold, 'smtnum' => $smtnum, 'ttnum' => $ttnum,'amznum'=>$amznum ,'dlznum' => $dlznum, 'smtmoney' => $smtmoney, 'ttmoney' => $ttmoney, 'amzmoney'=>$amzmoney,'dlzmoney' => $dlzmoney, 'smtmoneyb' => $smtmoneyb, 'ttmoneyb' => $ttmoneyb,'amzmoneyb' => $amzmoneyb ,'dlzmoneyb' => $dlzmoneyb, 'dlzsl' => $dlzsl, 'dlzje' => number_format($dlzje, 2), 'dlzssje' => number_format($dlzssje, 2), 'smtsl' => $smtsl,'amzsl' => $amzsl ,'ttsl' => $ttsl, 'smtje' => number_format($smtje, 2),'amzje' => number_format($amzje, 2), 'ttje' => number_format($ttje, 2), 'smtssje' => number_format($smtssje, 2),'amzssje' => number_format($amzssje, 2), 'ttssje' => number_format($ttssje, 2), 'zje' => number_format($dlzje + $smtje + $ttje + $amzje, 2), 'zsl' => $dlzsl + $smtsl + $ttsl + $amzsl, 'shopdata' => $shopdata, 'success' => true));
  1443. exit; //,'sycp'=>$sycp昨日产品数据
  1444. }
  1445. //统计的时间段
  1446. protected function _statistics_sjd($fgshop,$zdt,$where,$k,$usat){
  1447. $timedata = explode('|', $zdt);
  1448. $ktime = strtotime($timedata[0]);
  1449. $jtime = strtotime($timedata[1]);
  1450. $ktime = $ktime - ($jtime - $ktime);
  1451. $k = $ktime;
  1452. $j = $jtime;
  1453. $n = ($j - $k) / (24 * 3600);
  1454. $usat = $jtime;
  1455. $tm = $jtime;
  1456. $zdt = $jtime - $ktime;
  1457. $time = array();
  1458. $timeold = array();
  1459. $stime = array();
  1460. $dlznum = array();
  1461. $smtnum = array();
  1462. $ymoney = array();
  1463. $money = array();
  1464. $dlzmoneyb = array();
  1465. $smtmoneyb = array();
  1466. $ttmoneyb = array();
  1467. $zkh = array();
  1468. $dlzsl = 0;
  1469. $dlzje = 0;
  1470. $dlzssje = 0;
  1471. $smtsl = 0;
  1472. $smtje = 0;
  1473. $smtssje = 0;
  1474. $ttsl = 0;
  1475. $ttje = 0;
  1476. $ttssje = 0;
  1477. $amzsl = 0;
  1478. $amzje = 0;
  1479. $amzssje = 0;
  1480. $shopdata = array();
  1481. $ys = $this->shop->find_all("status = 0 and 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 != '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' and id != '56' and id != '48'", "*", 'px asc');
  1482. foreach ($ys as $v) {
  1483. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  1484. }
  1485. // [修复 2] 循环边界:i=1 → i=0;< n → <= n
  1486. for ($i = 0; $i <= $n; $i++) {
  1487. //近7天时间
  1488. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1489. // [修复 2] 主分支条件:i > n/2 → i >= n/2
  1490. if ($n > 13 && $i >= $n / 2 || $n < 14) {
  1491. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1492. $time[] = date('m-d', $t);
  1493. $ct = strtotime(date('Ymd', $t));
  1494. // [修复 3] $ctj 减 1 秒
  1495. $ctj = strtotime(date('Ymd', $t + 24 * 3600)) ;
  1496. $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');
  1497. $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');
  1498. $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');
  1499. $amz = $this->fullorderamz->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');
  1500. $ab[] = $dlz;
  1501. //数量及金额开始
  1502. $dlznum[] = count($dlz);
  1503. $smtnum[] = count($smt);
  1504. $ttnum[] = count($smt);
  1505. $amznum[] = count($amz);
  1506. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1507. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1508. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1509. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  1510. /**
  1511. //提出退款关闭等信息的实收金额
  1512. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1513. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1514. //提出退款关闭等信息的实收金额
  1515. **/
  1516. //实收金额
  1517. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  1518. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  1519. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  1520. $amzmss = sprintf("%01.2f", array_sum(array_column($amz, 'budget')));
  1521. //实收金额
  1522. //补/退原额
  1523. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  1524. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  1525. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  1526. $amzbty = sprintf("%01.2f", array_sum(array_column($amz, 'refundy')));
  1527. //补/退原额
  1528. $dlzmoney[] = $dlzm;
  1529. $smtmoney[] = $smtm;
  1530. $ttmoney[] = $ttm;
  1531. $amzmoney[] = $amzm;
  1532. $dlzsl += count($dlz);
  1533. $dlzje += $dlzm;
  1534. $smtsl += count($smt);
  1535. $smtje += $smtm;
  1536. $ttsl += count($tt);
  1537. $ttje += $ttm;
  1538. $amzsl += count($amz);
  1539. $amzje += $amzm;
  1540. /**
  1541. //减去的实收金额
  1542. $dlzssje += $dlzm+$dlzmss;
  1543. $smtssje += $smtm+$smtmss;
  1544. **/
  1545. //实收和补/退
  1546. $dlzssje += $dlzmss + $dlzbty;
  1547. $smtssje += $smtmss + $smtbty;
  1548. $ttssje += $ttmss + $ttbty;
  1549. $amzssje += $amzmss + $amzbty;
  1550. //数量及金额结束
  1551. $sd = array_merge($dlz, $smt, $tt, $amz);
  1552. foreach ($sd as $v) {
  1553. if (isset($shopdata[$v['shop']])) {
  1554. $shopdata[$v['shop']]['num'] += 1;
  1555. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  1556. $shopdata[$v['shop']]['tmoney'] += $v['budget'] + $v['refundy'];
  1557. }
  1558. }
  1559. }
  1560. // [修复 4] 对比周期条件:i <= n/2 → i < n/2
  1561. else if ($n > 13 && $i < $n / 2) {
  1562. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1563. $timeold[] = date('m-d', $t);
  1564. $ct = strtotime(date('Ymd', $t));
  1565. // [修复 3] $ctj 减 1 秒
  1566. $ctj = strtotime(date('Ymd', $t + 24 * 3600)) ;
  1567. $dlz = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1568. $smt = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1569. $tt = $this->fullordertt->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1570. $amz = $this->fullorderamz->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1571. //数量及金额开始
  1572. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1573. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1574. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1575. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  1576. $dlzmoneyb[] = $dlzm;
  1577. $smtmoneyb[] = $smtm;
  1578. $ttmoneyb[] = $ttm;
  1579. $amzmoneyb[] = $amzm;
  1580. //数量及金额结束
  1581. }
  1582. }
  1583. foreach ($shopdata as $k => $v) {
  1584. $sn = $this->shop->read($k);
  1585. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  1586. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  1587. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  1588. $shopdata[$k]['name'] = $sn['shopname'];
  1589. $shopdata[$k]['b'] = $sn['type'];
  1590. $shopdata[$k]['id'] = $sn['id'];
  1591. }
  1592. $shopdata = array_values($shopdata);
  1593. //$sycp=array();
  1594. /**
  1595. //根据所选时间产品排行开始
  1596. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1597. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1598. **/
  1599. /**
  1600. //昨日产品排行开始
  1601. $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');
  1602. $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');
  1603. $rows = array_merge($dlzlist,$smtlist);
  1604. foreach ($rows as $v)
  1605. {
  1606. $number = explode('|',trim($v['whlabel'],'|'));
  1607. $or = explode(';',trim($v['fpdata'],';'));
  1608. $i=0;
  1609. foreach ($or as $va)
  1610. {
  1611. $ord = explode('|',$va);
  1612. $orod = explode(',',$ord[0]);
  1613. $numberod = explode('-',$number[$i]);
  1614. if(!isset($orod[1]))
  1615. {
  1616. continue;
  1617. }
  1618. if(isset($sycp[$orod[1]) && isset($numberod[1]))
  1619. {
  1620. //$sycp[$orod[1]][0] += 1;//统计多少单
  1621. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  1622. $sycp[$orod[1]][1] += 0;//价格
  1623. }
  1624. else
  1625. {
  1626. if(isset($numberod[1]))
  1627. {
  1628. $typeclass = $this->typeclass->read($orod['0']);
  1629. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  1630. }
  1631. }
  1632. $i++;
  1633. }
  1634. }
  1635. arsort($sycp);
  1636. $sycp = array_values($sycp);
  1637. $sycp = array_slice($sycp,0,10);
  1638. //产品排行结束
  1639. **/
  1640. //当时实时数据结束
  1641. echo @json_encode(array('time' => $time, 'timeold' => $timeold, 'smtnum' => $smtnum, 'ttnum' => $ttnum, 'amznum' => $amznum, 'dlznum' => $dlznum, 'smtmoney' => $smtmoney, 'ttmoney' => $ttmoney, 'amzmoney' => $amzmoney, 'dlzmoney' => $dlzmoney, 'smtmoneyb' => $smtmoneyb, 'ttmoneyb' => $ttmoneyb, 'amzmoneyb' => $amzmoneyb, 'dlzmoneyb' => $dlzmoneyb, 'dlzsl' => $dlzsl, 'dlzje' => number_format($dlzje, 2), 'dlzssje' => number_format($dlzssje, 2), 'smtsl' => $smtsl, 'amzsl' => $amzsl, 'ttsl' => $ttsl, 'smtje' => number_format($smtje, 2), 'amzje' => number_format($amzje, 2), 'ttje' => number_format($ttje, 2), 'smtssje' => number_format($smtssje, 2), 'amzssje' => number_format($amzssje, 2), 'ttssje' => number_format($ttssje, 2), 'zje' => number_format($dlzje + $smtje + $ttje + $amzje, 2), 'zsl' => $dlzsl + $smtsl + $ttsl + $amzsl, 'shopdata' => $shopdata, 'success' => true));
  1642. exit; //,'sycp'=>$sycp昨日产品数据
  1643. }
  1644. /**
  1645. public function super_unique($array,$key)//多维删除重复
  1646. {
  1647. $temp_array = array();
  1648. foreach ($array as &$v) {
  1649. if (!isset($temp_array[$v[$key]]))
  1650. {
  1651. $temp_array[$v[$key]] =& $v;
  1652. }
  1653. }
  1654. $array = array_values($temp_array);
  1655. return $array;
  1656. }
  1657. **/
  1658. public function _usatime()
  1659. {
  1660. date_default_timezone_set("Etc/GMT+8");
  1661. return time();
  1662. }
  1663. //数据
  1664. public function _rows()
  1665. {
  1666. $post = $this->input->post(NULL, TRUE);
  1667. if (isset($post['shop'])) {
  1668. $shop = $this->input->post('shop', true);
  1669. $data = $this->shop->find_all('1=1',"*","px asc");
  1670. $list = array();
  1671. foreach ($data as $key => $value) {
  1672. $t = $this->typeclass->read($value['type']);
  1673. $list[] = array('id' => $value['id'], 'title' => $value['shopname'] . ' - ' . $t['title']);
  1674. }
  1675. $num = array();
  1676. if ($shop != "null") {
  1677. $num = $this->user->read($shop); //找出内容
  1678. if ($num['shop']) {
  1679. $num = explode('|', trim($num['shop'], '|')); //数组化内容
  1680. } else {
  1681. $num = array();
  1682. }
  1683. }
  1684. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1685. }
  1686. if (isset($post['excelshop'])) {
  1687. $excelshop = $this->input->post('excelshop', true);
  1688. $data = $this->shop->find_all('1=1',"*","px asc");
  1689. $list = array();
  1690. foreach ($data as $key => $value) {
  1691. $t = $this->typeclass->read($value['type']);
  1692. $list[] = array('id' => $value['id'], 'title' => $value['shopname'] . ' - ' . $t['title']);
  1693. }
  1694. $num = array();
  1695. if ($excelshop != "null") {
  1696. $num = $this->user->read($excelshop); //找出内容
  1697. if ($num['excelshop']) {
  1698. $num = explode('|', trim($num['excelshop'], '|')); //数组化内容
  1699. } else {
  1700. $num = array();
  1701. }
  1702. }
  1703. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1704. }
  1705. if (isset($post['purchase'])) {
  1706. $purchase = $this->input->post('purchase', true);
  1707. $data = $this->purchase->find_all('1=1');
  1708. $list = array();
  1709. foreach ($data as $key => $value) {
  1710. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1711. }
  1712. $num = array();
  1713. if ($purchase != "null") {
  1714. $num = $this->user->read($purchase); //找出内容
  1715. if ($num['purchase']) {
  1716. $num = explode('|', trim($num['purchase'], '|')); //数组化内容
  1717. } else {
  1718. $num = array();
  1719. }
  1720. }
  1721. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1722. }
  1723. if (isset($post['staff'])) {
  1724. $staff = $this->input->post('staff', true);
  1725. $data = $this->staff->find_all('1=1');
  1726. $list = array();
  1727. foreach ($data as $key => $value) {
  1728. $list[] = array('id' => $value['id'], 'title' => $value['name']);
  1729. }
  1730. $num = array();
  1731. if ($staff != "null") {
  1732. $num = $this->user->read($staff); //找出内容
  1733. if ($num['staff']) {
  1734. $num = explode('|', trim($num['staff'], '|')); //数组化内容
  1735. } else {
  1736. $num = array();
  1737. }
  1738. }
  1739. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1740. }
  1741. if (isset($post['warehouse'])) {
  1742. $warehouse = $this->input->post('warehouse', true);
  1743. $data = $this->warehouse->find_all('1=1');
  1744. $list = array();
  1745. foreach ($data as $key => $value) {
  1746. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1747. }
  1748. $num = array();
  1749. if ($warehouse != "null") {
  1750. $num = $this->user->read($warehouse); //找出内容
  1751. if ($num['warehouse']) {
  1752. $num = explode('|', trim($num['warehouse'], '|')); //数组化内容
  1753. } else {
  1754. $num = array();
  1755. }
  1756. }
  1757. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1758. }
  1759. if (isset($post['transfer'])) {
  1760. $transfer = $this->input->post('transfer', true);
  1761. $data = $this->transfer->find_all('1=1');
  1762. $list = array();
  1763. foreach ($data as $key => $value) {
  1764. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1765. }
  1766. $num = array();
  1767. if ($transfer != "null") {
  1768. $num = $this->user->read($transfer); //找出内容
  1769. if ($num['transfer']) {
  1770. $num = explode('|', trim($num['transfer'], '|')); //数组化内容
  1771. } else {
  1772. $num = array();
  1773. }
  1774. }
  1775. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1776. }
  1777. }
  1778. public function _shopfx()
  1779. {
  1780. $post = $this->input->post(NULL, TRUE);
  1781. if (isset($post['time'])) {
  1782. $time = $this->input->post('time', true);
  1783. $t = strtotime(date("Ymd", time() + 24 * 3600)); //明天0点
  1784. $shop = $this->shop->find_all(" ( type = 269 or type = 2768 ) and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1785. $sid = '';
  1786. foreach ($shop as $value) {
  1787. $sid .= " shop = " . $value['id'] . " or";
  1788. }
  1789. $sid = " and (" . rtrim($sid, 'or') . ")";
  1790. $znum = $this->fullorder->find_count("dtime > '" . ($t - $time * 24 * 3600) . "' and dtime < '" . $t . "'" . $sid);
  1791. $data = array();
  1792. $list = array();
  1793. $color = array('0' => '#30546c', '1' => '#61a0a8', '2' => '#c23531', '3' => '#d48265', '4' => '#546570', '5' => '#749f83', '6' => '#bda29a', '7' => '#6e7074', '8' => '#546570');
  1794. $j = 0;
  1795. $zt = array(7 => 1, 30 => 2);
  1796. foreach ($shop as $v) {
  1797. $d = $this->fullorder->find_count("shop = '" . $v['id'] . "' and dtime > '" . ($t - $time * 24 * 3600) . "' and dtime < '" . $t . "' and (state = '207' or state = '216')");
  1798. $wd = $this->allocation->read($zt[$time]);
  1799. $n = json_decode($wd['content'], true);
  1800. $bfb = ($d == 0) ? 0 : round(($d / $znum) * 100, 2);
  1801. $data[] = array('value' => $bfb, 'name' => $v['shopname'] . ' ' . $bfb . "%", 'itemStyle' => array('color' => $color[$j]));
  1802. $n[$v['id']][] = $this->fullorder->find_count("shop = '" . $v['id'] . "' and gtime = '" . date("Ymd", time()) . "' and (state = '207' or state = '216')");
  1803. $t_list = array();
  1804. for ($i = 0; $i < $time; $i++) {
  1805. $t_list[] = date("m-d", time() - ($i * 24 * 3600));
  1806. }
  1807. $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) . '%');
  1808. $j++;
  1809. }
  1810. $list = (array_reverse($list));
  1811. echo json_encode(array('data' => ($data), 'list' => $list, 't' => (array_reverse($t_list)), 'success' => true));
  1812. exit;
  1813. /**
  1814. $time = $this->input->post('time',true);
  1815. $t = strtotime(date("Ymd",time()+24*3600));//明天0点
  1816. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1817. $sid = '';
  1818. foreach ($shop as $value)
  1819. {
  1820. $sid .= " shop = ".$value['id']." or";
  1821. }
  1822. $sid = " and (".rtrim($sid,'or').")";
  1823. $znum = $this->fullorder->find_count("dtime > '".($t-$time*24*3600)."' and dtime < '".$t."'".$sid);
  1824. $data = array();$list = array();
  1825. $color = array('0'=>'#30546c','1'=>'#61a0a8','2'=>'#c23531','3'=>'#d48265','4'=>'#546570','5'=>'#749f83','6'=>'#bda29a','7'=>'#6e7074','8'=>'#546570');
  1826. $j = 0;
  1827. foreach ($shop as $v)
  1828. {
  1829. $d = $this->fullorder->find_count("shop = '".$v['id']."' and dtime > '".($t-$time*24*3600)."' and dtime < '".$t."' and (state = '207' or state = '216')");
  1830. $bfb = ($d==0)?0:round(($d / $znum) * 100, 2);
  1831. $data[] = array('value'=>$bfb,'name'=>$v['shopname'].' '.$bfb."%",'itemStyle'=>array('color'=>$color[$j]));
  1832. $n = array();$t_list = array();
  1833. for($i=0;$i<$time;$i++)
  1834. {
  1835. if($i == 0)
  1836. {
  1837. $s = date("Ymd",time());
  1838. }
  1839. else
  1840. {
  1841. $s = date("Ymd",time()-($i*24*3600));
  1842. }
  1843. $t_list[] = date("m-d",time()-($i*24*3600));
  1844. $n[] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".$s."' and (state = '207' or state = '216')");
  1845. }
  1846. $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).'%');
  1847. $j++;
  1848. }
  1849. $list = (array_reverse($list));
  1850. echo json_encode(array('data'=>($data),'list'=>$list,'t'=>(array_reverse($t_list)),'success'=>true));exit;
  1851. **/
  1852. }
  1853. $this->_Template('phone/p_user_shopfx', $this->data);
  1854. }
  1855. public function _shopfxlist()
  1856. {
  1857. $t = strtotime(date("Ymd", time())); //今天0点
  1858. $shop = $this->shop->find_all(" ( type = 269 or type = 2768 ) and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1859. $sid = '';
  1860. foreach ($shop as $value) {
  1861. $sid .= " shop = " . $value['id'] . " or";
  1862. }
  1863. $sid = " and (" . rtrim($sid, 'or') . ")";
  1864. $zt = array(7, 30);
  1865. $this->db->trans_begin();
  1866. foreach ($zt as $key => $time) {
  1867. $data = array();
  1868. $list = array();
  1869. foreach ($shop as $v) {
  1870. $n = array();
  1871. $t_list = array();
  1872. for ($i = 1; $i < $time; $i++) {
  1873. if ($i == 0) {
  1874. $s = date("Ymd", time());
  1875. } else {
  1876. $s = date("Ymd", time() - ($i * 24 * 3600));
  1877. }
  1878. $t_list[] = date("m-d", time() - ($i * 24 * 3600));
  1879. $n[] = $this->fullorder->find_count("shop = '" . $v['id'] . "' and gtime = '" . $s . "' and (state = '207' or state = '216')");
  1880. }
  1881. $list[$v['id']] = array_reverse($n);
  1882. }
  1883. $this->allocation->save(array('content' => json_encode($list)), $key + 1);
  1884. }
  1885. if ($this->db->trans_status() === FALSE) {
  1886. $this->db->trans_rollback();
  1887. echo 'orver';
  1888. } else {
  1889. $this->db->trans_commit();
  1890. echo 'ok';
  1891. }
  1892. }
  1893. public function _apple()
  1894. {
  1895. $this->_Template('phone/p_user_apple', $this->data);
  1896. }
  1897. //退出
  1898. public function _tc()
  1899. {
  1900. $this->session->sess_destroy();
  1901. header("Location:/");
  1902. }
  1903. public function _tjadd()
  1904. {
  1905. $pdtime = date('Y-m-d-H', time());
  1906. //if(is_file("./data/tj/".$pdtime.".txt"))
  1907. if (is_file("./data/tj/" . $pdtime . ".txt")) {
  1908. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  1909. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  1910. fclose($myfile);
  1911. $bc = json_decode($bc, true);
  1912. $zzt = array($bc['zzt'][0], $bc['zzt'][1]);
  1913. } else {
  1914. /** 暂时不需要了
  1915. //柱状图数据
  1916. $i = 0;
  1917. $data = array();$sndata1 = array();$sndata2 = array();$sndata3 = array();
  1918. $sj = array('01','02','03','04','05','06','07','08','09','10','11','12');
  1919. foreach ($sj as $k=>$v)
  1920. {
  1921. $i++;
  1922. $dlz1 = $this->fullorder->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1923. $smt1 = $this->fullordersmt->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1924. $m1 = sprintf("%01.2f",array_sum(array_column($dlz1,'shouldmoney'))+array_sum(array_column($smt1,'shouldmoney')));
  1925. $dlz2 = $this->fullorder->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1926. $smt2 = $this->fullordersmt->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1927. $m2 = sprintf("%01.2f",array_sum(array_column($dlz2,'shouldmoney'))+array_sum(array_column($smt2,'shouldmoney')));
  1928. $dlz3 = $this->fullorder->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1929. $smt3 = $this->fullordersmt->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1930. $m3 = sprintf("%01.2f",array_sum(array_column($dlz3,'shouldmoney'))+array_sum(array_column($smt3,'shouldmoney')));
  1931. $sndata1[$i] = $m3;
  1932. $sndata2[12+$i] = $m2;
  1933. $sndata3[24+$i] = $m1;
  1934. $data[] = array($v,$m1,$m2,$m3);
  1935. }
  1936. $sndata = array_merge($sndata1,$sndata2,$sndata3);
  1937. $zzt = array($data,$sndata);
  1938. //柱状图结束
  1939. **/
  1940. }
  1941. //详情内容
  1942. $dt = 0;
  1943. //系统报错 提示没有api下标的键
  1944. if(!isset($_SESSION['api'])){
  1945. echo "ERROR";
  1946. die;
  1947. }
  1948. $user = $this->user->get_api($_SESSION['api']);
  1949. $usp = $user;
  1950. $fgshop = "";
  1951. $sid = "";
  1952. $user = explode('|', trim($user['shop'], '|'));
  1953. foreach ($user as $value) {
  1954. if(!empty($value)){
  1955. $fgshop .= " shop = " . $value . " or";
  1956. $sid .= " id = " . $value . " or";
  1957. }
  1958. }
  1959. //为了让下面程序可以执行 给的如果用户没店铺权限 就给一个不存在的店铺
  1960. if(empty($fgshop)){
  1961. $fgshop = " shop = 0 or";
  1962. $sid = " id = 0 or";
  1963. }
  1964. $tm = strtotime(date("Ymd"), time());
  1965. $usat = $tm;
  1966. //$molist = array('0','1','2d');
  1967. $molist = array('0', '1');
  1968. $zqtime = array(259200, 345600, 691200, 2678400, 7862400, 31622400);
  1969. //time开始
  1970. $zqtdata = array();
  1971. foreach ($molist as $vval) {
  1972. $where = "";
  1973. $source = $vval;
  1974. if ($source == '2d') {
  1975. $where = " and source >= '2'";
  1976. } else if ($source != '0') {
  1977. $where = " and source = '$source'";
  1978. }
  1979. foreach ($zqtime as $value) {
  1980. $zdt = $value;
  1981. $k = $zdt;
  1982. $tab = 1;
  1983. //$start = '2018-10-15';
  1984. //$end = '2018-11-26';
  1985. //$tim = strtotime($start);
  1986. //$day = $time/(3600*24);
  1987. if ($tab == '1') {
  1988. if ($zdt >= 691200) {
  1989. $k = $usat - $k - $k;
  1990. $j = $usat;
  1991. $n = ($j - $k) / (24 * 3600);
  1992. } else {
  1993. $n = 2;
  1994. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  1995. }
  1996. } else {
  1997. $timedata = explode('|', $zdt);
  1998. $ktime = strtotime($timedata[0]);
  1999. $jtime = strtotime($timedata[1]);
  2000. $ktime = $ktime - ($jtime - $ktime);
  2001. $k = $ktime;
  2002. $j = $jtime;
  2003. $n = ($j - $k) / (24 * 3600);
  2004. $usat = $jtime;
  2005. $tm = $jtime;
  2006. $zdt = $jtime - $ktime;
  2007. }
  2008. $time = array();
  2009. $timeold = array();
  2010. $stime = array();
  2011. $dlznum = array();
  2012. $smtnum = array();;
  2013. $ttnum = array();
  2014. $ymoney = array();
  2015. $money = array();
  2016. $dlzmoney = array();
  2017. $smtmoney = array();
  2018. $ttmoney = array();
  2019. $dlzmoneyb = array();
  2020. $smtmoneyb = array();
  2021. $ttmoneyb = array();
  2022. $dlzsl = 0;
  2023. $dlzje = 0;
  2024. $dlzssje = 0;
  2025. $smtsl = 0;
  2026. $smtje = 0;
  2027. $smtssje = 0;
  2028. $ttsl = 0;
  2029. $ttje = 0;
  2030. $ttssje = 0;
  2031. $shopdata = array();
  2032. $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'");
  2033. foreach ($ys as $v) {
  2034. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  2035. }
  2036. for ($i = 1; $i < $n; $i++) {
  2037. //近7天时间
  2038. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  2039. if ($n > 13 && $i > $n / 2 || $n < 14) {
  2040. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  2041. $time[] = date('m-d', $t);
  2042. $ct = strtotime(date('Ymd', $t));
  2043. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  2044. $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');
  2045. $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');
  2046. $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');
  2047. $ab[] = $dlz;
  2048. //数量及金额开始
  2049. $dlznum[] = count($dlz);
  2050. $smtnum[] = count($smt);
  2051. $ttnum[] = count($smt);
  2052. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  2053. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  2054. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  2055. /**
  2056. //提出退款关闭等信息的实收金额
  2057. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  2058. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  2059. //提出退款关闭等信息的实收金额
  2060. **/
  2061. //实收金额
  2062. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  2063. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  2064. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  2065. //实收金额
  2066. //补/退原额
  2067. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  2068. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  2069. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  2070. //补/退原额
  2071. $dlzmoney[] = $dlzm;
  2072. $smtmoney[] = $smtm;
  2073. $ttmoney[] = $ttm;
  2074. $dlzsl += count($dlz);
  2075. $dlzje += $dlzm;
  2076. $smtsl += count($smt);
  2077. $smtje += $smtm;
  2078. $ttsl += count($tt);
  2079. $ttje += $ttm;
  2080. /**
  2081. //减去的实收金额
  2082. $dlzssje += $dlzm+$dlzmss;
  2083. $smtssje += $smtm+$smtmss;
  2084. **/
  2085. //实收和补/退
  2086. $dlzssje += $dlzmss + $dlzbty;
  2087. $smtssje += $smtmss + $smtbty;
  2088. $ttssje += $ttmss + $ttbty;
  2089. //数量及金额结束
  2090. $sd = array_merge($dlz, $smt, $tt);
  2091. foreach ($sd as $v) {
  2092. if (isset($shopdata[$v['shop']])) {
  2093. $shopdata[$v['shop']]['num'] += 1;
  2094. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  2095. $shopdata[$v['shop']]['tmoney'] += $v['budget'] + $v['refundy'];
  2096. }
  2097. }
  2098. } else if ($n > 13 && $i <= $n / 2) {
  2099. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  2100. $timeold[] = date('m-d', $t);
  2101. $ct = strtotime(date('Ymd', $t));
  2102. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  2103. $dlz = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  2104. $smt = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  2105. $tt = $this->fullordertt->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  2106. //数量及金额开始
  2107. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  2108. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  2109. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  2110. $dlzmoneyb[] = $dlzm;
  2111. $smtmoneyb[] = $smtm;
  2112. $ttmoneyb[] = $ttm;
  2113. //数量及金额结束
  2114. }
  2115. }
  2116. foreach ($shopdata as $k => $v) {
  2117. $sn = $this->shop->read($k);
  2118. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  2119. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  2120. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  2121. $shopdata[$k]['name'] = $sn['shopname'];
  2122. $shopdata[$k]['b'] = $sn['type'];
  2123. $shopdata[$k]['id'] = $sn['id'];
  2124. }
  2125. $shopdata = array_values($shopdata);
  2126. //$sycp=array();
  2127. /**
  2128. //根据所选时间产品排行开始
  2129. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  2130. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  2131. **/
  2132. /**
  2133. //昨日产品排行开始
  2134. $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');
  2135. $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');
  2136. $rows = array_merge($dlzlist,$smtlist);
  2137. foreach ($rows as $v)
  2138. {
  2139. $number = explode('|',trim($v['whlabel'],'|'));
  2140. $or = explode(';',trim($v['fpdata'],';'));
  2141. $i=0;
  2142. foreach ($or as $va)
  2143. {
  2144. $ord = explode('|',$va);
  2145. $orod = explode(',',$ord[0]);
  2146. $numberod = explode('-',$number[$i]);
  2147. if(!isset($orod[1]))
  2148. {
  2149. continue;
  2150. }
  2151. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  2152. {
  2153. //$sycp[$orod[1]][0] += 1;//统计多少单
  2154. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  2155. $sycp[$orod[1]][1] += 0;//价格
  2156. }
  2157. else
  2158. {
  2159. if(isset($numberod[1]))
  2160. {
  2161. $typeclass = $this->typeclass->read($orod['0']);
  2162. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  2163. }
  2164. }
  2165. $i++;
  2166. }
  2167. }
  2168. arsort($sycp);
  2169. $sycp = array_values($sycp);
  2170. $sycp = array_slice($sycp,0,10);
  2171. //产品排行结束
  2172. **/
  2173. //当时实时数据结束
  2174. $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昨日产品数据
  2175. }
  2176. }
  2177. //time结束
  2178. //zhcx开始
  2179. $zhcxdata = array();
  2180. foreach ($molist as $vval) {
  2181. $where = "";
  2182. $source = $vval;
  2183. if ($source == '2d') {
  2184. $where = " and source >= '2'";
  2185. } else if ($source != '0') {
  2186. $where = " and source = '$source'";
  2187. }
  2188. foreach ($zqtime as $value) {
  2189. $zdt = $value;
  2190. $k = $zdt;
  2191. $tab = 1;
  2192. //$customer = $this->customer->find_all("shop !=''",'num,zhcx');
  2193. //$customerkey = array_column($customer,'zhcx');
  2194. //$customer= array_combine($customerkey,$customer);
  2195. //$customersmt = $this->customersmt->find_all("shop !=''",'num,zhcx');
  2196. //$customersmtkey = array_column($customersmt,'zhcx');
  2197. //$customersmt= array_combine($customersmtkey,$customersmt);
  2198. //$customertt = $this->customertt->find_all("shop !=''",'num,zhcx');
  2199. //$customerttkey = array_column($customertt,'zhcx');
  2200. //$customertt= array_combine($customerttkey,$customertt);
  2201. if ($tab == '1') {
  2202. if ($zdt >= 691200) {
  2203. $k = $usat - $k - $k;
  2204. $j = $usat;
  2205. $n = ($j - $k) / (24 * 3600);
  2206. } else {
  2207. $n = 2;
  2208. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  2209. }
  2210. } else {
  2211. $timedata = explode('|', $zdt);
  2212. $ktime = strtotime($timedata[0]);
  2213. $jtime = strtotime($timedata[1]);
  2214. $ktime = $ktime - ($jtime - $ktime);
  2215. $k = $ktime;
  2216. $j = $jtime;
  2217. $n = ($j - $k) / (24 * 3600);
  2218. $usat = $jtime;
  2219. }
  2220. $time = array();
  2221. $timeold = array();
  2222. $stime = array();
  2223. $dlznum = array();
  2224. $smtnum = array();
  2225. $ttnum = array();
  2226. $ymoney = array();
  2227. $money = array();
  2228. $dlzmoneyb = array();
  2229. $smtmoneyb = array();
  2230. $ttmoneyb = array();
  2231. $zkh = array();
  2232. $dlzsl = 0;
  2233. $dlzje = 0;
  2234. $dlzssje = 0;
  2235. $smtsl = 0;
  2236. $smtje = 0;
  2237. $smtssje = 0;
  2238. $ttsl = 0;
  2239. $ttje = 0;
  2240. $ttssje = 0;
  2241. $shopdata = array();
  2242. $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'");
  2243. foreach ($ys as $v) {
  2244. $shopdata[$v['id']] = array('id' => $v['id'], 'b' => $v['type'], 'fdl' => 0, 'chl' => 0, 'num' => 0, 'fgl' => 0);
  2245. $zkh[$v['id']] = array();
  2246. }
  2247. for ($i = 1; $i < $n; $i++) {
  2248. if ($n > 13 && $i > $n / 2 || $n < 14) {
  2249. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  2250. $time[] = date('m-d', $t);
  2251. $ct = strtotime(date('Ymd', $t));
  2252. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  2253. $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');
  2254. $dlzemail = $this->fullorder->find_all("dtime <= " . $ctj . $where . " and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'shop,email');
  2255. $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');
  2256. $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');
  2257. //数量及金额结束
  2258. $sd = array_merge($dlz, $smt, $tt);
  2259. $fgldata = array();
  2260. foreach ($sd as $v) {
  2261. /**
  2262. $array = array(
  2263. 0 => array('email' => 123, 'id' => 1),
  2264. 1 => array('email' => 321, 'id' => 2),
  2265. 2 => array('email' => 123, 'id' => 3),
  2266. 3 => array('email' => 123, 'id' => 3)
  2267. );
  2268. // 使用 array_filter 筛选满足多个条件的元素
  2269. $result = array_filter($array, function($item) {
  2270. return $item['email'] === 123 && $item['id'] === 3;
  2271. });
  2272. // 计算满足条件的数量
  2273. $count = count($result);
  2274. echo "满足条件 (email = 123 且 id = 3) 的数量是:$count";
  2275. **/
  2276. /** 独立站查customer方法 弃用
  2277. if(isset($v['email']))
  2278. {
  2279. if(!isset($fgldata[$v['shop'].'-'.$v['email']]))
  2280. {
  2281. $fgldata[$v['shop'].'-'.$v['email']] = 0;
  2282. }
  2283. else
  2284. {
  2285. $fgldata[$v['shop'].'-'.$v['email']] += 1;
  2286. }
  2287. $zkh[$v['shop']][$v['email']] = array();
  2288. }
  2289. **/
  2290. /** 速卖通
  2291. else
  2292. {
  2293. if(!isset($fgldata[$v['shop'].'-'.$v['userid']]))
  2294. {
  2295. $fgldata[$v['shop'].'-'.$v['userid']] = 0;
  2296. }
  2297. else
  2298. {
  2299. $fgldata[$v['shop'].'-'.$v['userid']] += 1;
  2300. }
  2301. $zkh[$v['shop']][$v['userid']] = array();
  2302. }
  2303. **/
  2304. }
  2305. foreach ($sd as $v) {
  2306. //避免由于作用域引起的问题
  2307. $tmp_v = $v;
  2308. $fdl_result = array_filter($dlz, function ($item) use ($tmp_v) {
  2309. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  2310. return false;
  2311. } else {
  2312. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  2313. }
  2314. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  2315. });
  2316. $fdl = count($fdl_result) > 1 ? 1 : 0; //返单
  2317. $chl_result = array_filter($dlz, function ($item) use ($tmp_v) {
  2318. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  2319. return false;
  2320. } else {
  2321. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  2322. }
  2323. //return $item['email'] === $tmp_v['email'] && $item['shop'] !== $tmp_v['email'];
  2324. });
  2325. $chl = count($chl_result) > 1 ? 1 : 0; //重合
  2326. $fgl_result = array_filter($dlzemail, function ($item) use ($tmp_v) {
  2327. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  2328. return false;
  2329. } else {
  2330. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  2331. }
  2332. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  2333. });
  2334. $fgl = count($fgl_result) > 1 ? 1 : 0; //复购
  2335. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl'] + $fdl;
  2336. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl'] + $chl;
  2337. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl'] + $fgl;
  2338. $shopdata[$v['shop']]['num'] += 1;
  2339. /**
  2340. $chl = 0;
  2341. if(isset($shopdata[$v['shop']]))
  2342. {
  2343. if(isset($v['email']))
  2344. {
  2345. if(isset($customer[$v['shop'].'-'.$v['email']]['num']))
  2346. {
  2347. $fdl = $customer[$v['shop'].'-'.$v['email']]['num']>1?1:0;
  2348. }
  2349. else
  2350. {
  2351. $fdl = 0;
  2352. }
  2353. foreach ($ys as $vv)
  2354. {
  2355. if($vv['id'] != $v['shop'] && isset($customer[$vv['id'].'-'.$v['email']]))
  2356. {
  2357. $chl = 1;
  2358. }
  2359. }
  2360. if(isset($fgldata[$v['shop'].'-'.$v['email']]))
  2361. {
  2362. $fgl = $fgldata[$v['shop'].'-'.$v['email']]>0?1:0;
  2363. }
  2364. else
  2365. {
  2366. $fgl = 0;
  2367. }
  2368. }
  2369. else
  2370. {
  2371. if(isset($customersmt[$v['shop'].'-'.$v['userid']]['num']))
  2372. {
  2373. $fdl = $customersmt[$v['shop'].'-'.$v['userid']]['num']>1?1:0;
  2374. }
  2375. else
  2376. {
  2377. $fdl = 0;
  2378. }
  2379. foreach ($ys as $vv)
  2380. {
  2381. if($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'].'-'.$v['userid']]))
  2382. {
  2383. $chl = 1;
  2384. }
  2385. }
  2386. if(isset($fgldata[$v['shop'].'-'.$v['userid']]))
  2387. {
  2388. $fgl = $fgldata[$v['shop'].'-'.$v['userid']]>0?1:0;
  2389. }
  2390. else
  2391. {
  2392. $fgl = 0;
  2393. }
  2394. }
  2395. }
  2396. **/
  2397. }
  2398. }
  2399. }
  2400. foreach ($shopdata as $k => $v) {
  2401. $shopdata[$k]['fdl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['fdl'] / $v['num'] * 100)) . '%';
  2402. $shopdata[$k]['chl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['chl'] / $v['num'] * 100)) . '%';
  2403. $shopdata[$k]['fgl'] = count($zkh[$v['id']]) == '0' ? 0 : sprintf("%01.2f", ($v['fgl'] / count($zkh[$v['id']]) * 100)) . '%';
  2404. }
  2405. $shopdata = array_values($shopdata);
  2406. $zhcxdata[$vval][$value] = array('shopdata' => $shopdata, 'success' => true);
  2407. }
  2408. }
  2409. //zhcx结束
  2410. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "w") or die("Unable to open file!");
  2411. $txt = json_encode(array('zzt' => $zzt, 'tj' => $zqtdata, 'zhcx' => $zhcxdata));
  2412. fwrite($myfile, $txt);
  2413. fclose($myfile);
  2414. echo 1;
  2415. }
  2416. public function _statistics_hb(){
  2417. if (isset($_SESSION['api'])) {
  2418. $user = $this->user->get_api($_SESSION['api']);
  2419. $usp = $user;
  2420. $fgshop = "";
  2421. $sid = "";
  2422. $user = explode('|', trim($user['shop'], '|'));
  2423. foreach ($user as $value) {
  2424. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  2425. $fgshop .= " shop = " . $value . " or";
  2426. }
  2427. $sid .= " id = " . $value . " or";
  2428. }
  2429. }
  2430. $source = $this->input->post('source');
  2431. $time = $this->input->post('time');
  2432. $tab = $this->input->post('tab');
  2433. $table_name = $this->input->post('table_name');
  2434. if(empty($table_name)){
  2435. $table_name = 'fullorder';
  2436. }
  2437. if($tab == 2){
  2438. $now_time = [];
  2439. $timedata = explode('|', $time);
  2440. $ktime = strtotime($timedata[0]);
  2441. $jtime = strtotime($timedata[1]);
  2442. $ktime = $ktime - ($jtime - $ktime);
  2443. $k = $ktime;
  2444. $j = $jtime;
  2445. $n = ($j - $k) / (24 * 3600);
  2446. $usat = $jtime;
  2447. for ($i = 1; $i < $n; $i++) {
  2448. //近7天时间
  2449. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  2450. if ($n > 13 && $i > $n / 2 || $n < 14) {
  2451. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  2452. $now_time[] = date('Y-m-d', $t);
  2453. }
  2454. }
  2455. $k_tmp_time = strtotime($now_time[0]);
  2456. $e_tmp_time = strtotime($now_time[count($now_time) - 1] ) + 24 * 3600;
  2457. $ll_time = ($e_tmp_time - $k_tmp_time) ;
  2458. // var_dump(date("Y-m-d H:i:s", $k_tmp_time)."=========".date("Y-m-d H:i:s", $e_tmp_time));
  2459. // var_dump(date("Y-m-d H:i:s", $k_tmp_time - $ll_time)."=========".date("Y-m-d H:i:s", $k_tmp_time));
  2460. // die;
  2461. $k_time = $k_tmp_time - $ll_time;
  2462. $j_time = $k_tmp_time;
  2463. // $timedata = explode('|', $time);
  2464. // $ktime = strtotime($timedata[0]) + 24 * 3600;
  2465. // $jtime = strtotime($timedata[1]);
  2466. // $ll_time = ($jtime - $ktime);
  2467. // $k_time = $ktime - $ll_time ;
  2468. // $j_time = $jtime - $ll_time;
  2469. $where = "( dtime >= ".$k_time." and dtime <= ".$j_time." ) ";
  2470. }else{
  2471. $k_time = "";
  2472. $j_time = "";
  2473. if($time >= 691200){
  2474. $k_time = strtotime(date("Ymd", time())) - $time+ 24 * 3600;
  2475. $j_time = strtotime(date("Ymd", time()));
  2476. $k_hb_time = $k_time - $time + 24 * 3600;
  2477. $j_hb_time = $k_time;
  2478. }else{
  2479. $k_time = strtotime(date("Ymd", time())) - $time + 24 * 3600;
  2480. $j_time = $k_time + 24 * 3600;
  2481. $k_hb_time = $k_time - 24 * 3600;
  2482. $j_hb_time = $j_time - 24 * 3600;
  2483. }
  2484. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  2485. }
  2486. if ($source) {
  2487. if ($source == '2d') {
  2488. $where .= " and source >= '2' ";
  2489. } else {
  2490. $where .= " and source = '$source' ";
  2491. }
  2492. }
  2493. if($table_name == 'fullordertt' || $table_name == 'fullorderamz'){
  2494. $where .= " and state != 217 ";
  2495. }
  2496. $list = $this->$table_name->find_all($where . " and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'budget,shouldmoney,shop,number,refundy,budget,email,refundy');
  2497. $sl = count($list);
  2498. $je = sprintf("%01.2f", array_sum(array_column($list, 'shouldmoney')));
  2499. $ssje = 0;
  2500. //实收金额
  2501. $dlzmss = sprintf("%01.2f", array_sum(array_column($list, 'budget')));
  2502. //实收金额
  2503. //补/退原额
  2504. $dlzbty = sprintf("%01.2f", array_sum(array_column($list, 'refundy')));
  2505. $ssje = sprintf("%01.2f", $dlzmss + $dlzbty);
  2506. echo json_encode([
  2507. 'status' => 1,
  2508. 'data' => [
  2509. 'sl' => $sl,
  2510. 'je' => $je,
  2511. 'ssje' => $ssje,
  2512. ]
  2513. ]);
  2514. exit; //,'sycp'=>$sycp昨日产品数据
  2515. }
  2516. public function _statistics_tb(){
  2517. if (isset($_SESSION['api'])) {
  2518. $user = $this->user->get_api($_SESSION['api']);
  2519. $usp = $user;
  2520. $fgshop = "";
  2521. $sid = "";
  2522. $user = explode('|', trim($user['shop'], '|'));
  2523. foreach ($user as $value) {
  2524. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  2525. $fgshop .= " shop = " . $value . " or";
  2526. }
  2527. $sid .= " id = " . $value . " or";
  2528. }
  2529. }
  2530. $source = $this->input->post('source');
  2531. $time = $this->input->post('time');
  2532. $tab = $this->input->post('tab');
  2533. $table_name = $this->input->post('table_name');
  2534. if(empty($table_name)){
  2535. $table_name = 'fullorder';
  2536. }
  2537. if($tab == 2){
  2538. $now_time = [];
  2539. $timedata = explode('|', $time);
  2540. $ktime = strtotime($timedata[0]);
  2541. $jtime = strtotime($timedata[1]);
  2542. $ktime = $ktime - ($jtime - $ktime);
  2543. $k = $ktime;
  2544. $j = $jtime;
  2545. $n = ($j - $k) / (24 * 3600);
  2546. $usat = $jtime;
  2547. for ($i = 1; $i < $n; $i++) {
  2548. //近7天时间
  2549. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  2550. if ($n > 13 && $i > $n / 2 || $n < 14) {
  2551. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  2552. $now_time[] = date('Y-m-d', $t);
  2553. }
  2554. }
  2555. $k_tmp_time = strtotime($now_time[0]);
  2556. $e_tmp_time = strtotime($now_time[count($now_time) - 1] ) + 24 * 3600;
  2557. $k_hb_time = $k_tmp_time - 365*24*3600;
  2558. $j_hb_time = $e_tmp_time - 365*24*3600;
  2559. // var_dump(date("Y-m-d H:i:s", $k_tmp_time)."=========".date("Y-m-d H:i:s", $e_tmp_time));
  2560. // var_dump(date("Y-m-d H:i:s", $k_hb_time)."=========".date("Y-m-d H:i:s", $j_hb_time));
  2561. // die;
  2562. // $timedata = explode('|', $time);
  2563. // $ktime = strtotime($timedata[0]) + 24 * 3600;
  2564. // $jtime = strtotime($timedata[1]);
  2565. // $ll_time = ($jtime - $ktime);
  2566. // $k_time = $ktime - $ll_time ;
  2567. // $j_time = $jtime - $ll_time;
  2568. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  2569. }else{
  2570. $k_time = "";
  2571. $j_time = "";
  2572. if($time >= 691200){
  2573. $k_time = strtotime(date("Ymd", time())) - $time+ 24 * 3600;
  2574. $j_time = strtotime(date("Ymd", time()));
  2575. $k_hb_time = $k_time - 365*24*3600;
  2576. $j_hb_time = $j_time - 365*24*3600;
  2577. }else{
  2578. $k_time = strtotime(date("Ymd", time())) - $time + 24 * 3600;
  2579. $j_time = $k_time + 24 * 3600;
  2580. $k_hb_time = $k_time - 365*24*3600;
  2581. $j_hb_time = $j_time - 365*24*3600;
  2582. }
  2583. // var_dump(date("Y-m-d H:i:s", $k_time)."=========".date("Y-m-d H:i:s", $j_time));
  2584. // var_dump(date("Y-m-d H:i:s", $k_hb_time)."=========".date("Y-m-d H:i:s", $j_hb_time));
  2585. // die;
  2586. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  2587. }
  2588. if ($source) {
  2589. if ($source == '2d') {
  2590. $where .= " and source >= '2' ";
  2591. } else {
  2592. $where .= " and source = '$source' ";
  2593. }
  2594. }
  2595. if($table_name == 'fullordertt' || $table_name == 'fullorderamz'){
  2596. $where .= " and state != 217 ";
  2597. }
  2598. $list = $this->$table_name->find_all($where . " and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'budget,shouldmoney,shop,number,refundy,budget,email,refundy');
  2599. $sl = count($list);
  2600. $je = sprintf("%01.2f", array_sum(array_column($list, 'shouldmoney')));
  2601. $ssje = 0;
  2602. //实收金额
  2603. $dlzmss = sprintf("%01.2f", array_sum(array_column($list, 'budget')));
  2604. //实收金额
  2605. //补/退原额
  2606. $dlzbty = sprintf("%01.2f", array_sum(array_column($list, 'refundy')));
  2607. $ssje = sprintf("%01.2f", $dlzmss + $dlzbty);
  2608. echo json_encode([
  2609. 'status' => 1,
  2610. 'data' => [
  2611. 'sl' => $sl,
  2612. 'je' => $je,
  2613. 'ssje' => $ssje,
  2614. ]
  2615. ]);
  2616. exit; //,'sycp'=>$sycp昨日产品数据
  2617. }
  2618. public function _user_lvceshi(){
  2619. $dt = 0;
  2620. if (isset($_SESSION['api'])) {
  2621. $user = $this->user->get_api($_SESSION['api']);
  2622. $usp = $user;
  2623. $fgshop = "";
  2624. $sid = "";
  2625. $user = explode('|', trim($user['shop'], '|'));
  2626. foreach ($user as $value) {
  2627. // 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')
  2628. // {
  2629. // $fgshop .= " shop = ".$value." or";
  2630. // }
  2631. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  2632. $fgshop .= " shop = " . $value . " or";
  2633. }
  2634. $sid .= " id = " . $value . " or";
  2635. }
  2636. }
  2637. $post = $this->input->post(NULL, TRUE);
  2638. $source = $this->input->post('source', true);
  2639. $where = "";
  2640. if ($source) {
  2641. if ($source == '2d') {
  2642. $where = " and source >= '2'";
  2643. } else {
  2644. $where = " and source = '$source'";
  2645. }
  2646. }
  2647. $tm = strtotime(date("Ymd"), time());
  2648. $usat = $tm;
  2649. $wlshop = $this->shop->find_all('status = 0 and ' . rtrim($sid, 'or'));
  2650. $this->data['wlshop'] = $wlshop;
  2651. $dr = $usat;
  2652. $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));
  2653. $this->_Template('phone/p_user_statistics_copy', $this->data);
  2654. }
  2655. }