Browse Source

台账优化

wufeng 2 years ago
parent
commit
5f22ce0c86

+ 20 - 15
app/admin/controller/After.php

@@ -156,8 +156,7 @@ class After extends Base
         if($order_type!==""){
             $where[]=['a.order_type',"=", $order_type];
         }
-        $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode'])
-            :"";
+        $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode']) :"";
         if($orderCode!=""){
             $where[]=['a.orderCode',"like", "%{$orderCode}%"];
         }
@@ -211,7 +210,7 @@ class After extends Base
             ->leftJoin("order_returninfo b","a.returnCode=b.returnCode")
             ->where($where)
             ->where($condition)
-            ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark,u.itemid")
+            ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark,u.itemid,a.orderCode")
             ->page($page,$size)
             ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
             ->order("addtime desc")
@@ -726,12 +725,15 @@ class After extends Base
                     if($back>0){
 
                         //维护台账
-                        Db::name('standing_book')
-                            ->where('returnCode', $bkcode)
-                            ->update([
-                                'thNo' => $data['thNo'],
-                                'updatetime' => date("Y-m-d H:i:s")
-                            ]);
+//                        Db::name('standing_book')
+//                            ->where('returnCode', $bkcode)
+//                            ->update([
+//                                'thNo' => $data['thNo'],
+//                                'updatetime' => date("Y-m-d H:i:s")
+//                            ]);
+
+                        Db::execute("UPDATE `wsm_standing_book` SET `thNo`=CONCAT(`thNo`,',{$data['thNo']}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET(`returnCode`,'{$bkcode}')");//这里的returnCode可能有多个
+
 
                         $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
                         ActionLog::logAdd($this->post['token'],$order,"CKTHD", 0,$data);
@@ -1051,12 +1053,15 @@ class After extends Base
                         ]);
 
                         //维护台账记录
-                        Db::name('standing_book')
-                            ->where(['returnCode' => $bkcode])
-                            ->update([
-                                'thNo' => $thNo,
-                                'updatetime' => date("Y-m-d H:i:s")
-                            ]);
+//                        Db::name('standing_book')
+//                            ->where(['returnCode' => $bkcode])
+//                            ->update([
+//                                'thNo' => $thNo,
+//                                'updatetime' => date("Y-m-d H:i:s")
+//                            ]);
+                        Db::execute("UPDATE `wsm_standing_book` SET `thNo`=CONCAT(`thNo`,',{$thNo}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET(`returnCode`,'{$bkcode}')");//这里的returnCode可能有多个
+
+
 
                         if($info['return_tag']==1){
                             $sale['th_num']+= $info['error_num'];

+ 8 - 22
app/admin/controller/Purchin.php

@@ -255,22 +255,7 @@ class Purchin extends Base
                 $order = ["order_code"=>$cgdNo,"status"=>$cgdinfo['status'],"action_remark"=>'',"action_type"=>"edit"];
 
                 //维护台账信息
-                $rs = Db::name('standing_book')
-                    ->where('cgdNo', $cgdNo)
-                    ->order('wsm_in_code')
-                    ->find();
-
-                if(!empty($rs)){
-                    if($rs['wsm_in_code']=='')  Db::name('standing_book')->where('id', $rs['id'])->update(['wsm_in_code' => $wsm_in_code, 'updatetime' => date('Y-m-d H:i:s')]);
-                    else {
-                        unset($rs['id']);
-                        $rs['updatetime']=date('Y-m-d H:i:s');
-                        $rs['wsm_in_code']=$wsm_in_code;
-                        $rs['standBookNo']=makeNo('IO');
-                        Db::name('standing_book')->insert($rs);
-                    }
-
-                }
+                Db::execute("UPDATE `wsm_standing_book` SET `wsm_in_code`=CONCAT(`wsm_in_code`,',{$wsm_in_code}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `cgdNo`='{$cgdNo}'");
 
                 if($status==1){
                             Db::commit();
@@ -918,12 +903,13 @@ class Purchin extends Base
                 ActionLog::logAdd($this->post['token'],$sto,"RKTHD",0,$data);
 
          //维护台账记录
-         Db::name('standing_book')
-             ->where('wsm_in_code', $incode)
-             ->update([
-                 'cgdReturnCode' => $returnCode,
-                 'updatetime' => date('Y-m-d H:i:s'),
-             ]);
+//         Db::name('standing_book')
+//             ->where('wsm_in_code', $incode)
+//             ->update([
+//                 'cgdReturnCode' => $returnCode,
+//                 'updatetime' => date('Y-m-d H:i:s'),
+//             ]);
+         Db::execute("UPDATE `wsm_standing_book` SET `cgdReturnCode`=CONCAT(`cgdReturnCode`,',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET(`wsm_in_code`,$incode)");//这里的wsm_in_code可能有多个
 
             }
 

+ 20 - 17
app/admin/controller/Reorder.php

@@ -106,17 +106,19 @@ class Reorder extends Base
                 ProcessOrder::AddProcess($this->post['token'],$process);
 
                 //维护台账信息
-                $rs = Db::name('standing_book')->where('orderCode', $ordeCode)->order('returnGoodCode')->find();
-                if (!empty($rs)) {
-                    if ($rs['returnGoodCode'] == '') Db::name('standing_book')->where('id', $rs['id'])->update(["returnGoodCode" => $returnCode, "updatetime" => date("Y-m-d H:i:s")]);
-                    else {
-                        unset($rs['id']);
-                        $rs['standBookNo'] = makeNo('IO');
-                        $rs['addtime'] = $rs['updatetime'] = date("Y-m-d H:i:s");
-                        $rs['returnGoodCode'] = $returnCode;
-                        Db::name('standing_book')->insert($rs);
-                    }
-                }
+                Db::execute("UPDATE `wsm_standing_book` SET `returnGoodCode`=CONCAT(`returnGoodCode`,',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `orderCode`='{$ordeCode}'");
+
+//                $rs = Db::name('standing_book')->where('orderCode', $ordeCode)->order('returnGoodCode')->find();
+//                if (!empty($rs)) {
+//                    if ($rs['returnGoodCode'] == '') Db::name('standing_book')->where('id', $rs['id'])->update(["returnGoodCode" => $returnCode, "updatetime" => date("Y-m-d H:i:s")]);
+//                    else {
+//                        unset($rs['id']);
+//                        $rs['standBookNo'] = makeNo('IO');
+//                        $rs['addtime'] = $rs['updatetime'] = date("Y-m-d H:i:s");
+//                        $rs['returnGoodCode'] = $returnCode;
+//                        Db::name('standing_book')->insert($rs);
+//                    }
+//                }
 
                 if($returnadr!=""){
                     $inf=[];
@@ -1073,12 +1075,13 @@ class Reorder extends Base
                 ActionLog::logAdd($this->post['token'],$ste,"XSTHD",3,$in);
 
                 //维护台账记录
-                Db::name('standing_book')
-                    ->where('ordeCode', $ordeCode)
-                    ->update([
-                        'returnGoodCode' => $returnCode,
-                        'updatetime' => date("Y-m-d H:i:s")
-                    ]);
+//                Db::name('standing_book')
+//                    ->where('ordeCode', $ordeCode)
+//                    ->update([
+//                        'returnGoodCode' => $returnCode,
+//                        'updatetime' => date("Y-m-d H:i:s")
+//                    ]);
+                Db::execute("UPDATE `wsm_standing_book` SET `returnGoodCode`=CONCAT(`returnGoodCode`,',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `ordeCode`='{$ordeCode}'");
 
                 if ($order['send_type'] == 1) {
                     $wsend = Db::name("order_out")->where(['orderCode' => $ordeCode, "status" => 1, "order_type"=>2])->select();

+ 17 - 45
app/admin/controller/Sale.php

@@ -323,7 +323,6 @@ class Sale extends Base
 
                 }
 
-                $outCodeS=[];
                 if($sendtype==1){
                     foreach ($addrlist as $value){
                         $temp=[];
@@ -424,8 +423,9 @@ class Sale extends Base
                                         ]);
 
 
-                                        $outCodeS[]=$outCode;
 //                                        $standing_book_da['outCode'] = $outCode;
+                                        if (isset($standing_book_da['outCode'])) $standing_book_da['outCode'][] = $outCode;
+                                        else $standing_book_da['outCode'] = [$outCode];
                                     }
                              //   }
                         }else{
@@ -436,29 +436,13 @@ class Sale extends Base
                 }
 
                 //处理台账
+                if (isset($standing_book_da['outCode'])) $standing_book_da['outCode'] = implode(',', $standing_book_da['outCode']);//发货单号拼接
                 if (isset($standing_book_da['bk_code'])) {
                     $temp = Db::name('standing_book')->field('id')->where('bk_code', $standing_book_da['bk_code'])->find();
                     if (!empty($temp)) Db::name('standing_book')->where('id', $temp['id'])->update($standing_book_da);
                     else Db::name('standing_book')->insert(array_merge($standing_book_da, ['addtime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo('IO')]));
                 } else Db::name('standing_book')->insert(array_merge($standing_book_da, ['addtime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo('IO')]));
 
-
-                foreach ($outCodeS as $outCodeTemp) {
-                    $rs = Db::name('standing_book')->where('orderCode', $orderCode)->order('outCode')->find();
-
-                    if (!empty($rs)) {
-                        if ($rs['outCode'] == '') Db::name('standing_book')->where('id', $rs['id'])->update(['outCode' => $outCodeTemp, 'updatetime' => date('Y-m-d H:i:s')]);
-                        else {
-                            unset($rs['id']);
-                            $rs['standBookNo'] = makeNo('IO');
-                            $rs['outCode'] = $outCodeTemp;
-                            $rs['addtime'] = date('Y-m-d H:i:s');
-                            Db::name('standing_book')->insert($rs);
-                        }
-                    }
-                }
-
-
                 Db::commit();
                 return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
             }
@@ -800,7 +784,8 @@ class Sale extends Base
                             ]);
 
                             //处理台账-既然是根据orderCode更新的数据,那么肯定是有数据的,只需要更新就行了
-                            Db::name('standing_book')->where('orderCode', $orderCode)->update(['outCode' => $outCode, 'updatetime' => date('Y-m-d H:i:s')]);
+                            Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(`outCode`,',{$outCode}'),`updatetime`='".date('Y-m-d H:i:s')."' WHERE `orderCode`='{$orderCode}'");
+
                         }
 
                         //维护商品所在仓库的库存 --- end
@@ -1136,7 +1121,7 @@ class Sale extends Base
                                     ]);
 
                                     //将发货编号添加到台账中
-                                    $standing_book_data['outCode']=$outCode;
+                                    $standing_book_data['outCode'][]=$outCode;
                                 }
                                 $order['send_num']+=$value['receipt_quantity'];
                                 $order['wsend_num']-=$value['receipt_quantity'];
@@ -1169,6 +1154,11 @@ class Sale extends Base
                     }
 
                     //处理台账
+                if(isset($standing_book_data['outCode'])){
+                    Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(`outCode`,',".implode(',',$standing_book_data['outCode'])."'),`updatetime`='".date('Y-m-d H:i:s')."' WHERE `infoNo`='{$standing_book_data['infoNo']}'");
+                    unset($standing_book_data['outCode']);
+                }
+
                 Db::name('standing_book')->where('infoNo', $standing_book_data['infoNo'])->update($standing_book_data);
 
                 Db::commit();
@@ -1310,6 +1300,7 @@ class Sale extends Base
                 //项目创建时已有供应商和企业,不能修改
                 if (isset($standing_book_data['companyNo'])) unset($standing_book_data['companyNo']);
                 if (isset($standing_book_data['customer_code'])) unset($standing_book_data['customer_code']);
+                if (isset($standing_book_data['outCode'])) $standing_book_data['outCode'] = implode(',', $standing_book_data['outCode']);
 
                 //普通商品
                 if ($feedback['data_source'] == 1) {
@@ -1327,16 +1318,6 @@ class Sale extends Base
                 } else {
                     //项目类竞价单
                     Db::name('standing_book')->where(['projectNo' => $plan['projectNo'], 'infoNo' => $standing_book_data['infoNo']])->update($standing_book_data);
-//                    if ($key == 0) Db::name('standing_book')->where('projectNo', $plan['projectNo'])->where('infoNo', $standing_book_data['infoNo'])->update($standing_book_data);
-//                    else {
-//                        $temp = Db::name('standing_book')->where('projectNo', $plan['projectNo'])->where('infoNo', $standing_book_data['infoNo'])->find();
-//                        if (!empty($temp)) {
-//                            unset($temp['id']);
-//                            $temp = array_merge($temp, $standing_book_data);
-//                            $temp['standBookNo'] = makeNo('IO');
-//                            Db::name('standing_book')->insert($temp);
-//                        }
-//                    }
                 }
 
             }
@@ -1653,7 +1634,7 @@ class Sale extends Base
                                 return false;
                             }
 
-                            $standing_book_data['outCode'] = $outCode;
+                            $standing_book_data['outCode'][] = $outCode;
                         }
 
                     } else {
@@ -1911,7 +1892,7 @@ class Sale extends Base
                                 if ($ou == false) {
                                     return 0;
                                 } else {
-                                    $standing_book_data['outCode'] = $outCode;
+                                    $standing_book_data['outCode'][] = $outCode;
                                     //修改状态,添加待办
                                     ActionLog::logAdd($this->post['token'], [
                                         "order_code" => $outCode,//出库单号
@@ -2579,17 +2560,7 @@ class Sale extends Base
                         }
 
                         //维护台账
-                        $rs = Db::name('standing_book')->where('cgdNo', $cgd)->order('wsm_in_code')->find();
-                        if (!empty($rs)) {
-                            if ($rs['wsm_in_code'] == '') Db::name('standing_book')->where('id', $rs['id'])->update(['wsm_in_code' => $wsm_in_code, 'update' => date('Y-m-d H:i:s')]);
-                            else {
-                                unset($rs['id']);
-                                $rs['standBookNo'] = makeNo('IO');
-                                $rs['updatetime'] = $rs['addtime'] = date('Y-m-d H:i:s');
-                                $rs['wsm_in_code'] = $wsm_in_code;
-                                Db::name('standing_book')->insert($rs);
-                            }
-                        }
+                        Db::execute("UPDATE `wsm_standing_book` SET `wsm_in_code`=CONCAT(`wsm_in_code`,',{$wsm_in_code}'),`updatetime`='".date('Y-m-d H:i:s')."' WHERE `cgdNo`='{$cgd}'");
 
                         $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
                         if (empty($good)) {
@@ -3518,11 +3489,12 @@ class Sale extends Base
                                 'order_type' => $der['order_type'],
                                 'order_source' => $der['order_source'],
                                 'cgdNo' => $order['cgdNo'],
-                                'outCode' => $outCode,
                                 'customer_code' => $der['customer_code'],
                                 'updatetime' => date('Y-m-d H:i:s'),
                             ]);
 
+                        Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(`outCode`,',{$outCode}') WHERE `cgdNo`='{$cgd}'");
+
                         Db::commit();
                         return app_show(0,"出库单新建成功");
                     }

+ 3 - 0
app/admin/controller/Salezx.php

@@ -213,6 +213,8 @@ class Salezx extends \app\BaseController
                                    "order_status" => $out['status']
                                ]);
 
+                               $standing_bood_data['outCode'][]=$outCode;
+
                            }
                         }else{
                             Db::rollback();
@@ -238,6 +240,7 @@ class Salezx extends \app\BaseController
 
 
                 //根据zxinfoNo查找infoNo,找到则更新台账,否则就新增台账
+                if (isset($standing_bood_data['outCode'])) $standing_bood_data['outCode'] = implode(',', $standing_bood_data['outCode']);
                 $infoNo = Db::name('consult_bids')->where('bidNo', $zxinfoNo)->value('infoNo');
                 if (empty($infoNo)) Db::name('standing_book')->insert(array_merge($standing_bood_data, ['addtime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo("IO")]));
                 else Db::name('standing_book')->where('infoNo', $infoNo)->update($standing_bood_data);

+ 5 - 18
app/admin/controller/StandingBook.php

@@ -21,16 +21,9 @@ class StandingBook extends Base
             'bargainNo' => '',
             'bk_code' => '',
             'orderCode' => '',
-            'outCode' => '',
-            'returnCode' => '',
-            'thNo' => '',
-            'returnGoodCode' => '',
             'cgdNo' => '',
-            'wsm_in_code' => '',
-            'cgdReturnCode' => '',
             'spuCode' => '',
             'skuCode' => '',
-            'order_type' => '',
             'supplierNo' => '',
             'companyNo' => '',
             'customer_code' => '',
@@ -46,16 +39,9 @@ class StandingBook extends Base
         if ($param['bargainNo'] != '') $where[] = ['bargainNo', 'like', '%' . $param['bargainNo'] . '%'];
         if ($param['bk_code'] != '') $where[] = ['bk_code', 'like', '%' . $param['bk_code'] . '%'];
         if ($param['orderCode'] != '') $where[] = ['orderCode', 'like', '%' . $param['orderCode'] . '%'];
-        if ($param['outCode'] != '') $where[] = ['outCode', 'like', '%' . $param['outCode'] . '%'];
-        if ($param['returnCode'] != '') $where[] = ['returnCode', 'like', '%' . $param['returnCode'] . '%'];
-        if ($param['thNo'] != '') $where[] = ['thNo', 'like', '%' . $param['thNo'] . '%'];
-        if ($param['returnGoodCode'] != '') $where[] = ['returnGoodCode', 'like', '%' . $param['returnGoodCode'] . '%'];
         if ($param['cgdNo'] != '') $where[] = ['cgdNo', 'like', '%' . $param['cgdNo'] . '%'];
-        if ($param['wsm_in_code'] != '') $where[] = ['wsm_in_code', 'like', '%' . $param['wsm_in_code'] . '%'];
-        if ($param['cgdReturnCode'] != '') $where[] = ['cgdReturnCode', 'like', '%' . $param['cgdReturnCode'] . '%'];
         if ($param['spuCode'] != '') $where[] = ['spuCode', 'like', '%' . $param['spuCode'] . '%'];
         if ($param['skuCode'] != '') $where[] = ['skuCode', 'like', '%' . $param['skuCode'] . '%'];
-        if ($param['order_type'] != '') $where[] = ['order_type', '=', $param['order_type']];
         if ($param['supplierNo'] != '') $where[] = ['supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
         if ($param['companyNo'] != '') $where[] = ['companyNo', 'like', '%' . $param['companyNo'] . '%'];
         if ($param['customer_code'] != '') $where[] = ['customer_code', 'like', '%' . $param['customer_code'] . '%'];
@@ -77,15 +63,16 @@ class StandingBook extends Base
 
 
     //台账详情
-    public function getDetail(){
+    public function getDetail()
+    {
 
-        $id = $this->request->post('id/d',0,'trim');
+        $id = $this->request->post('id/d', 0, 'trim');
 
         $res = Db::name('standing_book')
-            ->where('id',$id)
+            ->where('id', $id)
             ->find();
 
-        return app_show(0,'请求成功',$res);
+        return app_show(0, '请求成功', $res);
 
     }