User.php 88 KB

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