Stat.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Cache;
  6. use think\facade\Db;
  7. use think\facade\Response;
  8. use think\helper\Arr;
  9. class Stat extends Base{
  10. public function __construct(App $app) {parent::__construct($app);}
  11. public function stats(){
  12. $data=Cache::get("pay_inv_stat");
  13. return app_show(0,"获取成功",$data);
  14. }
  15. public function depart(){
  16. $data=Cache::get("departContent");
  17. return app_show(0,"获取成功",$data);
  18. }
  19. public function total(){
  20. $list =Db::name("total_tips")->where("year",date("Y"))->column("depart_id,depart_ment,tips,month,year,total,th_total,profit,rate,prate");
  21. $data=[
  22. [
  23. "depart_ment"=>'总计',
  24. "content"=>[
  25. 1=>["tips"=>0,"month"=>1,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  26. 2=>["tips"=>0,"month"=>2,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  27. 3=>["tips"=>0,"month"=>3,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  28. 4=>["tips"=>0,"month"=>4,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  29. 5=>["tips"=>0,"month"=>5,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  30. 6=>["tips"=>0,"month"=>6,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  31. 7=>["tips"=>0,"month"=>7,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  32. 8=>["tips"=>0,"month"=>8,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  33. 9=>["tips"=>0,"month"=>9,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  34. 10=>["tips"=>0,"month"=>10,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  35. 11=>["tips"=>0,"month"=>11,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  36. 12=>["tips"=>0,"month"=>12,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  37. ]
  38. ]
  39. ];
  40. foreach ($list as $value){
  41. $temp=["tips"=>$value['tips'],"month"=>$value['month'],"year"=>date("Y"),"total"=>$value['total'],"th_total"=>$value['th_total'],"profit"=>$value['profit'],"rate"=>$value['rate'],"prate"=>$value['prate']];
  42. $data[0]['content'][$value['month']]["tips"]+=$value['tips'];
  43. $data[0]['content'][$value['month']]["total"]+=$value['total'];
  44. $data[0]['content'][$value['month']]["th_total"]+=$value['th_total'];
  45. $data[0]['content'][$value['month']]["profit"]=$data[0]['content'][$value['month']]["total"] - $data[0]['content'][$value['month']]["th_total"];
  46. $data[0]['content'][$value['month']]["rate"]=round($data[0]['content'][$value['month']]["total"]/$data[0]['content'][$value['month']]["tips"] *100,2);
  47. $data[0]['content'][$value['month']]["prate"]=round($data[0]['content'][$value['month']]["profit"]/$data[0]['content'][$value['month']]["tips"] *100,2);
  48. if (isset($data[$value['depart_id']])){
  49. $data[$value['depart_id']]['content'][$value['month']]= $temp;
  50. }else{
  51. $data[$value['depart_id']]["depart_ment"]=$value['depart_ment'];
  52. $data[$value['depart_id']]['content'][$value['month']]= $temp;
  53. }
  54. }
  55. return app_show(0,"获取成功",$data);
  56. }
  57. public function departEveryDay(){
  58. $post = $this->request->only(["daytime"=>date("Y-m-d H:i:s")],"post","trim");
  59. $depart_tips = Db::connect("mysql_wsm3.0")->name("depart_tips")
  60. ->where("year",date("Y",strtotime($post["daytime"])))
  61. ->where("month",date("m",strtotime($post["daytime"])))
  62. ->select();
  63. if($depart_tips->isEmpty()){
  64. return error_show(1004,"未获取到各部门指标");
  65. }
  66. $return=[];
  67. $everyday =Db::name("depart_everyday")
  68. ->where("day_time",date("Y-m-d",strtotime($post["daytime"])))
  69. ->where("companyNo","GS2203161855277894")
  70. ->column("sale_total,th_total,zy_sale_total,channel_sale_total,cgd_total,cgd_th_total","depart_id");
  71. $everymonth =Db::name("depart_everyday")
  72. ->whereBetween("day_time",[date("Y-m-01",strtotime($post["daytime"])),date("Y-m-t", strtotime($post["daytime"]))])
  73. ->where("companyNo","GS2203161855277894")
  74. ->group("depart_id")
  75. ->column("sum(sale_total) as msale_total,sum(th_total) as mth_total,sum(cgd_total) as mcgd_total,sum(cgd_th_total) as mcgd_th_total,sum(zy_sale_total) as mzy_sale_total,sum(channel_sale_total) as mchannel_sale_total,depart_id","depart_id");
  76. foreach ($depart_tips as $value){
  77. $temp=[];
  78. $temp["depart"] = $value['depart_item'];
  79. $temp["total_tips"] = $value['total_tips'];
  80. $temp["sale_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['sale_total']:0;
  81. $temp["cgd_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['cgd_total']:0;
  82. $temp["cgd_th_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['cgd_th_total']:0;
  83. $temp["zy_sale_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['zy_sale_total']:0;
  84. $temp["channel_sale_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['channel_sale_total']:0;
  85. $temp["th_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['th_total']:0;
  86. $temp["msale_total"] =isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['msale_total']:0;
  87. $temp["mth_total"] = isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['mth_total']:0;
  88. $temp["mchannel_sale_total"] = isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['mchannel_sale_total']:0;
  89. $temp["mzy_sale_total"] = isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['mzy_sale_total']:0;
  90. $temp["mcgd_total"] = isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['mcgd_total']:0;
  91. $temp["mcgd_th_total"] = isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['mcgd_th_total']:0;
  92. $return[]=$temp;
  93. }
  94. return app_show(0,"获取成功",$return);
  95. }
  96. public function companyEveryMonth(){
  97. $post = $this->request->only(["daytime"=>date("Y-m-d H:i:s"),"companyNo"=>''],"post","trim");
  98. $where=[];
  99. if($post['companyNo']!='') $where=["companyNo"=>$post['companyNo']];
  100. $depart_tips = Db::name("depart_tips")
  101. ->where("year",date("Y",strtotime($post["daytime"])))
  102. ->where("month",date("m",strtotime($post["daytime"])))
  103. ->where($where)
  104. ->column("*","companyNo");
  105. if(empty($depart_tips)){
  106. return error_show(1004,"未获取到各部门指标");
  107. }
  108. $return=[];
  109. $sort=["GS2302231125079621",'GS2302231323386950','GS2304031312553746','GS2302231124114965','GS2203161855277894'];
  110. foreach ($sort as $value){
  111. $temp=[];
  112. if(isset($depart_tips[$value])){
  113. $temp["companyName"] = $depart_tips[$value]['companyName'];
  114. $temp["total_tips"] = $depart_tips[$value]['total_tips'];
  115. $temp["dayinfo"] =Db::name("depart_company")
  116. ->where("day_time",date("Y-m-d",strtotime($post["daytime"])))
  117. ->where(["companyNo"=>$value])
  118. ->column("sale_total,th_total,type,cgd_total,cgd_th_total,companyNo");;
  119. $temp["monthinfo"] =Db::name("depart_company")
  120. ->whereBetween("day_time",[date("Y-m-01",strtotime($post["daytime"])),date("Y-m-t", strtotime($post["daytime"]))])
  121. ->where(["companyNo"=>$value])
  122. ->group("companyNo,type")
  123. ->column("sum(sale_total) as msale_total,sum(th_total) as mth_total,sum(cgd_total) as mcgd_total,sum(cgd_th_total) as mcgd_th_total,companyNo,type");
  124. $return[]=$temp;
  125. }
  126. }
  127. return app_show(0,"获取成功",$return);
  128. }
  129. //月统计销售额
  130. public function departEveryMonth(){
  131. $post = $this->request->only(["year"=>date("Y")],"post","trim");
  132. $depart_tips = Db::connect("mysql_wsm3.0")->name("depart_tips")
  133. ->where("year",$post['year'])
  134. ->group('month')->order("month asc")
  135. ->column("sum(total_tips)","month");
  136. if(empty($depart_tips)){
  137. return error_show(1004,"未获取到各月指标");
  138. }
  139. $return=[];
  140. foreach ($depart_tips as $key=>$value){
  141. $info = Db::name("depart_everyday")
  142. ->whereMonth("day_time",$post['year']."-".$key)
  143. ->field("sum(sale_total) sum_sale_total,
  144. sum(th_total) sum_th_total,
  145. sum(cgd_total) sum_cgd_total,
  146. sum(cgd_th_total) sum_cgd_th_total")
  147. ->findOrEmpty();
  148. $temp=[
  149. "month"=>$key,
  150. "total_tips"=>$value,
  151. "sale_total"=>$info["sum_sale_total"]??0,
  152. "th_total"=>$info["sum_th_total"]??0,
  153. "cgd_total"=>$info["sum_cgd_total"]??0,
  154. "cgd_th_total"=>$info["sum_cgd_th_total"]??0,
  155. ];
  156. $return[]=$temp;
  157. }
  158. return app_show(0,"获取成功",$return);
  159. }
  160. //月统计销售额
  161. public function companyEvery(){
  162. $post = $this->request->only(["year"=>date("Y"),"companyNo"=>""],"post","trim");
  163. $where=[];
  164. if($post['companyNo']!='') $where=["companyNo"=>$post['companyNo']];
  165. $depart_tips = Db::name("depart_tips")
  166. ->where("year",$post['year'])
  167. ->where($where)
  168. ->order("month asc")
  169. ->column("total_tips","month");
  170. if(empty($depart_tips)){
  171. return error_show(1004,"未获取到各月指标");
  172. }
  173. $return=[];
  174. foreach ($depart_tips as $key=>$value){
  175. $info = Db::name("depart_company")
  176. ->whereMonth("day_time",$post['year']."-".$key)
  177. ->where($where)
  178. ->field("sum(sale_total) sum_sale_total,sum(th_total) sum_th_total,sum(cgd_total) sum_cgd_total,sum(cgd_th_total) sum_cgd_th_total")
  179. ->findOrEmpty();
  180. $temp=[
  181. "month"=>$key,
  182. "total_tips"=>$value,
  183. "sale_total"=>$info["sum_sale_total"]??0,
  184. "th_total"=>$info["sum_th_total"]??0,
  185. "cgd_total"=>$info["sum_cgd_total"]??0,
  186. "cgd_th_total"=>$info["sum_cgd_th_total"]??0,
  187. ];
  188. $return[]=$temp;
  189. }
  190. return app_show(0,"获取成功",$return);
  191. }
  192. public function DzQrd(){
  193. $post = $this->request->only(["companyNo"=>'GS2203161855277894'],"post","trim");
  194. $list = Db::name("qrd_info")
  195. ->where([["createdTime","<=",date("Y-m-d H:i:s",time()-180*24*3600)],["companyNo","=",$post['companyNo']],["wpay_fee",">",0],["platform_type","=",1]])
  196. ->field("sequenceNo,if(cxCode='',sequenceNo,cxCode) cxCode,createdTime,customerName,department,ownerName,goodName,goodNum,goodPrice,totalPrice,apay_fee,wpay_fee,ainv_fee,winv_fee,inv_fee,
  197. wpay_fee-winv_fee ainv_wpay,datediff(now(),createdTime) dz_day,pay_status,inv_status,sendStatus")
  198. ->select();
  199. return app_show(0,"获取成功",$list);
  200. }
  201. }