<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                # 模型邏輯層之實戰代碼 這節 其實沒有什么好說的 當你把每個復雜的邏輯處理過程封裝到邏輯層中,你前段的控制器代碼就會優雅簡潔很多 >[warning] 不要糾結你給你的邏輯處理代碼起的名稱 和存放位置 * 代碼一 ~~~ /** * 創建項目預算書 * User: Mikkle * Q Q:776329498 * @param $data * @param $id * @param $project_id * @return array */ public function buildBudgetBook($data,$id,$project_id){ try{ $this->startTrans(); //修改審核記錄 if(!$this->data($data)->isUpdate(true,['guid'=>$id])->save()){ throw new Exception("審核信息失敗"); } if($project_id!=$this->where(['guid'=>$id])->value("project_id")){ throw new Exception("項目ID獲取出錯!"); } //審核結果 1審核通過 $m=isset($data['examine_status']) ? $data['examine_status'] : 0 ; if($m==1){ $model_book_number= new BudgetBookNumber(); Db::table("mk_budget_default_book_number")->where(["project_id"=>$project_id,"status"=>1])->update(["status"=>2]); $model_book_number->save(["project_id"=>$project_id]); $book_number_id = $model_book_number->id; if(!is_numeric($book_number_id)){ throw new Exception("獲取預算書ID失敗"); } //預算書編號 $book_number = $book_number_id+100000; $model_book_number->save(["book_number"=>$book_number],["id"=>$book_number_id]); $list_default_book = Db::table("mk_budget_default_book")->where(["project_id"=>$project_id,"status"=>1])->select(); if(count($list_default_book)!=1){ throw new Exception("項目書數量不是唯一"); } $list_default_book=$list_default_book[0]; unset($list_default_book["id"]); $list_default_book["book_number"]=$book_number; if(!isset(DefaultBookCopy::create($list_default_book)["id"])){ throw new Exception("出錯了"); } //插入裝修項目信息 $list_default_project = Db::table("mk_budget_default_project")->where(["project_id"=>$project_id,"status"=>1])->select(); $append=["book_number"=>$book_number]; $unset=["id"]; //重整數組 追加 book_number 刪除 id $list_default_project=$this->changeArrayColumnData($list_default_project,$append,$unset); $insert_count= count($list_default_project); $model_project =new DefaultProjectCopy(); //超過100條 分批插入 if ($insert_count>0 && $insert_count<100){ $model_project->insertAll($list_default_project); }elseif($insert_count>100){ $insert_batch= ceil($insert_count/100); for( $i=0 ;$i<$insert_batch;$i++ ){ $model_project->insertAll(array_slice($list_default_project, $i*100,100)); } } //插入裝修費率信息 $list_default_rate = Db::table("mk_budget_default_rate")->where(["project_id"=>$project_id,"status"=>1])->select(); $append=["book_number"=>$book_number]; $unset=["id"]; //重整數組 追加 book_number 刪除 id $list_default_rate=$this->changeArrayColumnData($list_default_rate,$append,$unset); $model_rate =new DefaultRateCopy(); $model_rate->insertAll($list_default_rate) ; } $this->commit(); return self::showReturnCodeWithOutData(1001); }catch (Exception $e){ $this->rollback(); return self::showReturnCodeWithOutData(1008,$e->getMessage()); } } ~~~ * 實戰代碼二 以前寫的代碼 其實他更像是控制器的邏輯層 我現在也看著頭大 ~~~ /** * 訂單排產 * User: Mikkle * Q Q:776329498 * @param string $batch_no */ public function createFactoryProductBomByBatchNo($batch_no='20170303-16575510'){ @ob_end_clean(); @ob_implicit_flush(0); try{ if (!$batch_no){ throw new \Exception("生產批號[{$batch_no}]數據不存在"); } $model = new FactoryBatch(); $batch_info=$model -> where(['batch_no'=>$batch_no])->find(); if($batch_info['batch_status']!= 1){ throw new \Exception("生產批號[{$batch_no}]排產狀態異常,請確認是否已經安排排產"); } $this->flush_str("生產批號[{$batch_no}]排產狀態驗證通過!"); $this->batch_no=$batch_no; $order_list = $model -> table('my_factory_orders_batch_access') -> where(['batch_no'=>$batch_no,'factory_state'=>0,'status'=>1]) -> column('order_no'); if($batch_info['order_num']!== count($order_list)){ throw new \Exception("生產批號[{$batch_no}]訂單數量和流水線數量不符 請聯系系統管理員Mikkle"); } $this->flush_str("生產批號[{$batch_no}]訂單數量和流水線數量驗證相符!"); $this->flush_str("生產批號[{$batch_no}]共有訂單{$batch_info['order_num']}份"); $model->startTrans(); $this->flush_str("生產批號[{$batch_no}]驗證通過,進入BOM單分解流程開始!"); $count_package=[]; $count_product=[]; foreach ($order_list as $item=>$order) { $no = $item +1; $order_info = $model ->table('my_orders')->where(['order_no' => $order,'status' => 1,'is_pay' => 1,'factory_batch'=>$batch_no,'factory_state'=>1])->find(); if (!$order_info) { throw new \Exception("訂單[{$order}]狀態異常或不存在,請核對訂單號再排產"); } $this->flush_str("<-------------------拆解訂單第{$no}個[{$order}]數據開始------------------->"); $this->flush_str("已經驗證訂單[{$order}]狀態正常"); $save_data=$this->splitOrder($order); if (!$save_data) { throw new \Exception("訂單[{$order}]BOM單分解數據不存在,請聯系管理員."); } $count_package = $this->guidCountAdd($count_package,$this->count_package); $count_product = $this->guidCountAdd($count_product,$this->count_product); $data_num = count($save_data); $this->flush_str("拆解訂單第{$no}個[{$order}]數據,共計[$data_num]份BOM數據"); foreach($save_data as $key=>$value){ $num=$key+1; $this->flush_str("拆解訂單[{$order}]數據第[$num]份BOM數據,{$value['product_bom_name']}"); } if($model->table('my_factory_orders_bom_access')->insertAll($save_data)==0){ throw new \Exception("寫入訂單[{$order}]Bom單信息數據失敗!"); }; $this->flush_str("寫入訂單[{$order}]Bom單信息數據成功!"); $this->flush_str("<-------------------拆解訂單第{$no}個[{$order}]數據結束------------------->"); } $save_count_data=array_merge($this->buildCountDataArray($count_package,'Package'), $this->buildCountDataArray($count_product,'Product')); if($model->table('my_factory_batch_plan')->insertAll($save_count_data)==0){ throw new \Exception("寫入生產批次[{$batch_no}]商品統計數據失敗!"); }; $this->flush_str("寫入生產批次[{$batch_no}]商品統計數據成功!"); $this->flush_str("生產批號[{$batch_no}]全部BOM單分解成功!"); //更新訂單表信息 if (!$model->table('my_orders')->where(['factory_batch' => $batch_no])->update([ 'factory_state' => 2])) { throw new \Exception("更新[$batch_no]訂單表數據失敗"); } $this->flush_str("更新[$batch_no]訂單表數據成功."); //更新訂單表信息 if($batch_info->where('batch_no',$batch_no)->update(['batch_status'=>2])==0){ throw new \Exception("生產批號[{$batch_no}]排產狀態修改失敗!"); }; $this->flush_str("生產批號[{$batch_no}]狀態修改成功!"); $model->commit(); $this->flush_str("生產批號[{$batch_no}]BOM單分解成功!"); $this->flush_str("<a onclick='history.go(-1)'>返回上一頁</a>"); } catch (\Exception $e) { // / dump($e); $model->rollback(); $this->batch_no = Null; $str = "出錯了,[{$e->getMessage()}],系統關聯操作被取消!"; $this->flush_str($str); } } public function batchNoFactoryProductBomRollback($batch_no){ @ob_end_clean(); @ob_implicit_flush(0); $model_order = new Orders(); try { if (!$batch_no) { throw new \Exception('要回滾的生產批號不存在'); } $batch_info=$model_order->table('my_factory_batch')->where(['batch_no'=>$batch_no,'status'=>1])->find(); if (!$batch_info) { throw new \Exception("要回滾的生產批號[{$batch_no}]數據不存在"); } if ($batch_info['batch_status']!=2) { throw new \Exception("該生產批號[{$batch_no}]狀態已經改變,不允許回滾."); } $order_num=$model_order->where(['is_pay' => 1, 'status' => 1, 'factory_batch' => $batch_no])->count('id'); if ($batch_info['order_num']!=$order_num) { throw new \Exception("該生產批號[{$batch_no}]要回滾的數量異常,請聯系Mikkle."); } $this->flush_str("生產批號{$batch_no}回滾的訂單號數量[{$order_num}]條,驗證正確!!"); $model_order->startTrans(); $this->flush_str("生產批號{$batch_no}回滾驗證已經通過,開始執行生成批號撤銷!"); //更新訂單表信息 if (!$model_order->update([ 'factory_state' => 1], ['factory_batch' => $batch_no,'is_pay' => 1, 'status' => 1,])) { throw new \Exception("回滾生成批次[$batch_no]數據失敗"); } $this->flush_str("生產批號{$batch_no}相關訂單數據回滾成功!"); //回滾生產BOM表 if (!$model_order->table('my_factory_orders_bom_access')->where(['batch_no'=>$batch_no,'status' => 1])->update(['status'=>0,'factory_desc'=>'該生產批號已經撤銷'])) { throw new \Exception("回滾生產批次[$batch_no]BOM數據失敗"); } $this->flush_str("回滾生產批次[$batch_no]流水數據成功!"); //回滾生產統計數據 if (!$model_order->table('my_factory_batch_plan')->where(['batch_no'=>$batch_no,'status' => 1])->update(['status'=>0,'factory_desc'=>'該生產批號已經撤銷'])) { throw new \Exception("回滾生產批次[$batch_no]統計數據失敗"); } $this->flush_str("回滾生產批次[$batch_no]統計數據成功!"); //回滾生產批號狀態 if (!$model_order->table('my_factory_batch')->where(['batch_no'=>$batch_no])->update(['batch_status'=>1,])) { throw new \Exception("回滾生產批號[{$batch_no}]數據失敗"); } $this->flush_str("回滾生產表批號[{$batch_no}]數據成功"); $model_order->commit(); $this->flush_str("回滾操作成功"); } catch (\Exception $e) { $model_order->rollback(); $str = "出錯了,[{$e->getMessage()}],系統關聯操作被取消!"; $this->flush_str($str); } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看