WxOrders.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class WxOrders extends Auth
  5. {
  6. protected function initialize()
  7. {
  8. parent::initialize(); // TODO: Change the autogenerated stub
  9. }
  10. public function index(){
  11. if(request()->isAjax()){
  12. //分页参数
  13. $length = input('rows',10,'intval'); //每页条数
  14. $page = input('page',1,'intval'); //第几页
  15. $start = ($page - 1) * $length; //分页开始位置
  16. //排序
  17. $sortRow = input('sidx','sort','trim'); //排序列
  18. $sort = input('sord','asc','trim'); //排序方式
  19. $order = $sortRow.' '.$sort.' ,id desc';
  20. $order_sn = input('order_sn','','trim');
  21. if($order_sn){
  22. $map[] = ['order_sn','=',$order_sn];
  23. }
  24. $name = input('name','','trim');
  25. if($name){
  26. $map[] = ['name','like','%'.$name.'%'];
  27. }
  28. $status = input('status','','trim');
  29. if($status != ''){
  30. if($status==99){
  31. $ids = Db::name('wx_orders_refund')
  32. ->where('org_id',$this->orgId)
  33. ->where('status',1)
  34. ->column('order_id');
  35. if(empty($ids)){
  36. $map[]=['id','=',-1];
  37. }else{
  38. $map[]=['id','in',$ids];
  39. }
  40. }else{
  41. $map[] = ['status','=',$status];
  42. }
  43. }
  44. // if($this->user_id > 1){
  45. // $map[] = ['user_id','=',$this->user_id];
  46. // }
  47. $order_type = input('order_type','','trim');
  48. if($order_type!=''){
  49. $map[] = ['order_type','=',$order_type];
  50. }
  51. $cate_id = input('cate_id','','trim');
  52. if($cate_id != ''){
  53. $goodIds = Db::name('wx_goods')
  54. ->where('cate_id',$cate_id)
  55. ->column('id');
  56. if(empty($goodIds)){
  57. $map[] = ['id','=',-1];
  58. }else{
  59. $ii = Db::name('wx_orders_goods')
  60. ->where('goods_id','in',$goodIds)
  61. ->column('order_id');
  62. if(empty($ii)){
  63. $map[] = ['id','=',-1];
  64. }else{
  65. $map[] = ['id','in',$ii];
  66. }
  67. }
  68. }
  69. $b = input('begin','','trim');
  70. $e = input('end','','trim');
  71. if($b){
  72. $b = date('Y-m-d 00:00:00',strtotime($b));
  73. $map[] = ['create_time','>=',$b];
  74. }
  75. if($e){
  76. $e = date('Y-m-d 23:59:59',strtotime($e));
  77. $map[] = ['create_time','<=',$e];
  78. }
  79. $map[] = ['org_id','=',cur_org_id()];
  80. $map[] = ['del','=',0];
  81. $map = empty($map) ? true: $map;
  82. //数据查询
  83. $lists = Db::name('wx_orders')->where($map)->limit($start,$length)->order($order)->select();
  84. foreach ($lists as $k=>$v){
  85. $lists[$k]['status_name'] =isset(model('WxOrders')->status[$v['status']])?model('WxOrders')->status[$v['status']]:'';
  86. $r = model('wxOrders')->checkOrderSend($v['id']);
  87. $lists[$k]['checkOrderSend'] = $r;
  88. if($r==2){
  89. $lists[$k]['status_name'] = $lists[$k]['status_name'].'(已退款)';
  90. }elseif ($r==1){
  91. $lists[$k]['status_name'] = $lists[$k]['status_name'].'(部分退款)';
  92. }elseif ($r==3){
  93. $lists[$k]['status_name'] = $lists[$k]['status_name'].'(退款中)';
  94. }
  95. }
  96. //数据返回
  97. $totalCount = Db::name('wx_orders')->where($map)->count();
  98. $totalPage = ceil($totalCount/$length);
  99. $yzf = Db::name('wx_orders')
  100. ->where($map)
  101. ->where('status','in',[1,2,3])
  102. ->sum('amount');
  103. $ytk = Db::name('wx_orders')
  104. ->where($map)
  105. ->sum('refund_money');
  106. $result['yzf'] = $yzf;
  107. $result['ytk'] = $ytk;
  108. $result['page'] = $page;
  109. $result['total'] = $totalPage;
  110. $result['records'] = $totalCount;
  111. $result['rows'] = $lists;
  112. return json($result);
  113. }else{
  114. $cate = model('WxGoodsCate')->lists($this->orgId);
  115. $status = model('WxOrders')->status;
  116. $this->assign('status',$status);
  117. $this->assign('cate',$cate);
  118. $this->assign('meta_title','订单列表');
  119. return $this->fetch();
  120. }
  121. }
  122. public function details($id){
  123. if(!$id){
  124. $this->error('参数错误');
  125. }
  126. $ret = model('WxOrders')->details($id);
  127. $this->assign('info',$ret);
  128. $this->assign('meta_title','订单详情');
  129. return $this->fetch();
  130. }
  131. public function send($id){
  132. $info = Db::name('wx_orders')->where('id',$id)
  133. ->find();
  134. if($info['status']!=1){
  135. $this->error('当前订单状态不可发货');
  136. }
  137. $res = Db::name('wx_orders')->where('id',$id)
  138. ->update([
  139. 'status'=>2,
  140. 'send_time'=>getTime(),
  141. ]);
  142. if($res){
  143. $this->success('操作成功',url('index'));
  144. }else{
  145. $this->error('操作失败');
  146. }
  147. }
  148. /**
  149. * 退款
  150. */
  151. public function refund($id = 0){
  152. if(request()->isPost()){
  153. $res = model('GOrders')->refundOrder($this->userId);
  154. if($res){
  155. $this->success('操作成功',url('index'));
  156. }else{
  157. $this->error(model('GOrders')->getError());
  158. }
  159. }else{
  160. $pay = Db::name('g_orders')->where('id',$id)->find();
  161. $money = $pay['amount'];
  162. $this->assign('money',$money);
  163. $this->assign('pay',$pay);
  164. $this->assign('id',$id);
  165. return $this->fetch();
  166. }
  167. }
  168. }