User.php 68 KB

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