SubscribeController.php 2.9 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/4
 * Time: 9:09
 */

namespace app\admin\controller;


use cmf\controller\AdminBaseController;
use think\Db;
use think\Validate;

class SubscribeController extends AdminBaseController
{
    //首页列表
    public function index()
    {
        $where['r.delete_time'] = ['eq',0];
        $param = $this->request->param();
        //接收时间并判断
        $startTime = empty($param['start_time']) ? '' : strtotime($param['start_time']);
        $endTime = empty($param['end_time']) ? '' : (strtotime($param['end_time']));
        if (!empty($startTime) && !empty($endTime)) {
            $where['r.create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
        } else {
            if (!empty($startTime)) {
                $where['r.create_time'] = ['>= time', $startTime];
            }
            if (!empty($endTime)) {
                $where['r.create_time'] = ['<= time', $endTime];
            }
        }
        //查询回收订单表
        $data = Db::name('subscribe')
            ->alias('r')
            ->join('user u','r.user_id = u.id')
            ->field('r.*,u.user_nickname')
            ->where($where)
            ->order('r.id desc')
            ->paginate(10);
        $list=$data->items();
        $this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
        $this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
        $this->assign([
            'data'=>$list,
            'page'=>$data->render(),
        ]);
        return $this->fetch();
    }

    //订单详情
    public function detail()
    {
        $id = $this->request->param('id');
        $param = $this->request->param();
        $data = Db::name('subscribe')
            ->alias('r')
            ->join('user u','r.user_id = u.id')
            ->field('r.*,u.user_nickname')
            ->where('r.id',$id)
           ->find();
        $address = Db::name('recycle')->where('id',$data['recycle_id'])->find();
        $attr_id = explode(',',$data['attr_id']);
        $data['attr_id'] = [];
        foreach ($attr_id as &$v){
            $merge = Db::name('attr')
                ->alias('a')
                ->join('rgoods r','a.rgoods_id = r.id')
                ->field('a.attr_name,r.rgoods_name')
                ->where('a.id',$v)
                ->find();
            $attr = $merge['rgoods_name'].','.$merge['attr_name'];
            array_push($data['attr_id'],$attr);
        }
        $data['name'] = $address['name'];
        $data['phone'] = $address['phone'];
        $data['address'] = $address['address'];
        $this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
        $this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
        $this->assign('data',$data);
        return $this->fetch();
    }
}