tp6框架的销售统计系统

SaleCompany.php 2.1KB

    <?php namespace app\controller; use think\App; use think\facade\View; use app\model\SaleCompany as CompanyModel; class SaleCompany extends Base { protected $model; public function __construct(App $app) { parent::__construct($app); $this->model = new CompanyModel(); } public function index($key="") { $map = []; if ($key) { $map[] = ['name','LIKE', '%'.$key.'%']; } // var_dump($map); // exit; $list = $this->model->where($map)->paginate(); $page = $list->render(); return View::fetch('',[ 'list' => $list, 'page' => $page, 'key' => $key ]); } public function save() { if ($this->request->isPost()) { $param = $this->request->param(); try { if ($param['id']) { $seller = $this->model->find(intval($param['id'])); } else { $seller = new CompanyModel(); $seller->create_time = time(); } $seller->name = $param['name']; $seller->department_id = $param['department_id']; $seller->save(); } catch (\Exception $e) { $this->error($e->getMessage()); } $this->success('操作成功', 'sale_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, 'name' => '', 'department_id' => 1, ]; } return View::fetch('', [ 'data' => $data, ]); } } public function delete($id) { if ($this->model->destroy($id)) { return json(['code'=>2]); } else { return json(['code'=>0]); } } }