Index.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\controller\Site;
  4. use app\common\library\Common;
  5. use app\common\controller\Api;
  6. use app\common\library\WxPay;
  7. use EasyWeChat\Factory;
  8. use think\Db;
  9. use think\facade\Validate;
  10. use app\common\library\AliPay;
  11. use function Qiniu\arraySort;
  12. use app\common\model\SiteModel;
  13. use app\common\model\TownsModel;
  14. /**
  15. * @title 首页
  16. * @controller Index
  17. */
  18. class Index extends Api
  19. {
  20. /**
  21. * @title 当月截止昨日各乡镇总数量/中间大图数据
  22. * @desc 当月截止昨日各乡镇总数量/中间大图数据
  23. * @url /api/Index/townsData
  24. * @method POST
  25. * @tag 基础
  26. */
  27. public function townsData(){
  28. $start = date('Y-m-01'); //当月开始日期
  29. $end = date("Y-m-d",strtotime("-1 day")); //昨天日期
  30. $list = Db::name('system_towns')
  31. ->where('is_del',1)
  32. ->field('id,name')
  33. ->select();
  34. $dm = '005,006,007,008,018,029,040,042,043,066,068,069,070,071,073,074,075,076,077,078,079,080,081,083,084,085,086,087,090,091,092,094,096,097,098,099,123,124,125,126,127';
  35. foreach ($list as &$v){
  36. if ($v['name']=='城关街道办'){
  37. $v['value'] = Db::name('system_values3')
  38. ->whereBetween('date',[$start,$end])
  39. ->whereIn('dm',$dm)
  40. ->sum('value') ? : 0;
  41. }else{
  42. $site_ids = Db::name('system_site')->where('towns_id',$v['id'])->column('id');
  43. $v['value'] = Db::name('system_values')
  44. ->whereIn('site_id',$site_ids)
  45. ->where('name','总签收')
  46. ->whereBetween('date',[$start,$end])
  47. ->sum('value') ? : 0;
  48. }
  49. }
  50. $list = arraySort($list,'value',SORT_DESC);
  51. $this->success('成功',$list);
  52. }
  53. /**
  54. * @title 全县快递量
  55. * @desc 全县快递量
  56. * @url /api/Index/CountyExpress
  57. * @method POST
  58. * @tag 基础
  59. */
  60. public function CountyExpress(){
  61. $date = date('Y-m-d');
  62. $list = Db::name('system_values')->where('date','lt',$date)->limit(12)->group('date')->column('date');
  63. $arr = array();
  64. foreach ($list as &$v){
  65. $array['date'] =$v;
  66. $array['value']= Db::name('system_values')->where('date',$v)->where('name','总签收')->sum('value') ? : 0;
  67. array_push($arr,$array);
  68. }
  69. $this->success('成功',$arr);
  70. }
  71. /**
  72. * @title 截止昨日年度快递总量/昨日快递总量
  73. * @desc 截止昨日年度快递总量/昨日快递总量
  74. * @url /api/Index/YesterDayOrBeforeExpressTotal
  75. * @method POST
  76. * @tag 基础
  77. *
  78. * @param name:type type:int require:0 default:1 desc:1:截止昨日年度快递总量2:昨日快递总量
  79. */
  80. public function YesterDayOrBeforeExpressTotal(){
  81. $type = input('type',1);
  82. if ($type==1){
  83. $start = date('Y-01-01'); //当年开始日期
  84. $end = date("Y-m-d",strtotime("-1 day")); //昨天日期
  85. }else{
  86. $start = date("Y-m-d",strtotime("-1 day")); //昨天日期
  87. $end = date("Y-m-d",strtotime("-1 day")); //昨天日期
  88. }
  89. $kd = Db::name('system_kd')->field('id,name')->select();
  90. foreach ($kd as &$v){
  91. if (in_array($v['name'],['中通','申通'])){
  92. $v['value'] = Db::name('system_values2')
  93. ->whereBetween('date',[$start,$end])
  94. ->where('name',$v['name'])
  95. ->sum('value') ? : 0;
  96. }else{
  97. $value = Db::name('system_values')
  98. ->whereBetween('date',[$start,$end])
  99. ->where('name',$v['name'])
  100. ->sum('value') ? : 0;
  101. $value2 = Db::name('system_values2')
  102. ->whereBetween('date',[$start,$end])
  103. ->where('name',$v['name'])
  104. ->sum('value') ? : 0;
  105. $v['value'] = floatval(bcadd($value,$value2));
  106. }
  107. }
  108. $total = array_sum(array_column($kd,'value'));
  109. $list = arraySort($kd,'value',SORT_DESC);
  110. $this->success('成功',['total'=>$total,'list'=>$list]);
  111. }
  112. /**
  113. * @title 查询页面数据
  114. * @desc 查询页面数据
  115. * @url /api/Index/SellDate
  116. * @method POST
  117. * @tag 基础
  118. *
  119. * @param name:name type:string require:0 default: desc:站点名称
  120. * @param name:town_name type:string require:0 default: desc:乡镇名称
  121. * @param name:date type:date require:0 default: desc:日期
  122. */
  123. public function SellDate(){
  124. $name = input('name'); //站点名称
  125. $town_name = input('town_name'); //乡镇名称
  126. $date = input('date'); //日期
  127. $list = Db::name('system_site')->alias('a')
  128. ->leftJoin('system_towns b','a.towns_id=b.id')
  129. ->field('a.id,a.code,a.name,b.name as towns_name')
  130. ->where('a.is_del',1)
  131. ->when($name,function($query) use ($name){
  132. $query->whereLike('a.name','%'.$name.'%');
  133. })
  134. ->when($town_name,function($query) use ($town_name){
  135. $query->whereLike('b.name','%'.$town_name.'%');
  136. })
  137. ->order('a.id asc')
  138. ->select();
  139. $kd = Db::name('system_kd')->field('name')->select();
  140. $kd = array_merge([['name' => '总签收']],$kd);
  141. foreach ($list as &$v){
  142. foreach ($kd as &$a){
  143. $v[$a['name']] = Db::name('system_values')
  144. ->where('site_id',$v['id'])
  145. ->when($date,function($query) use ($date){
  146. $query->where('date',$date);
  147. })
  148. ->where('name',$a['name'])
  149. ->sum('value') ? : 0;
  150. }
  151. }
  152. $this->success('成功',['list'=>$list,'kd'=>$kd]);
  153. }
  154. /**
  155. * @title 查询页面数据
  156. * @desc 查询页面数据
  157. * @url /api/Index/SellDate
  158. * @method POST
  159. * @tag 基础
  160. *
  161. * @param name:name type:string require:0 default: desc:站点名称
  162. * @param name:town_name type:string require:0 default: desc:乡镇名称
  163. * @param name:date type:date require:0 default: desc:日期
  164. */
  165. public function SellDate2(){
  166. $name = input('name'); //站点名称
  167. $town_name = input('town_name'); //乡镇名称
  168. $date = input('date'); //日期
  169. $list = SiteModel::where('is_del',1)
  170. ->with('towns,kd')
  171. ->field('id,code,name')
  172. ->select();
  173. dump($list);
  174. die;
  175. }
  176. }