StatisticsController.class.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  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,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.order_status_id in (1,4,6,7,11,14) ");
  47. $order_ids_arr = array();
  48. foreach($order_ids_list as $vv)
  49. {
  50. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  51. {
  52. $order_ids_arr[$vv['order_id']] = $vv;
  53. }
  54. }
  55. $result['today_pay_order_count'] = count($order_ids_arr);
  56. $today_pay_money = 0;
  57. foreach($order_ids_arr as $vv)
  58. {
  59. $today_pay_money += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  60. }
  61. $today_pay_money = empty($today_pay_money) ? 0:$today_pay_money;
  62. $result['today_pay_money'] = sprintf("%.2f",$today_pay_money);
  63. }else{
  64. $today_pay_where = " {$total_where} and pay_time > {$today_time} and order_status_id in (1,4,6,7,11,14) ";
  65. $today_pay_order_count = D('Seller/Order')->get_order_count($today_pay_where);
  66. $result['today_pay_order_count'] = $today_pay_order_count;
  67. //get_order_sum($field=' sum(total) as total ' , $where = '',$uniacid = 0)
  68. //total
  69. $today_pay_money_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money) as total ' , $today_pay_where);
  70. $today_pay_money = empty($today_pay_money_info['total']) ? 0:$today_pay_money_info['total'];
  71. $result['today_pay_money'] = sprintf("%.2f",$today_pay_money);
  72. }
  73. //--end
  74. //$result['total_order_money'] = 0;
  75. if (defined('ROLE') && ROLE == 'agenter' )
  76. {
  77. $supper_info = get_agent_logininfo();
  78. $goods_count = M('lionfish_comshop_good_common')->where( array('supply_id' => $supper_info['id'] ) )->count();
  79. }else{
  80. $total_tixian_money_all = M('lionfish_community_head_tixian_order')->where( "state = 0" )->sum('money');
  81. $total_tixian_money_service_fare = M('lionfish_community_head_tixian_order')->where("state = 0")->sum('service_charge');
  82. $result['total_tixian_money'] = sprintf("%.2f",$total_tixian_money_all - $total_tixian_money_service_fare);
  83. $total_commiss_money_all = M('lionfish_community_head_tixian_order')->where( "state = 1" )->sum('money');
  84. $total_commiss_money_service_fare = M('lionfish_community_head_tixian_order')->where("state = 1")->sum('service_charge');
  85. $result['total_commiss_money'] = sprintf("%.2f",$total_commiss_money_all - $total_commiss_money_service_fare);
  86. //C('DB_PREFIX')
  87. $sq_s = "SELECT sum(total+shipping_fare-voucher_credit-fullreduction_money) as total FROM ".
  88. C('DB_PREFIX')."lionfish_comshop_order where order_status_id in (1,4,6,11,12,14) ";
  89. $total_order_money_arr = M()->query($sq_s);
  90. $total_order_money = $total_order_money_arr[0]['total'];
  91. $result['total_order_money'] = empty($total_order_money) ? 0: sprintf("%.2f",$total_order_money);
  92. }
  93. //会员数量
  94. $result['member_count'] = $member_count;
  95. //商品数量
  96. if (defined('ROLE') && ROLE == 'agenter' ) {
  97. $supper_info = get_agent_logininfo();
  98. $goods_count = M('lionfish_comshop_good_common')->where( array('supply_id' => $supper_info['id'] ) )->count();
  99. }else{
  100. $goods_count = D('Seller/Goods')->get_goods_count();
  101. }
  102. $result['goods_count'] = $goods_count;
  103. //团长数量
  104. //ims_ lionfish_community_head
  105. $community_head_count = M('lionfish_community_head')->count();
  106. $result['community_head_count'] = $community_head_count;
  107. //待付款订单
  108. if (defined('ROLE') && ROLE == 'agenter' )
  109. {
  110. $supper_info = get_agent_logininfo();
  111. $total_where = " and supply_id= ".$supper_info['id'];
  112. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  113. "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 ");
  114. $order_ids_arr = array();
  115. foreach($order_ids_list as $vv)
  116. {
  117. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  118. {
  119. $order_ids_arr[$vv['order_id']] = $vv;
  120. }
  121. }
  122. $result['wait_pay_order_count'] = count($order_ids_arr);
  123. }else{
  124. $wait_pay_order_count = D('Seller/Order')->get_order_count(" and order_status_id =3 {$total_where}");
  125. $result['wait_pay_order_count'] = $wait_pay_order_count;
  126. }
  127. //待发货订单 1
  128. if (defined('ROLE') && ROLE == 'agenter' )
  129. {
  130. $supper_info = get_agent_logininfo();
  131. $total_where = " and supply_id= ".$supper_info['id'];
  132. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  133. "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 ");
  134. $order_ids_arr = array();
  135. foreach($order_ids_list as $vv)
  136. {
  137. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  138. {
  139. $order_ids_arr[$vv['order_id']] = $vv;
  140. }
  141. }
  142. $result['wait_order_count'] = count($order_ids_arr);
  143. }else{
  144. $wait_order_count = D('Seller/Order')->get_order_count(" and order_status_id =1 ");
  145. $result['wait_order_count'] = $wait_order_count;
  146. }
  147. //售后中订单
  148. if (defined('ROLE') && ROLE == 'agenter' )
  149. {
  150. $supper_info = get_agent_logininfo();
  151. $total_where = " and supply_id= ".$supper_info['id'];
  152. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  153. "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 ");
  154. $order_ids_arr = array();
  155. foreach($order_ids_list as $vv)
  156. {
  157. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  158. {
  159. $order_ids_arr[$vv['order_id']] = $vv;
  160. }
  161. }
  162. $result['after_sale_order_count'] = count($order_ids_arr);
  163. }else{
  164. $after_sale_order_count = D('Seller/Order')->get_order_count(" and order_status_id = 12 ");
  165. $result['after_sale_order_count'] = $after_sale_order_count;
  166. }
  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 =6 ");
  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['wai_comment_order_count'] = count($order_ids_arr);
  182. }else{
  183. $wai_comment_order_count = D('Seller/Order')->get_order_count(" and order_status_id = 6 ");
  184. $result['wai_comment_order_count'] = $wai_comment_order_count;
  185. }
  186. $result['wait_shen_order_comment_count'] = D('Seller/Order')->get_wait_shen_order_comment();
  187. $result['stock_goods_count'] = D('Seller/Goods')->get_goods_count(' and grounding =2 ');
  188. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  189. $end_time = time();
  190. //7天订单数量
  191. if (defined('ROLE') && ROLE == 'agenter' ) {
  192. $supper_info = get_agent_logininfo();
  193. $total_where = " and supply_id= ".$supper_info['id'];
  194. $order_ids_list = M()->query("select og.order_id,o.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  195. "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} ");
  196. $order_ids_arr = array();
  197. foreach($order_ids_list as $vv)
  198. {
  199. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  200. {
  201. $order_ids_arr[$vv['order_id']] = $vv;
  202. }
  203. }
  204. $result['seven_order_count'] = count($order_ids_arr);
  205. }else{
  206. $seven_order_count = D('Seller/Order')->get_order_count(" and date_added>={$begin_time} and date_added< {$end_time} {$total_where} ");
  207. $result['seven_order_count'] = $seven_order_count;
  208. }
  209. //7天的订单总金额
  210. if (defined('ROLE') && ROLE == 'agenter' ) {
  211. $supper_info = get_agent_logininfo();
  212. $total_where = " and supply_id= ".$supper_info['id'];
  213. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  214. "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} and o.order_status_id in (1,4,6,11,14) ");
  215. $order_ids_arr = array();
  216. $seven_pay_money= 0;
  217. foreach($order_ids_list as $vv)
  218. {
  219. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  220. {
  221. $order_ids_arr[$vv['order_id']] = $vv;
  222. $seven_pay_money += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  223. }
  224. }
  225. $seven_pay_money = empty($seven_pay_money) ? 0:$seven_pay_money;
  226. $result['seven_pay_money'] = $seven_pay_money;
  227. }else{
  228. $seven_pay_where = " and pay_time > {$begin_time} and order_status_id in (1,4,6,11,14) ";
  229. $seven_pay_money_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money) as total ' , $seven_pay_where);
  230. $seven_pay_money = empty($seven_pay_money_info['total']) ? 0:$seven_pay_money_info['total'];
  231. $result['seven_pay_money'] = sprintf("%.2f",$seven_pay_money);
  232. }
  233. //7天订单总退款金额
  234. if (defined('ROLE') && ROLE == 'agenter' ) {
  235. $supper_info = get_agent_logininfo();
  236. $total_where = " and supply_id= ".$supper_info['id'];
  237. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  238. "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} and o.order_status_id = 7 ");
  239. $order_ids_arr = array();
  240. $seven_refund_money= 0;
  241. foreach($order_ids_list as $vv)
  242. {
  243. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  244. {
  245. $order_ids_arr[$vv['order_id']] = $vv;
  246. $seven_refund_money += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  247. }
  248. }
  249. $seven_refund_money = empty($seven_refund_money) ? 0:$seven_refund_money;
  250. $result['seven_refund_money'] = sprintf("%.2f",$seven_refund_money);
  251. }else{
  252. $seven_refund_pay_where = " and pay_time > {$begin_time} and order_status_id = 7 ";
  253. $seven_refund_money_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money) as total ' , $seven_refund_pay_where);
  254. $seven_refund_money = empty($seven_refund_money_info['total']) ? 0:$seven_refund_money_info['total'];
  255. $result['seven_refund_money'] = sprintf("%.2f",$seven_refund_money);
  256. }
  257. $goods_stock_notice = D('Home/Front')->get_config_by_name('goods_stock_notice');
  258. if( empty($goods_stock_notice) )
  259. {
  260. $goods_stock_notice = 0;
  261. }
  262. //库存预警商品数量
  263. $goods_stock_notice_count = D('Seller/Goods')->get_goods_count(" and grounding = 1 and total <= ".$goods_stock_notice." and grounding = 1 and type = 'normal' ");
  264. $result['goods_stock_notice_count'] = $goods_stock_notice_count;
  265. $apply_count = M('lionfish_community_head_tixian_order')->where("state=0")->count();
  266. $result['apply_count'] = $apply_count;
  267. echo json_encode( array('code' => 0, 'data' => $result) );
  268. die();
  269. break;
  270. case 'pintuan':
  271. $result = array();
  272. echo json_encode( array('code' => 0, 'data' => $result) );
  273. die();
  274. break;
  275. }
  276. }
  277. function order_buy_data()
  278. {
  279. //成交量(件) //成交额(元) 人均消费
  280. $gpc = I('request.');
  281. $type = isset($gpc['type']) ? $gpc['type']:'normal';
  282. $s_index = isset($gpc['s_index']) ? $gpc['s_index']:2;
  283. $begin_time = 0;
  284. $end_time = 0;
  285. //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]}]}}}};
  286. switch( $s_index )
  287. {
  288. case 0:
  289. //今日
  290. $begin_time = strtotime( date('Y-m-d').' 00:00:00' );
  291. $end_time = $begin_time + 86400;
  292. break;
  293. case 1:
  294. //昨日
  295. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 86400;
  296. $end_time = $begin_time + 86400;
  297. break;
  298. case 2:
  299. //最近七日
  300. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  301. $end_time = time();
  302. break;
  303. case 3:
  304. //本月
  305. $begin_time = strtotime( date('Y-m').'-01 00:00:00' );
  306. $end_time = time();
  307. break;
  308. }
  309. switch( $type )
  310. {
  311. case 'normal':
  312. $result = array();
  313. if (!defined('ROLE') && ROLE != 'agenter' )
  314. {
  315. $where = " and type = 'normal' and date_added >= {$begin_time} and date_added <={$end_time} ";
  316. $count = D('Seller/Order')->get_order_count($where);
  317. $sum_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money) as total ' , $where);
  318. $total = $sum_info['total'];
  319. }else{
  320. $supper_info = get_agent_logininfo();
  321. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  322. "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} ");
  323. $count = count($order_ids_list);
  324. $order_ids_arr = array();
  325. $sum_info = array('total' => 0);
  326. foreach($order_ids_list as $vv)
  327. {
  328. $sum_info['total'] += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  329. }
  330. $total = $sum_info['total'];
  331. }
  332. if($count > 0)
  333. {
  334. $per_money = $total / $count;
  335. } else{
  336. $per_money = 0;
  337. }
  338. $result['count'] = $count;
  339. $result['total'] = round($total,2);
  340. $result['per_money'] = round($per_money,2);
  341. echo json_encode( array('code' => 0, 'data' => $result) );
  342. die();
  343. break;
  344. case 'pintuan':
  345. $result = array();
  346. $where = " and type = 'pintuan' and date_added >= {$begin_time} and date_added <={$end_time} ";
  347. $count = load_model_class('order')->get_order_count($where);
  348. //total
  349. $sum_info = load_model_class('order')->get_order_sum(' sum(total) as total ' , $where);
  350. $total = $sum_info['total'];
  351. if($count > 0)
  352. {
  353. $per_money = $total / $count;
  354. } else{
  355. $per_money = 0;
  356. }
  357. $result['count'] = $count;
  358. $result['total'] = round($total,2);
  359. $result['per_money'] = round($per_money,2);
  360. echo json_encode( array('code' => 0, 'data' => $result) );
  361. die();
  362. break;
  363. }
  364. //s_index
  365. }
  366. //----
  367. public function load_echat_member_incr()
  368. {
  369. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  370. $end_time = time();
  371. $date_arr = array();
  372. $member_count_arr = array();
  373. for($i =7; $i>=1; $i--)
  374. {
  375. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - $i * 86400;
  376. $end_time = $begin_time + 86400;
  377. $member_count = M('lionfish_comshop_member')->where("create_time >= ".$begin_time." and create_time < ".$end_time)->count();
  378. $date_arr[] = date('m-d', $begin_time);
  379. $member_count_arr[] = $member_count;
  380. }
  381. echo json_encode( array('code' => 0, 'date_arr' => $date_arr, 'member_count' => $member_count_arr ) );
  382. die();
  383. }
  384. public function load_echat_head_incr()
  385. {
  386. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  387. $end_time = time();
  388. $date_arr = array();
  389. $member_count_arr = array();
  390. for($i =7; $i>=1; $i--)
  391. {
  392. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - $i * 86400;
  393. $end_time = $begin_time + 86400;
  394. $member_count = M('lionfish_community_head')->where( "state = 1 and addtime >= ".$begin_time." and addtime < ".$end_time )->count();
  395. $date_arr[] = date('m-d', $begin_time);
  396. $member_count_arr[] = $member_count;
  397. }
  398. echo json_encode( array('code' => 0, 'date_arr' => $date_arr, 'member_count' => $member_count_arr ) );
  399. die();
  400. }
  401. public function load_echat_month_head_sales()
  402. {
  403. $type = I('request.type');
  404. if( $type == 1)
  405. {
  406. $begin_time = strtotime( date('Y-m').'-01 00:00:00' );
  407. $date_month =date('Y-m',$begin_time);
  408. }else{
  409. //$begin_time= strtotime( date("Y-m", strtotime("-1 month")) .'-01 00:00:00' );
  410. $begin_time= strtotime( "first day of last month" ) ;
  411. $date_month =date('Y-m',$begin_time);
  412. }
  413. $end_time = time();
  414. //lionfish_comshop_order 1 4 6 11 14 date_added
  415. $sql = " select sum(total+shipping_fare-voucher_credit-fullreduction_money) as total,head_id from ".C('DB_PREFIX').
  416. "lionfish_comshop_order where date_added >= {$begin_time} and date_added <={$end_time} and order_status_id in(1,4,6,11,14)
  417. group by head_id order by total desc limit 10 ";
  418. $list = M()->query($sql);
  419. $total = 0;
  420. foreach( $list as $key => $val )
  421. {
  422. $hd_info = M('lionfish_community_head')->field('community_name,head_name')->where( array('id' => $val['head_id'] ) )->find();
  423. $val['community_name'] = $hd_info['community_name'];
  424. $val['head_name'] = $hd_info['head_name'];
  425. $val['total'] = sprintf('%.2f',$val['total'] );
  426. $total += $val['total'];
  427. $list[$key] = $val;
  428. }
  429. $total = sprintf('%.2f',$total);
  430. echo json_encode( array('code' => 0, 'list' => $list, 'total' => $total,'month' => $date_month) );
  431. die();
  432. }
  433. //--
  434. public function load_echat_month_goods_sales()
  435. {
  436. $type = I('request.type');
  437. if( $type == 1)
  438. {
  439. $begin_time = strtotime( date('Y-m').'-01 00:00:00' );
  440. $date_month =date('Y-m',$begin_time);
  441. }else{
  442. //$begin_time= strtotime( date("Y-m", strtotime("-1 month")) .'-01 00:00:00' );
  443. $begin_time= strtotime( "first day of last month" ) ;
  444. $date_month =date('Y-m',$begin_time);
  445. }
  446. $end_time = time();
  447. //lionfish_comshop_order 1 4 6 11 14 date_added
  448. $sql = "SELECT og.goods_id,og.name ,og.quantity as total_quantity,sum( og.total + og.shipping_fare - og.voucher_credit - og.fullreduction_money ) as total
  449. FROM ".C('DB_PREFIX')."lionfish_comshop_order_goods as og ,".C('DB_PREFIX')."lionfish_comshop_order as o
  450. where og.order_id = o.order_id and o.date_added >= {$begin_time} and o.date_added <={$end_time} and o.order_status_id in(1,4,6,11,14) group by og.goods_id order by total desc limit 10 ";
  451. $list = M()->query($sql);
  452. $total = 0;
  453. $total_quantity = 0;
  454. foreach( $list as $key => $val )
  455. {
  456. $val['community_name'] = $hd_info['name'];
  457. $val['head_name'] = $hd_info['name'];
  458. $val['name'] = mb_substr($val['name'],0,8,'utf-8').' '.'销量:'. $val['total_quantity'];
  459. $val['total'] = sprintf('%.2f',$val['total'] );
  460. $total += $val['total'];
  461. $total_quantity += $val['total_quantity'];
  462. $list[$key] = $val;
  463. }
  464. $total = sprintf('%.2f',$total);
  465. echo json_encode( array('code' => 0, 'list' => $list, 'total_quantity' => $total_quantity,'total' => $total,'month' => $date_month) );
  466. die();
  467. }
  468. //---
  469. function load_goods_chart()
  470. {
  471. //成交量(件) //成交额(元) 人均消费
  472. $type = 'normal';
  473. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  474. $end_time = time();
  475. switch( $type )
  476. {
  477. case 'normal':
  478. $result = array();
  479. $count_value = array();
  480. $price_key = array();
  481. $price_value = array();
  482. $price_value_2 = array();
  483. for($i =7; $i>=1; $i--)
  484. {
  485. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - $i * 86400;
  486. $end_time = $begin_time + 86400;
  487. //supply_id
  488. if (!defined('ROLE') || ROLE != 'agenter' ) {
  489. $where = " and date_added >= {$begin_time} and date_added <={$end_time} and order_status_id in(1,4,6,11,14) ";
  490. $where_refund = " and date_added >= {$begin_time} and date_added <={$end_time} and order_status_id in(7) ";
  491. $count = D('Seller/Order')->get_order_count($where);
  492. $sum_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money) as total ' , $where);
  493. $refund_sum_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money) as total ' , $where_refund);
  494. }else{
  495. $supper_info = get_agent_logininfo();
  496. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  497. "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) ");
  498. $order_ids_list2 = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  499. "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) ");
  500. if( empty($order_ids_list2) )
  501. {
  502. $refund_sum_info = 0;
  503. }else{
  504. $order_ids_arr = array();
  505. $refund_sum_info = array('total' => 0);
  506. foreach($order_ids_list2 as $vv)
  507. {
  508. $refund_sum_info['total'] += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  509. }
  510. }
  511. if( empty($order_ids_list) )
  512. {
  513. $count = 0;
  514. $sum_info = 0;
  515. }else{
  516. $count = count($order_ids_list);
  517. $order_ids_arr = array();
  518. $sum_info = array('total' => 0);
  519. foreach($order_ids_list as $vv)
  520. {
  521. $sum_info['total'] += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  522. }
  523. }
  524. }
  525. if( empty($sum_info) || empty($sum_info['total']) || $sum_info['total'] < 0)
  526. {
  527. $total = 0;
  528. }else{
  529. $total = $sum_info['total'];
  530. }
  531. if( empty($refund_sum_info) || empty($refund_sum_info['total']) || $refund_sum_info['total'] < 0)
  532. {
  533. $refund_total = 0;
  534. }else{
  535. $refund_total = $refund_sum_info['total'];
  536. }
  537. $price_key[] = date('m-d', $begin_time);
  538. $count_value[] = $count;
  539. $price_value[] = sprintf('%.2f',$total);
  540. $price_value_2[] = sprintf('%.2f',$refund_total);
  541. }
  542. //$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]}]}}}}';
  543. $result['lines'] = array();
  544. $result['lines']['payAmountLine']['xAxisData'] = $price_key;
  545. $result['lines']['payAmountLine']['seriesData'][0]['data'] = $price_value;
  546. $result['lines']['payAmountLine']['seriesData'][1]['data'] = $price_value_2;
  547. $result['price_key'] =$price_key;
  548. $result['count_value'] =$count_value;
  549. $result['price_value'] =$price_value;
  550. echo json_encode( array('code' => 0, 'data' => $result) );
  551. die();
  552. break;
  553. case 'pintuan':
  554. $result = array();
  555. $count_value = array();
  556. $price_key = array();
  557. $price_value = array();
  558. for($i =7; $i>=1; $i--)
  559. {
  560. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - $i * 86400;
  561. $end_time = $begin_time + 86400;
  562. $where = " and type = 'pintuan' and date_added >= {$begin_time} and date_added <={$end_time} ";
  563. $count = load_model_class('order')->get_order_count($where);
  564. $sum_info = load_model_class('order')->get_order_sum(' sum(total) as total ' , $where);
  565. if( empty($sum_info) || empty($sum_info['total']))
  566. {
  567. $total = 0;
  568. }else{
  569. $total = $sum_info['total'];
  570. }
  571. $price_key[] = date('Y-m-d', $begin_time);
  572. $count_value[] = $count;
  573. $price_value[] = sprintf('%.2f',$total);
  574. }
  575. //{"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]}
  576. $result['price_key'] =$price_key;
  577. $result['count_value'] =$count_value;
  578. $result['price_value'] =$price_value;
  579. echo json_encode( array('code' => 0, 'data' => $result) );
  580. die();
  581. break;
  582. }
  583. //s_index
  584. }
  585. function load_goods_paihang()
  586. {
  587. //成交量(件) //成交额(元) 人均消费
  588. $gpc = I('request.');
  589. $type = $gpc['type'];
  590. $s_index = $gpc['s_index'];
  591. $begin_time = 0;
  592. $end_time = 0;
  593. switch( $s_index )
  594. {
  595. case 0:
  596. //今日
  597. $begin_time = strtotime( date('Y-m-d').' 00:00:00' );
  598. $end_time = $begin_time + 86400;
  599. break;
  600. case 1:
  601. //昨日
  602. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 86400;
  603. $end_time = $begin_time + 86400;
  604. break;
  605. case 2:
  606. //最近七日
  607. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 7 * 86400;
  608. $end_time = time();
  609. break;
  610. }
  611. $list = array();
  612. switch( $type )
  613. {
  614. case 'normal':
  615. $result = array();
  616. if (!defined('ROLE') || ROLE != 'agenter' )
  617. {
  618. $where = " and addtime >= {$begin_time} and addtime <={$end_time} ";
  619. }else{
  620. $supper_info = get_agent_logininfo();
  621. $where = " and supply_id= ".$supper_info['id']." and addtime >= {$begin_time} and addtime <={$end_time} ";
  622. }
  623. $list = D('Seller/Order')->get_order_goods_group_paihang($where );
  624. break;
  625. case 'pintuan':
  626. $result = array();
  627. $where = " and goods_type='pintuan' and addtime >= {$begin_time} and addtime <={$end_time} ";
  628. $list = D('Seller/Order')->get_order_goods_group_paihang($where );
  629. break;
  630. }
  631. $html = '';
  632. if( !empty($list) )
  633. {
  634. $i =1;
  635. foreach($list as $val)
  636. {
  637. $html .= "<tr>";
  638. $html .= " <td>{$i}</td>";
  639. $html .= " <td><a href='#'>".$val['name']."</a></td>";
  640. $html .= " <td>".$val['total_quantity']."</td>";
  641. $html .= " <td class='text-warning'>".$val['m_total']."</td>";
  642. $html .= " </tr>";
  643. $i++;
  644. }
  645. }
  646. echo json_encode( array('code' => 0, 'html' => $html) );
  647. die();
  648. }
  649. }
  650. ?>