User.php 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728
  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. }
  26. //定义方法的调用规则 获取URI第二段值
  27. public function _remap($arg, $arg_array)
  28. {
  29. if ($arg == 'tc') //退出
  30. {
  31. $this->_tc();
  32. } else if ($arg == 'data') //操作页
  33. {
  34. $this->_data();
  35. } else if ($arg == 'del') //删除
  36. {
  37. $this->_del();
  38. } else if ($arg == 'default') //默认页
  39. {
  40. $this->_default();
  41. } else if ($arg == 'add') //添加
  42. {
  43. $this->_add();
  44. } else if ($arg == 'edit') //修改
  45. {
  46. $this->_edit($arg_array);
  47. } else if ($arg == 'rows') //数据
  48. {
  49. $this->_rows();
  50. } else if ($arg == 'statistics') //数据
  51. {
  52. $this->_statistics();
  53. } else if ($arg == 'apple') //数据
  54. {
  55. $this->_apple();
  56. } else if ($arg == 'zzt') //数据
  57. {
  58. $this->_zzt();
  59. } else if ($arg == 'tjadd') //数据
  60. {
  61. $this->_tjadd();
  62. } else if ($arg == 'shopfx') //店铺分析
  63. {
  64. $this->_shopfx();
  65. } else if ($arg == 'shopfxlist') //店铺分析
  66. {
  67. $this->_shopfxlist();
  68. } else {
  69. $this->_index();
  70. }
  71. }
  72. //首页
  73. public function _index()
  74. {
  75. $user = $this->user->get_api($_SESSION['api']);
  76. $this->data['user'] = $user; //登录的用户信息
  77. $power = $this->power->read($user['power']);
  78. $power = $power['powerid'];
  79. //$power = explode('|',trim($power,'|'));字符串转数组
  80. $dataa = $this->nav->find_all('type=1', '*', 'px asc');
  81. $datab = $this->nav->find_all('type=2', '*', 'px asc');
  82. $datac = $this->nav->find_all('type=3', '*', 'sort asc,px desc');
  83. $an = array();
  84. foreach ($dataa as $key => $value) {
  85. foreach ($datab as $ke => $va) {
  86. if ($va['class'] == $value['id']) {
  87. foreach ($datac as $k => $v) {
  88. if ($v['class'] == $va['id']) {
  89. if (strstr($power, '|' . $v['id'] . '|') == true) {
  90. $va['cn'][] = $v;
  91. }
  92. }
  93. }
  94. if (strstr($power, '|' . $va['id'] . '|') == true) {
  95. $value['bn'][] = $va;
  96. }
  97. }
  98. } //循环出二级导航航
  99. if (strstr($power, '|' . $value['id'] . '|') == true) {
  100. $an[] = $value;
  101. }
  102. }
  103. //print_r($an);
  104. $this->data['data'] = $an;
  105. $this->data['ip'] = $this->input->ip_address();
  106. $this->data['power'] = $user['power'];
  107. $this->data['link'] = $user['link'];
  108. if (stripos($_SERVER['HTTP_HOST'], 'a.') !== false) {
  109. $url = 'b';
  110. } else {
  111. $url = 'a';
  112. }
  113. $this->data['url'] = $url;
  114. $this->_Template('user', $this->data);
  115. }
  116. //管理
  117. public function _data()
  118. {
  119. $user = $this->user->get_api($_SESSION['api']);
  120. $post = $this->input->post(NULL, TRUE);
  121. if (isset($post['page'])) {
  122. $page = $this->input->post('page', true);
  123. $perpage = $this->input->post('perpage', true);
  124. $power = $this->input->post('power', true);
  125. $name = $this->input->post('name', true);
  126. $userid = $this->input->post('userid', true);
  127. $where = "own='" . $user['own'] . "'";
  128. if ($power) {
  129. $where .= " and power = '$power'";
  130. }
  131. if ($name) {
  132. $where .= " and name like '%$name%'";
  133. }
  134. if ($userid) {
  135. $where .= " and userid like '%$userid%'";
  136. }
  137. //数据排序
  138. $order_str = "id asc";
  139. if (empty($page)) {
  140. $start = 0;
  141. $perpage = 1;
  142. } else {
  143. $start = ($page - 1) * $perpage;
  144. }
  145. //取得信息列表
  146. //$info_list = $this->user->find_all($where,'id,name,userid,power,shoptext,purchasetext,warehousetext,stafftext,transfertext,type,lasttime',$order_str,$start,$perpage);
  147. $info_list = $this->user->find_all($where, 'id,name,userid,power,shoptext,purchasetext,warehousetext,transfertext,type,lasttime', $order_str, $start, $perpage);
  148. //格式化数据
  149. foreach ($info_list as $key => $value) {
  150. if ($value['type'] == 1) {
  151. if (empty($value['lasttime'])) {
  152. $info_list[$key]['type'] = '正常';
  153. } else {
  154. $info_list[$key]['type'] = '正常' . "<br>最后操作时间:<br>" . date("Y-m-d", $value['lasttime']);
  155. }
  156. } else {
  157. $info_list[$key]['type'] = '停用';
  158. }
  159. $power = $this->power->read($value['power']);
  160. $info_list[$key]['power'] = $power['powername'];
  161. unset($info_list[$key]['lasttime']);
  162. }
  163. $total = $this->user->find_count($where);
  164. $pagenum = ceil($total / $perpage);
  165. $over = $total - ($start + $perpage);
  166. $rows = array('total' => $total, 'over' => $over, 'pagenum' => $pagenum, 'rows' => ($info_list));
  167. echo json_encode($rows);
  168. exit;
  169. }
  170. $power = $this->power->find_all();
  171. $this->data['power'] = $power;
  172. $this->_Template('user_data', $this->data);
  173. }
  174. //添加
  175. public function _add()
  176. {
  177. $user = $this->user->get_api($_SESSION['api']);
  178. $post = $this->input->post(NULL, TRUE);
  179. if (isset($post['userid'])) {
  180. $post['userid'] = $this->input->post('userid', true);
  181. $userpass = $this->input->post('userpass', true);
  182. $post['userpass'] = sha1($userpass);
  183. $post['shop'] = $this->input->post('shop', true);
  184. $post['shoptext'] = $this->input->post('shoptext', true);
  185. $post['excelshop'] = $this->input->post('excelshop', true);
  186. $post['excelshoptext'] = $this->input->post('excelshoptext', true);
  187. $post['purchase'] = $this->input->post('purchase', true);
  188. $post['purchasetext'] = $this->input->post('purchasetext', true);
  189. $post['warehouse'] = $this->input->post('warehouse', true);
  190. $post['warehousetext'] = $this->input->post('warehousetext', true);
  191. $post['customer'] = $this->input->post('customer', true);
  192. $post['staff'] = $this->input->post('staff', true);
  193. $post['stafftext'] = $this->input->post('stafftext', true);
  194. $post['power'] = $this->input->post('power', true);
  195. $post['name'] = $this->input->post('name', true);
  196. $post['phone'] = $this->input->post('phone', true);
  197. $post['type'] = $this->input->post('type', true);
  198. $post['html'] = $this->input->post('html', true);
  199. $post['own'] = $user['own'];
  200. $post['api'] = sha1(rand(1000000, 9999999));
  201. if ($this->user->insert($post)) {
  202. echo json_encode(array('msg' => '添加成功', 'success' => true));
  203. exit;
  204. } else {
  205. echo json_encode(array('msg' => '添加失败,请重试', 'success' => false));
  206. exit;
  207. }
  208. }
  209. $power = $this->power->find_all();
  210. $this->data['power'] = $power;
  211. $this->_Template('user_add', $this->data);
  212. }
  213. //修改
  214. public function _edit($arg_array)
  215. {
  216. $post = $this->input->post(NULL, TRUE);
  217. if (isset($post['id'])) {
  218. $id = $this->input->post('id', true);
  219. $post['userid'] = $this->input->post('edituserid', true);
  220. $userpass = $this->input->post('edituserpass', true);
  221. $post['shop'] = $this->input->post('shop', true);
  222. $post['shoptext'] = $this->input->post('shoptext', true);
  223. $post['excelshop'] = $this->input->post('excelshop', true);
  224. $post['excelshoptext'] = $this->input->post('excelshoptext', true);
  225. $post['purchase'] = $this->input->post('purchase', true);
  226. $post['purchasetext'] = $this->input->post('purchasetext', true);
  227. $post['warehouse'] = $this->input->post('warehouse', true);
  228. $post['warehousetext'] = $this->input->post('warehousetext', true);
  229. $post['customer'] = $this->input->post('customer', true);
  230. $post['staff'] = $this->input->post('staff', true);
  231. $post['stafftext'] = $this->input->post('stafftext', true);
  232. $post['power'] = $this->input->post('power', true);
  233. $post['name'] = $this->input->post('name', true);
  234. $post['phone'] = $this->input->post('phone', true);
  235. $post['type'] = $this->input->post('type', true);
  236. $post['html'] = $this->input->post('html', true);
  237. $ud = $this->user->read($id);
  238. if ($userpass != NULL) {
  239. $post['userpass'] = sha1($userpass);
  240. $post['api'] = sha1(rand(1000000, 9999999));
  241. } else {
  242. $post['userpass'] = $ud['userpass'];
  243. }
  244. if ($this->user->save($post, $id)) {
  245. echo json_encode(array('msg' => '修改成功', 'success' => true));
  246. exit;
  247. } else {
  248. echo json_encode(array('msg' => '修改失败,请重试', 'success' => false));
  249. exit;
  250. }
  251. }
  252. $arg_array = $arg_array[0];
  253. $user = $this->user->read($arg_array);
  254. $this->data['user'] = $user;
  255. $power = $this->power->find_all();
  256. $this->data['power'] = $power;
  257. $this->_Template('user_edit', $this->data);
  258. }
  259. //删除
  260. public function _del()
  261. {
  262. $post = $this->input->post(NULL, TRUE);
  263. if (isset($post['s'])) {
  264. $id_arr = $this->input->post('s');
  265. $id_arr = explode(',', $id_arr);
  266. if (!$id_arr) {
  267. echo json_encode(array('msg' => '参数错误!', 'success' => false));
  268. exit;
  269. }
  270. //循环删除记录
  271. foreach ($id_arr as $v) {
  272. $this->user->remove($v);
  273. }
  274. echo json_encode(array('del' => $id_arr, 'msg' => '删除记录成功!', 'success' => true));
  275. }
  276. }
  277. //默认页
  278. public function _default()
  279. {
  280. /**
  281. $order = $this->order->get_w();
  282. $order = count($order);//查询订单未处理数量
  283. $message = $this->message->get_w();
  284. $message = count($message);//查询留言未处理数量
  285. $this->_Template('default',$this->data);
  286. **/
  287. $dt = 0;
  288. if (isset($_SESSION['api'])) {
  289. $user = $this->user->get_api($_SESSION['api']);
  290. $usp = $user;
  291. $fgshop = "";
  292. $sid = "";
  293. $user = explode('|', trim($user['shop'], '|'));
  294. foreach ($user as $value) {
  295. if ($value != '18' && $value != '19' && $value != '12' && $value != '13' && $value != '9' && $value != '15' && $value != '27') {
  296. $fgshop .= " shop = " . $value . " or";
  297. }
  298. $sid .= " id = " . $value . " or";
  299. }
  300. }
  301. $post = $this->input->post(NULL, TRUE);
  302. if (isset($post['timek'])) {
  303. //$start = '2018-10-15';
  304. //$end = '2018-11-26';
  305. //$tim = strtotime($start);
  306. //$day = $time/(3600*24);
  307. $timek = $this->input->post('timek', true);
  308. $timej = $this->input->post('timej', true);
  309. $k = strtotime($timek) - 24 * 3600; //少一天为增加选择开始天时间
  310. $j = strtotime($timej);
  311. $n = ($j - $k) / (24 * 3600);
  312. if ($n < 1) {
  313. $n = 1;
  314. }
  315. $time = array();
  316. $stime = array();
  317. $num = array();
  318. $ymoney = array();
  319. $money = array();
  320. for ($i = 1; $i < $n; $i++) {
  321. //近7天时间
  322. $t = $j - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  323. $time[] = date('Y-m-d', $t);
  324. $ct = strtotime(date('Ymd', $t));
  325. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  326. $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');
  327. $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');
  328. $dsmt = array();
  329. $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');
  330. $d = array_merge($dlz, $dsmt, $tt);
  331. $num[] = count($d);
  332. $ymoney[] = sprintf("%01.2f", array_sum(array_column($d, 'budget')));
  333. $money[] = sprintf("%01.2f", array_sum(array_column($d, 'shouldmoney')));
  334. }
  335. $snuz = $this->fullorder->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  336. $snuz += $this->fullordersmt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  337. $snuz += $this->fullordertt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  338. $lnuz = $this->fullorder->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待出库
  339. $lnuz += $this->fullordersmt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待出库
  340. $lnuz += $this->fullordertt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待出库
  341. $snu = $this->fullorder->find_count('reviewtime = 0 and dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  342. $snu += $this->fullordersmt->find_count('reviewtime = 0 and dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  343. $snu += $this->fullordertt->find_count('reviewtime = 0 and dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  344. $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') . ')'); //待出库
  345. $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') . ')'); //待出库
  346. $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') . ')'); //待出库
  347. 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));
  348. exit;
  349. }
  350. $this->_Template('user_default', $this->data);
  351. }
  352. public function _zzt()
  353. {
  354. exit;
  355. if (isset($_SESSION['api'])) {
  356. $user = $this->user->get_api($_SESSION['api']);
  357. $usp = $user;
  358. $fgshop = "";
  359. $sid = "";
  360. $user = explode('|', trim($user['shop'], '|'));
  361. foreach ($user as $value) {
  362. $fgshop .= " shop = " . $value . " or";
  363. $sid .= " id = " . $value . " or";
  364. }
  365. }
  366. $data = array();
  367. $sntime = array();
  368. $sndata1 = array();
  369. $sndata2 = array();
  370. $sndata3 = array();
  371. $sj = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
  372. for ($i = 0; $i < 3; $i++) {
  373. foreach ($sj as $v) {
  374. $sntime[] = date("Y") - 2 + $i . '-' . $v;
  375. }
  376. }
  377. $pdtime = date('Y-m-d-H', time());
  378. if (is_file("./data/tj/" . $pdtime . ".txt")) {
  379. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  380. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  381. fclose($myfile);
  382. $bc = json_decode($bc, true);
  383. $data = $bc['zzt'][0];
  384. $sndata = $bc['zzt'][1];
  385. } else {
  386. $i = 0;
  387. foreach ($sj as $k => $v) {
  388. $i++;
  389. $dlz1 = $this->fullorder->find_all("gtime > '" . date("Y") . $v . "00' and gtime < '" . date("Y") . $v . "32'", 'shouldmoney');
  390. $smt1 = $this->fullordersmt->find_all("gtime > '" . date("Y") . $v . "00' and gtime < '" . date("Y") . $v . "32'", 'shouldmoney');
  391. $m1 = sprintf("%01.2f", array_sum(array_column($dlz1, 'shouldmoney')) + array_sum(array_column($smt1, 'shouldmoney')));
  392. $dlz2 = $this->fullorder->find_all("gtime > '" . (date("Y") - 1) . $v . "00' and gtime < '" . (date("Y") - 1) . $v . "32'", 'shouldmoney');
  393. $smt2 = $this->fullordersmt->find_all("gtime > '" . (date("Y") - 1) . $v . "00' and gtime < '" . (date("Y") - 1) . $v . "32'", 'shouldmoney');
  394. $m2 = sprintf("%01.2f", array_sum(array_column($dlz2, 'shouldmoney')) + array_sum(array_column($smt2, 'shouldmoney')));
  395. $dlz3 = $this->fullorder->find_all("gtime > '" . (date("Y") - 2) . $v . "00' and gtime < '" . (date("Y") - 2) . $v . "32'", 'shouldmoney');
  396. $smt3 = $this->fullordersmt->find_all("gtime > '" . (date("Y") - 2) . $v . "00' and gtime < '" . (date("Y") - 2) . $v . "32'", 'shouldmoney');
  397. $m3 = sprintf("%01.2f", array_sum(array_column($dlz3, 'shouldmoney')) + array_sum(array_column($smt3, 'shouldmoney')));
  398. $sndata1[$i] = $m3;
  399. $sndata2[12 + $i] = $m2;
  400. $sndata3[24 + $i] = $m1;
  401. $data[] = array($v, $m1, $m2, $m3);
  402. }
  403. }
  404. $time = array(date("Y"), (date("Y") - 1), (date("Y") - 2));
  405. echo json_encode(array('data' => $data, 'time' => $time, 'sndata' => $sndata, 'sntime' => $sntime, 'success' => true));
  406. exit;
  407. }
  408. //默认页
  409. public function _statistics()
  410. {
  411. /**
  412. $order = $this->order->get_w();
  413. $order = count($order);//查询订单未处理数量
  414. $message = $this->message->get_w();
  415. $message = count($message);//查询留言未处理数量
  416. $this->_Template('default',$this->data);
  417. **/
  418. //date_default_timezone_set("Etc/GMT+8");
  419. $dt = 0;
  420. if (isset($_SESSION['api'])) {
  421. $user = $this->user->get_api($_SESSION['api']);
  422. $usp = $user;
  423. $fgshop = "";
  424. $sid = "";
  425. $user = explode('|', trim($user['shop'], '|'));
  426. foreach ($user as $value) {
  427. // 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')
  428. // {
  429. // $fgshop .= " shop = ".$value." or";
  430. // }
  431. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34])) {
  432. $fgshop .= " shop = " . $value . " or";
  433. }
  434. $sid .= " id = " . $value . " or";
  435. }
  436. }
  437. $post = $this->input->post(NULL, TRUE);
  438. $source = $this->input->post('source', true);
  439. $where = "";
  440. if ($source) {
  441. if ($source == '2d') {
  442. $where = " and source >= '2'";
  443. } else {
  444. $where = " and source = '$source'";
  445. }
  446. }
  447. $tm = strtotime(date("Ymd"), time());
  448. $usat = $tm;
  449. if (isset($post['zhcx'])) {
  450. $zdt = $this->input->post('time', true);
  451. $k = $zdt;
  452. $tab = $this->input->post('tab', true);
  453. $pdtime = date('Y-m-d-H', time());
  454. if (is_file("./data/tj/" . $pdtime . ".txt") && $tab == 1 && $zdt > 172800) {
  455. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  456. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  457. fclose($myfile);
  458. $bc = json_decode($bc, true);
  459. echo json_encode($bc['zhcx'][$source][$zdt]);
  460. exit;
  461. } else {
  462. $customer = $this->customer->find_all("shop !=''", 'num,zhcx');
  463. $customerkey = array_column($customer, 'zhcx');
  464. $customer = array_combine($customerkey, $customer);
  465. $customersmt = $this->customersmt->find_all("shop !=''", 'num,zhcx');
  466. $customersmtkey = array_column($customersmt, 'zhcx');
  467. $customersmt = array_combine($customersmtkey, $customersmt);
  468. //$start = '2018-10-15';
  469. //$end = '2018-11-26';
  470. //$tim = strtotime($start);
  471. //$day = $time/(3600*24);
  472. if ($tab == '1') {
  473. if ($zdt >= 691200) {
  474. $k = $usat - $k - $k;
  475. $j = $usat;
  476. $n = ($j - $k) / (24 * 3600);
  477. } else {
  478. $n = 2;
  479. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  480. }
  481. } else {
  482. $timedata = explode('|', $zdt);
  483. $ktime = strtotime($timedata[0]);
  484. $jtime = strtotime($timedata[1]);
  485. $ktime = $ktime - ($jtime - $ktime);
  486. $k = $ktime;
  487. $j = $jtime;
  488. $n = ($j - $k) / (24 * 3600);
  489. $usat = $jtime;
  490. }
  491. $time = array();
  492. $timeold = array();
  493. $stime = array();
  494. $dlznum = array();
  495. $smtnum = array();
  496. $ymoney = array();
  497. $money = array();
  498. $dlzmoneyb = array();
  499. $smtmoneyb = array();
  500. $ttmoneyb = array();
  501. $zkh = array();
  502. $dlzsl = 0;
  503. $dlzje = 0;
  504. $dlzssje = 0;
  505. $smtsl = 0;
  506. $smtje = 0;
  507. $smtssje = 0;
  508. $ttsl = 0;
  509. $ttje = 0;
  510. $ttssje = 0;
  511. $shopdata = array();
  512. $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'");
  513. foreach ($ys as $v) {
  514. $shopdata[$v['id']] = array('id' => $v['id'], 'b' => $v['type'], 'fdl' => 0, 'chl' => 0, 'num' => 0, 'fgl' => 0);
  515. $zkh[$v['id']] = array();
  516. }
  517. for ($i = 1; $i < $n; $i++) {
  518. if ($n > 13 && $i > $n / 2 || $n < 14) {
  519. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  520. $time[] = date('m-d', $t);
  521. $ct = strtotime(date('Ymd', $t));
  522. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  523. $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');
  524. $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');
  525. $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');
  526. $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');
  527. //数量及金额结束
  528. $sd = array_merge($dlz, $smt, $tt,$amz);
  529. $fgldata = array();
  530. foreach ($sd as $v) {
  531. if (isset($v['email'])) {
  532. if (!isset($fgldata[$v['shop'] . '-' . $v['email']])) {
  533. $fgldata[$v['shop'] . '-' . $v['email']] = 0;
  534. } else {
  535. $fgldata[$v['shop'] . '-' . $v['email']] += 1;
  536. }
  537. $zkh[$v['shop']][$v['email']] = array();
  538. } else {
  539. if (!isset($fgldata[$v['shop'] . '-' . $v['userid']])) {
  540. $fgldata[$v['shop'] . '-' . $v['userid']] = 0;
  541. } else {
  542. $fgldata[$v['shop'] . '-' . $v['userid']] += 1;
  543. }
  544. $zkh[$v['shop']][$v['userid']] = array();
  545. }
  546. }
  547. foreach ($sd as $v) {
  548. $chl = 0;
  549. if (isset($shopdata[$v['shop']])) {
  550. if (isset($v['email'])) {
  551. if (isset($customer[$v['shop'] . '-' . $v['email']]['num'])) {
  552. $fdl = $customer[$v['shop'] . '-' . $v['email']]['num'] > 1 ? 1 : 0;
  553. } else {
  554. $fdl = 0;
  555. }
  556. foreach ($ys as $vv) {
  557. if ($vv['id'] != $v['shop'] && isset($customer[$vv['id'] . '-' . $v['email']])) {
  558. $chl = 1;
  559. }
  560. }
  561. if (isset($fgldata[$v['shop'] . '-' . $v['email']])) {
  562. $fgl = $fgldata[$v['shop'] . '-' . $v['email']] > 0 ? 1 : 0;
  563. } else {
  564. $fgl = 0;
  565. }
  566. } else {
  567. if (isset($customersmt[$v['shop'] . '-' . $v['userid']]['num'])) {
  568. $fdl = $customersmt[$v['shop'] . '-' . $v['userid']]['num'] > 1 ? 1 : 0;
  569. } else {
  570. $fdl = 0;
  571. }
  572. foreach ($ys as $vv) {
  573. if ($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'] . '-' . $v['userid']])) {
  574. $chl = 1;
  575. }
  576. }
  577. if (isset($fgldata[$v['shop'] . '-' . $v['userid']])) {
  578. $fgl = $fgldata[$v['shop'] . '-' . $v['userid']] > 0 ? 1 : 0;
  579. } else {
  580. $fgl = 0;
  581. }
  582. }
  583. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl'] + $fdl;
  584. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl'] + $chl;
  585. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl'] + $fgl;
  586. $shopdata[$v['shop']]['num'] += 1;
  587. }
  588. }
  589. }
  590. }
  591. foreach ($shopdata as $k => $v) {
  592. $shopdata[$k]['fdl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['fdl'] / $v['num'] * 100)) . '%';
  593. $shopdata[$k]['chl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['chl'] / $v['num'] * 100)) . '%';
  594. $shopdata[$k]['fgl'] = count($zkh[$v['id']]) == '0' ? 0 : sprintf("%01.2f", ($v['fgl'] / count($zkh[$v['id']]) * 100)) . '%';
  595. }
  596. $shopdata = array_values($shopdata);
  597. echo @json_encode(array('shopdata' => $shopdata, 'success' => true));
  598. exit;
  599. }
  600. }
  601. if (isset($post['time'])) {
  602. $zdt = $this->input->post('time', true);
  603. $k = $zdt;
  604. $tab = $this->input->post('tab', true);
  605. $pdtime = date('Y-m-d-H', time());
  606. // if (is_file("./data/tj/" . $pdtime . ".txt") && $tab == 1 && $zdt > 172800) //前端改店内需要修改zdt 172800
  607. // {
  608. // $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  609. // $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  610. // fclose($myfile);
  611. // $bc = json_decode($bc, true);
  612. // echo json_encode($bc['tj'][$source][$zdt]);
  613. // exit;
  614. // } else {
  615. //$start = '2018-10-15';
  616. //$end = '2018-11-26';
  617. //$tim = strtotime($start);
  618. //$day = $time/(3600*24);
  619. if ($tab == '1') {
  620. if ($zdt >= 691200) {
  621. $k = $usat - $k - $k;
  622. $j = $usat;
  623. $n = ($j - $k) / (24 * 3600);
  624. } else {
  625. $n = 2;
  626. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  627. }
  628. } else {
  629. $timedata = explode('|', $zdt);
  630. $ktime = strtotime($timedata[0]);
  631. $jtime = strtotime($timedata[1]);
  632. $ktime = $ktime - ($jtime - $ktime);
  633. $k = $ktime;
  634. $j = $jtime;
  635. $n = ($j - $k) / (24 * 3600);
  636. $usat = $jtime;
  637. $tm = $jtime;
  638. $zdt = $jtime - $ktime;
  639. }
  640. $time = array();
  641. $timeold = array();
  642. $stime = array();
  643. $dlznum = array();
  644. $smtnum = array();
  645. $ymoney = array();
  646. $money = array();
  647. $dlzmoneyb = array();
  648. $smtmoneyb = array();
  649. $ttmoneyb = array();
  650. $zkh = array();
  651. $dlzsl = 0;
  652. $dlzje = 0;
  653. $dlzssje = 0;
  654. $smtsl = 0;
  655. $smtje = 0;
  656. $smtssje = 0;
  657. $ttsl = 0;
  658. $ttje = 0;
  659. $ttssje = 0;
  660. $amzsl = 0;
  661. $amzje = 0;
  662. $amzssje = 0;
  663. $shopdata = array();
  664. $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'");
  665. foreach ($ys as $v) {
  666. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  667. }
  668. for ($i = 1; $i < $n; $i++) {
  669. //近7天时间
  670. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  671. if ($n > 13 && $i > $n / 2 || $n < 14) {
  672. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  673. $time[] = date('m-d', $t);
  674. $ct = strtotime(date('Ymd', $t));
  675. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  676. $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');
  677. $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');
  678. $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');
  679. $amz = $this->fullorderamz->find_all("state != 217 and dtime >= " . $ct . " and dtime <= " . $ctj . $where . " and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'budget,shouldmoney,shop,number,refundy,budget,email,refundy');
  680. $ab[] = $dlz;
  681. //数量及金额开始
  682. $dlznum[] = count($dlz);
  683. $smtnum[] = count($smt);
  684. $ttnum[] = count($smt);
  685. $amznum[] = count($amz);
  686. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  687. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  688. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  689. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  690. /**
  691. //提出退款关闭等信息的实收金额
  692. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  693. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  694. //提出退款关闭等信息的实收金额
  695. **/
  696. //实收金额
  697. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  698. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  699. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  700. $amzmss = sprintf("%01.2f", array_sum(array_column($amz, 'budget')));
  701. //实收金额
  702. //补/退原额
  703. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  704. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  705. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  706. $amzbty = sprintf("%01.2f", array_sum(array_column($amz, 'refundy')));
  707. //补/退原额
  708. $dlzmoney[] = $dlzm;
  709. $smtmoney[] = $smtm;
  710. $ttmoney[] = $ttm;
  711. $amzmoney[] = $amzm;
  712. $dlzsl += count($dlz);
  713. $dlzje += $dlzm;
  714. $smtsl += count($smt);
  715. $smtje += $smtm;
  716. $ttsl += count($tt);
  717. $ttje += $ttm;
  718. $amzsl += count($amz);
  719. $amzje += $amzm;
  720. /**
  721. //减去的实收金额
  722. $dlzssje += $dlzm+$dlzmss;
  723. $smtssje += $smtm+$smtmss;
  724. **/
  725. //实收和补/退
  726. $dlzssje += $dlzmss + $dlzbty;
  727. $smtssje += $smtmss + $smtbty;
  728. $ttssje += $ttmss + $ttbty;
  729. $amzssje += $amzmss + $amzbty;
  730. //数量及金额结束
  731. $sd = array_merge($dlz, $smt, $tt,$amz);
  732. foreach ($sd as $v) {
  733. if (isset($shopdata[$v['shop']])) {
  734. $shopdata[$v['shop']]['num'] += 1;
  735. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  736. $shopdata[$v['shop']]['tmoney'] += $v['budget'] + $v['refundy'];
  737. }
  738. }
  739. } else if ($n > 13 && $i <= $n / 2) {
  740. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  741. $timeold[] = date('m-d', $t);
  742. $ct = strtotime(date('Ymd', $t));
  743. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  744. $dlz = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  745. $smt = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  746. $tt = $this->fullordertt->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  747. $amz = $this->fullorderamz->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  748. //数量及金额开始
  749. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  750. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  751. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  752. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  753. $dlzmoneyb[] = $dlzm;
  754. $smtmoneyb[] = $smtm;
  755. $ttmoneyb[] = $ttm;
  756. $amzmoneyb[] = $amzm;
  757. //数量及金额结束
  758. }
  759. }
  760. foreach ($shopdata as $k => $v) {
  761. $sn = $this->shop->read($k);
  762. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  763. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  764. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  765. $shopdata[$k]['name'] = $sn['shopname'];
  766. $shopdata[$k]['b'] = $sn['type'];
  767. $shopdata[$k]['id'] = $sn['id'];
  768. }
  769. $shopdata = array_values($shopdata);
  770. //$sycp=array();
  771. /**
  772. //根据所选时间产品排行开始
  773. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  774. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  775. **/
  776. /**
  777. //昨日产品排行开始
  778. $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');
  779. $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');
  780. $rows = array_merge($dlzlist,$smtlist);
  781. foreach ($rows as $v)
  782. {
  783. $number = explode('|',trim($v['whlabel'],'|'));
  784. $or = explode(';',trim($v['fpdata'],';'));
  785. $i=0;
  786. foreach ($or as $va)
  787. {
  788. $ord = explode('|',$va);
  789. $orod = explode(',',$ord[0]);
  790. $numberod = explode('-',$number[$i]);
  791. if(!isset($orod[1]))
  792. {
  793. continue;
  794. }
  795. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  796. {
  797. //$sycp[$orod[1]][0] += 1;//统计多少单
  798. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  799. $sycp[$orod[1]][1] += 0;//价格
  800. }
  801. else
  802. {
  803. if(isset($numberod[1]))
  804. {
  805. $typeclass = $this->typeclass->read($orod['0']);
  806. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  807. }
  808. }
  809. $i++;
  810. }
  811. }
  812. arsort($sycp);
  813. $sycp = array_values($sycp);
  814. $sycp = array_slice($sycp,0,10);
  815. //产品排行结束
  816. **/
  817. //当时实时数据结束
  818. 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));
  819. exit; //,'sycp'=>$sycp昨日产品数据
  820. }
  821. //}
  822. if (isset($post['sstime'])) {
  823. $shop = $this->input->post('shop', true);
  824. $zdtime = $usat;
  825. //当时实时数据开始
  826. if (!$shop) {
  827. $sssl = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  828. $ssje = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  829. $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');
  830. $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');
  831. $sssldlz = count($sssl);
  832. $ssslsmt = count($ssje);
  833. $sssltt = count($tje);
  834. $ssslamz = count($amzje);
  835. $ssjedlz = sprintf("%01.2f", array_sum(array_column($sssl, 'budget')));
  836. $ssjesmt = sprintf("%01.2f", array_sum(array_column($ssje, 'budget')));
  837. $ssjett = sprintf("%01.2f", array_sum(array_column($tje, 'budget')));
  838. $ssjeamz = sprintf("%01.2f", array_sum(array_column($amzje, 'budget')));
  839. $sssl = $sssldlz + $ssslsmt + $sssltt + $ssslamz;
  840. $ssje = $ssjedlz + $ssjesmt + $ssjett + $ssjeamz;
  841. } else {
  842. $sp = $this->shop->read($shop);
  843. if($sp['type'] == '1513'){
  844. $fu = 'fullorderamz';
  845. }elseif($sp['type'] == '270'){
  846. $fu = 'fullordersmt';
  847. }elseif($sp['type'] == '1514'){
  848. $fu = 'fullordertt';
  849. }else{
  850. $fu = 'fullorder';
  851. }
  852. //1513
  853. //$fu = ($sp['type'] == '269') ? 'fullorder' : 'fullordersmt';
  854. $ss = $this->$fu->find_all("dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . " and shop = '" . $shop . "'", 'budget,shouldmoney');
  855. $sssl = count($ss);
  856. $ssje = sprintf("%01.2f", array_sum(array_column($ss, 'budget')));
  857. }
  858. echo @json_encode(array('sstime' => date('m-d H:i', time()), 'sssl' => $sssl, 'ssje' => sprintf("%.2f", $ssje), 'success' => true));
  859. exit;
  860. }
  861. //店铺产品详情
  862. if (isset($post['id'])) {
  863. $tm += 24 * 3600;
  864. $gshtime = date('Y-m-d 0:0:0', time());
  865. $gshtime = strtotime($gshtime) + 24 * 60 * 60;
  866. $dpxq = array();
  867. $id = $this->input->post('id', true);
  868. $xqtime = $this->input->post('xqtime', true);
  869. $xqshop = $this->shop->read($id);
  870. if ($xqshop['type'] == "269") {
  871. $sid = 'fullorder';
  872. } else if ($xqshop['type'] == "270") {
  873. $sid = 'fullordersmt';
  874. } else if ($xqshop['type'] == "1513") {
  875. $sid = 'fullorderamz';
  876. }else if ($xqshop['type'] == "1514") {
  877. $sid = 'fullordertt';
  878. }
  879. if ($xqtime > 345600) {
  880. $rows = $this->$sid->find_all("shop = '" . $id . "' and dtime >= '" . ($gshtime - $xqtime) . "' and dtime <= '" . ($gshtime + 24 * 60 * 60) . "'", 'whlabel,fpdata,number');
  881. } else {
  882. $rows = $this->$sid->find_all("shop = '" . $id . "' and dtime >= '" . ($gshtime - $xqtime) . "' and dtime <= '" . ($gshtime + 24 * 60 * 60 - $xqtime) . "'", 'whlabel,fpdata,number');
  883. }
  884. foreach ($rows as $v) {
  885. $or = explode('|', ltrim($v['whlabel'], '|'));
  886. for ($i = 0; $i < count($or); $i++) {
  887. $orod = explode('-', $or[$i]);
  888. if ($orod[0] == '') {
  889. continue;
  890. }
  891. if (isset($dpxq[$orod[0]])) {
  892. $dpxq[$orod[0]][0] += $orod[1]; //统计多少条
  893. //$dpxq[$orod[0]][0] += 1;//统计多少单
  894. $dpxq[$orod[0]][1] .= $v['number'] . ';'; //价格
  895. } else {
  896. $oo = explode(';', rtrim($v['fpdata'], ';'));
  897. @$ro = explode('|', $oo[$i]);
  898. if (isset($ro[1])) {
  899. $dpxq[$orod[0]] = array($orod[1], $v['number'] . ';', $ro[1]); //统计多少条
  900. //$dpxq[$orod[0]] = array(1,0,$ro[1]);//统计多少单
  901. }
  902. }
  903. }
  904. }
  905. $dpxq = array_values($dpxq);
  906. arsort($dpxq);
  907. $dpxq = array_slice($dpxq, 0, 9999);
  908. echo @json_encode(array('dpxq' => $dpxq, 'success' => true));
  909. exit;
  910. }
  911. $wlshop = $this->shop->find_all('1=1 and ' . rtrim($sid, 'or'));
  912. $this->data['wlshop'] = $wlshop;
  913. $dr = $usat;
  914. $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));
  915. $this->_Template('phone/p_user_statisticsbak', $this->data);
  916. }
  917. /**
  918. public function super_unique($array,$key)//多维删除重复
  919. {
  920. $temp_array = array();
  921. foreach ($array as &$v) {
  922. if (!isset($temp_array[$v[$key]]))
  923. {
  924. $temp_array[$v[$key]] =& $v;
  925. }
  926. }
  927. $array = array_values($temp_array);
  928. return $array;
  929. }
  930. **/
  931. public function _usatime()
  932. {
  933. date_default_timezone_set("Etc/GMT+8");
  934. return time();
  935. }
  936. //数据
  937. public function _rows()
  938. {
  939. $post = $this->input->post(NULL, TRUE);
  940. if (isset($post['shop'])) {
  941. $shop = $this->input->post('shop', true);
  942. $data = $this->shop->find_all('1=1');
  943. $list = array();
  944. foreach ($data as $key => $value) {
  945. $t = $this->typeclass->read($value['type']);
  946. $list[] = array('id' => $value['id'], 'title' => $value['shopname'] . ' - ' . $t['title']);
  947. }
  948. $num = array();
  949. if ($shop != "null") {
  950. $num = $this->user->read($shop); //找出内容
  951. if ($num['shop']) {
  952. $num = explode('|', trim($num['shop'], '|')); //数组化内容
  953. } else {
  954. $num = array();
  955. }
  956. }
  957. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  958. }
  959. if (isset($post['excelshop'])) {
  960. $excelshop = $this->input->post('excelshop', true);
  961. $data = $this->shop->find_all('1=1');
  962. $list = array();
  963. foreach ($data as $key => $value) {
  964. $t = $this->typeclass->read($value['type']);
  965. $list[] = array('id' => $value['id'], 'title' => $value['shopname'] . ' - ' . $t['title']);
  966. }
  967. $num = array();
  968. if ($excelshop != "null") {
  969. $num = $this->user->read($excelshop); //找出内容
  970. if ($num['excelshop']) {
  971. $num = explode('|', trim($num['excelshop'], '|')); //数组化内容
  972. } else {
  973. $num = array();
  974. }
  975. }
  976. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  977. }
  978. if (isset($post['purchase'])) {
  979. $purchase = $this->input->post('purchase', true);
  980. $data = $this->purchase->find_all('1=1');
  981. $list = array();
  982. foreach ($data as $key => $value) {
  983. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  984. }
  985. $num = array();
  986. if ($purchase != "null") {
  987. $num = $this->user->read($purchase); //找出内容
  988. if ($num['purchase']) {
  989. $num = explode('|', trim($num['purchase'], '|')); //数组化内容
  990. } else {
  991. $num = array();
  992. }
  993. }
  994. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  995. }
  996. if (isset($post['staff'])) {
  997. $staff = $this->input->post('staff', true);
  998. $data = $this->staff->find_all('1=1');
  999. $list = array();
  1000. foreach ($data as $key => $value) {
  1001. $list[] = array('id' => $value['id'], 'title' => $value['name']);
  1002. }
  1003. $num = array();
  1004. if ($staff != "null") {
  1005. $num = $this->user->read($staff); //找出内容
  1006. if ($num['staff']) {
  1007. $num = explode('|', trim($num['staff'], '|')); //数组化内容
  1008. } else {
  1009. $num = array();
  1010. }
  1011. }
  1012. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1013. }
  1014. if (isset($post['warehouse'])) {
  1015. $warehouse = $this->input->post('warehouse', true);
  1016. $data = $this->warehouse->find_all('1=1');
  1017. $list = array();
  1018. foreach ($data as $key => $value) {
  1019. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1020. }
  1021. $num = array();
  1022. if ($warehouse != "null") {
  1023. $num = $this->user->read($warehouse); //找出内容
  1024. if ($num['warehouse']) {
  1025. $num = explode('|', trim($num['warehouse'], '|')); //数组化内容
  1026. } else {
  1027. $num = array();
  1028. }
  1029. }
  1030. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1031. }
  1032. if (isset($post['transfer'])) {
  1033. $transfer = $this->input->post('transfer', true);
  1034. $data = $this->transfer->find_all('1=1');
  1035. $list = array();
  1036. foreach ($data as $key => $value) {
  1037. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1038. }
  1039. $num = array();
  1040. if ($transfer != "null") {
  1041. $num = $this->user->read($transfer); //找出内容
  1042. if ($num['transfer']) {
  1043. $num = explode('|', trim($num['transfer'], '|')); //数组化内容
  1044. } else {
  1045. $num = array();
  1046. }
  1047. }
  1048. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1049. }
  1050. }
  1051. public function _shopfx()
  1052. {
  1053. $post = $this->input->post(NULL, TRUE);
  1054. if (isset($post['time'])) {
  1055. $time = $this->input->post('time', true);
  1056. $t = strtotime(date("Ymd", time() + 24 * 3600)); //明天0点
  1057. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1058. $sid = '';
  1059. foreach ($shop as $value) {
  1060. $sid .= " shop = " . $value['id'] . " or";
  1061. }
  1062. $sid = " and (" . rtrim($sid, 'or') . ")";
  1063. $znum = $this->fullorder->find_count("dtime > '" . ($t - $time * 24 * 3600) . "' and dtime < '" . $t . "'" . $sid);
  1064. $data = array();
  1065. $list = array();
  1066. $color = array('0' => '#30546c', '1' => '#61a0a8', '2' => '#c23531', '3' => '#d48265', '4' => '#546570', '5' => '#749f83', '6' => '#bda29a', '7' => '#6e7074', '8' => '#546570');
  1067. $j = 0;
  1068. $zt = array(7 => 1, 30 => 2);
  1069. foreach ($shop as $v) {
  1070. $d = $this->fullorder->find_count("shop = '" . $v['id'] . "' and dtime > '" . ($t - $time * 24 * 3600) . "' and dtime < '" . $t . "' and (state = '207' or state = '216')");
  1071. $wd = $this->allocation->read($zt[$time]);
  1072. $n = json_decode($wd['content'], true);
  1073. $bfb = ($d == 0) ? 0 : round(($d / $znum) * 100, 2);
  1074. $data[] = array('value' => $bfb, 'name' => $v['shopname'] . ' ' . $bfb . "%", 'itemStyle' => array('color' => $color[$j]));
  1075. $n[$v['id']][] = $this->fullorder->find_count("shop = '" . $v['id'] . "' and gtime = '" . date("Ymd", time()) . "' and (state = '207' or state = '216')");
  1076. $t_list = array();
  1077. for ($i = 0; $i < $time; $i++) {
  1078. $t_list[] = date("m-d", time() - ($i * 24 * 3600));
  1079. }
  1080. $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) . '%');
  1081. $j++;
  1082. }
  1083. $list = (array_reverse($list));
  1084. echo json_encode(array('data' => ($data), 'list' => $list, 't' => (array_reverse($t_list)), 'success' => true));
  1085. exit;
  1086. /**
  1087. $time = $this->input->post('time',true);
  1088. $t = strtotime(date("Ymd",time()+24*3600));//明天0点
  1089. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1090. $sid = '';
  1091. foreach ($shop as $value)
  1092. {
  1093. $sid .= " shop = ".$value['id']." or";
  1094. }
  1095. $sid = " and (".rtrim($sid,'or').")";
  1096. $znum = $this->fullorder->find_count("dtime > '".($t-$time*24*3600)."' and dtime < '".$t."'".$sid);
  1097. $data = array();$list = array();
  1098. $color = array('0'=>'#30546c','1'=>'#61a0a8','2'=>'#c23531','3'=>'#d48265','4'=>'#546570','5'=>'#749f83','6'=>'#bda29a','7'=>'#6e7074','8'=>'#546570');
  1099. $j = 0;
  1100. foreach ($shop as $v)
  1101. {
  1102. $d = $this->fullorder->find_count("shop = '".$v['id']."' and dtime > '".($t-$time*24*3600)."' and dtime < '".$t."' and (state = '207' or state = '216')");
  1103. $bfb = ($d==0)?0:round(($d / $znum) * 100, 2);
  1104. $data[] = array('value'=>$bfb,'name'=>$v['shopname'].' '.$bfb."%",'itemStyle'=>array('color'=>$color[$j]));
  1105. $n = array();$t_list = array();
  1106. for($i=0;$i<$time;$i++)
  1107. {
  1108. if($i == 0)
  1109. {
  1110. $s = date("Ymd",time());
  1111. }
  1112. else
  1113. {
  1114. $s = date("Ymd",time()-($i*24*3600));
  1115. }
  1116. $t_list[] = date("m-d",time()-($i*24*3600));
  1117. $n[] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".$s."' and (state = '207' or state = '216')");
  1118. }
  1119. $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).'%');
  1120. $j++;
  1121. }
  1122. $list = (array_reverse($list));
  1123. echo json_encode(array('data'=>($data),'list'=>$list,'t'=>(array_reverse($t_list)),'success'=>true));exit;
  1124. **/
  1125. }
  1126. $this->_Template('phone/p_user_shopfx', $this->data);
  1127. }
  1128. public function _shopfxlist()
  1129. {
  1130. $t = strtotime(date("Ymd", time())); //今天0点
  1131. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1132. $sid = '';
  1133. foreach ($shop as $value) {
  1134. $sid .= " shop = " . $value['id'] . " or";
  1135. }
  1136. $sid = " and (" . rtrim($sid, 'or') . ")";
  1137. $zt = array(7, 30);
  1138. $this->db->trans_begin();
  1139. foreach ($zt as $key => $time) {
  1140. $data = array();
  1141. $list = array();
  1142. foreach ($shop as $v) {
  1143. $n = array();
  1144. $t_list = array();
  1145. for ($i = 1; $i < $time; $i++) {
  1146. if ($i == 0) {
  1147. $s = date("Ymd", time());
  1148. } else {
  1149. $s = date("Ymd", time() - ($i * 24 * 3600));
  1150. }
  1151. $t_list[] = date("m-d", time() - ($i * 24 * 3600));
  1152. $n[] = $this->fullorder->find_count("shop = '" . $v['id'] . "' and gtime = '" . $s . "' and (state = '207' or state = '216')");
  1153. }
  1154. $list[$v['id']] = array_reverse($n);
  1155. }
  1156. $this->allocation->save(array('content' => json_encode($list)), $key + 1);
  1157. }
  1158. if ($this->db->trans_status() === FALSE) {
  1159. $this->db->trans_rollback();
  1160. echo 'orver';
  1161. } else {
  1162. $this->db->trans_commit();
  1163. echo 'ok';
  1164. }
  1165. }
  1166. public function _apple()
  1167. {
  1168. $this->_Template('phone/p_user_apple', $this->data);
  1169. }
  1170. //退出
  1171. public function _tc()
  1172. {
  1173. $this->session->sess_destroy();
  1174. header("Location:/");
  1175. }
  1176. public function _tjadd()
  1177. {
  1178. $pdtime = date('Y-m-d-H', time());
  1179. //if(is_file("./data/tj/".$pdtime.".txt"))
  1180. if (is_file("./data/tj/" . $pdtime . ".txt")) {
  1181. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  1182. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  1183. fclose($myfile);
  1184. $bc = json_decode($bc, true);
  1185. $zzt = array($bc['zzt'][0], $bc['zzt'][1]);
  1186. } else {
  1187. /** 暂时不需要了
  1188. //柱状图数据
  1189. $i = 0;
  1190. $data = array();$sndata1 = array();$sndata2 = array();$sndata3 = array();
  1191. $sj = array('01','02','03','04','05','06','07','08','09','10','11','12');
  1192. foreach ($sj as $k=>$v)
  1193. {
  1194. $i++;
  1195. $dlz1 = $this->fullorder->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1196. $smt1 = $this->fullordersmt->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1197. $m1 = sprintf("%01.2f",array_sum(array_column($dlz1,'shouldmoney'))+array_sum(array_column($smt1,'shouldmoney')));
  1198. $dlz2 = $this->fullorder->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1199. $smt2 = $this->fullordersmt->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1200. $m2 = sprintf("%01.2f",array_sum(array_column($dlz2,'shouldmoney'))+array_sum(array_column($smt2,'shouldmoney')));
  1201. $dlz3 = $this->fullorder->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1202. $smt3 = $this->fullordersmt->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1203. $m3 = sprintf("%01.2f",array_sum(array_column($dlz3,'shouldmoney'))+array_sum(array_column($smt3,'shouldmoney')));
  1204. $sndata1[$i] = $m3;
  1205. $sndata2[12+$i] = $m2;
  1206. $sndata3[24+$i] = $m1;
  1207. $data[] = array($v,$m1,$m2,$m3);
  1208. }
  1209. $sndata = array_merge($sndata1,$sndata2,$sndata3);
  1210. $zzt = array($data,$sndata);
  1211. //柱状图结束
  1212. **/
  1213. }
  1214. //详情内容
  1215. $dt = 0;
  1216. $user = $this->user->get_api($_SESSION['api']);
  1217. $usp = $user;
  1218. $fgshop = "";
  1219. $sid = "";
  1220. $user = explode('|', trim($user['shop'], '|'));
  1221. foreach ($user as $value) {
  1222. $fgshop .= " shop = " . $value . " or";
  1223. $sid .= " id = " . $value . " or";
  1224. }
  1225. $tm = strtotime(date("Ymd"), time());
  1226. $usat = $tm;
  1227. //$molist = array('0','1','2d');
  1228. $molist = array('0', '1');
  1229. $zqtime = array(259200, 345600, 691200, 2678400, 7862400, 31622400);
  1230. //time开始
  1231. $zqtdata = array();
  1232. foreach ($molist as $vval) {
  1233. $where = "";
  1234. $source = $vval;
  1235. if ($source == '2d') {
  1236. $where = " and source >= '2'";
  1237. } else if ($source != '0') {
  1238. $where = " and source = '$source'";
  1239. }
  1240. foreach ($zqtime as $value) {
  1241. $zdt = $value;
  1242. $k = $zdt;
  1243. $tab = 1;
  1244. //$start = '2018-10-15';
  1245. //$end = '2018-11-26';
  1246. //$tim = strtotime($start);
  1247. //$day = $time/(3600*24);
  1248. if ($tab == '1') {
  1249. if ($zdt >= 691200) {
  1250. $k = $usat - $k - $k;
  1251. $j = $usat;
  1252. $n = ($j - $k) / (24 * 3600);
  1253. } else {
  1254. $n = 2;
  1255. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  1256. }
  1257. } else {
  1258. $timedata = explode('|', $zdt);
  1259. $ktime = strtotime($timedata[0]);
  1260. $jtime = strtotime($timedata[1]);
  1261. $ktime = $ktime - ($jtime - $ktime);
  1262. $k = $ktime;
  1263. $j = $jtime;
  1264. $n = ($j - $k) / (24 * 3600);
  1265. $usat = $jtime;
  1266. $tm = $jtime;
  1267. $zdt = $jtime - $ktime;
  1268. }
  1269. $time = array();
  1270. $timeold = array();
  1271. $stime = array();
  1272. $dlznum = array();
  1273. $smtnum = array();;
  1274. $ttnum = array();
  1275. $ymoney = array();
  1276. $money = array();
  1277. $dlzmoney = array();
  1278. $smtmoney = array();
  1279. $ttmoney = array();
  1280. $dlzmoneyb = array();
  1281. $smtmoneyb = array();
  1282. $ttmoneyb = array();
  1283. $dlzsl = 0;
  1284. $dlzje = 0;
  1285. $dlzssje = 0;
  1286. $smtsl = 0;
  1287. $smtje = 0;
  1288. $smtssje = 0;
  1289. $ttsl = 0;
  1290. $ttje = 0;
  1291. $ttssje = 0;
  1292. $shopdata = array();
  1293. $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'");
  1294. foreach ($ys as $v) {
  1295. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  1296. }
  1297. for ($i = 1; $i < $n; $i++) {
  1298. //近7天时间
  1299. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1300. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1301. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1302. $time[] = date('m-d', $t);
  1303. $ct = strtotime(date('Ymd', $t));
  1304. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1305. $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');
  1306. $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');
  1307. $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');
  1308. $ab[] = $dlz;
  1309. //数量及金额开始
  1310. $dlznum[] = count($dlz);
  1311. $smtnum[] = count($smt);
  1312. $ttnum[] = count($smt);
  1313. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1314. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1315. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1316. /**
  1317. //提出退款关闭等信息的实收金额
  1318. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1319. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1320. //提出退款关闭等信息的实收金额
  1321. **/
  1322. //实收金额
  1323. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  1324. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  1325. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  1326. //实收金额
  1327. //补/退原额
  1328. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  1329. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  1330. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  1331. //补/退原额
  1332. $dlzmoney[] = $dlzm;
  1333. $smtmoney[] = $smtm;
  1334. $ttmoney[] = $ttm;
  1335. $dlzsl += count($dlz);
  1336. $dlzje += $dlzm;
  1337. $smtsl += count($smt);
  1338. $smtje += $smtm;
  1339. $ttsl += count($tt);
  1340. $ttje += $ttm;
  1341. /**
  1342. //减去的实收金额
  1343. $dlzssje += $dlzm+$dlzmss;
  1344. $smtssje += $smtm+$smtmss;
  1345. **/
  1346. //实收和补/退
  1347. $dlzssje += $dlzmss + $dlzbty;
  1348. $smtssje += $smtmss + $smtbty;
  1349. $ttssje += $ttmss + $ttbty;
  1350. //数量及金额结束
  1351. $sd = array_merge($dlz, $smt, $tt);
  1352. foreach ($sd as $v) {
  1353. if (isset($shopdata[$v['shop']])) {
  1354. $shopdata[$v['shop']]['num'] += 1;
  1355. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  1356. $shopdata[$v['shop']]['tmoney'] += $v['budget'] + $v['refundy'];
  1357. }
  1358. }
  1359. } else if ($n > 13 && $i <= $n / 2) {
  1360. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1361. $timeold[] = date('m-d', $t);
  1362. $ct = strtotime(date('Ymd', $t));
  1363. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1364. $dlz = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1365. $smt = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1366. $tt = $this->fullordertt->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1367. //数量及金额开始
  1368. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1369. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1370. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1371. $dlzmoneyb[] = $dlzm;
  1372. $smtmoneyb[] = $smtm;
  1373. $ttmoneyb[] = $ttm;
  1374. //数量及金额结束
  1375. }
  1376. }
  1377. foreach ($shopdata as $k => $v) {
  1378. $sn = $this->shop->read($k);
  1379. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  1380. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  1381. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  1382. $shopdata[$k]['name'] = $sn['shopname'];
  1383. $shopdata[$k]['b'] = $sn['type'];
  1384. $shopdata[$k]['id'] = $sn['id'];
  1385. }
  1386. $shopdata = array_values($shopdata);
  1387. //$sycp=array();
  1388. /**
  1389. //根据所选时间产品排行开始
  1390. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1391. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1392. **/
  1393. /**
  1394. //昨日产品排行开始
  1395. $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');
  1396. $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');
  1397. $rows = array_merge($dlzlist,$smtlist);
  1398. foreach ($rows as $v)
  1399. {
  1400. $number = explode('|',trim($v['whlabel'],'|'));
  1401. $or = explode(';',trim($v['fpdata'],';'));
  1402. $i=0;
  1403. foreach ($or as $va)
  1404. {
  1405. $ord = explode('|',$va);
  1406. $orod = explode(',',$ord[0]);
  1407. $numberod = explode('-',$number[$i]);
  1408. if(!isset($orod[1]))
  1409. {
  1410. continue;
  1411. }
  1412. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  1413. {
  1414. //$sycp[$orod[1]][0] += 1;//统计多少单
  1415. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  1416. $sycp[$orod[1]][1] += 0;//价格
  1417. }
  1418. else
  1419. {
  1420. if(isset($numberod[1]))
  1421. {
  1422. $typeclass = $this->typeclass->read($orod['0']);
  1423. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  1424. }
  1425. }
  1426. $i++;
  1427. }
  1428. }
  1429. arsort($sycp);
  1430. $sycp = array_values($sycp);
  1431. $sycp = array_slice($sycp,0,10);
  1432. //产品排行结束
  1433. **/
  1434. //当时实时数据结束
  1435. $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昨日产品数据
  1436. }
  1437. }
  1438. //time结束
  1439. //zhcx开始
  1440. $zhcxdata = array();
  1441. foreach ($molist as $vval) {
  1442. $where = "";
  1443. $source = $vval;
  1444. if ($source == '2d') {
  1445. $where = " and source >= '2'";
  1446. } else if ($source != '0') {
  1447. $where = " and source = '$source'";
  1448. }
  1449. foreach ($zqtime as $value) {
  1450. $zdt = $value;
  1451. $k = $zdt;
  1452. $tab = 1;
  1453. //$customer = $this->customer->find_all("shop !=''",'num,zhcx');
  1454. //$customerkey = array_column($customer,'zhcx');
  1455. //$customer= array_combine($customerkey,$customer);
  1456. //$customersmt = $this->customersmt->find_all("shop !=''",'num,zhcx');
  1457. //$customersmtkey = array_column($customersmt,'zhcx');
  1458. //$customersmt= array_combine($customersmtkey,$customersmt);
  1459. //$customertt = $this->customertt->find_all("shop !=''",'num,zhcx');
  1460. //$customerttkey = array_column($customertt,'zhcx');
  1461. //$customertt= array_combine($customerttkey,$customertt);
  1462. if ($tab == '1') {
  1463. if ($zdt >= 691200) {
  1464. $k = $usat - $k - $k;
  1465. $j = $usat;
  1466. $n = ($j - $k) / (24 * 3600);
  1467. } else {
  1468. $n = 2;
  1469. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  1470. }
  1471. } else {
  1472. $timedata = explode('|', $zdt);
  1473. $ktime = strtotime($timedata[0]);
  1474. $jtime = strtotime($timedata[1]);
  1475. $ktime = $ktime - ($jtime - $ktime);
  1476. $k = $ktime;
  1477. $j = $jtime;
  1478. $n = ($j - $k) / (24 * 3600);
  1479. $usat = $jtime;
  1480. }
  1481. $time = array();
  1482. $timeold = array();
  1483. $stime = array();
  1484. $dlznum = array();
  1485. $smtnum = array();
  1486. $ttnum = array();
  1487. $ymoney = array();
  1488. $money = array();
  1489. $dlzmoneyb = array();
  1490. $smtmoneyb = array();
  1491. $ttmoneyb = array();
  1492. $zkh = array();
  1493. $dlzsl = 0;
  1494. $dlzje = 0;
  1495. $dlzssje = 0;
  1496. $smtsl = 0;
  1497. $smtje = 0;
  1498. $smtssje = 0;
  1499. $ttsl = 0;
  1500. $ttje = 0;
  1501. $ttssje = 0;
  1502. $shopdata = array();
  1503. $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'");
  1504. foreach ($ys as $v) {
  1505. $shopdata[$v['id']] = array('id' => $v['id'], 'b' => $v['type'], 'fdl' => 0, 'chl' => 0, 'num' => 0, 'fgl' => 0);
  1506. $zkh[$v['id']] = array();
  1507. }
  1508. for ($i = 1; $i < $n; $i++) {
  1509. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1510. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1511. $time[] = date('m-d', $t);
  1512. $ct = strtotime(date('Ymd', $t));
  1513. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1514. $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');
  1515. $dlzemail = $this->fullorder->find_all("dtime <= " . $ctj . $where . " and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'shop,email');
  1516. $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');
  1517. $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');
  1518. //数量及金额结束
  1519. $sd = array_merge($dlz, $smt, $tt);
  1520. $fgldata = array();
  1521. foreach ($sd as $v) {
  1522. /**
  1523. $array = array(
  1524. 0 => array('email' => 123, 'id' => 1),
  1525. 1 => array('email' => 321, 'id' => 2),
  1526. 2 => array('email' => 123, 'id' => 3),
  1527. 3 => array('email' => 123, 'id' => 3)
  1528. );
  1529. // 使用 array_filter 筛选满足多个条件的元素
  1530. $result = array_filter($array, function($item) {
  1531. return $item['email'] === 123 && $item['id'] === 3;
  1532. });
  1533. // 计算满足条件的数量
  1534. $count = count($result);
  1535. echo "满足条件 (email = 123 且 id = 3) 的数量是:$count";
  1536. **/
  1537. /** 独立站查customer方法 弃用
  1538. if(isset($v['email']))
  1539. {
  1540. if(!isset($fgldata[$v['shop'].'-'.$v['email']]))
  1541. {
  1542. $fgldata[$v['shop'].'-'.$v['email']] = 0;
  1543. }
  1544. else
  1545. {
  1546. $fgldata[$v['shop'].'-'.$v['email']] += 1;
  1547. }
  1548. $zkh[$v['shop']][$v['email']] = array();
  1549. }
  1550. **/
  1551. /** 速卖通
  1552. else
  1553. {
  1554. if(!isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1555. {
  1556. $fgldata[$v['shop'].'-'.$v['userid']] = 0;
  1557. }
  1558. else
  1559. {
  1560. $fgldata[$v['shop'].'-'.$v['userid']] += 1;
  1561. }
  1562. $zkh[$v['shop']][$v['userid']] = array();
  1563. }
  1564. **/
  1565. }
  1566. foreach ($sd as $v) {
  1567. //避免由于作用域引起的问题
  1568. $tmp_v = $v;
  1569. $fdl_result = array_filter($dlz, function ($item) use ($tmp_v) {
  1570. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1571. return false;
  1572. } else {
  1573. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1574. }
  1575. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1576. });
  1577. $fdl = count($fdl_result) > 1 ? 1 : 0; //返单
  1578. $chl_result = array_filter($dlz, function ($item) use ($tmp_v) {
  1579. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1580. return false;
  1581. } else {
  1582. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1583. }
  1584. //return $item['email'] === $tmp_v['email'] && $item['shop'] !== $tmp_v['email'];
  1585. });
  1586. $chl = count($chl_result) > 1 ? 1 : 0; //重合
  1587. $fgl_result = array_filter($dlzemail, function ($item) use ($tmp_v) {
  1588. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1589. return false;
  1590. } else {
  1591. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1592. }
  1593. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1594. });
  1595. $fgl = count($fgl_result) > 1 ? 1 : 0; //复购
  1596. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl'] + $fdl;
  1597. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl'] + $chl;
  1598. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl'] + $fgl;
  1599. $shopdata[$v['shop']]['num'] += 1;
  1600. /**
  1601. $chl = 0;
  1602. if(isset($shopdata[$v['shop']]))
  1603. {
  1604. if(isset($v['email']))
  1605. {
  1606. if(isset($customer[$v['shop'].'-'.$v['email']]['num']))
  1607. {
  1608. $fdl = $customer[$v['shop'].'-'.$v['email']]['num']>1?1:0;
  1609. }
  1610. else
  1611. {
  1612. $fdl = 0;
  1613. }
  1614. foreach ($ys as $vv)
  1615. {
  1616. if($vv['id'] != $v['shop'] && isset($customer[$vv['id'].'-'.$v['email']]))
  1617. {
  1618. $chl = 1;
  1619. }
  1620. }
  1621. if(isset($fgldata[$v['shop'].'-'.$v['email']]))
  1622. {
  1623. $fgl = $fgldata[$v['shop'].'-'.$v['email']]>0?1:0;
  1624. }
  1625. else
  1626. {
  1627. $fgl = 0;
  1628. }
  1629. }
  1630. else
  1631. {
  1632. if(isset($customersmt[$v['shop'].'-'.$v['userid']]['num']))
  1633. {
  1634. $fdl = $customersmt[$v['shop'].'-'.$v['userid']]['num']>1?1:0;
  1635. }
  1636. else
  1637. {
  1638. $fdl = 0;
  1639. }
  1640. foreach ($ys as $vv)
  1641. {
  1642. if($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'].'-'.$v['userid']]))
  1643. {
  1644. $chl = 1;
  1645. }
  1646. }
  1647. if(isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1648. {
  1649. $fgl = $fgldata[$v['shop'].'-'.$v['userid']]>0?1:0;
  1650. }
  1651. else
  1652. {
  1653. $fgl = 0;
  1654. }
  1655. }
  1656. }
  1657. **/
  1658. }
  1659. }
  1660. }
  1661. foreach ($shopdata as $k => $v) {
  1662. $shopdata[$k]['fdl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['fdl'] / $v['num'] * 100)) . '%';
  1663. $shopdata[$k]['chl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['chl'] / $v['num'] * 100)) . '%';
  1664. $shopdata[$k]['fgl'] = count($zkh[$v['id']]) == '0' ? 0 : sprintf("%01.2f", ($v['fgl'] / count($zkh[$v['id']]) * 100)) . '%';
  1665. }
  1666. $shopdata = array_values($shopdata);
  1667. $zhcxdata[$vval][$value] = array('shopdata' => $shopdata, 'success' => true);
  1668. }
  1669. }
  1670. //zhcx结束
  1671. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "w") or die("Unable to open file!");
  1672. $txt = json_encode(array('zzt' => $zzt, 'tj' => $zqtdata, 'zhcx' => $zhcxdata));
  1673. fwrite($myfile, $txt);
  1674. fclose($myfile);
  1675. echo 1;
  1676. }
  1677. }