Order.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\shop;
  9. use app\ais\controller\Common;
  10. use app\ais\model\AisShopOrder;
  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("ais/shopOrder/index")]]);
  17. }
  18. /**
  19. * 列表
  20. */
  21. public function index(int $types = 1){
  22. $condition = [];
  23. $condition[] = ['AisShopOrder.member_miniapp_id','=',$this->member_miniapp_id];
  24. $condition[] = ['AisShopOrder.is_del', '=',0];
  25. $time = Request::param('time/d',0);
  26. $starttime = Request::param('starttime/s');
  27. $endtime = Request::param('endtime/s');
  28. if ($time) {
  29. switch ($time) {
  30. case 2:
  31. list($start, $end) = Time::yesterday();
  32. break;
  33. case 30:
  34. list($start, $end) = Time::month();
  35. break;
  36. case 60:
  37. list($start, $end) = Time::lastMonth();
  38. break;
  39. default:
  40. list($start, $end) = Time::today();
  41. break;
  42. }
  43. $condition[] = ['create_time', '>=', $start];
  44. $condition[] = ['create_time', '<=', $end];
  45. } else {
  46. if ($starttime) {
  47. $condition[] = ['create_time', '>=', strtotime($starttime)];
  48. }
  49. if ($endtime) {
  50. $condition[] = ['create_time', '<=', strtotime($endtime)];
  51. }
  52. }
  53. switch ($types) {
  54. case 1:
  55. $condition[] = ['paid_at', '=',1];
  56. $condition[] = ['status', '=', 0];
  57. break;
  58. case 2:
  59. $condition[] = ['paid_at', '=',1];
  60. $condition[] = ['status', '=', 1];
  61. break;
  62. default:
  63. $condition[] = ['paid_at', '=',0];
  64. break;
  65. }
  66. $keyword = Request::param('keyword/s');
  67. $lists = AisShopOrder::hasWhere('shop', function($query) use($keyword) {
  68. if($keyword){
  69. $query->where('phone|name', 'like', '%'.$keyword.'%', 'or');
  70. }
  71. })->where($condition)->order('id desc')->paginate(20, false, ['query' => ['keyword' => $keyword, 'starttime' => $starttime, 'endtime' => $endtime, 'time' => $time]]);
  72. $view['pay'] = AisShopOrder::where($this->mini_program)->where(['paid_at' => 1])->sum('amount');
  73. $view['invalid'] = AisShopOrder::where($this->mini_program)->where(['status' => 1])->sum('amount');
  74. $view['lists'] = $lists;
  75. $view['types'] = $types;
  76. $view['keyword'] = $keyword;
  77. $view['time'] = $time;
  78. $view['starttime'] = $starttime;
  79. $view['endtime'] = $endtime;
  80. return view()->assign($view);
  81. }
  82. /**
  83. * 订单详情
  84. */
  85. public function detail(int $id){
  86. $view['info'] = AisShopOrder::where(['id' => $id])->find();
  87. return view()->assign($view);
  88. }
  89. /**
  90. * 删除
  91. */
  92. public function delete($id){
  93. $result = AisShopOrder::update(['is_del'=>1],['id' => $id]);
  94. if($result){
  95. return enjson(200,'操作成功',['url' => url('ais/shopOrder/index',['status' => $this->request->param('status/d')])]);
  96. }
  97. return enjson(0,'操作失败');
  98. }
  99. /**
  100. * 订单完成
  101. */
  102. public function force_completion($id){
  103. $result = AisShopOrder::update(['status'=>1],['id' => $id]);
  104. if($result){
  105. return enjson(200,'操作成功',['url' => url('ais/shopOrder/index',['status' => $this->request->param('status/d')])]);
  106. }else{
  107. return enjson(0,'操作失败');
  108. }
  109. }
  110. }