|
|
@@ -5,7 +5,6 @@ namespace app\admin\controller;
|
|
|
use app\common\controller\Backend;
|
|
|
use think\Cache;
|
|
|
use think\Db;
|
|
|
-use think\Validate;
|
|
|
|
|
|
/**
|
|
|
* 生产管理
|
|
|
@@ -61,7 +60,7 @@ class Product extends Backend
|
|
|
|
|
|
foreach ($list as $row) {
|
|
|
$row->visible(['id','time','weight','material','status']);
|
|
|
-
|
|
|
+ $row['material'] = decode($row['material']);
|
|
|
}
|
|
|
$result = array("total" => $list->total(), "rows" => $list->items());
|
|
|
|
|
|
@@ -78,28 +77,68 @@ class Product extends Backend
|
|
|
$batch = $str[(count($str))-1];
|
|
|
$bach_info = Db::name('task')->where('bach',$batch)->find();
|
|
|
Cache::set('bach',serialize($bach_info),0);
|
|
|
+ $form = Db::name('formula')->find($bach_info['fid']);
|
|
|
+ $res = Db::name('formula_detail')->where('pid = '.$bach_info['fid'].' and version = "'.$form['version'].'"')->field('id,pid,material,version,is_replace')->select();
|
|
|
+ foreach($res as &$v){
|
|
|
+ if($v['is_replace']==1){
|
|
|
+ $v['replace'] = Db::name('formula_replace')->where('fid',$v['id'])->order('id','desc')->select();
|
|
|
+ }else{
|
|
|
+ $v['replace'] = [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查出所有关于批次号的数据存储
|
|
|
+ Cache::set('data',serialize($res),0);
|
|
|
return json($bach_info);
|
|
|
}
|
|
|
|
|
|
//获取配方单信息
|
|
|
public function get_formula(){
|
|
|
- $bach = unserialize(Cache::get('bach'));
|
|
|
- $formula = $this->request->post('formula');
|
|
|
- $form = Db::name('formula')->find($bach['fid']);
|
|
|
- $res = Db::name('formula_detail')->where('pid = '.$bach['fid'].' and material like "%'.$formula.'%" and version = "'.$form['version'].'"')->select();
|
|
|
+ $bach = unserialize(Cache::get('bach'));//获取配方单信息
|
|
|
+ $formula = $this->request->post('formula');//配方名称
|
|
|
+ $data = unserialize(Cache::get('data'));//获取当前批次号缓存数据
|
|
|
+ $arr = [];
|
|
|
+ $arr['material']=$formula;
|
|
|
+ foreach($data as $vv) {
|
|
|
+ //没有替代料 error==0为有当前配方, error==1为没有配方,,前台提示
|
|
|
+ if ($vv['is_replace'] == 0) {
|
|
|
+ if ($vv['material'] == $formula) {
|
|
|
+ $arr['error'] = 0;
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ $arr['error'] = 1;
|
|
|
+ }
|
|
|
+ } else {//有替代料
|
|
|
+ foreach ($vv['replace'] as $val) {
|
|
|
+ if ($val['material'] == $formula) {
|
|
|
+ $arr['error'] = 0;
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ $arr['error'] = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($arr['error'] == 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询数据库↓ 缓存↑
|
|
|
+ /*$form = Db::name('formula')->find($bach['fid']);
|
|
|
+ $res = Db::name('formula_detail')->where('pid = '.$bach['fid'].' and material like "%'.encrypt($formula).'%" and version = "'.$form['version'].'"')->select();
|
|
|
$arr = [];
|
|
|
+
|
|
|
if(!$res){
|
|
|
$arr['material'] = $formula;
|
|
|
$arr['error']=1;
|
|
|
- }
|
|
|
- foreach($res as &$v){
|
|
|
- if($v['is_replace']==1){
|
|
|
- $v['material'] = Db::name('formula_replace')->where('fid',$v['id'])->where('material',$formula)->order('id','desc')->value('material');
|
|
|
+ }else{
|
|
|
+ foreach($res as &$v){
|
|
|
+ if($v['is_replace']==1){
|
|
|
+ $v['material'] = Db::name('formula_replace')->where('fid',$v['id'])->where('material',encrypt($formula))->order('id','desc')->value('material');
|
|
|
+ }
|
|
|
+ $arr=$v;
|
|
|
+ $arr['error']=0;
|
|
|
}
|
|
|
- $arr=$v;
|
|
|
- $arr['error']=0;
|
|
|
- }
|
|
|
- $arr['pname'] = $bach['name'];
|
|
|
+ }*/
|
|
|
+ $arr['pname'] = $bach['name'];//配方名称
|
|
|
$arr['time'] = date("Y-m-d H:i:s");
|
|
|
$arr['bach'] = $bach['bach'];
|
|
|
return json($arr);
|
|
|
@@ -122,7 +161,7 @@ class Product extends Backend
|
|
|
$arr[$k]['time'] = $params['time'][$k];
|
|
|
$arr[$k]['audit'] = $params['audit'];
|
|
|
$arr[$k]['unit'] = $params['unit'][$k];
|
|
|
- $arr[$k]['material'] = $params['material'][$k];
|
|
|
+ $arr[$k]['material'] = encrypt($params['material'][$k]);
|
|
|
$arr[$k]['weight'] = $params['weight'][$k];
|
|
|
}
|
|
|
$result = $this->model->saveAll($arr);
|
|
|
@@ -130,5 +169,6 @@ class Product extends Backend
|
|
|
$this->error(__('No rows were inserted'));
|
|
|
}
|
|
|
$this->success();
|
|
|
+ return $this->view->fetch();
|
|
|
}
|
|
|
}
|