0
0

GOrders.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class GOrders extends Auth
  5. {
  6. public function index(){
  7. if(request()->isAjax()){
  8. //分页参数
  9. $length = input('rows',10,'intval'); //每页条数
  10. $page = input('page',1,'intval'); //第几页
  11. $start = ($page - 1) * $length; //分页开始位置
  12. //排序
  13. $sortRow = input('sidx','sort','trim'); //排序列
  14. $sort = input('sord','asc','trim'); //排序方式
  15. $order = $sortRow.' '.$sort.' ,id desc';
  16. $order_sn = input('order_sn','','trim');
  17. if($order_sn){
  18. $map[] = ['order_sn','=',$order_sn];
  19. }
  20. $name = input('name','','trim');
  21. if($name){
  22. $map[] = ['name','like','%'.$name.'%'];
  23. }
  24. $status = input('status','','trim');
  25. if($status != ''){
  26. $map[] = ['status','=',$status];
  27. }
  28. // if($this->user_id > 1){
  29. // $map[] = ['user_id','=',$this->user_id];
  30. // }
  31. $map[] = ['org_id','=',cur_org_id()];
  32. $map= empty($map) ? true: $map;
  33. //数据查询
  34. $lists = Db::name('g_orders')->where($map)->limit($start,$length)->order($order)->select();
  35. //数据返回
  36. $totalCount = Db::name('g_orders')->where($map)->count();
  37. $totalPage = ceil($totalCount/$length);
  38. $result['page'] = $page;
  39. $result['total'] = $totalPage;
  40. $result['records'] = $totalCount;
  41. $result['rows'] = $lists;
  42. return json($result);
  43. }else{
  44. $this->assign('meta_title','订单列表');
  45. return $this->fetch();
  46. }
  47. }
  48. public function details($id){
  49. if(!$id){
  50. $this->error('参数错误');
  51. }
  52. $ret = Db::name('g_orders')->where('id',$id)->find();
  53. $ret['goods'] = $orderGoods = Db::name('g_order_goods')
  54. ->alias('og')
  55. ->field('og.nums,og.price,og.goods_id,g.title,g.img')
  56. ->join('g_goods g', 'g.id=og.goods_id')
  57. ->where('og.order_id', $ret['id'])
  58. ->select();
  59. if($ret['status']==1 && time() < (strtotime($ret['create_time'])+(7*24*3600))){
  60. $ret['tk'] = 1;
  61. }else{
  62. $ret['tk'] = 0;
  63. }
  64. $this->assign('info',$ret);
  65. $this->assign('meta_title','订单详情');
  66. return $this->fetch();
  67. }
  68. /**
  69. * 退款
  70. */
  71. public function refund($id = 0){
  72. if(request()->isPost()){
  73. $res = model('GOrders')->refundOrder($this->userId);
  74. if($res){
  75. $this->success('操作成功',url('index'));
  76. }else{
  77. $this->error(model('GOrders')->getError());
  78. }
  79. }else{
  80. $pay = Db::name('g_orders')->where('id',$id)->find();
  81. $money = $pay['amount'];
  82. $this->assign('money',$money);
  83. $this->assign('pay',$pay);
  84. $this->assign('id',$id);
  85. return $this->fetch();
  86. }
  87. }
  88. }