Statisticsindustry.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. * DSMall多用户商城
  12. * ============================================================================
  13. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  14. * 网站地址: http://www.csdeshang.com
  15. * ----------------------------------------------------------------------------
  16. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  17. * 不允许对程序代码以任何形式任何目的的再发布。
  18. * ============================================================================
  19. * 控制器
  20. */
  21. class Statisticsindustry extends BaseSeller {
  22. private $search_arr; //处理后的参数
  23. private $gc_arr; //分类数组
  24. private $choose_gcid; //选择的分类ID
  25. public function initialize() {
  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. $datanum = 30;
  59. if (!isset($this->search_arr['search_type'])) {
  60. $this->search_arr['search_type'] = 'day';
  61. }
  62. $stat_model = model('stat');
  63. //获得搜索的开始时间和结束时间
  64. $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
  65. $where = array();
  66. $where[] = array('order_isvalid', '=', 1); //计入统计的有效订单
  67. $where[] = array('order_add_time', 'between', $searchtime_arr);
  68. $where[] = array('store_id', '<>', session('store_id'));
  69. $gc_id_depth = @$this->gc_arr[$this->choose_gcid]['depth'];
  70. if ($this->choose_gcid > 0) {
  71. $where[] = array('gc_parentid_' . $gc_id_depth, '=', $this->choose_gcid);
  72. }
  73. /**
  74. * 商品排行
  75. */
  76. $goods_stat_arr = array();
  77. //构造横轴数据
  78. for ($i = 1; $i <= $datanum; $i++) {
  79. //数据
  80. $goods_stat_arr['series'][0]['data'][] = array('name' => '', 'y' => 0);
  81. //横轴
  82. $goods_stat_arr['xAxis']['categories'][] = "$i";
  83. }
  84. $field = 'goods_id,goods_name,SUM(goods_num) as goodsnum';
  85. $goods_list = $stat_model->statByStatordergoods($where, $field, 0, $datanum, 'goodsnum desc,goods_id asc', 'goods_id');
  86. foreach ((array) $goods_list as $k => $v) {
  87. $goods_stat_arr['series'][0]['data'][$k] = array('name' => strval($v['goods_name']), 'y' => floatval($v['goodsnum']));
  88. }
  89. //得到统计图数据
  90. $goods_stat_arr['series'][0]['name'] = lang('order_quantity');
  91. $goods_stat_arr['title'] = sprintf(lang('industry_products'), $datanum);
  92. $goods_stat_arr['legend']['enabled'] = false;
  93. $goods_stat_arr['yAxis'] = lang('order_quantity');
  94. $goods_statjson = getStatData_Column2D($goods_stat_arr);
  95. View::assign('goods_statjson', $goods_statjson);
  96. View::assign('goods_list', $goods_list);
  97. $this->setSellerCurMenu('Statisticsindustry');
  98. $this->setSellerCurItem('hot');
  99. return View::fetch($this->template_dir . 'index');
  100. }
  101. /**
  102. * 价格分布
  103. */
  104. public function price() {
  105. if (!isset($this->search_arr['search_type'])) {
  106. $this->search_arr['search_type'] = 'day';
  107. }
  108. $stat_model = model('stat');
  109. //获得搜索的开始时间和结束时间
  110. $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
  111. $where = array();
  112. $where[] = array('order_isvalid','=',1); //计入统计的有效订单
  113. $where[] = array('order_add_time','between',$searchtime_arr);
  114. $gc_id_depth = @$this->gc_arr[$this->choose_gcid]['depth'];
  115. if ($this->choose_gcid > 0) {
  116. $where[] = array('gc_parentid_' . $gc_id_depth,'=',$this->choose_gcid);
  117. }
  118. $field = '*';
  119. $pricerange = ds_getvalue_byname('storeextend', 'store_id', session('store_id'), 'pricerange');
  120. $pricerange_arr = $pricerange ? unserialize($pricerange) : array();
  121. if ($pricerange_arr) {
  122. $stat_arr['series'][0]['name'] = lang('order_quantity');
  123. //设置价格区间最后一项,最后一项只有开始值没有结束值
  124. $pricerange_count = count($pricerange_arr);
  125. if ($pricerange_arr[$pricerange_count - 1]['e']) {
  126. $pricerange_arr[$pricerange_count]['s'] = $pricerange_arr[$pricerange_count - 1]['e'] + 1;
  127. $pricerange_arr[$pricerange_count]['e'] = '';
  128. }
  129. foreach ((array) $pricerange_arr as $k => $v) {
  130. $v['s'] = intval($v['s']);
  131. $v['e'] = intval($v['e']);
  132. //构造查询字段
  133. if ($v['e']) {
  134. $field .= " ,SUM(IF(goods_pay_price/goods_num > {$v['s']} and goods_pay_price/goods_num <= {$v['e']},goods_num,0)) as goodsnum_{$k}";
  135. } else {
  136. $field .= " ,SUM(IF(goods_pay_price/goods_num > {$v['s']},goods_num,0)) as goodsnum_{$k}";
  137. }
  138. }
  139. $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) : ''));
  140. if ($ordergooods_list) {
  141. $ordergooods_list = current($ordergooods_list);
  142. foreach ((array) $pricerange_arr as $k => $v) {
  143. //横轴
  144. if ($v['e']) {
  145. $stat_arr['xAxis']['categories'][] = $v['s'] . '-' . $v['e'];
  146. } else {
  147. $stat_arr['xAxis']['categories'][] = $v['s'] . lang('above');
  148. }
  149. //统计图数据
  150. if (isset($ordergooods_list['goodsnum_' . $k])) {
  151. $stat_arr['series'][0]['data'][$k] = ($t = intval($ordergooods_list['goodsnum_' . $k])) ? $t : 0;
  152. } else {
  153. $stat_arr['series'][0]['data'][$k] = 0;
  154. }
  155. }
  156. }
  157. //得到统计图数据
  158. $stat_arr['legend']['enabled'] = false;
  159. $stat_arr['title'] = lang('number_goods_ordered_trade_price');
  160. $stat_arr['yAxis'] = '';
  161. $stat_json = getStatData_LineLabels($stat_arr);
  162. } else {
  163. $stat_json = '';
  164. }
  165. View::assign('stat_json', $stat_json);
  166. $this->setSellerCurMenu('Statisticsindustry');
  167. $this->setSellerCurItem('price');
  168. return View::fetch($this->template_dir . 'price');
  169. }
  170. /**
  171. * 用户中心右边,小导航
  172. *
  173. * @param string $menu_type 导航类型
  174. * @param string $name 当前导航的name
  175. * @return
  176. */
  177. protected function getSellerItemList() {
  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. }