User.php 68 KB

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