User.php 69 KB

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