|
|
@@ -5,6 +5,7 @@ namespace app\admin\controller;
|
|
|
use app\common\controller\Backend;
|
|
|
use think\Cache;
|
|
|
use think\Db;
|
|
|
+use think\Exception;
|
|
|
|
|
|
/**
|
|
|
* 生产管理
|
|
|
@@ -20,10 +21,13 @@ class Product extends Backend
|
|
|
*/
|
|
|
protected $model = null;
|
|
|
|
|
|
+ protected $detail = null;
|
|
|
+
|
|
|
public function _initialize()
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
$this->model = new \app\admin\model\Product;
|
|
|
+ $this->detail = new \app\admin\model\ProductDetail;
|
|
|
$this->view->assign("statusList", $this->model->getStatusList());
|
|
|
}
|
|
|
|
|
|
@@ -53,15 +57,9 @@ class Product extends Backend
|
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
|
|
|
$list = $this->model
|
|
|
-
|
|
|
->where($where)
|
|
|
->order($sort, $order)
|
|
|
->paginate($limit);
|
|
|
-
|
|
|
- foreach ($list as $row) {
|
|
|
- $row->visible(['id','time','weight','material','status']);
|
|
|
- $row['material'] = decode($row['material']);
|
|
|
- }
|
|
|
$result = array("total" => $list->total(), "rows" => $list->items());
|
|
|
|
|
|
return json($result);
|
|
|
@@ -152,23 +150,51 @@ class Product extends Backend
|
|
|
if (empty($params)) {
|
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
|
}
|
|
|
- $arr = [];
|
|
|
- foreach($params['material'] as $k=>$v){
|
|
|
- $arr[$k]['status'] = $params['status'];
|
|
|
- $arr[$k]['batch'] = $params['batch'][$k];
|
|
|
- $arr[$k]['pname'] = $params['pname'][$k];
|
|
|
- $arr[$k]['specifications'] = $params['specifications'][$k];
|
|
|
- $arr[$k]['time'] = $params['time'][$k];
|
|
|
- $arr[$k]['audit'] = $params['audit'];
|
|
|
- $arr[$k]['unit'] = $params['unit'][$k];
|
|
|
- $arr[$k]['material'] = encrypt($params['material'][$k]);
|
|
|
- $arr[$k]['weight'] = $params['weight'][$k];
|
|
|
- }
|
|
|
- $result = $this->model->saveAll($arr);
|
|
|
- if ($result === false) {
|
|
|
- $this->error(__('No rows were inserted'));
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $pro = [];
|
|
|
+ foreach(explode(';',$params['bach']) as $key=> $val){
|
|
|
+ if(!empty($val)){
|
|
|
+ $res = [];
|
|
|
+ $res['time'] = date("Y-m-d H:i:s");
|
|
|
+ $res['audit'] = $params['audit'][$key];
|
|
|
+ $res['status'] = $params['status'];
|
|
|
+ $res['batch'] = $val;
|
|
|
+ $res['pname'] = $params['proname'][$key];
|
|
|
+ $res['specifications'] = $params['specifications'][$key];
|
|
|
+ $res['unit'] = $params['unit'][$key];
|
|
|
+ $pro[] = $res;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach($pro as $v){
|
|
|
+ $this->model->insert($v);
|
|
|
+ $id = $this->model->getLastInsID();
|
|
|
+ $arr = [];
|
|
|
+ $prodet = [];
|
|
|
+ foreach($params['material'] as $k=>$vv){
|
|
|
+ if($v['batch']==$params['batch'][$k]){
|
|
|
+ $arr['weight'] = $params['weight'][$k];
|
|
|
+ $arr['pid'] = /*1;//*/$id;
|
|
|
+ $arr['material'] = $params['material'][$k];
|
|
|
+ $arr['createtime'] = date("Y-m-d H:i:s");
|
|
|
+ $prodet[] = $arr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->detail->saveAll($prodet);
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ }catch(Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
}
|
|
|
$this->success();
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
+ public function show($ids){
|
|
|
+ $row = $this->model->get($ids);
|
|
|
+ $row['data'] = $this->detail->where('pid',$row['id'])->select();
|
|
|
+// halt($row['data']);
|
|
|
+ $this->view->assign("row", $row);
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
}
|