StatisticsController.class.php 34 KB

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