OrderController.php 2.4 KB
<?php
/**
 * Created by PhpStorm.
 * auther: sgj
 * Date: 2019/1/19
 * Time: 15:17
 */

namespace app\admin\controller;


use app\admin\model\OrderModel;
use cmf\controller\AdminBaseController;
use think\Request;


/**
 * Class OrderController
 * @package app\admin\controller
 * @adminMenuRoot(
 *     'name'   => '订单列表',
 *     'action' => 'default',
 *     'parent' => '',
 *     'display'=> true,
 *     'order'  => 10000,
 *     'icon'   => '',
 *     'remark' => '管理组'
 * )
 */
class OrderController extends AdminBaseController
{
    /**
     *订单列表
     * @adminMenu(
     *     'name'   => '订单列表',
     *     'parent' => 'default',
     *     'display'=> true,
     *	   'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '订单列表',
     *     'param'  => ''
     * )
     */
    public function index(){
        $Order=new OrderModel();
        $map['o.delete_time']=null;
        $list=$Order->alias('o')
            ->field('o.*,u.user_login,u.avatar,g.name')
            ->join('user u','u.id=o.user_id')
            ->join('goods g','g.id=o.good_id')
            ->where($map)
            ->order('id','desc')
            ->paginate('20');
        $page = $list->render();
        $this->assign('list',$list);
        $this->assign('page',$page);
        return   $this->fetch();
    }

    public function orderDelete(){
        $id=input('id');
        $delete['delete_time']=time();
        $result=db('order')->where('id',$id)->update($delete);
        if ($result==1){
            $this->success('操作成功!');
        }else{
            $this->error('操作失败!');
        }
    }

    public function orderDetail(){
        $map['o.id']=input('id');
        $info=db('order')
            ->alias('o')
            ->field('o.*,u.user_login,u.avatar,g.name')
            ->join('user u','u.id=o.user_id')
            ->join('goods g','g.id=o.good_id')
            ->where($map)
            ->find();
        $this->assign('info',$info);
        return $this->fetch();
    }

    public function orderEdit(){
        $map['id']=input('good_id');
        $data=input();
        unset($data['good_id']);
        $result=db('order')->where($map)->update($data);
        if ($result==1){
            $this->success('编辑成功!');
        }else{
            $this->error('编辑失败!');
        }
    }

}