tp6框架的销售统计系统

Order.php 5.3KB

    <?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; use app\model\Company as CompanyModel; use app\model\Seller as SellerModel; 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('',[ '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'])); if (!$order){ throw new \think\exception\HttpException(404, '页面参数不正确'); } } 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_id = $param['company_id']; $order->seller_id = $param['seller_id']; $order->consignor = $param['consignor']; $order->fare = int_money($param['fare']); $order->agency = int_money($param['agency']); $order->remark = $param['remark']; $order->payment = int_money($param['payment']); $order->pay_type = $param['pay_type']; $order->pay_time = $param['pay_time']? :'0000-00-00'; $order->save(); } catch (\Exception $e) { $this->error($e->getMessage()); } $this->success('操作成功', '/order/lists/'.$year); } 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_id' => 0, 'seller_id' => 0, 'consignor' => '', 'fare' => 0, 'agency' => 0, 'pay_type'=> '', 'payment'=> 0, 'pay_time'=> '', 'remark' => '', ]; } $sellers = SellerModel::column('name', 'id'); $companies = CompanyModel::column('name', 'id'); return View::fetch('',[ 'data' => $data, 'year' => $year, 'sellers' => $sellers, 'companies' => $companies ]); } } public function delete($id) { if ($this->request->isPost()) { if ($this->model->destroy($id)) { return json(['code'=>2]); } else { return json(['code'=>0]); } } } public function cancel($id) { if ($this->request->isPost()) { if (OrderModel::update(['status' => -1, 'id' => $id])) { return json(['code'=>2]); } else { return json(['code'=>0]); } } } public function restore($id) { if ($this->request->isPost()) { if (OrderModel::update(['status' => 0, 'id' => $id])) { return json(['code'=>2]); } else { return json(['code'=>0]); } } } }