cqp 3 месяцев назад
Родитель
Сommit
4be1b1b34a

+ 12 - 1
app/Jobs/ProcessDataJob.php

@@ -4,6 +4,7 @@ namespace App\Jobs;
 
 use App\Model\ErrorTable;
 use App\Model\U8Job;
+use App\Service\ProductService;
 use App\Service\U8ServerService;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
@@ -25,10 +26,11 @@ class ProcessDataJob implements ShouldQueue
     public $tries = 0;
     public $timeout = 60;
 
-    //1 采购  2 销售(合同)
+    //1 采购  2 销售(合同) 3 总社库存
     protected $function = [
         1 => 'U8PO_PomainSave',
         2 => 'U8SaleOrderSave',
+        3 => 'U8StockToMy',
     ];
 
     public function __construct($data)
@@ -78,6 +80,15 @@ class ProcessDataJob implements ShouldQueue
 //        $this->recordErrorTable($errorMessage);
 //    }
 
+    //总社库存
+    private function U8StockToMy(){
+        $service = new ProductService();
+        list($status, $msg) = $service->writeStock($this->data);
+
+        $service = new U8ServerService();
+        $service->finalSettle(-1, U8Job::three, $msg);
+    }
+
     private function recordErrorTable($msg){
         $data = $this->data;
 

+ 3 - 0
app/Model/U8Job.php

@@ -17,6 +17,7 @@ class U8Job extends Model
 
     const one = 1;
     const two = 2;
+    const three = 3;
     public static $type = [
         self::one,
         self::two,
@@ -28,8 +29,10 @@ class U8Job extends Model
 
     const job1 = 't9u8_purchase';
     const job2 = 't9u8_sales';
+    const job3 = 't9u8_stock';
     public static $job = [
         self::one => self::job1,
         self::two => self::job2,
+        self::three => self::job3,
     ];
 }

+ 2 - 0
app/Service/InvoiceOrderService.php

@@ -346,6 +346,8 @@ class InvoiceOrderService extends Service
             $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
         }
 
+        $data['is_check_stock'] = $user['is_check_stock'];
+
         $product_submit = $product_id = [];
         foreach ($data['product'] as $value){
             if(empty($value['number'])) return [false,'产品数量不能为空'];

+ 131 - 25
app/Service/ProductService.php

@@ -2,6 +2,7 @@
 
 namespace App\Service;
 
+use App\Jobs\ProcessDataJob;
 use App\Model\BasicType;
 use App\Model\Depart;
 use App\Model\Employee;
@@ -17,6 +18,7 @@ use App\Model\Role;
 use App\Model\RoleMenuButton;
 use App\Model\SeeRange;
 use App\Model\Storehouse;
+use App\Model\U8Job;
 use Illuminate\Support\Facades\DB;
 
 /**
@@ -1311,25 +1313,108 @@ class ProductService extends Service
     }
 
     public function updateTopStock($data, $user){
-        $service = new U8ServerService(true);
-        if(! empty($service->error)) return [false, $service->error];
-
         $limit_key = "updateTopStockFromYy";
-        list($status, $msg) = $this->limitingSendRequestBackgExpire($limit_key, 20);
-        if(! $status) return [false, '正在获取T9杭州总仓库存货库存,请勿重复操作'];
+//        list($status, $msg) = $this->limitingSendRequestBackg($limit_key);
+//        if(! $status) return [false, '正在获取T9杭州总仓库存货库存,请勿重复操作'];
+
+        //总店
+        $head = $user['head']['id'] ?? 0;
+        $storehouse_id = Storehouse::where('top_depart_id', $head)->where('del_time',0)->value('id') ?? 0;
+
+        $time = time();
+        DB::table('product')
+            ->where('del_time', 0)
+            ->where('top_depart_id', $head)
+            ->select('id','code')
+            ->orderBy('id')
+            ->chunk(200, function ($data) use($head,$storehouse_id,$time){
+                $data = Collect($data)->map(function ($object) {
+                    return (array)$object;
+                })->toArray();
+
+                $map = array_column($data,'id','code');
+                $id = array_unique(array_column($data,'id'));
+                $code = array_unique(array_column($data,'code'));
+                $post = [
+                    'urlFromT9' => 'getStock',
+                    'code' => $code,
+                    'warehouse' => '001',
+                ];
+                $post = json_encode($post);
+                $header = ['Content-Type:application/json'];
+                list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/updateTopStock",$post, $header);
+                if($msg['code'] != 200) return [false, $msg['msg']];
+                $msg = $msg['data'] ?? [];
+
+                $insert = [];
+                foreach ($msg as $value){
+                    $insert[] = [
+                        'product_id' => $map[$value['product_no']] ?? 0,
+                        'storehouse_id' => $storehouse_id,
+                        'top_depart_id' => $head,
+                        'number' => $value['number'],
+                        'crt_time' => $time,
+                    ];
+                }
+
+                ProductInventoryOfTop::where('del_time',0)
+                    ->whereIn('product_id',$id)
+                    ->update(['del_time' => $time]);
+
+                if(! empty($insert)) ProductInventoryOfTop::insert($insert);
+            });
+
+        return [true, ''];
+
+        try{
+            $job = ProcessDataJob::dispatch(['head' => $head, 'storehouse_id' => $storehouse_id, 'type' => U8Job::three,'limit_key' => $limit_key])->onQueue(U8Job::job3);
+            if(! $job) {
+                $this->dellimitingSendRequestBackg($limit_key);
+                return [false,'T9杭州总仓库存货库存任务没有进入队列!'];
+            }
+        }catch (\Throwable $e){
+            $this->dellimitingSendRequestBackg($limit_key);
+            return [false,$e->getMessage()];
+        }
+
+        return [true, 'T9杭州总仓库存货库存任务正在后台执行,请等待'];
+    }
+
+    private function returnStock($stock, $value){
+        if(isset($stock[$value['id']])){
+            $number = $stock[$value['id']];
+            if($number <= 0){
+                $stock = "售罄";
+            } elseif($number <= 15){
+                $stock = " 库存紧张";
+            }else{
+                $stock = " 库存充足";
+            }
+        }else{
+            $stock = "联系客服";
+        }
 
+        return $stock;
+    }
+
+    public function writeStock($data){
         try {
+            $head = $data['head'];
+            $storehouse_id = $data['storehouse_id'];
+            $limit_key = $data['limit_key'];
+
             DB::enableQueryLog();
-            //总店
-            $head = $user['head']['id'] ?? 0;
-            $storehouse_id = Storehouse::where('top_depart_id', $head)->where('del_time',0)->value('id') ?? 0;
+
+            $service = new U8ServerService(true);
+            if(! empty($service->error)) return [false, $service->error];
+
             $time = time();
             DB::table('product')
                 ->where('del_time', 0)
                 ->where('top_depart_id', $head)
                 ->select('id','code')
                 ->orderBy('id')
-                ->chunk(200, function ($data) use($service,$head,$storehouse_id,$time){
+                ->chunk(200, function ($data) use($head,$storehouse_id,$time){
                     $data = Collect($data)->map(function ($object) {
                         return (array)$object;
                     })->toArray();
@@ -1337,8 +1422,16 @@ class ProductService extends Service
                     $map = array_column($data,'id','code');
                     $id = array_unique(array_column($data,'id'));
                     $code = array_unique(array_column($data,'code'));
-                    list($status, $msg) = $service->getStock($code, "001");
-                    if(! $status) return [false, $msg];
+                    $post = [
+                        'urlFromT9' => 'getStock',
+                        'code' => $code,
+                        'warehouse' => '001',
+                    ];
+                    $post = json_encode($post);
+                    $header = ['Content-Type:application/json'];
+                    list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/updateTopStock",$post, $header);
+                    if($msg['code'] != 200) return [false, $msg['msg']];
+                    $msg = $msg['data'] ?? [];
 
                     $insert = [];
                     foreach ($msg as $value){
@@ -1355,32 +1448,45 @@ class ProductService extends Service
                         ->whereIn('product_id',$id)
                         ->update(['del_time' => $time]);
 
-                    ProductInventoryOfTop::insert($insert);
+                    if(! empty($insert)) ProductInventoryOfTop::insert($insert);
                 });
 
             DB::commit();
+            $this->dellimitingSendRequestBackg($limit_key);
         }catch (\Throwable $exception){
             DB::rollBack();
+            $this->dellimitingSendRequestBackg($limit_key);
             return [false, $exception->getMessage()];
         }
 
         return [true, ''];
     }
 
-    private function returnStock($stock, $value){
-        if(isset($stock[$value['id']])){
-            $number = $stock[$value['id']];
-            if($number <= 0){
-                $stock = "售罄";
-            } elseif($number <= 15){
-                $stock = " 库存紧张";
-            }else{
-                $stock = " 库存充足";
-            }
-        }else{
-            $stock = "联系客服";
+    public function post_helper($url, $data, $header = [], $timeout = 20){
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch,  CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_ENCODING, '');
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+
+        if(!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+        $r = curl_exec($ch);
+
+        if ($r === false) {
+            // 获取错误号
+            $errorNumber = curl_errno($ch);
+            // 获取错误信息
+            $errorMessage = curl_error($ch);
+            $message = "cURL Error #{$errorNumber}: {$errorMessage}";
+
+            return [false, $message];
         }
+        curl_close($ch);
 
-        return $stock;
+        return [true, json_decode($r, true)];
     }
 }

+ 13 - 0
app/Service/PurchaseOrderService.php

@@ -6,6 +6,7 @@ use App\Model\BasicType;
 use App\Model\BookingList;
 use App\Model\Depart;
 use App\Model\Employee;
+use App\Model\InvoiceOrder;
 use App\Model\PaymentReceipt;
 use App\Model\PaymentReceiptInfo;
 use App\Model\PurchaseOrder;
@@ -256,6 +257,13 @@ class PurchaseOrderService extends Service
         $order['order_type_title'] = PurchaseOrder::$order_type[$order['order_type']] ?? '';
         $sales = SalesOrder::where('id',$order['sales_order_id'])->value('order_number');
         $order['sales_order_number'] = $sales;
+        $saleForInvoice = SalesOrder::where('del_time',0)->where('contact_order_no', $order['order_number'])->first();
+        $logistics_number = "";
+        if(! empty($saleForInvoice)){
+            $saleForInvoice = $saleForInvoice->toArray();
+            $logistics_number = InvoiceOrder::where('del_time',0)->where('sales_order_id',$saleForInvoice['id'])->value('logistics_number') ?? "";
+        }
+        $order['logistics_number'] = $logistics_number;
         $emp_map = Employee::whereIn('id',array_unique(array_merge_recursive([$order['purchase_id']],[$order['crt_id']])))
             ->pluck('emp_name','id')
             ->toArray();
@@ -297,6 +305,11 @@ class PurchaseOrderService extends Service
         //回款信息
         $this->purchaseFillDetailPayment($order);
 
+        $sale_order = SalesOrder::where('del_time',0)
+            ->where('contact_order_no', $order['order_number'])
+            ->value('id');
+        $order['fsdh_id'] = $sale_order ?? 0;
+
         return [true, $order];
     }
 

+ 25 - 0
app/Service/SalesOrderService.php

@@ -546,6 +546,7 @@ class SalesOrderService extends Service
      */
     public function detail($data,$user){
         if(empty($data['id']) && empty($data['order_number'])) return [false,'请选择数据!'];
+        $is_flag = isset($data['invoice_state']) ? 1 : 0;
 
         if(! empty($data['id'])){
             $sales = SalesOrder::where('del_time',0)
@@ -560,6 +561,30 @@ class SalesOrderService extends Service
 
         if(empty($sales)) return [false,'合同不存在或已被删除'];
         $sales = $sales->toArray();
+        if($is_flag && $sales['invoice_state']) return [false, '合同已发货'];
+
+        $take_address = $take_man = $take_phone = "";
+        $purchase = PurchaseOrder::where('del_time',0)
+            ->where('order_number',$sales['contact_order_no'])
+            ->first();
+        if(! empty($purchase)){
+            $purchase = $purchase->toArray();
+            $depart = Depart::where('id', $purchase['top_depart_id'])->first();
+            if(! empty($depart)) {
+                $depart = $depart->toArray();
+                $take_address = $depart['title'];
+                $employee = Employee::where('id', $depart['notify_id'])->first();
+                if(! empty($employee)){
+                    $employee = $employee->toArray();
+                    $take_man = $employee['emp_name'];
+                    $take_phone = $employee['mobile'];
+                }
+            }
+        }
+        $sales['take_address'] = $take_address;
+        $sales['take_man'] = $take_man;
+        $sales['take_phone'] = $take_phone;
+
         $is_add_construction = 0;
         if($sales['top_depart_id'] == $user['head']['id']){
             if($sales['state'] >= SalesOrder::State_four && $sales['state'] < SalesOrder::State_seven) $is_add_construction = 1;

+ 41 - 0
config/header/57.php

@@ -0,0 +1,41 @@
+<?php
+/**
+ * '菜单ID' => [
+ *     '字段英文名' =》 '字段中文名'
+ * ]
+ */
+
+return [
+    [
+        'key' => 'title',
+        'value' => '活动包名称',
+    ],
+    [
+        'key' => 'sports_bag_time',
+        'value' => '活动包时间范围',
+    ],
+    [
+        'key' => 'total_amount',
+        'value' => '活动包金额',
+    ],
+    [
+        'key' => 'mark',
+        'value' => '活动包备注',
+    ],
+    [
+        'key' => 'is_attribute_title',
+        'value' => '活动包属性',
+    ],
+    [
+        'key' => 'crt_time',
+        'value' => '创建时间',
+    ],
+    [
+        'key' => 'crt_name',
+        'value' => '创建人',
+    ],
+    [
+        'key' => 'state_title',
+        'value' => '活动包状态',
+    ],
+];

+ 21 - 0
config/morequery.php

@@ -19,6 +19,27 @@ return [
                 2 => 43,
             ],
         ],
+        "api/sportsBagOrderList" => [
+            'key' => 'is_attribute',
+            'array' => [
+                1 => 30,
+                2 => 57,
+            ],
+        ],
+        "api/sportsBagAdd" => [
+            'key' => 'is_attribute',
+            'array' => [
+                1 => 30,
+                2 => 57,
+            ],
+        ],
+        "api/sportsBagEdit" => [
+            'key' => 'is_attribute',
+            'array' => [
+                1 => 30,
+                2 => 57,
+            ],
+        ],
         "api/invoiceOrderList" => 36,
         "api/ReturnExchangeOrderList" => 35,
         "api/ReturnExchangeOrderAdd" => 35,

+ 36 - 2
config/oa.php

@@ -419,7 +419,7 @@ return [
     ],
     [
         'menu_id' => 30,
-        'menu_title' => '组合活动价',
+        'menu_title' => '销售活动价',
         'children' => [
             [
                 'key' => 'title',
@@ -431,7 +431,41 @@ return [
             ],
             [
                 'key' => 'purchase_attribute_title',
-                'title' => '采购属性',
+                'title' => '属性',
+            ],
+            [
+                'key' => 'crt_name',
+                'title' => '创建人',
+            ],
+            [
+                'key' => 'crt_time',
+                'title' => '创建时间',
+            ],
+            [
+                'key' => 'mark',
+                'title' => '备注',
+            ],
+            [
+                'key' => 'state_title',
+                'title' => '活动价状态',
+            ],
+        ]
+    ],
+    [
+        'menu_id' => 57,
+        'menu_title' => '采购活动价',
+        'children' => [
+            [
+                'key' => 'title',
+                'title' => '活动价名称',
+            ],
+            [
+                'key' => 'total_amount',
+                'title' => '活动包金额',
+            ],
+            [
+                'key' => 'purchase_attribute_title',
+                'title' => '属性',
             ],
             [
                 'key' => 'crt_name',