Stataftersale.php 14 KB

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