ShopOrders.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class ShopOrders 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','id','trim'); //排序列
  14. $sort = input('sord','asc','trim'); //排序方式
  15. $order = $sortRow.' '.$sort;
  16. $orderSn = input('orderSn','','trim');
  17. if($orderSn){
  18. $map[] = ['order_sn','like','%'.$orderSn.'%'];
  19. }
  20. $name = input('name','','trim');
  21. if($name){
  22. $map[] = ['name','like','%'.$name.'%'];
  23. }
  24. $cate = input('cate','','trim');
  25. if($cate != ''){
  26. $map[] = ['cate','=',$cate];
  27. }
  28. $status = input('status','','trim');
  29. if($status != ''){
  30. $map[] = ['status','=',$status];
  31. }
  32. $map[] = ['org_id','=',$this->orgId];
  33. $map[] = ['del','=',0];
  34. $map= empty($map) ? true: $map;
  35. //数据查询
  36. $lists = Db::name('shop_orders')->where($map)
  37. ->limit($start,$length)->order($order)
  38. ->select();
  39. //数据返回
  40. $totalCount = Db::name('shop_orders')->where($map)->count();
  41. $totalPage = ceil($totalCount/$length);
  42. $result['page'] = $page;
  43. $result['total'] = $totalPage;
  44. $result['records'] = $totalCount;
  45. $result['rows'] = $lists;
  46. return json($result);
  47. }else{
  48. $this->assign('meta_title','订单列表');
  49. return $this->fetch();
  50. }
  51. }
  52. public function detail($id = 0){
  53. $info = Db::name('shop_orders')
  54. ->where('id',$id)->where('del',0)->find();
  55. if(!$info){
  56. $this->error('订单不存在');
  57. }
  58. $goods = Db::name('shop_order_goods')
  59. ->alias('sog')
  60. ->join('shop_goods sg','sg.id = sog.goods_id')
  61. ->where('sog.order_id',$id)
  62. ->field('sog.*,sg.title,sg.img')
  63. ->select();
  64. $info['goods'] = $goods?$goods:[];
  65. $this->assign('info',$info);
  66. return $this->fetch();
  67. }
  68. /**
  69. * 删除记录
  70. * @param int $id
  71. */
  72. public function del($id=0){
  73. if(!$id){
  74. $this->error('参数错误');
  75. }
  76. $res = Db::name('shop_orders')->where('id',$id)->update(['del'=>1]);
  77. if($res){
  78. $this->success('删除成功');
  79. }else{
  80. $this->error('删除失败');
  81. }
  82. }
  83. /**
  84. * 取消记录
  85. * @param int $id
  86. */
  87. public function cancel($id=0){
  88. if(!$id){
  89. $this->error('参数错误');
  90. }
  91. $info = Db::name('shop_orders')->where('id',$id)->where('del',0)->find();
  92. if(!$info){
  93. $this->error('订单不存在');
  94. }
  95. if($info['status'] != 1){
  96. $this->error('此状态无法取消');
  97. }
  98. $res = Db::name('shop_orders')->where('id',$id)->update(['status'=>2,'cancel_time'=>date('Y-m-d H:i:s')]);
  99. if($res){
  100. $this->success('操作成功');
  101. }else{
  102. $this->error('操作失败');
  103. }
  104. }
  105. }