| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use think\Session;
- use think\Db;
- use think\Where;
- /**
- * 油墨库存管理
- *
- * @icon fa fa-circle-o
- */
- class WarehousingDetail extends Backend
- {
-
- /**
- * Warehousing模型对象
- * @var \app\admin\model\Warehousing
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\WarehousingDetail();
- $this->view->assign("isScrapList", $this->model->getIsScrapList());
- $this->view->assign("statusList", $this->model->getStatusList());
- }
-
- /**
- * 默认生成的控制器所继承的父类中有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();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $search = input('search');
- $map=array();
- if (!empty($search)){
- $map['formula'] = array('like',"%$search%");
- }
- $total = Db::name('warehousing')
- ->order('update desc')
- ->where($map)
- ->count();
- $list = Db::name('warehousing')
- ->order('update desc')
- ->where($map)
- ->limit($offset, $limit)
- ->select();
- $list = collection($list)->toArray();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- //增加库存
- public function add()
- {
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- //过滤前台传的字段
- $params = $this->preExcludeFields($params);
- // print_r($params);die;
- if (empty($params['cid'])){
- return array('status'=>0,'msg'=>'请请选择颜色');
- }
- //专色墨批次 由产品编码+时间+色号+人员编号+'-'+当日本产品第几次调墨
- //产品编码
- $product_number = $params['product_number'];
- //时间取6位
- $time = date('Ymd');
- $time = substr($time,-6);
- $user = Session::get('admin');
- $name = $user['nickname'];
- //人员编号,根据缓存的nickname确认人员编号
- $people_number = Db::name('people')->where('name',$name)->value('number');
- //色号,根据产品编码和颜色 确定它的色号
- $color_number = Db::name('formula')->where('id',$params['cid'])->value('color_number');
- $params['color'] = Db::name('formula')->where('id',$params['cid'])->value('color');
- //查这个色号当日第几次调配
- $num = Db::name('warehousing_detail')->where('product_number',$product_number)->where('cid',$params['cid'])->whereTime('create','today')->count();
- if (empty($num)){
- $color = 1;
- }else{
- $color = $num + 1;
- }
- //专色墨批次号
- $params['bach_number'] = $product_number.$time.$color_number.$people_number.'-'.$color;
- $params['weight'] = $params['weight'] * 1000;
- $params['create'] = date('Y-m-d H:i:s');
- Db::startTrans();
- try{
- $id = Db::name('warehousing_detail')->insertGetId($params);
- if (empty($id)){
- throw new Exception('插入数据失败,请联系开发人员');
- }
- $totalWeight = Db::name('warehousing')->where('product_name',$params['product_name'])->where('cid',$params['cid'])->find();
- if (!empty($totalWeight)){
- $totalWeight['weight'] = $totalWeight['weight'] + $params['weight'];
- Db::name('warehousing')->where('product_name',$params['product_name'])->where('cid',$params['cid'])->setField('weight',$totalWeight['weight']);
- Db::name('warehousing')->where('product_name',$params['product_name'])->where('cid',$params['cid'])->setField('update',date('Y-m-d H:i:s'));
- }else{
- $data = array();
- $data['weight'] = $params['weight'];
- $data['product_name'] = $params['product_name'];
- $data['product_number'] = $params['product_number'];
- $data['formula'] = $params['formula'];
- $data['cid'] = $params['cid'];
- $data['color'] = $params['color'];
- $data['update'] = date('Y-m-d H:i:s');
- Db::name('warehousing')->insert($data);
- }
- Db::commit();
- $this->success();
- }catch (\think\Exception\DbException $exception){
- Db::rollback();
- $this->error(__('No rows were inserted'));
- }
- }
- //检索数据
- $data = Db::connect('db2')->query("select 产品名称 from 产品_基本资料 where 状态 = '' ");
- $backData = array();
- foreach ($data as $key=>$value){
- $backData[$key] = trim($value['产品名称']);
- }
- return $this->view->fetch('',compact('backData'));
- }
- //查看油墨详情
- public function read(){
- $params = input('');
- $warehousing = Db::name('warehousing')->where('id', $params['ids'])->find();
- $result = Db::name('warehousing_detail')->where('cid', $warehousing['cid'])->where('status',0)->order('id desc')->select();
- return $this->view->fetch('',compact('result'));
- }
- //获取某个产品色号
- public function getColor(){
- $params = input('data');
- if (is_numeric($params)){//传递来的是产品编号
- $product_number = trim($params);
- $where[] = ['exp',Db::raw("FIND_IN_SET($product_number,product_number)")];
- $result = Db::name('formula')
- ->where($where)
- ->select();
- }else{//传递来的是产品名称
- $product = Db::connect('db2')->query("select * from 工单_基本资料 where 成品名称 = '{$params}' limit 1");
- if (empty($product)){
- return array('status'=>0,'msg'=>'MES库不存在,请重新选择产品名称');
- }
- $product_number = rtrim($product[0]['Gd_cpdh']);
- $where[] = ['exp',Db::raw("FIND_IN_SET($product_number,product_number)")];
- $result = Db::name('formula')
- ->where($where)
- ->select();
- }
- $fomulaData = array();
- foreach ($result as $key=>$value){
- $result[$key]['product_number'] = $product_number;
- $fomulaData[$key] = $value['product_name'];
- if ($key > 0){
- if ($value['product_name'] != $result[$key-1]['product_name']){
- $fomulaData[$key] = $value['product_name'];
- }else{
- unset($fomulaData[$key]);
- }
- }
- }
- if (!empty($result)){
- return array('status'=>1,'msg'=>'请求成功','data'=>$result,'formula'=>$fomulaData);
- }else{
- return array('status'=>0,'msg'=>'未查询到数据');
- }
- }
- }
|