Index.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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\KdModel;
  14. /**
  15. * @title 首页
  16. * @controller Index
  17. */
  18. class Index extends Api
  19. {
  20. /**
  21. * @title 获取天气
  22. * @desc 获取天气
  23. * @url /api/Index/GetWeather
  24. * @method POST
  25. * @tag 基础
  26. */
  27. public function GetWeather(){
  28. $weather = Db::name('system_day')->where('date',date('Y-m-d'))->value('weather') ? : "晴转多云";
  29. $this->success('成功',['weather'=>$weather]);
  30. }
  31. /**
  32. * @title 当月截止昨日各乡镇总数量/中间大图数据
  33. * @desc 当月截止昨日各乡镇总数量/中间大图数据
  34. * @url /api/Index/townsData
  35. * @method POST
  36. * @tag 基础
  37. */
  38. public function townsData(){
  39. $start = date('Y-m-01'); //当月开始日期
  40. $end = date("Y-m-d",strtotime("-1 day")); //昨天日期
  41. $list = Db::name('system_towns')
  42. ->where('is_del',1)
  43. ->field('id,name')
  44. ->select();
  45. $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';
  46. foreach ($list as &$v){
  47. if ($v['name']=='城关街道办'){
  48. $v['value'] = Db::name('system_values3')
  49. ->whereBetween('date',[$start,$end])
  50. ->whereIn('dm',$dm)
  51. ->sum('value') ? : 0;
  52. }else{
  53. $site_ids = Db::name('system_site')->where('towns_id',$v['id'])->column('id');
  54. $v['value'] = Db::name('system_values')
  55. ->whereIn('site_id',$site_ids)
  56. ->where('name','总签收')
  57. ->whereBetween('date',[$start,$end])
  58. ->sum('value') ? : 0;
  59. }
  60. }
  61. $list = arraySort($list,'value',SORT_DESC);
  62. $this->success('成功',$list);
  63. }
  64. /**
  65. * @title 全县快递量
  66. * @desc 全县快递量
  67. * @url /api/Index/CountyExpress
  68. * @method POST
  69. * @tag 基础
  70. */
  71. public function CountyExpress(){
  72. $month = monthpast();
  73. $arr = array();
  74. $no_array = ['中通','申通','总签收'];
  75. foreach ($month as &$v){
  76. $array['date'] =$v;
  77. $value1 = Db::name('system_values')
  78. ->whereRaw("date_format(date,'%Y-%m')='".$v."'")
  79. ->whereNotIn('name',$no_array)
  80. ->sum('value') ? : 0;
  81. $value2 = Db::name('system_values2')
  82. ->whereRaw("date_format(date,'%Y-%m')='".$v."'")
  83. ->sum('value') ? : 0;
  84. $array['value'] = floatval(bcadd($value1,$value2));
  85. array_push($arr,$array);
  86. }
  87. $arr = arraySort($arr,'date',SORT_ASC);
  88. $this->success('成功',$arr);
  89. }
  90. /**
  91. * @title 全县快递量
  92. * @desc 全县快递量
  93. * @url /api/Index/CountyExpress
  94. * @method POST
  95. * @tag 基础
  96. */
  97. public function CountyExpress2(){
  98. $date = date('Y-m-d');
  99. $list = Db::name('system_values')->where('date','lt',$date)
  100. ->group('date')->limit(12)
  101. ->order('date asc')
  102. ->column('date');
  103. $arr = array();
  104. foreach ($list as &$v){
  105. $array['date'] =$v;
  106. $array['value']= Db::name('system_values')->where('date',$v)->where('name','总签收')->sum('value') ? : 0;
  107. array_push($arr,$array);
  108. }
  109. $this->success('成功',$arr);
  110. }
  111. /**
  112. * @title 截止昨日年度快递总量/昨日快递总量
  113. * @desc 截止昨日年度快递总量/昨日快递总量
  114. * @url /api/Index/YesterDayOrBeforeExpressTotal
  115. * @method POST
  116. * @tag 基础
  117. *
  118. * @param name:type type:int require:0 default:1 desc:1:截止昨日年度快递总量2:昨日快递总量
  119. */
  120. public function YesterDayOrBeforeExpressTotal(){
  121. $type = input('type',1);
  122. if ($type==1){
  123. $start = date('Y-01-01'); //当年开始日期
  124. $end = date("Y-m-d",strtotime("-1 day")); //昨天日期
  125. }else{
  126. $start = date("Y-m-d",strtotime("-1 day")); //昨天日期
  127. $end = date("Y-m-d",strtotime("-1 day")); //昨天日期
  128. }
  129. $kd = Db::name('system_kd')->field('id,name')->select();
  130. foreach ($kd as &$v){
  131. if (in_array($v['name'],['中通','申通'])){
  132. $v['value'] = Db::name('system_values2')
  133. ->whereBetween('date',[$start,$end])
  134. ->where('name',$v['name'])
  135. ->sum('value') ? : 0;
  136. }else{
  137. $value = Db::name('system_values')
  138. ->whereBetween('date',[$start,$end])
  139. ->where('name',$v['name'])
  140. ->sum('value') ? : 0;
  141. $value2 = Db::name('system_values2')
  142. ->whereBetween('date',[$start,$end])
  143. ->where('name',$v['name'])
  144. ->sum('value') ? : 0;
  145. $v['value'] = floatval(bcadd($value,$value2));
  146. }
  147. }
  148. $total = array_sum(array_column($kd,'value'));
  149. $list = arraySort($kd,'value',SORT_DESC);
  150. $this->success('成功',['total'=>$total,'list'=>$list]);
  151. }
  152. /**
  153. * @title 今日数据
  154. * @desc 今日数据
  155. * @url /api/Index/ThisDayData
  156. * @method POST
  157. * @tag 基础
  158. */
  159. public function ThisDayData(){
  160. $total = Db::name('system_day_fake')
  161. ->where('date',date('Y-m-d'))
  162. ->sum('value') ? : 0;
  163. $list = Db::name('system_day_fake')
  164. ->where('date',date('Y-m-d'))
  165. ->field('name,value')
  166. ->order('value desc')
  167. ->select();
  168. $this->success('成功',compact('total','list'));
  169. }
  170. /**
  171. * @title 查询页面数据
  172. * @desc 查询页面数据
  173. * @url /api/Index/SellDate2
  174. * @method POST
  175. * @tag 基础
  176. *
  177. * @param name:name type:string require:0 default: desc:站点名称
  178. * @param name:town_name type:string require:0 default: desc:乡镇名称
  179. * @param name:date type:string require:0 default: desc:日期
  180. * @param name:page type:int require:0 default:1 desc:
  181. * @param name:limit type:int require:0 default:10 desc:
  182. */
  183. public function SellDate2(){
  184. $name = input('name'); //站点名称
  185. $town_name = input('town_name'); //乡镇名称
  186. $date = input('date'); //日期
  187. $Nowpage = input('page',1);
  188. $limits = input("limit",10);
  189. $count = Db::name('system_site')->alias('a')
  190. ->leftJoin('system_towns b','a.towns_id=b.id')
  191. ->field('a.id,a.code,a.name,b.name as towns_name')
  192. ->where('a.is_del',1)
  193. ->when($name,function($query) use ($name){
  194. $query->whereLike('a.name','%'.$name.'%');
  195. })
  196. ->when($town_name,function($query) use ($town_name){
  197. $query->whereLike('b.name','%'.$town_name.'%');
  198. })
  199. ->count();
  200. $list = Db::name('system_site')->alias('a')
  201. ->leftJoin('system_towns b','a.towns_id=b.id')
  202. ->field('a.id,a.code,a.name,b.name as towns_name')
  203. ->where('a.is_del',1)
  204. ->when($name,function($query) use ($name){
  205. $query->whereLike('a.name','%'.$name.'%');
  206. })
  207. ->when($town_name,function($query) use ($town_name){
  208. $query->whereLike('b.name','%'.$town_name.'%');
  209. })
  210. ->order('a.id asc')
  211. ->page($Nowpage,$limits)
  212. ->select();
  213. $kd = Db::name('system_kd')->field('name')->select();
  214. $kd = array_merge([['name' => '总签收']],$kd);
  215. foreach ($list as &$v){
  216. foreach ($kd as &$a){
  217. $v[$a['name']] = Db::name('system_values')
  218. ->where('site_id',$v['id'])
  219. ->when($date,function($query) use ($date){
  220. $query->where('date',$date);
  221. })
  222. ->where('name',$a['name'])
  223. ->sum('value') ? : 0;
  224. }
  225. }
  226. $this->success('成功',['count'=>$count,'list'=>$list,'kd'=>$kd]);
  227. }
  228. /**
  229. * @title 查询页面数据
  230. * @desc 查询页面数据
  231. * @url /api/Index/SellDate
  232. * @method POST
  233. * @tag 基础
  234. *
  235. * @param name:name type:string require:0 default: desc:站点名称
  236. * @param name:town_name type:string require:0 default: desc:乡镇名称
  237. * @param name:date type:string require:0 default: desc:日期
  238. * @param name:page type:int require:0 default:1 desc:
  239. * @param name:limit type:int require:0 default:10 desc:
  240. */
  241. public function SellDate(){
  242. $name = input('name'); //站点名称
  243. $town_name = input('town_name'); //乡镇名称
  244. $date = input('date'); //日期
  245. $Nowpage = input('page',1);
  246. $limits = input("limit",10);
  247. $count = SiteModel::alias('a')
  248. ->leftJoin('system_towns b','a.towns_id=b.id')
  249. ->when($name,function($query) use ($name){
  250. $query->whereLike('a.name','%'.$name.'%');
  251. })
  252. ->when($town_name,function($query) use ($town_name){
  253. $query->whereLike('b.name','%'.$town_name.'%');
  254. })
  255. ->where('a.is_del',1)
  256. ->where('b.is_del',1)
  257. ->count();
  258. $list = SiteModel::alias('a')
  259. ->leftJoin('system_towns b','a.towns_id=b.id')
  260. ->when($name,function($query) use ($name){
  261. $query->whereLike('a.name','%'.$name.'%');
  262. })
  263. ->when($town_name,function($query) use ($town_name){
  264. $query->whereLike('b.name','%'.$town_name.'%');
  265. })
  266. ->field('a.id,a.code,a.name,b.name as towns_name')
  267. ->with(['kd'=>function($query) use ($date){
  268. $query->when($date,function ($q) use ($date){
  269. $q->where('date',$date);
  270. })
  271. ->group('site_id,name')
  272. ->order('id asc')
  273. ->field('id,site_id,name,sum(value) as value');
  274. }])
  275. ->where('a.is_del',1)
  276. ->where('b.is_del',1)
  277. ->order('a.id asc')
  278. ->page($Nowpage,$limits)
  279. ->select();
  280. $kd = Db::name('system_kd')->field('name')->select();
  281. $kd = array_merge([['name' => '总签收']],$kd);
  282. foreach ($list as &$v) {
  283. $kdarray = array();
  284. foreach ($v['kd'] as &$a){
  285. $kdarray[$a['name']] = $a['value'];
  286. }
  287. foreach ($kd as $key=>$b){
  288. if (empty($kdarray)){
  289. $v[$b['name']] = 0;
  290. }else{
  291. $v[$b['name']] = isset($kdarray[$b['name']]) ? (int)$kdarray[$b['name']] : 0;
  292. }
  293. }
  294. unset($v['kd']);
  295. }
  296. $this->success('成功',['count'=>$count,'list'=>$list,'kd'=>$kd]);
  297. }
  298. }