User.php 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049
  1. <?php defined('BASEPATH') or exit('No direct script access allowed');
  2. class User 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()
  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])) {
  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'");
  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'");
  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', $this->data);
  937. }
  938. /**
  939. public function super_unique($array,$key)//多维删除重复
  940. {
  941. $temp_array = array();
  942. foreach ($array as &$v) {
  943. if (!isset($temp_array[$v[$key]]))
  944. {
  945. $temp_array[$v[$key]] =& $v;
  946. }
  947. }
  948. $array = array_values($temp_array);
  949. return $array;
  950. }
  951. **/
  952. public function _usatime()
  953. {
  954. date_default_timezone_set("Etc/GMT+8");
  955. return time();
  956. }
  957. //数据
  958. public function _rows()
  959. {
  960. $post = $this->input->post(NULL, TRUE);
  961. if (isset($post['shop'])) {
  962. $shop = $this->input->post('shop', true);
  963. $data = $this->shop->find_all('1=1',"*","px asc");
  964. $list = array();
  965. foreach ($data as $key => $value) {
  966. $t = $this->typeclass->read($value['type']);
  967. $list[] = array('id' => $value['id'], 'title' => $value['shopname'] . ' - ' . $t['title']);
  968. }
  969. $num = array();
  970. if ($shop != "null") {
  971. $num = $this->user->read($shop); //找出内容
  972. if ($num['shop']) {
  973. $num = explode('|', trim($num['shop'], '|')); //数组化内容
  974. } else {
  975. $num = array();
  976. }
  977. }
  978. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  979. }
  980. if (isset($post['excelshop'])) {
  981. $excelshop = $this->input->post('excelshop', true);
  982. $data = $this->shop->find_all('1=1',"*","px asc");
  983. $list = array();
  984. foreach ($data as $key => $value) {
  985. $t = $this->typeclass->read($value['type']);
  986. $list[] = array('id' => $value['id'], 'title' => $value['shopname'] . ' - ' . $t['title']);
  987. }
  988. $num = array();
  989. if ($excelshop != "null") {
  990. $num = $this->user->read($excelshop); //找出内容
  991. if ($num['excelshop']) {
  992. $num = explode('|', trim($num['excelshop'], '|')); //数组化内容
  993. } else {
  994. $num = array();
  995. }
  996. }
  997. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  998. }
  999. if (isset($post['purchase'])) {
  1000. $purchase = $this->input->post('purchase', true);
  1001. $data = $this->purchase->find_all('1=1');
  1002. $list = array();
  1003. foreach ($data as $key => $value) {
  1004. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1005. }
  1006. $num = array();
  1007. if ($purchase != "null") {
  1008. $num = $this->user->read($purchase); //找出内容
  1009. if ($num['purchase']) {
  1010. $num = explode('|', trim($num['purchase'], '|')); //数组化内容
  1011. } else {
  1012. $num = array();
  1013. }
  1014. }
  1015. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1016. }
  1017. if (isset($post['staff'])) {
  1018. $staff = $this->input->post('staff', true);
  1019. $data = $this->staff->find_all('1=1');
  1020. $list = array();
  1021. foreach ($data as $key => $value) {
  1022. $list[] = array('id' => $value['id'], 'title' => $value['name']);
  1023. }
  1024. $num = array();
  1025. if ($staff != "null") {
  1026. $num = $this->user->read($staff); //找出内容
  1027. if ($num['staff']) {
  1028. $num = explode('|', trim($num['staff'], '|')); //数组化内容
  1029. } else {
  1030. $num = array();
  1031. }
  1032. }
  1033. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1034. }
  1035. if (isset($post['warehouse'])) {
  1036. $warehouse = $this->input->post('warehouse', true);
  1037. $data = $this->warehouse->find_all('1=1');
  1038. $list = array();
  1039. foreach ($data as $key => $value) {
  1040. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1041. }
  1042. $num = array();
  1043. if ($warehouse != "null") {
  1044. $num = $this->user->read($warehouse); //找出内容
  1045. if ($num['warehouse']) {
  1046. $num = explode('|', trim($num['warehouse'], '|')); //数组化内容
  1047. } else {
  1048. $num = array();
  1049. }
  1050. }
  1051. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1052. }
  1053. if (isset($post['transfer'])) {
  1054. $transfer = $this->input->post('transfer', true);
  1055. $data = $this->transfer->find_all('1=1');
  1056. $list = array();
  1057. foreach ($data as $key => $value) {
  1058. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1059. }
  1060. $num = array();
  1061. if ($transfer != "null") {
  1062. $num = $this->user->read($transfer); //找出内容
  1063. if ($num['transfer']) {
  1064. $num = explode('|', trim($num['transfer'], '|')); //数组化内容
  1065. } else {
  1066. $num = array();
  1067. }
  1068. }
  1069. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1070. }
  1071. }
  1072. public function _shopfx()
  1073. {
  1074. $post = $this->input->post(NULL, TRUE);
  1075. if (isset($post['time'])) {
  1076. $time = $this->input->post('time', true);
  1077. $t = strtotime(date("Ymd", time() + 24 * 3600)); //明天0点
  1078. $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");
  1079. $sid = '';
  1080. foreach ($shop as $value) {
  1081. $sid .= " shop = " . $value['id'] . " or";
  1082. }
  1083. $sid = " and (" . rtrim($sid, 'or') . ")";
  1084. $znum = $this->fullorder->find_count("dtime > '" . ($t - $time * 24 * 3600) . "' and dtime < '" . $t . "'" . $sid);
  1085. $data = array();
  1086. $list = array();
  1087. $color = array('0' => '#30546c', '1' => '#61a0a8', '2' => '#c23531', '3' => '#d48265', '4' => '#546570', '5' => '#749f83', '6' => '#bda29a', '7' => '#6e7074', '8' => '#546570');
  1088. $j = 0;
  1089. $zt = array(7 => 1, 30 => 2);
  1090. foreach ($shop as $v) {
  1091. $d = $this->fullorder->find_count("shop = '" . $v['id'] . "' and dtime > '" . ($t - $time * 24 * 3600) . "' and dtime < '" . $t . "' and (state = '207' or state = '216')");
  1092. $wd = $this->allocation->read($zt[$time]);
  1093. $n = json_decode($wd['content'], true);
  1094. $bfb = ($d == 0) ? 0 : round(($d / $znum) * 100, 2);
  1095. $data[] = array('value' => $bfb, 'name' => $v['shopname'] . ' ' . $bfb . "%", 'itemStyle' => array('color' => $color[$j]));
  1096. $n[$v['id']][] = $this->fullorder->find_count("shop = '" . $v['id'] . "' and gtime = '" . date("Ymd", time()) . "' and (state = '207' or state = '216')");
  1097. $t_list = array();
  1098. for ($i = 0; $i < $time; $i++) {
  1099. $t_list[] = date("m-d", time() - ($i * 24 * 3600));
  1100. }
  1101. $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) . '%');
  1102. $j++;
  1103. }
  1104. $list = (array_reverse($list));
  1105. echo json_encode(array('data' => ($data), 'list' => $list, 't' => (array_reverse($t_list)), 'success' => true));
  1106. exit;
  1107. /**
  1108. $time = $this->input->post('time',true);
  1109. $t = strtotime(date("Ymd",time()+24*3600));//明天0点
  1110. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1111. $sid = '';
  1112. foreach ($shop as $value)
  1113. {
  1114. $sid .= " shop = ".$value['id']." or";
  1115. }
  1116. $sid = " and (".rtrim($sid,'or').")";
  1117. $znum = $this->fullorder->find_count("dtime > '".($t-$time*24*3600)."' and dtime < '".$t."'".$sid);
  1118. $data = array();$list = array();
  1119. $color = array('0'=>'#30546c','1'=>'#61a0a8','2'=>'#c23531','3'=>'#d48265','4'=>'#546570','5'=>'#749f83','6'=>'#bda29a','7'=>'#6e7074','8'=>'#546570');
  1120. $j = 0;
  1121. foreach ($shop as $v)
  1122. {
  1123. $d = $this->fullorder->find_count("shop = '".$v['id']."' and dtime > '".($t-$time*24*3600)."' and dtime < '".$t."' and (state = '207' or state = '216')");
  1124. $bfb = ($d==0)?0:round(($d / $znum) * 100, 2);
  1125. $data[] = array('value'=>$bfb,'name'=>$v['shopname'].' '.$bfb."%",'itemStyle'=>array('color'=>$color[$j]));
  1126. $n = array();$t_list = array();
  1127. for($i=0;$i<$time;$i++)
  1128. {
  1129. if($i == 0)
  1130. {
  1131. $s = date("Ymd",time());
  1132. }
  1133. else
  1134. {
  1135. $s = date("Ymd",time()-($i*24*3600));
  1136. }
  1137. $t_list[] = date("m-d",time()-($i*24*3600));
  1138. $n[] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".$s."' and (state = '207' or state = '216')");
  1139. }
  1140. $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).'%');
  1141. $j++;
  1142. }
  1143. $list = (array_reverse($list));
  1144. echo json_encode(array('data'=>($data),'list'=>$list,'t'=>(array_reverse($t_list)),'success'=>true));exit;
  1145. **/
  1146. }
  1147. $this->_Template('phone/p_user_shopfx', $this->data);
  1148. }
  1149. public function _shopfxlist()
  1150. {
  1151. $t = strtotime(date("Ymd", time())); //今天0点
  1152. $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");
  1153. $sid = '';
  1154. foreach ($shop as $value) {
  1155. $sid .= " shop = " . $value['id'] . " or";
  1156. }
  1157. $sid = " and (" . rtrim($sid, 'or') . ")";
  1158. $zt = array(7, 30);
  1159. $this->db->trans_begin();
  1160. foreach ($zt as $key => $time) {
  1161. $data = array();
  1162. $list = array();
  1163. foreach ($shop as $v) {
  1164. $n = array();
  1165. $t_list = array();
  1166. for ($i = 1; $i < $time; $i++) {
  1167. if ($i == 0) {
  1168. $s = date("Ymd", time());
  1169. } else {
  1170. $s = date("Ymd", time() - ($i * 24 * 3600));
  1171. }
  1172. $t_list[] = date("m-d", time() - ($i * 24 * 3600));
  1173. $n[] = $this->fullorder->find_count("shop = '" . $v['id'] . "' and gtime = '" . $s . "' and (state = '207' or state = '216')");
  1174. }
  1175. $list[$v['id']] = array_reverse($n);
  1176. }
  1177. $this->allocation->save(array('content' => json_encode($list)), $key + 1);
  1178. }
  1179. if ($this->db->trans_status() === FALSE) {
  1180. $this->db->trans_rollback();
  1181. echo 'orver';
  1182. } else {
  1183. $this->db->trans_commit();
  1184. echo 'ok';
  1185. }
  1186. }
  1187. public function _apple()
  1188. {
  1189. $this->_Template('phone/p_user_apple', $this->data);
  1190. }
  1191. //退出
  1192. public function _tc()
  1193. {
  1194. $this->session->sess_destroy();
  1195. header("Location:/");
  1196. }
  1197. public function _tjadd()
  1198. {
  1199. $pdtime = date('Y-m-d-H', time());
  1200. //if(is_file("./data/tj/".$pdtime.".txt"))
  1201. if (is_file("./data/tj/" . $pdtime . ".txt")) {
  1202. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  1203. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  1204. fclose($myfile);
  1205. $bc = json_decode($bc, true);
  1206. $zzt = array($bc['zzt'][0], $bc['zzt'][1]);
  1207. } else {
  1208. /** 暂时不需要了
  1209. //柱状图数据
  1210. $i = 0;
  1211. $data = array();$sndata1 = array();$sndata2 = array();$sndata3 = array();
  1212. $sj = array('01','02','03','04','05','06','07','08','09','10','11','12');
  1213. foreach ($sj as $k=>$v)
  1214. {
  1215. $i++;
  1216. $dlz1 = $this->fullorder->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1217. $smt1 = $this->fullordersmt->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1218. $m1 = sprintf("%01.2f",array_sum(array_column($dlz1,'shouldmoney'))+array_sum(array_column($smt1,'shouldmoney')));
  1219. $dlz2 = $this->fullorder->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1220. $smt2 = $this->fullordersmt->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1221. $m2 = sprintf("%01.2f",array_sum(array_column($dlz2,'shouldmoney'))+array_sum(array_column($smt2,'shouldmoney')));
  1222. $dlz3 = $this->fullorder->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1223. $smt3 = $this->fullordersmt->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1224. $m3 = sprintf("%01.2f",array_sum(array_column($dlz3,'shouldmoney'))+array_sum(array_column($smt3,'shouldmoney')));
  1225. $sndata1[$i] = $m3;
  1226. $sndata2[12+$i] = $m2;
  1227. $sndata3[24+$i] = $m1;
  1228. $data[] = array($v,$m1,$m2,$m3);
  1229. }
  1230. $sndata = array_merge($sndata1,$sndata2,$sndata3);
  1231. $zzt = array($data,$sndata);
  1232. //柱状图结束
  1233. **/
  1234. }
  1235. //详情内容
  1236. $dt = 0;
  1237. //系统报错 提示没有api下标的键
  1238. if(!isset($_SESSION['api'])){
  1239. echo "ERROR";
  1240. die;
  1241. }
  1242. $user = $this->user->get_api($_SESSION['api']);
  1243. $usp = $user;
  1244. $fgshop = "";
  1245. $sid = "";
  1246. $user = explode('|', trim($user['shop'], '|'));
  1247. foreach ($user as $value) {
  1248. if(!empty($value)){
  1249. $fgshop .= " shop = " . $value . " or";
  1250. $sid .= " id = " . $value . " or";
  1251. }
  1252. }
  1253. //为了让下面程序可以执行 给的如果用户没店铺权限 就给一个不存在的店铺
  1254. if(empty($fgshop)){
  1255. $fgshop = " shop = 0 or";
  1256. $sid = " id = 0 or";
  1257. }
  1258. $tm = strtotime(date("Ymd"), time());
  1259. $usat = $tm;
  1260. //$molist = array('0','1','2d');
  1261. $molist = array('0', '1');
  1262. $zqtime = array(259200, 345600, 691200, 2678400, 7862400, 31622400);
  1263. //time开始
  1264. $zqtdata = array();
  1265. foreach ($molist as $vval) {
  1266. $where = "";
  1267. $source = $vval;
  1268. if ($source == '2d') {
  1269. $where = " and source >= '2'";
  1270. } else if ($source != '0') {
  1271. $where = " and source = '$source'";
  1272. }
  1273. foreach ($zqtime as $value) {
  1274. $zdt = $value;
  1275. $k = $zdt;
  1276. $tab = 1;
  1277. //$start = '2018-10-15';
  1278. //$end = '2018-11-26';
  1279. //$tim = strtotime($start);
  1280. //$day = $time/(3600*24);
  1281. if ($tab == '1') {
  1282. if ($zdt >= 691200) {
  1283. $k = $usat - $k - $k;
  1284. $j = $usat;
  1285. $n = ($j - $k) / (24 * 3600);
  1286. } else {
  1287. $n = 2;
  1288. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  1289. }
  1290. } else {
  1291. $timedata = explode('|', $zdt);
  1292. $ktime = strtotime($timedata[0]);
  1293. $jtime = strtotime($timedata[1]);
  1294. $ktime = $ktime - ($jtime - $ktime);
  1295. $k = $ktime;
  1296. $j = $jtime;
  1297. $n = ($j - $k) / (24 * 3600);
  1298. $usat = $jtime;
  1299. $tm = $jtime;
  1300. $zdt = $jtime - $ktime;
  1301. }
  1302. $time = array();
  1303. $timeold = array();
  1304. $stime = array();
  1305. $dlznum = array();
  1306. $smtnum = array();;
  1307. $ttnum = array();
  1308. $ymoney = array();
  1309. $money = array();
  1310. $dlzmoney = array();
  1311. $smtmoney = array();
  1312. $ttmoney = array();
  1313. $dlzmoneyb = array();
  1314. $smtmoneyb = array();
  1315. $ttmoneyb = array();
  1316. $dlzsl = 0;
  1317. $dlzje = 0;
  1318. $dlzssje = 0;
  1319. $smtsl = 0;
  1320. $smtje = 0;
  1321. $smtssje = 0;
  1322. $ttsl = 0;
  1323. $ttje = 0;
  1324. $ttssje = 0;
  1325. $shopdata = array();
  1326. $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'");
  1327. foreach ($ys as $v) {
  1328. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  1329. }
  1330. for ($i = 1; $i < $n; $i++) {
  1331. //近7天时间
  1332. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1333. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1334. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1335. $time[] = date('m-d', $t);
  1336. $ct = strtotime(date('Ymd', $t));
  1337. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1338. $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');
  1339. $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');
  1340. $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');
  1341. $ab[] = $dlz;
  1342. //数量及金额开始
  1343. $dlznum[] = count($dlz);
  1344. $smtnum[] = count($smt);
  1345. $ttnum[] = count($smt);
  1346. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1347. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1348. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1349. /**
  1350. //提出退款关闭等信息的实收金额
  1351. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1352. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1353. //提出退款关闭等信息的实收金额
  1354. **/
  1355. //实收金额
  1356. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  1357. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  1358. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  1359. //实收金额
  1360. //补/退原额
  1361. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  1362. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  1363. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  1364. //补/退原额
  1365. $dlzmoney[] = $dlzm;
  1366. $smtmoney[] = $smtm;
  1367. $ttmoney[] = $ttm;
  1368. $dlzsl += count($dlz);
  1369. $dlzje += $dlzm;
  1370. $smtsl += count($smt);
  1371. $smtje += $smtm;
  1372. $ttsl += count($tt);
  1373. $ttje += $ttm;
  1374. /**
  1375. //减去的实收金额
  1376. $dlzssje += $dlzm+$dlzmss;
  1377. $smtssje += $smtm+$smtmss;
  1378. **/
  1379. //实收和补/退
  1380. $dlzssje += $dlzmss + $dlzbty;
  1381. $smtssje += $smtmss + $smtbty;
  1382. $ttssje += $ttmss + $ttbty;
  1383. //数量及金额结束
  1384. $sd = array_merge($dlz, $smt, $tt);
  1385. foreach ($sd as $v) {
  1386. if (isset($shopdata[$v['shop']])) {
  1387. $shopdata[$v['shop']]['num'] += 1;
  1388. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  1389. $shopdata[$v['shop']]['tmoney'] += $v['budget'] + $v['refundy'];
  1390. }
  1391. }
  1392. } else if ($n > 13 && $i <= $n / 2) {
  1393. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1394. $timeold[] = date('m-d', $t);
  1395. $ct = strtotime(date('Ymd', $t));
  1396. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1397. $dlz = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1398. $smt = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1399. $tt = $this->fullordertt->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1400. //数量及金额开始
  1401. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1402. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1403. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1404. $dlzmoneyb[] = $dlzm;
  1405. $smtmoneyb[] = $smtm;
  1406. $ttmoneyb[] = $ttm;
  1407. //数量及金额结束
  1408. }
  1409. }
  1410. foreach ($shopdata as $k => $v) {
  1411. $sn = $this->shop->read($k);
  1412. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  1413. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  1414. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  1415. $shopdata[$k]['name'] = $sn['shopname'];
  1416. $shopdata[$k]['b'] = $sn['type'];
  1417. $shopdata[$k]['id'] = $sn['id'];
  1418. }
  1419. $shopdata = array_values($shopdata);
  1420. //$sycp=array();
  1421. /**
  1422. //根据所选时间产品排行开始
  1423. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1424. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1425. **/
  1426. /**
  1427. //昨日产品排行开始
  1428. $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');
  1429. $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');
  1430. $rows = array_merge($dlzlist,$smtlist);
  1431. foreach ($rows as $v)
  1432. {
  1433. $number = explode('|',trim($v['whlabel'],'|'));
  1434. $or = explode(';',trim($v['fpdata'],';'));
  1435. $i=0;
  1436. foreach ($or as $va)
  1437. {
  1438. $ord = explode('|',$va);
  1439. $orod = explode(',',$ord[0]);
  1440. $numberod = explode('-',$number[$i]);
  1441. if(!isset($orod[1]))
  1442. {
  1443. continue;
  1444. }
  1445. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  1446. {
  1447. //$sycp[$orod[1]][0] += 1;//统计多少单
  1448. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  1449. $sycp[$orod[1]][1] += 0;//价格
  1450. }
  1451. else
  1452. {
  1453. if(isset($numberod[1]))
  1454. {
  1455. $typeclass = $this->typeclass->read($orod['0']);
  1456. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  1457. }
  1458. }
  1459. $i++;
  1460. }
  1461. }
  1462. arsort($sycp);
  1463. $sycp = array_values($sycp);
  1464. $sycp = array_slice($sycp,0,10);
  1465. //产品排行结束
  1466. **/
  1467. //当时实时数据结束
  1468. $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昨日产品数据
  1469. }
  1470. }
  1471. //time结束
  1472. //zhcx开始
  1473. $zhcxdata = array();
  1474. foreach ($molist as $vval) {
  1475. $where = "";
  1476. $source = $vval;
  1477. if ($source == '2d') {
  1478. $where = " and source >= '2'";
  1479. } else if ($source != '0') {
  1480. $where = " and source = '$source'";
  1481. }
  1482. foreach ($zqtime as $value) {
  1483. $zdt = $value;
  1484. $k = $zdt;
  1485. $tab = 1;
  1486. //$customer = $this->customer->find_all("shop !=''",'num,zhcx');
  1487. //$customerkey = array_column($customer,'zhcx');
  1488. //$customer= array_combine($customerkey,$customer);
  1489. //$customersmt = $this->customersmt->find_all("shop !=''",'num,zhcx');
  1490. //$customersmtkey = array_column($customersmt,'zhcx');
  1491. //$customersmt= array_combine($customersmtkey,$customersmt);
  1492. //$customertt = $this->customertt->find_all("shop !=''",'num,zhcx');
  1493. //$customerttkey = array_column($customertt,'zhcx');
  1494. //$customertt= array_combine($customerttkey,$customertt);
  1495. if ($tab == '1') {
  1496. if ($zdt >= 691200) {
  1497. $k = $usat - $k - $k;
  1498. $j = $usat;
  1499. $n = ($j - $k) / (24 * 3600);
  1500. } else {
  1501. $n = 2;
  1502. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  1503. }
  1504. } else {
  1505. $timedata = explode('|', $zdt);
  1506. $ktime = strtotime($timedata[0]);
  1507. $jtime = strtotime($timedata[1]);
  1508. $ktime = $ktime - ($jtime - $ktime);
  1509. $k = $ktime;
  1510. $j = $jtime;
  1511. $n = ($j - $k) / (24 * 3600);
  1512. $usat = $jtime;
  1513. }
  1514. $time = array();
  1515. $timeold = array();
  1516. $stime = array();
  1517. $dlznum = array();
  1518. $smtnum = array();
  1519. $ttnum = array();
  1520. $ymoney = array();
  1521. $money = array();
  1522. $dlzmoneyb = array();
  1523. $smtmoneyb = array();
  1524. $ttmoneyb = array();
  1525. $zkh = array();
  1526. $dlzsl = 0;
  1527. $dlzje = 0;
  1528. $dlzssje = 0;
  1529. $smtsl = 0;
  1530. $smtje = 0;
  1531. $smtssje = 0;
  1532. $ttsl = 0;
  1533. $ttje = 0;
  1534. $ttssje = 0;
  1535. $shopdata = array();
  1536. $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'");
  1537. foreach ($ys as $v) {
  1538. $shopdata[$v['id']] = array('id' => $v['id'], 'b' => $v['type'], 'fdl' => 0, 'chl' => 0, 'num' => 0, 'fgl' => 0);
  1539. $zkh[$v['id']] = array();
  1540. }
  1541. for ($i = 1; $i < $n; $i++) {
  1542. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1543. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1544. $time[] = date('m-d', $t);
  1545. $ct = strtotime(date('Ymd', $t));
  1546. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1547. $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');
  1548. $dlzemail = $this->fullorder->find_all("dtime <= " . $ctj . $where . " and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'shop,email');
  1549. $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');
  1550. $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');
  1551. //数量及金额结束
  1552. $sd = array_merge($dlz, $smt, $tt);
  1553. $fgldata = array();
  1554. foreach ($sd as $v) {
  1555. /**
  1556. $array = array(
  1557. 0 => array('email' => 123, 'id' => 1),
  1558. 1 => array('email' => 321, 'id' => 2),
  1559. 2 => array('email' => 123, 'id' => 3),
  1560. 3 => array('email' => 123, 'id' => 3)
  1561. );
  1562. // 使用 array_filter 筛选满足多个条件的元素
  1563. $result = array_filter($array, function($item) {
  1564. return $item['email'] === 123 && $item['id'] === 3;
  1565. });
  1566. // 计算满足条件的数量
  1567. $count = count($result);
  1568. echo "满足条件 (email = 123 且 id = 3) 的数量是:$count";
  1569. **/
  1570. /** 独立站查customer方法 弃用
  1571. if(isset($v['email']))
  1572. {
  1573. if(!isset($fgldata[$v['shop'].'-'.$v['email']]))
  1574. {
  1575. $fgldata[$v['shop'].'-'.$v['email']] = 0;
  1576. }
  1577. else
  1578. {
  1579. $fgldata[$v['shop'].'-'.$v['email']] += 1;
  1580. }
  1581. $zkh[$v['shop']][$v['email']] = array();
  1582. }
  1583. **/
  1584. /** 速卖通
  1585. else
  1586. {
  1587. if(!isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1588. {
  1589. $fgldata[$v['shop'].'-'.$v['userid']] = 0;
  1590. }
  1591. else
  1592. {
  1593. $fgldata[$v['shop'].'-'.$v['userid']] += 1;
  1594. }
  1595. $zkh[$v['shop']][$v['userid']] = array();
  1596. }
  1597. **/
  1598. }
  1599. foreach ($sd as $v) {
  1600. //避免由于作用域引起的问题
  1601. $tmp_v = $v;
  1602. $fdl_result = array_filter($dlz, function ($item) use ($tmp_v) {
  1603. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1604. return false;
  1605. } else {
  1606. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1607. }
  1608. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1609. });
  1610. $fdl = count($fdl_result) > 1 ? 1 : 0; //返单
  1611. $chl_result = array_filter($dlz, function ($item) use ($tmp_v) {
  1612. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1613. return false;
  1614. } else {
  1615. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1616. }
  1617. //return $item['email'] === $tmp_v['email'] && $item['shop'] !== $tmp_v['email'];
  1618. });
  1619. $chl = count($chl_result) > 1 ? 1 : 0; //重合
  1620. $fgl_result = array_filter($dlzemail, function ($item) use ($tmp_v) {
  1621. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1622. return false;
  1623. } else {
  1624. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1625. }
  1626. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1627. });
  1628. $fgl = count($fgl_result) > 1 ? 1 : 0; //复购
  1629. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl'] + $fdl;
  1630. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl'] + $chl;
  1631. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl'] + $fgl;
  1632. $shopdata[$v['shop']]['num'] += 1;
  1633. /**
  1634. $chl = 0;
  1635. if(isset($shopdata[$v['shop']]))
  1636. {
  1637. if(isset($v['email']))
  1638. {
  1639. if(isset($customer[$v['shop'].'-'.$v['email']]['num']))
  1640. {
  1641. $fdl = $customer[$v['shop'].'-'.$v['email']]['num']>1?1:0;
  1642. }
  1643. else
  1644. {
  1645. $fdl = 0;
  1646. }
  1647. foreach ($ys as $vv)
  1648. {
  1649. if($vv['id'] != $v['shop'] && isset($customer[$vv['id'].'-'.$v['email']]))
  1650. {
  1651. $chl = 1;
  1652. }
  1653. }
  1654. if(isset($fgldata[$v['shop'].'-'.$v['email']]))
  1655. {
  1656. $fgl = $fgldata[$v['shop'].'-'.$v['email']]>0?1:0;
  1657. }
  1658. else
  1659. {
  1660. $fgl = 0;
  1661. }
  1662. }
  1663. else
  1664. {
  1665. if(isset($customersmt[$v['shop'].'-'.$v['userid']]['num']))
  1666. {
  1667. $fdl = $customersmt[$v['shop'].'-'.$v['userid']]['num']>1?1:0;
  1668. }
  1669. else
  1670. {
  1671. $fdl = 0;
  1672. }
  1673. foreach ($ys as $vv)
  1674. {
  1675. if($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'].'-'.$v['userid']]))
  1676. {
  1677. $chl = 1;
  1678. }
  1679. }
  1680. if(isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1681. {
  1682. $fgl = $fgldata[$v['shop'].'-'.$v['userid']]>0?1:0;
  1683. }
  1684. else
  1685. {
  1686. $fgl = 0;
  1687. }
  1688. }
  1689. }
  1690. **/
  1691. }
  1692. }
  1693. }
  1694. foreach ($shopdata as $k => $v) {
  1695. $shopdata[$k]['fdl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['fdl'] / $v['num'] * 100)) . '%';
  1696. $shopdata[$k]['chl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['chl'] / $v['num'] * 100)) . '%';
  1697. $shopdata[$k]['fgl'] = count($zkh[$v['id']]) == '0' ? 0 : sprintf("%01.2f", ($v['fgl'] / count($zkh[$v['id']]) * 100)) . '%';
  1698. }
  1699. $shopdata = array_values($shopdata);
  1700. $zhcxdata[$vval][$value] = array('shopdata' => $shopdata, 'success' => true);
  1701. }
  1702. }
  1703. //zhcx结束
  1704. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "w") or die("Unable to open file!");
  1705. $txt = json_encode(array('zzt' => $zzt, 'tj' => $zqtdata, 'zhcx' => $zhcxdata));
  1706. fwrite($myfile, $txt);
  1707. fclose($myfile);
  1708. echo 1;
  1709. }
  1710. public function _statistics_hb(){
  1711. if (isset($_SESSION['api'])) {
  1712. $user = $this->user->get_api($_SESSION['api']);
  1713. $usp = $user;
  1714. $fgshop = "";
  1715. $sid = "";
  1716. $user = explode('|', trim($user['shop'], '|'));
  1717. foreach ($user as $value) {
  1718. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  1719. $fgshop .= " shop = " . $value . " or";
  1720. }
  1721. $sid .= " id = " . $value . " or";
  1722. }
  1723. }
  1724. $source = $this->input->post('source');
  1725. $time = $this->input->post('time');
  1726. $tab = $this->input->post('tab');
  1727. $table_name = $this->input->post('table_name');
  1728. if(empty($table_name)){
  1729. $table_name = 'fullorder';
  1730. }
  1731. if($tab == 2){
  1732. $now_time = [];
  1733. $timedata = explode('|', $time);
  1734. $ktime = strtotime($timedata[0]);
  1735. $jtime = strtotime($timedata[1]);
  1736. $ktime = $ktime - ($jtime - $ktime);
  1737. $k = $ktime;
  1738. $j = $jtime;
  1739. $n = ($j - $k) / (24 * 3600);
  1740. $usat = $jtime;
  1741. for ($i = 1; $i < $n; $i++) {
  1742. //近7天时间
  1743. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1744. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1745. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1746. $now_time[] = date('Y-m-d', $t);
  1747. }
  1748. }
  1749. $k_tmp_time = strtotime($now_time[0]);
  1750. $e_tmp_time = strtotime($now_time[count($now_time) - 1] ) + 24 * 3600;
  1751. $ll_time = ($e_tmp_time - $k_tmp_time) ;
  1752. // var_dump(date("Y-m-d H:i:s", $k_tmp_time)."=========".date("Y-m-d H:i:s", $e_tmp_time));
  1753. // var_dump(date("Y-m-d H:i:s", $k_tmp_time - $ll_time)."=========".date("Y-m-d H:i:s", $k_tmp_time));
  1754. // die;
  1755. $k_time = $k_tmp_time - $ll_time;
  1756. $j_time = $k_tmp_time;
  1757. // $timedata = explode('|', $time);
  1758. // $ktime = strtotime($timedata[0]) + 24 * 3600;
  1759. // $jtime = strtotime($timedata[1]);
  1760. // $ll_time = ($jtime - $ktime);
  1761. // $k_time = $ktime - $ll_time ;
  1762. // $j_time = $jtime - $ll_time;
  1763. $where = "( dtime >= ".$k_time." and dtime <= ".$j_time." ) ";
  1764. }else{
  1765. $k_time = "";
  1766. $j_time = "";
  1767. if($time >= 691200){
  1768. $k_time = strtotime(date("Ymd", time())) - $time+ 24 * 3600;
  1769. $j_time = strtotime(date("Ymd", time()));
  1770. $k_hb_time = $k_time - $time + 24 * 3600;
  1771. $j_hb_time = $k_time;
  1772. }else{
  1773. $k_time = strtotime(date("Ymd", time())) - $time + 24 * 3600;
  1774. $j_time = $k_time + 24 * 3600;
  1775. $k_hb_time = $k_time - 24 * 3600;
  1776. $j_hb_time = $j_time - 24 * 3600;
  1777. }
  1778. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  1779. }
  1780. if ($source) {
  1781. if ($source == '2d') {
  1782. $where .= " and source >= '2' ";
  1783. } else {
  1784. $where .= " and source = '$source' ";
  1785. }
  1786. }
  1787. if($table_name == 'fullordertt' || $table_name == 'fullorderamz'){
  1788. $where .= " and state != 217 ";
  1789. }
  1790. $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');
  1791. $sl = count($list);
  1792. $je = sprintf("%01.2f", array_sum(array_column($list, 'shouldmoney')));
  1793. $ssje = 0;
  1794. //实收金额
  1795. $dlzmss = sprintf("%01.2f", array_sum(array_column($list, 'budget')));
  1796. //实收金额
  1797. //补/退原额
  1798. $dlzbty = sprintf("%01.2f", array_sum(array_column($list, 'refundy')));
  1799. $ssje = sprintf("%01.2f", $dlzmss + $dlzbty);
  1800. echo json_encode([
  1801. 'status' => 1,
  1802. 'data' => [
  1803. 'sl' => $sl,
  1804. 'je' => $je,
  1805. 'ssje' => $ssje,
  1806. ]
  1807. ]);
  1808. exit; //,'sycp'=>$sycp昨日产品数据
  1809. }
  1810. public function _statistics_tb(){
  1811. if (isset($_SESSION['api'])) {
  1812. $user = $this->user->get_api($_SESSION['api']);
  1813. $usp = $user;
  1814. $fgshop = "";
  1815. $sid = "";
  1816. $user = explode('|', trim($user['shop'], '|'));
  1817. foreach ($user as $value) {
  1818. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  1819. $fgshop .= " shop = " . $value . " or";
  1820. }
  1821. $sid .= " id = " . $value . " or";
  1822. }
  1823. }
  1824. $source = $this->input->post('source');
  1825. $time = $this->input->post('time');
  1826. $tab = $this->input->post('tab');
  1827. $table_name = $this->input->post('table_name');
  1828. if(empty($table_name)){
  1829. $table_name = 'fullorder';
  1830. }
  1831. if($tab == 2){
  1832. $now_time = [];
  1833. $timedata = explode('|', $time);
  1834. $ktime = strtotime($timedata[0]);
  1835. $jtime = strtotime($timedata[1]);
  1836. $ktime = $ktime - ($jtime - $ktime);
  1837. $k = $ktime;
  1838. $j = $jtime;
  1839. $n = ($j - $k) / (24 * 3600);
  1840. $usat = $jtime;
  1841. for ($i = 1; $i < $n; $i++) {
  1842. //近7天时间
  1843. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1844. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1845. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1846. $now_time[] = date('Y-m-d', $t);
  1847. }
  1848. }
  1849. $k_tmp_time = strtotime($now_time[0]);
  1850. $e_tmp_time = strtotime($now_time[count($now_time) - 1] ) + 24 * 3600;
  1851. $k_hb_time = $k_tmp_time - 365*24*3600;
  1852. $j_hb_time = $e_tmp_time - 365*24*3600;
  1853. // var_dump(date("Y-m-d H:i:s", $k_tmp_time)."=========".date("Y-m-d H:i:s", $e_tmp_time));
  1854. // var_dump(date("Y-m-d H:i:s", $k_hb_time)."=========".date("Y-m-d H:i:s", $j_hb_time));
  1855. // die;
  1856. // $timedata = explode('|', $time);
  1857. // $ktime = strtotime($timedata[0]) + 24 * 3600;
  1858. // $jtime = strtotime($timedata[1]);
  1859. // $ll_time = ($jtime - $ktime);
  1860. // $k_time = $ktime - $ll_time ;
  1861. // $j_time = $jtime - $ll_time;
  1862. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  1863. }else{
  1864. $k_time = "";
  1865. $j_time = "";
  1866. if($time >= 691200){
  1867. $k_time = strtotime(date("Ymd", time())) - $time+ 24 * 3600;
  1868. $j_time = strtotime(date("Ymd", time()));
  1869. $k_hb_time = $k_time - 365*24*3600;
  1870. $j_hb_time = $j_time - 365*24*3600;
  1871. }else{
  1872. $k_time = strtotime(date("Ymd", time())) - $time + 24 * 3600;
  1873. $j_time = $k_time + 24 * 3600;
  1874. $k_hb_time = $k_time - 365*24*3600;
  1875. $j_hb_time = $j_time - 365*24*3600;
  1876. }
  1877. // var_dump(date("Y-m-d H:i:s", $k_time)."=========".date("Y-m-d H:i:s", $j_time));
  1878. // var_dump(date("Y-m-d H:i:s", $k_hb_time)."=========".date("Y-m-d H:i:s", $j_hb_time));
  1879. // die;
  1880. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  1881. }
  1882. if ($source) {
  1883. if ($source == '2d') {
  1884. $where .= " and source >= '2' ";
  1885. } else {
  1886. $where .= " and source = '$source' ";
  1887. }
  1888. }
  1889. if($table_name == 'fullordertt' || $table_name == 'fullorderamz'){
  1890. $where .= " and state != 217 ";
  1891. }
  1892. $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');
  1893. $sl = count($list);
  1894. $je = sprintf("%01.2f", array_sum(array_column($list, 'shouldmoney')));
  1895. $ssje = 0;
  1896. //实收金额
  1897. $dlzmss = sprintf("%01.2f", array_sum(array_column($list, 'budget')));
  1898. //实收金额
  1899. //补/退原额
  1900. $dlzbty = sprintf("%01.2f", array_sum(array_column($list, 'refundy')));
  1901. $ssje = sprintf("%01.2f", $dlzmss + $dlzbty);
  1902. echo json_encode([
  1903. 'status' => 1,
  1904. 'data' => [
  1905. 'sl' => $sl,
  1906. 'je' => $je,
  1907. 'ssje' => $ssje,
  1908. ]
  1909. ]);
  1910. exit; //,'sycp'=>$sycp昨日产品数据
  1911. }
  1912. public function _user_lvceshi(){
  1913. $dt = 0;
  1914. if (isset($_SESSION['api'])) {
  1915. $user = $this->user->get_api($_SESSION['api']);
  1916. $usp = $user;
  1917. $fgshop = "";
  1918. $sid = "";
  1919. $user = explode('|', trim($user['shop'], '|'));
  1920. foreach ($user as $value) {
  1921. // 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')
  1922. // {
  1923. // $fgshop .= " shop = ".$value." or";
  1924. // }
  1925. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  1926. $fgshop .= " shop = " . $value . " or";
  1927. }
  1928. $sid .= " id = " . $value . " or";
  1929. }
  1930. }
  1931. $post = $this->input->post(NULL, TRUE);
  1932. $source = $this->input->post('source', true);
  1933. $where = "";
  1934. if ($source) {
  1935. if ($source == '2d') {
  1936. $where = " and source >= '2'";
  1937. } else {
  1938. $where = " and source = '$source'";
  1939. }
  1940. }
  1941. $tm = strtotime(date("Ymd"), time());
  1942. $usat = $tm;
  1943. $wlshop = $this->shop->find_all('status = 0 and ' . rtrim($sid, 'or'));
  1944. $this->data['wlshop'] = $wlshop;
  1945. $dr = $usat;
  1946. $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));
  1947. $this->_Template('phone/p_user_statistics_copy', $this->data);
  1948. }
  1949. }