123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?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();
- }
- }
- }
|