model = new \app\admin\model\fastflow\bill\Tmrxyo; $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', 'trim']); if (false === $this->request->isAjax()) { return $this->view->fetch(); } //如果发送的来源是 Selectpage,则转发到 Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $bill_ids = $this->filtrateBillIds(); //halt($bill_ids); //halt($bill_ids); if (is_array($bill_ids) && empty($bill_ids)) { return ['total' => 0, 'rows' => []]; } if (is_array($bill_ids) && !empty($bill_ids)) { $this->model->where($this->model->getTable().'.id in (' . implode(',', $bill_ids) . ')')->where($this->model->getTable().'.status','<>','-1'); } $list = $this->model ->where($where)->where($this->model->getTable().'.status','<>','-1') ->order($sort, $order) ->paginate($limit); $result = ['total' => $list->total(), 'rows' => $list->items()]; return json($result); } public function add() { $aa = $this->request->param(); $token=''; if(isset($aa['token'])){ $token = $aa['token']; } $param = [ 'initiator_id'=>$this->auth->id, 'status'=>'-1', ]; $this->model->save($param); $id = $this->model->id; $this->redirect('admin\fastflow/flow/run/start?bill=ats_tmrxyo&bill_id='.$id.'&token='.$token); } /** * 编辑 */ public function edit($ids = null) { $can_edit_fields = []; $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $api = new api(); $isSuperManager = false; $admin_id = Session::get()['admin']['id']; $groupAccess = AuthGroupAccess::where('uid', $admin_id)->select(); foreach ($groupAccess as $access) { $groupId = $access['group_id']; $group = AuthGroup::find($groupId); if ($group['pid'] == 0) { $isSuperManager = true; } } $bill = Config::get('database')['prefix'] . $this->model->getName(); if (input('threadid') == null) { if (!$isSuperManager) { $bill_process = $api->getProcessByBill($bill, $row['id']); if ($bill_process) { if (input('way') == 'detail') { $can_edit_fields = []; } else { $this->error('流程审批中,您不能直接编辑该单据', ''); } } else { $agency_info = $api->checkAgency($bill, $row['id'], 1, [$row['initiator_id']]); if ($agency_info) { if (!in_array($admin_id, $agency_info['agency_workers']) && !$isSuperManager) { $this->error('您不是超级管理员或代理人,无权限编辑该单据', ''); } else { $can_edit_fields = true; } } else { if ($row['initiator_id'] != Session::get()['admin']['id'] && !$isSuperManager) { $this->error('您不是超级管理员或流程发起人,暂无权限编辑该单据', ''); } else { $can_edit_fields = true; } } } } else { $can_edit_fields = true; } } else { $can_edit_fields = (new api())->getCanEditFields($bill, $row['id'], input('threadid')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } if ($this->request->isPost()) { $params = $this->request->post("row/a"); //组合商品 //if(!empty($params['goods_id'])){ // $goods_array = []; // for($i = 0 ; $i < count($params['goods_id']); $i++) { // $goods_array[]=[ // 'goods_id'=>$params['goods_id'][$i], // 'nums'=>$params['nums'][$i], // ]; // } //}else{ // $this->error('该合同没有商品!'); //} //$amodelGoods = new AmodelGoods(); // //$bill_id = (new Contract())->where('id',$params['contract_id'])->value('bill_id'); //$price = []; //if($bill_id){ // $bywnpk_bill_id = (new \app\admin\model\fastflow\bill\Bywnpk())->where('id',$bill_id)->value('bill_id'); // $data = (new Amodela())->where('id',$bywnpk_bill_id)->find(); // $json = $this->object_array(json_decode($data['json'])); // $inster_data = []; // // foreach ($goods_array as $v){ // // $inster_data[]=[ // 'amodela_id'=>$bywnpk_bill_id, // 'tmrxyo_id'=>$row['id'], // 'goods_id'=>$v['goods_id'], // 'nums'=>$v['nums'], // 'status'=>1, // 'createtime'=>time() // ]; // $qty = $amodelGoods->where('goods_id',$v['goods_id'])->where('amodela_id',$bywnpk_bill_id)->count('nums'); // $qty = $v['nums'] + $qty; // // foreach ($json as $item){ // // //halt($item); // $price[$item['productID']] = $item['unitPrice']; // if($item['productID'] == $v['goods_id']){ // if($qty > $item['qty']){ // $msg = $item['productName'].'已超出该报价单数量'; // $this->error($msg); // } // } // } // } //}else{ // $this->error('查询不到该合同!'); //} // ////halt($price); // ////出库单数据 //$purchase_code = 'QTCK'.date('YmdHis'); //$purchase_time = time(); //$createtime = time(); //$updatetime = time(); //$admin = $this->auth->id; //$customers_id = 1; //$preparation_id = $this->auth->id; //$number = 0; // //$goodsModel = new Goods(); //foreach ($inster_data as $item){ // $number += $item['nums']; // $rres = $goodsModel->where('id',$item['goods_id'])->find(); // $wp_info_data[]= [ // 'purchase_code'=>$purchase_code, // 'purchase_time'=>$purchase_time, // 'goods_id'=>$item['goods_id'], // 'goods_attr'=>'', // 'goods_unit'=>$rres['unit_id'], // 'stores_id'=>1, // 'stock'=>$rres['inventory'], // 'number'=>$item['nums'], // 'basic_nmber'=>$item['nums'], // 'period'=>'', // 'unit_price'=>$price[$item['goods_id']], // 'price'=>$price[$item['goods_id']], // 'remark'=>'', // 'batch'=>'', // 'manufacture'=>'', // 'guarantee'=>'', // 'validity'=>'', // 'createtime'=>$createtime, // 'updatetime'=>$updatetime, // 'admin_id'=>$admin, // ]; //} //$wp_data = [ // 'purchase_code'=>$purchase_code, // 'purchase_time'=>$purchase_time, // 'business_type'=>2, // 'number'=>$number, // 'price'=>'', // 'customers_id'=>$customers_id, // 'preparation_id'=>$preparation_id, // 'remarks'=>'', // 'order_id'=>0, // 'order_type'=>'', // 'createtime'=>$createtime, // 'updatetime'=>$updatetime, // 'admin_id'=>$admin, //]; unset($params['goods_id']); unset($params['nums']); if ($params) { $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { //$rws = (new Warehouse())->insertGetId($wp_data); //Db::name('kuerp_warehouse_info')->insertAll($wp_info_data); //$amodelGoods->insertAll($inster_data); //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validateFailException(true)->validate($validate); } $result = $row->allowField($can_edit_fields === true ? true : implode(',', $can_edit_fields))->save($params); Db::commit(); } catch (ValidateException $e) { Db::rollback(); $this->error($e->getMessage()); } catch (PDOException $e) { Db::rollback(); $this->error($e->getMessage()); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success(); } else { $this->error(__('No rows were updated')); } } //4.4.1-- $this->success(); //$this->error(__('Parameter %s can not be empty', '')); //-- } $bill_fileds = $api->getFieldsWithComment($bill); $fields = []; foreach ($bill_fileds as $bill_filed) { $fields[] = $bill_filed['field']; } if ($can_edit_fields === true) { $can_edit_fields = $fields; } //halt([$fields,$can_edit_fields]); $this->assignconfig(['billFileds' => $fields, 'canEditFields' => $can_edit_fields]); //halt(['billFileds' => $fields, 'canEditFields' => $can_edit_fields]); $this->view->assign("row", $row); //halt(['billFileds' => $fields, 'canEditFields' => $can_edit_fields]); return $this->view->fetch(); } public function dateils($ids){ $row = $this->model->get($ids); $find = (new \addons\antis\model\Contract())->where('id',$row['contract_id'])->find(); $data = (new Amodela())->where('id',$find['offer_id'])->find(); if($data){ $json = json_decode($data['json']); $json = $this->object_array($json); } $amodelGoods = new AmodelGoods(); foreach ($json as &$item){ $count = $amodelGoods->where('amodela_id',$find['offer_id'])->where('goods_id',$item['productID'])->count('nums')??0; $item['nums'] = $amodelGoods->where('tmrxyo_id',$ids)->where('goods_id',$item['productID'])->value('nums'); $item['surplus'] = $item['qty'] - $count; } $this->assign('row', $json); return $this->view->fetch('dateils'); } }