| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace app\admin\controller\stock;
- use app\common\controller\Backend;
- /**
- * 商品库存
- *
- * @icon fa fa-circle-o
- */
- class Stockcur extends Backend {
- /**
- * StockStockcur模型对象
- * @var \app\admin\model\stock\Stockcur
- */
- protected $noNeedLogin = ['getGoodsStoknum', 'countData'];
- protected $model = null;
- public function _initialize() {
- parent::_initialize();
- $this->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 "<pre>";
- // print_r($stockinsum);
- // echo "</pre>";
- // 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);
- }
- }
- }
|