ShoporderController.php 3.5 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/5
 * Time: 11:20
 */

namespace app\admin\controller;


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

class ShoporderController extends AdminBaseController
{
    public function index()
    {
        $where['a.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['a.create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
        } else {
            if (!empty($startTime)) {
                $where['a.create_time'] = ['>= time', $startTime];
            }
            if (!empty($endTime)) {
                $where['a.create_time'] = ['<= time', $endTime];
            }
        }
        $data = Db::name('shoporder')
            ->alias('a')
            ->join('shopgoods r','a.shopgoods_id = r.id')
            ->join('user u','a.user_id = u.id')
            ->field('a.*,r.goods_name,r.price,r.freight,u.user_nickname')
            ->where($where)
            ->order('a.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 edit()
    {
        $id = $this->request->param('id');
        if($this->request->isPost()){
            $param = $this->request->param();
            if($param['status'] == 2 && empty($param['express_num'])){
                $this->error('请填写快递单号');
            }
            if(!empty($param['express_num'])){
                if(empty($param['status'] == 1)){
                    $this->error('请正确填写发货状态');
                }
            }
            if($param['status'] == 2 && empty($param['express_num'])){
                Db::name('shoporder')
                    ->where('id',$id)
                    ->update($param);
                Db::name('shoporder')
                    ->where('id',$id)
                    ->update(['orderstatus'=>2]);
                $this->success('更新成功!');
            }else{
                Db::name('shoporder')
                    ->where('id',$id)
                    ->update($param);
                $this->success('更新成功!');
            }
        }else{
            $param = $this->request->param();
            $data = Db::name('shoporder')
                ->alias('a')
                ->join('shopgoods r','a.shopgoods_id = r.id')
                ->join('user u','a.user_id = u.id')
                ->field('a.*,r.goods_name,r.price,r.freight,u.user_nickname')
                ->where('a.id',$id)
                ->find();
            $address = Db::name('shoprecycle')->where('id',$data['shoprecycle_id'])->find();
            $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();
        }
    }

}