ShopOrder.php 4.0 KB

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