User.php 87 KB

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