PlatformmobileController.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Home\Controller;
  10. use Home\Model\OrderModel;
  11. class PlatformmobileController extends CommonController {
  12. public $member_id;
  13. protected function _initialize(){
  14. parent::_initialize();
  15. $isopen_admin_managefront = D('Home/Front')->get_config_by_name('isopen_admin_managefront');
  16. $isopen_admin_managefront = isset($isopen_admin_managefront) ? $isopen_admin_managefront : 0;
  17. if( $isopen_admin_managefront == 0 )
  18. {
  19. echo json_encode( array('code' => 3, 'message' => '未开启平台手机端功能') );
  20. die();
  21. }
  22. $token = I('request.token');
  23. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  24. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  25. {
  26. echo json_encode( array('code' => 1,'message' => '请先登录') );
  27. die();
  28. }
  29. $this->member_id = $weprogram_token['member_id'];
  30. //检测是否平台管理员
  31. $platform_admin_member = D('Home/Front')->get_config_by_name('platform_admin_member');
  32. if( empty($platform_admin_member) )
  33. {
  34. echo json_encode( array('code' => 3, 'message' => '您不是平台管理员') );
  35. die();
  36. }
  37. $platform_admin_member_arr = explode(',', $platform_admin_member );
  38. if( !in_array( $this->member_id , $platform_admin_member_arr ) )
  39. {
  40. echo json_encode( array('code' => 3, 'message' => '您不是平台管理员') );
  41. die();
  42. }
  43. }
  44. /**
  45. * @author yj
  46. * @desc 获取平台手机端数据所需要的内容
  47. */
  48. public function getIndexData()
  49. {
  50. $begin_time = 0;
  51. $end_time = time() +1;
  52. $sales_data = D('Home/OrderV3')->analySalesByTime( $begin_time , $end_time );//销售统计
  53. $todayOrderData = D('Home/OrderV3')->getTodayOrderData();//今日平台数据
  54. $user_data = D('Home/OrderV3')->getPlatformUserData();
  55. $goods_data = D('Home/OrderV3')->getPlatformGoodsData();
  56. $business_data = D('Home/OrderV3')->getBusinessData();
  57. $need_data = [];
  58. $need_data['sales_data'] = $sales_data;
  59. $need_data['todayOrderData'] = $todayOrderData;
  60. $need_data['user_data'] = $user_data;
  61. $need_data['goods_data'] = $goods_data;
  62. $need_data['business_data'] = $business_data;
  63. $need_data['code'] = 0;
  64. echo json_encode( $need_data );
  65. die();
  66. }
  67. public function searchAnalySalesByTime()
  68. {
  69. $type = I('request.type', 0);
  70. $begin_time = I('request.begin_time','','strtotime');
  71. $end_time = I('request.end_time', '', 'strtotime');
  72. switch( $type )
  73. {
  74. case 0:
  75. $begin_time = 0;
  76. $end_time = time() +1;
  77. break;
  78. case 1:
  79. //今日
  80. $begin_time = strtotime( date('Y-m-d').' 00:00:00' );
  81. $end_time = $begin_time + 86400;
  82. break;
  83. case 2:
  84. //昨日
  85. $begin_time = strtotime( date('Y-m-d').' 00:00:00' ) - 86400;
  86. $end_time = $begin_time + 86400;
  87. break;
  88. case 3:
  89. //7日
  90. $begin_time = strtotime( date('Y-m-d').' 00:00:00' );
  91. $end_time = $begin_time + 86400;
  92. $begin_time = $begin_time - 6*86400;
  93. break;
  94. }
  95. $sales_data = D('Home/OrderV3')->analySalesByTime( $begin_time , $end_time );//销售统计
  96. $need_data = [];
  97. $need_data['code'] = 1;
  98. $need_data['sales_data'] = $sales_data;
  99. echo json_encode( $need_data );
  100. die();
  101. }
  102. }