cqpCow 1 anno fa
parent
commit
8f6b9c3529

+ 22 - 0
app/Http/Controllers/Api/DataSyncToU8Controller.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\DataSyncToU8Service;
+use Illuminate\Http\Request;
+
+class DataSyncToU8Controller extends BaseController
+{
+    public function add(Request $request)
+    {
+        $service = new DataSyncToU8Service();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->add($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 98 - 0
app/Jobs/ProcessDataJob.php

@@ -0,0 +1,98 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Model\ErrorTable;
+use App\Model\U8Job;
+use App\Service\U8ServerService;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Redis;
+use MongoDB\Driver\Exception\Exception;
+use Symfony\Component\Console\Output\ConsoleOutput;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class ProcessDataJob implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    protected $data;
+
+    public $tries = 0;
+    public $timeout = 60;
+
+    //1 采购  2 销售(合同)
+    protected $function = [
+        1 => 'U8PO_PomainSave',
+        2 => 'U8SaleOrderSave',
+    ];
+
+    public function __construct($data)
+    {
+        $this->data = $data;
+    }
+
+    public function handle()
+    {
+        try {
+            $function = $this->function[$this->data['type']] ?? '';
+            if(empty($function)) return;
+
+            //调用同步方法
+            $this->$function();
+        } catch (\Exception $e) {
+            $this->delete();
+        }
+    }
+
+    //采购
+    private function U8PO_PomainSave(){
+        $service = new U8ServerService();
+        if(! empty($service->error)) {
+            $service->finalSettle($this->data['id'], U8Job::one, $service->error);
+            return;
+        }
+
+        $service->U8PO_PomainSave($this->data['id']);
+    }
+
+    //销售(合同)
+    private function U8SaleOrderSave(){
+        $service = new U8ServerService();
+        if(! empty($service->error)) {
+            $service->finalSettle($this->data['id'], U8Job::two, $service->error);
+            return;
+        }
+
+        $service->U8SaleOrderSave($this->data['id']);
+    }
+
+//    public function failed($exception)
+//    {
+//        // 记录失败错误信息到日志或其他媒介
+//        $errorMessage = $exception->getFile() . $exception->getMessage() . $exception->getLine();
+//        $this->recordErrorTable($errorMessage);
+//    }
+
+    private function recordErrorTable($msg){
+        $data = $this->data;
+
+        ErrorTable::insert([
+            'msg' => $msg,
+            'data' => json_encode($this->data),
+            'user_id' => $data['user']['id'],
+            'user_operation_time' => $data['user']['operate_time'],
+            'type' => $data['type']
+        ]);
+    }
+
+    protected function echoMessage(OutputInterface $output)
+    {
+        //输出消息
+        $output->writeln(json_encode($this->data));
+    }
+}

+ 19 - 0
app/Model/ErrorTable.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+class ErrorTable extends Model
+{
+    protected $table = "error_table"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+    public static $type = [
+        1 => '采购单同步',
+        2 => '销售订单(合同同步)',
+    ];
+}

+ 35 - 0
app/Model/U8Job.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+class U8Job extends Model
+{
+    protected $table = "u8_job"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+    const success = 1;
+    const failed = 2;
+
+    const one = 1;
+    const two = 2;
+    public static $type = [
+        self::one,
+        self::two,
+    ];
+    public static $type_title = [
+        self::one => '采购单同步',
+        self::two => '销售订单(合同同步)',
+    ];
+
+    const job1 = 't9u8_purchase';
+    const job2 = 't9u8_sales';
+    public static $job = [
+        self::one => self::job1,
+        self::two => self::job2,
+    ];
+}

+ 44 - 0
app/Service/DataSyncToU8Service.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace App\Service;
+
+use App\Jobs\ProcessDataJob;
+use App\Model\PurchaseOrder;
+use App\Model\Supplier;
+use App\Model\U8Job;
+
+class DataSyncToU8Service extends Service
+{
+    public function add($data,$user){
+        list($status,$msg) = $this->orderRule($data);
+        if(!$status) return [$status,$msg];
+
+        dd((new U8ServerService())->U8PO_PomainSave($data['id']));
+        try{
+            $job = ProcessDataJob::dispatch($data)->onQueue($data['job']);
+            if(! $job) return [false,'任务没有进入队列!'];
+        }catch (\Throwable $e){
+            return [false,$e->getMessage()];
+        }
+
+        return [true,''];
+    }
+
+    public function orderRule(&$data){
+        if(empty($data['type'])) return [false,'type不能为空!'];
+        if(! in_array($data['type'],U8Job::$type)) return [false,'type不能存在!'];
+        if(empty($data['id'])) return [false,'同步数据不能为空!'];
+        $data['job'] = U8Job::$job[$data['type']] ?? "";
+        if(empty($data['job'])) return [false,'未找到同步任务!'];
+        if($data['type'] == U8Job::one){
+            //采购同步校验
+            $bool = PurchaseOrder::whereIn('id',$data['id'])
+                ->where('del_time',0)
+                ->where('supplier',0)
+                ->exists();
+            if($bool) return [false,'同步的采购单供应商不能为空!'];
+        }
+
+        return [true, ''];
+    }
+}

+ 545 - 0
app/Service/U8ServerService.php

@@ -0,0 +1,545 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\BasicType;
+use App\Model\Customer;
+use App\Model\Depart;
+use App\Model\Employee;
+use App\Model\Product;
+use App\Model\PurchaseOrder;
+use App\Model\PurchaseOrderInfo;
+use App\Model\SalesOrder;
+use App\Model\SalesOrderProductInfo;
+use App\Model\Setting;
+use App\Model\Supplier;
+use App\Model\U8Job;
+use Illuminate\Support\Facades\Config;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class U8ServerService extends Service
+{
+    public $db = null;
+    public $error = null; // 错误信息
+    public $u8 = []; //u8 配置连接参数
+    public $u8_api = ""; //u8接口请求地址
+    public $post_common = [];//u8接口公用参数
+
+    public function __construct($is_need_connect = 0)
+    {
+        //u8 配置连接参数 u8_api设置
+        list($status,$msg) = $this->settingConnection();
+        if(! $status) {
+            $this->error = $msg;
+            return;
+        }
+
+        //是否需要连接u8数据库
+        if($is_need_connect){
+            //构建数据库连接对象
+            list($status,$msg) = $this->settingDb();
+            if(! $status) {
+                $this->error = $msg;
+            }
+        }
+    }
+
+    //设置u8连接参数
+    private function settingConnection(){
+        $u8 = Setting::where('setting_name','u8')->where('setting_value','<>','')->first();
+        if(empty($u8)) return [false, 'u8配置参数不存在!'];
+        $u8 = $u8->toArray();
+        // 使用 eval() 函数执行字符串并转换为数组
+        $u8 = eval("return {$u8['setting_value']};");
+
+        if(empty($u8['domain'])) return [false, '外部域名不能为空!'];
+        if(empty($u8['u8_api_port'])) return [false, 'u8程序API端口不能为空!'];
+        if(empty($u8['u8_database_port'])) return [false, 'u8程序数据库端口不能为空!'];
+        if(empty($u8['database'])) return [false, 'u8程序数据库不能为空!'];
+        if(empty($u8['database_account'])) return [false, 'u8程序数据库登录账号不能为空!'];
+        if(empty($u8['database_password'])) return [false, 'u8程序数据库登录密码不能为空!'];
+        if(empty($u8['sAccID'])) return [false, 'u8程序sAccID不能为空!'];
+        if(empty($u8['sServer'])) return [false, 'u8程序sServer不能为空!'];
+        if(empty($u8['sUserID'])) return [false, 'u8程序sUserID不能为空!'];
+        if(empty($u8['sPassword'])) return [false, 'u8程序sPassword不能为空!'];
+
+        $this->u8 = $u8;
+        $this->u8_api = "https://" . $u8['domain'] . ":" . $u8['u8_api_port'] . "/U8Sys/U8API";
+        $this->post_common = [
+            "password"=>"cloud@123456",
+            "entity"=>"", //调用方法
+            "login"=>[
+                "sAccID"=> $u8['sAccID'],
+                "sDate"=> date("Y-m-d"),
+                "sServer"=> $u8['sServer'],
+                "sUserID"=> $u8['sUserID'],
+                "sSerial"=> "",
+                "sPassword"=> $u8['sPassword']
+            ]
+        ];
+
+        return [true, ''];
+    }
+
+    //设置u8数据库连接
+    private function settingDb(){
+        if(empty($this->db)){
+            $u8 = $this->u8;
+
+            $config = [
+                'driver' => 'sqlsrv',
+                'host' =>  $u8['domain'],
+                'port' => $u8['u8_database_port'],
+                'database' => $u8['database'],
+                'username' => $u8['database_account'],
+                'password' => $u8['database_password'],
+            ];
+
+            // 数据库配置设置
+            Config::set('database.connections.sqlsrvs', $config);
+
+            // 连接
+            try {
+                $pdo = DB::connection('sqlsrvs')->getPdo();
+                if ($pdo instanceof \PDO) {
+                    // 连接成功的逻辑代码
+                    $this->db = DB::connection('sqlsrvs');
+                } else {
+                    return [false, '连接失败!'];
+                }
+            } catch (\Throwable $e) {
+                return [false, $e->getMessage()];
+            }
+
+        }
+
+        return [true, ''];
+    }
+
+    //采购订单保存
+    public function U8PO_PomainSave($data){
+        $id = $data;
+
+        //映射ip是否通畅
+        $bool = $this->isDomainAvailable($this->u8['domain']);
+        if(! $bool) {
+            $msg = 'U8程序外部域名不可达';
+            $this->finalSettle($id, U8Job::one,$msg);
+            return;
+        }
+
+        //获取数据
+        $result = $this->getPurchaseData($id);
+        if(empty($result)) {
+            $msg = "同步数据获取失败";
+            $this->finalSettle($id, U8Job::one, $msg);
+            return;
+        }
+
+        //u8接口参数组织
+        $post = $this->post_common;
+        $post['entity'] = "U8PO_PomainSave";
+
+        $time = date("Y-m-d");
+
+        foreach ($result as $value){
+            $bodys = [];
+            foreach ($value['product'] as $son){
+                //子表数据
+                $bodys[] = [
+                    "iappids"=>"", //子表id
+                    "cinvcode"=>$son['code'], //存货编码
+                    "iquantity"=>$son['number'], //数量
+                    "inum"=>$son['number'], //件数
+                    "ipertaxrate"=>$son['ipertaxrate'], //税率
+                    "iunitprice"=>$son['iunitprice'], //原币单价
+                    "itaxprice"=>$son['itaxprice'], //原币含税单价
+                    "isum"=>$son['isum'], //原币价税合计
+                    "imoney"=>$son['imoney'], //原币无税金额
+                    "itax"=>$son['itax'],//原币税额
+                    "cbmemo"=>$son['mark'], //表体备注
+                    "cdefine22"=>"",
+                    "cdefine23"=>"",
+                    "cdefine24"=>"",
+                    "cdefine25"=>"",
+                    "cdefine26"=>"",
+                    "cdefine27"=>"",
+                    "cdefine28"=>"",
+                    "cdefine29"=>"",
+                    "cdefine30"=>"",
+                    "cdefine31"=>"",
+                    "cdefine32"=>"",
+                    "cdefine33"=>"",
+                    "cdefine34"=>"",
+                    "cdefine35"=>"",
+                    "cdefine36"=>"",
+                    "cdefine37"=>"",
+                    "cfree1"=>"",
+                    "cfree2"=>"",
+                    "cfree3"=>"",
+                    "cfree4"=>"",
+                    "cfree5"=>"",
+                    "cfree6"=>"",
+                    "cfree7"=>"",
+                    "cfree8"=>"",
+                    "cfree9"=>"",
+                    "cfree10"=>""
+                ];
+            }
+
+            //最终数据
+            $post['data'] = [
+                "cpoid"=>$value['order_number'],
+                "dpodate"=>date("Y-m-d H:i:s",$value['crt_time']),
+                "cmemo"=>"T9同步采购单",
+                "cmaker"=>"admin",
+                "cmaketime"=>$time,
+                "IsExamine"=>false,
+                "cvencode"=>$value['cvencode'], //供应商编码
+                "cdepcode"=>$value['cdepcode'], //部门编号
+                "cpersoncode"=>$value['cpersoncode'], //业务员编码
+                "cdefine1"=>"",
+                "cdefine2"=>"",
+                "cdefine3"=>"",
+                "cdefine4"=>"",
+                "cdefine5"=>"",
+                "cdefine6"=>"",
+                "cdefine7"=>"",
+                "cdefine8"=>"",
+                "cdefine9"=>"",
+                "cdefine10"=>"",
+                "cdefine11"=>"",
+                "cdefine12"=>"",
+                "cdefine13"=>"",
+                "cdefine14"=>"",
+                "cdefine15"=>"",
+                "cdefine16"=>"",
+                "bodys"=>$bodys
+            ];
+
+            file_put_contents('record_purchase.txt',"请求参数:" . json_encode($post) . PHP_EOL,8);
+            $return = $this->post_helper($this->u8_api,json_encode($post), ['Content-Type:application/json']);
+            file_put_contents('record_purchase.txt',"返回结果:" . json_encode($return). PHP_EOL,8);
+
+            //剔除数据
+            $id = array_diff($id, [$value['id']]);
+
+            if(empty($return)) {
+                $msg = '异常错误,请确认请求接口地址或地址不可达';
+                $this->finalSettle($value['id'], U8Job::one, $msg);
+            }else{
+                if( ! empty($return['flag'])){
+                    $this->finalSettle($value['id'], U8Job::one);
+                }else{
+                    $this->finalSettle($value['id'],  U8Job::one, $return['msg']);
+                }
+            }
+        }
+
+        if(! empty($id)){
+            $msg = "未找到同步数据";
+            $this->finalSettle($id, U8Job::one, $msg);
+        }
+    }
+
+    //销售订单(合同)保存
+    public function U8SaleOrderSave($data){
+        $id = $data;
+
+        //映射ip是否通畅
+        $bool = $this->isDomainAvailable($this->u8['domain']);
+        if(! $bool) {
+            $msg = 'U8程序外部域名不可达';
+            $this->finalSettle($id, U8Job::two, $msg);
+            return;
+        }
+
+        //获取数据
+        $result = $this->getSaleOrderData($id);
+        if(empty($result)) {
+            $msg = "同步数据获取失败";
+            $this->finalSettle($id, U8Job::two, $msg);
+            return;
+        }
+
+        //u8接口参数组织
+        $post = $this->post_common;
+        $post['entity'] = "U8SaleOrderSave";
+
+        $time = date("Y-m-d");
+        $time1 = date("Y-m-d H:i:s");
+        foreach ($result as $value){
+            $bodys = [];
+            foreach ($value['product'] as $son){
+                //子表数据
+                $bodys[] = [
+                    "iappids"=>"", //子表id
+                    "cinvcode"=>$son['code'], //存货编码
+                    "iquantity"=>$son['number'], //数量
+                    "inum"=>$son['number'], //件数
+                    "ipertaxrate"=>$son['ipertaxrate'], //税率
+                    "iunitprice"=>$son['iunitprice'], //原币单价
+                    "itaxprice"=>$son['itaxprice'], //原币含税单价
+                    "isum"=>$son['isum'], //原币价税合计
+                    "imoney"=>$son['imoney'], //原币无税金额
+                    "itax"=>$son['itax'],//原币税额
+                    "cbmemo"=>$son['mark'], //表体备注
+                    "cdefine22"=>"",
+                    "cdefine23"=>"",
+                    "cdefine24"=>"",
+                    "cdefine25"=>"",
+                    "cdefine26"=>"",
+                    "cdefine27"=>"",
+                    "cdefine28"=>"",
+                    "cdefine29"=>"",
+                    "cdefine30"=>"",
+                    "cdefine31"=>"",
+                    "cdefine32"=>"",
+                    "cdefine33"=>"",
+                    "cdefine34"=>"",
+                    "cdefine35"=>"",
+                    "cdefine36"=>"",
+                    "cdefine37"=>"",
+                    "cfree1"=>"",
+                    "cfree2"=>"",
+                    "cfree3"=>"",
+                    "cfree4"=>"",
+                    "cfree5"=>"",
+                    "cfree6"=>"",
+                    "cfree7"=>"",
+                    "cfree8"=>"",
+                    "cfree9"=>"",
+                    "cfree10"=>""
+                ];
+            }
+
+            //最终数据
+            $post['data'] = [
+                "csocode"=>$value['order_number'],
+                "ddate"=> $time,
+                "cmaker"=>"admin",
+                "dcreatesystime"=>$time1,
+                "cstcode"=>$value['cstcode'],
+                "ccuscode"=>$value['ccuscode'],
+                "cdepcode"=>$value['cdepcode'],
+                "cpersoncode"=>$value['cpersoncode'],
+                "itaxrate"=>"0",
+                "cmemo"=>"T9同步销售顶单",
+                "cdefine1"=>"",
+                "cdefine2"=>"",
+                "cdefine3"=>"",
+                "cdefine4"=>"",
+                "cdefine5"=>"",
+                "cdefine6"=>"",
+                "cdefine7"=>"",
+                "cdefine8"=>"",
+                "cdefine9"=>"",
+                "cdefine10"=>"",
+                "cdefine11"=>"",
+                "cdefine12"=>"",
+                "cdefine13"=>"",
+                "cdefine14"=>"",
+                "cdefine15"=>"",
+                "cdefine16"=>"",
+                "cdefine16"=>"",
+                "cdefine16"=>"",
+                "bodys"=>$bodys
+            ];
+
+            file_put_contents('record_purchase.txt',"请求参数:" . json_encode($post) . PHP_EOL,8);
+            $return = $this->post_helper($this->u8_api,json_encode($post), ['Content-Type:application/json']);
+            file_put_contents('record_purchase.txt',"返回结果:" . json_encode($return). PHP_EOL,8);
+
+            //剔除数据
+            $id = array_diff($id, [$value['id']]);
+
+            if(empty($return)) {
+                $msg = '异常错误,请确认请求接口地址或地址不可达';
+                $this->finalSettle($value['id'],U8Job::two, $msg);
+            }else{
+                if( ! empty($return['flag'])){
+                    $this->finalSettle($value['id'],U8Job::two);
+                }else{
+                    $this->finalSettle($value['id'], U8Job::two, $return['msg']);
+                }
+            }
+        }
+
+        if(! empty($id)){
+            $msg = "未找到同步数据";
+            $this->finalSettle($id,U8Job::two, $msg);
+        }
+    }
+
+    //最终处理
+    public function finalSettle($data,$data_type, $msg = ''){
+        if(! is_array($data)) $data = [$data];
+        $time = time();
+        $insert = [];
+
+        U8Job::where('del_time',0)
+            ->where('data_type',U8Job::one)
+            ->whereIn('data',$data)
+            ->update(['del_time' => $time]);
+        foreach ($data as $value){
+            if(empty($msg)){
+                $insert[] = [
+                    'data' => $value,
+                    'data_type' => $data_type,
+                    'crt_time' => $time,
+                    'state' => U8Job::success,
+                ];
+            }else{
+                $insert[] = [
+                    'data' => $value,
+                    'data_type' => $data_type,
+                    'crt_time' => $time,
+                    'state' => U8Job::failed,
+                    'msg' => $msg
+                ];
+            }
+        }
+
+        U8Job::insert($insert);
+    }
+
+    public function getPurchaseData($id){
+        $main = PurchaseOrder::whereIn('id',$id)
+            ->where('del_time',0)
+            ->get()->toArray();
+        if(empty($main)) return [];
+        $supplier = Supplier::whereIn('id',array_unique(array_column($main,'supplier')))
+            ->pluck('title','id')
+            ->toArray();
+        $depart = Depart::whereIn('id',array_unique(array_column($main,'depart_id')))
+            ->pluck('title','id')
+            ->toArray();
+        $emp = Employee::whereIn('id',array_unique(array_column($main,'purchase_id')))
+            ->pluck('number','id')
+            ->toArray();
+
+        $sub = PurchaseOrderInfo::whereIn('purchase_order_id',$id)
+            ->where('del_time',0)
+            ->get()->toArray();
+        $product = Product::whereIn('id',array_unique(array_column($sub,'product_id')))
+            ->get()->toArray();
+        $product_map = array_column($product,null,'id');
+
+        $sub_map = [];
+        foreach ($sub as $value){
+            $product_tmp = $product_map[$value['product_id']] ?? [];
+            $value['code'] = $product_tmp['code'];
+
+            //计算金额
+            if($value['rate'] > 0){
+                $value['ipertaxrate'] = $value['rate'];
+                $rate = round($value['rate'] / 100,2);
+                $value['iunitprice'] = round($value['price'] / $rate,2);
+                $value['itaxprice'] = $value['price'];
+                $value['isum'] = $value['price'] * $value['number'];
+                $value['imoney'] = $value['iunitprice'] * $value['number'];
+                $value['itax'] = $value['isum'] - $value['imoney'];
+            }else{
+                $value['ipertaxrate'] = 0;
+                $value['iunitprice'] = $value['price'];
+                $value['itaxprice'] = $value['price'];
+                $value['isum'] = $value['price'] * $value['number'];
+                $value['imoney'] = $value['isum'];
+                $value['itax'] = 0;
+            }
+
+            $sub_map[$value['purchase_order_id']][] = $value;
+        }
+        foreach ($main as $key => $value){
+            $main[$key]['cvencode'] = $supplier[$value['supplier']] ?? "";
+            $main[$key]['cdepcode'] = $depart[$value['depart_id']] ?? "";
+            $main[$key]['cpersoncode'] = $emp[$value['purchase_id']] ?? "";
+            $main[$key]['product'] = $sub_map[$value['id']] ?? [];
+        }
+
+        return $main;
+    }
+
+    public function getSaleOrderData($id){
+        $main = SalesOrder::whereIn('id',$id)
+            ->where('del_time',0)
+            ->get()->toArray();
+        if(empty($main)) return [];
+        $sub = SalesOrderProductInfo::whereIn('sales_order_id',$id)
+            ->where('del_time',0)
+            ->get()->toArray();
+        $product = Product::whereIn('id',array_unique(array_column($sub,'product_id')))
+            ->get()->toArray();
+        $product_map = array_column($product,null,'id');
+
+        $code_map = BasicType::whereIn('id',array_unique(array_merge_recursive(array_column($main,'business_type'),array_column($main,'sale_type'),array_column($main,'plat_type'))))
+            ->pluck('title','id')
+            ->toArray();
+        $customer_map = Customer::whereIn('id',array_unique(array_column($main,'customer_id')))
+            ->pluck('title','id')
+            ->toArray();
+        $depart = Depart::whereIn('id',array_unique(array_column($main,'depart_id')))
+            ->pluck('title','id')
+            ->toArray();
+        $emp = Employee::whereIn('id',array_unique(array_column($main,'crt_id')))
+            ->pluck('number','id')
+            ->toArray();
+
+        $sub_map = [];
+        foreach ($sub as $value){
+            $product_tmp = $product_map[$value['product_id']] ?? [];
+
+            //计算金额
+            if($value['rate'] > 0){
+                $value['ipertaxrate'] = $value['rate'];
+                $rate = round($value['rate'] / 100,2);
+                $value['iunitprice'] = round($value['price'] / $rate,2);
+                $value['itaxprice'] = $value['price'];
+                $value['isum'] = $value['price'] * $value['number'];
+                $value['imoney'] = $value['iunitprice'] * $value['number'];
+                $value['itax'] = $value['isum'] - $value['imoney'];
+            }else{
+                $value['ipertaxrate'] = 0;
+                $value['iunitprice'] = $value['price'];
+                $value['itaxprice'] = $value['price'];
+                $value['isum'] = $value['price'] * $value['number'];
+                $value['imoney'] = $value['isum'];
+                $value['itax'] = 0;
+            }
+
+            $value['code'] = $product_tmp['code'];
+            $sub_map[$value['sales_order_id']][] = $value;
+        }
+        foreach ($main as $key => $value){
+            $main[$key]['cstcode'] = $code_map[$value['sale_type']] ?? ""; //销售类型
+            $main[$key]['cbustype'] = $code_map[$value['business_type']] ?? ""; //业务类型
+            $main[$key]['cdefine25'] = $code_map[$value['plat_type']] ?? ""; //平台类型
+            $main[$key]['cdefine28'] = $code_map[$value['order_number']] ?? ""; //平台单号
+
+            $main[$key]['ccuscode'] = $customer_map[$value['customer_id']] ?? "";
+            $main[$key]['cdepcode'] = $depart[$value['depart_id']] ?? "";
+            $main[$key]['cpersoncode'] = $emp[$value['crt_id']] ?? "";
+            $main[$key]['product'] = $sub_map[$value['id']] ?? [];
+        }
+
+        return $main;
+    }
+
+    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);
+        curl_close($ch);
+        return json_decode($r, true);
+    }
+}

+ 4 - 0
routes/api.php

@@ -44,6 +44,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('reportList', 'Api\OaController@reportList');
     $route->any('reportCount', 'Api\OaController@reportCount');
     $route->any('reportCheck', 'Api\OaController@reportCheck');
+    $route->any('reportTime', 'Api\OaController@reportTime');
     //审批流参数
     $route->any('oaParamGet','Api\OaController@oaParamGet');
 
@@ -249,4 +250,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
 
     //获取审核单据的详情
     $route->any('checkDetail', 'Api\CheckController@getOrderDetail');
+
+    //数据同步到U8
+    $route->any('dataToU8','Api\DataSyncToU8Controller@add');
 });