model = model('\app\admin\model\stock\Stockcur'); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } //当前是否为关联查询 $this->relationSearch = true; $this->searchFields = 'stockgoods.volnum,stockgoods.goodsname'; $categoryids = $this->request->request("categoryids"); $query = []; if ($categoryids !== NULL) { $query["stockgoods.goodscategoryid"] = ["in", $categoryids]; } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $total = $this->model->with('stockgoods')->field("sum(curnums) as totalcurnums")->where($where)->where($query)->group("stock_goods_id")->order($sort, $order)->count(); $list = $this->model->with('stockgoods')->field("sum(curnums) as totalcurnums")->where($where)->where($query)->group("stock_goods_id")->order($sort, $order)->limit($offset, $limit)->select(); $list = collection($list)->toArray(); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 库存首页 */ public function mainpage() { $stockinsum=\app\admin\model\stock\Stockinlist::with('stockin') ->field('IFNULL(SUM(stockinnums),0) as totalnums,IFNULL(SUM(amount),0) as totalamount') ->where('stockin.audittime','NOT NULL') ->whereTime("stockin.audittime",'today') ->select(); // echo "
";
//        print_r($stockinsum);
//        echo "
"; // die; $stockoutsum=\app\admin\model\stock\Stockoutlist::with('stockout') ->field('IFNULL(SUM(stockoutnums),0) totalnums,IFNULL(SUM(amount),0) totalamount') ->where('stockout.audittime','NOT NULL') ->whereTime("stockout.audittime",'today') ->select(); $stockcursum=\app\admin\model\stock\Stockcur::with('stockinlist') ->field('IFNULL(SUM(curnums),0) totalnums,IFNULL(SUM(stockinlist.inboundprice*curnums),0) totalamount') ->select(); $stockin_toaudit=\app\admin\model\stock\Stockin::where('audittime','NULL')->count(); $stockout_toaudit=\app\admin\model\stock\Stockout::where('audittime','NULL')->count(); if ($this->request->isAjax()) { $stockinsum=\app\admin\model\stock\Stockinlist::field('sum(stockinnums) totalnums,sum(amount) totalamount')->where("createtime",'today')->select(); $result = array("stockinsum" => $stockinsum); return json($result); } $this->view->assign("stockinsum", $stockinsum[0]); $this->view->assign("stockoutsum", $stockoutsum[0]); $this->view->assign("stockcursum", $stockcursum[0]); $this->view->assign("stockin_toaudit", $stockin_toaudit); $this->view->assign("stockout_toaudit", $stockout_toaudit); return $this->view->fetch(); } /** * 编辑 */ public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } $stockinmodel = model('StockStockin'); if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { try { //是否采用模型验证 if ($this->modelValidate) { $name = basename(str_replace('\\', '/', get_class($this->model))); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate; $row->validate($validate); } $id = $params['stock_stockin_id']; $allocation = $params['allocation']; $result = $stockinmodel->where('id', $id)->update(['allocation' => $allocation]); if ($result !== false) { $this->success(); } else { $this->error($row->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } $this->view->assign("row", $row); return $this->view->fetch(); } /** * 出库单,根据选定商品返回库存数 */ public function getGoodsStoknum($goodsid) { if ($this->request->isPost()) { $goodsid = $this->request->post('goodsid'); if ($goodsid) { try { $curnum = $this->model->getGoodsStoknum($goodsid); return json($curnum); } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } $this->error('只接受POST请求', ''); } /** * 库存首页统计 */ public function countData() { //当前是否为关联查询 $this->relationSearch = true; if ($this->request->isAjax()) { $total = $this->model ->group('stock_goods_id') ->count(); $list = $this->model ->with('StockGoods,Stockinlist') ->field('sum(curnums*inboundprice) totalitemamount,count(*) totalitem,sum(curnums) totalnum') ->group('goodscategoryid') ->select(); $list = collection($list)->toArray(); $result = array("total" => $total, "rows" => $list); return json($result); } } }