Stataftersale.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <?php
  2. /**
  3. * 售后统计分析
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. * ============================================================================
  10. *
  11. * ============================================================================
  12. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Stataftersale extends AdminControl
  20. {
  21. private $search_arr;//处理后的参数
  22. public function initialize()
  23. {
  24. parent::initialize(); // TODO: Change the autogenerated stub
  25. Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/stat.lang.php');
  26. include_once root_path(). 'extend/mall/statistics.php';
  27. include_once root_path(). 'extend/mall/datehelper.php';
  28. $stat_model = model('stat');
  29. //存储参数
  30. $this->search_arr = input('param.');
  31. //处理搜索时间
  32. if (in_array(request()->action(),array('refund'))){
  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. }
  44. View::assign('search_arr', $this->search_arr);
  45. }
  46. /**
  47. * 退款统计
  48. */
  49. public function refund(){
  50. $where = array();
  51. if(!isset($this->search_arr['search_type'])){
  52. $this->search_arr['search_type'] = 'day';
  53. }
  54. $stat_model = model('stat');
  55. //获得搜索的开始时间和结束时间
  56. $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
  57. $field = ' SUM(refund_amount) as amount ';
  58. if($this->search_arr['search_type'] == 'day'){
  59. //构造横轴数据
  60. for($i=0; $i<24; $i++){
  61. $stat_arr['xAxis']['categories'][] = "$i";
  62. $statlist[$i] = 0;
  63. }
  64. $field .= ' ,HOUR(FROM_UNIXTIME(add_time)) as timeval ';
  65. }
  66. if($this->search_arr['search_type'] == 'week'){
  67. //构造横轴数据
  68. for($i=1; $i<=7; $i++){
  69. $tmp_weekarr = getSystemWeekArr();
  70. //横轴
  71. $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
  72. unset($tmp_weekarr);
  73. $statlist[$i] = 0;
  74. }
  75. $field .= ' ,WEEKDAY(FROM_UNIXTIME(add_time))+1 as timeval ';
  76. }
  77. if($this->search_arr['search_type'] == 'month'){
  78. //计算横轴的最大量(由于每个月的天数不同)
  79. $dayofmonth = date('t',$searchtime_arr[0]);
  80. //构造横轴数据
  81. for($i=1; $i<=$dayofmonth; $i++){
  82. //横轴
  83. $stat_arr['xAxis']['categories'][] = $i;
  84. $statlist[$i] = 0;
  85. }
  86. $field .= ' ,day(FROM_UNIXTIME(add_time)) as timeval ';
  87. }
  88. $where = array();
  89. $where[] = array('add_time','between',$searchtime_arr);
  90. $statlist_tmp = $stat_model->statByRefundreturn($where, $field, 0, 0, 'timeval asc', 'timeval');
  91. if ($statlist_tmp){
  92. foreach((array)$statlist_tmp as $k=>$v){
  93. $statlist[$v['timeval']] = floatval($v['amount']);
  94. }
  95. }
  96. //得到统计图数据
  97. $stat_arr['legend']['enabled'] = false;
  98. $stat_arr['series'][0]['name'] = lang('stattrade_refund_total');
  99. $stat_arr['series'][0]['data'] = array_values($statlist);
  100. $stat_arr['title'] = lang('refund_amount_statis');
  101. $stat_arr['yAxis'] = lang('stattrade_refund_total');
  102. $stat_json = getStatData_LineLabels($stat_arr);
  103. View::assign('stat_json',$stat_json);
  104. View::assign('searchtime',implode('|',$searchtime_arr));
  105. $this->setAdminCurItem('refund');
  106. return View::fetch('aftersale_refund');
  107. }
  108. /**
  109. * 退款统计
  110. */
  111. public function refundlist(){
  112. $refundreturn_model = model('refundreturn');
  113. $refundstate_arr = $this->getRefundStateArray();
  114. $where = array();
  115. $statlist= array();
  116. $searchtime_arr_tmp = explode('|',$this->search_arr['t']);
  117. foreach ((array)$searchtime_arr_tmp as $k=>$v){
  118. $searchtime_arr[] = intval($v);
  119. }
  120. $where[] = array('add_time','between',$searchtime_arr);
  121. if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel'){
  122. $refundlist_tmp = $refundreturn_model->getRefundreturnList($where, 0);
  123. } else {
  124. $refundlist_tmp = $refundreturn_model->getRefundreturnList($where, 10);
  125. }
  126. $statheader = array();
  127. $statheader[] = array('text'=>lang('ds_order_sn'),'key'=>'order_sn');
  128. $statheader[] = array('text'=>lang('ds_refund_sn'),'key'=>'refund_sn');
  129. $statheader[] = array('text'=>lang('ds_store_name'),'key'=>'store_name','class'=>'alignleft');
  130. $statheader[] = array('text'=>lang('ds_goods_name'),'key'=>'goods_name','class'=>'alignleft');
  131. $statheader[] = array('text'=>lang('ds_member_name'),'key'=>'buyer_name');
  132. $statheader[] = array('text'=>lang('apply_time'),'key'=>'add_time');
  133. $statheader[] = array('text'=>lang('stattrade_refund_total'),'key'=>'refund_amount');
  134. $statheader[] = array('text'=>lang('seller_state'),'key'=>'seller_state');
  135. $statheader[] = array('text'=>lang('admin_state'),'key'=>'refund_state');
  136. foreach ((array)$refundlist_tmp as $k=>$v){
  137. $tmp = $v;
  138. foreach ((array)$statheader as $h_k=>$h_v){
  139. $tmp[$h_v['key']] = $v[$h_v['key']];
  140. if ($h_v['key'] == 'add_time'){
  141. $tmp[$h_v['key']] = @date('Y-m-d',$v['add_time']);
  142. }
  143. if ($h_v['key'] == 'refund_state'){
  144. $tmp[$h_v['key']] = $v['seller_state']==2 ? $refundstate_arr['admin'][$v['refund_state']]:lang('none');
  145. }
  146. if ($h_v['key'] == 'seller_state'){
  147. $tmp[$h_v['key']] = $refundstate_arr['seller'][$v['seller_state']];
  148. }
  149. if ($h_v['key'] == 'goods_name'){
  150. $tmp[$h_v['key']] = '<a href="'.(string)url('Goods/index', array('goods_id' => $v['goods_id'])).'" target="_blank">'.$v['goods_name'].'</a>';
  151. }
  152. }
  153. $statlist[] = $tmp;
  154. }
  155. if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel'){
  156. //导出Excel
  157. $excel_obj = new \excel\Excel();
  158. $excel_data = array();
  159. //设置样式
  160. $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
  161. //header
  162. foreach ((array)$statheader as $k=>$v){
  163. $excel_data[0][] = array('styleid'=>'s_title','data'=>$v['text']);
  164. }
  165. //data
  166. foreach ((array)$statlist as $k=>$v){
  167. foreach ((array)$statheader as $h_k=>$h_v){
  168. $excel_data[$k+1][] = array('data'=>$v[$h_v['key']]);
  169. }
  170. }
  171. $excel_data = $excel_obj->charset($excel_data,CHARSET);
  172. $excel_obj->addArray($excel_data);
  173. $excel_obj->addWorksheet($excel_obj->charset(lang('refund_log'),CHARSET));
  174. $excel_obj->generateXML($excel_obj->charset(lang('refund_log'),CHARSET).date('Y-m-d-H',TIMESTAMP));
  175. exit();
  176. } else {
  177. View::assign('statheader',$statheader);
  178. View::assign('statlist',$statlist);
  179. View::assign('show_page',$refundreturn_model->page_info->render());
  180. View::assign('searchtime',input('param.t'));
  181. View::assign('actionurl',(string)url('Stataftersale/refundlist',['t'=>$this->search_arr['t']]));
  182. echo View::fetch('stat_listandorder');
  183. }
  184. }
  185. /**
  186. * 店铺动态评分统计
  187. */
  188. public function evalstore(){
  189. //店铺分类
  190. View::assign('class_list', rkcache('storeclass', true));
  191. $stat_model = model('stat');
  192. $where = array();
  193. $statlist=array();
  194. if(intval(input('param.store_class')) > 0){
  195. $where[]=array('storeclass_id','=',intval(input('param.store_class')));
  196. }
  197. if (isset($this->search_arr['storename'])){
  198. $where[]=array('seval_storename','like',"%".trim($this->search_arr['storename'])."%");
  199. }
  200. $field = ' seval_storeid, seval_storename';
  201. $field .= ' ,(SUM(seval_desccredit)/COUNT(*)) as avgdesccredit';
  202. $field .= ' ,(SUM(seval_servicecredit)/COUNT(*)) as avgservicecredit';
  203. $field .= ' ,(SUM(seval_deliverycredit)/COUNT(*)) as avgdeliverycredit';
  204. $orderby_arr = array('avgdesccredit asc','avgdesccredit desc','avgservicecredit asc','avgservicecredit desc','avgdeliverycredit asc','avgdeliverycredit desc');
  205. if (!isset($this->search_arr['orderby'])||!in_array(trim($this->search_arr['orderby']),$orderby_arr)){
  206. $this->search_arr['orderby'] = 'avgdesccredit desc';
  207. }
  208. $orderby = trim($this->search_arr['orderby']).',seval_storeid';
  209. //查询评论的店铺总数
  210. $count_arr = $stat_model->statByStoreAndEvaluatestore($where, 'count(DISTINCT evaluatestore.seval_storeid) as countnum');
  211. $countnum = intval($count_arr[0]['countnum']);
  212. if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel'){
  213. $statlist_tmp = $stat_model->statByStoreAndEvaluatestore($where, $field, 0, 0, $orderby, 'seval_storeid');
  214. } else {
  215. $statlist_tmp = $stat_model->statByStoreAndEvaluatestore($where, $field, 10, 0, $orderby, 'seval_storeid');
  216. }
  217. foreach((array)$statlist_tmp as $k=>$v){
  218. $tmp = $v;
  219. $tmp['avgdesccredit'] = round($v['avgdesccredit'],2);
  220. $tmp['avgservicecredit'] = round($v['avgservicecredit'],2);
  221. $tmp['avgdeliverycredit'] = round($v['avgdeliverycredit'],2);
  222. $statlist[] = $tmp;
  223. }
  224. //导出Excel
  225. if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel'){
  226. //导出Excel
  227. $excel_obj = new \excel\Excel();
  228. $excel_data = array();
  229. //设置样式
  230. $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
  231. //header
  232. $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('ds_store_name'));
  233. $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('avgdesccredit'));
  234. $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('avgservicecredit'));
  235. $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('avgdeliverycredit'));
  236. //data
  237. foreach ((array)$statlist as $k=>$v){
  238. $excel_data[$k+1][] = array('data'=>$v['seval_storename']);
  239. $excel_data[$k+1][] = array('data'=>$v['avgdesccredit']);
  240. $excel_data[$k+1][] = array('data'=>$v['avgservicecredit']);
  241. $excel_data[$k+1][] = array('data'=>$v['avgdeliverycredit']);
  242. }
  243. $excel_data = $excel_obj->charset($excel_data,CHARSET);
  244. $excel_obj->addArray($excel_data);
  245. $excel_obj->addWorksheet($excel_obj->charset(lang('store_dynamic_score_statis'),CHARSET));
  246. $excel_obj->generateXML($excel_obj->charset(lang('store_dynamic_score_statis'),CHARSET).date('Y-m-d-H',TIMESTAMP));
  247. exit();
  248. }
  249. View::assign('statlist',$statlist);
  250. View::assign('orderby',$this->search_arr['orderby']);
  251. View::assign('show_page',$stat_model->page_info->render());
  252. $this->setAdminCurItem('evalstore');
  253. return View::fetch('aftersale_evalstore');
  254. }
  255. function getRefundStateArray($type = 'all') {
  256. $state_array = array(
  257. '1' => lang('refund_state_confirm'),
  258. '2' => lang('refund_state_yes'),
  259. '3' => lang('refund_state_no')
  260. ); //卖家处理状态:1为待审核,2为同意,3为不同意
  261. View::assign('state_array', $state_array);
  262. $admin_array = array(
  263. '1' => lang('admin_state_1'),
  264. '2' => lang('admin_state_2'),
  265. '3' => lang('admin_state_3')
  266. ); //确认状态:1为买家或卖家处理中,2为待平台管理员处理,3为退款退货已完成
  267. View::assign('admin_array', $admin_array);
  268. $state_data = array(
  269. 'seller' => $state_array,
  270. 'admin' => $admin_array
  271. );
  272. if ($type == 'all') {
  273. return $state_data; //返回所有
  274. }
  275. return $state_data[$type];
  276. }
  277. protected function getAdminItemList()
  278. {
  279. $menu_array=array(
  280. array('name'=>'refund','text'=>lang('stat_refund'),'url'=>(string)url('Stataftersale/refund')),
  281. array('name'=>'evalstore','text'=>lang('stat_evalstore'),'url'=>(string)url('Stataftersale/evalstore')),
  282. );
  283. return $menu_array;
  284. }
  285. }