User.php 69 KB

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