Statisticsindustry.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  14. * 网站地址: https://www.valimart.net/
  15. * ----------------------------------------------------------------------------
  16. *
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class Statisticsindustry extends BaseSeller {
  21. private $search_arr; //处理后的参数
  22. private $gc_arr; //分类数组
  23. private $choose_gcid; //选择的分类ID
  24. public function initialize() {
  25. parent::initialize(); // TODO: Change the autogenerated stub
  26. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/statisticsindustry.lang.php');
  27. include_once root_path() . 'extend/mall/statistics.php';
  28. include_once root_path() . 'extend/mall/datehelper.php';
  29. $stat_model = model('stat');
  30. //存储参数
  31. $this->search_arr = $_REQUEST;
  32. //处理搜索时间
  33. $this->search_arr = $stat_model->dealwithSearchTime($this->search_arr);
  34. //获得系统年份
  35. $year_arr = getSystemYearArr();
  36. //获得系统月份
  37. $month_arr = getSystemMonthArr();
  38. //获得本月的周时间段
  39. $week_arr = getMonthWeekArr($this->search_arr['week']['current_year'], $this->search_arr['week']['current_month']);
  40. View::assign('year_arr', $year_arr);
  41. View::assign('month_arr', $month_arr);
  42. View::assign('week_arr', $week_arr);
  43. View::assign('search_arr', $this->search_arr);
  44. /**
  45. * 处理商品分类
  46. */
  47. $this->choose_gcid = ($t = intval(input('param.choose_gcid'))) > 0 ? $t : 0;
  48. $gccache_arr = model('goodsclass')->getGoodsclassCache($this->choose_gcid, 3);
  49. $this->gc_arr = $gccache_arr['showclass'];
  50. View::assign('gc_json', json_encode($gccache_arr['showclass']));
  51. View::assign('gc_choose_json', json_encode($gccache_arr['choose_gcid']));
  52. }
  53. /**
  54. * 行业排行
  55. */
  56. public function index() {
  57. $datanum = 30;
  58. if (!isset($this->search_arr['search_type'])) {
  59. $this->search_arr['search_type'] = 'day';
  60. }
  61. $stat_model = model('stat');
  62. //获得搜索的开始时间和结束时间
  63. $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
  64. $where = array();
  65. $where[] = array('order_isvalid', '=', 1); //计入统计的有效订单
  66. $where[] = array('order_add_time', 'between', $searchtime_arr);
  67. $where[] = array('store_id', '<>', session('store_id'));
  68. $gc_id_depth = @$this->gc_arr[$this->choose_gcid]['depth'];
  69. if ($this->choose_gcid > 0) {
  70. $where[] = array('gc_parentid_' . $gc_id_depth, '=', $this->choose_gcid);
  71. }
  72. /**
  73. * 商品排行
  74. */
  75. $goods_stat_arr = array();
  76. //构造横轴数据
  77. for ($i = 1; $i <= $datanum; $i++) {
  78. //数据
  79. $goods_stat_arr['series'][0]['data'][] = array('name' => '', 'y' => 0);
  80. //横轴
  81. $goods_stat_arr['xAxis']['categories'][] = "$i";
  82. }
  83. $field = 'goods_id,goods_name,SUM(goods_num) as goodsnum';
  84. $goods_list = $stat_model->statByStatordergoods($where, $field, 0, $datanum, 'goodsnum desc,goods_id asc', 'goods_id');
  85. foreach ((array) $goods_list as $k => $v) {
  86. $goods_stat_arr['series'][0]['data'][$k] = array('name' => strval($v['goods_name']), 'y' => floatval($v['goodsnum']));
  87. }
  88. //得到统计图数据
  89. $goods_stat_arr['series'][0]['name'] = lang('order_quantity');
  90. $goods_stat_arr['title'] = sprintf(lang('industry_products'), $datanum);
  91. $goods_stat_arr['legend']['enabled'] = false;
  92. $goods_stat_arr['yAxis'] = lang('order_quantity');
  93. $goods_statjson = getStatData_Column2D($goods_stat_arr);
  94. View::assign('goods_statjson', $goods_statjson);
  95. View::assign('goods_list', $goods_list);
  96. $this->setSellerCurMenu('Statisticsindustry');
  97. $this->setSellerCurItem('hot');
  98. return View::fetch($this->template_dir . 'index');
  99. }
  100. /**
  101. * 价格分布
  102. */
  103. public function price() {
  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. $menu_array = array(
  178. array('name' => 'hot', 'text' => lang('peer_selling'), 'url' => (string) url('Statisticsindustry/index')),
  179. array('name' => 'price', 'text' => lang('industry_price_distribution'), 'url' => (string) url('Statisticsindustry/price')),
  180. );
  181. return $menu_array;
  182. }
  183. }