Statisticsindustry.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /**
  3. * 行业F分析
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. use think\facade\Db;
  9. /**
  10. *
  11. *
  12. * ----------------------------------------------------------------------------
  13. *
  14. * 控制器
  15. */
  16. class Statisticsindustry extends BaseSeller
  17. {
  18. private $search_arr; //处理后的参数
  19. private $gc_arr; //分类数组
  20. private $choose_gcid; //选择的分类ID
  21. public function initialize()
  22. {
  23. parent::initialize(); // TODO: Change the autogenerated stub
  24. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/statisticsindustry.lang.php');
  25. include_once root_path() . 'extend/mall/statistics.php';
  26. include_once root_path() . 'extend/mall/datehelper.php';
  27. $stat_model = model('stat');
  28. //存储参数
  29. $this->search_arr = $_REQUEST;
  30. //处理搜索时间
  31. $this->search_arr = $stat_model->dealwithSearchTime($this->search_arr);
  32. //获得系统年份
  33. $year_arr = getSystemYearArr();
  34. //获得系统月份
  35. $month_arr = getSystemMonthArr();
  36. //获得本月的周时间段
  37. $week_arr = getMonthWeekArr($this->search_arr['week']['current_year'], $this->search_arr['week']['current_month']);
  38. View::assign('year_arr', $year_arr);
  39. View::assign('month_arr', $month_arr);
  40. View::assign('week_arr', $week_arr);
  41. View::assign('search_arr', $this->search_arr);
  42. /**
  43. * 处理商品分类
  44. */
  45. $this->choose_gcid = ($t = intval(input('param.choose_gcid'))) > 0 ? $t : 0;
  46. $gccache_arr = model('goodsclass')->getGoodsclassCache($this->choose_gcid, 3);
  47. $this->gc_arr = $gccache_arr['showclass'];
  48. View::assign('gc_json', json_encode($gccache_arr['showclass']));
  49. View::assign('gc_choose_json', json_encode($gccache_arr['choose_gcid']));
  50. }
  51. /**
  52. * 行业排行
  53. */
  54. public function index()
  55. {
  56. $datanum = 30;
  57. if (!isset($this->search_arr['search_type'])) {
  58. $this->search_arr['search_type'] = 'day';
  59. }
  60. $stat_model = model('stat');
  61. //获得搜索的开始时间和结束时间
  62. $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
  63. $where = array();
  64. $where[] = array('order_isvalid', '=', 1); //计入统计的有效订单
  65. $where[] = array('order_add_time', 'between', $searchtime_arr);
  66. $where[] = array('store_id', '<>', session('store_id'));
  67. $gc_id_depth = @$this->gc_arr[$this->choose_gcid]['depth'];
  68. if ($this->choose_gcid > 0) {
  69. $where[] = array('gc_parentid_' . $gc_id_depth, '=', $this->choose_gcid);
  70. }
  71. /**
  72. * 商品排行
  73. */
  74. $goods_stat_arr = array();
  75. //构造横轴数据
  76. for ($i = 1; $i <= $datanum; $i++) {
  77. //数据
  78. $goods_stat_arr['series'][0]['data'][] = array('name' => '', 'y' => 0);
  79. //横轴
  80. $goods_stat_arr['xAxis']['categories'][] = "$i";
  81. }
  82. $field = 'goods_id,goods_name,SUM(goods_num) as goodsnum';
  83. $goods_list = $stat_model->statByStatordergoods($where, $field, 0, $datanum, 'goodsnum desc,goods_id asc', 'goods_id');
  84. foreach ((array) $goods_list as $k => $v) {
  85. $goods_stat_arr['series'][0]['data'][$k] = array('name' => strval($v['goods_name']), 'y' => floatval($v['goodsnum']));
  86. }
  87. //得到统计图数据
  88. $goods_stat_arr['series'][0]['name'] = lang('order_quantity');
  89. $goods_stat_arr['title'] = sprintf(lang('industry_products'), $datanum);
  90. $goods_stat_arr['legend']['enabled'] = false;
  91. $goods_stat_arr['yAxis'] = lang('order_quantity');
  92. $goods_statjson = getStatData_Column2D($goods_stat_arr);
  93. View::assign('goods_statjson', $goods_statjson);
  94. View::assign('goods_list', $goods_list);
  95. $this->setSellerCurMenu('Statisticsindustry');
  96. $this->setSellerCurItem('hot');
  97. return View::fetch($this->template_dir . 'index');
  98. }
  99. /**
  100. * 价格分布
  101. */
  102. public function price()
  103. {
  104. if (!isset($this->search_arr['search_type'])) {
  105. $this->search_arr['search_type'] = 'day';
  106. }
  107. $stat_model = model('stat');
  108. //获得搜索的开始时间和结束时间
  109. $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
  110. $where = array();
  111. $where[] = array('order_isvalid', '=', 1); //计入统计的有效订单
  112. $where[] = array('order_add_time', 'between', $searchtime_arr);
  113. $gc_id_depth = @$this->gc_arr[$this->choose_gcid]['depth'];
  114. if ($this->choose_gcid > 0) {
  115. $where[] = array('gc_parentid_' . $gc_id_depth, '=', $this->choose_gcid);
  116. }
  117. $field = '*';
  118. $pricerange = ds_getvalue_byname('storeextend', 'store_id', session('store_id'), 'pricerange');
  119. $pricerange_arr = $pricerange ? unserialize($pricerange) : array();
  120. if ($pricerange_arr) {
  121. $stat_arr['series'][0]['name'] = lang('order_quantity');
  122. //设置价格区间最后一项,最后一项只有开始值没有结束值
  123. $pricerange_count = count($pricerange_arr);
  124. if ($pricerange_arr[$pricerange_count - 1]['e']) {
  125. $pricerange_arr[$pricerange_count]['s'] = $pricerange_arr[$pricerange_count - 1]['e'] + 1;
  126. $pricerange_arr[$pricerange_count]['e'] = '';
  127. }
  128. foreach ((array) $pricerange_arr as $k => $v) {
  129. $v['s'] = intval($v['s']);
  130. $v['e'] = intval($v['e']);
  131. //构造查询字段
  132. if ($v['e']) {
  133. $field .= " ,SUM(IF(goods_pay_price/goods_num > {$v['s']} and goods_pay_price/goods_num <= {$v['e']},goods_num,0)) as goodsnum_{$k}";
  134. } else {
  135. $field .= " ,SUM(IF(goods_pay_price/goods_num > {$v['s']},goods_num,0)) as goodsnum_{$k}";
  136. }
  137. }
  138. $ordergooods_list = Db::query('SELECT ' . $field . ' FROM ' . config('database.connections.mysql.prefix') . 'statordergoods WHERE order_isvalid=1 AND order_add_time BETWEEN ' . $searchtime_arr[0] . ' AND ' . $searchtime_arr[1] . ($this->choose_gcid > 0 ? (' AND gc_parentid_' . $gc_id_depth . '=' . $this->choose_gcid) : ''));
  139. if ($ordergooods_list) {
  140. $ordergooods_list = current($ordergooods_list);
  141. foreach ((array) $pricerange_arr as $k => $v) {
  142. //横轴
  143. if ($v['e']) {
  144. $stat_arr['xAxis']['categories'][] = $v['s'] . '-' . $v['e'];
  145. } else {
  146. $stat_arr['xAxis']['categories'][] = $v['s'] . lang('above');
  147. }
  148. //统计图数据
  149. if (isset($ordergooods_list['goodsnum_' . $k])) {
  150. $stat_arr['series'][0]['data'][$k] = ($t = intval($ordergooods_list['goodsnum_' . $k])) ? $t : 0;
  151. } else {
  152. $stat_arr['series'][0]['data'][$k] = 0;
  153. }
  154. }
  155. }
  156. //得到统计图数据
  157. $stat_arr['legend']['enabled'] = false;
  158. $stat_arr['title'] = lang('number_goods_ordered_trade_price');
  159. $stat_arr['yAxis'] = '';
  160. $stat_json = getStatData_LineLabels($stat_arr);
  161. } else {
  162. $stat_json = '';
  163. }
  164. View::assign('stat_json', $stat_json);
  165. $this->setSellerCurMenu('Statisticsindustry');
  166. $this->setSellerCurItem('price');
  167. return View::fetch($this->template_dir . 'price');
  168. }
  169. /**
  170. * 用户中心右边,小导航
  171. *
  172. * @param string $menu_type 导航类型
  173. * @param string $name 当前导航的name
  174. * @return
  175. */
  176. protected function getSellerItemList()
  177. {
  178. $menu_array = array(
  179. array('name' => 'hot', 'text' => lang('peer_selling'), 'url' => (string) url('Statisticsindustry/index')),
  180. array('name' => 'price', 'text' => lang('industry_price_distribution'), 'url' => (string) url('Statisticsindustry/price')),
  181. );
  182. return $menu_array;
  183. }
  184. }