wugg 2 years ago
parent
commit
e132dce8ae
2 changed files with 81 additions and 170 deletions
  1. 5 5
      app/admin/controller/ReorderChild.php
  2. 76 165
      app/admin/controller/Sale.php

+ 5 - 5
app/admin/controller/ReorderChild.php

@@ -55,7 +55,7 @@ class ReorderChild extends Base
 
         }
         $val_child = Validate::rule([
-//            'outChildCode|发货工单号' => 'require',
+            'outChildCode|发货工单号' => 'max:255',
             'return_num|退货数量' => 'require|number|gt:0|max:999999999999',
             'return_wsm_code|退货仓库编码' => 'require'
         ]);
@@ -88,7 +88,7 @@ class ReorderChild extends Base
                     'returnCode' => $param['returnCode'],
                     'outCode' => $param['outCode'],
                     'outChildCode' => $value['outChildCode'] ?? '',
-                    'order_out_child_status' => $orderOutChild[$value['outChildCode']]['status'] ?? 0,
+                    'order_out_child_status' =>isset($value['outChildCode'])?($orderOutChild[$value['outChildCode']]['status'] ?? 0) :0,
                     'saleReturnChildCode' => substr(makeNo('KCC'), 0, -2) . str_pad($i++, 2, '0', STR_PAD_LEFT),
 //                    'type' => $param['type'],
                     'companyNo' => $saleReturn['companyNo'],
@@ -101,8 +101,8 @@ class ReorderChild extends Base
                     'addtime' => $date,
                     'updatetime' => $date,
                     'record' => '',
-                    'send_wsm_code' => $orderOutChild[$value['outChildCode']]['wsm_code'] ?? '',
-                    'send_num' => $orderOutChild[$value['outChildCode']]['num'] ?? 0,
+                    'send_wsm_code' =>  isset($value['outChildCode'])?($orderOutChild[$value['outChildCode']]['wsm_code'] ?? ''):"",
+                    'send_num' =>  isset($value['outChildCode'])?($orderOutChild[$value['outChildCode']]['num'] ?? 0):"",
                     'return_num' => $value['return_num'],
                     'return_wsm_code' => $value['return_wsm_code'],
                     'good_receive_type' => 0,
@@ -207,7 +207,7 @@ class ReorderChild extends Base
             'remark|备注' => 'max:255'
         ]);
 
-        if ($val->check($param)) return json_show(1004, $val->getError());
+        if ($val->check($param)==false) return json_show(1004, $val->getError());
 
         $info = Db::name('sale_return_child')
             ->alias('a')

+ 76 - 165
app/admin/controller/Sale.php

@@ -369,7 +369,6 @@ class Sale extends Base
                                 "error_num" => 0,
                                 "wsm_code" => $is_stock == 1 ?'':$cgdinfo['wsm_code'],
                                 "order_type" => $is_stock == 1 ? 1 : 2,
-                                "send_status" => $outstatus,
                                 "status" => $outstatus,
                                 "addtime" => date("Y-m-d H:i:s"),
                                 "updatetime" => date("Y-m-d H:i:s")
@@ -717,12 +716,12 @@ class Sale extends Base
                             $status = 0;
                         } else {
                             if (($goodStock_num - $num) < 0) throw new Exception("非库存品可用库存不足");
-                            $goodStock_num -= $num;
+                            $goodStock_num = -$num;
                             $status = 1;
                         }
                     } else {
                         if ($goodStock_num == 0 || ($goodStock_num - $num) < 0) throw new Exception("库存品可用库存不足");
-                        $goodStock_num -= $num;
+                        $goodStock_num = -$num;
                         $status = 1;
                     }
 
@@ -2135,8 +2134,8 @@ class Sale extends Base
         $all_createrid = array_column($list,'apply_id');
         $item = get_company_name_by_uid($all_createrid);
 
-//        $userCommon = \app\admin\common\User::getIns();
-//        $names = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'customer_code'),array_column($list,'supplierNo'))]);
+        $userCommon = \app\admin\common\User::getIns();
+        $names = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'customer_code'),array_column($list,'supplierNo'))]);
 
         $data = [];
         foreach ($list as $value) {
@@ -3440,7 +3439,7 @@ class Sale extends Base
         }
         $supplier_name = isset($this->post['supplier_name']) && $this->post['supplier_name'] !== "" ? trim($this->post['supplier_name']) : "";
         if ($supplier_name !== "") {
-            $where[] = ['b.supName', "like", "%$supplier_name%"];
+            $where[] = ['wpo.supplier_name', "like", "%$supplier_name%"];
         }
         $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
         if ($status !== "") {
@@ -3490,50 +3489,38 @@ class Sale extends Base
 
         //只有level2的账号过滤数据权限
         if ($this->level == 2) {
+            $hand = resign_hand_user($this->uid, 0);
+            $uidarr = implode(",", $hand);
+            //库管只能看到库存品订单,供应商负责人只能看到非库存品订单
+            if (!in_array($this->roleid, [1, 33])) {
+                //库管看到所有的库存品发货申请单
+                if (in_array($this->roleid, config('app.wsm_cgder_role'))) $condition .= " b.is_stock=1";
+                else {
+                    $role = $this->checkDataShare();
+                    if (!empty($role[DataGroupModel::$type_全部])) {
+                        $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
+                        if ($condition != '') $condition .= " or ";
+                        $condition .= " a.apply_id in (" . implode(',', $arr) . ")";
+                    }
+                }
+//                $personid = Db::name('supplier')->field('id')->where(['is_del' => 0, 'personid' => $hand])->findOrEmpty();
+                if (!empty($hand)) {
+                    if ($condition != '') $condition .= " or ";
+//                    $condition .= "(b.is_stock=0 and sip.personid in ($uidarr))";
 
-            //如果是供应商负责人,根据供应商筛选
-            $person_supplier = Db::connect('mysql_sys')
-                ->name('supplier')
-                ->where(['is_del' => 0, 'personid' =>$this->uid])
-                ->column('code');
-
-            if(!empty($person_supplier)) $condition = "b.supNo in ('" . implode('\',\'', $person_supplier) . "')";
-            else{
-                //不是供应商负责人,根据数据权限筛选申请人
-                $role = $this->checkDataShare();
-                if (!empty($role[DataGroupModel::$type_全部])) $condition = " a.apply_id in (" . implode(',', $role[DataGroupModel::$type_全部]) . ")";
-            }
-
+                    $person_supplier = Db::connect('mysql_sys')
+                        ->name('supplier')
+                        ->where(['is_del'=>0,'personid'=>$uidarr])
+                        ->column('code');
 
-//            $hand = resign_hand_user($this->uid, 0);
-//            $uidarr = implode(",", $hand);
-//            //库管只能看到库存品订单,供应商负责人只能看到非库存品订单
-//            if (!in_array($this->roleid, [1, 33])) {
-//                //库管看到所有的库存品发货申请单
-//                if (in_array($this->roleid, config('app.wsm_cgder_role'))) $condition .= " b.is_stock=1";
-//                else {
-//                    $role = $this->checkDataShare();
-//                    if (!empty($role[DataGroupModel::$type_全部])) {
-//                        $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
-//                        if ($condition != '') $condition .= " or ";
-//                        $condition .= " a.apply_id in (" . implode(',', $arr) . ")";
-//                    }
-//                }
-////                $personid = Db::name('supplier')->field('id')->where(['is_del' => 0, 'personid' => $hand])->findOrEmpty();
-//                if (!empty($hand)) {
-//                    if ($condition != '') $condition .= " or ";
-////                    $condition .= "(b.is_stock=0 and sip.personid in ($uidarr))";
-//
-//                    $person_supplier = Db::connect('mysql_sys')
-//                        ->name('supplier')
-//                        ->where(['is_del'=>0,'personid'=>$uidarr])
-//                        ->column('code');
-//
-//                    $condition .= "(b.is_stock=0 and wpo.supplierNo in ('" . implode('\',\'', $person_supplier) . "'))";
-//                }
-//            }
+                    $condition .= "(b.is_stock=0 and wpo.supplierNo in ('" . implode('\',\'', $person_supplier) . "'))";
+                }
+            }
         }
 
+        //供应商账号只能看到非库存品的订单
+        if ($this->level == 3) $where[] = ['b.is_stock', '=', 0];
+
 //        if(!empty($role['platform']) ){
 //            $where[]=["b.platform_id","in",$role['platform']];
 //        }
@@ -3558,11 +3545,11 @@ class Sale extends Base
 //            ->join("customer_info v", "v.companyNo=b.customer_code", "left")
             ->join("warehouse_info n", "n.wsm_code=a.wsm_code", "left")
             ->leftJoin("order_send os", "os.outCode=a.outCode")
-//            ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
+            ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
 //	        ->leftJoin('supplier sip', 'sip.code=wpo.supplierNo')
             ->where($where)
             ->where($condition)
-            ->count('a.id');
+            ->count();
         $total = ceil($count / $size);
         $page = $page >= $total ? $total : $page;
         $list = Db::name('order_out')
@@ -3571,9 +3558,9 @@ class Sale extends Base
 //            ->join("customer_info v", "v.companyNo=b.customer_code", "left")
             ->join("warehouse_info n", "n.wsm_code=a.wsm_code AND n.is_del=0", "left")
             ->leftJoin("order_send os", "os.outCode=a.outCode")
-//            ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
+            ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
 //	        ->leftJoin('supplier sip', 'sip.code=wpo.supplierNo')
-            ->field("a.*,b.order_type,b.order_source,b.good_name,b.good_code,b.skuCode,b.customer_code,b.supplierNo companyNo,b.supplierName companyName,b.origin_price,b.sale_price,b.total_price,os.cgdNo,b.supNo supplierNo,n.supplierNo wsm_supplierNo")
+            ->field("a.*,b.order_type,b.order_source,b.good_name,b.good_code,b.skuCode,b.customer_code,b.supplierNo companyNo,b.supplierName companyName,b.origin_price,b.sale_price,b.total_price,os.cgdNo,wpo.supplierNo,n.supplierNo wsm_supplierNo")
             ->where($where)
             ->where($condition)
             ->order("addtime desc")
@@ -3589,8 +3576,6 @@ class Sale extends Base
 //        $userCommon = \app\admin\common\User::getIns();
 //        $names = $userCommon->handle('getCodeAndName',['code'=>array_column($list,'customer_code')]);
 
-        $has_account = checkHasAccountBySupplierNos(array_unique(array_column($list,'wsm_supplierNo')));
-
         $data = [];
         foreach ($list as $value) {
 
@@ -3621,7 +3606,7 @@ class Sale extends Base
             } else {
                 $goon = Db::name('good_platform')->field('a.id,b.cat_id')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')->where(['a.skuCode' => $value['skuCode']])->find();
             }
-            $value['wsm_has_account'] = (int)isset($has_account[$value['wsm_supplierNo']]);
+            $value['wsm_has_account'] = 0;//(int)isset(checkHasAccountBySupplierNos([$wsmcode['wsm_supplierNo']])[$wsmcode['wsm_supplierNo']]);
             $value['addr'] = isset($addr['addr']) ? $addr['addr_cn'] . $addr['addr'] : "";
             $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
             $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
@@ -3728,7 +3713,7 @@ class Sale extends Base
             return error_show(1002, "参数orderCoder不能为空");
         }
         $retrun =Db::name("sale_return")->where([["orderCode","=",$orderCode],["is_del","=",0],["status","in",[1,2,3,
-        7,9,10,8,11,12]]])->count();
+        7,9,10]]])->count();
         if($retrun>0){
             return error_show(1005,"存在未完成退货订单数据");
         }
@@ -3873,7 +3858,6 @@ class Sale extends Base
                     "send_num" => $send_num,
                     "check_num" => 0,
                     "error_num" => 0,
-                    "send_status" => 1,
                     "status" => 1,
                     "addtime" => date("Y-m-d H:i:s"),
                     "updatetime" => date("Y-m-d H:i:s")
@@ -3891,22 +3875,21 @@ class Sale extends Base
                         if (($temp == false || ($temp['usable_stock'] - $send_num) < 0) && $der['send_type'] == 2) {
                             $data['status'] = 0;
                         } else {
-                            //这个地方不需要更新,因为后面尝试拆单的时候会维护库存数
-//                            $up = Db::name('good_stock')
-//                                ->where('id', $temp['id'])
-//                                ->update([
-//                                    'usable_stock' => $temp['usable_stock'] - $send_num,
-//                                    'wait_out_stock' => $temp['wait_out_stock'] + $send_num,
-//                                    'updatetime' => date('Y-m-d H:i:s'),
-//                                ]);
-//                            if ($up == false) {
-//                                Db::rollback();
-//                                return error_show(1004, '库存更新失败');
-//                            }
+                            $up = Db::name('good_stock')
+                                ->where('id', $temp['id'])
+                                ->update([
+                                    'usable_stock' => $temp['usable_stock'] - $send_num,
+                                    'wait_out_stock' => $temp['wait_out_stock'] + $send_num,
+                                    'updatetime' => date('Y-m-d H:i:s'),
+                                ]);
+                            if ($up == false) {
+                                Db::rollback();
+                                return error_show(1004, '库存更新失败');
+                            }
                             // ::todo
-//                            $good_data[] = ['good_log_code' => $outCode, "stock_id" => $temp['id'], "type" => 1, 'stock' => $send_num, "stock_name" => "wait_out_stock"];
-//                            $good_data[] = ['good_log_code' => $outCode, "stock_id" => $temp['id'], "type" => 2, 'stock' => $send_num, "stock_name" => "usable_stock"];
-//                            GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, "CKD");
+                            $good_data[] = ['good_log_code' => $outCode, "stock_id" => $temp['id'], "type" => 1, 'stock' => $send_num, "stock_name" => "wait_out_stock"];
+                            $good_data[] = ['good_log_code' => $outCode, "stock_id" => $temp['id'], "type" => 2, 'stock' => $send_num, "stock_name" => "usable_stock"];
+                            GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, "CKD");
                         }
 
                     }
@@ -3925,9 +3908,6 @@ class Sale extends Base
                     //是否库存品,待办数据推送到的人有区别,
                     $process = [];
                     if ($data['status'] == 1) {
-
-                        if ($data['send_status'] == 1) OrderOutChild::makeChild($outCode);//尝试拆单
-
                         if ($der['is_stock'] == 1) {
                             //库存品,推给库管和库管-张凯旋
                             $roleid = config('app.wsm_cgder_role');
@@ -4401,11 +4381,9 @@ class Sale extends Base
 
         $stock = 0;
         if ($ct['is_stock'] == 1) {
-            $good_stock = Db::name("good_stock")->alias("a")->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")->where
-            (["spuCode" => $ct['spuCode'], "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5])->field("a.id,a.usable_stock,a.wait_out_stock")->find();
-
-            //  $good_stock = Db::name("good_stock")->where(["spuCode" => $ct['spuCode'], "is_del" => 0])->find();
-            $stock = isset($good_stock['usable_stock']) ? $good_stock['usable_stock'] : "0";
+//            $good_stock = Db::name("good_stock")->alias("a")->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")->where
+//            (["spuCode" => $ct['spuCode'], "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5])->field("a.id,a.usable_stock,a.wait_out_stock")->find();
+            $stock = Db::name("good")->where(["spuCode"=>$ct['spuCode']])->value("usable_stock",0);
         }
         if ($is_activity == 1) {
             $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b", "a.activity_code=b.activity_code")
@@ -4723,8 +4701,6 @@ class Sale extends Base
                 ->where(['id' => $rs['id'], 'status' => 2, "is_del" => 0])
                 ->update(['status' => 3, 'updatetime' => date('Y-m-d H:i:s')]);
 
-            //发货工单不做更新,发货工单只给库管人员看,不关心是否收货,只保留 待发货/已发货/已取消 这几个状态就可以了
-
             //查询该发货单所属的销售单,是否还有未收货的其他发货单
             $other_res_sale = Db::name('order_out')
                 ->where(['orderCode' => $rs['orderCode'], 'status' => 2, "is_del" => 0])
@@ -5127,7 +5103,7 @@ class Sale extends Base
 
         $list = Db::name('sale')
             ->alias('a')
-            ->field('a.id sale_id,a.order_type,a.status sale_status,a.orderCode,a.cat_id,a.good_createrid,c.id cgd_id,c.status cgd_status,c.cgdNo,c.cgder_id')
+            ->field('a.id sale_id,a.order_type,a.status sale_status,a.orderCode,a.cat_id,a.good_createrid,c.id cgd_id,c.status cgd_status')
             ->leftJoin('order_num b', 'b.orderCode=a.orderCode')
             ->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
             ->where(['a.is_del' => 0, 'a.orderCode' => $orderCode])
@@ -5162,37 +5138,21 @@ class Sale extends Base
 //                }
 
                 //修改状态,添加待办
-                ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
-                    "order_code" => $sale['orderCode'],//销售单号
-                    "status" => $sale['sale_status'],//这里的status是之前的值
-                    "action_remark" => '',//备注
-                    "action_type" => "status"//新建create,编辑edit,更改状态status
-                ], "XSQRD", 3, ['orderCode' => $orderCode]);
-
-                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
-                    "order_type" => 'XSQRD',
-                    "order_code" => $sale['orderCode'],
-                    "order_id" => $sale['sale_id'],
-                    "order_status" => 3,
-                    "before_status" => $sale['sale_status'],
-                    'holder_id' => $sale['good_createrid'],
-                ]);
-
-                ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
-                    "order_code" => $sale['cgdNo'],//销售单号
-                    "status" => $sale['cgd_status'],//这里的status是之前的值
-                    "action_remark" => '',//备注
-                    "action_type" => "status"//新建create,编辑edit,更改状态status
-                ], "CGD", 4, ['orderCode' => $sale['cgdNo']]);
-
-                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
-                    "order_type" => 'CGD',
-                    "order_code" => $sale['cgdNo'],
-                    "order_id" => $sale['cgd_id'],
-                    "order_status" => 4,
-                    "before_status" => $sale['cgd_status'],
-                    'holder_id' => $sale['cgder_id'],
-                ]);
+//                ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
+//                    "order_code" => $sale['orderCode'],//销售单号
+//                    "status" => $sale['sale_status'],//这里的status是之前的值
+//                    "action_remark" => '',//备注
+//                    "action_type" => "edit"//新建create,编辑edit,更改状态status
+//                ], "XSQRD", 3, ['orderCode' => $orderCode]);
+//
+//                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
+//                    "order_type" => 'XSQRD',
+//                    "order_code" => $sale['orderCode'],
+//                    "order_id" => $sale['sale_id'],
+//                    "order_status" => 3,
+//                    "before_status" => $sale['sale_status'],
+//                    'holder_id' => $sale['good_createrid'],
+//                ]);
             }
             Db::name('sale')
                 ->where(['is_del' => 0, 'id' => array_column($list, 'sale_id')])
@@ -5202,62 +5162,13 @@ class Sale extends Base
                 ->where(['is_del' => 0, 'id' => array_column($list, 'cgd_id')])
                 ->update(['status' => 4, 'updatetime' => $date]);
 
-            $out_list = Db::name('order_out')
+            Db::name('order_out')
                 ->where(['is_del' => 0, 'orderCode' => $orderCode])
-                ->select()
-                ->toArray();
-            if (!empty($out_list)) {
-                Db::name('order_out')
-                    ->field('id,outCode,status')
-                    ->where(['is_del' => 0, 'orderCode' => $orderCode])
-                    ->update(['status' => 5, 'updatetime' => $date]);
-                foreach ($out_list as $out) {
-                    ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
-                        "order_code" => $out['outCode'],//销售单号
-                        "status" => $out['status'],//这里的status是之前的值
-                        "action_remark" => '',//备注
-                        "action_type" => "status"//新建create,编辑edit,更改状态status
-                    ], "CKD", 5, $out);
+                ->update(['status' => 5, 'updatetime' => $date]);
 
-                    ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
-                        "order_type" => 'CKD',
-                        "order_code" => $out['outCode'],
-                        "order_id" => $out['id'],
-                        "order_status" => 5,
-                        "before_status" => $out['status'],
-                        'holder_id' => $out['apply_id'],
-                    ]);
-                }
-            }
-
-
-            $ooc_list = Db::name('order_out_child')
+            Db::name('order_out_child')
                 ->where(['is_del' => 0, 'orderCode' => $orderCode])
-                ->select()
-                ->toArray();
-            if (!empty($ooc_list)) {
-                Db::name('order_out_child')
-                    ->where(['is_del' => 0, 'orderCode' => $orderCode])
-                    ->update(['status' => 5, 'updatetime' => $date]);
-                foreach ($ooc_list as $ooc) {
-                    ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
-                        "order_code" => $ooc['outChildCode'],//销售单号
-                        "status" => $ooc['status'],//这里的status是之前的值
-                        "action_remark" => '',//备注
-                        "action_type" => "status"//新建create,编辑edit,更改状态status
-                    ], "FHGD", 5, $ooc);
-
-                    ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
-                        "order_type" => 'FHGD',
-                        "order_code" => $ooc['outChildCode'],
-                        "order_id" => $ooc['id'],
-                        "order_status" => 5,
-                        "before_status" => $ooc['status'],
-                        'holder_id' => $ooc['apply_id'],
-                    ]);
-                }
-            }
-
+                ->update(['status' => 5, 'updatetime' => $date]);
 
             Db::commit();
             return json_show(0, '操作成功');