User.php 66 KB

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