tp6框架的销售统计系统

OrderItem.php 2.8KB

    <?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 OrderItem extends Base { protected $model; protected $orderModel; protected $detailsModel; public function __construct(App $app) { parent::__construct($app); $this->model = new OrderItemModel(); $this->orderModel = new OrderModel(); $this->detailsModel = new OrderDetailsModel(); } public function index($order_id) { $list = $this->model->where('order_id', $order_id)->select(); $orderInfo = $this->detailsModel->field('id,no,contract_no,company_name,contract_time')->find($order_id); $year = date('Y', strtotime($orderInfo->contract_time)); return View::fetch('',[ 'list' => $list, 'order_id' => $order_id, 'orderInfo' => $orderInfo, 'year' => $year, ]); } public function info($id) { $data = $this->model->find($id); if ($this->request->isAjax()) { return json(['code'=>2, 'data'=>$data]); } } public function save() { if ($this->request->isAjax()) { $param = $this->request->param(); // var_dump($param); // exit; try { if ($param['id']) { $order = $this->model->find(intval($param['id'])); } else { $order = new OrderItemModel(); } $order->order_id = intval($param['order_id']); $order->goods_category = $param['goods_category']; $order->goods_name = $param['goods_name']; $order->goods_price = $param['goods_price']; $order->sales_amount = $param['sales_amount']; $order->sales_price = $param['sales_price']; $order->actual_amount = $param['actual_amount']; $order->actual_price = $param['actual_price']; $order->agency = $param['agency']; $order->fare = $param['fare']; $order->type = intval($param['type']); $order->remark = $param['remark']; $order->save(); } catch (\Exception $e) { // $this->error($e->getMessage()); return json(['code'=>0, 'msg'=>$e->getMessage()]); } return json(['code'=>2]); } } public function delete($id) { if ($this->request->isPost()) { if ($this->model->destroy($id)) { return json(['code'=>2]); } else { return json(['code'=>0]); } } } }