AdminGoodsOrderController.php 4.5 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author:kane < chengjin005@163.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

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

/**
 * Class AdminGoodsOrderController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'订单管理',
 *     'action' =>'default',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 30,
 *     'icon'   =>'th',
 *     'remark' =>'订单管理'
 * )
 */
class AdminGoodsOrderController extends AdminBaseController
{
    /**
     * 订单列表
     * @adminMenu(
     *     'name'   => '订单列表',
     *     'parent' => 'portal/AdminGoodsOrder/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '订单列表',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        //接收搜索参数
        $param = $this->request->param();
        //添加搜索条件
        $where = [];
        $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.published_time'] = [['>= time', $startTime], ['<= time', $endTime]];
        } else {
            if (!empty($startTime)) {
                $where['go.create_time'] = ['>= time', $startTime];
            }
            if (!empty($endTime)) {
                $where['go.create_time'] = ['<= time', $endTime];
            }
        }
        $order_sn = empty($param['order_sn']) ? '' : $param['order_sn'];
        if (!empty($order_sn)) {
            $where['go.order_sn'] = ['like', "%$order_sn%"];
        }
        $status = empty($param['status']) ? '' : $param['status'];
        if (!empty($status)) {
            $where['go.status'] = $status;
        }
        $user_nickname = empty($param['user_nickname']) ? '' : $param['user_nickname'];
        if (!empty($user_nickname)) {
            $where['u.user_nickname'] = ['like', "%$user_nickname%"];
        }
        $mobile = empty($param['mobile']) ? '' : $param['mobile'];
        if (!empty($mobile)) {
            $where['u.mobile'] = ['like', "%$mobile%"];
        }
        $data = Db::name('goods_order')
            ->alias('go')
            ->join('goods g','go.goods_id=g.id')
            ->join('user u','go.user_id=u.id')
            ->join('address a','go.address_id=a.id')
            ->where($where)
            ->field('*,go.create_time as gcreate_time,go.id as goid,go.status as gostatus')
            ->order('go.create_time', 'desc')
            ->paginate('10');
        //向地址传参
        $data->appends($param);

        $this->assign('page', $data->render());
        $this->assign('start_time', $startTime);
        $this->assign('end_time', $endTime);
        $this->assign('order_sn', $order_sn);
        $this->assign('status', $status);
        $this->assign('user_nickname', $user_nickname);
        $this->assign('mobile', $mobile);
        $this->assign('list', $data);
        return $this->fetch();
    }


    public function fahuo(){
        $param=$this->request->param();
        Db::name('goods_order')->where('id',$param['id'])->update(['status'=>2]);
        $this->success('发货成功');
    }


    /**
     * 删除订单
     * @adminMenu(
     *     'name'   => '删除订单',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除订单',
     *     'param'  => ''
     * )
     */
    public function delete()
    {
        $param=$this->request->param();
        if (!empty($param['ids'])){
            Db::name('goods_order')->where(['id' => ['in', $param['ids']]])->delete();
            $this->success('删除成功');
        }
        Db::name('goods_order')->where('id', $param['id'])->delete();
        $this->success('删除成功');
    }

}