Просмотр исходного кода

Merge branch 'master-new-wgg' of wugg/phpstock into master-new

wugg 1 год назад
Родитель
Сommit
0bf4ce81e9

+ 67 - 41
app/admin/controller/AfterChild.php

@@ -2,8 +2,8 @@
 
 namespace app\admin\controller;
 
-use app\admin\model\DataGroup as DataGroupModel;
-use think\Exception;
+use app\admin\model\ActionLog;use app\admin\model\DataGroup as DataGroupModel;
+use app\admin\model\ProcessOrder;use think\Exception;
 use think\facade\Db;
 use think\facade\Validate;
 
@@ -282,24 +282,40 @@ class AfterChild extends Base
 
                 if ($insert) Db::name('order_return_child')->insertAll($insert);
 
-//                Db::name('order_return_child')
-//                    ->where(['is_del' => 0, 'id' => $value['id']])
-//                    ->update([
-//                        'can_sell_num' => $value['can_sell_num'],
-//                        'defective_num' => $value['defective_num'],
-//                        'loss_num' => $value['loss_num'],
-//                        'remark' => $value['remark'] ?? '',
-//                        'updatetime' => $date,
-//                        'status' => 2,
-//                        'return_num_total' => $value['can_sell_num']
-//                    ]);
-
                 //发货工单数量减少
-                Db::name('order_out_child')
+                $ot=Db::name('order_out_child')
                     ->data(['updatetime' => $date])
                     ->where(['is_del' => 0, 'outChildCode' => $info[$value['id']]['outChildCode']])
                     ->dec('num', $info[$value['id']]['return_num'])
                     ->update();
+                if($ot==false) throw new \Exception('发货工单更新失败');
+                $orde = Db::name('order_out')
+                            ->field('id,outCode,status')
+                            ->where(['outCode' => $info[$value['id']]['outCode'], 'is_del' => 0])
+                            ->findOrEmpty();
+                        if (empty($orde)) throw new \Exception('未找到出库单数据');
+
+                        $sale = Db::name('sale')
+                            ->field('id,th_num,th_fee,sale_price,good_code,good_name,cat_id')
+                            ->where(['is_del' => 0, 'orderCode' => $info[$value['id']]['orderCode']])
+                            ->findOrEmpty();
+                        if (empty($sale)) throw new \Exception('未找到销售单数据');
+
+                        $od_status = $orde['status'];
+                        $orde['status'] = 4;
+                        $orde['updatetime'] = $date;
+                        $out = Db::name('order_out')->save($orde);
+                        if ($out == false) throw new Exception('发货单更新失败');
+						 $action_log_user = ['id' => $this->uid, 'nickname' => $this->uname];
+                        $order = ['order_code' => $orde['outCode'], 'status' => $od_status, 'action_remark' => '', 'action_type' => 'edit'];
+                        ActionLog::logAdd($action_log_user, $order, 'CKD', $orde['status'], $this->post);
+                        $process = ['order_code' => $orde['outCode'], 'order_id' => $orde['id'], 'order_status' => $orde['status'], 'order_type' => 'CKD', 'before_status' => $od_status];
+                        ProcessOrder::AddProcess($action_log_user, $process);
+                        $sale['th_num'] += $info[$value['id']]['return_num'];
+                        $sale['th_fee'] += round($info[$value['id']]['return_num']* $sale['sale_price'], 2);
+                        $sale['updatetime'] = $date;
+                        $sup = Db::name('sale')->save($sale);
+                        if ($sup == false) throw new \Exception('销售单更新失败');
             }
 
             $total = array_sum(array_column($param['list'], 'can_sell_num'));
@@ -318,7 +334,7 @@ class AfterChild extends Base
                                 ->where('spuCode', $order_return['good_code'])
                                 ->findOrEmpty();
                             if (!empty($good)) {
-                                Db::name('good_basic')->insert(array_merge($good, [
+                                $up2=Db::name('good_basic')->insert(array_merge($good, [
                                     'id' => null,
                                     'is_stock' => 1,
                                     'spuCode' => $spuCode,
@@ -328,13 +344,14 @@ class AfterChild extends Base
                                     'createrid'=>0,
                                     'creater'=>'system'
                                 ]));
+                                 if($up2==false) throw new \Exception("{$order_return['good_code']} 商品库新增失败");
                             }
                         } else {
                             $good = Db::name('good_zixun')
                                 ->where(['spuCode' => $order_return['good_code']])
                                 ->findOrEmpty();
                             if (!empty($good)) {
-                                Db::name('good_basic')->insert([
+                               $up= Db::name('good_basic')->insert([
                                     'spuCode' => $spuCode,
                                     'good_code' => $good['good_code'],
                                     'good_name' => $good['good_name'],
@@ -404,12 +421,14 @@ class AfterChild extends Base
                                     'charger' => $good['creater'],
                                     'is_support_stock' => 1
                                 ]);
+                               
+                               if($up==false) throw new \Exception("咨询商品录入商品库失败");
                             }
                         }
 
                         if (!empty($good)) {
                             //关联表增数据
-                            Db::name('good_change_stock')
+                           $dd= Db::name('good_change_stock')
                                 ->insert([
                                     'old_spuCode' => $order_return['good_code'],
                                     'old_order_type' => $order_return['order_type'],
@@ -417,6 +436,7 @@ class AfterChild extends Base
                                     'addtime' => $date,
                                     'updatetime' => $date,
                                 ]);
+                           if($dd==false) throw new \Exception('关联表新增失败');
 
                         } else throw new Exception('未找到对应的商品数据');
 
@@ -432,11 +452,12 @@ class AfterChild extends Base
                     $origin_price = $j = 0;
                     foreach ($child_bns as $child_bn) {
                         if ($origin_price === 0) $origin_price = $child_bn['origin_price'];
-                        Db::name('child_bn')
+                       $bn= Db::name('child_bn')
                             ->data(['updatetime' => $date])
                             ->where(['id' => $child_bn['id']])
                             ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
                             ->update();
+                        if($bn==false) throw new \Exception('商品库bn数据更新失败');
                         $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
                         if ($total == 0) break;
                     }
@@ -459,8 +480,8 @@ class AfterChild extends Base
                                     'addtime' => $date,
                                     'updatetime' => $date,
                                 ]);
-
-                            Db::name('good_stock_info')
+                    if($stockid==false) throw new \Exception('商品库存新增失败');
+                         $stockinfo=   Db::name('good_stock_info')
                                 ->insert([
                                     'stockid' => $stockid,
                                     'bnCode' => substr(makeNo("BN"), 0, -2) . str_pad($j++, 2, '0', STR_PAD_LEFT),
@@ -471,9 +492,11 @@ class AfterChild extends Base
                                     'addtime' => $date,
                                     'updatetime' => $date,
                                 ]);
+                         if($stockinfo==false) throw new \Exception('商品库存BN新增失败');
                         }
                     }
-                } else {
+                }
+                else {
                     //库存品,直接维护stock和info
                     $stockids = Db::name('good_stock')
                         ->where(['is_del' => 0, 'spuCode' => $order_return['good_code'], 'wsm_code' => array_column($info, 'return_wsm_code')])
@@ -497,13 +520,13 @@ class AfterChild extends Base
 
                                 $total = $value['can_sell_num'];
                                 foreach ($child_bns as $child_bn) {
-                                    Db::name('child_bn')
+                                 $bns=   Db::name('child_bn')
                                         ->data(['updatetime' => $date])
                                         ->where(['id' => $child_bn['id']])
                                         ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
                                         ->update();
-
-                                    Db::name('good_stock_info')
+								if($bns==false) throw new \Exception('商品库存BN数量新增失败');
+                                  $bninfo=  Db::name('good_stock_info')
                                         ->insert([
                                             'stockid' => $stockids[$info[$value['id']]['return_wsm_code']],
                                             'bnCode' => $child_bn['bnCode'],
@@ -514,28 +537,29 @@ class AfterChild extends Base
                                             'addtime' => $date,
                                             'updatetime' => $date,
                                         ]);
-
+									if($bninfo==false) throw new \Exception('商品库存BN更新失败');
                                     $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
                                     if ($total == 0) break;
                                 }
                             } else {
                                 //维护记录
-                                Db::name('good_stock_info')
+                             $bninfo=   Db::name('good_stock_info')
                                     ->data(['updatetime' => $date])
                                     ->where(['id' => $good_stock_info['id']])
                                     ->inc('balance_num', $value['can_sell_num'])//可用数量增加
                                     ->dec('used_num', $value['can_sell_num'])//已用数量减少
                                     ->update();
+                             if($bninfo==false) throw new \Exception('商品库存BN更新失败');
                             }
 
                             //维护good_stock
-                            Db::name('good_stock')
+                          $stockinfoe=  Db::name('good_stock')
                                 ->data(['updatetime' => $date])
                                 ->where(['is_del' => 0, 'id' => $stockids[$info[$value['id']]['return_wsm_code']]])
                                 ->inc('usable_stock', $value['can_sell_num'])
                                 ->inc('total_stock', $value['can_sell_num'])
                                 ->update();
-
+                    if($stockinfoe==false) throw new \Exception('商品库存更新失败');
                         } else {
                             //新建good_stock和good_stock_info
                             $stockid = Db::name('good_stock')
@@ -554,7 +578,7 @@ class AfterChild extends Base
                                     'addtime' => $date,
                                     'updatetime' => $date,
                                 ]);
-
+							if($stockid==false) throw new \Exception('商品库存新增失败');
                             //从child_bn查询bn号并维护,新建到good_stock_info中
                             $child_bns = Db::name('child_bn')
                                 ->field('id,num,bnCode,origin_price')
@@ -564,13 +588,13 @@ class AfterChild extends Base
 
                             $total = $value['can_sell_num'];
                             foreach ($child_bns as $child_bn) {
-                                Db::name('child_bn')
+                                $bn=Db::name('child_bn')
                                     ->data(['updatetime' => $date])
                                     ->where(['id' => $child_bn['id']])
                                     ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
                                     ->update();
-
-                                Db::name('good_stock_info')
+								if($bn==false) throw new \Exception('商品库存BN更新失败');
+                                $bninfo=Db::name('good_stock_info')
                                     ->insert([
                                         'stockid' => $stockid,
                                         'bnCode' => $child_bn['bnCode'],
@@ -581,7 +605,7 @@ class AfterChild extends Base
                                         'addtime' => $date,
                                         'updatetime' => $date,
                                     ]);
-
+								if($bninfo==false) throw new \Exception('商品库存BN新增失败');
                                 $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
                                 if ($total == 0) break;
                             }
@@ -590,25 +614,27 @@ class AfterChild extends Base
                     }
 
                     //维护商品层面的库存数
-                    Db::name('good')
+                  $goodinfo=  Db::name('good')
                         ->data(['updatetime' => $date])
                         ->where(['is_del' => 0, 'spuCode' => $order_return['good_code']])
                         ->inc('usable_stock', array_sum(array_column($param['list'], 'can_sell_num')))
                         ->update();
+                    if($goodinfo==false) throw new \Exception('商品可售库存数更新失败');
 
                 }
             }
 
             //售后申请单状态维护
-            Db::name('order_return')
+            $Reup=Db::name('order_return')
                 ->where(['is_del' => 0, 'returnCode' => $param['returnCode'], 'status' => 12])
                 ->update(['status' => 5, 'updatetime' => $date]);
-
+			 if($Reup==false) throw new \Exception('售后申请退货状态更新失败');
             //售后退货工单设置信息维护
-            Db::name('order_return_prepare')
+            $Reupchild=Db::name('order_return_prepare')
                 ->where(['is_del' => 0, 'status' => 1, 'id' => array_column($info, 'id')])
                 ->update(['updatetime' => $date, 'status' => 3]);
-			 $data = [
+             if($Reupchild==false) throw new \Exception('售后申请退货工单状态更新失败');
+            $data = [
                             "orderCode" => $order_return['orderCode'],
                             "th_type" => 2,
                             "th_num" => $order_return['error_num'],
@@ -623,8 +649,8 @@ class AfterChild extends Base
                             "status" => 1,
                             "is_del" => 0
                         ];
-                        $inse = Db::name("th_data")->insert($data);
-                        if ($inse == false) throw new Exception('退回单更新失败');
+            $inse = Db::name("th_data")->insert($data);
+            if ($inse == false) throw new Exception('退回单更新失败');
             Db::commit();
             return json_show(0, '库管收货成功');
         } catch (Exception $exception) {

+ 259 - 108
app/admin/controller/Filing.php

@@ -2,7 +2,6 @@
 
 namespace app\admin\controller;
 
-use think\Exception;
 use think\facade\Db;
 use think\facade\Validate;
 
@@ -12,7 +11,8 @@ class Filing extends Base
     //列表
     public function getList()
     {
-        $data = $this->request->only(['page' => 1, 'size' => 10, 'cat_id' => '', 'start_date' => '', 'end_date' => '', 'filingCode' => '', 'status' => '', 'good_name' => '', 'companyName' => '', 'companyCode' => '', 'orderCode' => '', 'supplierNo' => ''], 'post');
+        $data = $this->request->only(['page' => 1, 'size' => 10, 'cat_id' => '', 'start_date' => '', 'end_date' => '',
+        'filingCode' => '', 'status' => '', 'good_name' => '', 'companyName' => '', 'companyCode' => '', 'orderCode' => '','customerCode' => '', 'supplierNo' => ''], 'post');
 
         $where = [['is_del', '=', '0']];
         if ($data['cat_id'] != '') $where[] = ['cat_id', '=', $data['cat_id']];
@@ -23,14 +23,17 @@ class Filing extends Base
         if ($data['companyName'] != '') $where[] = ['companyName', 'like', '%' . $data['companyName'] . '%'];
         if ($data['companyCode'] != '') $where[] = ['companyCode', 'like', '%' . $data['companyCode'] . '%'];
         if ($data['orderCode'] != '') $where[] = ['orderCode', 'like', '%' . $data['orderCode'] . '%'];
-        if ($data['supplierNo'] != '') $where[] = ['supplierNo', '=', $data['supplierNo']];
+        if ($data['supplierNo'] != '') $where[] = ['supplierNo', 'like', '%' . $data['supplierNo']. '%' ];
+        if ($data['customerCode'] != '') $where[] = ['customerCode', 'like', '%' . $data['customerCode'] . '%'];
 
         $count = Db::name('filing')
             ->where($where)
             ->count('id');
 
         $list = Db::name('filing')
-            ->field('id,filingCode,cat_id,good_name,num,good_img,price,expect_service,companyName,companyCode,status,addtime,"" catinfo,orderCode,cgd_charge')
+            ->field('id,filingCode,cat_id,good_name,num,wait_num,transfer_num,good_img,
+            price,expect_service,companyName,companyCode,status,addtime,supplierNo,supplierName,customerCode,customerName,
+            "" catinfo,orderCode,cgd_charge')
             ->where($where)
             ->page($data['page'], $data['size'])
             ->order('id', 'desc')
@@ -39,24 +42,52 @@ class Filing extends Base
             })
             ->select()
             ->toArray();
-
+		 $has_account = checkHasAccountBySupplierNos(array_unique(array_column($list,'supplierNo')));
         $all_cat = [];
         foreach ($list as &$value) {
             if (!isset($all_cat[$value['cat_id']])) $all_cat[$value['cat_id']] = implode('/', array_column(made($value['cat_id']), 'name'));
-
             $value['catinfo'] = $all_cat[$value['cat_id']];
+            $value['wsm_has_account'] = (int)isset($has_account[$value['supplierNo']]);
+            
         }
-
         return json_show(0, '获取报备单列表成功', ['count' => $count, 'list' => $list]);
-
-
-//        return FilingLogic::list($param);
     }
 
     //添加
     public function add()
     {
-        $param = $this->request->only(['customerCode', 'supplierNo', 'companyName', 'num', 'is_determine_price', 'price' => 0, 'expect_service_proportion', 'expect_service', 'cgd_charge' => 0, 'brand_id', 'preservation_day', 'delivery_day', 'make_day', 'tax', 'unit_id', 'cat_id', 'spec_list' => [], 'good_name', 'origin_place', 'delivery_place', 'weight', 'supply_area', 'pay_way', 'gold_weight', 'noble_metal', 'config', 'other_config', 'remark', 'cost_desc', 'good_img'], 'post');
+        $param = $this->request->filter(["trim",'strip_tags'])->only([
+        	'customerCode',
+        	'supplierNo',
+        	'companyName',
+        	'num',
+        	'is_determine_price',
+        	'price' => 0,
+        	'expect_service_proportion',
+        	'expect_service',
+        	'cgd_charge' => 0,
+        	'brand_id',
+        	'fill_url',
+        	'preservation_day',
+        	'delivery_day',
+        	'make_day',
+        	'tax',
+        	'unit_id',
+        	'cat_id',
+        	'spec_list' => [],
+        	'good_name',
+        	'origin_place',
+        	'delivery_place',
+        	'weight',
+        	'supply_area',
+        	'pay_way',
+        	'gold_weight',
+        	'noble_metal',
+        	'config',
+        	'other_config',
+        	'remark',
+        	'cost_desc',
+        	'good_img'], 'post');
 
         $val = Validate::rule([
             'customerCode|业务公司' => 'require|max:255',
@@ -69,6 +100,7 @@ class Filing extends Base
             'expect_service|期望服务费' => 'require|float|max:99999999.99',
             'cgd_charge|采购价' => 'requireIf:is_determine_price,0|float|max:99999999.99',
             'brand_id|品牌' => 'require|number|gt:0',
+            'fill_url|报备附件' => 'require',
             'preservation_day|有效期' => 'require|number|max:999999999',
             'delivery_day|物流时间' => 'require|number|max:999999999',
             'make_day|生产工期' => 'require|number|max:999999999',
@@ -123,10 +155,6 @@ class Filing extends Base
         if ($param['is_determine_price'] == 1) $param['cgd_charge'] = round(bcsub($param['price'], $param['expect_service'], 3), 2);//确定售价时,采购价=售价-服务费
         else $param['price'] = round(bcadd($param['cgd_charge'], $param['expect_service'], 3), 2);//不确定售价时,售价=采购价+服务费
 
-//        $customerName = Db::name('business')
-//            ->where(['companyNo' => $param['customerCode']])
-//            ->value('company', '');
-//        if ($customerName == '') return json_show(1004, '该业务公司不存在');
         $userCommon = \app\admin\common\User::getIns();
         $names = $userCommon->handle('getCodeAndName', ['code' => [$param['customerCode'], $param['supplierNo']]]);
         if (!isset($names['data'][$param['customerCode']]) || $names['data'][$param['customerCode']] == '') return json_show(1004, '该业务公司不存在');
@@ -141,6 +169,7 @@ class Filing extends Base
                 'service_proportion' => $param['expect_service_proportion'],//服务费比例与期望服务费比例一致
                 'service_charge' => $param['expect_service'],//服务费与期望服务费一致
                 'specinfo' => json_encode($param['spec_list']),
+                "wait_num"=>$param["num"],
                 'send_way' => 2,
                 'cert_fee' => 0,
                 'pakge_fee' => 0,
@@ -148,6 +177,7 @@ class Filing extends Base
                 'mark_fee' => 0,
                 'demo_fee' => 0,
                 'open_fee' => 0,
+                'fill_url' =>$param['fill_url'],
                 'delivery_fee' => 0,
                 'is_gold_price' => 0,
                 'is_diff' => 0,
@@ -170,14 +200,145 @@ class Filing extends Base
 
         return $rs ? json_show(0, '创建报备单成功') : json_show(1004, '创建报备单失败');
 
+    }
+    //添加
+    public function save()
+    {
+        $param = $this->request->filter(['trim','strip_tags'])->only(["id",
+        	'customerCode',
+        	'supplierNo',
+        	'companyName',
+        	'num',
+        	'is_determine_price',
+        	'price' => 0,
+        	'expect_service_proportion',
+        	'expect_service',
+        	'cgd_charge' => 0,
+        	'brand_id',
+        	'preservation_day',
+        	'delivery_day',
+        	'make_day',
+        	'tax',
+        	  'fill_url' ,
+        	'unit_id',
+        	'cat_id',
+        	'spec_list' => [],
+        	'good_name',
+        	'origin_place',
+        	'delivery_place',
+        	'weight',
+        	'supply_area',
+        	'pay_way',
+        	'gold_weight',
+        	'noble_metal',
+        	'config',
+        	'other_config',
+        	'remark',
+        	'cost_desc',
+        	'good_img'], 'post');
+
+        $val = Validate::rule([
+            'id|报备单主键id' => 'require',
+            'customerCode|业务公司' => 'require|max:255',
+            'supplierNo|供应商' => 'require|max:255',
+            'companyName|客户名称' => 'require|max:255',
+            'num|销售数量' => 'require|number|gt:0|lt:999999999',
+            'is_determine_price|是否确定售价' => 'require|number|in:1,0',
+            'price|销售价' => 'requireIf:is_determine_price,1|float|max:99999999.99',
+            'expect_service_proportion|期望服务费比例' => 'require|float|between:0,100',
+            'expect_service|期望服务费' => 'require|float|max:99999999.99',
+            'cgd_charge|采购价' => 'requireIf:is_determine_price,0|float|max:99999999.99',
+            'brand_id|品牌' => 'require|number|gt:0',
+            'preservation_day|有效期' => 'require|number|max:999999999',
+            'delivery_day|物流时间' => 'require|number|max:999999999',
+            'make_day|生产工期' => 'require|number|max:999999999',
+            'fill_url|报备附件' =>"require",
+            'tax|税点' => 'require|number|between:0,100',
+            'unit_id|单位' => 'require|number|gt:0',
+            'cat_id|分类' => 'require|number|gt:0',
+            'spec_list|规格类型' => 'array|max:100',
+            'good_name|商品名称' => 'require|max:255',
+            'origin_place|产地' => 'require|array|length:3',
+            'delivery_place|发货地' => 'require|array|length:3',
+            'weight|总重量' => 'require|float|max:99999999.99',
+            'supply_area|供货区域' => 'require|number|in:1,2',
+            'pay_way|付款方式' => 'require|number|in:0,1,2',
+            'remark|采购备注' => 'require|max:255',
+            'cost_desc|工艺说明' => 'max:255',
+            'good_img|商品图片' => 'require|array|max:10',
+        ]);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+		$row= Db::name("filing")->findOrEmpty($param["id"]);
+		if(empty($row))  return json_show(1004, "未找到数据");
+        //如果是贵金属的话,额外判断
+        $cat = made($param['cat_id']);
+        if (isset($cat[0]['id']) && $cat[0]['id'] == 6) {
+            $val_gold = Validate::rule([
+                'gold_weight|贵金属重量' => 'require|float|max:99999999.99',
+                'noble_metal|贵金属类型' => 'require|number|in:1,2,3',
+                'config|配置要求' => 'require|max:255',
+                'other_config|其他配置要求' => 'require|max:255',
+            ]);
+            if (!$val_gold->check($param)) return json_show(1004, $val_gold->getError());
+        }
 
-//        $param['supplierNo']= $this->request->user['supplierNo'];
-//        $param['supplierName']= $this->request->user['supplierName'];
+        $val2 = Validate::rule([
+            'spec_id|规格id' => 'require|number|gt:0',
+            'spec_value_id|规格值id' => 'require|number|gt:0',
+        ]);
 
-//        return FilingLogic::add($param);
+        $all_spec = Db::name('specs')
+            ->whereIn('id', array_column($param['spec_list'], 'spec_id'))
+            ->column('spec_name', 'id');
 
-    }
+        $all_spec_value = Db::name('spec_value')
+            ->whereIn('id', array_column($param['spec_list'], 'spec_value_id'))
+            ->column('spec_value', 'id');
+
+        foreach ($param['spec_list'] as &$spec_list) {
+            if (!$val2->check($spec_list)) return json_show(1004, $val2->getError());
+            $spec_list['spec_name'] = $all_spec[$spec_list['spec_id']] ?? '';
+            $spec_list['spec_value_name'] = $all_spec_value[$spec_list['spec_value_id']] ?? '';
+        }
+
+        if ($param['is_determine_price'] == 1) $param['cgd_charge'] = round(bcsub($param['price'], $param['expect_service'], 3), 2);//确定售价时,采购价=售价-服务费
+        else $param['price'] = round(bcadd($param['cgd_charge'], $param['expect_service'], 3), 2);//不确定售价时,售价=采购价+服务费
+
+        $userCommon = \app\admin\common\User::getIns();
+        $names = $userCommon->handle('getCodeAndName', ['code' => [$param['customerCode'], $param['supplierNo']]]);
+        if (!isset($names['data'][$param['customerCode']]) || $names['data'][$param['customerCode']] == '') return json_show(1004, '该业务公司不存在');
+        if (!isset($names['data'][$param['supplierNo']]) || $names['data'][$param['supplierNo']] == '') return json_show(1004, '该供应商不存在');
+        $data=array_merge($param,[
+                'customerName' => $names['data'][$param['customerCode']],
+                'supplierName' => $names['data'][$param['supplierNo']],
+                'service_proportion' => $param['expect_service_proportion'],//服务费比例与期望服务费比例一致
+                'service_charge' => $param['expect_service'],//服务费与期望服务费一致
+                'specinfo' => json_encode($param['spec_list']),
+                'wait_num'=>$param['num'],
+                'send_way' => 2,
+                'status'=>0,
+                'is_check'=>0,
+                'fill_url'=>$param['fill_url'],
+                'apply_id' => $this->uid,
+                'apply_name' => $this->uname,
+                'updaterid' => $this->uid,
+                'updater' => $this->uname,
+                'updatetime' => date('Y-m-d H:i:s'),
+                'gold_weight' => $param['gold_weight'] ?? 0,
+                'noble_metal' => $param['noble_metal'] ?? 0,
+                'config' => $param['config'] ?? '',
+                'other_config' => $param['other_config'] ?? '',
+                'good_img' => implode(',', $param['good_img']),
+                'origin_place' => implode(',', $param['origin_place']),
+                'delivery_place' => implode(',', $param['delivery_place']),
+            ]);
+        $rs = Db::name('filing')
+            ->save(array_intersect_key($data,$row));
 
+        return $rs ? json_show(0, '报备单更新成功') : json_show(1004, '报备单更新失败');
+
+    }
     //详情
     public function detail()
     {
@@ -203,64 +364,62 @@ class Filing extends Base
                 return made($da['cat_id']);
             })
             ->findOrEmpty();
+        if(!empty($rs['origin_place']))$origin = ["provice_code"=>$rs['origin_place'][0]??"","city_code"=>$rs['origin_place'][1]??'','area_code'=>$rs['origin_place'][2]??''];
+        $rs["origin_place_cn"] = GetAddr(json_encode($origin));
+        if(!empty($rs['delivery_place']))$deliev = ['provice_code'=>$rs['delivery_place'][0]??'','city_code'=>$rs['delivery_place'][1]??'','area_code'=>$rs['delivery_place'][2]??''];
+        $rs['delivery_place_cn'] = GetAddr(json_encode($deliev));
         return json_show(0, '获取报备单详情成功', $rs);
 //        return FilingLogic::detail($param);
     }
 
-    //审核
+    //0 待审核  1 待修改 不合规 2 合规可转单 3 部分 4 转单成功 5取消转单
     public function status()
     {
         if ($this->level != 2) return json_show(1004, '业务公司账号不能审核');
 
-        $param = $this->request->only(['id', 'status', 'companyCode', 'plat_code' => '', 'service_charge', 'service_proportion', 'platform_id'], 'post');
+        $param = $this->request->only(['id', 'companyCode', 'plat_code' => '','platform_id',"remark"=>"",'is_check'=>''], 'post');
 
         $val = Validate::rule([
             'id' => 'require|number|gt:0',
-            'status|状态' => 'require|number|in:1,2',
-            'companyCode|客户' => 'require|length:18',
-            'service_charge|服务费' => 'require|float|egt:0|max:99999999.99',
-            'service_proportion|服务费比例' => 'require|float|egt:0',
-            'platform_id|平台id' => 'require|number|gt:0',
+            'companyCode|客户' => 'requireIf:is_check,2|length:18',
+            'platform_id|平台id' => 'requireIf:is_check,2|number|gt:0',
+            'plat_code|平台商品编号' => 'requireIf:is_check,2|max:255',
+            "is_check|是否合规"=> 'require|number|in:1,2',
+            "remark|备注"=> 'requireIf:is_check,1',
         ]);
 
         if (!$val->check($param)) return json_show(1004, $val->getError());
-
         $rs = Db::name('filing')
-            ->field('id,status,is_determine_price,price,cgd_charge,platform_id,companyCode')
-            ->where(['is_del' => 0, 'id' => $param['id']])
-            ->whereIn('status', [0, 2])
+            ->field('id,status,is_determine_price,price,cgd_charge,platform_id,customerCode,customerName')
+            ->where(['is_del' => 0, 'id' => $param['id'],"status"=>0])
             ->findOrEmpty();
         if (empty($rs)) return json_show(1005, '该报备单不存在或不允许审核');
 
         $userCommon = \app\admin\common\User::getIns();
         $company = $userCommon->handle('cInfo', ['companyNo' => $param['companyCode']]);
         if (!isset($company['data'])) return json_show(1005, '该客户不存在');
-//        $companyName = Db::name('customer_info')
-//            ->where(['is_del' => 0, 'companyNo' => $param['companyCode']])
-//            ->value('companyName', '');
-//        if ($companyName == '') return json_show(1005, '该客户不存在');
-
         $tmp = Db::name('platform')
             ->where(['is_del' => 0, 'id' => $param['platform_id']])
             ->field('id,is_select_pay_rate,status')
             ->findOrEmpty();
         if (empty($tmp)) return json_show(1005, '该平台不存在');
         if ($tmp['status'] != 1) return error_show(1004, "平台信息已禁用");
-	    if($tmp['is_select_pay_rate']==1 && channel_is_company($param['platform_id'],$param['companyCode']))return
-	    error_show(1004, "平台渠道包含当前业务公司 {$company['data']['companyName']}");
+	    if($tmp['is_select_pay_rate']==1 && channel_is_company($param['platform_id'],$rs['customerCode']))return
+	    error_show(1004, "平台渠道包含当前业务公司 {$rs['customerName']}");
 
 
         //校验支付渠道中的业务公司是否与报备单业务公司重复
 
         $update = array_merge($param, [
             'companyName' => $company['data']['companyName'],
+            "status"=>$param["is_check"],
             'updaterid' => $this->uid,
             'updater' => $this->uname,
             'updatetime' => date('Y-m-d H:i:s'),
         ]);
-
-        if ($rs['is_determine_price'] == 1) $update['cgd_charge'] = round(bcsub($rs['price'], $param['service_charge'], 3), 2);//确定售价时,采购价=售价-服务费
-        else $update['price'] = round(bcadd($rs['cgd_charge'], $param['service_charge'], 3), 2);//不确定售价时,售价=采购价+服务费
+//
+//        if ($rs['is_determine_price'] == 1) $update['cgd_charge'] = round(bcsub($rs['price'], $param['service_charge'], 3), 2);//确定售价时,采购价=售价-服务费
+//        else $update['price'] = round(bcadd($rs['cgd_charge'], $param['service_charge'], 3), 2);//不确定售价时,售价=采购价+服务费
 
         $res = Db::name('filing')
             ->where(['is_del' => 0, 'id' => $param['id']])
@@ -278,13 +437,11 @@ class Filing extends Base
         if ($this->level == 1) return json_show(1004, '超管不允许操作');
 
         $param = $this->request->only(['id'], 'post');
-//        $param['supplierNo'] = $this->request->user['supplierNo'];
-//        return FilingLogic::cancel($param);
+
 
         $where = [
             ['is_del', '=', 0],
             ['id', '=', $param['id']],
-//            ['supplierNo', '=', $param['supplierNo']],
             ['status', 'in', [0, 1, 2, 4]]
         ];
 
@@ -294,12 +451,7 @@ class Filing extends Base
             ->findOrEmpty();
         if (empty($rs)) return json_show(1005, '该报备单不存在或不允许取消');
 
-        //level3账号都可以操作
-        //level2账号的话,只有供应商负责人能操作
         if ($this->level == 2) {
-//            $userCommon = \app\admin\common\User::getIns();
-//            $supp = $userCommon->handle('sInfo', ['code' => $rs['supplierNo']]);
-
             $supp = get_personid_by_supplierNo([$rs['supplierNo']]);
             if ($this->uid != $supp[$rs['supplierNo']]) return json_show(1004, '只有供应商负责人才能操作');
         }
@@ -315,10 +467,14 @@ class Filing extends Base
     {
         if ($this->level == 1) return json_show(1004, '超管不允许操作');
 
-        $param = $this->request->only(['id', 'addr_list'], 'post');
+        $param = $this->request->only([
+        	'id',
+        'addr_list'=>[],
+        "customerCode"=>""], 'post');
 
         $val = Validate::rule([
-            'id' => 'require|number|gt:0',
+            'id|报备的主键id' => 'require|number|gt:0',
+            "customerCode|客户编号"=>"require|max:255",
             'addr_list|收货地址' => 'require|array|max:100',
         ]);
 
@@ -328,7 +484,7 @@ class Filing extends Base
             'receipt_quantity|收货数量' => 'require|number|gt:0|max:999999999',
             'contactor|联系人' => 'require|max:255',
             'mobile|联系电话' => 'require|mobile',
-            'addr_code|收货省市区编码' => 'require|array|length:3',
+            'addr_code|收货省市区编码' => 'array|length:3',
             'addr|详细地址' => 'require|max:255',
         ]);
 
@@ -336,25 +492,21 @@ class Filing extends Base
         foreach ($param['addr_list'] as $addr_list) {
             if (!$val2->check($addr_list)) return json_show(1004, $val2->getError());
         }
-
+		
         $filing = Db::name('filing')
             ->field(true)
-            ->where(['is_del' => 0, 'id' => $param['id'], 'status' => 2])
+            ->where(['is_del' => 0, 'id' => $param['id'], 'status' => [2,3]])
             ->findOrEmpty();
         if (empty($filing)) return json_show(1005, '该报备单不存在或不允许转单');
-
-        if (array_sum(array_column($param['addr_list'], 'receipt_quantity')) != $filing['num']) return json_show(1004, '收货地址的收货总数不符合');
-
-
-//        $supplier = Db::name('supplier')
-//            ->field('id,person,personid,name,code')
-//            ->where(['code' => $filing['supplierNo']])
-//            ->findOrEmpty();
+        $send_num = array_sum(array_column($param['addr_list'], 'receipt_quantity'));
+		$wait_num = $filing['wait_num'] - $send_num ;
+        if ($wait_num<0) return json_show(1004, '收货地址的收货总数超过报备单可转单数量');
+        
         $userCommon = \app\admin\common\User::getIns();
         $supplier = $userCommon->handle('sInfo', ['code' => $filing['supplierNo']]);
 
-//        $names = $userCommon->handle('getCodeAndName', ['code' => [$filing['companyCode'], $filing['customerCode'],]]);
-
+        $names = $userCommon->handle('getCodeAndName', ['code' => [ $param['customerCode']]]);
+		if (!isset($names['data'])) return json_show(1005, '该客户不存在');
         //level3账号都可以操作
         //level2账号的话,只有供应商负责人能操作
         if (($this->level == 2) && ($this->uid != $supplier['data']['personid'])) return json_show(1004, '只有供应商负责人才能操作');
@@ -371,7 +523,7 @@ class Filing extends Base
             $spuCode = makeNo('SKU');
 
             //商品表
-            Db::name('good_zixun')
+         $goodIn=   Db::name('good_zixun')
                 ->insert([
                     'spuCode' => $spuCode,
                     'good_name' => $filing['good_name'],
@@ -410,11 +562,12 @@ class Filing extends Base
                     'pay_way' => $filing['pay_way'],
                     'send_way' => $filing['send_way'],
                     'companyNo' => $filing['customerCode'],
+                    'companyName' => $filing['customerName'],
                     'proof_type' => '',
                     'proof_url' => '',
                     'order_type' => $order_type
                 ]);
-
+			if($goodIn==false) throw new \Exception("商品录入商品库失败");
             $orderCode = makeNo('QR');
             //订单表
             //sale
@@ -429,7 +582,7 @@ class Filing extends Base
                 'skuCode' => '',
                 'cat_id' => $filing['cat_id'],
                 'good_name' => $filing['good_name'],
-                'good_num' => $filing['num'],
+                'good_num' => $send_num,
                 'good_type' => 1,
                 'origin_price' => $filing['cgd_charge'],
                 'sale_price' => $filing['price'],
@@ -439,16 +592,16 @@ class Filing extends Base
                 'is_activity' => 0,
                 'activity_code' => '',
                 'is_stock' => 0,
-                'customer_code' => $filing['companyCode'],
-                'customerName' => $filing['companyName'],
+                'customer_code' => $param['customerCode'],
+                'customerName' => $names['data'][$param['customerCode']]??"",
                 'supplierNo' => $filing['customerCode'],
                 'supplierName' => $filing['customerName'],
                 'supNo' => $filing['supplierNo'],
                 'supName' => $filing['supplierName'],
                 'zxNo' => '',
-                'platform_order' => '',
+                'platform_order' =>$filing['filingCode'],
                 'send_num' => 0,
-                'wsend_num' => $filing['num'],
+                'wsend_num' => $send_num,
                 'th_num' => 0,
                 'th_fee' => 0,
                 'send_status' => 1,
@@ -474,7 +627,7 @@ class Filing extends Base
                 'good_createrid' => $filing['updaterid'],
                 'good_creater' => $filing['updater'],
             ]);
-
+			if($sale_id==false)  throw new \Exception('订单生成失败');
 
             //仓库
             $wsm = Db::name('warehouse_info')
@@ -484,7 +637,7 @@ class Filing extends Base
             if (empty($wsm)) {
                 $wsm_code = makeNo('WSM');
 
-                Db::name('warehouse_info')->insert([
+              $ws=  Db::name('warehouse_info')->insert([
                     'wsm_code' => $wsm_code,
                     'name' => $supplier['data']['name'],
                     'wsm_type' => 2,
@@ -501,13 +654,13 @@ class Filing extends Base
                     'addtime' => $date,
                     'updatetime' => $date,
                 ]);
-
+              if($ws==false)throw new \Exception('仓库生成失败');
             } else  $wsm_code = $wsm['wsm_code'];
 
             //采购单
             $cgdCode = makeNo('CG');
 
-            Db::name('purchease_order')->insert([
+           $cg= Db::name('purchease_order')->insert([
                 'cgdNo' => $cgdCode,
                 'bkcode' => '',
                 'wsm_code' => $wsm_code,
@@ -515,7 +668,7 @@ class Filing extends Base
                 'cgder_id' => $supplier['data']['personid'],
                 'spuCode' => $spuCode,
                 'good_name' => $filing['good_name'],
-                'good_num' => $filing['num'],
+                'good_num' => $send_num,
                 'good_price' => $filing['cgd_charge'],
                 'total_fee' => round(bcmul($filing['cgd_charge'], $filing['num']), 2),
                 'pakge_fee' => $filing['pakge_fee'],
@@ -533,7 +686,7 @@ class Filing extends Base
                 'companyName' => $filing['customerName'],
                 'send_status' => 1,
                 'send_num' => '0',
-                'wsend_num' => $filing['num'],
+                'wsend_num' => $send_num,
                 'remark' => '',
                 'status' => 0,
                 'lasttime' => $date,
@@ -546,7 +699,7 @@ class Filing extends Base
                 'good_createrid' => $filing['updaterid'],
                 'good_creater' => $filing['updater'],
             ]);
-
+			if($cg==false)throw new \Exception('采购单生成失败');
             //台账
             $standing_bood_data = [
                 'standBookNo' => makeNo('IO'),
@@ -569,23 +722,23 @@ class Filing extends Base
                 $addrid = Db::name('order_addr')->insertGetId([
                     'orderCode' => $orderCode,
                     'addr' => $addr['addr'],
-                    'addr_code' => implode(',', $addr['addr_code']),
+                    'addr_code' =>empty( $addr['addr_code'])?"": implode(',', $addr['addr_code']),
                     'contactor' => $addr['contactor'],
                     'mobile' => $addr['mobile'],
-                    'customer_code' => $filing['companyCode'],
+                    'customer_code' => $param['customerCode'],
                     'post_fee' => 0,
                     'receipt_quantity' => $addr['receipt_quantity'],
                     'is_del' => 0,
                     'addtime' => $date,
                     'updatetime' => $date,
                 ]);
-
+				if($addrid==false)throw new \Exception('地址生成失败');
                 //发货单
                 $outCode = makeNo('DF');
                 //改变编码规则,将原来的编码后两位换成序列号
                 //str_pad字符串填充
                 $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
-                Db::name('order_out')->insert([
+               $send= Db::name('order_out')->insert([
                     'orderCode' => $orderCode,
                     'outCode' => $outCode,
                     'apply_id' => $filing['updaterid'],
@@ -598,12 +751,13 @@ class Filing extends Base
                     'send_num' => $addr['receipt_quantity'],
                     'check_num' => 0,
                     'error_num' => 0,
-                    'wsm_code' => '',
+                    'wsm_code' => $wsm_code,
                     'order_type' => $order_type,
                     'status' => 0,
                     'addtime' => $date,
                     'updatetime' => $date,
                 ]);
+               if($send==false) throw new \Exception('发货单生成失败');
                 $standing_bood_data['outCode'][] = $outCode;
                 $order_send_insert[] = [
                     'cgdNo' => $cgdCode,
@@ -618,32 +772,35 @@ class Filing extends Base
             }
 
             //更新报备单
-            Db::name('filing')
-                ->where(['is_del' => 0, 'id' => $param['id'], 'status' => 2])
+           $fillup= Db::name('filing')
+                ->where(['is_del' => 0, 'id' => $param['id'], 'status' => [2,3]])
                 ->update([
-                	'status' => 3,
+                	'status' =>$wait_num>0?3:4,
+                	'wait_num' =>$wait_num,
+                	'transfer_num' =>$filing['transfer_num']+$send_num,
                     'updatetime' => $date,
-                    'orderCode' => $orderCode,
                     'spuCode' => $spuCode,
+                    'orderCode' =>$filing["orderCode"].$orderCode.",",
                     'reason' => '',
                     'updaterid' => $this->uid,
                     'updater' => $this->uname]);
-
+	  
+			if($fillup==false)throw new \Exception('报备单更新失败');
             //待办已办先不处理
 
             //关联表
-            Db::name('order_num')
+           $gu= Db::name('order_num')
                 ->insert([
                     'orderCode' => $orderCode,
                     'cgdNo' => $cgdCode,
                     'spuCode' => $spuCode,
                     'companyNo' => $filing['customerCode'],
-                    'good_num' => $filing['num'],
-                    'wsend_num' => $filing['num'],
+                    'good_num' => $send_num,
+                    'wsend_num' =>$send_num,
                     'send_num' => 0,
-                    'wait_num' => $filing['num'],
+                    'wait_num' => $send_num,
                 ]);
-
+			if($gu==false) throw new \Exception('关联表新建失败');
             if ($order_send_insert) Db::name('order_send')->insertAll($order_send_insert);
 
 
@@ -655,16 +812,10 @@ class Filing extends Base
             Db::commit();
             return json_show(0, '转单成功');
 
-        } catch (Exception $exception) {
+        } catch (\Exception $exception) {
             Db::rollback();
-            Db::name('filing')
-                ->where(['is_del' => 0, 'id' => $param['id'], 'status' => 2])
-                ->update(['status' => 4, 'updatetime' => $date, 'reason' => $exception->getMessage()]);
             return json_show(1005, '转单失败,' . $exception->getMessage());
         }
-
-//        $param['supplierNo'] = $this->request->user['supplierNo'];
-//        return FilingLogic::transfer($param);
     }
 
     //订单录入
@@ -868,15 +1019,15 @@ class Filing extends Base
         Db::startTrans();
         try {
             $qrd = Db::name("sale")->insert($qrddata);
-            if ($qrd == false) throw new Exception("销售单生成失败");
+            if ($qrd == false) throw new \Exception("销售单生成失败");
             $qrd = Db::name("order_num")->insert($orderCgd);
-            if ($qrd == false) throw new Exception("销售单采购管联生成失败");
+            if ($qrd == false) throw new \Exception("销售单采购管联生成失败");
             $qrd = Db::name("purchease_order")->insert($cgddata);
-            if ($qrd == false) throw new Exception("采购单生成失败");
+            if ($qrd == false) throw new \Exception("采购单生成失败");
             $qrd = Db::name("good_zixun")->insert($goodinfo);
-            if ($qrd == false) throw new Exception("商品信息录入生成失败");
+            if ($qrd == false) throw new \Exception("商品信息录入生成失败");
             $qrd = Db::name("order_addr")->insert($orderAddr);
-            if ($qrd == false) throw new Exception("销售单地址生成失败");
+            if ($qrd == false) throw new \Exception("销售单地址生成失败");
             Db::commit();
             return app_show(0, '订单生成成功');
         } catch (\Exception $exception) {
@@ -1043,13 +1194,13 @@ class Filing extends Base
         Db::startTrans();
         try {
             $qrd = Db::name("sale")->where($saleinfo)->update($qrddata);
-            if ($qrd == false) throw new Exception("销售单更新失败");
+            if ($qrd == false) throw new \Exception("销售单更新失败");
             $qrd = Db::name("purchease_order")->where($cgd)->update($cgddata);
-            if ($qrd == false) throw new Exception("采购单更新失败");
+            if ($qrd == false) throw new \Exception("采购单更新失败");
             $qrd = Db::name("good_zixun")->where($good)->update($goodinfo);
-            if ($qrd == false) throw new Exception("商品信息更新失败");
+            if ($qrd == false) throw new \Exception("商品信息更新失败");
             $qrd = Db::name("order_addr")->where($addr)->update($orderAddr);
-            if ($qrd == false) throw new Exception("销售单地址更新失败");
+            if ($qrd == false) throw new \Exception("销售单地址更新失败");
             Db::commit();
             return app_show(0, '订单更新成功');
         } catch (\Exception $exception) {

+ 29 - 21
app/admin/controller/Sale.php

@@ -5156,22 +5156,12 @@ class Sale extends Base
 
         $list = Db::name('sale')
             ->alias('a')
-            ->field('a.id sale_id,a.good_code,a.good_name,a.wsend_num,a.total_price,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.good_code,a.platform_order,a.good_name,a.wsend_num,a.total_price,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')
             ->leftJoin('order_num b', 'b.orderCode=a.orderCode')
             ->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
             ->where(['a.is_del' => 0, 'a.orderCode' => $orderCode])
             ->select()
             ->toArray();
-
-//        //贵金属的所有三级分类
-//        $cat_temp = Db::name('cat')
-//            ->field('id')
-//            ->where(['pid' => 6, 'is_del' => 0])
-//            ->buildSql();
-//        $cat_id = Db::name('cat')
-//            ->where('is_del = 0 AND pid IN ' . $cat_temp)
-//            ->column('id');
-
         Db::startTrans();
         try {
 
@@ -5180,19 +5170,32 @@ class Sale extends Base
             foreach ($list as $sale) {
 
                 if ($sale['sale_status'] == 3) throw new \think\Exception($sale['orderCode'] . '已取消,无法重复操作');
-//                if (cat_is_gold($sale['cat_id'])) throw new \think\Exception($sale['orderCode'] . '为贵金属,无法取消');
-//                if ($sale['sale_status']!=0) throw new \think\Exception($sale['orderCode'] . '已发货,无法取消');
                 if ($sale['order_type'] == 1) {
                     if ($sale['sale_status'] != 0) throw new \think\Exception($sale['orderCode'] . '已发货,无法取消');
                     $good = Db::name("good")->where(["spuCode" => $sale['good_code']])->findOrEmpty();
                     if (empty($good)) throw new Exception('未找到商品信息');
-                    $stock = Db::name("good")->where($good)->update(["usable_stock" => $good['usable_stock'] + $sale['wsend_num'], "updatetime" => date("Y-m-d H:i:s")]);
+                    $stock = Db::name("good")->where($good)
+                    ->inc("usable_stock",$sale['wsend_num'])
+                     ->data(["updatetime" => date("Y-m-d H:i:s")])
+                    ->update();
                     if ($stock == false) throw new Exception('商品库存更新失败');
+                }
+                if($sale['order_type'] == 4){
+                    $fill =Db::name("filing")->where(["filingCode"=>$sale["platform_order"]])->findOrEmpty();
+                    if(empty($fill)) throw new Exception($sale['orderCode'] . '未找到对应得报备单');
+                    $fillup=Db::name('filing')
+                    ->where($fill)
+                    ->data([
+                    	"transfer_num"=>$fill["transfer_num"]-$sale['wsend_num'],
+                    	"wait_num"=>$fill["wait_num"]+$sale['wsend_num'],
+                         "status"=>$fill['wait_num']+$sale['wsend_num']==0?4:($fill['transfer_num']-$sale['wsend_num']==0?2:3)
+                    ])
+                    ->update();
+                    if($fillup==false)throw new Exception($sale['platform_order'] . '报备单更新失败');
                 }
 				 $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$sale['orderCode'], "isCgd"=>1]);
 				if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
 					throw new Exception($fininfo['message']??"结算校验失败");
-//					return json_show(1005, $fininfo['message']??"结算校验失败");
 				}
 				$thtemp=[
 					"orderCode"=>$sale["orderCode"],
@@ -5244,7 +5247,7 @@ class Sale extends Base
                 }
 
             }
-            Db::name('sale')
+           $orderup= Db::name('sale')
                 ->where(['is_del' => 0, 'id' => array_column($list, 'sale_id')])
                 ->update([
                 	'status' => 3,
@@ -5255,8 +5258,11 @@ class Sale extends Base
                 	'send_status' =>3,
                 	'updatetime' => $date
                 	]);
-            Db::name("th_data")->insertAll($th);
-            Db::name('purchease_order')
+            if($orderup==false) throw new \Exception("订单状态更新失败");
+           
+           $thin= Db::name("th_data")->insertAll($th);
+           if($thin==false) throw new \Exception('订单取消失败');
+            $cgdup=Db::name('purchease_order')
                 ->where(['is_del' => 0, 'id' => array_column($list, 'cgd_id')])
                 ->update([
                 	'status' => 4,
@@ -5266,15 +5272,16 @@ class Sale extends Base
                 	'send_num' =>Db::raw("wsend_num"),
                 	'send_status' =>3,
                     'updatetime' => $date]);
-
+			 if($cgdup==false) throw new \Exception('采购单取消失败');
             $out_list = Db::name('order_out')
                 ->where(['is_del' => 0, 'orderCode' => $orderCode])
                 ->select()
                 ->toArray();
             if (!empty($out_list)) {
-                Db::name('order_out')
+               $sen= Db::name('order_out')
                     ->where(['is_del' => 0, 'orderCode' => $orderCode])
                     ->update(['status' => 5, 'updatetime' => $date]);
+                if($sen==false) throw new \Exception('发货单取消失败');
                 foreach ($out_list as $out) {
                     ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
                         "order_code" => $out['outCode'],//销售单号
@@ -5300,9 +5307,10 @@ class Sale extends Base
                 ->select()
                 ->toArray();
             if (!empty($ooc_list)) {
-                Db::name('order_out_child')
+               $child= Db::name('order_out_child')
                     ->where(['is_del' => 0, 'orderCode' => $orderCode])
                     ->update(['status' => 5, 'updatetime' => $date]);
+                if ($child == false) throw new Exception('发货工单更新失败');
                 foreach ($ooc_list as $ooc) {
                     $stockinfo = Db::name("good_stock")->where(["spuCode" => $ooc['spuCode'], "wsm_code" => $ooc['wsm_code']])->findOrEmpty();
                     if (empty($stockinfo)) throw new Exception('未找到库存信息');

+ 3 - 3
app/admin/controller/SaleReport.php

@@ -2337,7 +2337,7 @@ class SaleReport extends Base
 	    $count_row = Db::name('sale')
 	               ->alias('a')
 	               ->where($where)
-	               ->field(" a.good_num-th_num - IFNULL((select sum('receipt_quantity') from wsm_order_addr where orderCode=a.orderCode and is_del=0),0)  not_addr_address_good_num,count(a.id) as count")
+	               ->field(" a.good_num-th_num - IFNULL((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0)  not_addr_address_good_num,count(a.id) as count")
 	               ->having("not_addr_address_good_num>0")
 	               ->find();
 	    $data = Db::name('sale')
@@ -2353,7 +2353,7 @@ class SaleReport extends Base
             a.send_num,
             a.wsend_num,
             a.status,
-            a.good_num-a.th_num - IFNULL((select sum('receipt_quantity') from wsm_order_addr where orderCode=a.orderCode and is_del=0),0)  not_addr_address_good_num,
+            a.good_num-a.th_num - IFNULL((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0)  not_addr_address_good_num,
             a.apply_name nickname,
             a.apply_id,
             a.addtime")
@@ -2404,7 +2404,7 @@ class SaleReport extends Base
             a.good_code 商品成本编码,a.skuCode 商品上线编码,a.good_name 商品名称,
             a.good_num 购买数量,a.send_num 已发货数量,a.wsend_num 未发货数量,a.status 订单状态,
             a.apply_name 申请人名称,a.apply_id 申请人所属部门, 
-            a.good_num-a.th_num - IFNULL((select sum('receipt_quantity') from wsm_order_addr where orderCode=a.orderCode and is_del=0),0) 无地址数量,
+            a.good_num-a.th_num - IFNULL((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0) 无地址数量,
             '' 下单月份,
             a.addtime")
             ->where($where)

+ 1 - 156
app/admin/controller/Suppler.php

@@ -475,17 +475,8 @@ class Suppler extends Base
                 $data['ocr_status'] = 2;
             }
         }
-//            $ino = array_diff($data, $info['data']);
-//            $tem = json_encode($ino, JSON_UNESCAPED_UNICODE);
-//            $jsp = json_encode($info['data'], JSON_UNESCAPED_UNICODE);
 
-
-//            $join = Db::name('supplier')->where(['id' => $id, 'is_del' => 0])->save($data);
-//            if ($join) {
-//                ChangeLog::logAdd("1", $info['data']['code'], $jsp, $tem, $this->post['token'], $this->post);
-//                $item = Db::name('supplier_contact')->where(['code' => $info['data']['code']])->find();
         $temp = [];
-//                isset($item['id']) && $item['id'] !== "" ? $temp['id'] = $item['id'] : '';
         $temp['code'] = $info['data']['code'];
         $temp['contactor'] = $contactor;
         $temp['mobile'] = $mobile;
@@ -493,16 +484,8 @@ class Suppler extends Base
         $temp['telephone'] = $telephone;
         $temp['email'] = $email;
         $temp['is_del'] = 0;
-//                isset($item['id']) && $item['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
         $temp['updatetime'] = date("Y-m-d H:i:s");
-//                    $st = array_diff($item,$temp);
-//                    $snm =json_encode($st);
-//                $vp = Db::name('supplier_contact')->save($temp);
-//                if ($vp == "") {
-//                    ChangeLog::logAdd("1",$item['code'],$item,$snm,$this->post['token'],$this->post);
-//                    Db::rollback();
-//                    return error_show(1002, "更新失败");
-//                }
+
 
         $res = $userCommon->handle('sEdit', ['data' => $data, 'contact' => $temp]);
 
@@ -527,17 +510,6 @@ class Suppler extends Base
             Db::rollback();
             return json_show(1004, $exception->getMessage());
         }
-
-//                Db::commit();
-//                return app_show(0, "编辑成功");
-//            } else {
-//                Db::rollback();
-//                return error_show(1002, "编辑失败");
-//            }
-//        } catch (\Exception $e) {
-//            Db::rollback();
-//            return error_show(1003, $e->getMessage());
-//        }
     }
 
     public function info()
@@ -545,25 +517,7 @@ class Suppler extends Base
         $code = $this->request->only(['code' => ''], 'post', 'trim');
         $userCommon = \app\admin\common\User::getIns();
         $rs = $userCommon->handle('sInfo', $code);
-
         return json_show($rs['code'], $rs['message'], $rs['data']);
-
-
-//        if ($code == "") {
-//            return error_show(1002, "参数code不能为空");
-//        }
-//        $info = Db::name('supplier')->where(['code' => $code, 'is_del' => 0])->find();
-//        if ($info == "") {
-//            return error_show(1002, "未找到数据");
-//        }
-//        $contact = Db::name("supplier_contact")->where(["code" => $info['code'], "is_del" => 0])->find();
-//        $info['contactor'] = isset($contact['contactor']) ? $contact['contactor'] : "";
-//        $info['mobile'] = isset($contact['mobile']) ? $contact['mobile'] : "";
-//        $info['position'] = isset($contact['position']) ? $contact['position'] : "";
-//        $info['email'] = isset($contact['email']) ? $contact['email'] : "";
-//        $info['telephone'] = isset($contact['telephone']) ? $contact['telephone'] : "";
-//        $info['supplier_img'] = isset($info['license_img']) ? $info['license_img'] : "";
-//        return app_show(0, "获取成功", $info);
     }
 
     //删除 供应商
@@ -579,58 +533,6 @@ class Suppler extends Base
             'updaterid' => $this->uid,
         ]);
         return json_show($rs['code'], $rs['message'], $rs['data']);
-
-//        $sup = Db::name("supplier")
-//            ->where(['id' => $id, 'is_del' => 0])
-//            ->find();
-//        if (empty($sup)) return error_show(1005, '未找到对应数据');
-//
-//        Db::startTrans();
-//        try {
-//            //维护供应商表
-//            $supp = ['is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")];
-//            Db::name("supplier")
-//                ->where(['id' => $id, 'is_del' => 0])
-//                ->update($supp);
-//
-//            $vam = array_intersect_key($sup, $supp);//比较两个数组的键名,并返回交集
-
-//            ChangeLog::logAdd("1", $sup['code'], json_encode($sup, JSON_UNESCAPED_UNICODE), json_encode($vam, JSON_UNESCAPED_UNICODE), $this->post['token'], $this->post);
-
-//            Db::commit();
-//            return app_show(0, '删除成功');
-//        } catch (\Exception $exception) {
-//            Db::rollback();
-//            return error_show(1005, '删除失败' . $exception->getMessage());
-//        }
-
-
-//        $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
-//        $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
-//        if($sup==false){
-//            return error_show(1002,"供应商信息不存在");
-//        }
-//        $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
-//        $vam = array_diff($sup,$supp);
-//        $vap = json_encode($vam);
-//        if($supp){
-//            ChangeLog::logAdd("1",$sup['code'],$sup,$vap,$this->post['token'],$this->post);
-//
-//            //维护联系人账号
-//            $res = SupplierUser::where([
-//                'is_del' => SupplierUser::$is_del_normal,
-//                'status' => SupplierUser::$status_normal,
-//                'type' => SupplierUser::$type_default
-//            ])->whereFindInSet('supplierNos', $sup['code'])->save([
-//                'is_del' => SupplierUser::$is_del_deleted,
-//                'updatetime' => date('Y-m-d H:i:s')
-//            ]);
-//            if (!$res) return error_show('删除联系人账号失败');
-//
-//            return error_show(0,"删除成功");
-//        }else{
-//            return error_show(1002,"删除失败");
-//        }
     }
 
     //启/禁用 供应商
@@ -655,63 +557,6 @@ class Suppler extends Base
             'updaterid' => $this->uid,
         ]);
         return json_show($rs['code'], $rs['message'], $rs['data']);
-
-//        $param = $this->request->filter('trim')->only(['id', 'status'], 'post');
-//
-//        $val = Validate::rule(['id' => 'require|number|gt:0', 'status|状态' => 'require|number|in:0,1,2']);
-//
-//        if (!$val->check($param)) return error_show(1005, $val->getError());
-
-//        $msg = $param['status'] == 1 ? "启用" : "禁用";
-
-//        $info = Db::name("supplier")
-//            ->alias('a')
-//            ->field('a.id,a.code,a.status,b.mobile')
-//            ->leftJoin('supplier_contact b', 'b.code=a.code')
-//            ->where(['a.id' => $param['id'], 'a.is_del' => 0])
-//            ->find();
-//        if (empty($info)) return error_show(1005, '未找到对应数据');
-//        if ($info['status'] == $param['status']) return error_show(1005, '不能重复' . $msg);
-
-//        Db::startTrans();
-//        try {
-//            //维护供应商表
-//            Db::name("supplier")
-//                ->where('id', $param['id'])
-//                ->where('status', '<>', $param['status'])
-//                ->save([
-//                    'status' => $param['status'],
-//                    'updatetime' => date("Y-m-d H:i:s"),
-//                ]);
-//
-//            Db::commit();
-//            return app_show(0, $msg . '成功');
-//        } catch (\Exception $exception) {
-//            Db::rollback();
-//            return error_show(1005, $exception->getMessage());
-//        }
-
-//        $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
-//        if($id==""){
-//            return error_show(1002,"参数id不能为空");
-//        }
-//        $info =  Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find();
-//        if(!$info){
-//            return error_show(1002,"未找到对应数据");
-//        }
-//        $status =  isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
-//        if($status===""){
-//            return error_show(1002,"参数status不能为空");
-//        }
-//        if(!in_array($status,[0,1,2])){
-//            return error_show(1002,"参数status无效");
-//        }
-//        $info['status']=$status;
-//        $info['updatetime']=date("Y-m-d H:i:s");
-//        $msg = $status==1?"启用":"禁用";
-//        $update = Db::name("supplier")->save($info);
-//        return  $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
-
     }
 
     //供应商升级成业务公司

+ 1 - 0
app/admin/route/app.php

@@ -796,6 +796,7 @@ route::rule('getListByCompany', 'admin/CompanyCatProfit/getListByCompany');
 //报备单
 route::rule('filingList', 'Filing/getList');//获取列表
 route::rule('filingAdd', 'Filing/add');//添加
+route::rule('filingSave', 'Filing/save');//编辑
 route::rule('filingDetail', 'Filing/detail');//详情
 route::rule('filingStatus', 'Filing/status');//审核
 route::rule('filingCancel', 'Filing/cancel');//取消转单

+ 7 - 5
app/command/SplitSale.php

@@ -18,7 +18,7 @@ class SplitSale extends Command
     private $noble_metal = [1 => '18K', 2 => '24K', 3 => '白银'];//贵金属种类对应文本
     private $cgd_key = 0;//新增到wsm_cgd_caixiao的数组下标,从0开始
     private $order_source = 8;//支付渠道
-
+	private  $Tcode = '';
     protected function configure()
     {
         $this->setName('split_sale')->setDescription('销售订单拆分');
@@ -59,7 +59,8 @@ class SplitSale extends Command
                 $userCommon = User::getIns();
 
                 foreach ($data as $sale) {
-
+					if( strtotime($sale['addtime']) >= strtotime('2023-07-01 00:00:00'))$this->Tcode ='F';
+					else $this->Tcode ='';
                     //补充商品信息
                     if ($sale['order_type'] == 3 ||$sale['order_type'] == 4) {
                         //咨询相关
@@ -122,9 +123,10 @@ class SplitSale extends Command
                     foreach ($pay_rates as $keys=>$pay_rate) {
 
                         //生成新的采购单号和销售单号
-                        $cgdNo = makeNo('CG');
+                        $cgdNo = makeNo($this->Tcode.'CG');
+                       
                         $cgdNo = substr($cgdNo, 0, -2) . str_pad($this->i, 2, '0', STR_PAD_LEFT);
-                        $orderCode = makeNo('QR');
+                        $orderCode = makeNo($this->Tcode.'QR');
                         $orderCode = substr($orderCode, 0, -2) . str_pad($this->i, 2, '0', STR_PAD_LEFT);
                         $this->i++;
                         //计算渠道业务公司采购单单价。
@@ -139,7 +141,7 @@ class SplitSale extends Command
 	                    $sale_total =$cgd_total; //下一个渠道公司/原业务公司的 销售价未此次的采购单价
 	                    //判断是否是最后一个渠道遍历。最后一次需要额外生成一个销售单给原业务公司;
 						if($keys == count($pay_rates)-1){
-							$orderCode = makeNo('QR');
+							$orderCode = makeNo($this->Tcode.'QR');
 							$orderCode = substr($orderCode, 0, -2) . str_pad($this->i, 2, '0', STR_PAD_LEFT);
 							$supplier = ['No' => $sale['supplierNo'], 'name' => $sale['supplierName'],"pay_name"=>$pay_rate['pay_name']];
 							$this->_handle_sale_caixiao($sale, $orderCode, $cgd['cgdNo'] ?? '', $sale_total, $customer, $supplier);