Kd.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller;
  15. use app\service\queue\ImportTable2Queue;
  16. use app\service\queue\WechatQueue;
  17. use library\Controller;
  18. use think\cache\driver\Redis;
  19. use think\Db;
  20. use think\facade\Validate;
  21. use app\common\library\PHPExcelService;
  22. /**
  23. * 快递管理
  24. * Class help_center
  25. */
  26. class Kd extends Controller
  27. {
  28. /**
  29. * 绑定数据表
  30. * @var string
  31. */
  32. protected $table = 'system_kd';
  33. /**
  34. * 快递数据管理
  35. * @auth true
  36. * @menu true
  37. * @throws \think\Exception
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @throws \think\exception\DbException
  41. * @throws \think\exception\PDOException
  42. */
  43. public function index()
  44. {
  45. $this->title = '快递数据管理';
  46. sysoplog('快递管理', '访问快递管理页面');
  47. $this->_query('system_values')
  48. ->group('date')
  49. ->field('id,date')
  50. ->order('date desc')
  51. ->dateBetween('date')
  52. ->page();
  53. }
  54. /**
  55. * 数据列表处理
  56. * @auth true
  57. * @menu true
  58. * @param array $data
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. * @throws \think\exception\DbException
  62. */
  63. protected function _index_page_filter(&$data){
  64. $kd = Db::name('system_kd')->field('name')->select();
  65. $this->kd = $kd;
  66. foreach ($data as &$v){
  67. foreach ($kd as &$a){
  68. if (in_array($a['name'],['中通','申通'])){
  69. $v[$a['name']] = Db::name('system_values2')
  70. ->where('date',$v['date'])
  71. ->where('name',$a['name'])
  72. ->sum('value') ? : 0;
  73. }else{
  74. $value = Db::name('system_values')
  75. ->where('date',$v['date'])
  76. ->where('name',$a['name'])
  77. ->sum('value') ? : 0;
  78. $value2 = Db::name('system_values2')
  79. ->where('date',$v['date'])
  80. ->where('name',$a['name'])
  81. ->sum('value') ? : 0;
  82. $v[$a['name']] = floatval(bcadd($value,$value2));
  83. }
  84. }
  85. }
  86. }
  87. /**
  88. * 快递数据管理
  89. * @auth false
  90. * @menu false
  91. * @throws \think\Exception
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. * @throws \think\exception\DbException
  95. * @throws \think\exception\PDOException
  96. */
  97. public function index2()
  98. {
  99. $this->title = '快递数据管理';
  100. $query = $this->_query($this->table)->like('name');
  101. $query->order('id asc')
  102. ->page();
  103. }
  104. /**
  105. * 数据列表处理
  106. * @auth false
  107. * @menu false
  108. * @param array $data
  109. * @throws \think\db\exception\DataNotFoundException
  110. * @throws \think\db\exception\ModelNotFoundException
  111. * @throws \think\exception\DbException
  112. */
  113. protected function _index2_page_filter(&$data)
  114. {
  115. $date = '';
  116. $start_date_time = '';
  117. $end_date_time = '';
  118. if (isset($_GET['date']) && $_GET['date']){
  119. $date = $_GET['date'];
  120. $time = explode(' - ',$date);
  121. $start_date_time = $time[0].' 00:00:00';
  122. $end_date_time = $time[1].' 23:59:59';
  123. }
  124. foreach ($data as &$v){
  125. if (in_array($v['name'],['中通','申通'])){
  126. $v['value'] = Db::name('system_values2')
  127. ->when($date,function ($query) use ($date,$start_date_time,$end_date_time){
  128. $query->whereBetweenTime('date',$start_date_time,$end_date_time);
  129. })
  130. ->where('name',$v['name'])
  131. ->sum('value') ? : 0;
  132. }else{
  133. $value = Db::name('system_values')
  134. ->when($date,function ($query) use ($date,$start_date_time,$end_date_time){
  135. $query->whereBetweenTime('date',$start_date_time,$end_date_time);
  136. })
  137. ->where('name',$v['name'])->sum('value') ? : 0;
  138. $value2 = Db::name('system_values2')
  139. ->when($date,function ($query) use ($date,$start_date_time,$end_date_time){
  140. $query->whereBetweenTime('date',$start_date_time,$end_date_time);
  141. })
  142. ->where('name',$v['name'])->sum('value') ? : 0;
  143. $v['value'] = floatval(bcadd($value,$value2));
  144. }
  145. }
  146. }
  147. }