Order.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 订单管理
  7. */
  8. namespace app\ais\controller;
  9. use app\ais\controller\Common;
  10. use app\ais\model\AisOrder;
  11. use think\facade\Request;
  12. use think\helper\Time;
  13. class Order extends Common{
  14. public function initialize() {
  15. parent::initialize();
  16. $this->assign('pathMaps', [['name'=>'买单帐单','url'=>url("order/index")]]);
  17. }
  18. /**
  19. * 用户订单
  20. * @access public
  21. */
  22. public function Index(int $state = 1){
  23. $condition = [];
  24. $condition[] = ['member_miniapp_id', '=', $this->member_miniapp_id];
  25. $store_id = Request::param('store_id/d', '');
  26. $store_name = Request::param('store_name');
  27. if ($store_id) {
  28. $condition[] = ['store_id', '=', $store_id];
  29. }
  30. $time = Request::param('time/d',0);
  31. if($time){
  32. switch ($time) {
  33. case 2:
  34. list($start, $end) = Time::yesterday();
  35. break;
  36. case 30:
  37. list($start, $end) = Time::month();
  38. break;
  39. case 60:
  40. list($start, $end) = Time::lastMonth();
  41. break;
  42. default:
  43. list($start, $end) = Time::today();
  44. break;
  45. }
  46. $condition[] = ['paid_time','>=',$start];
  47. $condition[] = ['paid_time','<=',$end];
  48. }
  49. $starttime = Request::param('starttime/s');
  50. $endtime = Request::param('endtime/s');
  51. if($starttime){
  52. $condition[] = ['paid_time','>=',strtotime($starttime)];
  53. }
  54. if($endtime){
  55. $condition[] = ['paid_time','<=',strtotime($endtime)];
  56. }
  57. $view['orders'] = AisOrder::where($condition)->where(['state' => $state ? 1 : 0])->order('id desc')->paginate(20, false, ['query' => ['store_id' => $store_id, 'store_name' => $store_name, 'time' => $time, 'starttime' => $starttime, 'endtime' => $endtime]]);
  58. $view['order_num'] = AisOrder::where($condition)->where(['state' => 1])->count();
  59. $view['user_amount'] = AisOrder::where($condition)->where(['state' => 1])->sum('amount');
  60. $view['order_amount'] = AisOrder::where($condition)->where(['state' => 1])->sum('price');
  61. $view['coupon_price'] = money($view['user_amount'] - $view['order_amount']);
  62. $view['time'] = $time;
  63. $view['starttime'] = $starttime;
  64. $view['endtime'] = $endtime;
  65. $view['store_id'] = $store_id;
  66. $view['store_name'] = $store_name;
  67. return view()->assign($view);
  68. }
  69. }