User.php 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307
  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,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. // 2026年09月22日 应要求修改
  624. //总金额 = 订单金额 + 补/退原额 实收金额 = 预估到账金额 +补/退净额
  625. $zdt = $this->input->post('time', true);
  626. $k = $zdt;
  627. $tab = $this->input->post('tab', true);
  628. $pdtime = date('Y-m-d-H', time());
  629. // if (is_file("./data/tj/" . $pdtime . ".txt") && $tab == 1 && $zdt > 172800) //前端改店内需要修改zdt 172800
  630. // {
  631. // $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  632. // $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  633. // fclose($myfile);
  634. // $bc = json_decode($bc, true);
  635. // echo json_encode($bc['tj'][$source][$zdt]);
  636. // exit;
  637. // } else {
  638. //$start = '2018-10-15';
  639. //$end = '2018-11-26';
  640. //$tim = strtotime($start);
  641. //$day = $time/(3600*24);
  642. if ($tab == '1') {
  643. $this->_statistics_sjc($fgshop,$zdt,$where,$k,$usat);
  644. } else {
  645. $this->_statistics_sjd($fgshop,$zdt,$where,$k,$usat);
  646. }
  647. }
  648. //}
  649. if (isset($post['sstime'])) {
  650. $shop = $this->input->post('shop', true);
  651. $zdtime = $usat;
  652. //当时实时数据开始
  653. if (!$shop) {
  654. $sssl = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  655. $ssje = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  656. $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');
  657. $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');
  658. $sssldlz = count($sssl);
  659. $ssslsmt = count($ssje);
  660. $sssltt = count($tje);
  661. $ssslamz = count($amzje);
  662. $ssjedlz = sprintf("%01.2f", array_sum(array_column($sssl, 'budget')));
  663. $ssjesmt = sprintf("%01.2f", array_sum(array_column($ssje, 'budget')));
  664. $ssjett = sprintf("%01.2f", array_sum(array_column($tje, 'budget')));
  665. $ssjeamz = sprintf("%01.2f", array_sum(array_column($amzje, 'budget')));
  666. $sssl = $sssldlz + $ssslsmt + $sssltt + $ssslamz;
  667. $ssje = $ssjedlz + $ssjesmt + $ssjett + $ssjeamz;
  668. } else {
  669. $sp = $this->shop->read($shop);
  670. if($sp['type'] == '1513'){
  671. $fu = 'fullorderamz';
  672. }elseif($sp['type'] == '270'){
  673. $fu = 'fullordersmt';
  674. }elseif($sp['type'] == '1514'){
  675. $fu = 'fullordertt';
  676. }else{
  677. $fu = 'fullorder';
  678. }
  679. //1513
  680. //$fu = ($sp['type'] == '269') ? 'fullorder' : 'fullordersmt';
  681. $ss = $this->$fu->find_all("dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . " and shop = '" . $shop . "'", 'budget,shouldmoney');
  682. $sssl = count($ss);
  683. $ssje = sprintf("%01.2f", array_sum(array_column($ss, 'budget')));
  684. }
  685. echo @json_encode(array('sstime' => date('m-d H:i', time()), 'sssl' => $sssl, 'ssje' => sprintf("%.2f", $ssje), 'success' => true));
  686. exit;
  687. }
  688. //店铺产品详情
  689. if (isset($post['id'])) {
  690. $tm += 24 * 3600;
  691. $gshtime = date('Y-m-d 0:0:0', time());
  692. $gshtime = strtotime($gshtime) + 24 * 60 * 60;
  693. $dpxq = array();
  694. $id = $this->input->post('id', true);
  695. $xqtime = $this->input->post('xqtime', true);
  696. $xqshop = $this->shop->read($id);
  697. if ($xqshop['type'] == "269" || $xqshop['type'] == "2768") {
  698. $sid = 'fullorder';
  699. } else if ($xqshop['type'] == "270") {
  700. $sid = 'fullordersmt';
  701. } else if ($xqshop['type'] == "1513") {
  702. $sid = 'fullorderamz';
  703. }else if ($xqshop['type'] == "1514") {
  704. $sid = 'fullordertt';
  705. }
  706. if ($xqtime > 345600) {
  707. $rows = $this->$sid->find_all("shop = '" . $id . "' and dtime >= '" . ($gshtime - $xqtime) . "' and dtime <= '" . ($gshtime + 24 * 60 * 60) . "'", 'whlabel,fpdata,number');
  708. } else {
  709. $rows = $this->$sid->find_all("shop = '" . $id . "' and dtime >= '" . ($gshtime - $xqtime) . "' and dtime <= '" . ($gshtime + 24 * 60 * 60 - $xqtime) . "'", 'whlabel,fpdata,number');
  710. }
  711. foreach ($rows as $v) {
  712. $or = explode('|', ltrim($v['whlabel'], '|'));
  713. for ($i = 0; $i < count($or); $i++) {
  714. $orod = explode('-', $or[$i]);
  715. if ($orod[0] == '') {
  716. continue;
  717. }
  718. if (isset($dpxq[$orod[0]])) {
  719. $dpxq[$orod[0]][0] += $orod[1]; //统计多少条
  720. //$dpxq[$orod[0]][0] += 1;//统计多少单
  721. $dpxq[$orod[0]][1] .= $v['number'] . ';'; //价格
  722. } else {
  723. $oo = explode(';', rtrim($v['fpdata'], ';'));
  724. @$ro = explode('|', $oo[$i]);
  725. if (isset($ro[1])) {
  726. $dpxq[$orod[0]] = array($orod[1], $v['number'] . ';', $ro[1]); //统计多少条
  727. //$dpxq[$orod[0]] = array(1,0,$ro[1]);//统计多少单
  728. }
  729. }
  730. }
  731. }
  732. $dpxq = array_values($dpxq);
  733. arsort($dpxq);
  734. $dpxq = array_slice($dpxq, 0, 9999);
  735. echo @json_encode(array('dpxq' => $dpxq, 'success' => true));
  736. exit;
  737. }
  738. $wlshop = $this->shop->find_all('status = 0 and ' . rtrim($sid, 'or'));
  739. $this->data['wlshop'] = $wlshop;
  740. $dr = $usat;
  741. $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));
  742. $this->_Template('phone/p_user_statistics', $this->data);
  743. }
  744. //统计的时间戳
  745. protected function _statistics_sjc($fgshop,$zdt,$where,$k,$usat){
  746. if ($zdt >= 691200) {
  747. $usat = $usat - 24 * 3600;
  748. $k = $usat - $k - $k;
  749. $j = $usat;
  750. $n = ($j - $k) / (24 * 3600);
  751. $usat = $usat + 24 * 3600;
  752. } else {
  753. $n = 2;
  754. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  755. }
  756. $time = array();
  757. $timeold = array();
  758. $stime = array();
  759. $dlznum = array();
  760. $smtnum = array();
  761. $ymoney = array();
  762. $money = array();
  763. $dlzmoneyb = array();
  764. $smtmoneyb = array();
  765. $ttmoneyb = array();
  766. $zkh = array();
  767. $dlzsl = 0;
  768. $dlzje = 0;
  769. $dlzssje = 0;
  770. $smtsl = 0;
  771. $smtje = 0;
  772. $smtssje = 0;
  773. $ttsl = 0;
  774. $ttje = 0;
  775. $ttssje = 0;
  776. $amzsl = 0;
  777. $amzje = 0;
  778. $amzssje = 0;
  779. $shopdata = array();
  780. $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');
  781. foreach ($ys as $v) {
  782. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  783. }
  784. for ($i = 1; $i < $n; $i++) {
  785. //近7天时间
  786. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  787. if ($n > 13 && $i > $n / 2 || $n < 14) {
  788. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  789. $time[] = date('m-d', $t);
  790. $ct = strtotime(date('Ymd', $t));
  791. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  792. //var_dump(date("Y-m-d H:i:s",$ct)."=================".date("Y-m-d H:i:s",$ctj));
  793. $dlz = $this->fullorder->find_all(" dtime >= " . $ct . " and dtime < " . $ctj . $where . " and wzsgd = 0 and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'budget,shouldmoney,shop,number,refundy,email,refundj');
  794. $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,refundj');
  795. $tt = $this->fullordertt->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,email,refundj');
  796. $amz = $this->fullorderamz->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,email,refundj');
  797. $ab[] = $dlz;
  798. //数量及金额开始
  799. $dlznum[] = count($dlz);
  800. $smtnum[] = count($smt);
  801. $ttnum[] = count($smt);
  802. $amznum[] = count($amz);
  803. //订单金额
  804. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  805. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  806. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  807. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  808. /**
  809. //提出退款关闭等信息的实收金额
  810. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  811. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  812. //提出退款关闭等信息的实收金额
  813. **/
  814. //实收金额
  815. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  816. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  817. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  818. $amzmss = sprintf("%01.2f", array_sum(array_column($amz, 'budget')));
  819. //实收金额
  820. //补/退原额
  821. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  822. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  823. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  824. $amzbty = sprintf("%01.2f", array_sum(array_column($amz, 'refundy')));
  825. //补/退原额
  826. //补/退净额
  827. $dlzbtj = sprintf("%01.2f", array_sum(array_column($dlz, 'refundj')));
  828. $smtbtj = sprintf("%01.2f", array_sum(array_column($smt, 'refundj')));
  829. $ttbtj = sprintf("%01.2f", array_sum(array_column($tt, 'refundj')));
  830. $amzbtj = sprintf("%01.2f", array_sum(array_column($amz, 'refundj')));
  831. //补/退净额
  832. $dlzmoney[] = $dlzm;
  833. $smtmoney[] = $smtm;
  834. $ttmoney[] = $ttm;
  835. $amzmoney[] = $amzm;
  836. // $dlzsl += count($dlz);
  837. // $dlzje += $dlzm + $dlzbty;
  838. // $smtsl += count($smt);
  839. // $smtje += $smtm + $smtbty;
  840. // $ttsl += count($tt);
  841. // $ttje += $ttm + $ttbty;
  842. // $amzsl += count($amz);
  843. // $amzje += $amzm + $amzbty;
  844. $dlzsl += count($dlz);
  845. $dlzje += $dlzm ;
  846. $smtsl += count($smt);
  847. $smtje += $smtm ;
  848. $ttsl += count($tt);
  849. $ttje += $ttm ;
  850. $amzsl += count($amz);
  851. $amzje += $amzm ;
  852. /**
  853. //减去的实收金额
  854. $dlzssje += $dlzm+$dlzmss;
  855. $smtssje += $smtm+$smtmss;
  856. **/
  857. //实收和补/退净额
  858. // $dlzssje += $dlzmss + $dlzbtj;
  859. // $smtssje += $smtmss + $smtbtj;
  860. // $ttssje += $ttmss + $ttbtj;
  861. // $amzssje += $amzmss + $amzbtj;
  862. $dlzssje += $dlzmss;
  863. $smtssje += $smtmss;
  864. $ttssje += $ttmss ;
  865. $amzssje += $amzmss;
  866. //数量及金额结束
  867. $sd = array_merge($dlz, $smt, $tt,$amz);
  868. foreach ($sd as $v) {
  869. if (isset($shopdata[$v['shop']])) {
  870. $shopdata[$v['shop']]['num'] += 1;
  871. // $shopdata[$v['shop']]['money'] += $v['shouldmoney'] + $v['refundy'] ;
  872. // $shopdata[$v['shop']]['tmoney'] += $v['budget'] + $v['refundj'];
  873. $shopdata[$v['shop']]['money'] += $v['shouldmoney'] ;
  874. $shopdata[$v['shop']]['tmoney'] += $v['budget'] ;
  875. }
  876. }
  877. } else if ($n > 13 && $i <= $n / 2) {
  878. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  879. $timeold[] = date('m-d', $t);
  880. $ct = strtotime(date('Ymd', $t));
  881. $ctj = strtotime(date('Ymd', $t + 24 * 3600)) ;
  882. //var_dump(date("Y-m-d H:i:s",$ct)."------------------------".date("Y-m-d H:i:s",$ctj));
  883. $dlz = $this->fullorder->find_all(" (" . rtrim($fgshop, 'or') . ") and wzsgd = 0 and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  884. $smt = $this->fullordersmt->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  885. $tt = $this->fullordertt->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  886. $amz = $this->fullorderamz->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  887. //数量及金额开始
  888. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  889. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  890. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  891. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  892. $dlzmoneyb[] = $dlzm;
  893. $smtmoneyb[] = $smtm;
  894. $ttmoneyb[] = $ttm;
  895. $amzmoneyb[] = $amzm;
  896. //数量及金额结束
  897. }
  898. }
  899. foreach ($shopdata as $k => $v) {
  900. $sn = $this->shop->read($k);
  901. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  902. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  903. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  904. $shopdata[$k]['name'] = $sn['shopname'];
  905. $shopdata[$k]['b'] = $sn['type'];
  906. $shopdata[$k]['id'] = $sn['id'];
  907. }
  908. $shopdata = array_values($shopdata);
  909. //$sycp=array();
  910. /**
  911. //根据所选时间产品排行开始
  912. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  913. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  914. **/
  915. /**
  916. //昨日产品排行开始
  917. $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');
  918. $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');
  919. $rows = array_merge($dlzlist,$smtlist);
  920. foreach ($rows as $v)
  921. {
  922. $number = explode('|',trim($v['whlabel'],'|'));
  923. $or = explode(';',trim($v['fpdata'],';'));
  924. $i=0;
  925. foreach ($or as $va)
  926. {
  927. $ord = explode('|',$va);
  928. $orod = explode(',',$ord[0]);
  929. $numberod = explode('-',$number[$i]);
  930. if(!isset($orod[1]))
  931. {
  932. continue;
  933. }
  934. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  935. {
  936. //$sycp[$orod[1]][0] += 1;//统计多少单
  937. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  938. $sycp[$orod[1]][1] += 0;//价格
  939. }
  940. else
  941. {
  942. if(isset($numberod[1]))
  943. {
  944. $typeclass = $this->typeclass->read($orod['0']);
  945. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  946. }
  947. }
  948. $i++;
  949. }
  950. }
  951. arsort($sycp);
  952. $sycp = array_values($sycp);
  953. $sycp = array_slice($sycp,0,10);
  954. //产品排行结束
  955. **/
  956. //当时实时数据结束
  957. 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));
  958. exit; //,'sycp'=>$sycp昨日产品数据
  959. }
  960. //统计的时间段
  961. protected function _statistics_sjd($fgshop,$zdt,$where,$k,$usat){
  962. $timedata = explode('|', $zdt);
  963. $ktime = strtotime($timedata[0]);
  964. $jtime = strtotime($timedata[1]);
  965. $ktime = $ktime - ($jtime - $ktime);
  966. $k = $ktime;
  967. $j = $jtime;
  968. $n = ($j - $k) / (24 * 3600);
  969. $usat = $jtime;
  970. $tm = $jtime;
  971. $zdt = $jtime - $ktime;
  972. $time = array();
  973. $timeold = array();
  974. $stime = array();
  975. $dlznum = array();
  976. $smtnum = array();
  977. $ymoney = array();
  978. $money = array();
  979. $dlzmoneyb = array();
  980. $smtmoneyb = array();
  981. $ttmoneyb = array();
  982. $zkh = array();
  983. $dlzsl = 0;
  984. $dlzje = 0;
  985. $dlzssje = 0;
  986. $smtsl = 0;
  987. $smtje = 0;
  988. $smtssje = 0;
  989. $ttsl = 0;
  990. $ttje = 0;
  991. $ttssje = 0;
  992. $amzsl = 0;
  993. $amzje = 0;
  994. $amzssje = 0;
  995. $shopdata = array();
  996. $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');
  997. foreach ($ys as $v) {
  998. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  999. }
  1000. // [修复 2] 循环边界:i=1 → i=0;< n → <= n
  1001. for ($i = 0; $i <= $n; $i++) {
  1002. //近7天时间
  1003. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1004. // [修复 2] 主分支条件:i > n/2 → i >= n/2
  1005. if ($n > 13 && $i >= $n / 2 || $n < 14) {
  1006. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1007. $time[] = date('m-d', $t);
  1008. $ct = strtotime(date('Ymd', $t));
  1009. // [修复 3] $ctj 减 1 秒
  1010. $ctj = strtotime(date('Ymd', $t + 24 * 3600)) ;
  1011. $dlz = $this->fullorder->find_all(" dtime >= " . $ct . " and dtime < " . $ctj . $where . " and wzsgd = 0 and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'budget,shouldmoney,shop,number,refundy,email,refundj');
  1012. $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,refundj');
  1013. $tt = $this->fullordertt->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,email,refundj');
  1014. $amz = $this->fullorderamz->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,email,refundj');
  1015. $ab[] = $dlz;
  1016. //数量及金额开始
  1017. $dlznum[] = count($dlz);
  1018. $smtnum[] = count($smt);
  1019. $ttnum[] = count($smt);
  1020. $amznum[] = count($amz);
  1021. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1022. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1023. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1024. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  1025. /**
  1026. //提出退款关闭等信息的实收金额
  1027. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1028. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1029. //提出退款关闭等信息的实收金额
  1030. **/
  1031. //实收金额
  1032. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  1033. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  1034. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  1035. $amzmss = sprintf("%01.2f", array_sum(array_column($amz, 'budget')));
  1036. //实收金额
  1037. //补/退原额
  1038. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  1039. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  1040. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  1041. $amzbty = sprintf("%01.2f", array_sum(array_column($amz, 'refundy')));
  1042. //补/退原额
  1043. //补/退净额
  1044. $dlzbtj = sprintf("%01.2f", array_sum(array_column($dlz, 'refundj')));
  1045. $smtbtj = sprintf("%01.2f", array_sum(array_column($smt, 'refundj')));
  1046. $ttbtj = sprintf("%01.2f", array_sum(array_column($tt, 'refundj')));
  1047. $amzbtj = sprintf("%01.2f", array_sum(array_column($amz, 'refundj')));
  1048. //补/退净额
  1049. $dlzmoney[] = $dlzm;
  1050. $smtmoney[] = $smtm;
  1051. $ttmoney[] = $ttm;
  1052. $amzmoney[] = $amzm;
  1053. // $dlzsl += count($dlz);
  1054. // $dlzje += $dlzm + $dlzbty;
  1055. // $smtsl += count($smt);
  1056. // $smtje += $smtm + $smtbty;
  1057. // $ttsl += count($tt);
  1058. // $ttje += $ttm + $ttbty;
  1059. // $amzsl += count($amz);
  1060. // $amzje += $amzm + $amzbty;
  1061. $dlzsl += count($dlz);
  1062. $dlzje += $dlzm;
  1063. $smtsl += count($smt);
  1064. $smtje += $smtm;
  1065. $ttsl += count($tt);
  1066. $ttje += $ttm;
  1067. $amzsl += count($amz);
  1068. $amzje += $amzm;
  1069. /**
  1070. //减去的实收金额
  1071. $dlzssje += $dlzm+$dlzmss;
  1072. $smtssje += $smtm+$smtmss;
  1073. **/
  1074. //实收和补/退
  1075. // $dlzssje += $dlzmss + $dlzbtj;
  1076. // $smtssje += $smtmss + $smtbtj;
  1077. // $ttssje += $ttmss + $ttbtj;
  1078. // $amzssje += $amzmss + $amzbtj;
  1079. $dlzssje += $dlzmss;
  1080. $smtssje += $smtmss;
  1081. $ttssje += $ttmss;
  1082. $amzssje += $amzmss;
  1083. //数量及金额结束
  1084. $sd = array_merge($dlz, $smt, $tt, $amz);
  1085. foreach ($sd as $v) {
  1086. if (isset($shopdata[$v['shop']])) {
  1087. $shopdata[$v['shop']]['num'] += 1;
  1088. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  1089. $shopdata[$v['shop']]['tmoney'] += $v['budget'] ;
  1090. }
  1091. }
  1092. }
  1093. // [修复 4] 对比周期条件:i <= n/2 → i < n/2
  1094. else if ($n > 13 && $i < $n / 2) {
  1095. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1096. $timeold[] = date('m-d', $t);
  1097. $ct = strtotime(date('Ymd', $t));
  1098. // [修复 3] $ctj 减 1 秒
  1099. $ctj = strtotime(date('Ymd', $t + 24 * 3600)) ;
  1100. $dlz = $this->fullorder->find_all(" (" . rtrim($fgshop, 'or') . ") and wzsgd = 0 and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1101. $smt = $this->fullordersmt->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1102. $tt = $this->fullordertt->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1103. $amz = $this->fullorderamz->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1104. //数量及金额开始
  1105. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1106. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1107. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1108. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  1109. $dlzmoneyb[] = $dlzm;
  1110. $smtmoneyb[] = $smtm;
  1111. $ttmoneyb[] = $ttm;
  1112. $amzmoneyb[] = $amzm;
  1113. //数量及金额结束
  1114. }
  1115. }
  1116. foreach ($shopdata as $k => $v) {
  1117. $sn = $this->shop->read($k);
  1118. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  1119. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  1120. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  1121. $shopdata[$k]['name'] = $sn['shopname'];
  1122. $shopdata[$k]['b'] = $sn['type'];
  1123. $shopdata[$k]['id'] = $sn['id'];
  1124. }
  1125. $shopdata = array_values($shopdata);
  1126. //$sycp=array();
  1127. /**
  1128. //根据所选时间产品排行开始
  1129. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1130. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1131. **/
  1132. /**
  1133. //昨日产品排行开始
  1134. $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');
  1135. $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');
  1136. $rows = array_merge($dlzlist,$smtlist);
  1137. foreach ($rows as $v)
  1138. {
  1139. $number = explode('|',trim($v['whlabel'],'|'));
  1140. $or = explode(';',trim($v['fpdata'],';'));
  1141. $i=0;
  1142. foreach ($or as $va)
  1143. {
  1144. $ord = explode('|',$va);
  1145. $orod = explode(',',$ord[0]);
  1146. $numberod = explode('-',$number[$i]);
  1147. if(!isset($orod[1]))
  1148. {
  1149. continue;
  1150. }
  1151. if(isset($sycp[$orod[1]) && isset($numberod[1]))
  1152. {
  1153. //$sycp[$orod[1]][0] += 1;//统计多少单
  1154. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  1155. $sycp[$orod[1]][1] += 0;//价格
  1156. }
  1157. else
  1158. {
  1159. if(isset($numberod[1]))
  1160. {
  1161. $typeclass = $this->typeclass->read($orod['0']);
  1162. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  1163. }
  1164. }
  1165. $i++;
  1166. }
  1167. }
  1168. arsort($sycp);
  1169. $sycp = array_values($sycp);
  1170. $sycp = array_slice($sycp,0,10);
  1171. //产品排行结束
  1172. **/
  1173. //当时实时数据结束
  1174. 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));
  1175. exit; //,'sycp'=>$sycp昨日产品数据
  1176. }
  1177. /**
  1178. public function super_unique($array,$key)//多维删除重复
  1179. {
  1180. $temp_array = array();
  1181. foreach ($array as &$v) {
  1182. if (!isset($temp_array[$v[$key]]))
  1183. {
  1184. $temp_array[$v[$key]] =& $v;
  1185. }
  1186. }
  1187. $array = array_values($temp_array);
  1188. return $array;
  1189. }
  1190. **/
  1191. public function _usatime()
  1192. {
  1193. date_default_timezone_set("Etc/GMT+8");
  1194. return time();
  1195. }
  1196. //数据
  1197. public function _rows()
  1198. {
  1199. $post = $this->input->post(NULL, TRUE);
  1200. if (isset($post['shop'])) {
  1201. $shop = $this->input->post('shop', true);
  1202. $data = $this->shop->find_all('1=1',"*","px asc");
  1203. $list = array();
  1204. foreach ($data as $key => $value) {
  1205. $t = $this->typeclass->read($value['type']);
  1206. $list[] = array('id' => $value['id'], 'title' => $value['shopname'] . ' - ' . $t['title']);
  1207. }
  1208. $num = array();
  1209. if ($shop != "null") {
  1210. $num = $this->user->read($shop); //找出内容
  1211. if ($num['shop']) {
  1212. $num = explode('|', trim($num['shop'], '|')); //数组化内容
  1213. } else {
  1214. $num = array();
  1215. }
  1216. }
  1217. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1218. }
  1219. if (isset($post['excelshop'])) {
  1220. $excelshop = $this->input->post('excelshop', true);
  1221. $data = $this->shop->find_all('1=1',"*","px asc");
  1222. $list = array();
  1223. foreach ($data as $key => $value) {
  1224. $t = $this->typeclass->read($value['type']);
  1225. $list[] = array('id' => $value['id'], 'title' => $value['shopname'] . ' - ' . $t['title']);
  1226. }
  1227. $num = array();
  1228. if ($excelshop != "null") {
  1229. $num = $this->user->read($excelshop); //找出内容
  1230. if ($num['excelshop']) {
  1231. $num = explode('|', trim($num['excelshop'], '|')); //数组化内容
  1232. } else {
  1233. $num = array();
  1234. }
  1235. }
  1236. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1237. }
  1238. if (isset($post['purchase'])) {
  1239. $purchase = $this->input->post('purchase', true);
  1240. $data = $this->purchase->find_all('1=1');
  1241. $list = array();
  1242. foreach ($data as $key => $value) {
  1243. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1244. }
  1245. $num = array();
  1246. if ($purchase != "null") {
  1247. $num = $this->user->read($purchase); //找出内容
  1248. if ($num['purchase']) {
  1249. $num = explode('|', trim($num['purchase'], '|')); //数组化内容
  1250. } else {
  1251. $num = array();
  1252. }
  1253. }
  1254. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1255. }
  1256. if (isset($post['staff'])) {
  1257. $staff = $this->input->post('staff', true);
  1258. $data = $this->staff->find_all('1=1');
  1259. $list = array();
  1260. foreach ($data as $key => $value) {
  1261. $list[] = array('id' => $value['id'], 'title' => $value['name']);
  1262. }
  1263. $num = array();
  1264. if ($staff != "null") {
  1265. $num = $this->user->read($staff); //找出内容
  1266. if ($num['staff']) {
  1267. $num = explode('|', trim($num['staff'], '|')); //数组化内容
  1268. } else {
  1269. $num = array();
  1270. }
  1271. }
  1272. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1273. }
  1274. if (isset($post['warehouse'])) {
  1275. $warehouse = $this->input->post('warehouse', true);
  1276. $data = $this->warehouse->find_all('1=1');
  1277. $list = array();
  1278. foreach ($data as $key => $value) {
  1279. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1280. }
  1281. $num = array();
  1282. if ($warehouse != "null") {
  1283. $num = $this->user->read($warehouse); //找出内容
  1284. if ($num['warehouse']) {
  1285. $num = explode('|', trim($num['warehouse'], '|')); //数组化内容
  1286. } else {
  1287. $num = array();
  1288. }
  1289. }
  1290. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1291. }
  1292. if (isset($post['transfer'])) {
  1293. $transfer = $this->input->post('transfer', true);
  1294. $data = $this->transfer->find_all('1=1');
  1295. $list = array();
  1296. foreach ($data as $key => $value) {
  1297. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1298. }
  1299. $num = array();
  1300. if ($transfer != "null") {
  1301. $num = $this->user->read($transfer); //找出内容
  1302. if ($num['transfer']) {
  1303. $num = explode('|', trim($num['transfer'], '|')); //数组化内容
  1304. } else {
  1305. $num = array();
  1306. }
  1307. }
  1308. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1309. }
  1310. }
  1311. public function _shopfx()
  1312. {
  1313. $post = $this->input->post(NULL, TRUE);
  1314. if (isset($post['time'])) {
  1315. $time = $this->input->post('time', true);
  1316. $t = strtotime(date("Ymd", time() + 24 * 3600)); //明天0点
  1317. $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");
  1318. $sid = '';
  1319. foreach ($shop as $value) {
  1320. $sid .= " shop = " . $value['id'] . " or";
  1321. }
  1322. $sid = " and (" . rtrim($sid, 'or') . ")";
  1323. $znum = $this->fullorder->find_count("dtime > '" . ($t - $time * 24 * 3600) . "' and dtime < '" . $t . "'" . $sid);
  1324. $data = array();
  1325. $list = array();
  1326. $color = array('0' => '#30546c', '1' => '#61a0a8', '2' => '#c23531', '3' => '#d48265', '4' => '#546570', '5' => '#749f83', '6' => '#bda29a', '7' => '#6e7074', '8' => '#546570');
  1327. $j = 0;
  1328. $zt = array(7 => 1, 30 => 2);
  1329. foreach ($shop as $v) {
  1330. $d = $this->fullorder->find_count("shop = '" . $v['id'] . "' and dtime > '" . ($t - $time * 24 * 3600) . "' and dtime < '" . $t . "' and (state = '207' or state = '216')");
  1331. $wd = $this->allocation->read($zt[$time]);
  1332. $n = json_decode($wd['content'], true);
  1333. $bfb = ($d == 0) ? 0 : round(($d / $znum) * 100, 2);
  1334. $data[] = array('value' => $bfb, 'name' => $v['shopname'] . ' ' . $bfb . "%", 'itemStyle' => array('color' => $color[$j]));
  1335. $n[$v['id']][] = $this->fullorder->find_count("shop = '" . $v['id'] . "' and gtime = '" . date("Ymd", time()) . "' and (state = '207' or state = '216')");
  1336. $t_list = array();
  1337. for ($i = 0; $i < $time; $i++) {
  1338. $t_list[] = date("m-d", time() - ($i * 24 * 3600));
  1339. }
  1340. $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) . '%');
  1341. $j++;
  1342. }
  1343. $list = (array_reverse($list));
  1344. echo json_encode(array('data' => ($data), 'list' => $list, 't' => (array_reverse($t_list)), 'success' => true));
  1345. exit;
  1346. /**
  1347. $time = $this->input->post('time',true);
  1348. $t = strtotime(date("Ymd",time()+24*3600));//明天0点
  1349. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1350. $sid = '';
  1351. foreach ($shop as $value)
  1352. {
  1353. $sid .= " shop = ".$value['id']." or";
  1354. }
  1355. $sid = " and (".rtrim($sid,'or').")";
  1356. $znum = $this->fullorder->find_count("dtime > '".($t-$time*24*3600)."' and dtime < '".$t."'".$sid);
  1357. $data = array();$list = array();
  1358. $color = array('0'=>'#30546c','1'=>'#61a0a8','2'=>'#c23531','3'=>'#d48265','4'=>'#546570','5'=>'#749f83','6'=>'#bda29a','7'=>'#6e7074','8'=>'#546570');
  1359. $j = 0;
  1360. foreach ($shop as $v)
  1361. {
  1362. $d = $this->fullorder->find_count("shop = '".$v['id']."' and dtime > '".($t-$time*24*3600)."' and dtime < '".$t."' and (state = '207' or state = '216')");
  1363. $bfb = ($d==0)?0:round(($d / $znum) * 100, 2);
  1364. $data[] = array('value'=>$bfb,'name'=>$v['shopname'].' '.$bfb."%",'itemStyle'=>array('color'=>$color[$j]));
  1365. $n = array();$t_list = array();
  1366. for($i=0;$i<$time;$i++)
  1367. {
  1368. if($i == 0)
  1369. {
  1370. $s = date("Ymd",time());
  1371. }
  1372. else
  1373. {
  1374. $s = date("Ymd",time()-($i*24*3600));
  1375. }
  1376. $t_list[] = date("m-d",time()-($i*24*3600));
  1377. $n[] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".$s."' and (state = '207' or state = '216')");
  1378. }
  1379. $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).'%');
  1380. $j++;
  1381. }
  1382. $list = (array_reverse($list));
  1383. echo json_encode(array('data'=>($data),'list'=>$list,'t'=>(array_reverse($t_list)),'success'=>true));exit;
  1384. **/
  1385. }
  1386. $this->_Template('phone/p_user_shopfx', $this->data);
  1387. }
  1388. public function _shopfxlist()
  1389. {
  1390. $t = strtotime(date("Ymd", time())); //今天0点
  1391. $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");
  1392. $sid = '';
  1393. foreach ($shop as $value) {
  1394. $sid .= " shop = " . $value['id'] . " or";
  1395. }
  1396. $sid = " and (" . rtrim($sid, 'or') . ")";
  1397. $zt = array(7, 30);
  1398. $this->db->trans_begin();
  1399. foreach ($zt as $key => $time) {
  1400. $data = array();
  1401. $list = array();
  1402. foreach ($shop as $v) {
  1403. $n = array();
  1404. $t_list = array();
  1405. for ($i = 1; $i < $time; $i++) {
  1406. if ($i == 0) {
  1407. $s = date("Ymd", time());
  1408. } else {
  1409. $s = date("Ymd", time() - ($i * 24 * 3600));
  1410. }
  1411. $t_list[] = date("m-d", time() - ($i * 24 * 3600));
  1412. $n[] = $this->fullorder->find_count("shop = '" . $v['id'] . "' and gtime = '" . $s . "' and (state = '207' or state = '216')");
  1413. }
  1414. $list[$v['id']] = array_reverse($n);
  1415. }
  1416. $this->allocation->save(array('content' => json_encode($list)), $key + 1);
  1417. }
  1418. if ($this->db->trans_status() === FALSE) {
  1419. $this->db->trans_rollback();
  1420. echo 'orver';
  1421. } else {
  1422. $this->db->trans_commit();
  1423. echo 'ok';
  1424. }
  1425. }
  1426. public function _apple()
  1427. {
  1428. $this->_Template('phone/p_user_apple', $this->data);
  1429. }
  1430. //退出
  1431. public function _tc()
  1432. {
  1433. $this->session->sess_destroy();
  1434. header("Location:/");
  1435. }
  1436. public function _tjadd()
  1437. {
  1438. $pdtime = date('Y-m-d-H', time());
  1439. //if(is_file("./data/tj/".$pdtime.".txt"))
  1440. if (is_file("./data/tj/" . $pdtime . ".txt")) {
  1441. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  1442. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  1443. fclose($myfile);
  1444. $bc = json_decode($bc, true);
  1445. $zzt = array($bc['zzt'][0], $bc['zzt'][1]);
  1446. } else {
  1447. /** 暂时不需要了
  1448. //柱状图数据
  1449. $i = 0;
  1450. $data = array();$sndata1 = array();$sndata2 = array();$sndata3 = array();
  1451. $sj = array('01','02','03','04','05','06','07','08','09','10','11','12');
  1452. foreach ($sj as $k=>$v)
  1453. {
  1454. $i++;
  1455. $dlz1 = $this->fullorder->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1456. $smt1 = $this->fullordersmt->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1457. $m1 = sprintf("%01.2f",array_sum(array_column($dlz1,'shouldmoney'))+array_sum(array_column($smt1,'shouldmoney')));
  1458. $dlz2 = $this->fullorder->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1459. $smt2 = $this->fullordersmt->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1460. $m2 = sprintf("%01.2f",array_sum(array_column($dlz2,'shouldmoney'))+array_sum(array_column($smt2,'shouldmoney')));
  1461. $dlz3 = $this->fullorder->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1462. $smt3 = $this->fullordersmt->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1463. $m3 = sprintf("%01.2f",array_sum(array_column($dlz3,'shouldmoney'))+array_sum(array_column($smt3,'shouldmoney')));
  1464. $sndata1[$i] = $m3;
  1465. $sndata2[12+$i] = $m2;
  1466. $sndata3[24+$i] = $m1;
  1467. $data[] = array($v,$m1,$m2,$m3);
  1468. }
  1469. $sndata = array_merge($sndata1,$sndata2,$sndata3);
  1470. $zzt = array($data,$sndata);
  1471. //柱状图结束
  1472. **/
  1473. }
  1474. //详情内容
  1475. $dt = 0;
  1476. //系统报错 提示没有api下标的键
  1477. if(!isset($_SESSION['api'])){
  1478. echo "ERROR";
  1479. die;
  1480. }
  1481. $user = $this->user->get_api($_SESSION['api']);
  1482. $usp = $user;
  1483. $fgshop = "";
  1484. $sid = "";
  1485. $user = explode('|', trim($user['shop'], '|'));
  1486. foreach ($user as $value) {
  1487. if(!empty($value)){
  1488. $fgshop .= " shop = " . $value . " or";
  1489. $sid .= " id = " . $value . " or";
  1490. }
  1491. }
  1492. //为了让下面程序可以执行 给的如果用户没店铺权限 就给一个不存在的店铺
  1493. if(empty($fgshop)){
  1494. $fgshop = " shop = 0 or";
  1495. $sid = " id = 0 or";
  1496. }
  1497. $tm = strtotime(date("Ymd"), time());
  1498. $usat = $tm;
  1499. //$molist = array('0','1','2d');
  1500. $molist = array('0', '1');
  1501. $zqtime = array(259200, 345600, 691200, 2678400, 7862400, 31622400);
  1502. //time开始
  1503. $zqtdata = array();
  1504. foreach ($molist as $vval) {
  1505. $where = "";
  1506. $source = $vval;
  1507. if ($source == '2d') {
  1508. $where = " and source >= '2'";
  1509. } else if ($source != '0') {
  1510. $where = " and source = '$source'";
  1511. }
  1512. foreach ($zqtime as $value) {
  1513. $zdt = $value;
  1514. $k = $zdt;
  1515. $tab = 1;
  1516. //$start = '2018-10-15';
  1517. //$end = '2018-11-26';
  1518. //$tim = strtotime($start);
  1519. //$day = $time/(3600*24);
  1520. if ($tab == '1') {
  1521. if ($zdt >= 691200) {
  1522. $k = $usat - $k - $k;
  1523. $j = $usat;
  1524. $n = ($j - $k) / (24 * 3600);
  1525. } else {
  1526. $n = 2;
  1527. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  1528. }
  1529. } else {
  1530. $timedata = explode('|', $zdt);
  1531. $ktime = strtotime($timedata[0]);
  1532. $jtime = strtotime($timedata[1]);
  1533. $ktime = $ktime - ($jtime - $ktime);
  1534. $k = $ktime;
  1535. $j = $jtime;
  1536. $n = ($j - $k) / (24 * 3600);
  1537. $usat = $jtime;
  1538. $tm = $jtime;
  1539. $zdt = $jtime - $ktime;
  1540. }
  1541. $time = array();
  1542. $timeold = array();
  1543. $stime = array();
  1544. $dlznum = array();
  1545. $smtnum = array();;
  1546. $ttnum = array();
  1547. $ymoney = array();
  1548. $money = array();
  1549. $dlzmoney = array();
  1550. $smtmoney = array();
  1551. $ttmoney = array();
  1552. $dlzmoneyb = array();
  1553. $smtmoneyb = array();
  1554. $ttmoneyb = array();
  1555. $dlzsl = 0;
  1556. $dlzje = 0;
  1557. $dlzssje = 0;
  1558. $smtsl = 0;
  1559. $smtje = 0;
  1560. $smtssje = 0;
  1561. $ttsl = 0;
  1562. $ttje = 0;
  1563. $ttssje = 0;
  1564. $shopdata = array();
  1565. $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'");
  1566. foreach ($ys as $v) {
  1567. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  1568. }
  1569. for ($i = 1; $i < $n; $i++) {
  1570. //近7天时间
  1571. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1572. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1573. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1574. $time[] = date('m-d', $t);
  1575. $ct = strtotime(date('Ymd', $t));
  1576. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1577. $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');
  1578. $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');
  1579. $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');
  1580. $ab[] = $dlz;
  1581. //数量及金额开始
  1582. $dlznum[] = count($dlz);
  1583. $smtnum[] = count($smt);
  1584. $ttnum[] = count($smt);
  1585. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1586. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1587. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1588. /**
  1589. //提出退款关闭等信息的实收金额
  1590. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1591. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1592. //提出退款关闭等信息的实收金额
  1593. **/
  1594. //实收金额
  1595. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  1596. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  1597. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  1598. //实收金额
  1599. //补/退原额
  1600. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  1601. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  1602. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  1603. //补/退原额
  1604. $dlzmoney[] = $dlzm;
  1605. $smtmoney[] = $smtm;
  1606. $ttmoney[] = $ttm;
  1607. $dlzsl += count($dlz);
  1608. $dlzje += $dlzm;
  1609. $smtsl += count($smt);
  1610. $smtje += $smtm;
  1611. $ttsl += count($tt);
  1612. $ttje += $ttm;
  1613. /**
  1614. //减去的实收金额
  1615. $dlzssje += $dlzm+$dlzmss;
  1616. $smtssje += $smtm+$smtmss;
  1617. **/
  1618. //实收和补/退
  1619. $dlzssje += $dlzmss + $dlzbty;
  1620. $smtssje += $smtmss + $smtbty;
  1621. $ttssje += $ttmss + $ttbty;
  1622. //数量及金额结束
  1623. $sd = array_merge($dlz, $smt, $tt);
  1624. foreach ($sd as $v) {
  1625. if (isset($shopdata[$v['shop']])) {
  1626. $shopdata[$v['shop']]['num'] += 1;
  1627. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  1628. $shopdata[$v['shop']]['tmoney'] += $v['budget'] + $v['refundy'];
  1629. }
  1630. }
  1631. } else if ($n > 13 && $i <= $n / 2) {
  1632. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1633. $timeold[] = date('m-d', $t);
  1634. $ct = strtotime(date('Ymd', $t));
  1635. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1636. $dlz = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1637. $smt = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1638. $tt = $this->fullordertt->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1639. //数量及金额开始
  1640. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1641. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1642. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1643. $dlzmoneyb[] = $dlzm;
  1644. $smtmoneyb[] = $smtm;
  1645. $ttmoneyb[] = $ttm;
  1646. //数量及金额结束
  1647. }
  1648. }
  1649. foreach ($shopdata as $k => $v) {
  1650. $sn = $this->shop->read($k);
  1651. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  1652. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  1653. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  1654. $shopdata[$k]['name'] = $sn['shopname'];
  1655. $shopdata[$k]['b'] = $sn['type'];
  1656. $shopdata[$k]['id'] = $sn['id'];
  1657. }
  1658. $shopdata = array_values($shopdata);
  1659. //$sycp=array();
  1660. /**
  1661. //根据所选时间产品排行开始
  1662. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1663. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1664. **/
  1665. /**
  1666. //昨日产品排行开始
  1667. $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');
  1668. $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');
  1669. $rows = array_merge($dlzlist,$smtlist);
  1670. foreach ($rows as $v)
  1671. {
  1672. $number = explode('|',trim($v['whlabel'],'|'));
  1673. $or = explode(';',trim($v['fpdata'],';'));
  1674. $i=0;
  1675. foreach ($or as $va)
  1676. {
  1677. $ord = explode('|',$va);
  1678. $orod = explode(',',$ord[0]);
  1679. $numberod = explode('-',$number[$i]);
  1680. if(!isset($orod[1]))
  1681. {
  1682. continue;
  1683. }
  1684. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  1685. {
  1686. //$sycp[$orod[1]][0] += 1;//统计多少单
  1687. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  1688. $sycp[$orod[1]][1] += 0;//价格
  1689. }
  1690. else
  1691. {
  1692. if(isset($numberod[1]))
  1693. {
  1694. $typeclass = $this->typeclass->read($orod['0']);
  1695. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  1696. }
  1697. }
  1698. $i++;
  1699. }
  1700. }
  1701. arsort($sycp);
  1702. $sycp = array_values($sycp);
  1703. $sycp = array_slice($sycp,0,10);
  1704. //产品排行结束
  1705. **/
  1706. //当时实时数据结束
  1707. $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昨日产品数据
  1708. }
  1709. }
  1710. //time结束
  1711. //zhcx开始
  1712. $zhcxdata = array();
  1713. foreach ($molist as $vval) {
  1714. $where = "";
  1715. $source = $vval;
  1716. if ($source == '2d') {
  1717. $where = " and source >= '2'";
  1718. } else if ($source != '0') {
  1719. $where = " and source = '$source'";
  1720. }
  1721. foreach ($zqtime as $value) {
  1722. $zdt = $value;
  1723. $k = $zdt;
  1724. $tab = 1;
  1725. //$customer = $this->customer->find_all("shop !=''",'num,zhcx');
  1726. //$customerkey = array_column($customer,'zhcx');
  1727. //$customer= array_combine($customerkey,$customer);
  1728. //$customersmt = $this->customersmt->find_all("shop !=''",'num,zhcx');
  1729. //$customersmtkey = array_column($customersmt,'zhcx');
  1730. //$customersmt= array_combine($customersmtkey,$customersmt);
  1731. //$customertt = $this->customertt->find_all("shop !=''",'num,zhcx');
  1732. //$customerttkey = array_column($customertt,'zhcx');
  1733. //$customertt= array_combine($customerttkey,$customertt);
  1734. if ($tab == '1') {
  1735. if ($zdt >= 691200) {
  1736. $k = $usat - $k - $k;
  1737. $j = $usat;
  1738. $n = ($j - $k) / (24 * 3600);
  1739. } else {
  1740. $n = 2;
  1741. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  1742. }
  1743. } else {
  1744. $timedata = explode('|', $zdt);
  1745. $ktime = strtotime($timedata[0]);
  1746. $jtime = strtotime($timedata[1]);
  1747. $ktime = $ktime - ($jtime - $ktime);
  1748. $k = $ktime;
  1749. $j = $jtime;
  1750. $n = ($j - $k) / (24 * 3600);
  1751. $usat = $jtime;
  1752. }
  1753. $time = array();
  1754. $timeold = array();
  1755. $stime = array();
  1756. $dlznum = array();
  1757. $smtnum = array();
  1758. $ttnum = array();
  1759. $ymoney = array();
  1760. $money = array();
  1761. $dlzmoneyb = array();
  1762. $smtmoneyb = array();
  1763. $ttmoneyb = array();
  1764. $zkh = array();
  1765. $dlzsl = 0;
  1766. $dlzje = 0;
  1767. $dlzssje = 0;
  1768. $smtsl = 0;
  1769. $smtje = 0;
  1770. $smtssje = 0;
  1771. $ttsl = 0;
  1772. $ttje = 0;
  1773. $ttssje = 0;
  1774. $shopdata = array();
  1775. $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'");
  1776. foreach ($ys as $v) {
  1777. $shopdata[$v['id']] = array('id' => $v['id'], 'b' => $v['type'], 'fdl' => 0, 'chl' => 0, 'num' => 0, 'fgl' => 0);
  1778. $zkh[$v['id']] = array();
  1779. }
  1780. for ($i = 1; $i < $n; $i++) {
  1781. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1782. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1783. $time[] = date('m-d', $t);
  1784. $ct = strtotime(date('Ymd', $t));
  1785. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1786. $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');
  1787. $dlzemail = $this->fullorder->find_all("dtime <= " . $ctj . $where . " and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'shop,email');
  1788. $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');
  1789. $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');
  1790. //数量及金额结束
  1791. $sd = array_merge($dlz, $smt, $tt);
  1792. $fgldata = array();
  1793. foreach ($sd as $v) {
  1794. /**
  1795. $array = array(
  1796. 0 => array('email' => 123, 'id' => 1),
  1797. 1 => array('email' => 321, 'id' => 2),
  1798. 2 => array('email' => 123, 'id' => 3),
  1799. 3 => array('email' => 123, 'id' => 3)
  1800. );
  1801. // 使用 array_filter 筛选满足多个条件的元素
  1802. $result = array_filter($array, function($item) {
  1803. return $item['email'] === 123 && $item['id'] === 3;
  1804. });
  1805. // 计算满足条件的数量
  1806. $count = count($result);
  1807. echo "满足条件 (email = 123 且 id = 3) 的数量是:$count";
  1808. **/
  1809. /** 独立站查customer方法 弃用
  1810. if(isset($v['email']))
  1811. {
  1812. if(!isset($fgldata[$v['shop'].'-'.$v['email']]))
  1813. {
  1814. $fgldata[$v['shop'].'-'.$v['email']] = 0;
  1815. }
  1816. else
  1817. {
  1818. $fgldata[$v['shop'].'-'.$v['email']] += 1;
  1819. }
  1820. $zkh[$v['shop']][$v['email']] = array();
  1821. }
  1822. **/
  1823. /** 速卖通
  1824. else
  1825. {
  1826. if(!isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1827. {
  1828. $fgldata[$v['shop'].'-'.$v['userid']] = 0;
  1829. }
  1830. else
  1831. {
  1832. $fgldata[$v['shop'].'-'.$v['userid']] += 1;
  1833. }
  1834. $zkh[$v['shop']][$v['userid']] = array();
  1835. }
  1836. **/
  1837. }
  1838. foreach ($sd as $v) {
  1839. //避免由于作用域引起的问题
  1840. $tmp_v = $v;
  1841. $fdl_result = array_filter($dlz, function ($item) use ($tmp_v) {
  1842. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1843. return false;
  1844. } else {
  1845. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1846. }
  1847. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1848. });
  1849. $fdl = count($fdl_result) > 1 ? 1 : 0; //返单
  1850. $chl_result = array_filter($dlz, function ($item) use ($tmp_v) {
  1851. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1852. return false;
  1853. } else {
  1854. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1855. }
  1856. //return $item['email'] === $tmp_v['email'] && $item['shop'] !== $tmp_v['email'];
  1857. });
  1858. $chl = count($chl_result) > 1 ? 1 : 0; //重合
  1859. $fgl_result = array_filter($dlzemail, function ($item) use ($tmp_v) {
  1860. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1861. return false;
  1862. } else {
  1863. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1864. }
  1865. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1866. });
  1867. $fgl = count($fgl_result) > 1 ? 1 : 0; //复购
  1868. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl'] + $fdl;
  1869. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl'] + $chl;
  1870. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl'] + $fgl;
  1871. $shopdata[$v['shop']]['num'] += 1;
  1872. /**
  1873. $chl = 0;
  1874. if(isset($shopdata[$v['shop']]))
  1875. {
  1876. if(isset($v['email']))
  1877. {
  1878. if(isset($customer[$v['shop'].'-'.$v['email']]['num']))
  1879. {
  1880. $fdl = $customer[$v['shop'].'-'.$v['email']]['num']>1?1:0;
  1881. }
  1882. else
  1883. {
  1884. $fdl = 0;
  1885. }
  1886. foreach ($ys as $vv)
  1887. {
  1888. if($vv['id'] != $v['shop'] && isset($customer[$vv['id'].'-'.$v['email']]))
  1889. {
  1890. $chl = 1;
  1891. }
  1892. }
  1893. if(isset($fgldata[$v['shop'].'-'.$v['email']]))
  1894. {
  1895. $fgl = $fgldata[$v['shop'].'-'.$v['email']]>0?1:0;
  1896. }
  1897. else
  1898. {
  1899. $fgl = 0;
  1900. }
  1901. }
  1902. else
  1903. {
  1904. if(isset($customersmt[$v['shop'].'-'.$v['userid']]['num']))
  1905. {
  1906. $fdl = $customersmt[$v['shop'].'-'.$v['userid']]['num']>1?1:0;
  1907. }
  1908. else
  1909. {
  1910. $fdl = 0;
  1911. }
  1912. foreach ($ys as $vv)
  1913. {
  1914. if($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'].'-'.$v['userid']]))
  1915. {
  1916. $chl = 1;
  1917. }
  1918. }
  1919. if(isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1920. {
  1921. $fgl = $fgldata[$v['shop'].'-'.$v['userid']]>0?1:0;
  1922. }
  1923. else
  1924. {
  1925. $fgl = 0;
  1926. }
  1927. }
  1928. }
  1929. **/
  1930. }
  1931. }
  1932. }
  1933. foreach ($shopdata as $k => $v) {
  1934. $shopdata[$k]['fdl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['fdl'] / $v['num'] * 100)) . '%';
  1935. $shopdata[$k]['chl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['chl'] / $v['num'] * 100)) . '%';
  1936. $shopdata[$k]['fgl'] = count($zkh[$v['id']]) == '0' ? 0 : sprintf("%01.2f", ($v['fgl'] / count($zkh[$v['id']]) * 100)) . '%';
  1937. }
  1938. $shopdata = array_values($shopdata);
  1939. $zhcxdata[$vval][$value] = array('shopdata' => $shopdata, 'success' => true);
  1940. }
  1941. }
  1942. //zhcx结束
  1943. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "w") or die("Unable to open file!");
  1944. $txt = json_encode(array('zzt' => $zzt, 'tj' => $zqtdata, 'zhcx' => $zhcxdata));
  1945. fwrite($myfile, $txt);
  1946. fclose($myfile);
  1947. echo 1;
  1948. }
  1949. public function _statistics_hb(){
  1950. if (isset($_SESSION['api'])) {
  1951. $user = $this->user->get_api($_SESSION['api']);
  1952. $usp = $user;
  1953. $fgshop = "";
  1954. $sid = "";
  1955. $user = explode('|', trim($user['shop'], '|'));
  1956. foreach ($user as $value) {
  1957. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  1958. $fgshop .= " shop = " . $value . " or";
  1959. }
  1960. $sid .= " id = " . $value . " or";
  1961. }
  1962. }
  1963. $source = $this->input->post('source');
  1964. $time = $this->input->post('time');
  1965. $tab = $this->input->post('tab');
  1966. $table_name = $this->input->post('table_name');
  1967. if(empty($table_name)){
  1968. $table_name = 'fullorder';
  1969. }
  1970. if($tab == 2){
  1971. $now_time = [];
  1972. $timedata = explode('|', $time);
  1973. $ktime = strtotime($timedata[0]);
  1974. $jtime = strtotime($timedata[1]);
  1975. $ktime = $ktime - ($jtime - $ktime);
  1976. $k = $ktime;
  1977. $j = $jtime;
  1978. $n = ($j - $k) / (24 * 3600);
  1979. $usat = $jtime;
  1980. for ($i = 1; $i < $n; $i++) {
  1981. //近7天时间
  1982. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1983. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1984. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1985. $now_time[] = date('Y-m-d', $t);
  1986. }
  1987. }
  1988. $k_tmp_time = strtotime($now_time[0]);
  1989. $e_tmp_time = strtotime($now_time[count($now_time) - 1] ) + 24 * 3600;
  1990. $ll_time = ($e_tmp_time - $k_tmp_time) ;
  1991. // var_dump(date("Y-m-d H:i:s", $k_tmp_time)."=========".date("Y-m-d H:i:s", $e_tmp_time));
  1992. // var_dump(date("Y-m-d H:i:s", $k_tmp_time - $ll_time)."=========".date("Y-m-d H:i:s", $k_tmp_time));
  1993. // die;
  1994. $k_time = $k_tmp_time - $ll_time;
  1995. $j_time = $k_tmp_time;
  1996. // $timedata = explode('|', $time);
  1997. // $ktime = strtotime($timedata[0]) + 24 * 3600;
  1998. // $jtime = strtotime($timedata[1]);
  1999. // $ll_time = ($jtime - $ktime);
  2000. // $k_time = $ktime - $ll_time ;
  2001. // $j_time = $jtime - $ll_time;
  2002. $where = "( dtime >= ".$k_time." and dtime <= ".$j_time." ) ";
  2003. }else{
  2004. $k_time = "";
  2005. $j_time = "";
  2006. if($time >= 691200){
  2007. $k_time = strtotime(date("Ymd", time())) - $time+ 24 * 3600;
  2008. $j_time = strtotime(date("Ymd", time()));
  2009. $k_hb_time = $k_time - $time + 24 * 3600;
  2010. $j_hb_time = $k_time;
  2011. }else{
  2012. $k_time = strtotime(date("Ymd", time())) - $time + 24 * 3600;
  2013. $j_time = $k_time + 24 * 3600;
  2014. $k_hb_time = $k_time - 24 * 3600;
  2015. $j_hb_time = $j_time - 24 * 3600;
  2016. }
  2017. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  2018. }
  2019. if ($source) {
  2020. if ($source == '2d') {
  2021. $where .= " and source >= '2' ";
  2022. } else {
  2023. $where .= " and source = '$source' ";
  2024. }
  2025. }
  2026. if($table_name == 'fullordertt' || $table_name == 'fullorderamz'){
  2027. $where .= " and state != 217 ";
  2028. }
  2029. $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');
  2030. $sl = count($list);
  2031. $je = sprintf("%01.2f", array_sum(array_column($list, 'shouldmoney')));
  2032. $ssje = 0;
  2033. //实收金额
  2034. $dlzmss = sprintf("%01.2f", array_sum(array_column($list, 'budget')));
  2035. //实收金额
  2036. //补/退原额
  2037. $dlzbty = sprintf("%01.2f", array_sum(array_column($list, 'refundy')));
  2038. $ssje = sprintf("%01.2f", $dlzmss + $dlzbty);
  2039. echo json_encode([
  2040. 'status' => 1,
  2041. 'data' => [
  2042. 'sl' => $sl,
  2043. 'je' => $je,
  2044. 'ssje' => $ssje,
  2045. ]
  2046. ]);
  2047. exit; //,'sycp'=>$sycp昨日产品数据
  2048. }
  2049. public function _statistics_tb(){
  2050. if (isset($_SESSION['api'])) {
  2051. $user = $this->user->get_api($_SESSION['api']);
  2052. $usp = $user;
  2053. $fgshop = "";
  2054. $sid = "";
  2055. $user = explode('|', trim($user['shop'], '|'));
  2056. foreach ($user as $value) {
  2057. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  2058. $fgshop .= " shop = " . $value . " or";
  2059. }
  2060. $sid .= " id = " . $value . " or";
  2061. }
  2062. }
  2063. $source = $this->input->post('source');
  2064. $time = $this->input->post('time');
  2065. $tab = $this->input->post('tab');
  2066. $table_name = $this->input->post('table_name');
  2067. if(empty($table_name)){
  2068. $table_name = 'fullorder';
  2069. }
  2070. if($tab == 2){
  2071. $now_time = [];
  2072. $timedata = explode('|', $time);
  2073. $ktime = strtotime($timedata[0]);
  2074. $jtime = strtotime($timedata[1]);
  2075. $ktime = $ktime - ($jtime - $ktime);
  2076. $k = $ktime;
  2077. $j = $jtime;
  2078. $n = ($j - $k) / (24 * 3600);
  2079. $usat = $jtime;
  2080. for ($i = 1; $i < $n; $i++) {
  2081. //近7天时间
  2082. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  2083. if ($n > 13 && $i > $n / 2 || $n < 14) {
  2084. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  2085. $now_time[] = date('Y-m-d', $t);
  2086. }
  2087. }
  2088. $k_tmp_time = strtotime($now_time[0]);
  2089. $e_tmp_time = strtotime($now_time[count($now_time) - 1] ) + 24 * 3600;
  2090. $k_hb_time = $k_tmp_time - 365*24*3600;
  2091. $j_hb_time = $e_tmp_time - 365*24*3600;
  2092. // var_dump(date("Y-m-d H:i:s", $k_tmp_time)."=========".date("Y-m-d H:i:s", $e_tmp_time));
  2093. // var_dump(date("Y-m-d H:i:s", $k_hb_time)."=========".date("Y-m-d H:i:s", $j_hb_time));
  2094. // die;
  2095. // $timedata = explode('|', $time);
  2096. // $ktime = strtotime($timedata[0]) + 24 * 3600;
  2097. // $jtime = strtotime($timedata[1]);
  2098. // $ll_time = ($jtime - $ktime);
  2099. // $k_time = $ktime - $ll_time ;
  2100. // $j_time = $jtime - $ll_time;
  2101. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  2102. }else{
  2103. $k_time = "";
  2104. $j_time = "";
  2105. if($time >= 691200){
  2106. $k_time = strtotime(date("Ymd", time())) - $time+ 24 * 3600;
  2107. $j_time = strtotime(date("Ymd", time()));
  2108. $k_hb_time = $k_time - 365*24*3600;
  2109. $j_hb_time = $j_time - 365*24*3600;
  2110. }else{
  2111. $k_time = strtotime(date("Ymd", time())) - $time + 24 * 3600;
  2112. $j_time = $k_time + 24 * 3600;
  2113. $k_hb_time = $k_time - 365*24*3600;
  2114. $j_hb_time = $j_time - 365*24*3600;
  2115. }
  2116. // var_dump(date("Y-m-d H:i:s", $k_time)."=========".date("Y-m-d H:i:s", $j_time));
  2117. // var_dump(date("Y-m-d H:i:s", $k_hb_time)."=========".date("Y-m-d H:i:s", $j_hb_time));
  2118. // die;
  2119. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  2120. }
  2121. if ($source) {
  2122. if ($source == '2d') {
  2123. $where .= " and source >= '2' ";
  2124. } else {
  2125. $where .= " and source = '$source' ";
  2126. }
  2127. }
  2128. if($table_name == 'fullordertt' || $table_name == 'fullorderamz'){
  2129. $where .= " and state != 217 ";
  2130. }
  2131. $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');
  2132. $sl = count($list);
  2133. $je = sprintf("%01.2f", array_sum(array_column($list, 'shouldmoney')));
  2134. $ssje = 0;
  2135. //实收金额
  2136. $dlzmss = sprintf("%01.2f", array_sum(array_column($list, 'budget')));
  2137. //实收金额
  2138. //补/退原额
  2139. $dlzbty = sprintf("%01.2f", array_sum(array_column($list, 'refundy')));
  2140. $ssje = sprintf("%01.2f", $dlzmss + $dlzbty);
  2141. echo json_encode([
  2142. 'status' => 1,
  2143. 'data' => [
  2144. 'sl' => $sl,
  2145. 'je' => $je,
  2146. 'ssje' => $ssje,
  2147. ]
  2148. ]);
  2149. exit; //,'sycp'=>$sycp昨日产品数据
  2150. }
  2151. public function _user_lvceshi(){
  2152. $dt = 0;
  2153. if (isset($_SESSION['api'])) {
  2154. $user = $this->user->get_api($_SESSION['api']);
  2155. $usp = $user;
  2156. $fgshop = "";
  2157. $sid = "";
  2158. $user = explode('|', trim($user['shop'], '|'));
  2159. foreach ($user as $value) {
  2160. // 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')
  2161. // {
  2162. // $fgshop .= " shop = ".$value." or";
  2163. // }
  2164. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  2165. $fgshop .= " shop = " . $value . " or";
  2166. }
  2167. $sid .= " id = " . $value . " or";
  2168. }
  2169. }
  2170. $post = $this->input->post(NULL, TRUE);
  2171. $source = $this->input->post('source', true);
  2172. $where = "";
  2173. if ($source) {
  2174. if ($source == '2d') {
  2175. $where = " and source >= '2'";
  2176. } else {
  2177. $where = " and source = '$source'";
  2178. }
  2179. }
  2180. $tm = strtotime(date("Ymd"), time());
  2181. $usat = $tm;
  2182. $wlshop = $this->shop->find_all('status = 0 and ' . rtrim($sid, 'or'));
  2183. $this->data['wlshop'] = $wlshop;
  2184. $dr = $usat;
  2185. $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));
  2186. $this->_Template('phone/p_user_statistics_copy', $this->data);
  2187. }
  2188. }