model = new \app\admin\model\fastflow\bill\Czgprz; } public function index(){ $mdoel = new Amodela(); $where = []; //halt(111); $list = $mdoel->where($where)->paginate(10); $result = ['total' => $list->total(), 'rows' => $list->items()]; return json($result); } /** * 编辑 */ public function edit($ids = null) { $row = $this->model->get($ids); $goods_ids = (new Amodel())->where('bill_id',$ids)->where('type','goods')->value('json'); $row['goods_list'] = json_decode($goods_ids,true); if($row['goods_list']){ $row['ssss'] = 1 ; }else{ $row['ssss'] = 2 ; } if ($this->request->isPost()) { $params = $this->request->post("row/a"); // halt($params); $daa = \think\Cache::get('aaa'.$this->auth->id); $daa2 = \think\Cache::get('aaaa'.$this->auth->id); // \think\Cache::rm('aaa'.$this->auth->id); // \think\Cache::rm('aaaa'.$this->auth->id); //计算利润率 $lr = 0; $cb = 0; $totalprice = 0; //总价 // halt($daa2); foreach ($daa2['arr'] as $item){ //halt($item); $lr += $item['qty']*$item['unitPrice'] - $item['qty']*$item['wholesale_price']; $cb += $item['qty']*$item['wholesale_price']; $totalprice += $item['qty']*$item['unitPrice']; } if($cb == 0){ $price_lr = 1; }else{ $price_lr = $lr/$cb; } $data = [ 'bill_id'=>0, 'goods_id'=>$daa['ids'], 'type'=>'goods', 'json'=>json_encode($daa['arr']) ]; $customer_name = (new Customer())->where('id',$params['customer_id'])->value('name'); $business_name = (new \app\admin\model\qingdong\Business())->where('id',$params['business_id'])->value('name'); $data2 = [ 'bill_id'=>0, 'customer_id'=>$params['customer_id'], 'business_id'=>$params['business_id'], 'customer_name'=>$customer_name, 'business_name'=>$business_name, 'name'=>$params['name'], 'lr'=>$price_lr, 'goods_id'=>$daa2['ids'], 'type'=>'goods', 'json'=>json_encode($daa2['arr']) ]; $data3 = [ 'initiator_id'=>$this->auth->id, 'status'=>1, 'name'=>$params['name'], 'customer_id'=>$params['customer_id'], 'business_id'=>$params['business_id'], 'profit'=>$price_lr, 'customer_name'=>$customer_name, 'business_name'=>$business_name, 'totalprice'=>$totalprice, ]; Db::startTrans(); try { $amodel = new Amodel(); $amodelaModel = new Amodela(); if($price_lr < 0.8){ $this->model->save($data3); $id = $this->model->id; $this->api = new api(new CustomMessage(), (new Run)); $data['bill_id'] = $id; $amodel->save($data); $data2['bill_id'] = $id; $data2['amodel_id'] = $amodel->id; $data2['status'] = '0'; $amodelaModel->save($data2); $data4 = [ 'bill'=>'ats_czgprz', 'bill_id'=>$id, 'ebill_id'=>'', 'flow_id'=>30, 'checkcontent'=>'', 'file_name'=>'', 'file'=>'', 'carbon_scope'=>1, 'carbon_receiver'=>'', 'carbon_range'=>1, ]; $this->api->startFlow($data4); }else{ $client = new Client(); $url = 'http://8.130.38.56:8073/api/office/excel'; $headers = [ 'Content-Type' => 'application/json' ]; // POST参数 $body = array( 'email' => 'ss', 'contacts'=>'bosiny@bosiny.com', 'mobile' => 'ss', 'items' => $daa['arr'], ); $request = new Request('POST', $url, $headers, json_encode($body)); $res = $client->sendAsync($request)->wait(); $file = $res->getBody()->getContents(); $data['file'] = $file; $data2['file'] = $file; $amodel->save($data); $data2['amodel_id'] = $amodel->id; $data2['status'] = '2'; $amodelaModel->save($data2); } 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()); } \think\Cache::rm('aaa'.$this->auth->id); \think\Cache::rm('aaaa'.$this->auth->id); $this->success(); } $row['business_id'] = input('business_id'); $row['customer_id'] = input('customer_id'); $business_name = (new \app\admin\model\qingdong\Business())->where('id',$row['business_id'])->value('name'); $count = (new Amodela())->where('business_id',$row['business_id'])->count(); if($business_name){ $name = $business_name.'第'.($count+1).'次报价'; }else{ $name = '第'.($count+1).'次报价'; } $statusList = (new Goodsmb())->select(); $this->assignconfig(['statusList' => $statusList]); $this->view->assign('statusList',$statusList); $this->view->assign('row',$row); $this->view->assign('name',$name); return $this->view->fetch(); } public function detail($ids = null){ $admodela = (new Amodela())->where('id',$ids)->find(); $row = $this->model->get($admodela['bill_id']); $array = json_decode($admodela['json'],true); $grouped = []; $mbModel = new Goodsmb(); $goodsModel = new Goods(); if(!$row){ $row['name'] = $admodela['name']; $row['customer_name'] = $admodela['customer_name']; $row['business_name'] = $admodela['business_name']; $row['profit'] = $admodela['lr']; } $balance = 0; $cb_amount = 0; $totalprice = 0; foreach ($array as &$item) { $mb_id = $item["mb_id"]; $mb_name = $mbModel->where('id',$mb_id)->value('name'); $item['mb_name'] = $mb_name; $wholesale_price = $goodsModel->where('id',$item["productID"])->value('wholesale_price'); $item['wholesale_price'] = $wholesale_price; if (!isset($grouped[$mb_name])) { $grouped[$mb_name] = []; } $grouped[$mb_name][] = $item; //结算价 $balance += $wholesale_price * $item["qty"]; //成本价 $cb_amount += $item["qty"]*$item["cb_price"]; // halt($item['amount']); $totalprice += intval($item['amount']); } if(!isset($row['totalprice'])){ $row['totalprice'] = $totalprice; } $row['goods_list'] =$grouped; // halt($cb_amount); if($cb_amount == '0'){ $row['balance'] = 1; $row['profit'] = 1; }else{ $row['balance'] = (round(($balance-$cb_amount)/$cb_amount,4)*100).'%'; $row['profit'] = (round($row['profit'],4)*100).'%'; } $role = $this->auth->getRole($this->auth->id); $this->view->assign('role',$role); $this->view->assign('row',$row); return $this->view->fetch(); } public function detail2($ids = null){ $admodela = (new Amodela())->where('id',$ids)->find(); $row = $this->model->get($admodela['bill_id']); $array = json_decode($admodela['json'],true); if(!$row){ $row['name'] = $admodela['name']; $row['customer_name'] = $admodela['customer_name']; $row['business_name'] = $admodela['business_name']; } $grouped = []; $mbModel = new Goodsmb(); $goodsModel = new Goods(); $balance = 0; $cb_amount = 0; $totalprice = 0; foreach ($array as &$item) { $mb_id = $item["mb_id"]; $mb_name = $mbModel->where('id',$mb_id)->value('name'); $item['mb_name'] = $mb_name; $wholesale_price = $goodsModel->where('id',$item["productID"])->value('wholesale_price'); $item['wholesale_price'] = $wholesale_price; if (!isset($grouped[$mb_name])) { $grouped[$mb_name] = []; } $grouped[$mb_name][] = $item; //结算价 $balance += $wholesale_price * $item["qty"]; //成本价 $cb_amount += $item["qty"]*$item["cb_price"]; $totalprice += $item['amount']; } if(!isset($row['totalprice'])){ $row['totalprice'] = $totalprice; } $row['goods_list'] =$grouped; if($cb_amount == '0'){ $row['balance'] = (round(($balance-$cb_amount)/$cb_amount,4)*100).'%'; $row['profit'] = (round($row['profit'],4)*100).'%'; }else{ $row['balance'] = 1; $row['profit'] = 1; } $group_ids = $this->auth->getGroupIds(); if(in_array(1,$group_ids) || in_array(2,$group_ids)){ $admin_id = '1'; }elseif(in_array(3,$group_ids) || in_array(4,$group_ids) || in_array(8,$group_ids)){ $admin_id = '2'; }else{ $admin_id = '3'; } $this->view->assign('admin',['admin_id'=>$admin_id]); $this->view->assign('row',$row); return $this->view->fetch('detail2'); } }