User.php 69 KB

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