tp6框架的销售统计系统

Order.php 4.1KB

    <?php namespace app\controller; use think\App; use think\facade\View; use app\model\Order as OrderModel; use app\model\OrderItem as OrderItemModel; use app\model\OrderDetails as OrderDetailsModel; use app\model\Department as DepartmentModel; use think\facade\Db; class Order extends Base { protected $model; protected $itemModel; protected $detailsModel; public function __construct(App $app) { parent::__construct($app); $this->model = new OrderModel(); $this->itemModel = new OrderItemModel(); $this->detailsModel = new OrderDetailsModel(); } public function index() { return View::fetch(); } public function lists($year=0, $month=0, $key="") { $map = []; if ($year) { $map[] = ['year','=', $year]; } if ($key) { $map[] = ['company_name','LIKE', '%'.$key.'%']; } if ($month) { $map[] = ['month','=', $month]; } $limit = $this->request->cookie('limit') ? : 50; $list = $this->detailsModel->where($map)->order('id')->paginate([ 'list_rows' => $limit, 'query' => $this->request->param() ]); // 统计去除已取消合同 // $map[] = ['status', '=', 0]; // $total_contract_money = $this->detailsModel->where($map)->sum('contract_money'); // $total_payment = $this->detailsModel->where($map)->sum('payment'); $page = $list->render(); // return View::fetch(); return View::fetch('',[ // 'year' => $year, 'list' => $list, 'page' => $page, // 'key' => $key, // 'month' => $month, // 'limit' => $limit, // 'total_contract_money' => round($total_contract_money, 2), // 'total_payment' => round($total_payment, 2) ]); } public function info($id=0) { } public function save($year=0) { if ($this->request->isPost()) { $param = $this->request->param(); // var_dump($param); // exit; try { if ($param['id']) { $order = $this->model->find(intval($param['id'])); } else { $order = new OrderModel(); $order->create_time = time(); } $order->no = $param['no']; $order->contract_no = $param['contract_no']; $order->contract_time = $param['contract_time']; $order->company_name = $param['company_name']; $order->department_name = $param['department_name']; $order->seller_name = $param['seller_name']; $order->consignor = $param['consignor']; $order->fare = $param['fare']; $order->agency = $param['agency']; $order->remark = $param['remark']; $order->save(); } catch (\Exception $e) { $this->error($e->getMessage()); } $this->success('操作成功', 'seller/index'); } else { $id = $this->request->has('id','route') ? intval($this->request->param('id')) : 0; if ($id) { $data = $this->model->find($id); } else { $data = [ 'id' => '0', 'no' => '', 'contract_no' => '', 'contract_time' => '', 'company_name' => '', 'department_name' => '', 'seller_name' => '', 'consignor' => '', 'fare' => '0.00', 'agency' => '0.00', 'remark' => '', ]; } return View::fetch('',[ 'data' => $data, 'year' => $year ]); } } public function delete($id) { if ($this->model->destroy($id)) { return json(['code'=>2]); } else { return json(['code'=>0]); } } }