wangsaitao há 10 meses atrás
pai
commit
406231335a
46 ficheiros alterados com 6748 adições e 0 exclusões
  1. 468 0
      application/admin/controller/Statistics.php
  2. 129 0
      application/admin/controller/WxBarrel.php
  3. 103 0
      application/admin/controller/WxCash.php
  4. 192 0
      application/admin/controller/WxCashRefund.php
  5. 167 0
      application/admin/controller/WxGoods.php
  6. 125 0
      application/admin/controller/WxGoodsCate.php
  7. 103 0
      application/admin/controller/WxNotice.php
  8. 179 0
      application/admin/controller/WxOrders.php
  9. 155 0
      application/admin/controller/WxOrdersRefund.php
  10. 105 0
      application/admin/view/statistics/wx_order_tj.html
  11. 299 0
      application/admin/view/statistics/wx_order_view.html
  12. 74 0
      application/admin/view/wx_barrel/add.html
  13. 104 0
      application/admin/view/wx_barrel/index.html
  14. 38 0
      application/admin/view/wx_cash/details.html
  15. 120 0
      application/admin/view/wx_cash/index.html
  16. 59 0
      application/admin/view/wx_cash_refund/details.html
  17. 135 0
      application/admin/view/wx_cash_refund/index.html
  18. 56 0
      application/admin/view/wx_cash_refund/option.html
  19. 150 0
      application/admin/view/wx_goods/add.html
  20. 133 0
      application/admin/view/wx_goods/index.html
  21. 71 0
      application/admin/view/wx_goods_cate/add.html
  22. 106 0
      application/admin/view/wx_goods_cate/index.html
  23. 52 0
      application/admin/view/wx_notice/add.html
  24. 86 0
      application/admin/view/wx_notice/index.html
  25. 168 0
      application/admin/view/wx_orders/details.html
  26. 158 0
      application/admin/view/wx_orders/index.html
  27. 69 0
      application/admin/view/wx_orders_refund/details.html
  28. 60 0
      application/admin/view/wx_orders_refund/goods_refund.html
  29. 136 0
      application/admin/view/wx_orders_refund/index.html
  30. 63 0
      application/admin/view/wx_orders_refund/option.html
  31. 78 0
      application/api/controller/h5/WxCart.php
  32. 221 0
      application/api/controller/h5/WxGoods.php
  33. 488 0
      application/api/controller/h5/WxOrders.php
  34. 153 0
      application/api/controller/v1/Notify.php
  35. 19 0
      application/common.php
  36. 41 0
      application/common/model/WxBarrel.php
  37. 170 0
      application/common/model/WxCart.php
  38. 215 0
      application/common/model/WxCash.php
  39. 275 0
      application/common/model/WxGoods.php
  40. 57 0
      application/common/model/WxGoodsCate.php
  41. 52 0
      application/common/model/WxNotice.php
  42. 971 0
      application/common/model/WxOrders.php
  43. 42 0
      application/common/validate/WxBarrel.php
  44. 42 0
      application/common/validate/WxGoods.php
  45. 39 0
      application/common/validate/WxGoodsCate.php
  46. 22 0
      application/common/validate/WxNotice.php

+ 468 - 0
application/admin/controller/Statistics.php

@@ -7,6 +7,7 @@
  */
 
 namespace app\admin\controller;
+use app\common\util\ExcelUtil;
 use think\App;
 use think\Db;
 
@@ -1714,4 +1715,471 @@ class Statistics extends Auth{
         }
         echo $res;
     }
+
+    public function wxOrderTj(){
+        $cur = date('Y-m-d');
+        $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
+        $end = input('end', date('Y-m-d'));
+        $title = input('title','');
+        $cateId = input('cateId','');
+        $goodsId = input('goodsId','');
+        $start1 = $start . ' 00:00:00';
+        $end1 = $end . ' 23:59:59';
+        $data = $this->wxOrderTjData($start1,$end1,$title,$cateId);
+        $cateList = model('WxGoodsCate')->lists($this->orgId);
+        $this->assign('cateList', $cateList);
+        $this->assign('data', $data);
+        $this->assign('start', $start);
+        $this->assign('end', $end);
+        $this->assign('title', $title);
+        $this->assign('cateId', $cateId?explode(',',$cateId):"");
+        $this->assign('goodsId', $goodsId?explode(',',$goodsId):"");
+
+        $glist = Db::name('wx_goods')->where('org_id',$this->orgId)->where('enable',1)->where('del',0)->select();
+        $this->assign('glist', $glist);
+
+        return $this->fetch();
+    }
+
+    public function wxOrderTjData($start,$end,$title,$cateId){
+        $org_id = $this->orgId;
+        $map = [];
+        $goodsId = input('goodsId','');
+        if(!empty($title)){
+            $map[] = ['g.title','like','%'.$title.'%'];
+        }
+        if(!empty($cateId)){
+            $map[] = ['g.cate_id','in',explode(',',$cateId)];
+        }
+        if(!empty($goodsId)){
+            $map[] = ['g.id','in',explode(',',$goodsId)];
+        }
+        if(!empty($start)){
+            $map[] = ['a.create_time','>=',$start];
+        }
+        if(!empty($end)){
+            $map[] = ['a.create_time','<=',$end];
+        }
+        $map[] = ['a.status','in',[1,2,3,5]];
+        $map[] = ['a.del','=',0];
+        $map[] = ['a.org_id','=',$org_id];
+        $ret =Db::name('wx_orders')
+            ->alias('a')
+            ->join('wx_orders_goods b','a.id=b.order_id')
+            ->join('wx_goods g','b.goods_id=g.id')
+            ->join('wx_goods_cate ca','g.cate_id=ca.id')
+            ->where($map)
+            ->field('b.goods_id,a.id,sum(b.nums) as num,b.price,g.title,ca.title as cateName')
+            ->group('b.goods_id')
+            ->select();
+        $total = 0;
+        foreach ($ret as $k=>$v){
+            $refund = Db::name('wx_orders_refund')
+                ->where('order_id',$v['id'])
+                ->where('goods_id',$v['goods_id'])
+                ->where('del',0)
+                ->where('status','in',[0,1])
+                ->find();
+            $num =  $v['num'];
+            if($refund){
+                $num =  $v['num']-$refund['num'];
+            }
+            if($num==0){
+                unset($ret[$k]);
+            }else{
+                $t = $num*$v['price'];
+                $total+=$t;
+                $ret[$k]['total'] = $num*$v['price'];
+                $ret[$k]['num'] = $num;
+
+            }
+        }
+        array_push($ret,[
+            'title'=>'合计:',
+            'cateName'=>'',
+            'num'=>'',
+            'price'=>'',
+            'total'=>$total,
+        ]);
+        return $ret;
+    }
+
+    public function wxOrderTjExport(){
+        $cur = date('Y-m-d');
+        $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
+        $end = input('end', date('Y-m-d'));
+        $title = input('title','');
+        $cateId = input('cateId','');
+        $start1 = $start . ' 00:00:00';
+        $end1 = $end . ' 23:59:59';
+        $data = $this->wxOrderTjData($start1,$end1,$title,$cateId);
+        $header = [
+            ['title' => '商品名称', 'name' => 'title','width'=>'30'],
+            ['title' => '分类', 'name' => 'cateName','width'=>'30'],
+            ['title' => '数量', 'name' => 'num','width'=>'30'],
+            ['title' => '单价', 'name' => 'price','width'=>'80'],
+            ['title' => '总金额', 'name' => 'total','width'=>'30'],
+
+        ];
+        $filename = '销售统计';
+        ExcelUtil::export($filename,$header,$data);
+    }
+
+    public function wxOrderView(){
+        $startY = beginYear();
+        $zjygy = date('Y-m-d 00:00:00',time()-(30*86400));
+        $type = input('type/d',0);
+
+        if(request()->isPost()){
+            $dataTitle = [];
+            $dataValue = [];
+            $dataValue1 = [];
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['del','=',0];
+            $map[] = ['status','in',[1,2,3,5]];
+            $ddzs = 0;
+            $ddbl=0;
+            $ddzt=0;//0持平1上升2下降
+            $yzfdd=0;
+            $yzfbl=0;
+            $yzfzt=0;//0持平1上升2下降
+            $ddze=0;
+            $ddzebl=0;
+            $ddzezt=0;//0持平1上升2下降
+            $map1[] = ['org_id','=',$this->orgId];
+            $map1[] = ['del','=',0];
+            $cateList = model('WxGoodsCate')->lists($this->orgId);
+            $refund = Db::name('wx_orders_refund')
+                ->where('org_id','=',$this->orgId)
+                ->where('del',0)
+                ->where('status','in',[0,1])
+                ->column('goods_id');
+            $rMap = [];
+            if($refund){
+                $rMap[] = ['b.goods_id','not in',$refund];
+            }
+            if($type==0){
+                $title = getMinFromRange(date('Y-m-d 00:00:00'),date('Y-m-d H:i:s'));
+                foreach ($title as $k=>$v){
+                    $dataTitle[] = date('H点',strtotime($v));
+                    $dataValue[] = Db::name('wx_orders')
+                        ->where($map)
+                        ->where('create_yyyymmddhh','=',date('YmdH',strtotime($v)))
+                        ->count();
+                    $dataValue1[] = Db::name('wx_orders')
+                        ->where($map)
+                        ->where('create_yyyymmddhh','=',date('YmdH',strtotime($v)))
+                        ->sum('amount');
+                }
+                $zt = date("Ymd",strtotime("-1 day"));
+
+                $ddzs =Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('create_yyyymmdd','=',date('Ymd'))
+                    ->count();
+                $ztzs = Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('create_yyyymmdd','=',$zt)
+                    ->count();
+                if($ztzs==$ddzs){
+                    $ddzt = 0;
+                }elseif ($ztzs>$ddzs){
+                    $ddzt = 2;
+                    $ddbl = $ztzs>0?round((($ztzs-$ddzs)/$ztzs),2)*100:0;
+                }elseif ($ztzs<$ddzs){
+                    $ddzt = 1;
+                    $ddbl = $ddzs>0?round((($ddzs-$ztzs))/$ddzs,2)*100:0;
+                }
+
+
+                $yzfdd =Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyymmdd','=',date('Ymd'))
+                    ->count();
+                $ztyzfdd = Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyymmdd','=',$zt)
+                    ->count();
+                if($ztyzfdd==$yzfdd){
+                    $yzfzt = 0;
+                }elseif ($ztyzfdd>$yzfdd){
+                    $yzfzt = 2;
+                    $yzfbl = $ztyzfdd>0?round((($ztyzfdd-$yzfdd)/$ztyzfdd),2)*100:0;
+                }elseif ($ztyzfdd<$yzfdd){
+                    $yzfzt = 1;
+                    $yzfbl = $yzfdd>0?round((($yzfdd-$ztyzfdd))/$yzfdd,2)*100:0;
+                }
+
+
+                $ddze =Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyymmdd','=',date('Ymd'))
+                    ->sum('amount');
+                $ztddze = Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyymmdd','=',$zt)
+                    ->sum('amount');
+                if($ztddze==$ddze){
+                    $ddzezt = 0;
+                }elseif ($ztddze>$ddze){
+                    $ddzezt = 2;
+                    $ddzebl = $ztddze>0?round((($ztddze-$ddze)/$ztddze),2)*100:0;
+                }elseif ($ztddze<$ddze){
+                    $ddzezt = 1;
+                    $ddzebl = $ddze>0?round((($ddze-$ztddze))/$ddze,2)*100:0;
+                }
+                foreach ($cateList as $k=>$v){
+
+
+                    $a = Db::name('wx_orders')
+                        ->alias('a')
+                        ->join('wx_orders_goods b','a.id=b.order_id')
+                        ->join('wx_goods c','b.goods_id=c.id')
+                        ->where('a.del','=',0)
+                        ->where('a.org_id','=',$this->orgId)
+                        ->where('c.cate_id','=',$v['id'])
+                        ->where('a.status','in',[1,2,3,5])
+                        ->where($rMap)
+                        ->where('a.create_yyyymmdd','=',date('Ymd'))
+                        ->sum('b.nums*b.price');
+                    $cateList[$k]['total'] = $a?$a:0;
+                }
+            }elseif ($type==1){
+                $title = getDateFromRange(date('Y-m-01'),date('Y-m-d'));
+                foreach ($title as $k=>$v){
+                    $dataTitle[] = date('Y-m-d',strtotime($v));
+                    $dataValue[] = Db::name('wx_orders')
+                        ->where($map)
+                        ->where('create_yyyymmdd','=', date('Ymd',strtotime($v)))
+                        ->count();
+                    $dataValue1[] = Db::name('wx_orders')
+                        ->where($map)
+                        ->where('create_yyyymmdd','=', date('Ymd',strtotime($v)))
+                        ->sum('amount');
+                }
+                $zt = date("Ym",strtotime("-1 month"));
+
+                $ddzs =Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('create_yyyymm','=',date('Ym'))
+                    ->count();
+                $ztzs = Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('create_yyyymm','=',$zt)
+                    ->count();
+                if($ztzs==$ddzs){
+                    $ddzt = 0;
+                }elseif ($ztzs>$ddzs){
+                    $ddzt = 2;
+                    $ddbl = $ztzs>0?round((($ztzs-$ddzs)/$ztzs),2)*100:0;
+                }elseif ($ztzs<$ddzs){
+                    $ddzt = 1;
+                    $ddbl = $ddzs>0?round((($ddzs-$ztzs))/$ddzs,2)*100:0;
+                }
+
+
+                $yzfdd =Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyymm','=',date('Ym'))
+                    ->count();
+                $ztyzfdd = Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyymm','=',$zt)
+                    ->count();
+                if($ztyzfdd==$yzfdd){
+                    $yzfzt = 0;
+                }elseif ($ztyzfdd>$yzfdd){
+                    $yzfzt = 2;
+                    $yzfbl = $ztyzfdd>0?round((($ztyzfdd-$yzfdd)/$ztyzfdd),2)*100:0;
+                }elseif ($ztyzfdd<$yzfdd){
+                    $yzfzt = 1;
+                    $yzfbl = $yzfdd>0?round((($yzfdd-$ztyzfdd))/$yzfdd,2)*100:0;
+                }
+
+
+                $ddze =Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyymm','=',date('Ym'))
+                    ->sum('amount');
+                $ztddze = Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyymm','=',$zt)
+                    ->sum('amount');
+                if($ztddze==$ddze){
+                    $ddzezt = 0;
+                }elseif ($ztddze>$ddze){
+                    $ddzezt = 2;
+                    $ddzebl = $ztddze>0?round((($ztddze-$ddze)/$ztddze),2)*100:0;
+                }elseif ($ztddze<$ddze){
+                    $ddzezt = 1;
+                    $ddzebl = $ddze>0?round((($ddze-$ztddze))/$ddze,2)*100:0;
+                }
+                foreach ($cateList as $k=>$v){
+
+                    $a = Db::name('wx_orders')
+                        ->alias('a')
+                        ->join('wx_orders_goods b','a.id=b.order_id')
+                        ->join('wx_goods c','b.goods_id=c.id')
+                        ->where('a.del','=',0)
+                        ->where('a.org_id','=',$this->orgId)
+                        ->where('c.cate_id','=',$v['id'])
+                        ->where($rMap)
+                        ->where('a.status','in',[1,2,3,5])
+                        ->where('a.create_yyyymm','=',date('Ym'))
+                        ->sum('b.nums*b.price');
+                    $cateList[$k]['total'] = $a?$a:0;
+                }
+            }elseif ($type==2){
+                $title = getMonthFromRange($startY,date('Y-m-d H:i:s'));
+                foreach ($title as $k=>$v){
+                    $dataTitle[] = date('Y-m',strtotime($v));
+                    $dataValue[] = Db::name('wx_orders')
+                        ->where($map)
+                        ->where('create_yyyymm','=', date('Ym',strtotime($v)))
+                        ->count();
+                    $dataValue1[] = Db::name('wx_orders')
+                        ->where($map)
+                        ->where('create_yyyymm','=', date('Ym',strtotime($v)))
+                        ->sum('amount');
+                }
+                $zt = date ( "Y" , strtotime ( "-1 year" ));
+
+                $ddzs =Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('create_yyyy','=',date('Y'))
+                    ->count();
+                $ztzs = Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('create_yyyy','=',$zt)
+                    ->count();
+                if($ztzs==$ddzs){
+                    $ddzt = 0;
+                }elseif ($ztzs>$ddzs){
+                    $ddzt = 2;
+                    $ddbl = $ztzs>0?round((($ztzs-$ddzs)/$ztzs),2)*100:0;
+                }elseif ($ztzs<$ddzs){
+                    $ddzt = 1;
+                    $ddbl = $ddzs>0?round((($ddzs-$ztzs))/$ddzs,2)*100:0;
+                }
+
+
+                $yzfdd =Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyy','=',date('Y'))
+                    ->count();
+                $ztyzfdd = Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyy','=',$zt)
+                    ->count();
+                if($ztyzfdd==$yzfdd){
+                    $yzfzt = 0;
+                }elseif ($ztyzfdd>$yzfdd){
+                    $yzfzt = 2;
+                    $yzfbl = $ztyzfdd>0?round((($ztyzfdd-$yzfdd)/$ztyzfdd),2)*100:0;
+                }elseif ($ztyzfdd<$yzfdd){
+                    $yzfzt = 1;
+                    $yzfbl = $yzfdd>0?round((($yzfdd-$ztyzfdd))/$yzfdd,2)*100:0;
+                }
+
+
+                $ddze =Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyy','=',date('Y'))
+                    ->sum('amount');
+                $ztddze = Db::name('wx_orders')
+                    ->where($map1)
+                    ->where('status','in',[1,2,3,5])
+                    ->where('create_yyyy','=',$zt)
+                    ->sum('amount');
+                if($ztddze==$ddze){
+                    $ddzezt = 0;
+                }elseif ($ztddze>$ddze){
+                    $ddzezt = 2;
+                    $ddzebl = $ztddze>0?round((($ztddze-$ddze)/$ztddze),2)*100:0;
+                }elseif ($ztddze<$ddze){
+                    $ddzezt = 1;
+                    $ddzebl = $ddze>0?round((($ddze-$ztddze))/$ddze,2)*100:0;
+                }
+                foreach ($cateList as $k=>$v){
+                    $a = Db::name('wx_orders')
+                        ->alias('a')
+                        ->join('wx_orders_goods b','a.id=b.order_id')
+                        ->join('wx_goods c','b.goods_id=c.id')
+                        ->where('a.del','=',0)
+                        ->where('a.org_id','=',$this->orgId)
+                        ->where('c.cate_id','=',$v['id'])
+                        ->where($rMap)
+                        ->where('a.status','in',[1,2,3,5])
+                        ->where('a.create_yyyy','=',date('Y'))
+                        ->sum('b.nums*b.price');
+                    $cateList[$k]['total'] = $a?$a:0;
+                }
+            }
+            if($cateList){
+                $vol = array_column($cateList,'total');
+                array_multisort($vol,SORT_DESC,$cateList);
+            }
+            $p = [
+                'title'=>$dataTitle,
+                'value'=>$dataValue,
+                'value1'=>$dataValue1,
+                'ddzs' => $ddzs,
+                'ddbl' => $ddbl,
+                'ddzt' => $ddzt,
+                'yzfdd' => $yzfdd,
+                'yzfbl' => $yzfbl,
+                'yzfzt' => $yzfzt,
+                'ddze' => $ddze,
+                'ddzebl' => $ddzebl,
+                'ddzezt' => $ddzezt,
+                'cateList' => $cateList,
+
+            ];
+            $this->success('操作成功','',$p);
+        }else{
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['del','=',0];
+            $data['orderAmount'] = Db::name('wx_orders')
+                ->where($map)
+                ->where('status','in',[1,2,3,5])
+                ->where('create_yyyymm','=',date('Ym'))
+                ->sum('amount');
+            $data['orderCount'] = Db::name('wx_orders')
+                ->where($map)
+                ->where('status','in',[1,2,3,5])
+                ->where('create_yyyy','=',date('Y'))
+                ->count();
+            $data['orderUser'] = Db::name('wx_orders')
+                ->where($map)
+                ->where('status','in',[1,2,3,5])
+                ->where('create_yyyymmdd','=',date('Ymd'))
+                ->group('user_id')
+                ->count();
+            $beginMonth = beginMonth();
+            $data['refundCount'] =  Db::name('wx_orders_refund')
+                ->where('org_id',$this->orgId)
+                ->where('status',1)
+                ->where('del',0)
+                ->where('create_time','>=',$beginMonth)
+                ->where('create_time','<=',getTime())
+                ->sum('money');
+            $this->assign('data',$data);
+            return $this->fetch();
+
+        }
+
+
+
+    }
 }

+ 129 - 0
application/admin/controller/WxBarrel.php

@@ -0,0 +1,129 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class WxBarrel extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table = 'wx_barrel';
+        $this->model = 'WxBarrel';
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['org_id','=',cur_org_id()];
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = Db::name($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','空桶列表');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model($this->model)->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model($this->model)->getError());
+            }
+        }else{
+            $meta_title = '新增空桶';
+            if($id){
+                $info = Db::name($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+                $meta_title = '编辑空桶';
+            }
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+
+        $res = Db::name($this->table)->where('id',$id)
+        ->update(['del'=>1]);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name($this->table)->where('id',$id)->update([$fn => $fv]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    /**
+     * 排序
+     * @param int $id
+     * @param int $sort
+     */
+    public function changeSort($id=0,$sort=0){
+        if($id<0||$sort<0){
+            $this->error('参数错误');
+        }
+        $res = Db::name($this->table)->where('id',$id)->update(['sort'=>$sort]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+}

+ 103 - 0
application/admin/controller/WxCash.php

@@ -0,0 +1,103 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+use think\Exception;
+
+class WxCash extends Auth
+{
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $order_sn = input('order_sn','','trim');
+            if($order_sn){
+                $map[] = ['sn','=',$order_sn];
+            }
+            $name = input('name','','trim');
+            if($name){
+                $map1[] = ['nickname','like','%'.$name.'%'];
+                $u = Db::name('wxuser')
+                    ->where($map1)
+                    ->where('type',1)
+                    ->column('id');
+                if(empty($u)){
+                    $map[] = ['id','=',-1];
+                }else{
+                    $map[] = ['user_id','in',$u];
+                }
+            }
+
+            $b = input('begin','','trim');
+            $e = input('end','','trim');
+            if($b){
+                $b = date('Y-m-d 00:00:00',strtotime($b));
+                $map[] = ['create_time','>=',$b];
+
+            }
+            if($e){
+                $e = date('Y-m-d 23:59:59',strtotime($e));
+                $map[] = ['create_time','<=',$e];
+
+            }
+            $map[] = ['org_id','=',cur_org_id()];
+            $map[] = ['del','=',0];
+            $map = empty($map) ? true: $map;
+
+            //数据查询
+            $lists = Db::name('wx_cash')->where($map)
+                ->limit($start,$length)
+                ->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['barrel_name'] = Db::name('wx_barrel')
+                        ->where('id',$v['barrel_id'])
+                    ->value('title');
+                $lists[$k]['user_name'] = Db::name('wxuser')
+                    ->where('id',$v['user_id'])
+                    ->value('phone');
+            }
+            //数据返回
+            $totalCount = Db::name('wx_cash')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $status = model('WxCash')->status;
+            $this->assign('status',$status);
+            $this->assign('meta_title','押金列表');
+            return $this->fetch();
+        }
+    }
+    public function details($id){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $ret = Db::name('wx_cash')->where('id',$id)
+            ->find();
+        $ret['barrel_name'] = Db::name('wx_barrel')
+            ->where('id',$ret['barrel_id'])
+            ->value('title');
+        $ret['user_name'] = Db::name('wxuser')
+            ->where('id',$ret['user_id'])
+            ->value('phone');
+        $ret['del_user_name'] = Db::name('user')
+            ->where('id',$ret['user_id'])
+            ->value('real_name');
+        $this->assign('info',$ret);
+        $this->assign('meta_title','押金详情');
+        return $this->fetch();
+    }
+
+
+}

+ 192 - 0
application/admin/controller/WxCashRefund.php

@@ -0,0 +1,192 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+use think\Exception;
+
+class WxCashRefund extends Auth
+{
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $order_sn = input('order_sn','','trim');
+            if($order_sn){
+                $map[] = ['sn','=',$order_sn];
+            }
+            $name = input('name','','trim');
+            if($name){
+                $map1[] = ['nickname','like','%'.$name.'%'];
+                $u = Db::name('wxuser')
+                    ->where($map1)
+                    ->where('type',1)
+                    ->column('id');
+                if(empty($u)){
+                    $map[] = ['id','=',-1];
+                }else{
+                    $map[] = ['user_id','in',$u];
+                }
+            }
+            $status = input('status','','trim');
+            if($status != ''){
+                $map[] = ['status','=',$status];
+            }
+
+//            if($this->user_id > 1){
+//                $map[] = ['user_id','=',$this->user_id];
+//            }
+
+
+            $b = input('begin','','trim');
+            $e = input('end','','trim');
+            if($b){
+                $b = date('Y-m-d 00:00:00',strtotime($b));
+                $map[] = ['create_time','>=',$b];
+
+            }
+            if($e){
+                $e = date('Y-m-d 23:59:59',strtotime($e));
+                $map[] = ['create_time','<=',$e];
+
+            }
+            $map[] = ['org_id','=',cur_org_id()];
+            $map[] = ['del','=',0];
+            $map = empty($map) ? true: $map;
+
+            //数据查询
+            $lists = Db::name('wx_cash_refund')->where($map)
+                ->limit($start,$length)
+                ->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['status_name'] =isset(model('WxCash')->status[$v['status']])?model('WxCash')->status[$v['status']]:'';
+                $lists[$k]['barrel_name'] = Db::name('wx_barrel')
+                        ->where('id',$v['barrel_id'])
+                    ->value('title');
+                $lists[$k]['user_name'] = Db::name('wxuser')
+                    ->where('id',$v['user_id'])
+                    ->value('phone');
+            }
+            //数据返回
+            $totalCount = Db::name('wx_cash_refund')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $status = model('WxCash')->status;
+            $this->assign('status',$status);
+            $this->assign('meta_title','押金退款列表');
+            return $this->fetch();
+        }
+    }
+    public function details($id){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $ret = Db::name('wx_cash_refund')->where('id',$id)
+            ->find();
+        $ret['status_name'] =isset(model('WxCash')->status[$ret['status']])?model('WxCash')->status[$ret['status']]:'';
+        $ret['barrel_name'] = Db::name('wx_barrel')
+            ->where('id',$ret['barrel_id'])
+            ->value('title');
+        $ret['user_name'] = Db::name('wxuser')
+            ->where('id',$ret['user_id'])
+            ->value('phone');
+        $ret['deal_user_name'] = Db::name('user')
+            ->where('id',$ret['deal_user_id'])
+            ->value('real_name');
+        $this->assign('info',$ret);
+        $this->assign('meta_title','押金退款详情');
+        return $this->fetch();
+    }
+    public function option($id = 0){
+        $pay = Db::name('wx_cash_refund')->where('id',$id)->find();
+        if(request()->isPost()){
+            if(empty($pay)){
+                $this->error('退款申请不存在');
+            }
+            if($pay['status']!=0){
+                $this->error('当前状态不能操作');
+            }
+            $status = input('status/d',0);
+            if(!in_array($status,[1,2])){
+                $this->error('状态值错误');
+            }
+            Db::startTrans();
+            try{
+                $res  = Db::name('wx_cash_refund')
+                    ->where('id',$id)
+                    ->update([
+                        'deal_user_id'=>$this->userId,
+                        'deal_time'=>getTime(),
+                        'status'=>$status,
+                        'update_time'=>getTime(),
+                        'remark'=>input('remark'),
+                    ]);
+                if(!$res){
+                    \exception('操作失败');
+                }
+                if($status==1){
+                    $cash = Db::name('wx_cash')
+                        ->where('id',$pay['cash_id'])
+                        ->find();
+                    $tkSn = get_unique_id('TPH');
+                    $config = config('app.wx_mini_config');
+                    $app = \EasyWeChat\Factory::payment($config);
+                    $ret = $app->refund->byOutTradeNumber($cash['sn'], $tkSn, $cash['total_money']*100, $pay['amount']*100);
+
+                    if($ret['return_code'] != 'SUCCESS' || $ret['result_code'] != 'SUCCESS'){
+                        trace(json_encode($ret));
+                        \exception('退款申请提交失败');
+                    }
+                    Db::name('wx_cash')
+                        ->where('del',0)
+                        ->where('num',0)
+                        ->update(['del'=>1]);
+                    Db::commit();
+                    $this->success('操作成功',url('index'));
+                }
+                if($status==2){
+                    $res =Db::name('wx_cash')
+                        ->where('id',$pay['cash_id'])
+                        ->setInc('num',$pay['num']);
+                    if(!$res){
+                        \exception('操作失败');
+                    }
+                    $res =Db::name('wx_cash')
+                        ->where('id',$pay['cash_id'])
+                        ->setInc('amount',$pay['amount']);
+                    if(!$res){
+                        \exception('操作失败');
+                    }
+                    Db::commit();
+                    $this->success('操作成功',url('index'));
+                }
+            }catch (Exception $e){
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('WxCash')->getError());
+            }
+        }else{
+            $this->assign('pay',$pay);
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+
+}

+ 167 - 0
application/admin/controller/WxGoods.php

@@ -0,0 +1,167 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class WxGoods extends Auth
+{
+    protected function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+    }
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table = 'wx_goods';
+        $this->model = 'WxGoods';
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $is_tj = input('is_tj','','trim');
+            if($is_tj != ''){
+                $map[] = ['is_tj','=',$is_tj];
+            }
+            $cate_id = input('cate_id','','trim');
+            if($cate_id != ''){
+                $map[] = ['cate_id','=',$cate_id];
+            }
+            $map[] = ['org_id','=',cur_org_id()];
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name($this->table)
+                ->where($map)->limit($start,$length)
+                ->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['cate_name']=Db::name('wx_goods_cate')
+                    ->where('id',$v['cate_id'])->value('title');
+                $lists[$k]['label_name']=Db::name('wx_goods_label')
+                    ->where('id',$v['label'])->value('title');
+            }
+            //数据返回
+            $totalCount = Db::name($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $cateList = model('WxGoodsCate')->lists($this->orgId);
+            $label =model('WxGoodsCate')->getLabel();
+
+            $this->assign('cateList',$cateList);
+            $this->assign('label',$label);
+            $this->assign('meta_title','商品列表');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model($this->model)->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model($this->model)->getError());
+            }
+        }else{
+            $meta_title = '新增商品';
+            if($id){
+                $info = Db::name($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+                $cateInfo = Db::name('wx_goods_cate')
+                    ->where('id',$info['cate_id'])
+                    ->find();
+
+                $this->assign('cateInfo',$cateInfo);
+                $meta_title = '编辑商品';
+            }
+            $cateList = model('WxGoodsCate')->lists($this->orgId);
+            $label =model('WxGoodsCate')->getLabel();
+            $barrel =model('WxBarrel')->lists($this->orgId);
+
+            $this->assign('cateList',$cateList);
+            $this->assign('label',$label);
+            $this->assign('barrel',$barrel);
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name($this->table)->where('id',$id)->update(['del'=>1,'update_time'=>getTime()]);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name($this->table)->where('id',$id)->update([$fn => $fv]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    /**
+     * 排序
+     * @param int $id
+     * @param int $sort
+     */
+    public function changeSort($id=0,$sort=0){
+        if($id<0||$sort<0){
+            $this->error('参数错误');
+        }
+        $res = Db::name($this->table)->where('id',$id)->update(['sort'=>$sort]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    public function checkIsWater(){
+        $id =input('id/d',0);
+        $info = Db::name('wx_goods_cate')
+            ->where('id',$id)
+            ->find();
+        $this->success('操作成功','',$info);
+    }
+}

+ 125 - 0
application/admin/controller/WxGoodsCate.php

@@ -0,0 +1,125 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class WxGoodsCate extends Auth
+{
+
+    protected function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['org_id','=',cur_org_id()];
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('wx_goods_cate')->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = Db::name('wx_goods_cate')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','商品分类列表');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('WxGoodsCate')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('WxGoodsCate')->getError());
+            }
+        }else{
+            $meta_title = '新增商品分类';
+            if($id){
+                $info = Db::name('wx_goods_cate')->where('id',$id)->find();
+                $this->assign('info',$info);
+                $meta_title = '编辑商品分类';
+            }
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+
+        $res = Db::name('wx_goods_cate')->where('id',$id)
+        ->update(['del'=>1]);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('wx_goods_cate')->where('id',$id)->update([$fn => $fv]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    /**
+     * 排序
+     * @param int $id
+     * @param int $sort
+     */
+    public function changeSort($id=0,$sort=0){
+        if($id<0||$sort<0){
+            $this->error('参数错误');
+        }
+        $res = Db::name('wx_goods_cate')->where('id',$id)->update(['sort'=>$sort]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+}

+ 103 - 0
application/admin/controller/WxNotice.php

@@ -0,0 +1,103 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class WxNotice extends Auth
+{
+    protected function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+    }
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table = 'wx_notice';
+        $this->model = 'WxNotice';
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['org_id','=',cur_org_id()];
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['user_name'] = Db::name('user')
+                    ->where('id',$v['user_id'])
+                    ->value('real_name');
+            }
+            //数据返回
+            $totalCount = Db::name($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','通知列表');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model($this->model)->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model($this->model)->getError());
+            }
+        }else{
+            $meta_title = '新增通知';
+            if($id){
+                $info = Db::name($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+                $meta_title = '编辑通知';
+            }
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+
+        $res = Db::name($this->table)->where('id',$id)
+            ->update(['del'=>1,'del_user_id'=>$this->userId,'del_time'=>getTime()]);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+
+}

+ 179 - 0
application/admin/controller/WxOrders.php

@@ -0,0 +1,179 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class WxOrders extends Auth
+{
+    protected function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $order_sn = input('order_sn','','trim');
+            if($order_sn){
+                $map[] = ['order_sn','=',$order_sn];
+            }
+            $name = input('name','','trim');
+            if($name){
+                $map[] = ['name','like','%'.$name.'%'];
+            }
+            $status = input('status','','trim');
+            if($status != ''){
+                if($status==99){
+                    $ids = Db::name('wx_orders_refund')
+                        ->where('org_id',$this->orgId)
+                        ->where('status',1)
+                        ->column('order_id');
+                    if(empty($ids)){
+                        $map[]=['id','=',-1];
+                    }else{
+                        $map[]=['id','in',$ids];
+                    }
+                }else{
+                    $map[] = ['status','=',$status];
+                }
+
+            }
+
+//            if($this->user_id > 1){
+//                $map[] = ['user_id','=',$this->user_id];
+//            }
+            $order_type = input('order_type','','trim');
+            if($order_type!=''){
+                $map[] = ['order_type','=',$order_type];
+            }
+            $cate_id = input('cate_id','','trim');
+            if($cate_id != ''){
+               $goodIds = Db::name('wx_goods')
+                   ->where('cate_id',$cate_id)
+                   ->column('id');
+               if(empty($goodIds)){
+                   $map[] = ['id','=',-1];
+               }else{
+                   $ii = Db::name('wx_orders_goods')
+                       ->where('goods_id','in',$goodIds)
+                       ->column('order_id');
+                   if(empty($ii)){
+                       $map[] = ['id','=',-1];
+                   }else{
+                       $map[] = ['id','in',$ii];
+                   }
+               }
+            }
+            $b = input('begin','','trim');
+            $e = input('end','','trim');
+            if($b){
+                $b = date('Y-m-d 00:00:00',strtotime($b));
+                $map[] = ['create_time','>=',$b];
+
+            }
+            if($e){
+                $e = date('Y-m-d 23:59:59',strtotime($e));
+                $map[] = ['create_time','<=',$e];
+
+            }
+            $map[] = ['org_id','=',cur_org_id()];
+            $map[] = ['del','=',0];
+            $map = empty($map) ? true: $map;
+
+            //数据查询
+            $lists = Db::name('wx_orders')->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['status_name'] =isset(model('WxOrders')->status[$v['status']])?model('WxOrders')->status[$v['status']]:'';
+                $r  = model('wxOrders')->checkOrderSend($v['id']);
+                $lists[$k]['checkOrderSend'] = $r;
+                if($r==2){
+                    $lists[$k]['status_name'] =  $lists[$k]['status_name'].'(已退款)';
+                }elseif ($r==1){
+                    $lists[$k]['status_name'] =  $lists[$k]['status_name'].'(部分退款)';
+
+                }elseif ($r==3){
+                    $lists[$k]['status_name'] =  $lists[$k]['status_name'].'(退款中)';
+
+                }
+            }
+            //数据返回
+            $totalCount = Db::name('wx_orders')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $yzf = Db::name('wx_orders')
+                ->where($map)
+                ->where('status','in',[1,2,3])
+                ->sum('amount');
+            $ytk = Db::name('wx_orders')
+                ->where($map)
+                ->sum('refund_money');
+            $result['yzf'] = $yzf;
+            $result['ytk'] = $ytk;
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $cate = model('WxGoodsCate')->lists($this->orgId);
+            $status = model('WxOrders')->status;
+            $this->assign('status',$status);
+            $this->assign('cate',$cate);
+            $this->assign('meta_title','订单列表');
+            return $this->fetch();
+        }
+    }
+    public function details($id){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $ret = model('WxOrders')->details($id);
+        $this->assign('info',$ret);
+        $this->assign('meta_title','订单详情');
+        return $this->fetch();
+    }
+
+    public function send($id){
+        $info = Db::name('wx_orders')->where('id',$id)
+            ->find();
+        if($info['status']!=1){
+            $this->error('当前订单状态不可发货');
+        }
+        $res = Db::name('wx_orders')->where('id',$id)
+            ->update([
+                'status'=>2,
+                'send_time'=>getTime(),
+            ]);
+        if($res){
+            $this->success('操作成功',url('index'));
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    /**
+     * 退款
+     */
+    public function refund($id = 0){
+        if(request()->isPost()){
+            $res = model('GOrders')->refundOrder($this->userId);
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('GOrders')->getError());
+            }
+        }else{
+            $pay = Db::name('g_orders')->where('id',$id)->find();
+            $money = $pay['amount'];
+            $this->assign('money',$money);
+            $this->assign('pay',$pay);
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+}

+ 155 - 0
application/admin/controller/WxOrdersRefund.php

@@ -0,0 +1,155 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class WxOrdersRefund extends Auth
+{
+
+    protected function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $order_sn = input('order_sn','','trim');
+            if($order_sn){
+                $ids = Db::name('wx_orders')
+                    ->where('org_id',$this->orgId)
+                    ->where('order_sn',$order_sn)
+                    ->column('id');
+                if(empty($ids)){
+                    $map[]=['order_id','=',-1];
+                }else{
+                    $map[]=['order_id','in',$ids];
+                }
+            }
+
+            $status = input('status','','trim');
+            if($status != ''){
+                $map[] = ['status','=',$status];
+
+            }
+
+
+            $cate_id = input('cate_id','','trim');
+            if($cate_id != ''){
+               $goodIds = Db::name('wx_goods')
+                   ->where('cate_id',$cate_id)
+                   ->column('id');
+               if(empty($goodIds)){
+                   $map[] = ['id','=',-1];
+               }else{
+                   $map[] = ['goods_id','in',$goodIds];
+               }
+            }
+            $b = input('begin','','trim');
+            $e = input('end','','trim');
+            if($b){
+                $b = date('Y-m-d 00:00:00',strtotime($b));
+                $map[] = ['create_time','>=',$b];
+
+            }
+            if($e){
+                $e = date('Y-m-d 23:59:59',strtotime($e));
+                $map[] = ['create_time','<=',$e];
+
+            }
+            $map[] = ['org_id','=',cur_org_id()];
+            $map[] = ['del','=',0];
+            $map = empty($map) ? true: $map;
+
+            //数据查询
+            $lists = Db::name('wx_orders_refund')
+                ->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['status_name'] =isset(model('WxOrders')->rStatus[$v['status']])?model('WxOrders')->rStatus[$v['status']]:'';
+                $lists[$k]['user_name'] = Db::name('user')
+                    ->where('id',$v['user_id'])
+                    ->value('real_name');
+
+                $lists[$k]['goods_name'] = Db::name('wx_goods')
+                    ->where('id',$v['goods_id'])
+                    ->value('title');
+                $lists[$k]['order_sn'] = Db::name('wx_orders')
+                    ->where('id',$v['order_id'])
+                    ->value('order_sn');
+            }
+            //数据返回
+            $totalCount = Db::name('wx_orders_refund')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $cate = model('WxGoodsCate')->lists($this->orgId);
+            $status = model('WxOrders')->rStatus;
+            $this->assign('status',$status);
+            $this->assign('cate',$cate);
+            $this->assign('meta_title','订单退款列表');
+            return $this->fetch();
+        }
+    }
+    public function details($id,$goodsId){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $ret = model('WxOrders')->goodsRefundDetail($this->orgId,$id,$goodsId);
+        $this->assign('info',$ret);
+        $this->assign('meta_title','退款详情');
+        return $this->fetch();
+    }
+
+    /**
+     * 退款
+     */
+    public function option($id = 0){
+        if(request()->isPost()){
+            $res = model('WxOrders')->refundOrder($this->userId);
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('WxOrders')->getError());
+            }
+        }else{
+            $pay = Db::name('wx_orders_refund')->where('id',$id)->find();
+            $money = $pay['amount'];
+            $this->assign('money',$money);
+            $this->assign('pay',$pay);
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+    public function goodsRefund($id,$goodsId=0,$type=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        if(request()->isPost()){
+            $res = model('WxOrders')->orderRefund($this->userId,$this->orgId);
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('WxOrders')->getError());
+            }
+        }else{
+            $ret = model('WxOrders')->checkoutApplyRefund($this->userId,$this->orgId,$type,$id,$goodsId);
+            $this->assign('info',$ret);
+            $this->assign('id',$id);
+            $this->assign('meta_title','商品申请退款');
+            return $this->fetch();
+        }
+
+
+    }
+}

+ 105 - 0
application/admin/view/statistics/wx_order_tj.html

@@ -0,0 +1,105 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="ibox-content">
+<div class="ibox">
+
+    <div class="alert">
+        <form action="wxOrderTj" method="GET" id='search_form' class="form-inline">
+            <div class="input-group" style="width: 200px">
+                <span class="input-group-addon">开始时间</span>
+                <input class="form-control dialog-datetime" id="startTime" name="start" type="text" data-date-format="yyyy-mm-dd" value="{$start}" placeholder="" readonly/>
+            </div>
+            <div class="input-group" style="width: 200px">
+                <span class="input-group-addon">结束时间</span>
+                <input class="form-control dialog-datetime" id="endTime" name="end" type="text" data-date-format="yyyy-mm-dd" value="{$end}" placeholder="" readonly/>
+            </div>
+            <div class="input-group" style="width: 200px">
+                <input class="form-control"  name="title" type="text" value="{$title}" placeholder="商品名称"/>
+            </div>
+            <div class="input-group">
+                {:widget_view('common/multiselect',['name'=>'goodsId','lists' => $glist,'placeholder' => '请选择商品', 'val' =>isset($goodsId)?$goodsId:[]])}
+            </div>
+            <div class="input-group">
+                {:widget_view('common/multiselect',['name'=>'cateId','lists' => $cateList,'placeholder' => '请选择分类', 'val' =>isset($cateId)?$cateId:[]])}
+            </div>
+            <div class="input-group">
+            <span class="input-group-btn">
+                <button class="btn-sm btn-primary" type="submit"  ><i class="fa fa-search"></i></button>
+			</span>&nbsp;
+                <span class="input-group-btn">
+                     <button class="btn-sm btn-warning" type="reset" onclick="empty_search()"><i class="fa fa-undo"></i></button>
+            </span>
+            </div>
+        </form>
+    </div>
+
+    <div class="panel-group">
+        <div class="panel panel-default">
+            <div class="panel-heading clearfix">
+                <div class="btn-group pull-left">
+                    销售统计
+                </div>
+                <div class="btn-group pull-right">
+                    <a href="javascript:;" onclick="printer()" class="btn btn-sm btn btn-primary"><i class="glyphicon glyphicon-print"></i>打印</a>
+                    <a href="javascript:;" onclick="exportExcel()" class="btn btn-success btn-sm"><i class="glyphicon glyphicon-download"></i>导出</a>
+                </div>
+            </div>
+            <div class="panel-body" id="printer">
+                <table class="table table-bordered">
+                    <thead>
+                    <tr>
+                        <th>商品名称</th>
+                        <th>分类</th>
+                        <th>数量</th>
+                        <th>单价</th>
+                        <th>总金额</th>
+                    </tr>
+                    </thead>
+                    <tbody>
+                   {foreach $data as $k=>$v}
+                    <tr>
+                        <td>{$v['title']}</td>
+                        <td>{$v['cateName']}</td>
+                        <td>{$v['num']}</td>
+                        <td>{$v['price']}</td>
+                        <td>{$v['total']}</td>
+                    </tr>
+                    {/foreach}
+                    </tbody>
+                </table>
+            </div>
+        </div>
+    </div>
+</div>
+</div>
+{/block}
+{block name="script"}
+<script src="/static/layDate-v5.0.9/laydate.js"></script>
+<script src="/static/browser.js"></script>
+<script src="/static/jquery.jqprint-0.3.js"></script>
+<script>
+    $(function () {
+        laydate.render({
+            elem: '#startTime',
+            trigger: 'click',
+            theme: '#ffaa2d'
+        });
+        laydate.render({
+            elem: '#endTime',
+            trigger: 'click',
+            theme: '#ffaa2d'
+        });
+    });
+    function empty_search(){
+        window.location.href = 'wxOrderTj';
+    }
+    function printer(){
+        $('#printer').jqprint();
+    }
+
+    function exportExcel() {
+        window.location.href = "wxOrderTjExport?"+$('#search_form').serialize();
+    }
+
+</script>
+{/block}

+ 299 - 0
application/admin/view/statistics/wx_order_view.html

@@ -0,0 +1,299 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="ibox-content">
+<div class="ibox">
+    <div class="row">
+        <div class="col-sm-3">
+            <div class="ibox float-e-margins">
+                <div class="ibox-title">
+                    <span class="label label-success pull-right">月</span>
+                    <h5>收入</h5>
+                </div>
+                <div class="ibox-content">
+                    <h1 class="no-margins">{$data.orderAmount}</h1>
+                    <small>本月订单支付金额</small>
+                </div>
+            </div>
+        </div>
+        <div class="col-sm-3">
+            <div class="ibox float-e-margins">
+                <div class="ibox-title">
+                    <span class="label label-info pull-right">全年</span>
+                    <h5>订单</h5>
+                </div>
+                <div class="ibox-content">
+                    <h1 class="no-margins">{$data.orderCount}</h1>
+                    <small>全年已支付订单</small>
+                </div>
+            </div>
+        </div>
+        <div class="col-sm-3">
+            <div class="ibox float-e-margins">
+                <div class="ibox-title">
+                    <span class="label label-primary pull-right">今天</span>
+                    <h5>下单人数</h5>
+                </div>
+                <div class="ibox-content">
+                    <h1 class="no-margins">{$data.orderUser}</h1>
+                    <small>今日下单人数</small>
+                </div>
+            </div>
+        </div>
+        <div class="col-sm-3">
+            <div class="ibox float-e-margins">
+                <div class="ibox-title">
+                    <span class="label label-danger pull-right">月</span>
+                    <h5>退款金额</h5>
+                </div>
+                <div class="ibox-content">
+                    <h1 class="no-margins">{$data.refundCount}</h1>
+                    <small>本月退款金额</small>
+
+                </div>
+            </div>
+        </div>
+    </div>
+    <div id="app">
+        <div class="row" >
+            <div class="col-sm-12">
+                <div class="ibox float-e-margins">
+                    <div class="ibox-title">
+                        <h5>订单</h5>
+                        <div class="pull-right">
+                            <div class="btn-group">
+                                <button type="button"  @click="setType(0)" :class="'btn btn-xs btn-white'+ (type==0?'active':'')">天</button>
+                                <button type="button"   @click="setType(1)" :class="'btn btn-xs btn-white'+ (type==1?'active':'')">月</button>
+                                <button type="button"   @click="setType(2)" :class="'btn btn-xs btn-white'+ (type==2?'active':'')">年</button>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="ibox-content">
+                        <div class="row">
+                            <div class="col-sm-9">
+                                <div class="flot-chart">
+                                    <div class="flot-chart-content" id="tj"></div>
+                                </div>
+                            </div>
+                            <div class="col-sm-3">
+                                <ul class="stat-list">
+                                    <li>
+                                        <h2 class="no-margins">{{ddzs}}</h2>
+                                        <small>订单总数</small>
+                                        <div class="stat-percent">{{ddbl}}%
+                                            <i v-if="ddzt===0" class="fa fa-bolt text-navy"></i>
+                                            <i v-if="ddzt===1" class="fa fa-level-up text-navy"></i>
+                                            <i v-if="ddzt===2" class="fa fa-level-down text-navy"></i>
+                                        </div>
+                                        <div class="progress progress-mini">
+                                            <div :style="'width:'+ddbl+'%;'" class="progress-bar"></div>
+                                        </div>
+                                    </li>
+                                    <li>
+                                        <h2 class="no-margins ">{{yzfdd}}</h2>
+                                        <small>已支付订单</small>
+                                        <div class="stat-percent">{{yzfbl}}%
+                                            <i v-if="yzfzt===0" class="fa fa-bolt text-navy"></i>
+                                            <i v-if="yzfzt===1" class="fa fa-level-up text-navy"></i>
+                                            <i v-if="yzfzt===2" class="fa fa-level-down text-navy"></i>
+                                        </div>
+                                        <div class="progress progress-mini">
+                                            <div :style="'width:'+yzfbl+'%;'" class="progress-bar"></div>
+                                        </div>
+                                    </li>
+                                    <li>
+                                        <h2 class="no-margins ">{{ddze}}</h2>
+                                        <small>订单总额</small>
+                                        <div class="stat-percent">{{ddzebl}}%
+                                            <i v-if="ddzezt===0" class="fa fa-bolt text-navy"></i>
+                                            <i v-if="ddzezt===1" class="fa fa-level-up text-navy"></i>
+                                            <i v-if="ddzezt===2" class="fa fa-level-down text-navy"></i>
+                                        </div>
+                                        <div class="progress progress-mini">
+                                            <div :style="'width:'+ddzebl+'%;'" class="progress-bar"></div>
+                                        </div>
+                                    </li>
+                            </div>
+                        </div>
+                    </div>
+
+                </div>
+            </div>
+        </div>
+        <div class="row">
+            <div class="col-sm-12">
+                <div class="ibox float-e-margins">
+                    <div class="ibox-title">
+                        <h5>交易分类</h5>
+                    </div>
+                    <div class="ibox-content">
+
+                        <div class="row">
+                            <div class="col-sm-12">
+                                <table class="table table-hover margin bottom">
+                                    <thead>
+                                    <tr>
+                                        <th  class="text-center">序号</th>
+                                        <th>分类名称</th>
+                                        <th class="text-center">销售额</th>
+                                    </tr>
+                                    </thead>
+                                    <tbody>
+
+                                        <tr v-for="(item,key) in cateList">
+                                        <td class="text-center">{{key+1}}</td>
+                                        <td><small>{{item.title}}
+                                        </small>
+                                        </td>
+                                        <td class="text-center"><span class="label label-primary">&yen;{{item.total}}</span>
+                                        </td>
+                                    </tr>
+
+                                    </tbody>
+                                </table>
+                            </div>
+
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+</div>
+{/block}
+{block name="script"}
+<script src="/static/layDate-v5.0.9/laydate.js"></script>
+<script src="/static/browser.js"></script>
+<script src="/static/jquery.jqprint-0.3.js"></script>
+<script src="/static/echarts/dist/echarts.js"></script>
+
+<script>
+
+    new Vue({
+        el: '#app',
+        components:{
+
+        },
+        data(){
+            return {
+                ddzs:0,
+                ddbl:0,
+                ddzt:0,//0持平1上升2下降
+                yzfdd:0,
+                yzfbl:0,
+                yzfzt:0,//0持平1上升2下降
+                ddze:0,
+                ddzebl:0,
+                ddzezt:0,//0持平1上升2下降
+                loading:false,
+                date:'',
+                type:0,
+                cateList:[],
+                rules: {
+                }
+            }
+        },
+        mounted(){
+            this.getList();
+        },
+        methods: {
+
+            setType(type){
+                this.type = type;
+                this.getList();
+            },
+            getList(){
+                var that = this;
+                $.post('{:url("wxOrderView")}?type='+this.type,{},function (res) {
+                   if(res.code==1){
+                       that.dd(res.data)
+                       that.ddzs=res.data.ddzs;
+                       that.ddbl=res.data.ddbl;
+                       that.ddzt=res.data.ddzt;
+                       that.yzfdd=res.data.yzfdd;
+                       that.yzfbl=res.data.yzfbl;
+                       that.yzfzt=res.data.yzfzt;
+                       that.ddze=res.data.ddze;
+                       that.ddzebl=res.data.ddzebl;
+                       that.ddzezt=res.data.ddzezt;
+                       that.cateList=res.data.cateList;
+                   }else {
+                       alert('获取数据失败');
+                       return false;
+                   }
+                })
+            },
+
+            dd(data){
+                let myChart = echarts.init(document.getElementById('tj'), null, {renderer: 'svg'});
+                myChart.setOption({
+                    tooltip: {
+                        trigger: 'axis',
+                        axisPointer: {
+                            type: 'cross',
+                            crossStyle: {
+                                color: '#999'
+                            }
+                        }
+                    },
+
+                    legend: {
+                        data: ['订单数量', '订单金额']
+                    },
+                    xAxis: [
+                        {
+                            type: 'category',
+                            data: data.title,
+                            axisPointer: {
+                                type: 'shadow'
+                            }
+                        }
+                    ],
+                    yAxis: [
+                        {
+                            type: 'value',
+                            name: '订单数量',
+                            axisLabel: {
+                                formatter: '{value} '
+                            }
+                        },
+                        {
+                            type: 'value',
+                            name: '订单金额',
+                            axisLabel: {
+                                formatter: '{value} 元'
+                            }
+                        }
+                    ],
+                    series: [
+
+                        {
+                            name: '订单数量',
+                            type: 'bar',
+                            tooltip: {
+                                valueFormatter: function (value) {
+                                    return value;
+                                }
+                            },
+                            data: data.value,
+                        },
+                        {
+                            name: '订单金额',
+                            type: 'line',
+                            yAxisIndex: 1,
+                            tooltip: {
+                                valueFormatter: function (value) {
+                                    return value + ' 元';
+                                }
+                            },
+                            data: data.value1,
+                        }
+                    ]
+                })
+
+
+            },
+        }
+    })
+</script>
+{/block}

+ 74 - 0
application/admin/view/wx_barrel/add.html

@@ -0,0 +1,74 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-title">
+                <h5>{$meta_title}</h5>
+                <div class="ibox-tools">
+                    <a class="toback" href="{:url('index')}">
+                        返回上一页
+                    </a>
+                </div>
+            </div>
+            <div class="ibox-content">
+                <form method="post" action="{:url('add')}" class="form-horizontal">
+                    <input type="hidden" name="id" value="{$info['id']|default='0'}">
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">名称<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            <input type="text" class="form-control" name="title" value="{$info.title|default=''}">
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">图片<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            {:widget_view('common/upimg',['name'=>'path','multi'=>0,'val'=>isset($info)?$info['path']:''])}
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">押金<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            <input type="number" class="form-control" name="cash_price" value="{$info.cash_price|default=''}">
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">排序</label>
+                        <div class="col-sm-6">
+                            <input type="number" class="form-control" name="sort" value="{$info.sort|default='0'}">
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">状态</label>
+                        <div class="col-sm-6">
+                            <label class="cr-inline">
+                                <input type="radio" value="1" name="enable">正常&nbsp;&nbsp;
+                            </label>
+                            <label class="cr-inline">
+                                <input type="radio" value="0" name="enable">禁用
+                            </label>
+                        </div>
+                    </div>
+
+                    <div class="hr-line-dashed"></div>
+                    <div class="form-group">
+                        <div class="col-sm-4 col-sm-offset-2">
+                            <button class="btn btn-primary ajax-post" target-form="form-horizontal" type="submit">确 定</button>
+                            <a href="{:url('index')}" class="btn btn-default">取 消</a>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(document).ready(function(){
+        formSetValue("enable", {$info.enable|default=1});
+        formSetValue("is_water", {$info.is_water|default=0});
+    });
+
+</script>
+{/block}

+ 104 - 0
application/admin/view/wx_barrel/index.html

@@ -0,0 +1,104 @@
+{extend name="common/common2" /}
+{block name="main"}
+
+<div class="ibox">
+    <div class="ibox-content">
+        <div class="row">
+            <div class="col-xs-3">
+                <a href="{:url('add')}" class="btn btn-sm btn-primary">新增</a>
+            </div>
+            <div class="col-xs-9" style="text-align: right;">
+                <form class="form-inline" id="form-search" action="{:url('index')}">
+                    <div class="input-group">
+                        <input type="text" class="form-control" name="title" placeholder="分类名称">
+                    </div>
+                    <div class="input-group">
+                        <select name="enable" class="form-control">
+                            <option value="">选择状态</option>
+                            <option value="0">禁用</option>
+                            <option value="1">正常</option>
+                        </select>
+                    </div>
+                    <div class="input-group">
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
+                        </span>
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary " type="button" id="search-clear"><i class="fa fa-undo"></i></button>
+                        </span>
+                    </div>
+                </form>
+            </div>
+        </div>
+
+    </div>
+    <div class="ibox-content">
+        <div class="jqGrid_wrapper">
+            <table id="table" style="border-collapse: collapse"></table>
+            <div id="pager"></div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(function () {
+
+        $(window).bind("resize",function(){
+            var width=$(".jqGrid_wrapper").width();
+            $("#table").setGridWidth(width);
+        });
+
+        $.jgrid.defaults.styleUI="Bootstrap";
+        $("#table").jqGrid({
+            url:"{:url('index')}",
+            datatype: "json",
+            colModel:[
+                {label:'名称',name:'title',index:'title', width:60,sortable: false},
+                {label:'封面图',name:'path',index:'path',width:80,editable: false,sortable: false,formatter: function (a, b, c) {
+                        return '<img src="'+a+'" width="60" onclick="open_img(this)"></img>';
+                    }},
+                {label:'排序',name:'sort',index:'sort',width:40,sortable: true,formatter: function (a, b, c) {
+                    return '<input type="number" onchange="updateSort(this)" data-url="{:url('changeSort')}" class="form-control input-sm" data-id="'+c.id+'" data-old="'+a+'" value="'+a+'" />';
+                }},
+                {label:'押金',name:'cash_price',index:'cash_price', width:60,sortable: false},
+
+                {label:'状态',name:'enable',index:'enable',width:50,editable: false,sortable: false,formatter:function (a,b,c){
+                    if(a == 0){
+                        var url = "{:url('changeField',[],'')}/fn/enable/fv/1/id/"+c.id;
+                        return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-danger" title="禁用">禁用</span></a>';
+                    } else{
+                        var url = "{:url('changeField',[],'')}/fn/enable/fv/0/id/"+c.id;
+                        return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-primary" title="正常">正常</span></a>';
+                    }
+                }},
+                {label:'操作',width:100,sortable: false,formatter: function (a, b, c) {
+                    var editurl = "{:url('add',[],'')}/id/"+c.id;
+                    var delurl = "{:url('del',[],'')}/id/"+c.id;
+                    var btn = '<a href="'+editurl+'"><span class="label label-info" title="编辑">编辑</span></a>&nbsp;';
+                    btn += '<a href="'+delurl+'" class="confirm ajax-get" data-confirm="确定要删除此记录吗?" data-table="1"><span class="label label-danger" title="删除">删除</span></a>';
+                    return btn;
+                }},
+            ],
+            rowNum:10,
+            rowList:[10,20,30,50,100],
+            pager: '#pager',
+            sortname: 'sort',
+            viewrecords: true,
+            autowidth:true,
+            mtype: 'post',
+            height: 'auto',
+            emptyrecords: "暂无数据",
+            sortorder: "asc",
+            caption:"{$meta_title}",
+            loadComplete: function (xhr) {
+                if(xhr.code==0){
+                    layer.msg(xhr.msg);
+                    return false;
+                }
+            },
+        });
+    });
+
+</script>
+{/block}

+ 38 - 0
application/admin/view/wx_cash/details.html

@@ -0,0 +1,38 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-content">
+                <table class="table table-bordered">
+                    <tbody>
+                    <tr>
+                        <th style="width:120px ">单号</th><td>{$info['sn']}</td>
+                    </tr>
+
+                    <tr>
+                        <th>用户名</th><td>{$info['user_name']}</td>
+                    </tr>
+                    <tr>
+                        <th>空桶名称</th><td>{$info['barrel_name']}</td>
+                    </tr>
+                    <tr>
+                        <th>数量</th><td>{$info['num']}</td>
+                    </tr>
+                    <tr>
+                        <th>单价</th><td>{$info['price']}</td>
+                    </tr>
+                    <tr>
+                        <th>金额</th><td>{$info['amount']}</td>
+                    </tr>
+                    <tr>
+                        <th>创建时间</th><td>{$info['create_time']}</td>
+                    </tr>
+                    </tbody>
+                </table>
+            </div>
+
+        </div>
+    </div>
+</div>
+{/block}

+ 120 - 0
application/admin/view/wx_cash/index.html

@@ -0,0 +1,120 @@
+{extend name="common/common2" /}
+{block name="main"}
+
+<div class="ibox">
+    <div class="ibox-content">
+        <div class="row">
+            <div class="col-xs-3">
+
+            </div>
+            <div class="col-xs-12" style="text-align: right;">
+                <form class="form-inline" id="form-search" action="{:url('index')}">
+
+                    <div class="input-group">
+                        <input type="text" id="date" readonly class="form-control" name="begin" placeholder="开始日期">
+                    </div>
+                    <div class="input-group">
+                        <input type="text" id="date1" readonly class="form-control" name="end" placeholder="结束日期">
+                    </div>
+                    <div class="input-group">
+                        <input type="text" class="form-control" style="width: 180px;"  name="order_sn" placeholder="单号">
+                    </div>
+
+                    <div class="input-group">
+                        <input type="text" class="form-control" style="width: 150px;"  name="name" placeholder="用户名">
+                    </div>
+
+                    <div class="input-group">
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
+                        </span>
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary " type="button" id="search-clear"><i class="fa fa-undo"></i></button>
+                        </span>
+                    </div>
+                </form>
+            </div>
+        </div>
+
+    </div>
+    <div class="ibox-content">
+        <div class="jqGrid_wrapper">
+            <table id="table" style="border-collapse: collapse"></table>
+            <div id="pager"></div>
+        </div>
+    </div>
+</div>
+<script src="/static/layDate-v5.0.9/laydate.js"></script>
+
+{/block}
+
+{block name="script"}
+<script>
+    laydate.render({
+        elem: '#date',
+        //设置开始日期、日期日期的 input 选择器
+        //数组格式为 5.3.0 开始新增,之前版本直接配置 true 或任意分割字符即可
+        trigger: 'click' ,
+        theme: '#1ab394'
+    });
+    laydate.render({
+        elem: '#date1',
+        //设置开始日期、日期日期的 input 选择器
+        //数组格式为 5.3.0 开始新增,之前版本直接配置 true 或任意分割字符即可
+        trigger: 'click' ,
+        theme: '#1ab394'
+    });
+    $(function () {
+
+        $(window).bind("resize",function(){
+            var width=$(".jqGrid_wrapper").width();
+            $("#table").setGridWidth(width);
+        });
+
+        $.jgrid.defaults.styleUI="Bootstrap";
+        $("#table").jqGrid({
+            url:"{:url('index')}",
+            datatype: "json",
+            colModel:[
+                {label:'#',name:'id',index:'id', width:30,sortable: false},
+                {label:'单号',name:'sn',index:'sn', width:80,sortable: false},
+                {label:'用户名',name:'user_name',index:'user_name', width:60,sortable: false},
+                {label:'空桶',name:'barrel_name',index:'barrel_name', width:60,sortable: false},
+                {label:'数量',name:'num',index:'num', width:60,sortable: false},
+                {label:'单价',name:'price',index:'price', width:40,sortable: false},
+                {label:'金额',name:'amount',index:'amount', width:40,sortable: false},
+
+
+                {label:'创建时间',name:'create_time',index:'create_time', width:70,sortable: false},
+
+                {label:'操作',width:40,sortable: false,formatter: function (a, b, c) {
+                        var detailsurl = "{:url('details',[],'')}/id/"+c.id;
+                        var option = "{:url('option',[],'')}/id/"+c.id;
+                        var  btn= '<a url="'+detailsurl+'" href="javascript:;" data-title="详情" onclick="layer_open(this,1)"><span class="label label-primary" title="详情">详情</span></a>&nbsp;';
+
+                         return btn;
+                    }},
+            ],
+            rowNum:10,
+            rowList:[10,20,30,50,100],
+            pager: '#pager',
+            sortname: 'id',
+            viewrecords: true,
+            autowidth:true,
+            mtype: 'post',
+            height: 'auto',
+            emptyrecords: "暂无数据",
+            sortorder: "desc",
+            caption:"{$meta_title}",
+            loadComplete: function (xhr) {
+                if(xhr.code==0){
+                    layer.msg(xhr.msg);
+                    return false;
+                }
+
+            },
+        });
+    });
+
+</script>
+{/block}

+ 59 - 0
application/admin/view/wx_cash_refund/details.html

@@ -0,0 +1,59 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-content">
+                <table class="table table-bordered">
+                    <tbody>
+                    <tr>
+                        <th style="width:120px ">单号</th><td>{$info['sn']}</td>
+                    </tr>
+
+                    <tr>
+                        <th>用户名</th><td>{$info['user_name']}</td>
+                    </tr>
+                    <tr>
+                        <th>空桶名称</th><td>{$info['barrel_name']}</td>
+                    </tr>
+                    <tr>
+                        <th>数量</th><td>{$info['num']}</td>
+                    </tr>
+                    <tr>
+                        <th>金额</th><td>{$info['amount']}</td>
+                    </tr>
+                    <tr>
+                        <th>创建时间</th><td>{$info['create_time']}</td>
+                    </tr>
+
+
+                    <tr>
+                        <th>状态</th><td>{$info['status_name']}</td>
+                    </tr>
+
+                    {if $info.status>0}
+                    <tr>
+                        <th>审核人</th><td>{$info['deal_user_name']}</td>
+                    </tr>
+                    <tr>
+                        <th>审核时间</th><td>{$info['deal_time']}</td>
+                    </tr>
+                    <tr>
+                        <th>备注</th><td>{$info['remark']}</td>
+                    </tr>
+                    {/if}
+
+                    {if $info['status']==0}
+                    <tr>
+                        <th>操作</th><td><a href="javascript:;" url="{:url('option',['id'=>$info['id']])}" data-title="审核" onclick="layer_open(this,2)" class="btn btn-xs btn-danger">审核</a>
+                    </td>
+                    </tr>
+                    {/if}
+                    </tbody>
+                </table>
+            </div>
+
+        </div>
+    </div>
+</div>
+{/block}

+ 135 - 0
application/admin/view/wx_cash_refund/index.html

@@ -0,0 +1,135 @@
+{extend name="common/common2" /}
+{block name="main"}
+
+<div class="ibox">
+    <div class="ibox-content">
+        <div class="row">
+            <div class="col-xs-3">
+
+            </div>
+            <div class="col-xs-12" style="text-align: right;">
+                <form class="form-inline" id="form-search" action="{:url('index')}">
+
+                    <div class="input-group">
+                        <input type="text" id="date" readonly class="form-control" name="begin" placeholder="开始日期">
+                    </div>
+                    <div class="input-group">
+                        <input type="text" id="date1" readonly class="form-control" name="end" placeholder="结束日期">
+                    </div>
+                    <div class="input-group">
+                        <input type="text" class="form-control" style="width: 180px;"  name="order_sn" placeholder="单号">
+                    </div>
+
+                    <div class="input-group">
+                        <input type="text" class="form-control" style="width: 150px;"  name="name" placeholder="用户名">
+                    </div>
+                    <div class="input-group">
+                        <select name="status" class="form-control">
+                            <option value="">选择状态</option>
+                            {foreach $status as $k=>$v}
+                            <option value="{$k}">{$v}</option>
+                            {/foreach}
+
+                        </select>
+                    </div>
+                    <div class="input-group">
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
+                        </span>
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary " type="button" id="search-clear"><i class="fa fa-undo"></i></button>
+                        </span>
+                    </div>
+                </form>
+            </div>
+        </div>
+
+    </div>
+    <div class="ibox-content">
+        <div class="jqGrid_wrapper">
+            <table id="table" style="border-collapse: collapse"></table>
+            <div id="pager"></div>
+        </div>
+    </div>
+</div>
+<script src="/static/layDate-v5.0.9/laydate.js"></script>
+
+{/block}
+
+{block name="script"}
+<script>
+    laydate.render({
+        elem: '#date',
+        //设置开始日期、日期日期的 input 选择器
+        //数组格式为 5.3.0 开始新增,之前版本直接配置 true 或任意分割字符即可
+        trigger: 'click' ,
+        theme: '#1ab394'
+    });
+    laydate.render({
+        elem: '#date1',
+        //设置开始日期、日期日期的 input 选择器
+        //数组格式为 5.3.0 开始新增,之前版本直接配置 true 或任意分割字符即可
+        trigger: 'click' ,
+        theme: '#1ab394'
+    });
+    $(function () {
+
+        $(window).bind("resize",function(){
+            var width=$(".jqGrid_wrapper").width();
+            $("#table").setGridWidth(width);
+        });
+
+        $.jgrid.defaults.styleUI="Bootstrap";
+        $("#table").jqGrid({
+            url:"{:url('index')}",
+            datatype: "json",
+            colModel:[
+                {label:'#',name:'id',index:'id', width:30,sortable: false},
+                {label:'押金id',name:'cash_id',index:'cash_id', width:30,sortable: false},
+                {label:'单号',name:'sn',index:'sn', width:80,sortable: false},
+                {label:'用户名',name:'user_name',index:'user_name', width:60,sortable: false},
+                {label:'空桶',name:'barrel_name',index:'barrel_name', width:60,sortable: false},
+                {label:'数量',name:'num',index:'num', width:40,sortable: false},
+                {label:'金额',name:'amount',index:'amount', width:40,sortable: false},
+                {label:'状态',name:'status_name',index:'status_name',width:40,editable: false,sortable: false,formatter:function (a,b,c){
+                        return '<span title="'+a+'">'+a+'</span>';
+
+                    }},
+
+                {label:'创建时间',name:'create_time',index:'create_time', width:70,sortable: false},
+
+                {label:'操作',width:80,sortable: false,formatter: function (a, b, c) {
+                        var detailsurl = "{:url('details',[],'')}/id/"+c.id;
+                        var option = "{:url('option',[],'')}/id/"+c.id;
+                        var  btn= '<a url="'+detailsurl+'" href="javascript:;" data-title="详情" onclick="layer_open(this,1)"><span class="label label-primary" title="详情">详情</span></a>&nbsp;';
+
+                         if(c.status==0){
+                              btn+= '<a url="'+option+'" href="javascript:;" data-title="审核" onclick="layer_open(this,1)"><span class="label label-success" title="审核">审核</span></a>&nbsp;';
+
+                         }
+                         return btn;
+                    }},
+            ],
+            rowNum:10,
+            rowList:[10,20,30,50,100],
+            pager: '#pager',
+            sortname: 'id',
+            viewrecords: true,
+            autowidth:true,
+            mtype: 'post',
+            height: 'auto',
+            emptyrecords: "暂无数据",
+            sortorder: "desc",
+            caption:"{$meta_title}",
+            loadComplete: function (xhr) {
+                if(xhr.code==0){
+                    layer.msg(xhr.msg);
+                    return false;
+                }
+
+            },
+        });
+    });
+
+</script>
+{/block}

+ 56 - 0
application/admin/view/wx_cash_refund/option.html

@@ -0,0 +1,56 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-content">
+                <form method="post" action="{:url('option',[],'')}/id/{$id}" class="form-horizontal">
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">退款金额</label>
+                        <div class="col-sm-6">
+                            <input type="text" readonly class="form-control" value="{$pay.amount}">
+                        </div>
+                    </div>
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">备注</label>
+                        <div class="col-sm-6">
+                            <textarea name="remark" class="form-control"></textarea>
+                        </div>
+                    </div>
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">状态</label>
+                        <div class="col-sm-6">
+                            <label class="cr-inline">
+                                <input type="radio" value="1" name="status">同意&nbsp;&nbsp;
+                            </label>
+                            <label class="cr-inline">
+                                <input type="radio" value="2" name="status">拒绝
+                            </label>
+                        </div>
+                    </div>
+
+                    <div class="hr-line-dashed"></div>
+                    <div class="form-group">
+                        <div class="col-sm-4 col-sm-offset-2">
+                            <button class="btn btn-primary ajax-post" data-layer="1" target-form="form-horizontal" type="submit">确 定</button>
+                            <button  class="btn cancel-btn btn-default" type="button">取 消</button>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(document).ready(function(){
+        formSetValue("status", {$info.status|default=1});
+    });
+
+
+</script>
+{/block}

+ 150 - 0
application/admin/view/wx_goods/add.html

@@ -0,0 +1,150 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-content">
+                <form method="post" action="{:url('add')}" class="form-horizontal">
+                    <input type="hidden" name="id" value="{$info['id']|default='0'}">
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">商品名称<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            <input type="text" class="form-control" name="title" value="{$info.title|default=''}">
+                        </div>
+                    </div>
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">商品价格<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            <input type="number" class="form-control" name="price" value="{$info.price|default=''}">
+                        </div>
+                    </div>
+
+                    <!--<div class="form-group">-->
+                        <!--<label class="col-sm-2 control-label">库存</label>-->
+                        <!--<div class="col-sm-6">-->
+                            <!--<input type="number" class="form-control" name="stock" value="{$info.stock|default='0'}">-->
+                        <!--</div>-->
+                    <!--</div>-->
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">商品分类<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            <select name="cate_id" class="form-control" onchange="setCate(this.value)">
+                                <option value="0">选择商品分类</option>
+                                {volist name='cateList' id='v'}
+                                <option value="{$v.id|default=''}">{$v['title']}</option>
+                                {/volist}
+                            </select>
+                        </div>
+                    </div>
+                    <div class="form-group" id="kt" {if (isset($info) && $info.barrel_id>0) || (isset($cateInfo) && $cateInfo.is_water==1)} style="display:block" {else} style="display:none"  {/if}>
+                        <label class="col-sm-2 control-label">空桶<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            {:widget('common/select',['name'=>'barrel_id','lists'=>$barrel,'value'=>isset($info)?$info.barrel_id:''])}
+
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">标签</label>
+                        <div class="col-sm-6">
+                            {:widget('common/select',['name'=>'label','lists'=>$label,'value'=>isset($info)?$info.label:''])}
+
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">商品图片<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            {:widget_view('common/upimg',['name'=>'img','multi'=>0,'val'=>isset($info)?$info['img']:''])}
+                        </div>
+                    </div>
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">轮播图<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            {:widget_view('common/upimg',['name'=>'imgs','multi'=>1,'val'=>isset($info)?$info['imgs']:''])}
+                        </div>
+                    </div>
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">排序</label>
+                        <div class="col-sm-6">
+                            <input type="number" class="form-control" name="sort" value="{$info.sort|default='0'}">
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">商品描述</label>
+                        <div class="col-sm-6">
+                            <input type="text" class="form-control" name="dec" value="{$info.dec|default=''}">
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">状态</label>
+                        <div class="col-sm-6">
+                            <label class="cr-inline">
+                                <input type="radio" value="1" name="enable">上架&nbsp;&nbsp;
+                            </label>
+                            <label class="cr-inline">
+                                <input type="radio" value="0" name="enable">下架
+                            </label>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">是否推荐</label>
+                        <div class="col-sm-6">
+                            <label class="cr-inline">
+                                <input type="radio" value="0" name="is_tj">否&nbsp;&nbsp;
+                            </label>
+                            <label class="cr-inline">
+                                <input type="radio" value="1" name="is_tj">是
+                            </label>
+                        </div>
+                    </div>
+
+
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">详情<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            {:widget_view('common/ueditor',['name'=>'content','height'=>300,'val'=>isset($info)?$info['content']:''])}
+                        </div>
+                    </div>
+
+                    <div class="hr-line-dashed"></div>
+                    <div class="form-group">
+                        <div class="col-sm-6 col-sm-offset-2">
+                            <button class="btn btn-primary ajax-post" data-layer="1" target-form="form-horizontal" type="submit">确 定</button>
+                            <button  class="btn cancel-btn btn-default" type="button">取 消</button>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(document).ready(function(){
+        formSetValue("enable", {$info.enable|default=1});
+    });
+    $(document).ready(function(){
+        formSetValue("cate_id", {$info.cate_id|default=0});
+    });
+    $(document).ready(function(){
+        formSetValue("is_tj", {$info.is_tj|default=0});
+    });
+
+    function setCate(value) {
+        $.post("{:url('WxGoods/checkIsWater')}",{id:value},function (res) {
+            console.log(res);
+            if(res.code==1 && res.data.is_water==1){
+                $("#kt").attr('style','display:block');
+            }else {
+                $("#kt").attr('style','display:none');
+
+            }
+        })
+    }
+</script>
+{/block}

+ 133 - 0
application/admin/view/wx_goods/index.html

@@ -0,0 +1,133 @@
+{extend name="common/common2" /}
+{block name="main"}
+
+<div class="ibox">
+    <div class="ibox-content">
+        <div class="row">
+            <div class="col-xs-3">
+                <a href="javascript:;" url="{:url('add')}" data-title="新增" onclick="layer_open(this,1)" class="btn btn-sm btn-primary">新增</a>
+            </div>
+            <div class="col-xs-9" style="text-align: right;">
+                <form class="form-inline" id="form-search" action="{:url('index')}">
+                    <div class="input-group">
+                        <input type="text" class="form-control" name="title" placeholder="商品名称">
+                    </div>
+                    <div class="input-group">
+                        <select name="enable" class="form-control">
+                            <option value="">选择状态</option>
+                            <option value="0">下架</option>
+                            <option value="1">上架</option>
+                        </select>
+                    </div>
+                    <div class="input-group">
+                        <select name="is_tj" class="form-control">
+                            <option value="">是否推荐</option>
+                            <option value="0">否</option>
+                            <option value="1">是</option>
+                        </select>
+                    </div>
+                    <div class="input-group">
+                        <select name="cate_id" class="form-control">
+                            <option value="">选择分类</option>
+                            {foreach $cateList as $k=>$v}
+                            <option value="{$v.id}">{$v['title']}</option>
+                            {/foreach}
+                        </select>
+                    </div>
+
+                    <div class="input-group">
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
+                        </span>
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary " type="button" id="search-clear"><i class="fa fa-undo"></i></button>
+                        </span>
+                    </div>
+                </form>
+            </div>
+        </div>
+
+    </div>
+    <div class="ibox-content">
+        <div class="jqGrid_wrapper">
+            <table id="table" style="border-collapse: collapse"></table>
+            <div id="pager"></div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(function () {
+
+        $(window).bind("resize",function(){
+            var width=$(".jqGrid_wrapper").width();
+            $("#table").setGridWidth(width);
+        });
+
+        $.jgrid.defaults.styleUI="Bootstrap";
+        $("#table").jqGrid({
+            url:"{:url('index')}",
+            datatype: "json",
+            colModel:[
+                {label:'商品名称',name:'title',index:'title', width:80,sortable: false},
+                {label:'商品价格',name:'price',index:'price', width:40,sortable: false},
+                {label:'商品分类',name:'cate_name',index:'cate_name', width:80,sortable: false},
+
+                {label:'封面图',name:'img',index:'img',width:80,editable: false,sortable: false,formatter: function (a, b, c) {
+                    return '<img src="'+a+'" width="60" onclick="open_img(this)"></img>';
+                }},
+                {label:'标签',name:'label_name',index:'label_name',width:40,editable: false,sortable: false},
+              //  {label:'库存',name:'stock',index:'stock',width:40,editable: false,sortable: false},
+                {label:'销量',name:'sale',index:'sale',width:40,editable: false,sortable: false},
+                {label:'排序',name:'sort',index:'sort',width:40,sortable: true,formatter: function (a, b, c) {
+                    return '<input type="number" onchange="updateSort(this)" data-url="{:url('changeSort')}" class="form-control input-sm" data-id="'+c.id+'" data-old="'+a+'" value="'+a+'" />';
+                }},
+                {label:'是否推荐',name:'is_tj',index:'is_tj',width:50,editable: false,sortable: false,formatter:function (a,b,c){
+                        if(a == 0){
+                            var url = "{:url('changeField',[],'')}/fn/is_tj/fv/1/id/"+c.id;
+                            return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-danger" title="否">否</span></a>';
+                        } else{
+                            var url = "{:url('changeField',[],'')}/fn/is_tj/fv/0/id/"+c.id;
+                            return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-primary" title="是">是</span></a>';
+                        }
+                    }},
+                {label:'状态',name:'enable',index:'enable',width:50,editable: false,sortable: false,formatter:function (a,b,c){
+                        if(a == 0){
+                            var url = "{:url('changeField',[],'')}/fn/enable/fv/1/id/"+c.id;
+                            return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-danger" title="下架">下架</span></a>';
+                        } else{
+                            var url = "{:url('changeField',[],'')}/fn/enable/fv/0/id/"+c.id;
+                            return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-primary" title="上架">上架</span></a>';
+                        }
+                    }},
+                {label:'操作',width:80,sortable: false,formatter: function (a, b, c) {
+                    var editurl = "{:url('add',[],'')}/id/"+c.id;
+                    var delurl = "{:url('del',[],'')}/id/"+c.id;
+                        var btn = '<a url="'+editurl+'" href="javascript:;" data-title="编辑" onclick="layer_open(this,1)"><span class="label label-primary" title="编辑">编辑</span></a>&nbsp;';
+                        btn += '<a href="'+delurl+'" class="confirm ajax-get" data-confirm="确定要删除此记录吗?" data-table="1"><span class="label label-danger" title="删除">删除</span></a>';
+                    return btn;
+                }},
+            ],
+            rowNum:10,
+            rowList:[10,20,30,50,100],
+            pager: '#pager',
+            sortname: 'sort',
+            viewrecords: true,
+            autowidth:true,
+            mtype: 'post',
+            height: 'auto',
+            emptyrecords: "暂无数据",
+            sortorder: "asc",
+            caption:"{$meta_title}",
+            loadComplete: function (xhr) {
+                if(xhr.code==0){
+                    layer.msg(xhr.msg);
+                    return false;
+                }
+            },
+        });
+    });
+
+</script>
+{/block}

+ 71 - 0
application/admin/view/wx_goods_cate/add.html

@@ -0,0 +1,71 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-content">
+                <form method="post" action="{:url('add')}" class="form-horizontal">
+                    <input type="hidden" name="id" value="{$info['id']|default='0'}">
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">名称<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            <input type="text" class="form-control" name="title" value="{$info.title|default=''}">
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">图片<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            {:widget_view('common/upimg',['name'=>'path','multi'=>0,'val'=>isset($info)?$info['path']:''])}
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">排序</label>
+                        <div class="col-sm-6">
+                            <input type="number" class="form-control" name="sort" value="{$info.sort|default='0'}">
+                        </div>
+                    </div>
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">状态</label>
+                        <div class="col-sm-6">
+                            <label class="cr-inline">
+                                <input type="radio" value="1" name="enable">正常&nbsp;&nbsp;
+                            </label>
+                            <label class="cr-inline">
+                                <input type="radio" value="0" name="enable">禁用
+                            </label>
+                        </div>
+                    </div>
+<!--                    <div class="form-group">-->
+<!--                        <label class="col-sm-2 control-label">是否是桶装水</label>-->
+<!--                        <div class="col-sm-6">-->
+<!--                            <label class="cr-inline">-->
+<!--                                <input type="radio" value="0" name="is_water">否&nbsp;&nbsp;-->
+<!--                            </label>-->
+<!--                            <label class="cr-inline">-->
+<!--                                <input type="radio" value="1" name="is_water">是-->
+<!--                            </label>-->
+<!--                        </div>-->
+<!--                    </div>-->
+                    <div class="hr-line-dashed"></div>
+                    <div class="form-group">
+                        <div class="col-sm-4 col-sm-offset-2">
+                            <button class="btn btn-primary ajax-post" data-layer="1" target-form="form-horizontal" type="submit">确 定</button>
+                            <button  class="btn cancel-btn btn-default" type="button">取 消</button>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(document).ready(function(){
+        formSetValue("enable", {$info.enable|default=1});
+        formSetValue("is_water", {$info.is_water|default=0});
+    });
+
+</script>
+{/block}

+ 106 - 0
application/admin/view/wx_goods_cate/index.html

@@ -0,0 +1,106 @@
+{extend name="common/common2" /}
+{block name="main"}
+
+<div class="ibox">
+    <div class="ibox-content">
+        <div class="row">
+            <div class="col-xs-3">
+                <a href="javascript:;" url="{:url('add')}" data-title="新增" onclick="layer_open(this,1)" class="btn btn-sm btn-primary">新增</a>
+            </div>
+            <div class="col-xs-9" style="text-align: right;">
+                <form class="form-inline" id="form-search" action="{:url('index')}">
+                    <div class="input-group">
+                        <input type="text" class="form-control" name="title" placeholder="分类名称">
+                    </div>
+                    <div class="input-group">
+                        <select name="enable" class="form-control">
+                            <option value="">选择状态</option>
+                            <option value="0">禁用</option>
+                            <option value="1">正常</option>
+                        </select>
+                    </div>
+                    <div class="input-group">
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
+                        </span>
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary " type="button" id="search-clear"><i class="fa fa-undo"></i></button>
+                        </span>
+                    </div>
+                </form>
+            </div>
+        </div>
+
+    </div>
+    <div class="ibox-content">
+        <div class="jqGrid_wrapper">
+            <table id="table" style="border-collapse: collapse"></table>
+            <div id="pager"></div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(function () {
+
+        $(window).bind("resize",function(){
+            var width=$(".jqGrid_wrapper").width();
+            $("#table").setGridWidth(width);
+        });
+
+        $.jgrid.defaults.styleUI="Bootstrap";
+        $("#table").jqGrid({
+            url:"{:url('index')}",
+            datatype: "json",
+            colModel:[
+                {label:'名称',name:'title',index:'title', width:60,sortable: false},
+                {label:'排序',name:'sort',index:'sort',width:40,sortable: true,formatter: function (a, b, c) {
+                    return '<input type="number" onchange="updateSort(this)" data-url="{:url('changeSort')}" class="form-control input-sm" data-id="'+c.id+'" data-old="'+a+'" value="'+a+'" />';
+                }},
+                // {label:'是否是桶装水',name:'is_water',index:'is_water',width:50,editable: false,sortable: false,formatter:function (a,b,c){
+                //         if(a == 0){
+                //             return '否';
+                //         } else{
+                //             return '是';
+                //         }
+                //     }},
+                {label:'状态',name:'enable',index:'enable',width:50,editable: false,sortable: false,formatter:function (a,b,c){
+                    if(a == 0){
+                        var url = "{:url('changeField',[],'')}/fn/enable/fv/1/id/"+c.id;
+                        return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-danger" title="禁用">禁用</span></a>';
+                    } else{
+                        var url = "{:url('changeField',[],'')}/fn/enable/fv/0/id/"+c.id;
+                        return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-primary" title="正常">正常</span></a>';
+                    }
+                }},
+                {label:'操作',width:100,sortable: false,formatter: function (a, b, c) {
+                    var editurl = "{:url('add',[],'')}/id/"+c.id;
+                    var delurl = "{:url('del',[],'')}/id/"+c.id;
+                        var btn = '<a url="'+editurl+'" href="javascript:;" data-title="编辑" onclick="layer_open(this,1)"><span class="label label-primary" title="编辑">编辑</span></a>&nbsp;';
+                        btn += '<a href="'+delurl+'" class="confirm ajax-get" data-confirm="确定要删除此记录吗?" data-table="1"><span class="label label-danger" title="删除">删除</span></a>';
+                    return btn;
+                }},
+            ],
+            rowNum:10,
+            rowList:[10,20,30,50,100],
+            pager: '#pager',
+            sortname: 'sort',
+            viewrecords: true,
+            autowidth:true,
+            mtype: 'post',
+            height: 'auto',
+            emptyrecords: "暂无数据",
+            sortorder: "asc",
+            caption:"{$meta_title}",
+            loadComplete: function (xhr) {
+                if(xhr.code==0){
+                    layer.msg(xhr.msg);
+                    return false;
+                }
+            },
+        });
+    });
+
+</script>
+{/block}

+ 52 - 0
application/admin/view/wx_notice/add.html

@@ -0,0 +1,52 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-title">
+                <h5>{$meta_title}</h5>
+                <div class="ibox-tools">
+                    <a class="toback" href="{:url('index')}">
+                        返回上一页
+                    </a>
+                </div>
+            </div>
+            <div class="ibox-content">
+                <form method="post" action="{:url('add')}" class="form-horizontal">
+                    <input type="hidden" name="id" value="{$info['id']|default='0'}">
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">名称<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            <input type="text" class="form-control" name="title" value="{$info.title|default=''}">
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">内容<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            <textarea name="content" class="form-control" cols="30" rows="3"  >{$info.content|default=''}</textarea>
+
+                        </div>
+                    </div>
+
+
+                    <div class="hr-line-dashed"></div>
+                    <div class="form-group">
+                        <div class="col-sm-4 col-sm-offset-2">
+                            <button class="btn btn-primary ajax-post" target-form="form-horizontal" type="submit">确 定</button>
+                            <a href="{:url('index')}" class="btn btn-default">取 消</a>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(document).ready(function(){
+
+    });
+
+</script>
+{/block}

+ 86 - 0
application/admin/view/wx_notice/index.html

@@ -0,0 +1,86 @@
+{extend name="common/common2" /}
+{block name="main"}
+
+<div class="ibox">
+    <div class="ibox-content">
+        <div class="row">
+            <div class="col-xs-3">
+                <a href="{:url('add')}" class="btn btn-sm btn-primary">新增</a>
+            </div>
+            <div class="col-xs-9" style="text-align: right;">
+                <form class="form-inline" id="form-search" action="{:url('index')}">
+                    <div class="input-group">
+                        <input type="text" class="form-control" name="title" placeholder="名称">
+                    </div>
+
+                    <div class="input-group">
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
+                        </span>
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary " type="button" id="search-clear"><i class="fa fa-undo"></i></button>
+                        </span>
+                    </div>
+                </form>
+            </div>
+        </div>
+
+    </div>
+    <div class="ibox-content">
+        <div class="jqGrid_wrapper">
+            <table id="table" style="border-collapse: collapse"></table>
+            <div id="pager"></div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(function () {
+
+        $(window).bind("resize",function(){
+            var width=$(".jqGrid_wrapper").width();
+            $("#table").setGridWidth(width);
+        });
+
+        $.jgrid.defaults.styleUI="Bootstrap";
+        $("#table").jqGrid({
+            url:"{:url('index')}",
+            datatype: "json",
+            colModel:[
+                {label:'名称',name:'title',index:'title', width:60,sortable: false},
+                {label:'内容',name:'content',index:'content', width:60,sortable: false},
+                {label:'发布人',name:'user_name',index:'user_name', width:60,sortable: false},
+                {label:'创建时间',name:'create_time',index:'create_time', width:60,sortable: false},
+                {label:'更新时间',name:'update_time',index:'update_time', width:60,sortable: false},
+
+                {label:'操作',width:100,sortable: false,formatter: function (a, b, c) {
+                    var editurl = "{:url('add',[],'')}/id/"+c.id;
+                    var delurl = "{:url('del',[],'')}/id/"+c.id;
+                    var btn = '<a href="'+editurl+'"><span class="label label-info" title="编辑">编辑</span></a>&nbsp;';
+                    btn += '<a href="'+delurl+'" class="confirm ajax-get" data-confirm="确定要删除此记录吗?" data-table="1"><span class="label label-danger" title="删除">删除</span></a>';
+                    return btn;
+                }},
+            ],
+            rowNum:10,
+            rowList:[10,20,30,50,100],
+            pager: '#pager',
+            sortname: 'id',
+            viewrecords: true,
+            autowidth:true,
+            mtype: 'post',
+            height: 'auto',
+            emptyrecords: "暂无数据",
+            sortorder: "desc",
+            caption:"{$meta_title}",
+            loadComplete: function (xhr) {
+                if(xhr.code==0){
+                    layer.msg(xhr.msg);
+                    return false;
+                }
+            },
+        });
+    });
+
+</script>
+{/block}

+ 168 - 0
application/admin/view/wx_orders/details.html

@@ -0,0 +1,168 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-content">
+                <table class="table table-bordered">
+                    <tbody>
+                    <tr>
+                        <th style="width:120px ">订单号</th><td>{$info['order_sn']}</td>
+                    </tr>
+                    <tr>
+                        <th>订单金额</th><td>{$info['amount']}</td>
+                    </tr>
+                    <tr>
+                        <th>收货人</th><td>{$info['name']}</td>
+                    </tr>
+                    <tr>
+                        <th>联系电话</th><td>{$info['phone']}</td>
+                    </tr>
+                    <tr>
+                        <th>详细地址</th><td>{$info['address']}</td>
+                    </tr>
+                    <tr>
+                        <th>创建日期</th><td>{$info['create_time']}</td>
+                    </tr>
+                    {if in_array($info.status,[1,2,3,5])}
+                    <tr>
+                        <th>支付类型</th>
+                        <td>{if $info.pay_type==1}微信支付{/if}</td>
+                    </tr>
+                    <tr>
+                        <th>支付日期</th><td>{$info['pay_time']}</td>
+                    </tr>
+                    {/if}
+                    {if in_array($info.status,[2,3,5])}
+                    <tr>
+                        <th>发货日期</th><td>{$info['send_time']}</td>
+                    </tr>
+                    {/if}
+                    {if in_array($info.status,[3,5])}
+                    <tr>
+                        <th>完成日期</th><td>{$info['finish_time']}</td>
+                    </tr>
+                    {/if}
+                    {if $info.status==4}
+                    <tr>
+                        <th>取消日期</th><td>{$info['cancel_time']}</td>
+                    </tr>
+                    {/if}
+                    <!--<tr>-->
+                        <!--<th>送达时间</th>-->
+                        <!--<td>{$info.delivery_date}</td>-->
+                    <!--</tr>-->
+                    <tr>
+                        <th>配送类型</th>
+                        <td>{if $info.delivery_type==1}商家配送{/if}</td>
+                    </tr>
+                    <tr>
+                        <th>订单备注</th>
+                        <td>{$info.order_remark}</td>
+                    </tr>
+                    <tr>
+                        <th>状态</th>
+                        <td>{$info.status_name}</td>
+                    </tr>
+
+                    <tr>
+                        <th>订单类型</th>
+                        {if $info.order_type==0}
+                        <td>普通订单</td>
+                        {else}
+                        <td>桶装水订单</td>
+                        {/if}
+                    </tr>
+                    {if $info.order_type==1}
+                    {if $info.is_has_barrel==0}
+                    <tr>
+                        <th>是否有空桶</th>
+                        <td>没有</td>
+                    </tr>
+                    <tr>
+                        <th>押金</th>
+                        <td>{$info.cash_price}</td>
+                    </tr>
+                    <tr>
+                        <th>押金备注</th>
+                        <td>{$info.remark}</td>
+                    </tr>
+                    {else}
+                    <tr>
+                        <th>是否有空桶</th>
+                        <td>有</td>
+                    </tr>
+                    {/if}
+                    {/if}
+                    {if $info['is_can_refund']==1}
+                    <tr>
+                        <th>操作</th><td><a href="javascript:;" url="{:url('WxOrdersRefund/goodsRefund',['id'=>$info['id'],'type'=>1])}" data-title="退款" onclick="layer_open(this,2)" class="btn btn-xs btn-danger">申请退款</a>
+                    </td>
+                    </tr>
+                    {/if}
+                    </tbody>
+                </table>
+            </div>
+            {if $info.status==5}
+            <div class="ibox-content">
+
+                <table class="table table-bordered">
+                    <thead>
+                    <tr>
+                        <th>分值</th>
+                        <th>评价内容</th>
+                        <th>评价时间</th>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    <tr>
+                        <td>{$info['comment']['score']}</td>
+                        <td>{$info['comment']['content']}</td>
+                        <td>{$info['comment']['create_time']}</td>
+                    </tr>
+
+                    </tbody>
+                </table>
+            </div>
+            {/if}
+            <div class="ibox-content">
+
+                <table class="table table-bordered">
+                    <thead>
+                    <tr>
+                        <th>图片</th>
+                        <th>商品名称</th>
+                        <th>价格</th>
+                        <th>购买数量</th>
+                        <th>售后状态</th>
+                        <th>操作</th>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    {volist name="info['goods']" id='v'}
+                    <tr>
+                        <td><img src="{$v['img']}" alt="" onclick="open_img(this)" style="width: 40px;"  ></td>
+                        <td>{$v['title']}</td>
+                        <td>{$v['price']}</td>
+                        <td>{$v['num']}</td>
+                        <td>{if $v['is_refund'] >1}
+                            <a href="javascript:;" url="{:url('WxOrdersRefund/details',['id'=>$info['id'],'goodsId'=>$v['goods_id'],'type'=>0])}" data-title="售后详情" onclick="layer_open(this,2)" class="btn btn-xs {if $v.is_refund==3} btn-danger {else}btn-success {/if} " >{$v['refund_status_name']}</a>
+                            {else}
+                            暂无售后
+                            {/if}</td>
+                        <td>
+                            {if $v['is_refund'] ==1}
+                            <a href="javascript:;" url="{:url('WxOrdersRefund/goodsRefund',['id'=>$info['id'],'goodsId'=>$v['goods_id']])}" data-title="申请退款" onclick="layer_open(this,2)" class="btn btn-xs btn-danger">申请退款</a>
+                            {/if}
+                        </td>
+                    </tr>
+                    {/volist}
+                    </tbody>
+                </table>
+
+            </div>
+
+        </div>
+    </div>
+</div>
+{/block}

+ 158 - 0
application/admin/view/wx_orders/index.html

@@ -0,0 +1,158 @@
+{extend name="common/common2" /}
+{block name="main"}
+
+<div class="ibox">
+    <div class="ibox-content">
+        <div class="row">
+            <div class="col-xs-12" style="text-align: right;">
+                <form class="form-inline" id="form-search" action="{:url('index')}">
+                    <div class="input-group">
+                        <select name="cate_id" class="form-control">
+                            <option value="">选择分类</option>
+                            {foreach $cate as $k=>$v}
+                            <option value="{$v.id}">{$v.title}</option>
+                            {/foreach}
+                        </select>
+                    </div>
+                    <div class="input-group">
+                        <input type="text" id="date" readonly class="form-control" name="begin" placeholder="开始日期">
+                    </div>
+                    <div class="input-group">
+                        <input type="text" id="date1" readonly class="form-control" name="end" placeholder="结束日期">
+                    </div>
+                    <div class="input-group">
+                        <input type="text" class="form-control" style="width: 180px;"  name="order_sn" placeholder="订单号">
+                    </div>
+
+                    <div class="input-group">
+                        <input type="text" class="form-control" style="width: 150px;"  name="name" placeholder="收货人姓名">
+                    </div>
+                    <div class="input-group">
+                        <select name="status" class="form-control">
+                            <option value="">选择状态</option>
+                            {foreach $status as $k=>$v}
+                            <option value="{$k}">{$v}</option>
+                            {/foreach}
+                            <option value="99">已退款</option>
+                        </select>
+                    </div>
+<!--                    <div class="input-group">-->
+<!--                        <select name="order_type" class="form-control">-->
+<!--                            <option value="">订单类型</option>-->
+<!--                            <option value="0">普通订单</option>-->
+<!--                            <option value="1">桶装水订单</option>-->
+<!--                        </select>-->
+<!--                    </div>-->
+                    <div class="input-group">
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
+                        </span>
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary " type="button" id="search-clear"><i class="fa fa-undo"></i></button>
+                        </span>
+                    </div>
+                </form>
+            </div>
+        </div>
+
+    </div>
+    <div class="ibox-content">
+        <div class="jqGrid_wrapper">
+            <table id="table" style="border-collapse: collapse"></table>
+            <div id="pager"></div>
+        </div>
+    </div>
+</div>
+<script src="/static/layDate-v5.0.9/laydate.js"></script>
+
+{/block}
+
+{block name="script"}
+<script>
+    laydate.render({
+        elem: '#date',
+        //设置开始日期、日期日期的 input 选择器
+        //数组格式为 5.3.0 开始新增,之前版本直接配置 true 或任意分割字符即可
+        trigger: 'click' ,
+        theme: '#ffaa2d'
+    });
+    laydate.render({
+        elem: '#date1',
+        //设置开始日期、日期日期的 input 选择器
+        //数组格式为 5.3.0 开始新增,之前版本直接配置 true 或任意分割字符即可
+        trigger: 'click' ,
+        theme: '#ffaa2d'
+    });
+    $(function () {
+
+        $(window).bind("resize",function(){
+            var width=$(".jqGrid_wrapper").width();
+            $("#table").setGridWidth(width);
+        });
+
+        $.jgrid.defaults.styleUI="Bootstrap";
+        $("#table").jqGrid({
+            url:"{:url('index')}",
+            datatype: "json",
+            colModel:[
+                {label:'#',name:'id',index:'id', width:30,sortable: false},
+                {label:'订单号',name:'order_sn',index:'order_sn', width:80,sortable: false},
+                {label:'订单金额',name:'amount',index:'amount', width:40,sortable: false},
+                {label:'收货人',name:'name',index:'name', width:60,sortable: false},
+                {label:'联系方式',name:'phone',index:'phone', width:60,sortable: false},
+                {label:'状态',name:'status_name',index:'status_name',width:80,editable: false,sortable: false,formatter:function (a,b,c){
+                        return '<span title="'+a+'">'+a+'</span>';
+
+                    }},
+                // {label:'订单类型',name:'order_type',status:'order_type',width:30,editable: false,sortable: false,formatter:function (a,b,c){
+                //         if(a == 0){
+                //             return '<span title="普通订单">普通订单</span>';
+                //         }
+                //         if(a == 1){
+                //             return '<span title="桶装水订单">桶装水订单</span>';
+                //         }
+                //     }},
+                // {label:'押金',name:'cash_price',index:'cash_price', width:70,sortable: false},
+                // {label:'押金备注',name:'remark',index:'remark', width:70,sortable: false},
+                {label:'订单备注',name:'order_remark',index:'order_remark', width:70,sortable: false},
+                {label:'退款金额',name:'refund_money',index:'refund_money', width:70,sortable: false},
+
+                {label:'创建时间',name:'create_time',index:'create_time', width:70,sortable: false},
+
+                {label:'操作',width:100,sortable: false,formatter: function (a, b, c) {
+                        var detailsurl = "{:url('details',[],'')}/id/"+c.id;
+                        var send = "{:url('send',[],'')}/id/"+c.id;
+                        var btn = '<a url="'+detailsurl+'" href="javascript:;" data-title="详情" onclick="layer_open(this,1)"><span class="label label-info" title="详情">详情</span></a>&nbsp;';
+                        if(c.status==1 && c.checkOrderSend==0 ||c.checkOrderSend==1){
+                              btn += '<a href="'+send+'" class="confirm ajax-get" data-confirm="确定要发货吗?" data-table="1"><span class="label label-danger" title="发货">发货</span></a>';
+
+                          }
+                         return btn;
+                    }},
+            ],
+            rowNum:10,
+            rowList:[10,20,30,50,100],
+            pager: '#pager',
+            sortname: 'id',
+            viewrecords: true,
+            autowidth:true,
+            mtype: 'post',
+            height: 'auto',
+            emptyrecords: "暂无数据",
+            sortorder: "desc",
+            caption:"{$meta_title}",
+            loadComplete: function (xhr) {
+                if(xhr.code==0){
+                    layer.msg(xhr.msg);
+                    return false;
+                }
+                var yzf = xhr.yzf;
+                var ytk = xhr.ytk;
+                $('#pager_left').html('<span style="color:red;font-size: 10px;">已支付金额:'+yzf+' 元 <span style="color:red;font-size: 10px;">已退款金额:'+ytk+'元');
+
+            },
+        });
+    });
+
+</script>
+{/block}

+ 69 - 0
application/admin/view/wx_orders_refund/details.html

@@ -0,0 +1,69 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+
+            <div class="ibox-content">
+                <table class="table table-bordered">
+                    <tbody>
+                    <tr>
+                        <th style="width:120px ">订单号</th><td>{$info['order_sn']}</td>
+                    </tr>
+                    <tr>
+                        <th>申请退款金额</th><td>{$info['amount']}</td>
+                    </tr>
+                    <tr>
+                        <th>申请人</th><td>{$info['user_name']}</td>
+                    </tr>
+                    <tr>
+                        <th>申请原因</th><td>{$info['reason']}</td>
+                    </tr>
+                    <tr>
+                        <th>时间</th><td>{$info['create_time']}</td>
+                    </tr>
+                   {if $info.status >0}
+                    <tr>
+                        <th>处理人</th><td>{$info['deal_user_name']}</td>
+                    </tr>
+                    <tr>
+                        <th>处理时间</th><td>{$info['deal_time']}</td>
+                    </tr>
+                    {/if}
+                    </tbody>
+                </table>
+            </div>
+            <div class="ibox-content">
+
+                <table class="table table-bordered">
+                    <thead>
+                    <tr>
+                        <th>图片</th>
+                        <th>商品名称</th>
+                        <th>价格</th>
+                        <th>退款数量</th>
+                        <th>实际退款金额</th>
+                        <th>备注</th>
+                        <th>状态</th>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    <tr>
+                        <td><img src="{$info['goods']['img']}" alt="" onclick="open_img(this)" style="width: 40px;"  ></td>
+                        <td>{$info['goods']['title']}</td>
+                        <td>{$info['goods']['price']}</td>
+                        <td>{$info['goods']['num']}</td>
+                        <td>{$info['money']}</td>
+                        <td>{$info['remark']}</td>
+                        <td>{$info['statusName']}</td>
+
+                    </tr>
+                    </tbody>
+                </table>
+
+            </div>
+
+        </div>
+    </div>
+</div>
+{/block}

+ 60 - 0
application/admin/view/wx_orders_refund/goods_refund.html

@@ -0,0 +1,60 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-content">
+                <form method="post" action="{:url('goodsRefund',[],'')}/id/{$id}" class="form-horizontal">
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">退款商品 <span style="color: red;">*</span></label>
+                        <div class="col-sm-6">
+                            <table class="table table-bordered">
+                                <thead>
+                                <tr>
+                                    <th>图片</th>
+                                    <th>商品名称</th>
+                                    <th>价格</th>
+                                    <th>退款数量</th>
+                                </tr>
+                                </thead>
+                                <tbody>
+                                {volist name="info" id='v'}
+                                <tr>
+                                    <td><img src="{$v['img']}" alt="" onclick="open_img(this)" style="width: 40px;"  ></td>
+                                    <td>{$v['title']}</td>
+                                    <td>{$v['price']}</td>
+                                    <td><input type="text" name="num[{$v['goods_id']}]" value="{$v.num}"></td>
+
+                                </tr>
+                                {/volist}
+                                </tbody>
+                            </table>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">退款原因</label>
+                        <div class="col-sm-6">
+                            <textarea name="reason" class="form-control"></textarea>
+                        </div>
+                    </div>
+                    <div class="hr-line-dashed"></div>
+                    <div class="form-group">
+                        <div class="col-sm-4 col-sm-offset-2">
+                            <button class="btn btn-primary ajax-post" data-layer="1" target-form="form-horizontal" type="submit">确 定</button>
+                            <button  class="btn cancel-btn btn-default" type="button">取 消</button>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(document).ready(function(){
+    });
+
+</script>
+{/block}

+ 136 - 0
application/admin/view/wx_orders_refund/index.html

@@ -0,0 +1,136 @@
+{extend name="common/common2" /}
+{block name="main"}
+
+<div class="ibox">
+    <div class="ibox-content">
+        <div class="row">
+
+            <div class="col-xs-12" style="text-align: right;">
+                <form class="form-inline" id="form-search" action="{:url('index')}">
+                    <div class="input-group">
+                        <select name="cate_id" class="form-control">
+                            <option value="">选择分类</option>
+                            {foreach $cate as $k=>$v}
+                            <option value="{$v.id}">{$v.title}</option>
+                            {/foreach}
+                        </select>
+                    </div>
+                    <div class="input-group">
+                        <input type="text" id="date" readonly class="form-control" name="begin" placeholder="开始日期">
+                    </div>
+                    <div class="input-group">
+                        <input type="text" id="date1" readonly class="form-control" name="end" placeholder="结束日期">
+                    </div>
+                    <div class="input-group">
+                        <input type="text" class="form-control" style="width: 180px;"  name="order_sn" placeholder="订单号">
+                    </div>
+                    <div class="input-group">
+                        <select name="status" class="form-control">
+                            <option value="">选择状态</option>
+                            {foreach $status as $k=>$v}
+                            <option value="{$k}">{$v}</option>
+                            {/foreach}
+                        </select>
+                    </div>
+                    <div class="input-group">
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
+                        </span>
+                        <span class="input-group-btn">
+                            <button class="btn-sm btn-primary " type="button" id="search-clear"><i class="fa fa-undo"></i></button>
+                        </span>
+                    </div>
+                </form>
+            </div>
+        </div>
+
+    </div>
+    <div class="ibox-content">
+        <div class="jqGrid_wrapper">
+            <table id="table" style="border-collapse: collapse"></table>
+            <div id="pager"></div>
+        </div>
+    </div>
+</div>
+<script src="/static/layDate-v5.0.9/laydate.js"></script>
+
+{/block}
+
+{block name="script"}
+<script>
+    laydate.render({
+        elem: '#date',
+        //设置开始日期、日期日期的 input 选择器
+        //数组格式为 5.3.0 开始新增,之前版本直接配置 true 或任意分割字符即可
+        trigger: 'click' ,
+        theme: '#ffaa2d'
+    });
+    laydate.render({
+        elem: '#date1',
+        //设置开始日期、日期日期的 input 选择器
+        //数组格式为 5.3.0 开始新增,之前版本直接配置 true 或任意分割字符即可
+        trigger: 'click' ,
+        theme: '#ffaa2d'
+    });
+    $(function () {
+
+        $(window).bind("resize",function(){
+            var width=$(".jqGrid_wrapper").width();
+            $("#table").setGridWidth(width);
+        });
+
+        $.jgrid.defaults.styleUI="Bootstrap";
+        $("#table").jqGrid({
+            url:"{:url('index')}",
+            datatype: "json",
+            colModel:[
+                {label:'#',name:'id',index:'id', width:30,sortable: false},
+                {label:'订单号',name:'order_sn',index:'order_sn', width:80,sortable: false},
+                {label:'申请退款金额',name:'amount',index:'amount', width:80,sortable: false},
+                {label:'实际退款金额',name:'money',index:'money', width:80,sortable: false},
+                {label:'申请人',name:'user_name',index:'userName', width:80,sortable: false},
+                {label:'商品',name:'goods_name',index:'goods_name', width:80,sortable: false},
+                {label:'数量',name:'num',index:'num', width:80,sortable: false},
+                {label:'申请原因',name:'reason',index:'reason', width:80,sortable: false},
+                {label:'备注',name:'remark',index:'remark', width:80,sortable: false},
+                {label:'状态',name:'status_name',index:'status_name',width:80,editable: false,sortable: false,formatter:function (a,b,c){
+                        return '<span title="'+a+'">'+a+'</span>';
+
+                    }},
+
+
+                {label:'时间',name:'create_time',index:'create_time', width:120,sortable: false},
+
+                {label:'操作',width:100,sortable: false,formatter: function (a, b, c) {
+                        var detailsurl = "{:url('details',[],'')}/id/"+c.order_id+'/goodsId/'+c.goods_id;
+                        var option = "{:url('option',[],'')}/id/"+c.id;
+                        var btn = '<a data-title="详情" onclick="layer_open(this,1)" href="javascript:;" url="'+detailsurl+'"><span class="label label-info" title="详情">详情</span></a>&nbsp;';
+                        if(c.status==0){
+                             btn+= '<a data-title="审核" onclick="layer_open(this,1)" href="javascript:;" url="'+option+'"><span class="label label-success" title="审核">审核</span></a>&nbsp;';
+                        }
+                        return btn;
+                    }},
+            ],
+            rowNum:10,
+            rowList:[10,20,30,50,100],
+            pager: '#pager',
+            sortname: 'id',
+            viewrecords: true,
+            autowidth:true,
+            mtype: 'post',
+            height: 'auto',
+            emptyrecords: "暂无数据",
+            sortorder: "desc",
+            caption:"{$meta_title}",
+            loadComplete: function (xhr) {
+                if(xhr.code==0){
+                    layer.msg(xhr.msg);
+                    return false;
+                }
+
+            },
+        });
+    });
+
+</script>
+{/block}

+ 63 - 0
application/admin/view/wx_orders_refund/option.html

@@ -0,0 +1,63 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-content">
+                <form method="post" action="{:url('option')}" class="form-horizontal">
+                    <input type="hidden" name="id" value="{$id}">
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">申请退款金额</label>
+                        <div class="col-sm-6">
+                            <input type="text" readonly class="form-control" value="{$money}">
+                        </div>
+                    </div>
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">退款金额 <span style="color: red;">*</span></label>
+                        <div class="col-sm-6">
+                            <input type="text" class="form-control" name="money" value="{$money}">
+                        </div>
+                    </div>
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">备注</label>
+                        <div class="col-sm-6">
+                            <textarea name="remark" class="form-control"></textarea>
+                        </div>
+                    </div>
+
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">状态</label>
+                        <div class="col-sm-6">
+                            <label class="cr-inline">
+                                <input type="radio" value="1" name="status">退款同意&nbsp;&nbsp;
+                            </label>
+                            <label class="cr-inline">
+                                <input type="radio" value="2" name="status">退款拒绝
+                            </label>
+                        </div>
+                    </div>
+                    <div class="hr-line-dashed"></div>
+                    <div class="form-group">
+                        <div class="col-sm-4 col-sm-offset-2">
+                            <button class="btn btn-primary ajax-post" data-layer="1" target-form="form-horizontal" type="submit">确 定</button>
+                            <button  class="btn cancel-btn btn-default" type="button">取 消</button>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(document).ready(function(){
+        formSetValue("status", 1);
+    });
+
+</script>
+{/block}

+ 78 - 0
application/api/controller/h5/WxCart.php

@@ -0,0 +1,78 @@
+<?php
+namespace app\api\controller\h5;
+
+use app\hander\HelpHander;
+use think\App;
+use think\Db;
+use app\api\controller\Base;
+
+class WxCart extends Base
+{
+
+   public function __construct(App $app = null) {
+       parent::__construct($app);
+//       $this->orgId = 3;
+
+   }
+    public function getCartNum(){
+        $num = Db::name('wx_goods_cart')
+            ->alias('a')
+            ->join('wx_goods b','a.goods_id=b.id')
+            ->where('a.user_id',$this->userId)
+            ->where('b.del',0)
+            ->where('b.org_id',$this->orgId)
+            ->sum('a.nums');
+        HelpHander::success(['num'=>$num],'操作成功');
+    }
+     //添加购物车
+    public function addCart(){
+        $goodsId=input('goodsId/d',0);
+        $ret = model('WxCart')->add($goodsId,$this->userId);
+        if(!$ret){
+            HelpHander::error(model('WxCart')->getError());
+        }
+        HelpHander::success([],'添加成功');
+    }
+    //购物车列表
+    public function cartList(){
+        $ret = model('WxCart')->lists($this->userId,$this->orgId);
+        HelpHander::success($ret);
+    }
+    //修改购物车数量
+    public function updateNum(){
+        $id=input('id/d',0);
+        $nums=input('nums/d',0);
+        $ret = model('WxCart')->updateNum($id,$nums);
+        if($ret){
+            HelpHander::success([],'操作成功');
+        }else{
+            HelpHander::error('失败');
+        }
+    }
+    //购物车加减
+    public function setCartNum(){
+        $id=input('id/d',0);
+        $nums=input('nums/d',1);
+        $type=input('type/d',0);
+        $ret = model('WxCart')->setCartNum($this->userId,$id,$type,$nums);
+        if($ret){
+            HelpHander::success([],'操作成功');
+        }else{
+            HelpHander::error('操作失败');
+        }
+    }
+    //购物车删除
+    public function cartDel(){
+        $id = input('id','');
+        if($id == ''){
+            HelpHander::error('请选择商品');
+        }
+        $id = explode(',',$id);
+        $ret = Db::name('wx_goods_cart')->whereIn('id',$id)->delete();
+        if($ret){
+            HelpHander::success([],'操作成功');
+        }else{
+            HelpHander::error('操作失败');
+        }
+    }
+}

+ 221 - 0
application/api/controller/h5/WxGoods.php

@@ -0,0 +1,221 @@
+<?php
+namespace app\api\controller\h5;
+
+use app\hander\HelpHander;
+use think\App;
+use think\Db;
+use app\api\controller\Base;
+
+class WxGoods extends Base
+{
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+//        $this->orgId = 3;
+
+    }
+    public function getUser(){
+        $user =Db::name('wxuser')
+            ->where('id',$this->userId)
+            ->field('id,nickname,img,phone')
+            ->find();
+        $map[] = ['user_id','=',$this->userId];
+        $map[] = ['org_id','=',$this->orgId];
+        $map[] = ['del','=',0];
+        $dfk = Db::name('wx_orders')
+            ->where($map)
+            ->where('status',0)
+            ->count();
+        $map1 = [];
+        $ids = Db::name('wx_orders_refund')
+            ->where('org_id',$this->orgId)
+            ->where('user_id',$this->userId)
+            ->where('del',0)
+            ->column('order_id');
+        if(!empty($ids)){
+            $map1[]=['id','not in',$ids];
+        }
+        $dfh = Db::name('wx_orders')
+            ->where($map)
+            ->where($map1)
+            ->where('status',1)
+            ->count();
+
+        $dsh = Db::name('wx_orders')
+            ->where($map)
+            ->where('status',2)
+            ->count();
+        $th = Db::name('wx_orders_refund')
+            ->where('user_id',$this->userId)
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->group('order_id')
+            ->count();
+        $user['dfk'] = $dfk;
+        $user['dfh'] = $dfh;
+        $user['dsh'] = $dsh;
+        $user['th'] = $th;
+        HelpHander::success($user);
+    }
+    public function getPhone(){
+        $res = (new \app\common\model\Config())
+            ->getConfig('org_wx_shop_phone',$this->orgId);
+        HelpHander::success($res?$res:'');
+    }
+    public function getBanner(){
+        $ret = model('Banner')->getList(5,3);
+        HelpHander::success($ret);
+    }
+    public function getIndex(){
+        $data = [
+//            'phone'=>(new \app\common\model\Config())
+//                ->getConfig('org_wx_shop_phone',$this->orgId),
+//            'banner'=>model('Banner')->getList(5,3),
+//            'notice'=>model('WxNotice')->getOne($this->orgId),
+//            'orgName'=>Db::name('org')
+//            ->where('id',$this->orgId)->value('name'),
+            'phone'=>(new \app\common\model\Config())
+                ->getConfig('org_phone',$this->orgId),
+        ];
+        HelpHander::success($data);
+    }
+    public function getTjGoods(){
+        $ret = model('WxGoods')->getTjGoods($this->orgId);
+        HelpHander::success($ret);
+    }
+    public function getIndexGoods(){
+        $ret = model('WxGoods')->getIndexGoods($this->orgId);
+        HelpHander::success($ret);
+    }
+    public function getTjGoodsList(){
+        $page = input('page/d',1);
+        $size = input('size/d',20);
+        $ret = model('WxGoods')->getTjGoodsList($this->orgId,$page,$size);
+        HelpHander::success($ret);
+    }
+    public function getIndexGoodsList(){
+        $keywords=input('keywords','','trim');
+        $page = input('page/d',1);
+        $size = input('size/d',20);
+        $type = input('type/d',0);
+        $sort=input('sortName','sale');
+        $asc=input('sortAsc','desc');
+        $ret = model('WxGoods')->getIndexGoodsList($this->orgId,$page,$size,$type,$sort,$asc,$keywords);
+        HelpHander::success($ret);
+    }
+
+    public function getCateList(){
+        $list = model('WxGoodsCate')->lists($this->orgId);
+        HelpHander::success($list);
+    }
+    public function getCateInfo(){
+        $id = input('id/d',0);
+        $info = Db::name('wx_goods_cate')
+            ->field('id,title,is_water,path')
+            ->where(['id'=>$id])->find();
+        HelpHander::success($info);
+    }
+
+    public function cateGoodsList(){
+        $keywords=input('keywords','','trim');
+        $cateId=input('cateId/d',0);
+        $sort=input('sortName','sale');
+        $asc=input('sortAsc','desc');
+        $ret = model('WxGoods')->cateGoodsList($this->userId,$this->orgId,$cateId,$keywords,$sort,$asc);
+        HelpHander::success($ret);
+
+    }
+
+    public function setGoodsNum(){
+        $id=input('goodsId/d',0);
+        $nums=input('nums/d',1);
+        $type=input('type/d',0);
+        if(empty($id)){
+            HelpHander::error('参数错误');
+        }
+        $ret = model('WxCart')->setGoodsNum($this->userId,$id,$type,$nums);
+        if($ret){
+            HelpHander::success([],'操作成功');
+        }else{
+            HelpHander::error('操作失败');
+        }
+    }
+    public function goodsFav(){
+        $id=input('goodsId/d',0);
+        if(empty($id)){
+            HelpHander::error('参数错误');
+        }
+        $ret = model('WxCart')->goodsFav($this->userId,$id);
+        if($ret){
+            $msg = $ret['type']==0?'取消成功':'收藏成功';
+            if(!$ret['ret']){
+                $msg = $ret['type']==0?'取消失败':'收藏失败';
+                HelpHander::error($msg);
+            }
+            HelpHander::success([],$msg);
+        }else{
+            HelpHander::error('操作失败');
+        }
+    }
+    public function favGoodsList(){
+        $page = input('page/d',1);
+        $size = input('size/d',20);
+        $ret = model('WxGoods')->favGoodsList($this->userId,$this->orgId,$page,$size);
+        HelpHander::success($ret);
+    }
+
+    public function noticeList(){
+        $page = input('page/d',1);
+        $size = input('size/d',20);
+        $list = Db::name('wx_notice')
+            ->field('id,title,content,create_time')
+            ->where('del',0)
+            ->where('org_id',$this->orgId)
+            ->order(['id'=>'desc'])
+            ->page($page,$size)
+            ->select();
+        HelpHander::success($list);
+    }
+    public function noticeDetail(){
+        $id = input('id/d',0);
+        $list = Db::name('wx_notice')
+            ->field('id,title,content,create_time,user_id')
+            ->where('del',0)
+            ->where('id',$id)
+            ->where('org_id',$this->orgId)
+            ->find();
+        $list['create_date'] = date('Y-m-d',strtotime($list['create_time']));
+        $list['user_name'] = Db::name('user')
+            ->where('id',$list['user_id'])
+            ->value('real_name');
+        HelpHander::success($list);
+    }
+
+    public function goodsDetail(){
+        $id = input('id/d',0);
+        $info = model('WxGoods')->details($id,$this->userId);
+        $info?HelpHander::success($info):HelpHander::error('商品信息不存在');
+    }
+    public function barrelList(){
+        $page = input('page/d',1);
+        $size = input('size/d',20);
+        $ret = model('WxGoods')->barrelList($this->orgId,$page,$size);
+        HelpHander::success($ret);
+
+    }
+    public function myBarrelList(){
+        $page = input('page/d',1);
+        $size = input('size/d',20);
+        $ret = model('WxGoods')->myBarrelList($this->orgId,$this->userId,$page,$size);
+        HelpHander::success($ret);
+
+    }
+    public function myRefundBarrelList(){
+        $page = input('page/d',1);
+        $size = input('size/d',20);
+        $ret = model('WxGoods')->myRefundBarrelList($this->orgId,$this->userId,$page,$size);
+        HelpHander::success($ret);
+
+    }
+
+}
+

+ 488 - 0
application/api/controller/h5/WxOrders.php

@@ -0,0 +1,488 @@
+<?php
+namespace app\api\controller\h5;
+
+use app\hander\HelpHander;
+
+use EasyWeChat\Factory;
+use think\App;
+use think\Db;
+use think\Exception;
+use app\api\controller\Base;
+
+class WxOrders extends Base
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+//        $this->orgId = 3;
+
+
+    }
+    //订单结算页详情
+    public function checkOrderDetail(){
+        $type = input('type/d',0);
+        $goodsId = input('goodsId/d',0);
+        $cartId = input('cartId','');
+        $num = input('num/d',0);
+        $ids = [];
+        if($type==0){
+            if(empty($goodsId) || empty($num)){
+                HelpHander::error('参数错误');
+            }
+            $ids[] = ['id'=>$goodsId,'num'=>$num];
+        }else if($type==1){
+            if(empty($cartId)){
+                HelpHander::error('参数错误');
+            }
+            $gId = Db::name('wx_goods_cart')
+                ->where('id','in',explode(',',$cartId))
+                ->where('user_id',$this->userId)
+                ->group('goods_id')
+                ->select();
+
+            foreach ($gId as $k=>$v){
+                $ids[] = [
+                    'id'=>$v['goods_id'],
+                    'num'=>$v['nums'],
+                ];
+            }
+        }
+        $data = model('WxOrders')->formatOrder($ids);
+        HelpHander::success($data,'操作成功');
+    }
+
+    public function create(){
+        $type = input('type/d',0);
+        $goodsId = input('goodsId/d',0);
+        $cartId = input('cartId','');
+        $addressId=input('addressId/d',0);
+        $isHasBarrel=input('isHasBarrel/d',0);
+        $deliveryDate=input('deliveryDate','');
+        $deliveryType=input('deliveryType/d',1);
+        $orderRemark=input('orderRemark','');
+        $payType=input('payType/d',1);
+        $num = input('num/d',0);
+        if($this->orgId <= 0){
+            HelpHander::error('参数错误');
+        }
+        $ret = model('WxOrders')->add($cartId,$addressId,$this->userId,$this->orgId,$type,$goodsId,$isHasBarrel,$deliveryDate,$deliveryType,$orderRemark,$payType,$num);
+        if(!$ret){
+            HelpHander::error(model('WxOrders')->getError());
+        }
+        HelpHander::success(['id'=>$ret],'操作成功');
+    }
+
+
+
+    //商城订单列表
+    public function orderList(){
+        $status=input('status/d',0);
+        $page=input('page/d',1);
+        $size=input('size/d',20);
+        $ret = model('WxOrders')->lists($page,$size,$this->userId,$this->orgId,$status);
+        HelpHander::success($ret);
+    }
+
+    //订单详情
+    public function orderDetails(){
+        $orderId=input('orderId/d',0);
+        $ret = model('WxOrders')->details($orderId);
+        HelpHander::success($ret);
+    }
+
+    //取消订单
+    public function cancelOrder(){
+        $id = input('id',0);
+        $info = Db::name('wx_orders')
+            ->where('id',$id)
+            ->where('user_id',$this->userId)
+            ->find();
+        if(empty($info)){
+            HelpHander::error('订单不存在');
+        }
+        if($info['status']!=0){
+            HelpHander::error('订单已取消');
+        }
+        $data = [
+            'status'=>4,
+            'cancel_time'=>date('Y-m-d H:i:s')
+        ];
+        $ret = Db::name('wx_orders')->where('id',$id)->update($data);
+        //取消订单添加库存
+//        $orderGoods = Db::name('g_order_goods')
+//            ->where('order_id',$id)
+//            ->select();
+//        foreach ($orderGoods as $k=>$v){
+//            Db::name('g_goods')
+//                ->where('id',$v['goods_id'])
+//                ->inc('stock',$v['nums'])
+//                ->update();
+//        }
+        if($ret){
+            HelpHander::success([],'操作成功');
+        }else{
+            HelpHander::error('操作失败');
+        }
+    }
+    public function confirmOrder(){
+        $id = input('id',0);
+        $info = Db::name('wx_orders')
+            ->where('id',$id)
+            ->where('user_id',$this->userId)
+            ->find();
+        if(empty($info)){
+            HelpHander::error('订单不存在');
+        }
+        if($info['status']!=2){
+            HelpHander::error('订单已确认');
+        }
+        $data = [
+            'status'=>3,
+            'finish_time'=>date('Y-m-d H:i:s')
+        ];
+        $ret = Db::name('wx_orders')->where('id',$id)->update($data);
+
+        if($ret){
+            HelpHander::success([],'操作成功');
+        }else{
+            HelpHander::error('操作失败');
+        }
+    }
+    public function delOrder(){
+        $id = input('id',0);
+        $info = Db::name('wx_orders')
+            ->where('id',$id)
+            ->where('user_id',$this->userId)
+            ->find();
+        if(empty($info)){
+            HelpHander::error('订单不存在');
+        }
+        if(!in_array($info['status'],[4,5,7])){
+            HelpHander::error('订单状态不能删除');
+        }
+        $data = [
+            'del'=>1,
+            'del_time'=>date('Y-m-d H:i:s')
+        ];
+        $ret = Db::name('wx_orders')->where('id',$id)->update($data);
+
+        if($ret){
+            Db::name('wx_orders_refund')->where('order_id',$id)->update([
+                'del'=>1
+            ]);
+            HelpHander::success([],'操作成功');
+        }else{
+            HelpHander::error('操作失败');
+        }
+    }
+    //继续支付
+    public function goPay(){
+        $id = input('id',0);
+        $order = Db::name('wx_orders')
+            ->where('id',$id)
+            ->where('status',0)->find();
+        if(!$order){
+            HelpHander::error('订单不存在');
+        }
+        $config = config('app.wx_mini_config');
+        $notify = request()->domain().'/api/v1/notify/WxOrder';
+        $openid = Db::name('wxuser')->where('id',$this->userId)->value('openid');
+
+        $app = Factory::payment($config);
+
+        $result = $app->order->unify([
+            'body' => '订单-'.$order['order_sn'],
+            'out_trade_no' => $order['order_sn'],
+            'total_fee' => $order['amount']*100,
+            'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
+            'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
+            'openid' => $openid,
+        ]);
+        if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
+            $jssdk = $app->jssdk;
+            $ret = $jssdk->bridgeConfig($result['prepay_id'],false); // 返回数组
+            HelpHander::success($ret,'成功');
+        }else{
+            HelpHander::error($result['err_code_des']);
+        }
+
+    }
+
+    public function refuse(){
+        $id = input('id',0);
+        $order = Db::name('g_orders')->where('id',$id)->find();
+        if(!$order){
+            HelpHander::error('订单不存在');
+        }
+        if($order['status']!=1 || time() > (strtotime($order['create_time'])+(30*24*3600))){
+            HelpHander::error('当前订单不可退款');
+        }
+        $refund_money = input('refundMoney');
+        $refund_remark = input('refundRemark','');
+        if(empty($refund_money) ||$refund_money==0 ){
+            HelpHander::error('请输入退款金额');
+        }
+
+        $data = [
+            'money' =>0,
+            'refund_money' =>$refund_money,
+            'refund_remark' =>$refund_remark,
+            'order_id' => $id,
+            'user_id' => $this->userId,
+            'org_id' => $this->orgId,
+            'sn' => get_unique_id(),
+            'from' =>1,
+            'create_time' => date('Y-m-d H:i:s'),
+        ];
+        $r = Db::name('g_order_refund')
+            ->insertGetId($data);
+        Db::name('g_orders')
+            ->where('id',$id)
+            ->update([
+                'status'=>6
+            ]);
+        if($r){
+            HelpHander::success([],'操作成功');
+        }
+        HelpHander::error('操作失败');
+    }
+
+    public function buyBarrel(){
+        $id = input('id/d',0);
+        $num = input('num/d',1);
+        $ret = model('WxOrders')->buyBarrel($this->orgId,$this->userId,$id,$num);
+        HelpHander::success(['id'=>$ret]);
+    }
+    public function payBarrel(){
+        $id = input('id/d',0);
+        $info = Db::name('wx_cash_pay_log')
+            ->where('id',$id)
+            ->find();
+        if(empty($info)){
+            HelpHander::error('押金支付记录不存在');
+        }
+        if($info['status'] !=0){
+            HelpHander::error('押金已支付');
+        }
+
+        $config = config('app.wx_mini_config');
+        $notify = request()->domain().'/api/v1/notify/cashOrder';
+        $openid = Db::name('wxuser')->where('id',$this->userId)->value('openid');
+
+        $app = Factory::payment($config);
+
+        $result = $app->order->unify([
+            'body' => '订单-'.$info['sn'],
+            'out_trade_no' => $info['sn'],
+            'total_fee' => $info['amount']*100,
+            'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
+            'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
+            'openid' => $openid,
+        ]);
+        if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
+            $jssdk = $app->jssdk;
+            $ret = $jssdk->bridgeConfig($result['prepay_id'],false); // 返回数组
+            HelpHander::success($ret,'成功');
+        }else{
+            HelpHander::error($result['return_msg']);
+        }
+    }
+    public function refundBarrel(){
+        $id = input('id/d',0);
+        $num = input('num/d',1);
+        $ret = model('WxOrders')->refundBarrel($this->orgId,$this->userId,$id,$num);
+        HelpHander::success($ret,'操作成功');
+    }
+
+    public function commentOrder(){
+        $id = input('orderId',0);
+        $info = Db::name('wx_orders')
+            ->where('id',$id)
+            ->where('user_id',$this->userId)
+            ->find();
+        if(empty($info)){
+            HelpHander::error('订单不存在');
+        }
+        if($info['status']!=3){
+            HelpHander::error('该订单不能评价');
+        }
+        $data = [
+            'status'=>5,
+            'finish_time'=>date('Y-m-d H:i:s')
+        ];
+        Db::startTrans();
+        try{
+            $ret = Db::name('wx_orders')->where('id',$id)->update($data);
+            if(!$ret){
+                \exception('操作失败');
+            }
+            $data=[
+                'score'=>input('score',''),
+                'content'=>input('content',''),
+                'user_id'=>$this->userId,
+                'order_id'=>$id,
+                'org_id'=>$this->orgId,
+                'create_time'=>date('Y-m-d H:i:s'),
+                'create_yyyymm'=>date('Ym'),
+                'create_yyyy'=>date('Y'),
+                'create_yyyymmdd'=>date('Ymd'),
+            ];
+            if(!$data['score']){
+                \exception('得分不能为空');
+            }
+            $res = Db::name('wx_comment')->insertGetId($data);
+            if (!$res) {
+                exception('保存失败');
+            }
+            Db::commit();
+            HelpHander::success([],'操作成功');
+
+        }catch (Exception $e){
+            Db::rollback();
+            HelpHander::error($e->getMessage());
+        }
+    }
+    public function commentDetail(){
+        $id = input('orderId',0);
+        $info = Db::name('wx_comment')
+            ->field('create_yyyy,create_yyyymm,create_yyyymmdd',true)
+            ->where('order_id',$id)
+            ->find();
+        if(empty($info)){
+            HelpHander::error('评价不存在');
+        }
+        HelpHander::success($info,'操作成功');
+
+    }
+    public function checkoutApplyRefund(){
+        $type = input('type/d',0);
+        $orderId = input('orderId/d',0);
+        $goodsId = input('goodsId/d',0);
+        $ret = model('WxOrders')->checkoutApplyRefund($this->userId,$this->orgId,$type,$orderId,$goodsId);
+        $ret?HelpHander::success($ret,'操作成功'):HelpHander::error(model('WxOrders')->getError());
+    }
+    public function checkoutApplyRefund1(){
+        $orderId = input('orderId/d',0);
+        $goodsId = input('goodsId','');
+        $ret = model('WxOrders')->checkoutApplyRefund1($orderId,$goodsId);
+        $ret?HelpHander::success($ret,'操作成功'):HelpHander::error(model('WxOrders')->getError());
+    }
+    public function addApplyRefund(){
+        $goodsJson = input('goodsJson','');
+        $orderId = input('orderId/d',0);
+        $remark = input('reason','');
+        $ret = model('WxOrders')->addApplyRefund($this->userId,$this->orgId,$goodsJson,$orderId,$remark);
+        $ret?HelpHander::success($ret,'操作成功'):HelpHander::error(model('WxOrders')->getError());
+    }
+    public function orderRefundDetail(){
+        $orderId = input('orderId/d',0);
+        $goodsId = input('goodsId','');
+        $ret = model('WxOrders')->orderRefundDetail($this->orgId,$orderId,$goodsId);
+        HelpHander::success($ret,'操作成功');
+
+    }
+    public function goodsRefundDetail(){
+        $orderId = input('orderId/d',0);
+        $goodsId = input('goodsId/d',0);
+        $ret = model('WxOrders')->goodsRefundDetail($this->orgId,$orderId,$goodsId);
+        HelpHander::success($ret,'操作成功');
+
+    }
+    public function rBuy(){
+        $orderId =input('orderId/d',0);
+        $goods_id = Db::name('wx_orders_goods')
+            ->where('order_id', $orderId)
+            ->column('goods_id');
+        foreach ($goods_id as $k=>$v){
+            $check = Db::name('wx_goods_cart')
+                ->where('user_id',$this->userId)
+                ->where('goods_id',$v)
+                ->find();
+            if(empty($check)){
+                $data=[
+                    'user_id'=>$this->userId,
+                    'goods_id'=>$v,
+                    'nums'=>1,
+                    'create_time'=>date('Y-m-d H:i:s'),
+                ];
+                Db::name('wx_goods_cart')->insert($data);
+            }
+
+        }
+        HelpHander::success([],'操作成功');
+    }
+
+    public function checkRefundNum(){
+        $orderId = input('orderId/d',0);
+        $goodsId = input('goodsId/d',0);
+        $num = input('num/d',0);
+        $goodsList = Db::name('wx_orders_goods')
+            ->alias('og')
+            ->field('og.nums as num,og.price,og.goods_id,g.title,g.img,g.label')
+            ->join('wx_goods g', 'g.id=og.goods_id')
+            ->where('og.order_id', $orderId)
+            ->where('og.goods_id', $goodsId)
+            ->find();
+        if($goodsList['num'] <$num){
+            HelpHander::error('退款数量不能超过购买数量',1,['num'=>$goodsList['num']]);
+        }
+        HelpHander::success(['num'=>$num],'可以退款');
+    }
+
+
+    public function checkRefundChangeNum(){
+        $type = input('type/d',0);
+        $orderId = input('orderId/d',0);
+        $goodsId = input('goodsId/d',0);
+        $nums = input('nums',0);
+        if(empty($orderId)){
+            HelpHander::error('参数错误');
+        }
+        if($type==0 && empty($goodsId)){
+            HelpHander::error('参数错误');
+        }
+        if($type==0){
+            $goodsList = Db::name('wx_orders_goods')
+                ->alias('og')
+                ->field('og.nums as num,og.price,og.goods_id,g.title,g.img,g.label')
+                ->join('wx_goods g', 'g.id=og.goods_id')
+                ->where('og.order_id', $orderId)
+                ->where('og.goods_id', $goodsId)
+                ->select();
+            foreach ($goodsList as $k=>$v){
+                if($nums > 0){
+                    $goodsList[$k]['num'] = $nums;
+                }
+            }
+        }else{
+            $goodsList = Db::name('wx_orders_goods')
+                ->alias('og')
+                ->field('og.nums as num,og.price,og.goods_id,g.title,g.img,g.label')
+                ->join('wx_goods g', 'g.id=og.goods_id')
+                ->where('og.order_id', $orderId)
+                ->select();
+        }
+        foreach ($goodsList as $k=>$v){
+
+
+            //$rNum = $this->getRefundGoodsNum($v['goods_id'],$orderId);
+            //$goodsList[$k]['refund_num'] = $v['num']-$rNum;
+            // $goodsList[$k]['refund_num'] = $v['num'];
+            $goodsList[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
+                ->where('id',$v['label'])
+                ->value('title'):"";
+            $flag= Db::name('wx_orders_refund')
+                ->where('del',0)
+                ->where('goods_id',$v['goods_id'])
+                ->where('order_id',$orderId)
+                ->find();
+            if($flag){
+                unset($goodsList[$k]);
+            }
+        }
+        HelpHander::success($goodsList);
+
+
+    }
+
+}

+ 153 - 0
application/api/controller/v1/Notify.php

@@ -0,0 +1,153 @@
+<?php
+
+namespace app\api\controller\v1;
+use EasyWeChat\Factory;
+use think\Controller;
+use think\Db;
+use think\Exception;
+
+class Notify extends Controller {
+
+   
+
+    public function  WxOrder(){
+        $options = config('app.wx_mini_config');
+        $app = Factory::payment($options);
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                // 用户是否支付成功
+                $tradeNo = $message['out_trade_no'];
+                // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
+                $order = Db::name('wx_orders')->where('order_sn',$tradeNo)->find();
+                if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
+                    return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
+                }
+                $ret = Db::name('wx_orders')->where('id',$order['id'])->update(['status'=>1,'pay_time'=>date('Y-m-d H:i:s')]);
+                $goods = Db::name('wx_orders_goods')->where('order_id',$order['id'])->select();
+                //增加销量
+                $is = false;
+                foreach ($goods as $k=>$v){
+                    Db::name('wx_goods')
+                        ->where('id',$v['goods_id'])
+                        ->inc('sale',$v['nums'])
+                        ->update();
+                    $gInfo = Db::name('wx_goods')
+                        ->where('id',$v['goods_id'])
+                        ->find();
+                    $cateInfo = Db::name('wx_goods_cate')
+                        ->where('id',$gInfo['cate_id'])
+                        ->find();
+                    if($cateInfo['is_water']==1){
+                        $is = true;
+                    }
+                }
+                if($is){
+                    model('Orders')->waterSend($order['org_id']);
+                }
+                if(!$ret){
+                    trace('订单修改失败');
+                    $fail('订单修改失败');
+                }
+            } else {
+                return $fail('通信失败,请稍后再通知我');
+            }
+
+            return true; // 返回处理完成
+
+        });
+
+        $response->send();
+    }
+
+
+    public function  cashOrder(){
+        $options = config('app.wx_mini_config');
+        $app = Factory::payment($options);
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                // 用户是否支付成功
+                $tradeNo = $message['out_trade_no'];
+                // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
+                $order = Db::name('wx_cash_pay_log')->where('sn',$tradeNo)->find();
+                if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
+                    return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
+                }
+
+                Db::startTrans();
+                try{
+                   $ret = Db::name('wx_cash_pay_log')
+                       ->where('id',$order['id'])
+                       ->update(['status'=>1,'pay_time'=>date('Y-m-d H:i:s')]);
+                   if(!$ret){
+                       \exception('操作失败');
+                   }
+                   /* $old = Db::name('wx_cash')
+                        ->where('barrel_id',$order['barrel_id'])
+                        ->where('user_id',$order['user_id'])
+                        ->where('del',0)
+                        ->find();
+                   if($old){
+                       $r = Db::name('wx_cash')
+                           ->where('id',$old['id'])
+                           ->setInc('num',$order['num']);
+                       if(!$r){
+                           \exception('操作失败');
+                       }
+                   }else{
+                       $barrel = Db::name('wx_barrel')
+                           ->where('id',$order['barrel_id'])
+                           ->find();
+                       $params = [
+                           'sn'=>get_unique_id(),
+                           'user_id'=>$order['user_id'],
+                           'barrel_id'=>$order['barrel_id'],
+                           'org_id'=>$order['org_id'],
+                           'num'=>$order['num'],
+                           'amount'=>$order['amount'],
+                           'price'=>$barrel['cash_price'],
+                           'create_time'=>getTime()
+                       ];
+                       $res = Db::name('wx_cash')
+                           ->insertGetId($params);
+                       if(!$res){
+                           \exception('操作失败');
+                       }
+                   }*/
+                    $barrel = Db::name('wx_barrel')
+                        ->where('id',$order['barrel_id'])
+                        ->find();
+                    $params = [
+                        'sn'=>$order['sn'],
+                        'user_id'=>$order['user_id'],
+                        'barrel_id'=>$order['barrel_id'],
+                        'org_id'=>$order['org_id'],
+                        'num'=>$order['num'],
+                        'amount'=>$order['amount'],
+                        'total_money'=>$order['amount'],
+                        'price'=>$barrel['cash_price'],
+                        'create_time'=>getTime()
+                    ];
+                    $res = Db::name('wx_cash')
+                        ->insertGetId($params);
+                    if(!$res){
+                        \exception('操作失败');
+                    }
+                   Db::commit();
+                   return true;
+                }catch (Exception $e){
+                    Db::rollback();
+                    trace($e->getMessage());
+                    $fail($e->getMessage());
+                }
+
+            } else {
+                return $fail('通信失败,请稍后再通知我');
+            }
+
+            return true; // 返回处理完成
+
+        });
+
+        $response->send();
+    }
+}

+ 19 - 0
application/common.php

@@ -1624,3 +1624,22 @@ function second_to_str($diff){
     }
     return $time_cost;
 }
+
+//计算指定时间中间小时
+function getMinFromRange($startdate, $enddate){
+
+    $stimestamp = strtotime($startdate);
+    $etimestamp = strtotime($enddate);
+
+    // 计算日期段内有多少小时
+    $days = ($etimestamp-$stimestamp)/3600;
+
+    // 保存
+    $date = array();
+
+    for($i=0; $i<=$days; $i++){
+        $date[] = date('Y-m-d H:i:s', $stimestamp+(3600*$i));
+    }
+
+    return $date;
+}

+ 41 - 0
application/common/model/WxBarrel.php

@@ -0,0 +1,41 @@
+<?php
+namespace app\common\model;
+
+use think\Db;
+
+class WxBarrel extends Base
+{
+
+    public function updates(){
+        $data = request()->post();
+        $data['org_id'] = cur_org_id();
+        $result = validate('WxBarrel')->check($data,[],'');
+        if(true !== $result){
+            $this->error = validate('WxBarrel')->getError();
+            return false;
+        }
+        $id = $data['id'];
+        unset($data['id']);
+        if($id > 0){
+            $ret = $this->allowField(true)->save($data,['id'=>$id]);
+        }else{
+            $data['create_time'] = date('Y-m-d H:i:s');
+            $ret = $this->allowField(true)->save($data);
+        }
+        if(!$ret){
+            $this->error = '操作失败';
+            return false;
+        }
+        return true;
+    }
+
+    public function lists($orgId){
+        $ret=Db::name('wx_barrel')
+            ->field('id,title,cash_price,path')
+            ->where(['org_id'=>$orgId,'enable'=>1,'del'=>0])
+            ->order(['sort'=>'asc','id'=>'desc'])
+            ->select();
+
+        return $ret;
+    }
+}

+ 170 - 0
application/common/model/WxCart.php

@@ -0,0 +1,170 @@
+<?php
+namespace app\common\model;
+
+use app\hander\HelpHander;
+use think\Db;
+
+class WxCart extends Base
+{
+
+    public function add($goodsId,$userId){
+        $map[]=['user_id','=',$userId];
+        $map[]=['goods_id','=',$goodsId];
+        $goodsStock=Db::name('wx_goods')
+            ->where('id',$goodsId)->value('stock');
+//        if($goodsStock < 1){
+//            $this->error='库存不足';
+//            return false;
+//        }
+
+        $find=Db::name('wx_goods_cart')->where($map)->find();
+
+        if($find){
+            $ret=Db::name('wx_goods_cart')->where($map)->inc('nums')->update(['update_time'=>date('Y-m-d H:i:s')]);
+        }else{
+            $data=[
+                'user_id'=>$userId,
+                'goods_id'=>$goodsId,
+                'nums'=>1,
+                'create_time'=>date('Y-m-d H:i:s'),
+            ];
+            $ret=Db::name('wx_goods_cart')->insert($data);
+        }
+        return $ret;
+    }
+    public function lists($userId,$orgId){
+        $ret=Db::name('wx_goods_cart')
+            ->alias('c')
+            ->join('wx_goods g','c.goods_id=g.id')
+            ->field('c.id,c.goods_id,c.nums,g.title,g.img,g.price,g.enable,g.label')
+            ->where('c.user_id',$userId)
+            ->where('g.del',0)
+            ->where('g.org_id',$orgId)
+            ->order('c.id','desc')
+            ->select();
+        $total = 0;
+        $num = 0;
+        foreach ($ret as $k=>$v){
+            $ret[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
+                ->where('id',$v['label'])
+                ->value('title'):"";
+            $total+=$v['nums']*$v['price'];
+            $num+=$v['nums'];
+        }
+        $data = [
+            'list'=>$ret,
+            'nums'=>$num,
+            'total'=>sprintf("%01.2f", $total),
+
+        ];
+        return $data;
+    }
+    public function updateNum($id,$nums){
+        $nums = intval($nums);
+        if($nums==0){
+            $ret=Db::name('wx_goods_cart')->where('id',$id)
+                ->delete();
+            return $ret;
+        }else{
+            $ret=Db::name('wx_goods_cart')->where('id',$id)
+                ->update(['nums'=>$nums,'update_time'=>date('Y-m-d H:i:s')]);
+            return $ret;
+        }
+        $ret=Db::name('wx_goods_cart')->where('id',$id)
+            ->update(['nums'=>$nums,'update_time'=>date('Y-m-d H:i:s')]);
+        return $ret;
+    }
+    public function setCartNum($userId,$id,$type,$num){
+        $map[]=['user_id','=',$userId];
+        $map[]=['id','=',$id];
+        $find=Db::name('wx_goods_cart')->where($map)->find();
+        if(empty($find)){
+            HelpHander::error('信息不存在');
+        }
+        if($type==0){
+            $ret=Db::name('wx_goods_cart')
+                ->where($map)->inc('nums',$num)
+                ->update(['update_time'=>date('Y-m-d H:i:s')]);
+        }else{
+            if($find['nums']==1){
+                $ret=Db::name('wx_goods_cart')->where($map)
+                    ->delete();
+            }else{
+                $ret=Db::name('wx_goods_cart')->where($map)
+                    ->dec('nums')
+                    ->update(['update_time'=>date('Y-m-d H:i:s')]);
+            }
+        }
+        return $ret;
+    }
+
+
+    public function setGoodsNum($userId,$goodsId,$type,$num){
+        $map[]=['user_id','=',$userId];
+        $map[]=['goods_id','=',$goodsId];
+        $find=Db::name('wx_goods_cart')->where($map)->find();
+
+        if($type==0){
+            if($find){
+                $ret=Db::name('wx_goods_cart')
+                    ->where($map)->inc('nums',$num)
+                    ->update(['update_time'=>date('Y-m-d H:i:s')]);
+            }else{
+                $data=[
+                    'user_id'=>$userId,
+                    'goods_id'=>$goodsId,
+                    'nums'=>1,
+                    'create_time'=>date('Y-m-d H:i:s'),
+                ];
+                $ret=Db::name('wx_goods_cart')->insert($data);
+            }
+
+        }else{
+            if(empty($find)){
+                HelpHander::error('信息不存在');
+            }
+            if($find['nums']==1){
+                $ret = Db::name('wx_goods_cart')->where($map)->delete();
+            }else{
+                $ret=Db::name('wx_goods_cart')->where($map)
+                    ->dec('nums')
+                    ->update(['update_time'=>date('Y-m-d H:i:s')]);
+            }
+
+
+        }
+        return $ret;
+    }
+
+
+    public function goodsFav($userId,$goodsId){
+        $map[]=['user_id','=',$userId];
+        $map[]=['goods_id','=',$goodsId];
+        $find=Db::name('wx_goods_fav')->where($map)->find();
+        if($find){
+            $ret = Db::name('wx_goods_fav')->where($map)->delete();
+            $p = [
+                'type'=>0,
+                'ret'=>$ret,
+            ];
+        }else{
+            $data=[
+                'user_id'=>$userId,
+                'goods_id'=>$goodsId,
+                'create_time'=>date('Y-m-d H:i:s'),
+            ];
+            $ret=Db::name('wx_goods_fav')->insert($data);
+            $p = [
+                'type'=>1,
+                'ret'=>$ret,
+            ];
+        }
+
+        return $p;
+    }
+    public function del($id){
+        $ret=Db::name('wx_goods_cart')->where('id',$id)->delete();
+        return $ret;
+    }
+
+}

+ 215 - 0
application/common/model/WxCash.php

@@ -0,0 +1,215 @@
+<?php
+namespace app\common\model;
+
+use think\Db;
+use EasyWeChat\Factory;
+
+class WxCash extends Base
+{
+
+    public $status = [
+        0=> '退款处理中',
+        1=> '退款成功',
+        2=> '退款拒绝',
+    ];
+    public function lists($page,$size,$userId,$orgId,$status){
+        if($status>0){
+            if($status==1){
+                $map[]=['status','=',0];
+            }elseif ($status==2){
+                $map[]=['status','=',1];
+            }elseif ($status==3){
+                $map[]=['status','=',2];
+            }elseif ($status==4){
+                $map[]=['status','in',[5,6,7]];
+            }
+        }
+        $map[]=['user_id','=',$userId];
+        $map[]=['org_id','=',$orgId];
+        $map[]=['del','=',0];
+        $ret=Db::name('wx_orders')
+            ->field('id,order_sn,status,amount')
+            ->where($map)
+            ->order('id','desc')
+            ->page($page,$size)
+            ->select();
+        foreach ($ret as $k=>$v){
+            $orderGoods=Db::name('wx_orders_goods')
+                ->alias('og')
+                ->field('og.nums,og.price,og.goods_id,g.title,g.img,g.label')
+                ->join('wx_goods g','g.id=og.goods_id')
+                ->where('og.order_id',$v['id'])
+                ->select();
+            $nums=0;
+            foreach ($orderGoods as $kk=>$vv){
+                $nums+=$vv['nums'];
+                $orderGoods[$k]['label_name'] = $vv['label']>0?Db::name('wx_goods_label')
+                    ->where('id',$vv['label'])
+                    ->value('title'):"";
+            }
+            $ret[$k]['total_num']=$nums;
+            $ret[$k]['goods_num']=count($orderGoods);
+            $ret[$k]['order_goods']=$orderGoods;
+        }
+        return $ret?$ret:[];
+    }
+    public function details($ordersId){
+        $ret = Db::name('g_orders')->where('id', $ordersId)->find();
+        $ret['goods'] = Db::name('g_order_goods')
+            ->alias('og')
+            ->field('og.nums,og.price,og.goods_id,g.title,g.img')
+            ->join('g_goods g', 'g.id=og.goods_id')
+            ->where('og.order_id', $ret['id'])
+            ->select();
+        $rd = Db::name('g_order_refund')
+            ->where('order_id', $ret['id'])
+            ->find();
+        if(empty($rd)){
+            $rd = [
+                'sn'=>'',
+                'order_id'=>'',
+                'money'=>'',
+                'remark'=>'',
+                'refund_money'=>'',
+                'refund_remark'=>'',
+            ];
+        }
+        $ret['refund'] = $rd;
+        $nums=0;
+        foreach ($ret['goods'] as $k=>$v){
+            $nums+=$v['nums'];
+        }
+        $ret['sum']=$nums;
+        if($ret['status']==1 && time() < (strtotime($ret['create_time'])+(30*24*3600))){
+            $ret['tk'] = 1;
+        }else{
+            $ret['tk'] = 0;
+
+        }
+        $s = [
+            '未支付',
+            '已支付',
+            '已完成',
+            '已取消',
+            '已退款',
+            '退款拒绝',
+            '退款中',
+        ];
+        $ret['statusTxt']=isset($s[$ret['status']])?$s[$ret['status']]:'';
+
+        return $ret;
+    }
+    public function accomplish($ordersId){
+        $data=[
+            'status'=>2,
+            'finish_time'=>date('Y-m-d H:i:s'),
+        ];
+        $ret = Db::name('g_orders')->where('id', $ordersId)->update($data);
+        return $ret;
+    }
+
+    public function refundOrder($userId){
+        $data = [
+            'money' => input('money/f',0),
+            'order_id' => input('id/d',0),
+            'user_id' => $userId,
+            'remark' => input('remark','','trim'),
+            'create_time' => date('Y-m-d H:i:s'),
+        ];
+        if($data['money'] <= 0){
+            $this->error = '金额必须大于0';
+            return false;
+        }
+        $pay = Db::name('g_orders')
+            ->where('id',$data['order_id'])->find();
+        if(!$pay||$pay['status'] != 1){
+            $this->error = '订单不存在';
+            return false;
+        }
+        $data['sn'] = get_unique_id('TPH');
+        $data['org_id'] = $pay['org_id'];
+        if($data['money'] > $pay['amount']){
+            $this->error = '退款金额过大';
+            return false;
+        }
+
+        Db::startTrans();
+        try{
+
+            $ret = Db::name('g_order_refund')->insert($data);
+            if(!$ret){
+                \exception('操作失败');
+            }
+            $order = Db::name('g_orders')
+                ->where('id',$pay['id'])
+                ->lock(true)
+                ->find();
+            if(!$order){
+                \exception('订单不存在');
+            }
+
+            $ret = Db::name('g_orders')
+                ->where('id',$pay['id'])->update([
+                    'refund_money' => $data['money'],
+                    'status' => 4
+                ]);
+            if(!$ret){
+                \exception('操作失败');
+            }
+
+            $config = config('app.wx_mini_config');
+            $app = \EasyWeChat\Factory::payment($config);
+            $ret = $app->refund->byOutTradeNumber($pay['order_sn'], $data['sn'], $pay['amount']*100, $data['money']*100);
+            if($ret['return_code'] != 'SUCCESS' || $ret['result_code'] != 'SUCCESS'){
+                trace(json_encode($ret));
+                \exception('退款申请提交失败');
+            }
+            Db::commit();
+            return true;
+        }catch (\Exception $e){
+            Db::rollback();
+            trace($e->getMessage());
+            $this->error = $e->getMessage();
+            return false;
+        }
+
+    }
+
+
+    public function formatOrder($ids){
+        $list = [];
+        $total = 0;
+        $isWater = 0;
+        $cash_price = 0;
+        $remark = [];
+        foreach ($ids as $k=>$v){
+            $ret=Db::name('wx_goods')
+                ->field('price,id as goods_id,title,img,label,barrel_id')
+                ->where('id','=',$v['id'])
+                ->find();
+            $ret['label_name'] = $ret['label']>0?Db::name('wx_goods_label')
+                ->where('id',$ret['label'])
+                ->value('title'):"";
+            $ret['num'] = $v['num'];
+            $total+=$v['num']*$ret['price'];
+            if($ret['barrel_id'] >0){
+                $isWater = 1;
+                $wx_barrel = Db::name('wx_barrel')
+                    ->where('id',$ret['barrel_id'])
+                    ->find();
+                $cash_price+=$wx_barrel['cash_price']*$v['num'];
+                $remark[] =$ret['title'].'押金:'.$wx_barrel['cash_price']*$v['num'];
+            }
+            $list[] = $ret;
+        }
+        $data = [
+            'list'=>$list,
+            'isWater'=>$isWater,
+            'remark'=>$remark?implode(';',$remark):"",
+            'cash_price'=>sprintf("%01.2f", $cash_price),
+            'total'=>sprintf("%01.2f", $total),
+        ];
+        return $data;
+    }
+}
+

+ 275 - 0
application/common/model/WxGoods.php

@@ -0,0 +1,275 @@
+<?php
+namespace app\common\model;
+
+use think\Db;
+
+class WxGoods extends Base
+{
+
+    public function updates(){
+        $data = request()->post();
+        $data['org_id'] = cur_org_id();
+
+        $result = validate('WxGoods')->check($data,[],'');
+        if(true !== $result){
+            $this->error = validate('WxGoods')->getError();
+            return false;
+        }
+        if(!empty($data['imgs'])){
+            $data['imgs']=implode(',',$data['imgs']);;
+        }
+        $cateInfo = Db::name('wx_goods_cate')
+            ->where('id',$data['cate_id'])
+            ->find();
+        if($cateInfo['is_water']==1){
+            if(empty($data['barrel_id'])){
+                $this->error = '请选择空桶';
+                return false;
+            }
+        }else{
+            $data['barrel_id'] = 0;
+        }
+        $id = $data['id'];
+        unset($data['id']);
+        if($id > 0){
+            $data['update_time'] = date('Y-m-d H:i:s');
+            $ret = $this->allowField(true)->save($data,['id'=>$id]);
+        }else{
+            $data['create_time'] = date('Y-m-d H:i:s');
+            $ret = $this->allowField(true)->save($data);
+        }
+        if(!$ret){
+            $this->error = '操作失败';
+            return false;
+        }
+        return true;
+    }
+
+
+    public function cateGoodsList($userId,$orgId,$cateId,$title,$desc_name='sale',$desc='desc'){
+        $map[] = ['org_id','=',$orgId];
+        $map[] = ['enable','=',1];
+        $map[] = ['del','=',0];
+        $cateInfo = [];
+        if($cateId > 0){
+            $map[] = ['cate_id','=',$cateId];
+            $cateInfo = Db::name('wx_goods_cate')
+                ->field('id,title,is_water,path')
+                ->where(['id'=>$cateId])->find();
+        }
+        if($title != ''){
+            $map[] = ['title','like','%'.$title.'%'];
+        }
+
+        $ret=Db::name('wx_goods')
+            ->field('id,title,price,img,price,label,dec')
+            ->where($map)
+            ->order([$desc_name=>$desc,'sort'=>'asc','id'=>'desc',])
+            ->select();
+        foreach ($ret as $k=>$v){
+                $ret[$k]['label_name']=$v['label'] >0?Db::name('wx_goods_label')
+                ->where('id',$v['label'])
+                ->value('title'):'';
+                $cart =  Db::name('wx_goods_cart')
+                    ->where('user_id',$userId)
+                    ->where('goods_id',$v['id'])
+                    ->find();
+            $ret[$k]['cart_num'] = $cart?$cart['nums']:0;
+            $ret[$k]['cartId'] = $cart?$cart['id']:0;
+
+        }
+        $data =[
+            'list'=>$ret,
+            'cateInfo'=>$cateInfo,
+        ];
+        return $data;
+    }
+
+    public function details($id,$userId){
+        $ret=Db::name('wx_goods')
+            ->field('id,title,price,img,imgs,sale,content,label')
+            ->where('id',$id)
+            ->where('del',0)
+            ->where('enable',1)
+            ->find();
+        if($ret){
+            $ret['isFav'] = 0;
+            $ret['imgs']=$ret['imgs']?explode(',',$ret['imgs']):[];
+            $ret['label_name']=$ret['label'] >0?Db::name('wx_goods_label')
+                ->where('id',$ret['label'])
+                ->value('title'):'';
+            $checkFav = Db::name('wx_goods_fav')
+                ->where('user_id',$userId)
+                ->where('goods_id',$ret['id'])
+                ->find();
+            if($checkFav){
+                $ret['isFav'] = 1;
+            }
+        }
+        return $ret;
+    }
+
+
+    public function getTjGoods($orgId){
+        $list = Db::name('wx_goods')
+            ->field('id,title,img,price,label')
+            ->where('del',0)
+            ->where('org_id',$orgId)
+            ->where('enable',1)
+            ->where('is_tj',1)
+            ->order(['sort'=>'asc','id'=>'desc'])
+            ->limit(3)
+            ->select();
+        foreach ($list  as $k=>$v){
+            $list[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
+                ->where('id',$v['label'])
+                ->value('title'):"";
+        }
+        return $list?$list:[];
+    }
+    public function getTjGoodsList($orgId,$page,$size){
+        $list = Db::name('wx_goods')
+            ->field('id,title,img,price,label,sale')
+            ->where('del',0)
+            ->where('org_id',$orgId)
+            ->where('enable',1)
+            ->where('is_tj',1)
+            ->order(['sort'=>'asc','id'=>'desc'])
+            ->page($page,$size)
+            ->select();
+        foreach ($list  as $k=>$v){
+            $list[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
+                ->where('id',$v['label'])
+                ->value('title'):"";
+        }
+        return $list?$list:[];
+    }
+    public function getIndexGoods($orgId){
+        $list = Db::name('wx_goods')
+            ->field('id,title,img,price,label,sale')
+            ->where('del',0)
+            ->where('org_id',$orgId)
+            ->where('enable',1)
+           // ->where('is_tj',0)
+            ->order(['sort'=>'asc','id'=>'desc'])
+            ->limit(10)
+            ->select();
+        foreach ($list  as $k=>$v){
+            $list[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
+                ->where('id',$v['label'])
+                ->value('title'):"";
+        }
+        return $list?$list:[];
+    }
+    public function getIndexGoodsList($orgId,$page,$size,$type,$desc_name='sale',$desc='desc',$kw=''){
+        $map = [];
+        if($kw!=''){
+            $map[] = ['title','like','%'.$kw.'%'];
+        }
+        if($type ==0){
+            $order= [$desc_name=>$desc,'sort'=>'asc','id'=>'desc'];
+        }else{
+            $order= ['sort'=>'asc','id'=>'desc'];
+        }
+        if($type ==1){
+            $map[] = ['label','=',1];
+        }elseif ($type==2){
+            $map[] = ['barrel_id','>',0];
+        }elseif ($type==3){
+            $map[] = ['is_tj','=',1];
+        }
+        $list = Db::name('wx_goods')
+            ->field('id,title,img,price,label,sale,dec')
+            ->where('del',0)
+            ->where('org_id',$orgId)
+            ->where('enable',1)
+            ->where($map)
+            ->order($order)
+            ->page($page,$size)
+            ->select();
+        foreach ($list  as $k=>$v){
+            $list[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
+                ->where('id',$v['label'])
+                ->value('title'):"";
+        }
+        return $list?$list:[];
+    }
+
+    public function favGoodsList($userId,$orgId,$page,$size){
+            $ids = Db::name('wx_goods_fav')
+                ->where('user_id',$userId)
+                ->group('goods_id')
+                ->column('goods_id');
+            if(empty($ids)){
+                $map[] = ['id','=',-1];
+            }else{
+                $map[] = ['id','in',$ids];
+            }
+            $list = Db::name('wx_goods')
+            ->field('id,title,img,price,label,sale,dec')
+            ->where('del',0)
+            ->where('org_id',$orgId)
+            ->where('enable',1)
+            ->where($map)
+            ->order(['sort'=>'asc','id'=>'desc'])
+            ->page($page,$size)
+            ->select();
+        foreach ($list  as $k=>$v){
+            $list[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
+                ->where('id',$v['label'])
+                ->value('title'):"";
+        }
+        return $list?$list:[];
+    }
+
+    public function barrelList($orgId,$page,$size){
+        $map[] = ['org_id','=',$orgId];
+        $map[] = ['del','=',0];
+        $map[] = ['enable','=',1];
+
+        $list = Db::name('wx_barrel')
+            ->field('id,title,cash_price,path')
+            ->where($map)
+            ->order(['sort'=>'asc','id'=>'desc'])
+            ->page($page,$size)
+            ->select();
+
+        return $list?$list:[];
+    }
+    public function myBarrelList($orgId,$userId,$page,$size){
+        $map[] = ['a.org_id','=',$orgId];
+        $map[] = ['a.del','=',0];
+        $map[] = ['a.user_id','=',$userId];
+
+        $list = Db::name('wx_cash')
+            ->alias('a')
+            ->join('wx_barrel b','a.barrel_id=b.id')
+            ->field('a.id,b.title,b.cash_price,b.path,a.num,a.amount')
+            ->where($map)
+            ->order(['a.id'=>'desc'])
+            ->page($page,$size)
+            ->select();
+
+        return $list?$list:[];
+    }
+    public function myRefundBarrelList($orgId,$userId,$page,$size){
+        $map[] = ['a.org_id','=',$orgId];
+        $map[] = ['a.del','=',0];
+        $map[] = ['a.user_id','=',$userId];
+
+        $list = Db::name('wx_cash_refund')
+            ->alias('a')
+            ->join('wx_barrel b','a.barrel_id=b.id')
+            ->field('a.id,b.title,b.cash_price,b.path,a.num,a.amount,a.status,a.create_time,a.remark')
+            ->where($map)
+            ->order(['a.id'=>'desc'])
+            ->page($page,$size)
+            ->select();
+        foreach ($list as $k=>$v){
+            $list[$k]['status_name'] =isset(model('WxCash')->status[$v['status']])?model('WxCash')->status[$v['status']]:'';
+            $list[$k]['remark'] = $v['remark']?$v['remark']:"";
+        }
+
+        return $list?$list:[];
+    }
+}

+ 57 - 0
application/common/model/WxGoodsCate.php

@@ -0,0 +1,57 @@
+<?php
+namespace app\common\model;
+
+use think\Db;
+
+class WxGoodsCate extends Base
+{
+
+    public function updates(){
+        $data = request()->post();
+        $data['org_id'] = cur_org_id();
+        $result = validate('WxGoodsCate')->check($data,[],'');
+        if(true !== $result){
+            $this->error = validate('WxGoodsCate')->getError();
+            return false;
+        }
+        $id = $data['id'];
+        unset($data['id']);
+        if($id > 0){
+            $ret = $this->allowField(true)->save($data,['id'=>$id]);
+        }else{
+            $data['create_time'] = date('Y-m-d H:i:s');
+            $ret = $this->allowField(true)->save($data);
+        }
+        if(!$ret){
+            $this->error = '操作失败';
+            return false;
+        }
+        return true;
+    }
+
+    public function lists($orgId){
+        $ret=Db::name('wx_goods_cate')
+            ->field('id,title,is_water,path')
+            ->where(['org_id'=>$orgId,'enable'=>1,'del'=>0])
+            ->order(['sort'=>'asc','id'=>'desc'])
+            ->select();
+//        $data=[
+//            [
+//                'id'=>0,
+//                'title'=>'全部'
+//            ],
+//        ];
+//        foreach ($ret as $k=>$v){
+//            $data[] = $v;
+//        }
+        return $ret;
+    }
+
+    public function getLabel(){
+        $ret=Db::name('wx_goods_label')
+            ->where('enable',1)
+            ->where('del',0)
+            ->select();
+        return $ret;
+    }
+}

+ 52 - 0
application/common/model/WxNotice.php

@@ -0,0 +1,52 @@
+<?php
+namespace app\common\model;
+
+use think\Db;
+
+class WxNotice extends Base
+{
+
+    public function updates(){
+        $data = request()->post();
+        $data['org_id'] = cur_org_id();
+        $data['user_id'] = is_login();
+        $result = validate('WxNotice')->check($data,[],'');
+        if(true !== $result){
+            $this->error = validate('WxNotice')->getError();
+            return false;
+        }
+        $id = $data['id'];
+        unset($data['id']);
+        if($id > 0){
+            $ret = $this->allowField(true)->save($data,['id'=>$id]);
+        }else{
+            $data['create_time'] = date('Y-m-d H:i:s');
+            $ret = $this->allowField(true)->save($data);
+        }
+        if(!$ret){
+            $this->error = '操作失败';
+            return false;
+        }
+        return true;
+    }
+
+    public function lists($orgId){
+        $ret=Db::name('wx_notice')
+            ->field('id,title,content,create_time')
+            ->where(['org_id'=>$orgId,'del'=>0])
+            ->order(['id'=>'desc'])
+            ->select();
+
+        return $ret;
+    }
+
+    public function getOne($orgId){
+        $ret=Db::name('wx_notice')
+            ->field('id,title,content,create_time')
+            ->where(['org_id'=>$orgId,'del'=>0])
+            ->order(['id'=>'desc'])
+            ->find();
+
+        return $ret;
+    }
+}

+ 971 - 0
application/common/model/WxOrders.php

@@ -0,0 +1,971 @@
+<?php
+namespace app\common\model;
+
+use app\hander\HelpHander;
+use think\Db;
+use EasyWeChat\Factory;
+use think\Exception;
+
+class WxOrders extends Base
+{
+
+    public $status = [
+        '未支付',
+        '已支付',
+        '已发货',
+        '已完成',
+        '已取消',
+        '已评价',
+
+    ];
+    public $rStatus = [
+        '退款处理中',
+        '退款成功',
+        '退款拒绝',
+    ];
+    public function add($cartId,$addressId,$userId,$orgId,$type,$goodsId,$isHasBarrel,$deliveryDate,$deliveryType,$orderRemark,$payType,$num){
+        $addressInfo=Db::name('shop_address')->where('id',$addressId)->find();
+        if(!$addressInfo){
+            $this->error = "未选择地址";
+            return false;
+        }
+        $ids = [];
+        if($type==0){
+            if(empty($goodsId) || empty($num)){
+                $this->error ='参数错误';
+            }
+            $ids[] = ['id'=>$goodsId,'num'=>$num];
+        }else if($type==1){
+            if(empty($cartId)){
+                $this->error='参数错误';
+            }
+            $gId = Db::name('wx_goods_cart')
+                ->alias('a')
+                ->join('wx_goods b','a.goods_id=b.id')
+                ->where('a.id','in',explode(',',$cartId))
+                ->where('a.user_id',$userId)
+                ->where('b.del',0)
+                ->where('b.org_id',$orgId)
+                ->group('a.goods_id')
+                ->select();
+
+            foreach ($gId as $k=>$v){
+                $ids[] = [
+                    'id'=>$v['goods_id'],
+                    'num'=>$v['nums'],
+                ];
+            }
+        }
+
+        $data =$this->formatOrder($ids);
+
+        Db::startTrans();
+        try {
+            $params=[
+                'order_sn'=>get_unique_id(),
+                'org_id'=>$orgId,
+                'user_id'=>$userId,
+                'amount'=>$data['total'],
+                'status'=>0,
+                'create_time'=>date('Y-m-d H:i:s'),
+                'name'=>$addressInfo['name'],
+                'phone'=>$addressInfo['phone'],
+                'address'=>$addressInfo['content'],
+                'pay_type'=>$payType,
+                'order_remark'=>$orderRemark,
+                'delivery_date'=>$deliveryDate,
+                'delivery_type'=>$deliveryType,
+                'cash_price'=>$isHasBarrel==1?$data['cash_price']:0,
+                'is_has_barrel'=>$isHasBarrel,
+                'remark'=>$isHasBarrel==1?$data['remark']:"",
+                'order_type'=>$data['isWater'],
+                'create_yyyy'=>date('Y'),
+                'create_yyyymm'=>date('Ym'),
+                'create_yyyymmdd'=>date('Ymd'),
+                'create_yyyymmddhh'=>date('YmdH'),
+            ];
+
+            $addOrder=Db::name('wx_orders')->insertGetId($params);
+            if(!$addOrder){
+                exception('操作失败');
+            }
+            foreach ($data['list'] as $kay=>$val){
+                $gdata=[
+                    'order_id'=>$addOrder,
+                    'goods_id'=>$val['goods_id'],
+                    'nums'=>$val['num'],
+                    'price'=>$val['price'],
+                ];
+                $addOrderGoods=Db::name('wx_orders_goods')->insert($gdata);
+                if(!$addOrderGoods){
+                    exception('操作失败');
+                }
+//                 //减少库存
+//                 $dec= Db::name('wx_goods')
+//                    ->where('id',$val['goods_id'])
+//                    ->dec('stock', $val['num'])
+//                    ->update();
+//                if(!$dec){
+//                    exception('操作失败');
+//                }
+            }
+            //删除用户购物车信息
+            if($type==1){
+                $delCart=Db::name('wx_goods_cart')
+                    ->where('user_id',$userId)
+                    ->whereIn('id',explode(',',$cartId))->delete();
+                if(!$delCart){
+                    exception('操作失败');
+                }
+            }
+            Db::commit();
+            return $addOrder;
+        } catch (\Exception $e) {
+            // 回滚事务
+            $this->error = $e->getMessage();
+            Db::rollback();
+            return false;
+        }
+    }
+    public function lists($page,$size,$userId,$orgId,$status){
+        if($status>0){
+            if($status==1){
+                $map[]=['status','=',0];
+            }elseif ($status==2){
+                $ids = Db::name('wx_orders_refund')
+                    ->where('org_id',$orgId)
+                    ->where('user_id',$userId)
+                    ->where('del',0)
+                    ->column('order_id');
+                foreach ($ids as $k=>$v){
+                    $r = $this->checkOrderSend($v);
+                    if($r==2){//全部退款
+                        unset($ids[$k]);
+                    }
+                }
+                if(!empty($ids)){
+                    $map[]=['id','not in',$ids];
+                }
+                $map[]=['status','=',1];
+            }elseif ($status==3){
+
+                $map[]=['status','=',2];
+            }elseif ($status==4){
+                $ids = Db::name('wx_orders_refund')
+                    ->where('org_id',$orgId)
+                    ->where('user_id',$userId)
+                    ->where('del',0)
+                    ->column('order_id');
+                if(empty($ids)){
+                    $map[]=['id','=',-1];
+                }else{
+                    $map[]=['id','in',$ids];
+                }
+            }
+        }
+        $map[]=['user_id','=',$userId];
+        $map[]=['org_id','=',$orgId];
+        $map[]=['del','=',0];
+        $ret=Db::name('wx_orders')
+            ->field('id,order_sn,status,amount')
+            ->where($map)
+            ->order('id','desc')
+            ->page($page,$size)
+            ->select();
+        foreach ($ret as $k=>$v){
+
+            $ret[$k]['is_refund'] = $this->haveRefund($v['id']);
+            $ret[$k]['is_can_refund'] = $this->checkOrderRefund($v['id']);
+            $orderGoods=Db::name('wx_orders_goods')
+                ->alias('og')
+                ->field('og.nums,og.price,og.goods_id,g.title,g.img,g.label')
+                ->join('wx_goods g','g.id=og.goods_id')
+                ->where('og.order_id',$v['id'])
+                ->select();
+            $nums=0;
+            foreach ($orderGoods as $kk=>$vv){
+                $nums+=$vv['nums'];
+                $orderGoods[$kk]['label_name'] = $vv['label']>0?Db::name('wx_goods_label')
+                    ->where('id',$vv['label'])
+                    ->value('title'):"";
+
+                $r = $this->checkGoodsRefund1($v['id'],$vv['goods_id']);
+
+                $orderGoods[$kk]['is_refund'] =$r['is'];
+                $orderGoods[$kk]['refund_status_name'] =$r['refund_status_name'];
+            }
+            $ret[$k]['total_num']=$nums;
+            $ret[$k]['goods_num']=count($orderGoods);
+            $ret[$k]['order_goods']=$orderGoods;
+
+            $r  = $this->checkOrderSend($v['id']);
+            $ret[$k]['refund_status']=$r;
+            $ret[$k]['refund_name'] = '';
+            if($r==2){
+                $ret[$k]['refund_name'] =  '(已退款)';
+            }elseif ($r==1){
+                $ret[$k]['refund_name'] =  '(部分退款)';
+            }elseif ($r==3){
+                $ret[$k]['refund_name'] =  '(退款中)';
+
+            }
+        }
+        return $ret?$ret:[];
+    }
+    public function details($ordersId){
+        $ret = Db::name('wx_orders')
+            ->field('del,del_time,create_yyyy,create_yyyymm,create_yyyymmdd,create_yyyymmddhh',true)
+            ->where('id',$ordersId)->find();
+        $ret['pay_time'] =  $ret['pay_time']? $ret['pay_time']:"";
+        $ret['send_time'] =  $ret['send_time']? $ret['send_time']:"";
+        $ret['finish_time'] =  $ret['finish_time']? $ret['finish_time']:"";
+        $ret['cancel_time'] =  $ret['cancel_time']? $ret['cancel_time']:"";
+        $ret['delivery_date'] =  $ret['delivery_date']? $ret['delivery_date']:"";
+        $ret['status_name'] =  isset($this->status[$ret['status']])?$this->status[$ret['status']]:'';
+        $r  = $this->checkOrderSend($ordersId);
+        if($r==2){
+            $ret['status_name'] =  $ret['status_name'].'(已退款)';
+        }elseif ($r==1){
+            $ret['status_name'] =  $ret['status_name'].'(部分退款)';
+
+        }elseif ($r==3){
+            $ret['status_name'] =  $ret['status_name'].'(退款中)';
+
+        }
+        $ret['refund_status']=$r;
+        $ret['refund_name'] = '';
+        if($r==2){
+            $ret['refund_name'] =  '(已退款)';
+        }elseif ($r==1){
+            $ret['refund_name'] =  '(部分退款)';
+        }elseif ($r==3){
+            $ret['refund_name'] =  '(退款中)';
+
+        }
+        $ret['pay_type_name'] = $ret['pay_type']==1?'微信支付':'';
+        $ret['delivery_type_name'] = $ret['delivery_type']==1?'商家配送':'';
+        $ret['order_type_name'] = $ret['order_type']==1?'普通订单':'桶装水订单';
+        $ret['goods'] = Db::name('wx_orders_goods')
+            ->alias('og')
+            ->field('og.nums as num,og.price,og.goods_id,g.title,g.img,g.label')
+            ->join('wx_goods g', 'g.id=og.goods_id')
+            ->where('og.order_id', $ret['id'])
+            ->select();
+        $totalNum = 0;
+        $ret['is_refund'] = $this->haveRefund($ordersId);;
+        $ret['is_can_refund'] = $this->checkOrderRefund($ordersId);
+        foreach ($ret['goods'] as $k=>$v){
+            $ret['goods'][$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
+                ->where('id',$v['label'])
+                ->value('title'):"";
+            $r = $this->checkGoodsRefund($ordersId,$v['goods_id']);
+
+            $ret['goods'][$k]['is_refund'] =$r['is'];
+            $ret['goods'][$k]['refund_status_name'] =$r['refund_status_name'];
+
+
+            $totalNum+=$v['num'];
+        }
+        $ret['comment'] = Db::name('wx_comment')
+            ->field('create_yyyy,create_yyyymm,create_yyyymmdd',true)
+            ->where('order_id',$ordersId)
+            ->find();
+        $ret['totalNum'] = $totalNum;
+        $ret['goodsNum'] = count($ret['goods']);
+        return $ret;
+    }
+
+    public function haveRefund($id){
+        $refund = Db::name('wx_orders_refund')
+            ->where('del',0)
+            ->where('order_id',$id)
+            ->find();
+        return $refund?1:0;
+    }
+    public function checkOrderRefund($id){
+        $goodsList = Db::name('wx_orders_goods')
+            ->alias('og')
+            ->field('og.nums as num,og.price,og.goods_id,g.title,g.img,g.label,o.status')
+            ->join('wx_goods g', 'g.id=og.goods_id')
+            ->join('wx_orders o', 'og.order_id=o.id')
+            ->where('og.order_id', $id)
+            ->select();
+        $is = 0;
+        foreach ($goodsList as $k=>$v){
+            $refund = Db::name('wx_orders_refund')
+                ->where('order_id',$id)
+                ->where('del',0)
+                ->where('goods_id',$v['goods_id'])
+               // ->where('status','in',[0,1])
+                ->find();
+            if(!$refund && in_array($v['status'],[1,2])){
+                $is=1;
+            }
+        }
+        return $is;
+    }
+    public function checkOrderSend($id){
+        $goodsList = Db::name('wx_orders_goods')
+            ->alias('og')
+            ->field('og.nums as num,og.price,og.goods_id,g.title,g.img,g.label,o.status')
+            ->join('wx_goods g', 'g.id=og.goods_id')
+            ->join('wx_orders o', 'og.order_id=o.id')
+            ->where('og.order_id', $id)
+            ->select();
+        $is = 0;
+        $iss= 0;
+        foreach ($goodsList as $k=>$v){
+            $refund = Db::name('wx_orders_refund')
+                ->where('order_id',$id)
+                ->where('del',0)
+                ->where('goods_id',$v['goods_id'])
+                ->where('status','in',[1])
+                ->find();
+            if($refund){
+                $is++;
+            }
+            $refund = Db::name('wx_orders_refund')
+                ->where('order_id',$id)
+                ->where('del',0)
+                ->where('goods_id',$v['goods_id'])
+                ->where('status','in',[0])
+                ->find();
+            if($refund){
+                $iss++;
+            }
+        }
+        $r = 0;//未退款
+        if($is >0 || $iss >0){
+            if($is==count($goodsList)){
+                $r = 2;//全部退款
+            }elseif ($is < count($goodsList)){
+                if ($iss >0){
+                    $r = 3;//退款中
+                }else{
+                    $r = 1;//部分退款
+                }
+            }
+        }
+
+        return $r;
+    }
+    public function checkGoodsRefund1($orderId,$goodsId){
+
+        $is = 0;//不显示
+        $is_name = '';//不显示
+        $refund = Db::name('wx_orders_refund')
+            ->where('order_id',$orderId)
+            ->where('goods_id',$goodsId)
+            ->where('del',0)
+            ->where('status','=',1)
+            ->find();
+        if($refund){
+            $is=2;//显示退款成功
+            $is_name = '退款成功';
+        }
+        $refund = Db::name('wx_orders_refund')
+            ->where('order_id',$orderId)
+            ->where('goods_id',$goodsId)
+            ->where('del',0)
+            ->where('status','=',2)
+            ->find();
+        if($refund){
+            $is=3;//显示退款拒绝
+            $is_name = '退款拒绝';
+        }
+        $refund = Db::name('wx_orders_refund')
+            ->where('del',0)
+            ->where('order_id',$orderId)
+            ->where('goods_id',$goodsId)
+            ->where('status','=',0)
+            ->find();
+        if($refund){
+            $is=4;//显示审核处理中
+            $is_name = '退款处理中';
+        }
+        return ['is'=>$is,'refund_status_name'=>$is_name];
+    }
+    public function checkGoodsRefund($orderId,$goodsId){
+        $goodsList = Db::name('wx_orders_goods')
+            ->alias('og')
+            ->field('og.nums as num,og.price,og.goods_id,g.title,g.img,g.label,o.status')
+            ->join('wx_goods g', 'g.id=og.goods_id')
+            ->join('wx_orders o', 'og.order_id=o.id')
+            ->where('og.order_id', $orderId)
+            ->where('g.id', $goodsId)
+            ->find();
+        $is = 0;//不显示
+        $is_name = '';//不显示
+        $refund = Db::name('wx_orders_refund')
+            ->where('del',0)
+            ->where('order_id',$orderId)
+            ->where('goods_id',$goodsId)
+           // ->where('status','in',[0,1])
+            ->find();
+        if(!$refund  && in_array($goodsList['status'],[1,2])){
+            $is=1;//显示申请退款
+            $is_name = '申请退款';
+        }
+        $refund = Db::name('wx_orders_refund')
+            ->where('del',0)
+            ->where('order_id',$orderId)
+            ->where('goods_id',$goodsId)
+            ->where('status','=',1)
+            ->find();
+        if($refund){
+            $is=2;//显示退款成功
+            $is_name = '退款成功';
+        }
+        $refund = Db::name('wx_orders_refund')
+            ->where('del',0)
+            ->where('order_id',$orderId)
+            ->where('goods_id',$goodsId)
+            ->where('status','=',2)
+            ->find();
+        if($refund){
+            $is=3;//显示退款拒绝
+            $is_name = '退款拒绝';
+        }
+        $refund = Db::name('wx_orders_refund')
+            ->where('del',0)
+            ->where('order_id',$orderId)
+            ->where('goods_id',$goodsId)
+            ->where('status','=',0)
+            ->find();
+        if($refund){
+            $is=4;//显示审核处理中
+            $is_name = '退款处理中';
+        }
+        return ['is'=>$is,'refund_status_name'=>$is_name];
+    }
+    public function getRefundGoodsNum($goodsId,$orderId){
+        $refund = Db::name('wx_orders_refund')
+            ->where('del',0)
+            ->where('order_id',$orderId)
+            ->where('goods_id',$goodsId)
+           // ->where('status','=',3)
+            ->sum('num');
+        return $refund?$refund:0;
+    }
+    public function accomplish($ordersId){
+        $data=[
+            'status'=>2,
+            'finish_time'=>date('Y-m-d H:i:s'),
+        ];
+        $ret = Db::name('g_orders')->where('id', $ordersId)->update($data);
+        return $ret;
+    }
+
+    public function refundOrder($userId){
+        $id = input('id/d',0);
+        $data = [
+            'money' => input('money/f',0),
+            'status' => input('status/d',0),
+            'remark' => input('remark','','trim'),
+            'deal_user_id'=>$userId,
+            'deal_time'=>getTime(),
+        ];
+        if($data['money'] <= 0){
+            $this->error = '金额必须大于0';
+            return false;
+        }
+        $pay = Db::name('wx_orders_refund')
+            ->where('del',0)
+            ->where('id',$id)->find();
+        if(!$pay||$pay['status'] != 0){
+            $this->error = '申请单不存在';
+            return false;
+        }
+        if(!in_array($data['status'],[1,2])){
+            $this->error = '参数错误';
+            return false;
+        }
+        $sn = get_unique_id('TPH');
+        if($data['money'] > $pay['amount']){
+            $this->error = '退款金额过大';
+            return false;
+        }
+
+        Db::startTrans();
+        try{
+
+            $order = Db::name('wx_orders_refund')
+                ->where('del',0)
+                ->where('id',$pay['id'])
+                ->lock(true)
+                ->find();
+            if(!$order){
+                \exception('订单不存在');
+            }
+            if($data['status']==2){
+                $data['money'] = 0;
+            }
+            $ret = Db::name('wx_orders_refund')
+                ->where('id',$pay['id'])->update($data);
+            if(!$ret){
+                \exception('操作失败');
+            }
+            if($data['status']==1){
+                $orderInfo = Db::name('wx_orders')
+                    ->where('id',$pay['order_id'])
+                    ->find();
+                $r = Db::name('wx_orders')
+                    ->where('id',$pay['order_id'])
+                    ->setInc('refund_money',$data['money']);
+                if(!$r){
+                    \exception('修改退款金额失败');
+                }
+                $config = config('app.wx_mini_config');
+                $app = \EasyWeChat\Factory::payment($config);
+                $ret = $app->refund->byOutTradeNumber($orderInfo['order_sn'], $sn, $orderInfo['amount']*100, $data['money']*100);
+                if($ret['return_code'] != 'SUCCESS' || $ret['result_code'] != 'SUCCESS'){
+                    trace(json_encode($ret));
+                    \exception('退款申请提交失败');
+                }
+
+            }
+
+            Db::commit();
+            return true;
+        }catch (\Exception $e){
+            Db::rollback();
+            trace($e->getMessage());
+            $this->error = $e->getMessage();
+            return false;
+        }
+
+    }
+
+
+    public function formatOrder($ids){
+        $list = [];
+        $total = 0;
+        $isWater = 0;
+        $cash_price = 0;
+        $remark = [];
+        $totalNum = 0;
+        foreach ($ids as $k=>$v){
+            $ret=Db::name('wx_goods')
+                ->field('price,id as goods_id,title,img,label,barrel_id')
+                ->where('id','=',$v['id'])
+                ->find();
+            $ret['label_name'] = $ret['label']>0?Db::name('wx_goods_label')
+                ->where('id',$ret['label'])
+                ->value('title'):"";
+            $ret['num'] = $v['num'];
+            $total+=$v['num']*$ret['price'];
+            $totalNum+=$v['num'];
+            if($ret['barrel_id'] >0){
+                $isWater = 1;
+                $wx_barrel = Db::name('wx_barrel')
+                    ->where('id',$ret['barrel_id'])
+                    ->find();
+                $cash_price+=$wx_barrel['cash_price']*$v['num'];
+                $remark[] =$ret['title'].'押金:'.$wx_barrel['cash_price']*$v['num'];
+            }
+            $list[] = $ret;
+        }
+        $data = [
+            'list'=>$list,
+            'goodsNum'=>count($list),
+            'totalNum'=>$totalNum,
+            'isWater'=>$isWater,
+            'remark'=>$remark?implode(';',$remark):"",
+            'cash_price'=>sprintf("%01.2f", $cash_price),
+            'total'=>sprintf("%01.2f", $total),
+        ];
+        return $data;
+    }
+
+    public function buyBarrel($orgId,$userId,$id,$num){
+        $info = Db::name('wx_barrel')
+            ->where('id',$id)
+            ->where('enable',1)
+            ->where('del',0)
+            ->find();
+        if(empty($info)){
+            HelpHander::error('空桶不存在');
+        }
+        $params = [
+            'sn'=>get_unique_id(),
+            'user_id'=>$userId,
+            'barrel_id'=>$id,
+            'org_id'=>$orgId,
+            'num'=>$num,
+            'amount'=>$num*$info['cash_price'],
+            'create_time'=>getTime()
+        ];
+        $res = Db::name('wx_cash_pay_log')
+            ->insertGetId($params);
+        return $res;
+
+    }
+    public function refundBarrel($orgId,$userId,$id,$num){
+
+        $cash = Db::name('wx_cash')
+            ->where('id',$id)
+            ->find();
+        if($cash['num'] <$num){
+            HelpHander::error('超出退款数量');
+        }
+        Db::startTrans();
+        try{
+
+            $params = [
+                'sn'=>get_unique_id(),
+                'user_id'=>$userId,
+                'barrel_id'=>$cash['barrel_id'],
+                'org_id'=>$orgId,
+                'num'=>$num,
+                'amount'=>$num*$cash['price'],
+                'create_time'=>getTime(),
+                'cash_id'=>$id
+            ];
+            $res = Db::name('wx_cash')
+                ->where('id',$cash['id'])
+                ->setDec('num',$num);
+            Db::name('wx_cash')
+                ->where('id',$cash['id'])
+                ->setDec('amount',$num*$cash['price']);
+            if(!$res){
+                \exception('操作失败1');
+            }
+            $res = Db::name('wx_cash_refund')
+                ->insertGetId($params);
+            Db::commit();
+            return $res;
+        }catch (Exception $e){
+            Db::rollback();
+            HelpHander::error($e->getMessage());
+        }
+    }
+    public function checkoutApplyRefund($userId,$orgId,$type,$orderId,$goodsId){
+        if(empty($orderId)){
+            $this->error='参数错误';
+            return false;
+        }
+        if($type==0 && empty($goodsId)){
+            $this->error='参数错误';
+            return false;
+        }
+        if($type==0){
+            $goodsList = Db::name('wx_orders_goods')
+                ->alias('og')
+                ->field('og.nums as num,og.price,og.goods_id,g.title,g.img,g.label')
+                ->join('wx_goods g', 'g.id=og.goods_id')
+                ->where('og.order_id', $orderId)
+                ->where('og.goods_id', $goodsId)
+                ->select();
+        }else{
+            $goodsList = Db::name('wx_orders_goods')
+                ->alias('og')
+                ->field('og.nums as num,og.price,og.goods_id,g.title,g.img,g.label')
+                ->join('wx_goods g', 'g.id=og.goods_id')
+                ->where('og.order_id', $orderId)
+                ->select();
+        }
+        foreach ($goodsList as $k=>$v){
+            //$rNum = $this->getRefundGoodsNum($v['goods_id'],$orderId);
+            //$goodsList[$k]['refund_num'] = $v['num']-$rNum;
+           // $goodsList[$k]['refund_num'] = $v['num'];
+            $goodsList[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
+                ->where('id',$v['label'])
+                ->value('title'):"";
+            $flag= Db::name('wx_orders_refund')
+                ->where('del',0)
+                ->where('goods_id',$v['goods_id'])
+                ->where('order_id',$orderId)
+                ->find();
+            if($flag){
+                unset($goodsList[$k]);
+            }
+        }
+
+
+        return $goodsList;
+    }
+
+    public function checkoutApplyRefund1($orderId,$goodsId){
+        if(empty($orderId)){
+            $this->error='参数错误';
+            return false;
+        }
+        if(empty($goodsId)){
+            $this->error='参数错误';
+            return false;
+        }
+        $goodsList = Db::name('wx_orders_goods')
+            ->alias('og')
+            ->field('og.nums as num,og.price,og.goods_id,g.title,g.img,g.label')
+            ->join('wx_goods g', 'g.id=og.goods_id')
+            ->where('og.order_id', $orderId)
+            ->where('og.goods_id', 'in',explode(',',$goodsId))
+            ->select();
+        foreach ($goodsList as $k=>$v){
+            //$rNum = $this->getRefundGoodsNum($v['goods_id'],$orderId);
+            //$goodsList[$k]['refund_num'] = $v['num']-$rNum;
+            // $goodsList[$k]['refund_num'] = $v['num'];
+            $goodsList[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
+                ->where('id',$v['label'])
+                ->value('title'):"";
+            $flag= Db::name('wx_orders_refund')
+                ->where('del',0)
+                ->where('goods_id',$v['goods_id'])
+                ->where('order_id',$orderId)
+                ->find();
+            if($flag){
+                unset($goodsList[$k]);
+            }
+        }
+
+
+        return $goodsList;
+    }
+    public function addApplyRefund($userId,$orgId,$goodsJson,$orderId,$remark){
+        if(empty($orderId)){
+            $this->error='参数错误3';
+            return false;
+        }
+        if(empty($goodsJson)){
+            $this->error='参数错误2';
+            return false;
+        }
+        $goodsList = json_decode($goodsJson,'true');
+        if(empty($goodsList)){
+            $this->error='参数错误1';
+            return false;
+        }
+        if(!$this->checkOrderRefund($orderId)){
+            $this->error='当前订单不能申请退款';
+            return false;
+        }
+        foreach ($goodsList as $k=>$v){
+            $flag= Db::name('wx_orders_refund')
+                ->where('del',0)
+                ->where('goods_id',$v['id'])
+                ->where('order_id',$orderId)
+                ->find();
+            if(!$flag){
+                $wx_orders_goods = Db::name('wx_orders_goods')
+                    ->where('order_id',$orderId)
+                    ->where('goods_id',$v['id'])
+                    ->find();
+                $goodsInfo = Db::name('wx_goods')
+                    ->where('id',$v['id'])
+                    ->find();
+                if(empty($goodsInfo)){
+                    $this->error='商品不存在';
+                    return false;
+                }
+                if($v['num'] >$wx_orders_goods['nums']){
+                    $this->error=$goodsInfo['title'].'退款数量超过购买数量';
+                    return false;
+                }
+                $a[] = [
+                    'sn'=>get_unique_id(),
+                    'order_id'=>$orderId,
+                    'goods_id'=>$v['id'],
+                    'amount'=>$v['num']*$wx_orders_goods['price'],
+                    'num'=>$v['num'],
+                    'reason'=>$remark,
+                    'user_id'=>$userId,
+                    'org_id'=>$orgId,
+                    'create_time'=>getTime(),
+                ];
+            }
+        }
+        if(empty($a)){
+            $this->error = '没有符合退款条件的商品';
+            return false;
+        }
+        $res =Db::name('wx_orders_refund')
+            ->insertAll($a);
+        if(!$res){
+            $this->error = '操作失败';
+            return false;
+        }
+        $data = [
+            'orderId'=>$orderId,
+            'goodsId'=>implode(',',array_column($a,'goods_id')),
+        ];
+        return $data;
+    }
+
+    public function orderRefundDetail($orgId,$orderId,$goodsId){
+        $map = [];
+        if($goodsId!=''){
+            $map[] = ['goods_id','in',explode(',',$goodsId)];
+        }
+        $list = Db::name('wx_orders_refund')
+            ->where('del',0)
+            ->field('order_id,goods_id,status,create_time,num')
+            ->where('order_id',$orderId)
+            ->where($map)
+            ->where('org_id',$orgId)
+            ->select();
+        $sn = Db::name('wx_orders')
+            ->where('id',$orderId)
+            ->value('order_sn');
+        foreach ($list  as $k=>&$v){
+
+            $goodsInfo = Db::name('wx_orders_goods')
+                ->alias('og')
+                ->field('og.price,g.title,g.img')
+                ->join('wx_goods g', 'g.id=og.goods_id')
+                ->where('og.order_id', $orderId)
+                ->where('g.id', $v['goods_id'])
+                ->find();
+            $v['price'] = $goodsInfo['price'];
+            $v['title'] = $goodsInfo['title'];
+            $v['img'] = $goodsInfo['img'];
+            $v['statusName'] = $this->rStatus[$v['status']];
+        }
+        return ['list'=>$list,'sn'=>$sn];
+     }
+
+    public function goodsRefundDetail($orgId,$orderId,$goodsId){
+
+        $v = Db::name('wx_orders_refund')
+            ->field('deal_user_id,user_id,order_id,goods_id,status,create_time,num,amount,reason,deal_time,money,remark')
+            ->where('order_id',$orderId)
+            ->where('goods_id',$goodsId)
+            ->where('del',0)
+            ->where('org_id',$orgId)
+            ->find();
+
+        $goodsInfo = Db::name('wx_orders_goods')
+            ->alias('og')
+            ->field('og.price,g.title,g.img')
+            ->join('wx_goods g', 'g.id=og.goods_id')
+            ->where('og.order_id', $orderId)
+            ->where('g.id', $goodsId)
+            ->find();
+        $v['order_sn'] = Db::name('wx_orders')
+            ->where('id',$orderId)
+            ->value('order_sn');
+        $v['user_name'] = Db::name('wxuser')
+            ->where('id',$v['user_id'])
+            ->value('nickname');
+
+        $v['deal_user_name'] = Db::name('user')
+            ->where('id',$v['deal_user_id'])
+            ->value('real_name');
+        $v['goods'] = [
+            'price'=>$goodsInfo['price'],
+            'title'=>$goodsInfo['title'],
+            'img'=>$goodsInfo['img'],
+            'num'=>$v['num'],
+        ];
+        $v['statusName'] = $this->rStatus[$v['status']];
+        $v['deal_time'] =  $v['deal_time']? $v['deal_time']:'';
+        unset($v['num']);
+        return $v;
+     }
+
+     public function orderRefund($userId,$orgId){
+        $params = input('num',[]);
+        $orderId = input('id/d',0);
+        $reason = input('reason','');
+         if(empty($orderId)){
+             $this->error='参数错误3';
+             return false;
+         }
+         if(empty($params)){
+             $this->error='参数错误2';
+             return false;
+         }
+         if(!$this->checkOrderRefund($orderId)){
+             $this->error='当前订单不能申请退款';
+             return false;
+         }
+         $goodsList = [];
+         foreach ($params as $k=>$v){
+             $goodsList[] = [
+                 'id'=>$k,
+                 'num'=>$v,
+             ];
+         }
+         if(empty($goodsList)){
+             $this->error='参数错误1';
+             return false;
+         }
+         $total = 0;
+         foreach ($goodsList as $k=>$v){
+             $flag= Db::name('wx_orders_refund')
+                 ->where('del',0)
+                 ->where('goods_id',$v['id'])
+                 ->where('order_id',$orderId)
+                 ->find();
+             if(!$flag){
+                 $wx_orders_goods = Db::name('wx_orders_goods')
+                     ->where('order_id',$orderId)
+                     ->where('goods_id',$v['id'])
+                     ->find();
+                 $goodsInfo = Db::name('wx_goods')
+                     ->where('id',$v['id'])
+                     ->find();
+                 if(empty($goodsInfo)){
+                     $this->error='商品不存在';
+                     return false;
+                 }
+                 if($v['num'] >$wx_orders_goods['nums']){
+                     $this->error=$goodsInfo['title'].'退款数量超过购买数量';
+                     return false;
+                 }
+                 $m = $v['num']*$wx_orders_goods['price'];
+                 $a[] = [
+                     'sn'=>get_unique_id(),
+                     'order_id'=>$orderId,
+                     'goods_id'=>$v['id'],
+                     'amount'=>$m,
+                     'num'=>$v['num'],
+                     'reason'=>$reason,
+                     'user_id'=>$userId,
+                     'org_id'=>$orgId,
+                     'status'=>1,
+                     'money'=>$m,
+                     'create_time'=>getTime(),
+                 ];
+                 $total+=$m;
+             }
+         }
+         if(empty($a)){
+             $this->error = '没有符合退款条件的商品';
+             return false;
+         }
+         Db::startTrans();
+         try{
+             $res =Db::name('wx_orders_refund')
+                 ->insertAll($a);
+             if(!$res){
+                \exception( '操作失败');
+             }
+             $orderInfo = Db::name('wx_orders')
+                 ->where('id',$orderId)
+                 ->find();
+             $r = Db::name('wx_orders')
+                 ->where('id',$orderId)
+                 ->setInc('refund_money',$total);
+             if(!$r){
+                 \exception('修改退款金额失败');
+             }
+             $sn = get_unique_id('TPH');
+             $config = config('app.wx_mini_config');
+             $app = \EasyWeChat\Factory::payment($config);
+             $ret = $app->refund->byOutTradeNumber($orderInfo['order_sn'], $sn, $orderInfo['amount']*100, $total*100);
+             if($ret['return_code'] != 'SUCCESS' || $ret['result_code'] != 'SUCCESS'){
+                 trace(json_encode($ret));
+                 \exception('退款申请提交失败');
+             }
+
+             Db::commit();
+             return true;
+         }catch (Exception $e){
+             Db::rollback();
+             $this->error = $e->getMessage();
+             return false;
+         }
+
+     }
+}
+

+ 42 - 0
application/common/validate/WxBarrel.php

@@ -0,0 +1,42 @@
+<?php
+namespace app\common\validate;
+
+use think\Validate;
+use think\Db;
+class WxBarrel extends Validate{
+
+    protected $rule = [
+        'title|名称'  =>  'require|length:1,30',
+        'cash_price|押金'  =>  'require|gt:0',
+        'path|图片'  =>  'require',
+    ];
+
+    /**
+     * 定义错误信息
+     * 格式:'字段名.规则名' =>  '错误信息'
+     *
+     * @var array
+     */
+    protected $message = [];
+
+    protected function checkUnique($value, $rule, $data=[]){
+        if(isset($data['id']) && $data['id'] > 0){
+            $ret = Db::name('wx_barrel')
+                ->where('title',$data['title'])
+                ->where('org_id',$data['org_id'])
+                ->where('id','<>',$data['id'])
+                ->where('del',0)
+
+                ->find();
+        }else{
+            $ret = Db::name('wx_barrel')
+                ->where('title',$data['title'])
+                ->where('org_id',$data['org_id'])
+                ->where('del',0)
+
+                ->find();
+        }
+
+        return $ret?'名称已被使用':true;
+    }
+}

+ 42 - 0
application/common/validate/WxGoods.php

@@ -0,0 +1,42 @@
+<?php
+namespace app\common\validate;
+
+use think\Validate;
+use think\Db;
+class WxGoods extends Validate{
+
+    protected $rule = [
+        'title|商品名称'  =>  'require|length:1,20|checkUnique',
+        'img|商品图片'  =>  'require',
+        'imgs|宣传图'  =>  'require',
+        'price|商品价格'  =>  'require',
+//        'stock|库存'  =>  'require',
+        'cate_id|商品分类'  =>  'require|gt:0',
+        'content|详情'  =>  'require',
+    ];
+
+    protected $message = [
+        'cate_id.require'=>'商品分类不能为空',
+        'cate_id.gt'=>'商品分类不能为空'
+    ];
+
+    protected function checkUnique($value, $rule, $data=[]){
+        if(isset($data['id']) && $data['id'] > 0){
+            $ret = Db::name('wx_goods')
+                ->where('del',0)
+                ->where('title',$data['title'])
+                ->where('org_id',$data['org_id'])
+                ->where('id','<>',$data['id'])
+                ->find();
+        }else{
+            $ret = Db::name('wx_goods')
+                ->where('del',0)
+                ->where('title',$data['title'])
+                ->where('org_id',$data['org_id'])
+                ->find();
+        }
+
+        return $ret?'名称已被使用':true;
+    }
+
+}

+ 39 - 0
application/common/validate/WxGoodsCate.php

@@ -0,0 +1,39 @@
+<?php
+namespace app\common\validate;
+
+use think\Validate;
+use think\Db;
+class WxGoodsCate extends Validate{
+
+    protected $rule = [
+        'title|名称'  =>  'require|length:1,30',
+        'path|分类图片'  =>  'require',
+    ];
+
+    /**
+     * 定义错误信息
+     * 格式:'字段名.规则名' =>  '错误信息'
+     *
+     * @var array
+     */
+    protected $message = [];
+
+    protected function checkUnique($value, $rule, $data=[]){
+        if(isset($data['id']) && $data['id'] > 0){
+            $ret = Db::name('wx_goods_cate')
+                ->where('title',$data['title'])
+                ->where('org_id',$data['org_id'])
+                ->where('id','<>',$data['id'])
+                ->where('del',0)
+                ->find();
+        }else{
+            $ret = Db::name('wx_goods_cate')
+                ->where('title',$data['title'])
+                ->where('org_id',$data['org_id'])
+                ->where('del',0)
+                ->find();
+        }
+
+        return $ret?'名称已被使用':true;
+    }
+}

+ 22 - 0
application/common/validate/WxNotice.php

@@ -0,0 +1,22 @@
+<?php
+namespace app\common\validate;
+
+use think\Validate;
+use think\Db;
+class WxNotice extends Validate{
+
+    protected $rule = [
+        'title|名称'  =>  'require',
+        'content|内容'  =>  'require',
+    ];
+
+    /**
+     * 定义错误信息
+     * 格式:'字段名.规则名' =>  '错误信息'
+     *
+     * @var array
+     */
+    protected $message = [];
+
+
+}