User.php 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306
  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 if($arg == 'statistics_hb'){
  71. $this->_statistics_hb();
  72. }else if($arg == 'statistics_tb'){
  73. $this->_statistics_tb();
  74. }
  75. else if($arg == 'user_lvceshi'){
  76. $this->_user_lvceshi();
  77. }
  78. else {
  79. $this->_index();
  80. }
  81. }
  82. //首页
  83. public function _index()
  84. {
  85. if(empty($_SESSION['api'])){
  86. exit('No direct script access allowed');
  87. }
  88. $user = $this->user->get_api($_SESSION['api']);
  89. $this->data['user'] = $user; //登录的用户信息
  90. $power = $this->power->read($user['power']);
  91. $power = $power['powerid'];
  92. //$power = explode('|',trim($power,'|'));字符串转数组
  93. $dataa = $this->nav->find_all('type=1', '*', 'px asc');
  94. $datab = $this->nav->find_all('type=2', '*', 'px asc');
  95. $datac = $this->nav->find_all('type=3', '*', 'sort asc,px desc');
  96. $an = array();
  97. foreach ($dataa as $key => $value) {
  98. foreach ($datab as $ke => $va) {
  99. if ($va['class'] == $value['id']) {
  100. foreach ($datac as $k => $v) {
  101. if ($v['class'] == $va['id']) {
  102. if (strstr($power, '|' . $v['id'] . '|') == true) {
  103. $va['cn'][] = $v;
  104. }
  105. }
  106. }
  107. if (strstr($power, '|' . $va['id'] . '|') == true) {
  108. $value['bn'][] = $va;
  109. }
  110. }
  111. } //循环出二级导航航
  112. if (strstr($power, '|' . $value['id'] . '|') == true) {
  113. $an[] = $value;
  114. }
  115. }
  116. //print_r($an);
  117. $this->data['data'] = $an;
  118. $this->data['ip'] = $this->input->ip_address();
  119. $this->data['power'] = $user['power'];
  120. $this->data['link'] = $user['link'];
  121. if (stripos($_SERVER['HTTP_HOST'], 'a.') !== false) {
  122. $url = 'b';
  123. } else {
  124. $url = 'a';
  125. }
  126. $this->data['url'] = $url;
  127. $this->_Template('user', $this->data);
  128. }
  129. //管理
  130. public function _data()
  131. {
  132. $user = $this->user->get_api($_SESSION['api']);
  133. $post = $this->input->post(NULL, TRUE);
  134. if (isset($post['page'])) {
  135. $page = $this->input->post('page', true);
  136. $perpage = $this->input->post('perpage', true);
  137. $power = $this->input->post('power', true);
  138. $name = $this->input->post('name', true);
  139. $userid = $this->input->post('userid', true);
  140. $type = $this->input->post('type', true);
  141. $where = "own='" . $user['own'] . "'";
  142. if ($power) {
  143. $where .= " and power = '$power' ";
  144. }
  145. if ($name) {
  146. $where .= " and name like '%$name%' ";
  147. }
  148. if ($userid) {
  149. $where .= " and userid like '%$userid%' ";
  150. }
  151. if ($type) {
  152. $where .= " and type = '$type' ";
  153. }
  154. //数据排序
  155. $order_str = "id asc";
  156. if (empty($page)) {
  157. $start = 0;
  158. $perpage = 1;
  159. } else {
  160. $start = ($page - 1) * $perpage;
  161. }
  162. //取得信息列表
  163. //$info_list = $this->user->find_all($where,'id,name,userid,power,shoptext,purchasetext,warehousetext,stafftext,transfertext,type,lasttime',$order_str,$start,$perpage);
  164. $info_list = $this->user->find_all($where, 'id,name,userid,power,shoptext,purchasetext,warehousetext,transfertext,type,lasttime', $order_str, $start, $perpage);
  165. //格式化数据
  166. foreach ($info_list as $key => $value) {
  167. if ($value['type'] == 1) {
  168. if (empty($value['lasttime'])) {
  169. $info_list[$key]['type'] = '正常';
  170. } else {
  171. $info_list[$key]['type'] = '正常' . "<br>最后操作时间:<br>" . date("Y-m-d", $value['lasttime']);
  172. }
  173. } else {
  174. $info_list[$key]['type'] = '停用';
  175. }
  176. $power = $this->power->read($value['power']);
  177. $info_list[$key]['power'] = $power['powername'];
  178. unset($info_list[$key]['lasttime']);
  179. }
  180. $total = $this->user->find_count($where);
  181. $pagenum = ceil($total / $perpage);
  182. $over = $total - ($start + $perpage);
  183. $rows = array('total' => $total, 'over' => $over, 'pagenum' => $pagenum, 'rows' => ($info_list));
  184. echo json_encode($rows);
  185. exit;
  186. }
  187. $power = $this->power->find_all("1 = 1","*","sort asc,id asc");
  188. $this->data['power'] = $power;
  189. $this->_Template('user_data', $this->data);
  190. }
  191. //添加
  192. public function _add()
  193. {
  194. $user = $this->user->get_api($_SESSION['api']);
  195. $post = $this->input->post(NULL, TRUE);
  196. if (isset($post['userid'])) {
  197. $post['userid'] = $this->input->post('userid', true);
  198. $userpass = $this->input->post('userpass', true);
  199. $post['userpass'] = sha1($userpass);
  200. $post['shop'] = $this->input->post('shop', true);
  201. $post['shoptext'] = $this->input->post('shoptext', true);
  202. $post['excelshop'] = $this->input->post('excelshop', true);
  203. $post['excelshoptext'] = $this->input->post('excelshoptext', true);
  204. $post['purchase'] = $this->input->post('purchase', true);
  205. $post['purchasetext'] = $this->input->post('purchasetext', true);
  206. $post['warehouse'] = $this->input->post('warehouse', true);
  207. $post['warehousetext'] = $this->input->post('warehousetext', true);
  208. $post['customer'] = $this->input->post('customer', true);
  209. $post['staff'] = empty($this->input->post('staff', true))?0:$this->input->post('staff', true);
  210. $post['stafftext'] = $this->input->post('stafftext', true);
  211. $post['power'] = $this->input->post('power', true);
  212. $post['name'] = $this->input->post('name', true);
  213. $post['phone'] = $this->input->post('phone', true);
  214. $post['type'] = $this->input->post('type', true);
  215. $post['html'] = $this->input->post('html', true);
  216. $post['own'] = $user['own'];
  217. $post['api'] = sha1(rand(1000000, 9999999));
  218. unset($post['id']);
  219. if ($this->user->insert($post)) {
  220. echo json_encode(array('msg' => '添加成功', 'success' => true));
  221. exit;
  222. } else {
  223. echo json_encode(array('msg' => '添加失败,请重试', 'success' => false));
  224. exit;
  225. }
  226. }
  227. $power = $this->power->find_all("1 = 1","*","sort asc,id asc");
  228. $this->data['power'] = $power;
  229. $this->_Template('user_add', $this->data);
  230. }
  231. //修改
  232. public function _edit($arg_array)
  233. {
  234. $post = $this->input->post(NULL, TRUE);
  235. if (isset($post['id'])) {
  236. $id = $this->input->post('id', true);
  237. $post['userid'] = $this->input->post('edituserid', true);
  238. $userpass = $this->input->post('edituserpass', true);
  239. $post['shop'] = $this->input->post('shop', true);
  240. $post['shoptext'] = $this->input->post('shoptext', true);
  241. $post['excelshop'] = $this->input->post('excelshop', true);
  242. $post['excelshoptext'] = $this->input->post('excelshoptext', true);
  243. $post['purchase'] = $this->input->post('purchase', true);
  244. $post['purchasetext'] = $this->input->post('purchasetext', true);
  245. $post['warehouse'] = $this->input->post('warehouse', true);
  246. $post['warehousetext'] = $this->input->post('warehousetext', true);
  247. $post['customer'] = $this->input->post('customer', true);
  248. $post['staff'] = $this->input->post('staff', true);
  249. $post['stafftext'] = $this->input->post('stafftext', true);
  250. $post['power'] = $this->input->post('power', true);
  251. $post['name'] = $this->input->post('name', true);
  252. $post['phone'] = $this->input->post('phone', true);
  253. $post['type'] = $this->input->post('type', true);
  254. $post['html'] = $this->input->post('html', true);
  255. $ud = $this->user->read($id);
  256. if ($userpass != NULL) {
  257. $post['userpass'] = sha1($userpass);
  258. $post['api'] = sha1(rand(1000000, 9999999));
  259. } else {
  260. $post['userpass'] = $ud['userpass'];
  261. }
  262. if ($this->user->save($post, $id)) {
  263. echo json_encode(array('msg' => '修改成功', 'success' => true));
  264. exit;
  265. } else {
  266. echo json_encode(array('msg' => '修改失败,请重试', 'success' => false));
  267. exit;
  268. }
  269. }
  270. $arg_array = $arg_array[0];
  271. $user = $this->user->read($arg_array);
  272. $this->data['user'] = $user;
  273. $power = $this->power->find_all("1 = 1","*","sort asc,id asc");
  274. $this->data['power'] = $power;
  275. $this->_Template('user_edit', $this->data);
  276. }
  277. //删除
  278. public function _del()
  279. {
  280. $post = $this->input->post(NULL, TRUE);
  281. if (isset($post['s'])) {
  282. $id_arr = $this->input->post('s');
  283. $id_arr = explode(',', $id_arr);
  284. if (!$id_arr) {
  285. echo json_encode(array('msg' => '参数错误!', 'success' => false));
  286. exit;
  287. }
  288. //循环删除记录
  289. foreach ($id_arr as $v) {
  290. $this->user->remove($v);
  291. }
  292. echo json_encode(array('del' => $id_arr, 'msg' => '删除记录成功!', 'success' => true));
  293. }
  294. }
  295. //默认页
  296. public function _default()
  297. {
  298. /**
  299. $order = $this->order->get_w();
  300. $order = count($order);//查询订单未处理数量
  301. $message = $this->message->get_w();
  302. $message = count($message);//查询留言未处理数量
  303. $this->_Template('default',$this->data);
  304. **/
  305. $dt = 0;
  306. if (isset($_SESSION['api'])) {
  307. $user = $this->user->get_api($_SESSION['api']);
  308. $usp = $user;
  309. $fgshop = "";
  310. $sid = "";
  311. $user = explode('|', trim($user['shop'], '|'));
  312. foreach ($user as $value) {
  313. if ($value != '18' && $value != '19' && $value != '12' && $value != '13' && $value != '9' && $value != '15' && $value != '27') {
  314. $fgshop .= " shop = " . $value . " or";
  315. }
  316. $sid .= " id = " . $value . " or";
  317. }
  318. if(empty($fgshop)){
  319. $this->logic_ding->sendToDing("用户统计页面的店铺为空,请检查!".json_encode($user));
  320. }
  321. }
  322. $post = $this->input->post(NULL, TRUE);
  323. if (isset($post['timek'])) {
  324. //$start = '2018-10-15';
  325. //$end = '2018-11-26';
  326. //$tim = strtotime($start);
  327. //$day = $time/(3600*24);
  328. $timek = $this->input->post('timek', true);
  329. $timej = $this->input->post('timej', true);
  330. $k = strtotime($timek) - 24 * 3600; //少一天为增加选择开始天时间
  331. $j = strtotime($timej);
  332. $n = ($j - $k) / (24 * 3600);
  333. if ($n < 1) {
  334. $n = 1;
  335. }
  336. $time = array();
  337. $stime = array();
  338. $num = array();
  339. $ymoney = array();
  340. $money = array();
  341. for ($i = 1; $i < $n; $i++) {
  342. //近7天时间
  343. $t = $j - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  344. $time[] = date('Y-m-d', $t);
  345. $ct = strtotime(date('Ymd', $t));
  346. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  347. $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');
  348. $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');
  349. $dsmt = array();
  350. $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');
  351. $d = array_merge($dlz, $dsmt, $tt);
  352. $num[] = count($d);
  353. $ymoney[] = sprintf("%01.2f", array_sum(array_column($d, 'budget')));
  354. $money[] = sprintf("%01.2f", array_sum(array_column($d, 'shouldmoney')));
  355. }
  356. $snuz = $this->fullorder->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  357. $snuz += $this->fullordersmt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  358. $snuz += $this->fullordertt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  359. $lnuz = $this->fullorder->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待出库
  360. $lnuz += $this->fullordersmt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待出库
  361. $lnuz += $this->fullordertt->find_count('dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待出库
  362. $snu = $this->fullorder->find_count('reviewtime = 0 and dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  363. $snu += $this->fullordersmt->find_count('reviewtime = 0 and dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  364. $snu += $this->fullordertt->find_count('reviewtime = 0 and dtime >=' . ($k + 24 * 3600) . ' and dtime <=' . $j . ' and (' . rtrim($fgshop, 'or') . ')'); //待处理
  365. $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') . ')'); //待出库
  366. $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') . ')'); //待出库
  367. $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') . ')'); //待出库
  368. 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));
  369. exit;
  370. }
  371. $this->_Template('user_default', $this->data);
  372. }
  373. public function _zzt()
  374. {
  375. exit;
  376. if (isset($_SESSION['api'])) {
  377. $user = $this->user->get_api($_SESSION['api']);
  378. $usp = $user;
  379. $fgshop = "";
  380. $sid = "";
  381. $user = explode('|', trim($user['shop'], '|'));
  382. foreach ($user as $value) {
  383. $fgshop .= " shop = " . $value . " or";
  384. $sid .= " id = " . $value . " or";
  385. }
  386. }
  387. $data = array();
  388. $sntime = array();
  389. $sndata1 = array();
  390. $sndata2 = array();
  391. $sndata3 = array();
  392. $sj = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
  393. for ($i = 0; $i < 3; $i++) {
  394. foreach ($sj as $v) {
  395. $sntime[] = date("Y") - 2 + $i . '-' . $v;
  396. }
  397. }
  398. $pdtime = date('Y-m-d-H', time());
  399. if (is_file("./data/tj/" . $pdtime . ".txt")) {
  400. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  401. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  402. fclose($myfile);
  403. $bc = json_decode($bc, true);
  404. $data = $bc['zzt'][0];
  405. $sndata = $bc['zzt'][1];
  406. } else {
  407. $i = 0;
  408. foreach ($sj as $k => $v) {
  409. $i++;
  410. $dlz1 = $this->fullorder->find_all("gtime > '" . date("Y") . $v . "00' and gtime < '" . date("Y") . $v . "32'", 'shouldmoney');
  411. $smt1 = $this->fullordersmt->find_all("gtime > '" . date("Y") . $v . "00' and gtime < '" . date("Y") . $v . "32'", 'shouldmoney');
  412. $m1 = sprintf("%01.2f", array_sum(array_column($dlz1, 'shouldmoney')) + array_sum(array_column($smt1, 'shouldmoney')));
  413. $dlz2 = $this->fullorder->find_all("gtime > '" . (date("Y") - 1) . $v . "00' and gtime < '" . (date("Y") - 1) . $v . "32'", 'shouldmoney');
  414. $smt2 = $this->fullordersmt->find_all("gtime > '" . (date("Y") - 1) . $v . "00' and gtime < '" . (date("Y") - 1) . $v . "32'", 'shouldmoney');
  415. $m2 = sprintf("%01.2f", array_sum(array_column($dlz2, 'shouldmoney')) + array_sum(array_column($smt2, 'shouldmoney')));
  416. $dlz3 = $this->fullorder->find_all("gtime > '" . (date("Y") - 2) . $v . "00' and gtime < '" . (date("Y") - 2) . $v . "32'", 'shouldmoney');
  417. $smt3 = $this->fullordersmt->find_all("gtime > '" . (date("Y") - 2) . $v . "00' and gtime < '" . (date("Y") - 2) . $v . "32'", 'shouldmoney');
  418. $m3 = sprintf("%01.2f", array_sum(array_column($dlz3, 'shouldmoney')) + array_sum(array_column($smt3, 'shouldmoney')));
  419. $sndata1[$i] = $m3;
  420. $sndata2[12 + $i] = $m2;
  421. $sndata3[24 + $i] = $m1;
  422. $data[] = array($v, $m1, $m2, $m3);
  423. }
  424. }
  425. $time = array(date("Y"), (date("Y") - 1), (date("Y") - 2));
  426. echo json_encode(array('data' => $data, 'time' => $time, 'sndata' => $sndata, 'sntime' => $sntime, 'success' => true));
  427. exit;
  428. }
  429. //默认页
  430. public function _statistics()
  431. {
  432. /**
  433. $order = $this->order->get_w();
  434. $order = count($order);//查询订单未处理数量
  435. $message = $this->message->get_w();
  436. $message = count($message);//查询留言未处理数量
  437. $this->_Template('default',$this->data);
  438. **/
  439. //date_default_timezone_set("Etc/GMT+8");
  440. $dt = 0;
  441. if (isset($_SESSION['api'])) {
  442. $user = $this->user->get_api($_SESSION['api']);
  443. $usp = $user;
  444. $fgshop = "";
  445. $sid = "";
  446. $user = explode('|', trim($user['shop'], '|'));
  447. foreach ($user as $value) {
  448. // 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')
  449. // {
  450. // $fgshop .= " shop = ".$value." or";
  451. // }
  452. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56,48])) {
  453. $fgshop .= " shop = " . $value . " or";
  454. }
  455. $sid .= " id = " . $value . " or";
  456. }
  457. }
  458. $post = $this->input->post(NULL, TRUE);
  459. $source = $this->input->post('source', true);
  460. $where = "";
  461. if ($source) {
  462. if ($source == '2d') {
  463. $where = " and source >= '2'";
  464. } else {
  465. $where = " and source = '$source'";
  466. }
  467. }
  468. $tm = strtotime(date("Ymd"), time());
  469. $usat = $tm;
  470. if (isset($post['zhcx'])) {
  471. $zdt = $this->input->post('time', true);
  472. $k = $zdt;
  473. $tab = $this->input->post('tab', true);
  474. $pdtime = date('Y-m-d-H', time());
  475. if (is_file("./data/tj/" . $pdtime . ".txt") && $tab == 1 && $zdt > 172800) {
  476. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  477. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  478. fclose($myfile);
  479. $bc = json_decode($bc, true);
  480. echo json_encode($bc['zhcx'][$source][$zdt]);
  481. exit;
  482. } else {
  483. $customer = $this->customer->find_all("shop !=''", 'num,zhcx');
  484. $customerkey = array_column($customer, 'zhcx');
  485. $customer = array_combine($customerkey, $customer);
  486. $customersmt = $this->customersmt->find_all("shop !=''", 'num,zhcx');
  487. $customersmtkey = array_column($customersmt, 'zhcx');
  488. $customersmt = array_combine($customersmtkey, $customersmt);
  489. //$start = '2018-10-15';
  490. //$end = '2018-11-26';
  491. //$tim = strtotime($start);
  492. //$day = $time/(3600*24);
  493. if ($tab == '1') {
  494. if ($zdt >= 691200) {
  495. $k = $usat - $k - $k;
  496. $j = $usat;
  497. $n = ($j - $k) / (24 * 3600);
  498. } else {
  499. $n = 2;
  500. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  501. }
  502. } else {
  503. $timedata = explode('|', $zdt);
  504. $ktime = strtotime($timedata[0]);
  505. $jtime = strtotime($timedata[1]);
  506. $ktime = $ktime - ($jtime - $ktime);
  507. $k = $ktime;
  508. $j = $jtime;
  509. $n = ($j - $k) / (24 * 3600);
  510. $usat = $jtime;
  511. }
  512. $time = array();
  513. $timeold = array();
  514. $stime = array();
  515. $dlznum = array();
  516. $smtnum = array();
  517. $ymoney = array();
  518. $money = array();
  519. $dlzmoneyb = array();
  520. $smtmoneyb = array();
  521. $ttmoneyb = array();
  522. $zkh = array();
  523. $dlzsl = 0;
  524. $dlzje = 0;
  525. $dlzssje = 0;
  526. $smtsl = 0;
  527. $smtje = 0;
  528. $smtssje = 0;
  529. $ttsl = 0;
  530. $ttje = 0;
  531. $ttssje = 0;
  532. $shopdata = array();
  533. $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' and id != '48'","*",'px asc');
  534. foreach ($ys as $v) {
  535. $shopdata[$v['id']] = array('id' => $v['id'], 'b' => $v['type'], 'fdl' => 0, 'chl' => 0, 'num' => 0, 'fgl' => 0);
  536. $zkh[$v['id']] = array();
  537. }
  538. for ($i = 1; $i < $n; $i++) {
  539. if ($n > 13 && $i > $n / 2 || $n < 14) {
  540. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  541. $time[] = date('m-d', $t);
  542. $ct = strtotime(date('Ymd', $t));
  543. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  544. $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');
  545. $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');
  546. $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');
  547. $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');
  548. //数量及金额结束
  549. $sd = array_merge($dlz, $smt, $tt,$amz);
  550. $fgldata = array();
  551. foreach ($sd as $v) {
  552. if (isset($v['email'])) {
  553. if (!isset($fgldata[$v['shop'] . '-' . $v['email']])) {
  554. $fgldata[$v['shop'] . '-' . $v['email']] = 0;
  555. } else {
  556. $fgldata[$v['shop'] . '-' . $v['email']] += 1;
  557. }
  558. $zkh[$v['shop']][$v['email']] = array();
  559. } else {
  560. if (!isset($fgldata[$v['shop'] . '-' . $v['userid']])) {
  561. $fgldata[$v['shop'] . '-' . $v['userid']] = 0;
  562. } else {
  563. $fgldata[$v['shop'] . '-' . $v['userid']] += 1;
  564. }
  565. $zkh[$v['shop']][$v['userid']] = array();
  566. }
  567. }
  568. foreach ($sd as $v) {
  569. $chl = 0;
  570. if (isset($shopdata[$v['shop']])) {
  571. if (isset($v['email'])) {
  572. if (isset($customer[$v['shop'] . '-' . $v['email']]['num'])) {
  573. $fdl = $customer[$v['shop'] . '-' . $v['email']]['num'] > 1 ? 1 : 0;
  574. } else {
  575. $fdl = 0;
  576. }
  577. foreach ($ys as $vv) {
  578. if ($vv['id'] != $v['shop'] && isset($customer[$vv['id'] . '-' . $v['email']])) {
  579. $chl = 1;
  580. }
  581. }
  582. if (isset($fgldata[$v['shop'] . '-' . $v['email']])) {
  583. $fgl = $fgldata[$v['shop'] . '-' . $v['email']] > 0 ? 1 : 0;
  584. } else {
  585. $fgl = 0;
  586. }
  587. } else {
  588. if (isset($customersmt[$v['shop'] . '-' . $v['userid']]['num'])) {
  589. $fdl = $customersmt[$v['shop'] . '-' . $v['userid']]['num'] > 1 ? 1 : 0;
  590. } else {
  591. $fdl = 0;
  592. }
  593. foreach ($ys as $vv) {
  594. if ($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'] . '-' . $v['userid']])) {
  595. $chl = 1;
  596. }
  597. }
  598. if (isset($fgldata[$v['shop'] . '-' . $v['userid']])) {
  599. $fgl = $fgldata[$v['shop'] . '-' . $v['userid']] > 0 ? 1 : 0;
  600. } else {
  601. $fgl = 0;
  602. }
  603. }
  604. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl'] + $fdl;
  605. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl'] + $chl;
  606. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl'] + $fgl;
  607. $shopdata[$v['shop']]['num'] += 1;
  608. }
  609. }
  610. }
  611. }
  612. foreach ($shopdata as $k => $v) {
  613. $shopdata[$k]['fdl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['fdl'] / $v['num'] * 100)) . '%';
  614. $shopdata[$k]['chl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['chl'] / $v['num'] * 100)) . '%';
  615. $shopdata[$k]['fgl'] = count($zkh[$v['id']]) == '0' ? 0 : sprintf("%01.2f", ($v['fgl'] / count($zkh[$v['id']]) * 100)) . '%';
  616. }
  617. $shopdata = array_values($shopdata);
  618. echo @json_encode(array('shopdata' => $shopdata, 'success' => true));
  619. exit;
  620. }
  621. }
  622. if (isset($post['time'])) {
  623. // 2026年09月22日 应要求修改
  624. //总金额 = 订单金额 + 补/退原额 实收金额 = 预估到账金额 +补/退净额
  625. $zdt = $this->input->post('time', true);
  626. $k = $zdt;
  627. $tab = $this->input->post('tab', true);
  628. $pdtime = date('Y-m-d-H', time());
  629. // if (is_file("./data/tj/" . $pdtime . ".txt") && $tab == 1 && $zdt > 172800) //前端改店内需要修改zdt 172800
  630. // {
  631. // $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  632. // $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  633. // fclose($myfile);
  634. // $bc = json_decode($bc, true);
  635. // echo json_encode($bc['tj'][$source][$zdt]);
  636. // exit;
  637. // } else {
  638. //$start = '2018-10-15';
  639. //$end = '2018-11-26';
  640. //$tim = strtotime($start);
  641. //$day = $time/(3600*24);
  642. if ($tab == '1') {
  643. $this->_statistics_sjc($fgshop,$zdt,$where,$k,$usat);
  644. } else {
  645. $this->_statistics_sjd($fgshop,$zdt,$where,$k,$usat);
  646. }
  647. }
  648. //}
  649. if (isset($post['sstime'])) {
  650. $shop = $this->input->post('shop', true);
  651. $zdtime = $usat;
  652. //当时实时数据开始
  653. if (!$shop) {
  654. $sssl = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  655. $ssje = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . $where, 'budget,shouldmoney');
  656. $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');
  657. $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');
  658. $sssldlz = count($sssl);
  659. $ssslsmt = count($ssje);
  660. $sssltt = count($tje);
  661. $ssslamz = count($amzje);
  662. $ssjedlz = sprintf("%01.2f", array_sum(array_column($sssl, 'budget')));
  663. $ssjesmt = sprintf("%01.2f", array_sum(array_column($ssje, 'budget')));
  664. $ssjett = sprintf("%01.2f", array_sum(array_column($tje, 'budget')));
  665. $ssjeamz = sprintf("%01.2f", array_sum(array_column($amzje, 'budget')));
  666. $sssl = $sssldlz + $ssslsmt + $sssltt + $ssslamz;
  667. $ssje = $ssjedlz + $ssjesmt + $ssjett + $ssjeamz;
  668. } else {
  669. $sp = $this->shop->read($shop);
  670. if($sp['type'] == '1513'){
  671. $fu = 'fullorderamz';
  672. }elseif($sp['type'] == '270'){
  673. $fu = 'fullordersmt';
  674. }elseif($sp['type'] == '1514'){
  675. $fu = 'fullordertt';
  676. }else{
  677. $fu = 'fullorder';
  678. }
  679. //1513
  680. //$fu = ($sp['type'] == '269') ? 'fullorder' : 'fullordersmt';
  681. $ss = $this->$fu->find_all("dtime >= " . $zdtime . " and dtime <= " . strtotime(date('Ymd', $usat + 24 * 3600)) . " and shop = '" . $shop . "'", 'budget,shouldmoney');
  682. $sssl = count($ss);
  683. $ssje = sprintf("%01.2f", array_sum(array_column($ss, 'budget')));
  684. }
  685. echo @json_encode(array('sstime' => date('m-d H:i', time()), 'sssl' => $sssl, 'ssje' => sprintf("%.2f", $ssje), 'success' => true));
  686. exit;
  687. }
  688. //店铺产品详情
  689. if (isset($post['id'])) {
  690. $tm += 24 * 3600;
  691. $gshtime = date('Y-m-d 0:0:0', time());
  692. $gshtime = strtotime($gshtime) + 24 * 60 * 60;
  693. $dpxq = array();
  694. $id = $this->input->post('id', true);
  695. $xqtime = $this->input->post('xqtime', true);
  696. $xqshop = $this->shop->read($id);
  697. if ($xqshop['type'] == "269" || $xqshop['type'] == "2768") {
  698. $sid = 'fullorder';
  699. } else if ($xqshop['type'] == "270") {
  700. $sid = 'fullordersmt';
  701. } else if ($xqshop['type'] == "1513") {
  702. $sid = 'fullorderamz';
  703. }else if ($xqshop['type'] == "1514") {
  704. $sid = 'fullordertt';
  705. }
  706. if ($xqtime > 345600) {
  707. $rows = $this->$sid->find_all("shop = '" . $id . "' and dtime >= '" . ($gshtime - $xqtime) . "' and dtime <= '" . ($gshtime + 24 * 60 * 60) . "'", 'whlabel,fpdata,number');
  708. } else {
  709. $rows = $this->$sid->find_all("shop = '" . $id . "' and dtime >= '" . ($gshtime - $xqtime) . "' and dtime <= '" . ($gshtime + 24 * 60 * 60 - $xqtime) . "'", 'whlabel,fpdata,number');
  710. }
  711. foreach ($rows as $v) {
  712. $or = explode('|', ltrim($v['whlabel'], '|'));
  713. for ($i = 0; $i < count($or); $i++) {
  714. $orod = explode('-', $or[$i]);
  715. if ($orod[0] == '') {
  716. continue;
  717. }
  718. if (isset($dpxq[$orod[0]])) {
  719. $dpxq[$orod[0]][0] += $orod[1]; //统计多少条
  720. //$dpxq[$orod[0]][0] += 1;//统计多少单
  721. $dpxq[$orod[0]][1] .= $v['number'] . ';'; //价格
  722. } else {
  723. $oo = explode(';', rtrim($v['fpdata'], ';'));
  724. @$ro = explode('|', $oo[$i]);
  725. if (isset($ro[1])) {
  726. $dpxq[$orod[0]] = array($orod[1], $v['number'] . ';', $ro[1]); //统计多少条
  727. //$dpxq[$orod[0]] = array(1,0,$ro[1]);//统计多少单
  728. }
  729. }
  730. }
  731. }
  732. $dpxq = array_values($dpxq);
  733. arsort($dpxq);
  734. $dpxq = array_slice($dpxq, 0, 9999);
  735. echo @json_encode(array('dpxq' => $dpxq, 'success' => true));
  736. exit;
  737. }
  738. $wlshop = $this->shop->find_all('status = 0 and ' . rtrim($sid, 'or'));
  739. $this->data['wlshop'] = $wlshop;
  740. $dr = $usat;
  741. $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));
  742. $this->_Template('phone/p_user_statistics', $this->data);
  743. }
  744. //统计的时间戳
  745. protected function _statistics_sjc($fgshop,$zdt,$where,$k,$usat){
  746. if ($zdt >= 691200) {
  747. $k = $usat - $k - $k;
  748. $j = $usat;
  749. $n = ($j - $k) / (24 * 3600);
  750. $usat = $usat + 24 * 3600;
  751. } else {
  752. $n = 2;
  753. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  754. }
  755. $time = array();
  756. $timeold = array();
  757. $stime = array();
  758. $dlznum = array();
  759. $smtnum = array();
  760. $ymoney = array();
  761. $money = array();
  762. $dlzmoneyb = array();
  763. $smtmoneyb = array();
  764. $ttmoneyb = array();
  765. $zkh = array();
  766. $dlzsl = 0;
  767. $dlzje = 0;
  768. $dlzssje = 0;
  769. $smtsl = 0;
  770. $smtje = 0;
  771. $smtssje = 0;
  772. $ttsl = 0;
  773. $ttje = 0;
  774. $ttssje = 0;
  775. $amzsl = 0;
  776. $amzje = 0;
  777. $amzssje = 0;
  778. $shopdata = array();
  779. $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 != '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' and id != '48'","*",'px asc');
  780. foreach ($ys as $v) {
  781. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  782. }
  783. for ($i = 1; $i < $n; $i++) {
  784. //近7天时间
  785. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  786. if ($n > 13 && $i > $n / 2 || $n < 14) {
  787. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  788. $time[] = date('m-d', $t);
  789. $ct = strtotime(date('Ymd', $t));
  790. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  791. //var_dump(date("Y-m-d H:i:s",$ct)."=================".date("Y-m-d H:i:s",$ctj));
  792. $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,email,refundj');
  793. $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,refundj');
  794. $tt = $this->fullordertt->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,email,refundj');
  795. $amz = $this->fullorderamz->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,email,refundj');
  796. $ab[] = $dlz;
  797. //数量及金额开始
  798. $dlznum[] = count($dlz);
  799. $smtnum[] = count($smt);
  800. $ttnum[] = count($smt);
  801. $amznum[] = count($amz);
  802. //订单金额
  803. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  804. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  805. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  806. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  807. /**
  808. //提出退款关闭等信息的实收金额
  809. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  810. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  811. //提出退款关闭等信息的实收金额
  812. **/
  813. //实收金额
  814. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  815. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  816. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  817. $amzmss = sprintf("%01.2f", array_sum(array_column($amz, 'budget')));
  818. //实收金额
  819. //补/退原额
  820. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  821. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  822. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  823. $amzbty = sprintf("%01.2f", array_sum(array_column($amz, 'refundy')));
  824. //补/退原额
  825. //补/退净额
  826. $dlzbtj = sprintf("%01.2f", array_sum(array_column($dlz, 'refundj')));
  827. $smtbtj = sprintf("%01.2f", array_sum(array_column($smt, 'refundj')));
  828. $ttbtj = sprintf("%01.2f", array_sum(array_column($tt, 'refundj')));
  829. $amzbtj = sprintf("%01.2f", array_sum(array_column($amz, 'refundj')));
  830. //补/退净额
  831. $dlzmoney[] = $dlzm;
  832. $smtmoney[] = $smtm;
  833. $ttmoney[] = $ttm;
  834. $amzmoney[] = $amzm;
  835. // $dlzsl += count($dlz);
  836. // $dlzje += $dlzm + $dlzbty;
  837. // $smtsl += count($smt);
  838. // $smtje += $smtm + $smtbty;
  839. // $ttsl += count($tt);
  840. // $ttje += $ttm + $ttbty;
  841. // $amzsl += count($amz);
  842. // $amzje += $amzm + $amzbty;
  843. $dlzsl += count($dlz);
  844. $dlzje += $dlzm ;
  845. $smtsl += count($smt);
  846. $smtje += $smtm ;
  847. $ttsl += count($tt);
  848. $ttje += $ttm ;
  849. $amzsl += count($amz);
  850. $amzje += $amzm ;
  851. /**
  852. //减去的实收金额
  853. $dlzssje += $dlzm+$dlzmss;
  854. $smtssje += $smtm+$smtmss;
  855. **/
  856. //实收和补/退净额
  857. // $dlzssje += $dlzmss + $dlzbtj;
  858. // $smtssje += $smtmss + $smtbtj;
  859. // $ttssje += $ttmss + $ttbtj;
  860. // $amzssje += $amzmss + $amzbtj;
  861. $dlzssje += $dlzmss;
  862. $smtssje += $smtmss;
  863. $ttssje += $ttmss ;
  864. $amzssje += $amzmss;
  865. //数量及金额结束
  866. $sd = array_merge($dlz, $smt, $tt,$amz);
  867. foreach ($sd as $v) {
  868. if (isset($shopdata[$v['shop']])) {
  869. $shopdata[$v['shop']]['num'] += 1;
  870. // $shopdata[$v['shop']]['money'] += $v['shouldmoney'] + $v['refundy'] ;
  871. // $shopdata[$v['shop']]['tmoney'] += $v['budget'] + $v['refundj'];
  872. $shopdata[$v['shop']]['money'] += $v['shouldmoney'] ;
  873. $shopdata[$v['shop']]['tmoney'] += $v['budget'] ;
  874. }
  875. }
  876. } else if ($n > 13 && $i <= $n / 2) {
  877. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  878. $timeold[] = date('m-d', $t);
  879. $ct = strtotime(date('Ymd', $t));
  880. $ctj = strtotime(date('Ymd', $t + 24 * 3600)) ;
  881. //var_dump(date("Y-m-d H:i:s",$ct)."------------------------".date("Y-m-d H:i:s",$ctj));
  882. $dlz = $this->fullorder->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  883. $smt = $this->fullordersmt->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  884. $tt = $this->fullordertt->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  885. $amz = $this->fullorderamz->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  886. //数量及金额开始
  887. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  888. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  889. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  890. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  891. $dlzmoneyb[] = $dlzm;
  892. $smtmoneyb[] = $smtm;
  893. $ttmoneyb[] = $ttm;
  894. $amzmoneyb[] = $amzm;
  895. //数量及金额结束
  896. }
  897. }
  898. foreach ($shopdata as $k => $v) {
  899. $sn = $this->shop->read($k);
  900. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  901. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  902. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  903. $shopdata[$k]['name'] = $sn['shopname'];
  904. $shopdata[$k]['b'] = $sn['type'];
  905. $shopdata[$k]['id'] = $sn['id'];
  906. }
  907. $shopdata = array_values($shopdata);
  908. //$sycp=array();
  909. /**
  910. //根据所选时间产品排行开始
  911. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  912. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  913. **/
  914. /**
  915. //昨日产品排行开始
  916. $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');
  917. $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');
  918. $rows = array_merge($dlzlist,$smtlist);
  919. foreach ($rows as $v)
  920. {
  921. $number = explode('|',trim($v['whlabel'],'|'));
  922. $or = explode(';',trim($v['fpdata'],';'));
  923. $i=0;
  924. foreach ($or as $va)
  925. {
  926. $ord = explode('|',$va);
  927. $orod = explode(',',$ord[0]);
  928. $numberod = explode('-',$number[$i]);
  929. if(!isset($orod[1]))
  930. {
  931. continue;
  932. }
  933. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  934. {
  935. //$sycp[$orod[1]][0] += 1;//统计多少单
  936. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  937. $sycp[$orod[1]][1] += 0;//价格
  938. }
  939. else
  940. {
  941. if(isset($numberod[1]))
  942. {
  943. $typeclass = $this->typeclass->read($orod['0']);
  944. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  945. }
  946. }
  947. $i++;
  948. }
  949. }
  950. arsort($sycp);
  951. $sycp = array_values($sycp);
  952. $sycp = array_slice($sycp,0,10);
  953. //产品排行结束
  954. **/
  955. //当时实时数据结束
  956. 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));
  957. exit; //,'sycp'=>$sycp昨日产品数据
  958. }
  959. //统计的时间段
  960. protected function _statistics_sjd($fgshop,$zdt,$where,$k,$usat){
  961. $timedata = explode('|', $zdt);
  962. $ktime = strtotime($timedata[0]);
  963. $jtime = strtotime($timedata[1]);
  964. $ktime = $ktime - ($jtime - $ktime);
  965. $k = $ktime;
  966. $j = $jtime;
  967. $n = ($j - $k) / (24 * 3600);
  968. $usat = $jtime;
  969. $tm = $jtime;
  970. $zdt = $jtime - $ktime;
  971. $time = array();
  972. $timeold = array();
  973. $stime = array();
  974. $dlznum = array();
  975. $smtnum = array();
  976. $ymoney = array();
  977. $money = array();
  978. $dlzmoneyb = array();
  979. $smtmoneyb = array();
  980. $ttmoneyb = array();
  981. $zkh = array();
  982. $dlzsl = 0;
  983. $dlzje = 0;
  984. $dlzssje = 0;
  985. $smtsl = 0;
  986. $smtje = 0;
  987. $smtssje = 0;
  988. $ttsl = 0;
  989. $ttje = 0;
  990. $ttssje = 0;
  991. $amzsl = 0;
  992. $amzje = 0;
  993. $amzssje = 0;
  994. $shopdata = array();
  995. $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 != '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' and id != '48'", "*", 'px asc');
  996. foreach ($ys as $v) {
  997. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  998. }
  999. // [修复 2] 循环边界:i=1 → i=0;< n → <= n
  1000. for ($i = 0; $i <= $n; $i++) {
  1001. //近7天时间
  1002. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1003. // [修复 2] 主分支条件:i > n/2 → i >= n/2
  1004. if ($n > 13 && $i >= $n / 2 || $n < 14) {
  1005. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1006. $time[] = date('m-d', $t);
  1007. $ct = strtotime(date('Ymd', $t));
  1008. // [修复 3] $ctj 减 1 秒
  1009. $ctj = strtotime(date('Ymd', $t + 24 * 3600)) ;
  1010. $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,email,refundj');
  1011. $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,refundj');
  1012. $tt = $this->fullordertt->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,email,refundj');
  1013. $amz = $this->fullorderamz->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,email,refundj');
  1014. $ab[] = $dlz;
  1015. //数量及金额开始
  1016. $dlznum[] = count($dlz);
  1017. $smtnum[] = count($smt);
  1018. $ttnum[] = count($smt);
  1019. $amznum[] = count($amz);
  1020. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1021. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1022. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1023. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  1024. /**
  1025. //提出退款关闭等信息的实收金额
  1026. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1027. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1028. //提出退款关闭等信息的实收金额
  1029. **/
  1030. //实收金额
  1031. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  1032. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  1033. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  1034. $amzmss = sprintf("%01.2f", array_sum(array_column($amz, 'budget')));
  1035. //实收金额
  1036. //补/退原额
  1037. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  1038. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  1039. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  1040. $amzbty = sprintf("%01.2f", array_sum(array_column($amz, 'refundy')));
  1041. //补/退原额
  1042. //补/退净额
  1043. $dlzbtj = sprintf("%01.2f", array_sum(array_column($dlz, 'refundj')));
  1044. $smtbtj = sprintf("%01.2f", array_sum(array_column($smt, 'refundj')));
  1045. $ttbtj = sprintf("%01.2f", array_sum(array_column($tt, 'refundj')));
  1046. $amzbtj = sprintf("%01.2f", array_sum(array_column($amz, 'refundj')));
  1047. //补/退净额
  1048. $dlzmoney[] = $dlzm;
  1049. $smtmoney[] = $smtm;
  1050. $ttmoney[] = $ttm;
  1051. $amzmoney[] = $amzm;
  1052. // $dlzsl += count($dlz);
  1053. // $dlzje += $dlzm + $dlzbty;
  1054. // $smtsl += count($smt);
  1055. // $smtje += $smtm + $smtbty;
  1056. // $ttsl += count($tt);
  1057. // $ttje += $ttm + $ttbty;
  1058. // $amzsl += count($amz);
  1059. // $amzje += $amzm + $amzbty;
  1060. $dlzsl += count($dlz);
  1061. $dlzje += $dlzm;
  1062. $smtsl += count($smt);
  1063. $smtje += $smtm;
  1064. $ttsl += count($tt);
  1065. $ttje += $ttm;
  1066. $amzsl += count($amz);
  1067. $amzje += $amzm;
  1068. /**
  1069. //减去的实收金额
  1070. $dlzssje += $dlzm+$dlzmss;
  1071. $smtssje += $smtm+$smtmss;
  1072. **/
  1073. //实收和补/退
  1074. // $dlzssje += $dlzmss + $dlzbtj;
  1075. // $smtssje += $smtmss + $smtbtj;
  1076. // $ttssje += $ttmss + $ttbtj;
  1077. // $amzssje += $amzmss + $amzbtj;
  1078. $dlzssje += $dlzmss;
  1079. $smtssje += $smtmss;
  1080. $ttssje += $ttmss;
  1081. $amzssje += $amzmss;
  1082. //数量及金额结束
  1083. $sd = array_merge($dlz, $smt, $tt, $amz);
  1084. foreach ($sd as $v) {
  1085. if (isset($shopdata[$v['shop']])) {
  1086. $shopdata[$v['shop']]['num'] += 1;
  1087. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  1088. $shopdata[$v['shop']]['tmoney'] += $v['budget'] ;
  1089. }
  1090. }
  1091. }
  1092. // [修复 4] 对比周期条件:i <= n/2 → i < n/2
  1093. else if ($n > 13 && $i < $n / 2) {
  1094. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1095. $timeold[] = date('m-d', $t);
  1096. $ct = strtotime(date('Ymd', $t));
  1097. // [修复 3] $ctj 减 1 秒
  1098. $ctj = strtotime(date('Ymd', $t + 24 * 3600)) ;
  1099. $dlz = $this->fullorder->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1100. $smt = $this->fullordersmt->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1101. $tt = $this->fullordertt->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1102. $amz = $this->fullorderamz->find_all(" (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime < " . $ctj . $where, 'budget,shouldmoney,shop');
  1103. //数量及金额开始
  1104. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1105. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1106. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1107. $amzm = sprintf("%01.2f", array_sum(array_column($amz, 'shouldmoney')));
  1108. $dlzmoneyb[] = $dlzm;
  1109. $smtmoneyb[] = $smtm;
  1110. $ttmoneyb[] = $ttm;
  1111. $amzmoneyb[] = $amzm;
  1112. //数量及金额结束
  1113. }
  1114. }
  1115. foreach ($shopdata as $k => $v) {
  1116. $sn = $this->shop->read($k);
  1117. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  1118. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  1119. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  1120. $shopdata[$k]['name'] = $sn['shopname'];
  1121. $shopdata[$k]['b'] = $sn['type'];
  1122. $shopdata[$k]['id'] = $sn['id'];
  1123. }
  1124. $shopdata = array_values($shopdata);
  1125. //$sycp=array();
  1126. /**
  1127. //根据所选时间产品排行开始
  1128. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1129. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1130. **/
  1131. /**
  1132. //昨日产品排行开始
  1133. $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');
  1134. $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');
  1135. $rows = array_merge($dlzlist,$smtlist);
  1136. foreach ($rows as $v)
  1137. {
  1138. $number = explode('|',trim($v['whlabel'],'|'));
  1139. $or = explode(';',trim($v['fpdata'],';'));
  1140. $i=0;
  1141. foreach ($or as $va)
  1142. {
  1143. $ord = explode('|',$va);
  1144. $orod = explode(',',$ord[0]);
  1145. $numberod = explode('-',$number[$i]);
  1146. if(!isset($orod[1]))
  1147. {
  1148. continue;
  1149. }
  1150. if(isset($sycp[$orod[1]) && isset($numberod[1]))
  1151. {
  1152. //$sycp[$orod[1]][0] += 1;//统计多少单
  1153. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  1154. $sycp[$orod[1]][1] += 0;//价格
  1155. }
  1156. else
  1157. {
  1158. if(isset($numberod[1]))
  1159. {
  1160. $typeclass = $this->typeclass->read($orod['0']);
  1161. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  1162. }
  1163. }
  1164. $i++;
  1165. }
  1166. }
  1167. arsort($sycp);
  1168. $sycp = array_values($sycp);
  1169. $sycp = array_slice($sycp,0,10);
  1170. //产品排行结束
  1171. **/
  1172. //当时实时数据结束
  1173. 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));
  1174. exit; //,'sycp'=>$sycp昨日产品数据
  1175. }
  1176. /**
  1177. public function super_unique($array,$key)//多维删除重复
  1178. {
  1179. $temp_array = array();
  1180. foreach ($array as &$v) {
  1181. if (!isset($temp_array[$v[$key]]))
  1182. {
  1183. $temp_array[$v[$key]] =& $v;
  1184. }
  1185. }
  1186. $array = array_values($temp_array);
  1187. return $array;
  1188. }
  1189. **/
  1190. public function _usatime()
  1191. {
  1192. date_default_timezone_set("Etc/GMT+8");
  1193. return time();
  1194. }
  1195. //数据
  1196. public function _rows()
  1197. {
  1198. $post = $this->input->post(NULL, TRUE);
  1199. if (isset($post['shop'])) {
  1200. $shop = $this->input->post('shop', true);
  1201. $data = $this->shop->find_all('1=1',"*","px asc");
  1202. $list = array();
  1203. foreach ($data as $key => $value) {
  1204. $t = $this->typeclass->read($value['type']);
  1205. $list[] = array('id' => $value['id'], 'title' => $value['shopname'] . ' - ' . $t['title']);
  1206. }
  1207. $num = array();
  1208. if ($shop != "null") {
  1209. $num = $this->user->read($shop); //找出内容
  1210. if ($num['shop']) {
  1211. $num = explode('|', trim($num['shop'], '|')); //数组化内容
  1212. } else {
  1213. $num = array();
  1214. }
  1215. }
  1216. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1217. }
  1218. if (isset($post['excelshop'])) {
  1219. $excelshop = $this->input->post('excelshop', true);
  1220. $data = $this->shop->find_all('1=1',"*","px asc");
  1221. $list = array();
  1222. foreach ($data as $key => $value) {
  1223. $t = $this->typeclass->read($value['type']);
  1224. $list[] = array('id' => $value['id'], 'title' => $value['shopname'] . ' - ' . $t['title']);
  1225. }
  1226. $num = array();
  1227. if ($excelshop != "null") {
  1228. $num = $this->user->read($excelshop); //找出内容
  1229. if ($num['excelshop']) {
  1230. $num = explode('|', trim($num['excelshop'], '|')); //数组化内容
  1231. } else {
  1232. $num = array();
  1233. }
  1234. }
  1235. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1236. }
  1237. if (isset($post['purchase'])) {
  1238. $purchase = $this->input->post('purchase', true);
  1239. $data = $this->purchase->find_all('1=1');
  1240. $list = array();
  1241. foreach ($data as $key => $value) {
  1242. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1243. }
  1244. $num = array();
  1245. if ($purchase != "null") {
  1246. $num = $this->user->read($purchase); //找出内容
  1247. if ($num['purchase']) {
  1248. $num = explode('|', trim($num['purchase'], '|')); //数组化内容
  1249. } else {
  1250. $num = array();
  1251. }
  1252. }
  1253. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1254. }
  1255. if (isset($post['staff'])) {
  1256. $staff = $this->input->post('staff', true);
  1257. $data = $this->staff->find_all('1=1');
  1258. $list = array();
  1259. foreach ($data as $key => $value) {
  1260. $list[] = array('id' => $value['id'], 'title' => $value['name']);
  1261. }
  1262. $num = array();
  1263. if ($staff != "null") {
  1264. $num = $this->user->read($staff); //找出内容
  1265. if ($num['staff']) {
  1266. $num = explode('|', trim($num['staff'], '|')); //数组化内容
  1267. } else {
  1268. $num = array();
  1269. }
  1270. }
  1271. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1272. }
  1273. if (isset($post['warehouse'])) {
  1274. $warehouse = $this->input->post('warehouse', true);
  1275. $data = $this->warehouse->find_all('1=1');
  1276. $list = array();
  1277. foreach ($data as $key => $value) {
  1278. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1279. }
  1280. $num = array();
  1281. if ($warehouse != "null") {
  1282. $num = $this->user->read($warehouse); //找出内容
  1283. if ($num['warehouse']) {
  1284. $num = explode('|', trim($num['warehouse'], '|')); //数组化内容
  1285. } else {
  1286. $num = array();
  1287. }
  1288. }
  1289. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1290. }
  1291. if (isset($post['transfer'])) {
  1292. $transfer = $this->input->post('transfer', true);
  1293. $data = $this->transfer->find_all('1=1');
  1294. $list = array();
  1295. foreach ($data as $key => $value) {
  1296. $list[] = array('id' => $value['id'], 'title' => $value['title']);
  1297. }
  1298. $num = array();
  1299. if ($transfer != "null") {
  1300. $num = $this->user->read($transfer); //找出内容
  1301. if ($num['transfer']) {
  1302. $num = explode('|', trim($num['transfer'], '|')); //数组化内容
  1303. } else {
  1304. $num = array();
  1305. }
  1306. }
  1307. echo json_encode(array('msg' => ($list), 'num' => ($num), 'success' => true));
  1308. }
  1309. }
  1310. public function _shopfx()
  1311. {
  1312. $post = $this->input->post(NULL, TRUE);
  1313. if (isset($post['time'])) {
  1314. $time = $this->input->post('time', true);
  1315. $t = strtotime(date("Ymd", time() + 24 * 3600)); //明天0点
  1316. $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");
  1317. $sid = '';
  1318. foreach ($shop as $value) {
  1319. $sid .= " shop = " . $value['id'] . " or";
  1320. }
  1321. $sid = " and (" . rtrim($sid, 'or') . ")";
  1322. $znum = $this->fullorder->find_count("dtime > '" . ($t - $time * 24 * 3600) . "' and dtime < '" . $t . "'" . $sid);
  1323. $data = array();
  1324. $list = array();
  1325. $color = array('0' => '#30546c', '1' => '#61a0a8', '2' => '#c23531', '3' => '#d48265', '4' => '#546570', '5' => '#749f83', '6' => '#bda29a', '7' => '#6e7074', '8' => '#546570');
  1326. $j = 0;
  1327. $zt = array(7 => 1, 30 => 2);
  1328. foreach ($shop as $v) {
  1329. $d = $this->fullorder->find_count("shop = '" . $v['id'] . "' and dtime > '" . ($t - $time * 24 * 3600) . "' and dtime < '" . $t . "' and (state = '207' or state = '216')");
  1330. $wd = $this->allocation->read($zt[$time]);
  1331. $n = json_decode($wd['content'], true);
  1332. $bfb = ($d == 0) ? 0 : round(($d / $znum) * 100, 2);
  1333. $data[] = array('value' => $bfb, 'name' => $v['shopname'] . ' ' . $bfb . "%", 'itemStyle' => array('color' => $color[$j]));
  1334. $n[$v['id']][] = $this->fullorder->find_count("shop = '" . $v['id'] . "' and gtime = '" . date("Ymd", time()) . "' and (state = '207' or state = '216')");
  1335. $t_list = array();
  1336. for ($i = 0; $i < $time; $i++) {
  1337. $t_list[] = date("m-d", time() - ($i * 24 * 3600));
  1338. }
  1339. $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) . '%');
  1340. $j++;
  1341. }
  1342. $list = (array_reverse($list));
  1343. echo json_encode(array('data' => ($data), 'list' => $list, 't' => (array_reverse($t_list)), 'success' => true));
  1344. exit;
  1345. /**
  1346. $time = $this->input->post('time',true);
  1347. $t = strtotime(date("Ymd",time()+24*3600));//明天0点
  1348. $shop = $this->shop->find_all("type = 269 and tb = 1 and id != 22 and id != 28 and id != 29 and id != 30");
  1349. $sid = '';
  1350. foreach ($shop as $value)
  1351. {
  1352. $sid .= " shop = ".$value['id']." or";
  1353. }
  1354. $sid = " and (".rtrim($sid,'or').")";
  1355. $znum = $this->fullorder->find_count("dtime > '".($t-$time*24*3600)."' and dtime < '".$t."'".$sid);
  1356. $data = array();$list = array();
  1357. $color = array('0'=>'#30546c','1'=>'#61a0a8','2'=>'#c23531','3'=>'#d48265','4'=>'#546570','5'=>'#749f83','6'=>'#bda29a','7'=>'#6e7074','8'=>'#546570');
  1358. $j = 0;
  1359. foreach ($shop as $v)
  1360. {
  1361. $d = $this->fullorder->find_count("shop = '".$v['id']."' and dtime > '".($t-$time*24*3600)."' and dtime < '".$t."' and (state = '207' or state = '216')");
  1362. $bfb = ($d==0)?0:round(($d / $znum) * 100, 2);
  1363. $data[] = array('value'=>$bfb,'name'=>$v['shopname'].' '.$bfb."%",'itemStyle'=>array('color'=>$color[$j]));
  1364. $n = array();$t_list = array();
  1365. for($i=0;$i<$time;$i++)
  1366. {
  1367. if($i == 0)
  1368. {
  1369. $s = date("Ymd",time());
  1370. }
  1371. else
  1372. {
  1373. $s = date("Ymd",time()-($i*24*3600));
  1374. }
  1375. $t_list[] = date("m-d",time()-($i*24*3600));
  1376. $n[] = $this->fullorder->find_count("shop = '".$v['id']."' and gtime = '".$s."' and (state = '207' or state = '216')");
  1377. }
  1378. $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).'%');
  1379. $j++;
  1380. }
  1381. $list = (array_reverse($list));
  1382. echo json_encode(array('data'=>($data),'list'=>$list,'t'=>(array_reverse($t_list)),'success'=>true));exit;
  1383. **/
  1384. }
  1385. $this->_Template('phone/p_user_shopfx', $this->data);
  1386. }
  1387. public function _shopfxlist()
  1388. {
  1389. $t = strtotime(date("Ymd", time())); //今天0点
  1390. $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");
  1391. $sid = '';
  1392. foreach ($shop as $value) {
  1393. $sid .= " shop = " . $value['id'] . " or";
  1394. }
  1395. $sid = " and (" . rtrim($sid, 'or') . ")";
  1396. $zt = array(7, 30);
  1397. $this->db->trans_begin();
  1398. foreach ($zt as $key => $time) {
  1399. $data = array();
  1400. $list = array();
  1401. foreach ($shop as $v) {
  1402. $n = array();
  1403. $t_list = array();
  1404. for ($i = 1; $i < $time; $i++) {
  1405. if ($i == 0) {
  1406. $s = date("Ymd", time());
  1407. } else {
  1408. $s = date("Ymd", time() - ($i * 24 * 3600));
  1409. }
  1410. $t_list[] = date("m-d", time() - ($i * 24 * 3600));
  1411. $n[] = $this->fullorder->find_count("shop = '" . $v['id'] . "' and gtime = '" . $s . "' and (state = '207' or state = '216')");
  1412. }
  1413. $list[$v['id']] = array_reverse($n);
  1414. }
  1415. $this->allocation->save(array('content' => json_encode($list)), $key + 1);
  1416. }
  1417. if ($this->db->trans_status() === FALSE) {
  1418. $this->db->trans_rollback();
  1419. echo 'orver';
  1420. } else {
  1421. $this->db->trans_commit();
  1422. echo 'ok';
  1423. }
  1424. }
  1425. public function _apple()
  1426. {
  1427. $this->_Template('phone/p_user_apple', $this->data);
  1428. }
  1429. //退出
  1430. public function _tc()
  1431. {
  1432. $this->session->sess_destroy();
  1433. header("Location:/");
  1434. }
  1435. public function _tjadd()
  1436. {
  1437. $pdtime = date('Y-m-d-H', time());
  1438. //if(is_file("./data/tj/".$pdtime.".txt"))
  1439. if (is_file("./data/tj/" . $pdtime . ".txt")) {
  1440. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "r") or die("Unable to open file!");
  1441. $bc = fread($myfile, filesize("./data/tj/" . $pdtime . ".txt"));
  1442. fclose($myfile);
  1443. $bc = json_decode($bc, true);
  1444. $zzt = array($bc['zzt'][0], $bc['zzt'][1]);
  1445. } else {
  1446. /** 暂时不需要了
  1447. //柱状图数据
  1448. $i = 0;
  1449. $data = array();$sndata1 = array();$sndata2 = array();$sndata3 = array();
  1450. $sj = array('01','02','03','04','05','06','07','08','09','10','11','12');
  1451. foreach ($sj as $k=>$v)
  1452. {
  1453. $i++;
  1454. $dlz1 = $this->fullorder->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1455. $smt1 = $this->fullordersmt->find_all("gtime > '".date("Y").$v."00' and gtime < '".date("Y").$v."32'",'shouldmoney');
  1456. $m1 = sprintf("%01.2f",array_sum(array_column($dlz1,'shouldmoney'))+array_sum(array_column($smt1,'shouldmoney')));
  1457. $dlz2 = $this->fullorder->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1458. $smt2 = $this->fullordersmt->find_all("gtime > '".(date("Y")-1).$v."00' and gtime < '".(date("Y")-1).$v."32'",'shouldmoney');
  1459. $m2 = sprintf("%01.2f",array_sum(array_column($dlz2,'shouldmoney'))+array_sum(array_column($smt2,'shouldmoney')));
  1460. $dlz3 = $this->fullorder->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1461. $smt3 = $this->fullordersmt->find_all("gtime > '".(date("Y")-2).$v."00' and gtime < '".(date("Y")-2).$v."32'",'shouldmoney');
  1462. $m3 = sprintf("%01.2f",array_sum(array_column($dlz3,'shouldmoney'))+array_sum(array_column($smt3,'shouldmoney')));
  1463. $sndata1[$i] = $m3;
  1464. $sndata2[12+$i] = $m2;
  1465. $sndata3[24+$i] = $m1;
  1466. $data[] = array($v,$m1,$m2,$m3);
  1467. }
  1468. $sndata = array_merge($sndata1,$sndata2,$sndata3);
  1469. $zzt = array($data,$sndata);
  1470. //柱状图结束
  1471. **/
  1472. }
  1473. //详情内容
  1474. $dt = 0;
  1475. //系统报错 提示没有api下标的键
  1476. if(!isset($_SESSION['api'])){
  1477. echo "ERROR";
  1478. die;
  1479. }
  1480. $user = $this->user->get_api($_SESSION['api']);
  1481. $usp = $user;
  1482. $fgshop = "";
  1483. $sid = "";
  1484. $user = explode('|', trim($user['shop'], '|'));
  1485. foreach ($user as $value) {
  1486. if(!empty($value)){
  1487. $fgshop .= " shop = " . $value . " or";
  1488. $sid .= " id = " . $value . " or";
  1489. }
  1490. }
  1491. //为了让下面程序可以执行 给的如果用户没店铺权限 就给一个不存在的店铺
  1492. if(empty($fgshop)){
  1493. $fgshop = " shop = 0 or";
  1494. $sid = " id = 0 or";
  1495. }
  1496. $tm = strtotime(date("Ymd"), time());
  1497. $usat = $tm;
  1498. //$molist = array('0','1','2d');
  1499. $molist = array('0', '1');
  1500. $zqtime = array(259200, 345600, 691200, 2678400, 7862400, 31622400);
  1501. //time开始
  1502. $zqtdata = array();
  1503. foreach ($molist as $vval) {
  1504. $where = "";
  1505. $source = $vval;
  1506. if ($source == '2d') {
  1507. $where = " and source >= '2'";
  1508. } else if ($source != '0') {
  1509. $where = " and source = '$source'";
  1510. }
  1511. foreach ($zqtime as $value) {
  1512. $zdt = $value;
  1513. $k = $zdt;
  1514. $tab = 1;
  1515. //$start = '2018-10-15';
  1516. //$end = '2018-11-26';
  1517. //$tim = strtotime($start);
  1518. //$day = $time/(3600*24);
  1519. if ($tab == '1') {
  1520. if ($zdt >= 691200) {
  1521. $k = $usat - $k - $k;
  1522. $j = $usat;
  1523. $n = ($j - $k) / (24 * 3600);
  1524. } else {
  1525. $n = 2;
  1526. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  1527. }
  1528. } else {
  1529. $timedata = explode('|', $zdt);
  1530. $ktime = strtotime($timedata[0]);
  1531. $jtime = strtotime($timedata[1]);
  1532. $ktime = $ktime - ($jtime - $ktime);
  1533. $k = $ktime;
  1534. $j = $jtime;
  1535. $n = ($j - $k) / (24 * 3600);
  1536. $usat = $jtime;
  1537. $tm = $jtime;
  1538. $zdt = $jtime - $ktime;
  1539. }
  1540. $time = array();
  1541. $timeold = array();
  1542. $stime = array();
  1543. $dlznum = array();
  1544. $smtnum = array();;
  1545. $ttnum = array();
  1546. $ymoney = array();
  1547. $money = array();
  1548. $dlzmoney = array();
  1549. $smtmoney = array();
  1550. $ttmoney = array();
  1551. $dlzmoneyb = array();
  1552. $smtmoneyb = array();
  1553. $ttmoneyb = array();
  1554. $dlzsl = 0;
  1555. $dlzje = 0;
  1556. $dlzssje = 0;
  1557. $smtsl = 0;
  1558. $smtje = 0;
  1559. $smtssje = 0;
  1560. $ttsl = 0;
  1561. $ttje = 0;
  1562. $ttssje = 0;
  1563. $shopdata = array();
  1564. $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'");
  1565. foreach ($ys as $v) {
  1566. $shopdata[$v['id']] = array('num' => 0, 'money' => 0, 'tmoney' => 0, 'fdl' => 0, 'chl' => 0);
  1567. }
  1568. for ($i = 1; $i < $n; $i++) {
  1569. //近7天时间
  1570. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1571. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1572. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1573. $time[] = date('m-d', $t);
  1574. $ct = strtotime(date('Ymd', $t));
  1575. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1576. $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');
  1577. $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');
  1578. $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');
  1579. $ab[] = $dlz;
  1580. //数量及金额开始
  1581. $dlznum[] = count($dlz);
  1582. $smtnum[] = count($smt);
  1583. $ttnum[] = count($smt);
  1584. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1585. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1586. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1587. /**
  1588. //提出退款关闭等信息的实收金额
  1589. $dlzmss = sprintf("%01.2f",array_sum(array_column($dlz,'refundy')));
  1590. $smtmss = sprintf("%01.2f",array_sum(array_column($smt,'refundy')));
  1591. //提出退款关闭等信息的实收金额
  1592. **/
  1593. //实收金额
  1594. $dlzmss = sprintf("%01.2f", array_sum(array_column($dlz, 'budget')));
  1595. $smtmss = sprintf("%01.2f", array_sum(array_column($smt, 'budget')));
  1596. $ttmss = sprintf("%01.2f", array_sum(array_column($tt, 'budget')));
  1597. //实收金额
  1598. //补/退原额
  1599. $dlzbty = sprintf("%01.2f", array_sum(array_column($dlz, 'refundy')));
  1600. $smtbty = sprintf("%01.2f", array_sum(array_column($smt, 'refundy')));
  1601. $ttbty = sprintf("%01.2f", array_sum(array_column($tt, 'refundy')));
  1602. //补/退原额
  1603. $dlzmoney[] = $dlzm;
  1604. $smtmoney[] = $smtm;
  1605. $ttmoney[] = $ttm;
  1606. $dlzsl += count($dlz);
  1607. $dlzje += $dlzm;
  1608. $smtsl += count($smt);
  1609. $smtje += $smtm;
  1610. $ttsl += count($tt);
  1611. $ttje += $ttm;
  1612. /**
  1613. //减去的实收金额
  1614. $dlzssje += $dlzm+$dlzmss;
  1615. $smtssje += $smtm+$smtmss;
  1616. **/
  1617. //实收和补/退
  1618. $dlzssje += $dlzmss + $dlzbty;
  1619. $smtssje += $smtmss + $smtbty;
  1620. $ttssje += $ttmss + $ttbty;
  1621. //数量及金额结束
  1622. $sd = array_merge($dlz, $smt, $tt);
  1623. foreach ($sd as $v) {
  1624. if (isset($shopdata[$v['shop']])) {
  1625. $shopdata[$v['shop']]['num'] += 1;
  1626. $shopdata[$v['shop']]['money'] += $v['shouldmoney'];
  1627. $shopdata[$v['shop']]['tmoney'] += $v['budget'] + $v['refundy'];
  1628. }
  1629. }
  1630. } else if ($n > 13 && $i <= $n / 2) {
  1631. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1632. $timeold[] = date('m-d', $t);
  1633. $ct = strtotime(date('Ymd', $t));
  1634. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1635. $dlz = $this->fullorder->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1636. $smt = $this->fullordersmt->find_all("(" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1637. $tt = $this->fullordertt->find_all("state != 217 and (" . rtrim($fgshop, 'or') . ") and dtime >= " . $ct . " and dtime <= " . $ctj . $where, 'budget,shouldmoney,shop');
  1638. //数量及金额开始
  1639. $dlzm = sprintf("%01.2f", array_sum(array_column($dlz, 'shouldmoney')));
  1640. $smtm = sprintf("%01.2f", array_sum(array_column($smt, 'shouldmoney')));
  1641. $ttm = sprintf("%01.2f", array_sum(array_column($tt, 'shouldmoney')));
  1642. $dlzmoneyb[] = $dlzm;
  1643. $smtmoneyb[] = $smtm;
  1644. $ttmoneyb[] = $ttm;
  1645. //数量及金额结束
  1646. }
  1647. }
  1648. foreach ($shopdata as $k => $v) {
  1649. $sn = $this->shop->read($k);
  1650. $shopdata[$k]['money'] = sprintf("%01.2f", $v['money']) . '$';
  1651. $shopdata[$k]['tmoney'] = sprintf("%01.2f", $v['tmoney']) . '$';
  1652. $shopdata[$k]['bl'] = ($v['num'] == '0') ? '0$' : round($v['money'] / $v['num'], 2) . '$';
  1653. $shopdata[$k]['name'] = $sn['shopname'];
  1654. $shopdata[$k]['b'] = $sn['type'];
  1655. $shopdata[$k]['id'] = $sn['id'];
  1656. }
  1657. $shopdata = array_values($shopdata);
  1658. //$sycp=array();
  1659. /**
  1660. //根据所选时间产品排行开始
  1661. $dlzlist = $this->fullorder->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1662. $smtlist = $this->fullordersmt->find_all("dtime >= '".($tm-$zdt)."' and dtime <= '".$tm."' and (".rtrim($fgshop,'or').")".$where,'whlabel,fpdata');
  1663. **/
  1664. /**
  1665. //昨日产品排行开始
  1666. $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');
  1667. $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');
  1668. $rows = array_merge($dlzlist,$smtlist);
  1669. foreach ($rows as $v)
  1670. {
  1671. $number = explode('|',trim($v['whlabel'],'|'));
  1672. $or = explode(';',trim($v['fpdata'],';'));
  1673. $i=0;
  1674. foreach ($or as $va)
  1675. {
  1676. $ord = explode('|',$va);
  1677. $orod = explode(',',$ord[0]);
  1678. $numberod = explode('-',$number[$i]);
  1679. if(!isset($orod[1]))
  1680. {
  1681. continue;
  1682. }
  1683. if(isset($sycp[$orod[1]]) && isset($numberod[1]))
  1684. {
  1685. //$sycp[$orod[1]][0] += 1;//统计多少单
  1686. $sycp[$orod[1]][0] += $numberod[1];//统计多少条
  1687. $sycp[$orod[1]][1] += 0;//价格
  1688. }
  1689. else
  1690. {
  1691. if(isset($numberod[1]))
  1692. {
  1693. $typeclass = $this->typeclass->read($orod['0']);
  1694. $sycp[$orod[1]] = array($numberod[1],0,str_replace($typeclass['title'].' ','',$ord[1]));
  1695. }
  1696. }
  1697. $i++;
  1698. }
  1699. }
  1700. arsort($sycp);
  1701. $sycp = array_values($sycp);
  1702. $sycp = array_slice($sycp,0,10);
  1703. //产品排行结束
  1704. **/
  1705. //当时实时数据结束
  1706. $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昨日产品数据
  1707. }
  1708. }
  1709. //time结束
  1710. //zhcx开始
  1711. $zhcxdata = array();
  1712. foreach ($molist as $vval) {
  1713. $where = "";
  1714. $source = $vval;
  1715. if ($source == '2d') {
  1716. $where = " and source >= '2'";
  1717. } else if ($source != '0') {
  1718. $where = " and source = '$source'";
  1719. }
  1720. foreach ($zqtime as $value) {
  1721. $zdt = $value;
  1722. $k = $zdt;
  1723. $tab = 1;
  1724. //$customer = $this->customer->find_all("shop !=''",'num,zhcx');
  1725. //$customerkey = array_column($customer,'zhcx');
  1726. //$customer= array_combine($customerkey,$customer);
  1727. //$customersmt = $this->customersmt->find_all("shop !=''",'num,zhcx');
  1728. //$customersmtkey = array_column($customersmt,'zhcx');
  1729. //$customersmt= array_combine($customersmtkey,$customersmt);
  1730. //$customertt = $this->customertt->find_all("shop !=''",'num,zhcx');
  1731. //$customerttkey = array_column($customertt,'zhcx');
  1732. //$customertt= array_combine($customerttkey,$customertt);
  1733. if ($tab == '1') {
  1734. if ($zdt >= 691200) {
  1735. $k = $usat - $k - $k;
  1736. $j = $usat;
  1737. $n = ($j - $k) / (24 * 3600);
  1738. } else {
  1739. $n = 2;
  1740. $usat = strtotime(date("Ymd"), time()) - $k + 2 * 24 * 3600;
  1741. }
  1742. } else {
  1743. $timedata = explode('|', $zdt);
  1744. $ktime = strtotime($timedata[0]);
  1745. $jtime = strtotime($timedata[1]);
  1746. $ktime = $ktime - ($jtime - $ktime);
  1747. $k = $ktime;
  1748. $j = $jtime;
  1749. $n = ($j - $k) / (24 * 3600);
  1750. $usat = $jtime;
  1751. }
  1752. $time = array();
  1753. $timeold = array();
  1754. $stime = array();
  1755. $dlznum = array();
  1756. $smtnum = array();
  1757. $ttnum = array();
  1758. $ymoney = array();
  1759. $money = array();
  1760. $dlzmoneyb = array();
  1761. $smtmoneyb = array();
  1762. $ttmoneyb = array();
  1763. $zkh = array();
  1764. $dlzsl = 0;
  1765. $dlzje = 0;
  1766. $dlzssje = 0;
  1767. $smtsl = 0;
  1768. $smtje = 0;
  1769. $smtssje = 0;
  1770. $ttsl = 0;
  1771. $ttje = 0;
  1772. $ttssje = 0;
  1773. $shopdata = array();
  1774. $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'");
  1775. foreach ($ys as $v) {
  1776. $shopdata[$v['id']] = array('id' => $v['id'], 'b' => $v['type'], 'fdl' => 0, 'chl' => 0, 'num' => 0, 'fgl' => 0);
  1777. $zkh[$v['id']] = array();
  1778. }
  1779. for ($i = 1; $i < $n; $i++) {
  1780. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1781. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1782. $time[] = date('m-d', $t);
  1783. $ct = strtotime(date('Ymd', $t));
  1784. $ctj = strtotime(date('Ymd', $t + 24 * 3600));
  1785. $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');
  1786. $dlzemail = $this->fullorder->find_all("dtime <= " . $ctj . $where . " and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'shop,email');
  1787. $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');
  1788. $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');
  1789. //数量及金额结束
  1790. $sd = array_merge($dlz, $smt, $tt);
  1791. $fgldata = array();
  1792. foreach ($sd as $v) {
  1793. /**
  1794. $array = array(
  1795. 0 => array('email' => 123, 'id' => 1),
  1796. 1 => array('email' => 321, 'id' => 2),
  1797. 2 => array('email' => 123, 'id' => 3),
  1798. 3 => array('email' => 123, 'id' => 3)
  1799. );
  1800. // 使用 array_filter 筛选满足多个条件的元素
  1801. $result = array_filter($array, function($item) {
  1802. return $item['email'] === 123 && $item['id'] === 3;
  1803. });
  1804. // 计算满足条件的数量
  1805. $count = count($result);
  1806. echo "满足条件 (email = 123 且 id = 3) 的数量是:$count";
  1807. **/
  1808. /** 独立站查customer方法 弃用
  1809. if(isset($v['email']))
  1810. {
  1811. if(!isset($fgldata[$v['shop'].'-'.$v['email']]))
  1812. {
  1813. $fgldata[$v['shop'].'-'.$v['email']] = 0;
  1814. }
  1815. else
  1816. {
  1817. $fgldata[$v['shop'].'-'.$v['email']] += 1;
  1818. }
  1819. $zkh[$v['shop']][$v['email']] = array();
  1820. }
  1821. **/
  1822. /** 速卖通
  1823. else
  1824. {
  1825. if(!isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1826. {
  1827. $fgldata[$v['shop'].'-'.$v['userid']] = 0;
  1828. }
  1829. else
  1830. {
  1831. $fgldata[$v['shop'].'-'.$v['userid']] += 1;
  1832. }
  1833. $zkh[$v['shop']][$v['userid']] = array();
  1834. }
  1835. **/
  1836. }
  1837. foreach ($sd as $v) {
  1838. //避免由于作用域引起的问题
  1839. $tmp_v = $v;
  1840. $fdl_result = array_filter($dlz, function ($item) use ($tmp_v) {
  1841. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1842. return false;
  1843. } else {
  1844. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1845. }
  1846. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1847. });
  1848. $fdl = count($fdl_result) > 1 ? 1 : 0; //返单
  1849. $chl_result = array_filter($dlz, function ($item) use ($tmp_v) {
  1850. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1851. return false;
  1852. } else {
  1853. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1854. }
  1855. //return $item['email'] === $tmp_v['email'] && $item['shop'] !== $tmp_v['email'];
  1856. });
  1857. $chl = count($chl_result) > 1 ? 1 : 0; //重合
  1858. $fgl_result = array_filter($dlzemail, function ($item) use ($tmp_v) {
  1859. if (!isset($item['email']) || !isset($tmp_v['email']) || !isset($item['shop'])) {
  1860. return false;
  1861. } else {
  1862. return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1863. }
  1864. //return $item['email'] === $tmp_v['email'] && $item['shop'] === $tmp_v['email'];
  1865. });
  1866. $fgl = count($fgl_result) > 1 ? 1 : 0; //复购
  1867. $shopdata[$v['shop']]['fdl'] = $shopdata[$v['shop']]['fdl'] + $fdl;
  1868. $shopdata[$v['shop']]['chl'] = $shopdata[$v['shop']]['chl'] + $chl;
  1869. $shopdata[$v['shop']]['fgl'] = $shopdata[$v['shop']]['fgl'] + $fgl;
  1870. $shopdata[$v['shop']]['num'] += 1;
  1871. /**
  1872. $chl = 0;
  1873. if(isset($shopdata[$v['shop']]))
  1874. {
  1875. if(isset($v['email']))
  1876. {
  1877. if(isset($customer[$v['shop'].'-'.$v['email']]['num']))
  1878. {
  1879. $fdl = $customer[$v['shop'].'-'.$v['email']]['num']>1?1:0;
  1880. }
  1881. else
  1882. {
  1883. $fdl = 0;
  1884. }
  1885. foreach ($ys as $vv)
  1886. {
  1887. if($vv['id'] != $v['shop'] && isset($customer[$vv['id'].'-'.$v['email']]))
  1888. {
  1889. $chl = 1;
  1890. }
  1891. }
  1892. if(isset($fgldata[$v['shop'].'-'.$v['email']]))
  1893. {
  1894. $fgl = $fgldata[$v['shop'].'-'.$v['email']]>0?1:0;
  1895. }
  1896. else
  1897. {
  1898. $fgl = 0;
  1899. }
  1900. }
  1901. else
  1902. {
  1903. if(isset($customersmt[$v['shop'].'-'.$v['userid']]['num']))
  1904. {
  1905. $fdl = $customersmt[$v['shop'].'-'.$v['userid']]['num']>1?1:0;
  1906. }
  1907. else
  1908. {
  1909. $fdl = 0;
  1910. }
  1911. foreach ($ys as $vv)
  1912. {
  1913. if($vv['id'] != $v['shop'] && isset($customersmt[$vv['id'].'-'.$v['userid']]))
  1914. {
  1915. $chl = 1;
  1916. }
  1917. }
  1918. if(isset($fgldata[$v['shop'].'-'.$v['userid']]))
  1919. {
  1920. $fgl = $fgldata[$v['shop'].'-'.$v['userid']]>0?1:0;
  1921. }
  1922. else
  1923. {
  1924. $fgl = 0;
  1925. }
  1926. }
  1927. }
  1928. **/
  1929. }
  1930. }
  1931. }
  1932. foreach ($shopdata as $k => $v) {
  1933. $shopdata[$k]['fdl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['fdl'] / $v['num'] * 100)) . '%';
  1934. $shopdata[$k]['chl'] = $v['num'] == '0' ? 0 : sprintf("%01.2f", ($v['chl'] / $v['num'] * 100)) . '%';
  1935. $shopdata[$k]['fgl'] = count($zkh[$v['id']]) == '0' ? 0 : sprintf("%01.2f", ($v['fgl'] / count($zkh[$v['id']]) * 100)) . '%';
  1936. }
  1937. $shopdata = array_values($shopdata);
  1938. $zhcxdata[$vval][$value] = array('shopdata' => $shopdata, 'success' => true);
  1939. }
  1940. }
  1941. //zhcx结束
  1942. $myfile = fopen("./data/tj/" . $pdtime . ".txt", "w") or die("Unable to open file!");
  1943. $txt = json_encode(array('zzt' => $zzt, 'tj' => $zqtdata, 'zhcx' => $zhcxdata));
  1944. fwrite($myfile, $txt);
  1945. fclose($myfile);
  1946. echo 1;
  1947. }
  1948. public function _statistics_hb(){
  1949. if (isset($_SESSION['api'])) {
  1950. $user = $this->user->get_api($_SESSION['api']);
  1951. $usp = $user;
  1952. $fgshop = "";
  1953. $sid = "";
  1954. $user = explode('|', trim($user['shop'], '|'));
  1955. foreach ($user as $value) {
  1956. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  1957. $fgshop .= " shop = " . $value . " or";
  1958. }
  1959. $sid .= " id = " . $value . " or";
  1960. }
  1961. }
  1962. $source = $this->input->post('source');
  1963. $time = $this->input->post('time');
  1964. $tab = $this->input->post('tab');
  1965. $table_name = $this->input->post('table_name');
  1966. if(empty($table_name)){
  1967. $table_name = 'fullorder';
  1968. }
  1969. if($tab == 2){
  1970. $now_time = [];
  1971. $timedata = explode('|', $time);
  1972. $ktime = strtotime($timedata[0]);
  1973. $jtime = strtotime($timedata[1]);
  1974. $ktime = $ktime - ($jtime - $ktime);
  1975. $k = $ktime;
  1976. $j = $jtime;
  1977. $n = ($j - $k) / (24 * 3600);
  1978. $usat = $jtime;
  1979. for ($i = 1; $i < $n; $i++) {
  1980. //近7天时间
  1981. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  1982. if ($n > 13 && $i > $n / 2 || $n < 14) {
  1983. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  1984. $now_time[] = date('Y-m-d', $t);
  1985. }
  1986. }
  1987. $k_tmp_time = strtotime($now_time[0]);
  1988. $e_tmp_time = strtotime($now_time[count($now_time) - 1] ) + 24 * 3600;
  1989. $ll_time = ($e_tmp_time - $k_tmp_time) ;
  1990. // var_dump(date("Y-m-d H:i:s", $k_tmp_time)."=========".date("Y-m-d H:i:s", $e_tmp_time));
  1991. // var_dump(date("Y-m-d H:i:s", $k_tmp_time - $ll_time)."=========".date("Y-m-d H:i:s", $k_tmp_time));
  1992. // die;
  1993. $k_time = $k_tmp_time - $ll_time;
  1994. $j_time = $k_tmp_time;
  1995. // $timedata = explode('|', $time);
  1996. // $ktime = strtotime($timedata[0]) + 24 * 3600;
  1997. // $jtime = strtotime($timedata[1]);
  1998. // $ll_time = ($jtime - $ktime);
  1999. // $k_time = $ktime - $ll_time ;
  2000. // $j_time = $jtime - $ll_time;
  2001. $where = "( dtime >= ".$k_time." and dtime <= ".$j_time." ) ";
  2002. }else{
  2003. $k_time = "";
  2004. $j_time = "";
  2005. if($time >= 691200){
  2006. $k_time = strtotime(date("Ymd", time())) - $time+ 24 * 3600;
  2007. $j_time = strtotime(date("Ymd", time()));
  2008. $k_hb_time = $k_time - $time + 24 * 3600;
  2009. $j_hb_time = $k_time;
  2010. }else{
  2011. $k_time = strtotime(date("Ymd", time())) - $time + 24 * 3600;
  2012. $j_time = $k_time + 24 * 3600;
  2013. $k_hb_time = $k_time - 24 * 3600;
  2014. $j_hb_time = $j_time - 24 * 3600;
  2015. }
  2016. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  2017. }
  2018. if ($source) {
  2019. if ($source == '2d') {
  2020. $where .= " and source >= '2' ";
  2021. } else {
  2022. $where .= " and source = '$source' ";
  2023. }
  2024. }
  2025. if($table_name == 'fullordertt' || $table_name == 'fullorderamz'){
  2026. $where .= " and state != 217 ";
  2027. }
  2028. $list = $this->$table_name->find_all($where . " and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'budget,shouldmoney,shop,number,refundy,budget,email,refundy');
  2029. $sl = count($list);
  2030. $je = sprintf("%01.2f", array_sum(array_column($list, 'shouldmoney')));
  2031. $ssje = 0;
  2032. //实收金额
  2033. $dlzmss = sprintf("%01.2f", array_sum(array_column($list, 'budget')));
  2034. //实收金额
  2035. //补/退原额
  2036. $dlzbty = sprintf("%01.2f", array_sum(array_column($list, 'refundy')));
  2037. $ssje = sprintf("%01.2f", $dlzmss + $dlzbty);
  2038. echo json_encode([
  2039. 'status' => 1,
  2040. 'data' => [
  2041. 'sl' => $sl,
  2042. 'je' => $je,
  2043. 'ssje' => $ssje,
  2044. ]
  2045. ]);
  2046. exit; //,'sycp'=>$sycp昨日产品数据
  2047. }
  2048. public function _statistics_tb(){
  2049. if (isset($_SESSION['api'])) {
  2050. $user = $this->user->get_api($_SESSION['api']);
  2051. $usp = $user;
  2052. $fgshop = "";
  2053. $sid = "";
  2054. $user = explode('|', trim($user['shop'], '|'));
  2055. foreach ($user as $value) {
  2056. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  2057. $fgshop .= " shop = " . $value . " or";
  2058. }
  2059. $sid .= " id = " . $value . " or";
  2060. }
  2061. }
  2062. $source = $this->input->post('source');
  2063. $time = $this->input->post('time');
  2064. $tab = $this->input->post('tab');
  2065. $table_name = $this->input->post('table_name');
  2066. if(empty($table_name)){
  2067. $table_name = 'fullorder';
  2068. }
  2069. if($tab == 2){
  2070. $now_time = [];
  2071. $timedata = explode('|', $time);
  2072. $ktime = strtotime($timedata[0]);
  2073. $jtime = strtotime($timedata[1]);
  2074. $ktime = $ktime - ($jtime - $ktime);
  2075. $k = $ktime;
  2076. $j = $jtime;
  2077. $n = ($j - $k) / (24 * 3600);
  2078. $usat = $jtime;
  2079. for ($i = 1; $i < $n; $i++) {
  2080. //近7天时间
  2081. //$t = ($usat-16*3600)-($n*24*60*60)+($i*24*60*60);
  2082. if ($n > 13 && $i > $n / 2 || $n < 14) {
  2083. $t = $usat - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
  2084. $now_time[] = date('Y-m-d', $t);
  2085. }
  2086. }
  2087. $k_tmp_time = strtotime($now_time[0]);
  2088. $e_tmp_time = strtotime($now_time[count($now_time) - 1] ) + 24 * 3600;
  2089. $k_hb_time = $k_tmp_time - 365*24*3600;
  2090. $j_hb_time = $e_tmp_time - 365*24*3600;
  2091. // var_dump(date("Y-m-d H:i:s", $k_tmp_time)."=========".date("Y-m-d H:i:s", $e_tmp_time));
  2092. // var_dump(date("Y-m-d H:i:s", $k_hb_time)."=========".date("Y-m-d H:i:s", $j_hb_time));
  2093. // die;
  2094. // $timedata = explode('|', $time);
  2095. // $ktime = strtotime($timedata[0]) + 24 * 3600;
  2096. // $jtime = strtotime($timedata[1]);
  2097. // $ll_time = ($jtime - $ktime);
  2098. // $k_time = $ktime - $ll_time ;
  2099. // $j_time = $jtime - $ll_time;
  2100. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  2101. }else{
  2102. $k_time = "";
  2103. $j_time = "";
  2104. if($time >= 691200){
  2105. $k_time = strtotime(date("Ymd", time())) - $time+ 24 * 3600;
  2106. $j_time = strtotime(date("Ymd", time()));
  2107. $k_hb_time = $k_time - 365*24*3600;
  2108. $j_hb_time = $j_time - 365*24*3600;
  2109. }else{
  2110. $k_time = strtotime(date("Ymd", time())) - $time + 24 * 3600;
  2111. $j_time = $k_time + 24 * 3600;
  2112. $k_hb_time = $k_time - 365*24*3600;
  2113. $j_hb_time = $j_time - 365*24*3600;
  2114. }
  2115. // var_dump(date("Y-m-d H:i:s", $k_time)."=========".date("Y-m-d H:i:s", $j_time));
  2116. // var_dump(date("Y-m-d H:i:s", $k_hb_time)."=========".date("Y-m-d H:i:s", $j_hb_time));
  2117. // die;
  2118. $where = "( dtime >= ".$k_hb_time." and dtime <= ".$j_hb_time." ) ";
  2119. }
  2120. if ($source) {
  2121. if ($source == '2d') {
  2122. $where .= " and source >= '2' ";
  2123. } else {
  2124. $where .= " and source = '$source' ";
  2125. }
  2126. }
  2127. if($table_name == 'fullordertt' || $table_name == 'fullorderamz'){
  2128. $where .= " and state != 217 ";
  2129. }
  2130. $list = $this->$table_name->find_all($where . " and shop != '0' and (" . rtrim($fgshop, 'or') . ") and shop != '18' and shop != '19'", 'budget,shouldmoney,shop,number,refundy,budget,email,refundy');
  2131. $sl = count($list);
  2132. $je = sprintf("%01.2f", array_sum(array_column($list, 'shouldmoney')));
  2133. $ssje = 0;
  2134. //实收金额
  2135. $dlzmss = sprintf("%01.2f", array_sum(array_column($list, 'budget')));
  2136. //实收金额
  2137. //补/退原额
  2138. $dlzbty = sprintf("%01.2f", array_sum(array_column($list, 'refundy')));
  2139. $ssje = sprintf("%01.2f", $dlzmss + $dlzbty);
  2140. echo json_encode([
  2141. 'status' => 1,
  2142. 'data' => [
  2143. 'sl' => $sl,
  2144. 'je' => $je,
  2145. 'ssje' => $ssje,
  2146. ]
  2147. ]);
  2148. exit; //,'sycp'=>$sycp昨日产品数据
  2149. }
  2150. public function _user_lvceshi(){
  2151. $dt = 0;
  2152. if (isset($_SESSION['api'])) {
  2153. $user = $this->user->get_api($_SESSION['api']);
  2154. $usp = $user;
  2155. $fgshop = "";
  2156. $sid = "";
  2157. $user = explode('|', trim($user['shop'], '|'));
  2158. foreach ($user as $value) {
  2159. // 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')
  2160. // {
  2161. // $fgshop .= " shop = ".$value." or";
  2162. // }
  2163. if (!in_array($value, [9, 12, 13, 15, 18, 19, 21, 27, 28, 29, 30, 34,56])) {
  2164. $fgshop .= " shop = " . $value . " or";
  2165. }
  2166. $sid .= " id = " . $value . " or";
  2167. }
  2168. }
  2169. $post = $this->input->post(NULL, TRUE);
  2170. $source = $this->input->post('source', true);
  2171. $where = "";
  2172. if ($source) {
  2173. if ($source == '2d') {
  2174. $where = " and source >= '2'";
  2175. } else {
  2176. $where = " and source = '$source'";
  2177. }
  2178. }
  2179. $tm = strtotime(date("Ymd"), time());
  2180. $usat = $tm;
  2181. $wlshop = $this->shop->find_all('status = 0 and ' . rtrim($sid, 'or'));
  2182. $this->data['wlshop'] = $wlshop;
  2183. $dr = $usat;
  2184. $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));
  2185. $this->_Template('phone/p_user_statistics_copy', $this->data);
  2186. }
  2187. }