StatisticsController.class.php 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Controller;
  15. use Admin\Model\OrderModel;
  16. class StatisticsController extends CommonController{
  17. protected function _initialize(){
  18. parent::_initialize();
  19. }
  20. public function index_data()
  21. {
  22. global $_W;
  23. global $_GPC;
  24. $type = 'normal';
  25. $member_count = D('Seller/User')->get_member_count();
  26. $total_where = "";
  27. switch( $type )
  28. {
  29. case 'normal':
  30. $result = array();
  31. //今日
  32. $today_time = strtotime( date('Y-m-d').' 00:00:00' );
  33. $today_member_count = D('Seller/User')->get_member_count(" and create_time > ".$today_time );
  34. //今日会员数量
  35. $result['today_member_count'] = $today_member_count;
  36. $result['total_tixian_money'] = 0;
  37. $result['total_commiss_money'] = 0;
  38. $result['total_order_money'] = 0;
  39. //今日付款订单
  40. //--begin
  41. if (defined('ROLE') && ROLE == 'agenter' )
  42. {
  43. $supper_info = get_agent_logininfo();
  44. $total_where = " and supply_id= ".$supper_info['id'];
  45. $order_ids_list = M()->query("select og.order_id,o.total,o.packing_fare,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  46. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." and o.pay_time > {$today_time} and o.type <> 'integral' ");
  47. //and o.order_status_id in (1,4,6,7,11,14)
  48. $order_ids_arr = array();
  49. foreach($order_ids_list as $vv)
  50. {
  51. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  52. {
  53. $order_ids_arr[$vv['order_id']] = $vv;
  54. }
  55. }
  56. $result['today_pay_order_count'] = count($order_ids_arr);
  57. $today_pay_money = 0;
  58. foreach($order_ids_arr as $vv)
  59. {
  60. $today_pay_money += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money']+$vv['packing_fare'];
  61. }
  62. $today_pay_money = empty($today_pay_money) ? 0:$today_pay_money;
  63. $result['today_pay_money'] = sprintf("%.2f",$today_pay_money);
  64. }else{
  65. $today_pay_where = " {$total_where} and pay_time > {$today_time} and type <> 'integral' ";
  66. //and order_status_id in (1,4,6,7,11,14)
  67. $today_pay_order_count = D('Seller/Order')->get_order_count($today_pay_where);
  68. $result['today_pay_order_count'] = $today_pay_order_count;
  69. //get_order_sum($field=' sum(total) as total ' , $where = '',$uniacid = 0)
  70. //total
  71. $today_pay_money_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money-fare_shipping_free+packing_fare) as total ' , $today_pay_where);
  72. $today_pay_money = empty($today_pay_money_info['total']) ? 0:$today_pay_money_info['total'];
  73. $result['today_pay_money'] = sprintf("%.2f",$today_pay_money);
  74. }
  75. //--end
  76. //$result['total_order_money'] = 0;
  77. if (defined('ROLE') && ROLE == 'agenter' )
  78. {
  79. $supper_info = get_agent_logininfo();
  80. $goods_count = M('lionfish_comshop_good_common')->where( array('supply_id' => $supper_info['id'] ) )->count();
  81. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".
  82. C('DB_PREFIX')."lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id'] );
  83. $order_ids_arr = array();
  84. $order_ids_arr_dan = array();
  85. $total_money = 0;
  86. $total_count = 0;
  87. foreach($order_ids_list as $vv)
  88. {
  89. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  90. {
  91. $order_ids_arr[$vv['order_id']] = $vv;
  92. $order_ids_arr_dan[] = $vv['order_id'];
  93. }
  94. }
  95. if( !empty($order_ids_arr_dan) )
  96. {
  97. $sql = 'SELECT count(o.order_id) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_order as o where ' . " o.order_id in (".implode(',', $order_ids_arr_dan).") " ;
  98. $total_arr = M()->query($sql);
  99. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money,o.packing_fare from ".C('DB_PREFIX').
  100. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." ");
  101. $total_count = count($order_ids_list);
  102. if( !empty($order_ids_list) )
  103. {
  104. foreach($order_ids_list as $vv)
  105. {
  106. $total_money += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money']+$vv['packing_fare'];
  107. }
  108. }
  109. }
  110. $result['total_order_count'] = $total_count;
  111. $result['total_order_money'] = empty($total_money) ? 0: sprintf("%.2f",$total_money);
  112. }else{
  113. $total_tixian_money_all = M('lionfish_community_head_tixian_order')->where( "state = 0" )->sum('money');
  114. $total_tixian_money_service_fare = M('lionfish_community_head_tixian_order')->where("state = 0")->sum('service_charge');
  115. $result['total_tixian_money'] = sprintf("%.2f",$total_tixian_money_all - $total_tixian_money_service_fare);
  116. /**
  117. $total_commiss_money_all = pdo_fetchcolumn('SELECT sum(money) as total_money FROM ' . tablename('lionfish_community_head_tixian_order') .
  118. ' WHERE uniacid= '.$_W['uniacid'] . " and state = 1 ");
  119. $total_commiss_money_service_fare = pdo_fetchcolumn('SELECT sum(service_charge) as total_service_charge FROM ' . tablename('lionfish_community_head_tixian_order') .
  120. ' WHERE uniacid= '.$_W['uniacid'] . " and state = 1 ");
  121. $result['total_commiss_money'] = sprintf("%.2f",$total_commiss_money_all - $total_commiss_money_service_fare);
  122. **/
  123. $total_commiss_money_all = M('lionfish_community_head_commiss_order')->where( "state = 1 or state =0" )->sum('money');
  124. $result['total_commiss_money'] = sprintf("%.2f",$total_commiss_money_all);
  125. //C('DB_PREFIX')
  126. $sq_s = "SELECT sum(total+shipping_fare-voucher_credit-fullreduction_money-fare_shipping_free+packing_fare) as total FROM ".
  127. C('DB_PREFIX')."lionfish_comshop_order where order_status_id in (1,4,6,11,12,14) and type <> 'integral' ";
  128. $total_order_money_arr = M()->query($sq_s);
  129. $total_order_money = $total_order_money_arr[0]['total'];
  130. $result['total_order_money'] = empty($total_order_money) ? 0: sprintf("%.2f",$total_order_money);
  131. }
  132. //会员数量
  133. $result['member_count'] = $member_count;
  134. //商品数量
  135. if (defined('ROLE') && ROLE == 'agenter' ) {
  136. $supper_info = get_agent_logininfo();
  137. $goods_count = M('lionfish_comshop_good_common')->where( array('supply_id' => $supper_info['id'] ) )->count();
  138. }else{
  139. $goods_count = D('Seller/Goods')->get_goods_count();
  140. }
  141. $result['goods_count'] = $goods_count;
  142. //团长数量
  143. //ims_ lionfish_community_head
  144. $community_head_count = M('lionfish_community_head')->count();
  145. $result['community_head_count'] = $community_head_count;
  146. //待付款订单
  147. if (defined('ROLE') && ROLE == 'agenter' )
  148. {
  149. $supper_info = get_agent_logininfo();
  150. $total_where = " and supply_id= ".$supper_info['id'];
  151. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  152. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." and o.order_status_id =3 ");
  153. $order_ids_arr = array();
  154. foreach($order_ids_list as $vv)
  155. {
  156. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  157. {
  158. $order_ids_arr[$vv['order_id']] = $vv;
  159. }
  160. }
  161. $result['wait_pay_order_count'] = count($order_ids_arr);
  162. }else{
  163. $wait_pay_order_count = D('Seller/Order')->get_order_count(" and order_status_id =3 {$total_where}");
  164. $result['wait_pay_order_count'] = $wait_pay_order_count;
  165. }
  166. //待发货订单 1
  167. if (defined('ROLE') && ROLE == 'agenter' )
  168. {
  169. $supper_info = get_agent_logininfo();
  170. $total_where = " and supply_id= ".$supper_info['id'];
  171. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  172. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." and o.order_status_id =1 ");
  173. $order_ids_arr = array();
  174. foreach($order_ids_list as $vv)
  175. {
  176. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  177. {
  178. $order_ids_arr[$vv['order_id']] = $vv;
  179. }
  180. }
  181. $result['wait_order_count'] = count($order_ids_arr);
  182. }else{
  183. $wait_order_count = D('Seller/Order')->get_order_count(" and order_status_id =1 and type != 'ignore' ");
  184. $order_info = M('lionfish_comshop_order')->where( "order_status_id =1 and type != 'ignore'")->order('order_id desc')->find();
  185. $result['wait_order_type'] = $order_info['type'];
  186. $result['wait_order_count'] = $wait_order_count;
  187. }
  188. //售后中订单
  189. if (defined('ROLE') && ROLE == 'agenter' )
  190. {
  191. $supper_info = get_agent_logininfo();
  192. $total_where = " and supply_id= ".$supper_info['id'];
  193. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  194. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." and o.order_status_id =12 ");
  195. $order_ids_arr = array();
  196. foreach($order_ids_list as $vv)
  197. {
  198. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  199. {
  200. $order_ids_arr[$vv['order_id']] = $vv;
  201. }
  202. }
  203. $result['after_sale_order_count'] = count($order_ids_arr);
  204. }else{
  205. $after_sale_order_count = D('Seller/Order')->get_order_count(" and order_status_id = 12 ");
  206. $result['after_sale_order_count'] = $after_sale_order_count;
  207. }
  208. if (defined('ROLE') && ROLE == 'agenter' )
  209. {
  210. $supper_info = get_agent_logininfo();
  211. $total_where = " and supply_id= ".$supper_info['id'];
  212. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  213. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." and o.order_status_id =6 ");
  214. $order_ids_arr = array();
  215. foreach($order_ids_list as $vv)
  216. {
  217. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  218. {
  219. $order_ids_arr[$vv['order_id']] = $vv;
  220. }
  221. }
  222. $result['wai_comment_order_count'] = count($order_ids_arr);
  223. }else{
  224. $wai_comment_order_count = D('Seller/Order')->get_order_count(" and order_status_id = 6 ");
  225. $result['wai_comment_order_count'] = $wai_comment_order_count;
  226. }
  227. $result['wait_shen_order_comment_count'] = D('Seller/Order')->get_wait_shen_order_comment();
  228. $result['stock_goods_count'] = D('Seller/Goods')->get_goods_count(' and grounding =2 ');
  229. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  230. $end_time = time();
  231. //7天订单数量
  232. if (defined('ROLE') && ROLE == 'agenter' ) {
  233. $supper_info = get_agent_logininfo();
  234. $total_where = " and supply_id= ".$supper_info['id'];
  235. $order_ids_list = M()->query("select og.order_id,o.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  236. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." and o.date_added>={$begin_time} and o.date_added< {$end_time} ");
  237. $order_ids_arr = array();
  238. foreach($order_ids_list as $vv)
  239. {
  240. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  241. {
  242. $order_ids_arr[$vv['order_id']] = $vv;
  243. }
  244. }
  245. $result['seven_order_count'] = count($order_ids_arr);
  246. }else{
  247. $seven_order_count = D('Seller/Order')->get_order_count(" and date_added>={$begin_time} and date_added< {$end_time} {$total_where} ");
  248. $result['seven_order_count'] = $seven_order_count;
  249. }
  250. //7天的订单总金额
  251. if (defined('ROLE') && ROLE == 'agenter' ) {
  252. $supper_info = get_agent_logininfo();
  253. $total_where = " and supply_id= ".$supper_info['id'];
  254. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  255. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." and o.pay_time > {$begin_time} ");
  256. //and o.order_status_id in (1,4,6,11,14)
  257. $order_ids_arr = array();
  258. $seven_pay_money= 0;
  259. foreach($order_ids_list as $vv)
  260. {
  261. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  262. {
  263. $order_ids_arr[$vv['order_id']] = $vv;
  264. $seven_pay_money += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  265. }
  266. }
  267. $seven_pay_money = empty($seven_pay_money) ? 0:$seven_pay_money;
  268. $result['seven_pay_money'] = $seven_pay_money;
  269. }else{
  270. $seven_pay_where = " pay_time > {$begin_time} ";
  271. //and order_status_id in (1,4,6,11,14)
  272. $seven_pay_money = M('lionfish_comshop_order')->where($seven_pay_where)->sum('total+shipping_fare-voucher_credit-fullreduction_money-fare_shipping_free');
  273. //->get_order_sum(' sum() as total ' , $seven_pay_where);
  274. $seven_pay_money = empty($seven_pay_money) ? 0:$seven_pay_money;
  275. $result['seven_pay_money'] = sprintf("%.2f",$seven_pay_money);
  276. }
  277. //7天订单总退款金额
  278. if (defined('ROLE') && ROLE == 'agenter' ) {
  279. $supper_info = get_agent_logininfo();
  280. $total_where = " and supply_id= ".$supper_info['id'];
  281. $seven_refund_money_arr = M()->query("select sum(money) as money from ".C('DB_PREFIX').
  282. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund as ogr where og.order_goods_id = ogr.order_goods_id and og.supply_id = ".$supper_info['id']." and ogr.addtime > {$begin_time} ");
  283. $seven_refund_money= $seven_refund_money_arr[0]['money'];
  284. $seven_refund_money = empty($seven_refund_money) ? 0:$seven_refund_money;
  285. $result['seven_refund_money'] = sprintf("%.2f",$seven_refund_money);
  286. }else{
  287. $seven_refund_pay_where = " addtime > {$begin_time} ";
  288. $seven_refund_money = M('lionfish_comshop_order_goods_refund')->where($seven_refund_pay_where)->sum('money');
  289. $seven_refund_money = empty($seven_refund_money) ? 0:$seven_refund_money;
  290. $result['seven_refund_money'] = sprintf("%.2f",$seven_refund_money);
  291. }
  292. $goods_stock_notice = D('Home/Front')->get_config_by_name('goods_stock_notice');
  293. if( empty($goods_stock_notice) )
  294. {
  295. $goods_stock_notice = 0;
  296. }
  297. //库存预警商品数量
  298. $goods_stock_notice_count = D('Seller/Goods')->get_goods_count(" and grounding = 1 and total <= ".$goods_stock_notice." and grounding = 1 and type = 'normal' ");
  299. $result['goods_stock_notice_count'] = $goods_stock_notice_count;
  300. $apply_count = M('lionfish_community_head_tixian_order')->where("state=0")->count();
  301. $result['apply_count'] = $apply_count;
  302. echo json_encode( array('code' => 0, 'data' => $result) );
  303. die();
  304. break;
  305. case 'pintuan':
  306. $result = array();
  307. echo json_encode( array('code' => 0, 'data' => $result) );
  308. die();
  309. break;
  310. }
  311. }
  312. function order_buy_data()
  313. {
  314. //成交量(件) //成交额(元) 人均消费
  315. $gpc = I('request.');
  316. $type = isset($gpc['type']) ? $gpc['type']:'normal';
  317. $s_index = isset($gpc['s_index']) ? $gpc['s_index']:2;
  318. $begin_time = 0;
  319. $end_time = 0;
  320. //var json = {"success":true,"data":{"date":"0001-01-01 00:00:00","visits":3080,"orderUsers":24,"orderCount":52,"orderProducts":69,"orderAmount":14986.83,"payUsers":16,"payOrders":25,"payProducts":36,"payAmount":4380.31,"refundProducts":4,"refundOrderCounts":8,"refundAmount":1899.04,"refundRate":32.00,"preOrderRate":175.21,"preProductRate":121.68,"jointRate":1.44,"orderRate":1.69,"payRate":48.08,"tradeRate":0.81,"payAmountRank":1,"brokerageAmount":0.00,"lines":{"payAmountLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0.00,3196.00,0.20,162.14,379.01,642.96,0.00,0.0]}]},"payUserLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0,1,2,2,6,5,0,0]}]},"payProductLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0,3,2,13,10,8,0,0]}]},"orderRateLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0.0,4.00,1.22,1.53,2.74,1.52,1.00,0.0]}]},"payRateLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0.0,75.00,33.33,77.78,35.00,50.0,0.0,0.0]}]},"tradeRateLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0.0,3.00,0.41,1.19,0.96,0.76,0.0,0.0]}]}}}};
  321. switch( $s_index )
  322. {
  323. case 0:
  324. //今日
  325. $begin_time = strtotime( date('Y-m-d').' 00:00:00' );
  326. $end_time = $begin_time + 86400;
  327. break;
  328. case 1:
  329. //昨日
  330. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 86400;
  331. $end_time = $begin_time + 86400;
  332. break;
  333. case 2:
  334. //最近七日
  335. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  336. $end_time = time();
  337. break;
  338. case 3:
  339. //本月
  340. $begin_time = strtotime( date('Y-m').'-01 00:00:00' );
  341. $end_time = time();
  342. break;
  343. }
  344. switch( $type )
  345. {
  346. case 'normal':
  347. $result = array();
  348. if (!defined('ROLE') && ROLE != 'agenter' )
  349. {
  350. $where = " and type = 'normal' and date_added >= {$begin_time} and date_added <={$end_time} ";
  351. $count = D('Seller/Order')->get_order_count($where);
  352. $sum_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money-fare_shipping_free) as total ' , $where);
  353. $total = $sum_info['total'];
  354. }else{
  355. $supper_info = get_agent_logininfo();
  356. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  357. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." and og.addtime >= {$begin_time} and og.addtime <={$end_time} ");
  358. $count = count($order_ids_list);
  359. $order_ids_arr = array();
  360. $sum_info = array('total' => 0);
  361. foreach($order_ids_list as $vv)
  362. {
  363. $sum_info['total'] += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  364. }
  365. $total = $sum_info['total'];
  366. }
  367. if($count > 0)
  368. {
  369. $per_money = $total / $count;
  370. } else{
  371. $per_money = 0;
  372. }
  373. $result['count'] = $count;
  374. $result['total'] = round($total,2);
  375. $result['per_money'] = round($per_money,2);
  376. echo json_encode( array('code' => 0, 'data' => $result) );
  377. die();
  378. break;
  379. case 'pintuan':
  380. $result = array();
  381. $where = " and type = 'pintuan' and date_added >= {$begin_time} and date_added <={$end_time} ";
  382. $count = load_model_class('order')->get_order_count($where);
  383. //total
  384. $sum_info = load_model_class('order')->get_order_sum(' sum(total) as total ' , $where);
  385. $total = $sum_info['total'];
  386. if($count > 0)
  387. {
  388. $per_money = $total / $count;
  389. } else{
  390. $per_money = 0;
  391. }
  392. $result['count'] = $count;
  393. $result['total'] = round($total,2);
  394. $result['per_money'] = round($per_money,2);
  395. echo json_encode( array('code' => 0, 'data' => $result) );
  396. die();
  397. break;
  398. }
  399. //s_index
  400. }
  401. //----
  402. public function load_echat_member_incr()
  403. {
  404. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  405. $end_time = time();
  406. $date_arr = array();
  407. $member_count_arr = array();
  408. for($i =7; $i>=1; $i--)
  409. {
  410. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - $i * 86400;
  411. $end_time = $begin_time + 86400;
  412. $member_count = M('lionfish_comshop_member')->where("create_time >= ".$begin_time." and create_time < ".$end_time)->count();
  413. $date_arr[] = date('m-d', $begin_time);
  414. $member_count_arr[] = $member_count;
  415. }
  416. echo json_encode( array('code' => 0, 'date_arr' => $date_arr, 'member_count' => $member_count_arr ) );
  417. die();
  418. }
  419. public function load_echat_head_incr()
  420. {
  421. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  422. $end_time = time();
  423. $date_arr = array();
  424. $member_count_arr = array();
  425. for($i =7; $i>=1; $i--)
  426. {
  427. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - $i * 86400;
  428. $end_time = $begin_time + 86400;
  429. $member_count = M('lionfish_community_head')->where( "state = 1 and addtime >= ".$begin_time." and addtime < ".$end_time )->count();
  430. $date_arr[] = date('m-d', $begin_time);
  431. $member_count_arr[] = $member_count;
  432. }
  433. echo json_encode( array('code' => 0, 'date_arr' => $date_arr, 'member_count' => $member_count_arr ) );
  434. die();
  435. }
  436. public function load_echat_month_head_sales()
  437. {
  438. $type = I('request.type');
  439. if( $type == 1)
  440. {
  441. $begin_time = strtotime( date('Y-m').'-01 00:00:00' );
  442. $date_month =date('Y-m',$begin_time);
  443. }else{
  444. //$begin_time= strtotime( date("Y-m", strtotime("-1 month")) .'-01 00:00:00' );
  445. $begin_time= strtotime( "first day of last month" ) ;
  446. $date_month =date('Y-m',$begin_time);
  447. }
  448. $end_time = time();
  449. //lionfish_comshop_order 1 4 6 11 14 date_added
  450. $sql = " select sum(total+shipping_fare-voucher_credit-fullreduction_money-fare_shipping_free) as total,head_id from ".C('DB_PREFIX').
  451. "lionfish_comshop_order where date_added >= {$begin_time} and date_added <={$end_time} and order_status_id in(6,11)
  452. group by head_id order by total desc limit 10 ";
  453. $list = M()->query($sql);
  454. $total = 0;
  455. foreach( $list as $key => $val )
  456. {
  457. $hd_info = M('lionfish_community_head')->field('community_name,head_name')->where( array('id' => $val['head_id'] ) )->find();
  458. $val['community_name'] = $hd_info['community_name'];
  459. $val['head_name'] = $hd_info['head_name'];
  460. $val['total'] = sprintf('%.2f',$val['total'] );
  461. $total += $val['total'];
  462. $list[$key] = $val;
  463. }
  464. $total = sprintf('%.2f',$total);
  465. echo json_encode( array('code' => 0, 'list' => $list, 'total' => $total,'month' => $date_month) );
  466. die();
  467. }
  468. //--
  469. public function load_echat_month_goods_sales()
  470. {
  471. $type = I('request.type');
  472. if( $type == 1)
  473. {
  474. $begin_time = strtotime( date('Y-m').'-01 00:00:00' );
  475. $date_month =date('Y-m',$begin_time);
  476. $end_time = time();
  477. }else{
  478. //$begin_time= strtotime( date("Y-m", strtotime("-1 month")) .'-01 00:00:00' );
  479. //2020-02-01 10:32:28
  480. $month_begin_time = strtotime( date('Y-m').'-01 00:00:00' );
  481. $begin_time= strtotime( "first day of last month" ) ;
  482. $date_month =date('Y-m',$begin_time);
  483. $begin_time = strtotime( $date_month.'-01 00:00:00' );
  484. $end_time = $month_begin_time -1;
  485. }
  486. //lionfish_comshop_order 1 4 6 11 14 date_added
  487. $sql = "SELECT og.goods_id,og.name ,sum(og.quantity) as total_quantity,sum( og.total + og.shipping_fare - og.voucher_credit - og.fullreduction_money - og.score_for_money ) as total
  488. FROM ".C('DB_PREFIX')."lionfish_comshop_order_goods as og ,".C('DB_PREFIX')."lionfish_comshop_order as o
  489. where og.order_id = o.order_id and o.type != 'integral' and o.date_added >= {$begin_time} and o.date_added <={$end_time} and o.order_status_id in(6,11) group by og.goods_id order by total desc limit 10 ";
  490. $list = M()->query($sql);
  491. $total = 0;
  492. $total_quantity = 0;
  493. foreach( $list as $key => $val )
  494. {
  495. $val['community_name'] = $hd_info['name'];
  496. $val['head_name'] = $hd_info['name'];
  497. $val['name'] = mb_substr($val['name'],0,8,'utf-8').' '.'销量:'. $val['total_quantity'];
  498. $val['total'] = sprintf('%.2f',$val['total'] );
  499. $total += $val['total'];
  500. $total_quantity += $val['total_quantity'];
  501. $list[$key] = $val;
  502. }
  503. $last_index_sort = array_column($list, 'total_quantity');
  504. array_multisort($last_index_sort, SORT_DESC, $list);
  505. $total = sprintf('%.2f',$total);
  506. echo json_encode( array('code' => 0, 'list' => $list, 'total_quantity' => $total_quantity,'total' => $total,'month' => $date_month) );
  507. die();
  508. }
  509. //---
  510. function load_goods_chart()
  511. {
  512. //成交量(件) //成交额(元) 人均消费
  513. $type = 'normal';
  514. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  515. $end_time = time();
  516. switch( $type )
  517. {
  518. case 'normal':
  519. $result = array();
  520. $count_value = array();
  521. $price_key = array();
  522. $price_value = array();
  523. $price_value_2 = array();
  524. for($i =7; $i>=1; $i--)
  525. {
  526. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - $i * 86400;
  527. $end_time = $begin_time + 86400;
  528. //supply_id
  529. if (!defined('ROLE') || ROLE != 'agenter' ) {
  530. $where = " and date_added >= {$begin_time} and date_added <={$end_time} and order_status_id in(1,4,6,11,14) ";
  531. $where_refund = " and date_added >= {$begin_time} and date_added <={$end_time} and order_status_id in(7) ";
  532. $count = D('Seller/Order')->get_order_count($where);
  533. $sum_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money-fare_shipping_free) as total ' , $where);
  534. $refund_sum_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money-fare_shipping_free) as total ' , $where_refund);
  535. }else{
  536. $supper_info = get_agent_logininfo();
  537. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  538. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." and og.addtime >= {$begin_time} and og.addtime <={$end_time} and o.order_status_id in(1,4,6,11,14) ");
  539. $order_ids_list2 = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  540. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." and og.addtime >= {$begin_time} and og.addtime <={$end_time} and o.order_status_id in(7) ");
  541. if( empty($order_ids_list2) )
  542. {
  543. $refund_sum_info = 0;
  544. }else{
  545. $order_ids_arr = array();
  546. $refund_sum_info = array('total' => 0);
  547. foreach($order_ids_list2 as $vv)
  548. {
  549. $refund_sum_info['total'] += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  550. }
  551. }
  552. if( empty($order_ids_list) )
  553. {
  554. $count = 0;
  555. $sum_info = 0;
  556. }else{
  557. $count = count($order_ids_list);
  558. $order_ids_arr = array();
  559. $sum_info = array('total' => 0);
  560. foreach($order_ids_list as $vv)
  561. {
  562. $sum_info['total'] += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  563. }
  564. }
  565. }
  566. if( empty($sum_info) || empty($sum_info['total']) || $sum_info['total'] < 0)
  567. {
  568. $total = 0;
  569. }else{
  570. $total = $sum_info['total'];
  571. }
  572. if( empty($refund_sum_info) || empty($refund_sum_info['total']) || $refund_sum_info['total'] < 0)
  573. {
  574. $refund_total = 0;
  575. }else{
  576. $refund_total = $refund_sum_info['total'];
  577. }
  578. $price_key[] = date('m-d', $begin_time);
  579. $count_value[] = $count;
  580. $price_value[] = sprintf('%.2f',$total);
  581. $price_value_2[] = sprintf('%.2f',$refund_total);
  582. }
  583. //$json = '{"success":true,"data":{"date":"0001-01-01 00:00:00","visits":3080,"orderUsers":24,"orderCount":52,"orderProducts":69,"orderAmount":14986.83,"payUsers":16,"payOrders":25,"payProducts":36,"payAmount":4380.31,"refundProducts":4,"refundOrderCounts":8,"refundAmount":1899.04,"refundRate":32.00,"preOrderRate":175.21,"preProductRate":121.68,"jointRate":1.44,"orderRate":1.69,"payRate":48.08,"tradeRate":0.81,"payAmountRank":1,"brokerageAmount":0.00,"lines":{"payAmountLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0.00,3196.00,0.20,162.14,379.01,642.96,0.00,0.0]}]},"payUserLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0,1,2,2,6,5,0,0]}]},"payProductLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0,3,2,13,10,8,0,0]}]},"orderRateLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0.0,4.00,1.22,1.53,2.74,1.52,1.00,0.0]}]},"payRateLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0.0,75.00,33.33,77.78,35.00,50.0,0.0,0.0]}]},"tradeRateLine":{"xAxisData":["12-01","12-02","12-03","12-04","12-05","12-06","12-07","12-08"],"seriesData":[{"data":[0.0,3.00,0.41,1.19,0.96,0.76,0.0,0.0]}]}}}}';
  584. $result['lines'] = array();
  585. $result['lines']['payAmountLine']['xAxisData'] = $price_key;
  586. $result['lines']['payAmountLine']['seriesData'][0]['data'] = $price_value;
  587. $result['lines']['payAmountLine']['seriesData'][1]['data'] = $price_value_2;
  588. $result['price_key'] =$price_key;
  589. $result['count_value'] =$count_value;
  590. $result['price_value'] =$price_value;
  591. echo json_encode( array('code' => 0, 'data' => $result) );
  592. die();
  593. break;
  594. case 'pintuan':
  595. $result = array();
  596. $count_value = array();
  597. $price_key = array();
  598. $price_value = array();
  599. for($i =7; $i>=1; $i--)
  600. {
  601. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - $i * 86400;
  602. $end_time = $begin_time + 86400;
  603. $where = " and type = 'pintuan' and date_added >= {$begin_time} and date_added <={$end_time} ";
  604. $count = load_model_class('order')->get_order_count($where);
  605. $sum_info = load_model_class('order')->get_order_sum(' sum(total) as total ' , $where);
  606. if( empty($sum_info) || empty($sum_info['total']))
  607. {
  608. $total = 0;
  609. }else{
  610. $total = $sum_info['total'];
  611. }
  612. $price_key[] = date('Y-m-d', $begin_time);
  613. $count_value[] = $count;
  614. $price_value[] = sprintf('%.2f',$total);
  615. }
  616. //{"price_key":["2018-10-26","2018-10-27","2018-10-28","2018-10-29","2018-10-30","2018-10-31","2018-11-01"],"price_value":[0,0,0,0,0,0,0],"count_value":[0,0,0,0,0,0,0]}
  617. $result['price_key'] =$price_key;
  618. $result['count_value'] =$count_value;
  619. $result['price_value'] =$price_value;
  620. echo json_encode( array('code' => 0, 'data' => $result) );
  621. die();
  622. break;
  623. }
  624. //s_index
  625. }
  626. function load_goods_paihang()
  627. {
  628. //成交量(件) //成交额(元) 人均消费
  629. $gpc = I('request.');
  630. $type = $gpc['type'];
  631. $s_index = $gpc['s_index'];
  632. $begin_time = 0;
  633. $end_time = 0;
  634. switch( $s_index )
  635. {
  636. case 0:
  637. //今日
  638. $begin_time = strtotime( date('Y-m-d').' 00:00:00' );
  639. $end_time = $begin_time + 86400;
  640. break;
  641. case 1:
  642. //昨日
  643. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 86400;
  644. $end_time = $begin_time + 86400;
  645. break;
  646. case 2:
  647. //最近七日
  648. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  649. $end_time = time();
  650. break;
  651. }
  652. $list = array();
  653. switch( $type )
  654. {
  655. case 'normal':
  656. $result = array();
  657. if (!defined('ROLE') || ROLE != 'agenter' )
  658. {
  659. $where = " and addtime >= {$begin_time} and addtime <={$end_time} ";
  660. }else{
  661. $supper_info = get_agent_logininfo();
  662. $where = " and supply_id= ".$supper_info['id']." and addtime >= {$begin_time} and addtime <={$end_time} ";
  663. }
  664. $list = D('Seller/Order')->get_order_goods_group_paihang($where );
  665. break;
  666. case 'pintuan':
  667. $result = array();
  668. $where = " and goods_type='pintuan' and addtime >= {$begin_time} and addtime <={$end_time} ";
  669. $list = D('Seller/Order')->get_order_goods_group_paihang($where );
  670. break;
  671. }
  672. $html = '';
  673. if( !empty($list) )
  674. {
  675. $i =1;
  676. foreach($list as $val)
  677. {
  678. $html .= "<tr>";
  679. $html .= " <td>{$i}</td>";
  680. $html .= " <td><a href='#'>".$val['name']."</a></td>";
  681. $html .= " <td>".$val['total_quantity']."</td>";
  682. $html .= " <td class='text-warning'>".$val['m_total']."</td>";
  683. $html .= " </tr>";
  684. $i++;
  685. }
  686. }
  687. echo json_encode( array('code' => 0, 'html' => $html) );
  688. die();
  689. }
  690. }
  691. ?>