User.php 69 KB

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