Order.php 4.2 KB

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