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