wugg před 1 rokem
rodič
revize
8cfb6b975b

+ 67 - 29
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;
 
@@ -295,11 +295,39 @@ class AfterChild extends Base
 //                    ]);
 
                 //发货工单数量减少
-                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 +346,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 +356,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 +433,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 +448,7 @@ class AfterChild extends Base
                                     'addtime' => $date,
                                     'updatetime' => $date,
                                 ]);
+                           if($dd==false) throw new \Exception('关联表新增失败');
 
                         } else throw new Exception('未找到对应的商品数据');
 
@@ -432,11 +464,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 +492,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 +504,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 +532,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 +549,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 +590,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 +600,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 +617,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 +626,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 +661,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) {

+ 215 - 77
app/admin/controller/Filing.php

@@ -56,7 +56,37 @@ class Filing extends Base
     //添加
     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',
+        	'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',
@@ -123,10 +153,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 +167,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,
@@ -170,14 +197,140 @@ 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',
+        	'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',
+            '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',
+        ]);
 
-//        $param['supplierNo']= $this->request->user['supplierNo'];
-//        $param['supplierName']= $this->request->user['supplierName'];
+        if (!$val->check($param)) return json_show(1004, $val->getError());
 
-//        return FilingLogic::add($param);
+        //如果是贵金属的话,额外判断
+        $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());
+        }
 
-    }
+        $val2 = Validate::rule([
+            'spec_id|规格id' => 'require|number|gt:0',
+            'spec_value_id|规格值id' => 'require|number|gt:0',
+        ]);
+
+        $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, '该供应商不存在');
+        $rs = Db::name('filing')
+            ->save(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,
+                "staus"=>0,
+                "is_check"=>0,
+                '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']),
+            ]));
+
+        return $rs ? json_show(0, '报备单更新成功') : json_show(1004, '报备单更新失败');
 
+    }
     //详情
     public function detail()
     {
@@ -207,60 +360,54 @@ class Filing extends Base
 //        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"=>""], '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,1|length:18',
+            'platform_id|平台id' => 'requireIf:is_check,1|number|gt:0',
+            'plat_code|平台商品编号' => 'requireIf:is_check,1|max:255',
+            "is_check|是否合规"=> 'require|number|in:1,2',
+            "remark|备注"=> 'requireIf:is_check,2|number|in:1,2',
         ]);
 
         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 +425,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 +439,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 +455,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',
         ]);
 
@@ -336,25 +480,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])
             ->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 +511,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 +550,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
@@ -439,14 +580,14 @@ 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' =>'',
                 'send_num' => 0,
                 'wsend_num' => $filing['num'],
                 'th_num' => 0,
@@ -474,7 +615,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 +625,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 +642,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,
@@ -546,7 +687,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'),
@@ -572,20 +713,20 @@ class Filing extends Base
                     '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 +739,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,21 +760,23 @@ class Filing extends Base
             }
 
             //更新报备单
-            Db::name('filing')
+           $fillup= Db::name('filing')
                 ->where(['is_del' => 0, 'id' => $param['id'], 'status' => 2])
                 ->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,
@@ -643,7 +787,7 @@ class Filing extends Base
                     'send_num' => 0,
                     'wait_num' => $filing['num'],
                 ]);
-
+			if($gu==false) throw new \Exception('关联表新建失败');
             if ($order_send_insert) Db::name('order_send')->insertAll($order_send_insert);
 
 
@@ -657,14 +801,8 @@ class Filing extends Base
 
         } 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);
     }
 
     //订单录入

+ 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}失败");
-
     }
 
     //供应商升级成业务公司