| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775 |
- <?php
- namespace App\Service;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Config;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- class TestService extends Service
- {
- public function testdwy($data){
- if(empty($data['url']) || empty($data['post']) || empty($data['header'])) return [false,'API请求参数不能为空'];
- $url = $data['url'];
- $post = $data['post'];
- $header = $data['header'];
- $json = json_encode($post);
- $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',$json);
- $json = str_replace('"loginBindingParameters":[]','"loginBindingParameters":{}',$json);
- list($status, $result) = $this->post_helper($url,$json, $header, 40);
- if(! $status) return [false, $result];
- return [true, $result];
- }
- public function testdwyget($data){
- if(empty($data['url']) || empty($data['header'])) return [false,'API请求参数不能为空'];
- $url = $data['url'];
- $header = $data['header'];
- list($status,$result) = $this->get_helper($url,$header);
- if(! $status) return [false, $result];
- return [true, $result];
- }
- public function testdwyput($data){
- if(empty($data['url']) || empty($data['post']) || empty($data['header'])) return [false,'API请求参数不能为空'];
- $url = $data['url'];
- $post = $data['post'];
- $header = $data['header'];
- $json = json_encode($post);
- $json = str_replace('"workflowSearchBean":{}','"workflowSearchBean":[]',json_encode($post));
- $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
- list($status, $result) = $this->put_helper($url,$json, $header,40);
- if(! $status) return [false, $result];
- return [true, $result];
- }
- public function updateTopStock($data){
- list($status, $msg) = $this->rule();
- // if(! $status) return [false, 'IP未入白名单'];
- if(empty($data['urlFromT9']) || $data['urlFromT9'] != "getStock") return [false,'API请求参数不能为空'];
- if(empty($data['code'])) return [false,'API请求参数不能为空'];
- if(empty($data['warehouse'])) return [false,'API请求参数不能为空'];
- list($status, $msg) = $this->connectYy();
- if(! $status) return [false, $msg];
- //数据库
- $db = $msg[0];
- $u8 = $msg[1];
- list($status, $msg) = $this->getStock($db, $u8,$data['code'],$data['warehouse']);
- return [$status, $msg];
- }
- public function getSnList($data){
- list($status, $msg) = $this->rule();
- // if(! $status) return [false, 'IP未入白名单'];
- if(empty($data['urlFromT9']) || $data['urlFromT9'] != "getSnList") return [false,'API请求参数不能为空'];
- if(empty($data['sn_type'])) return [false, 'sn码来源依据不能为空'];
- list($status, $msg) = $this->connectYy();
- if(! $status) return [false, $msg];
- //数据库
- $db = $msg[0];
- $u8 = $msg[1];
- if($data['sn_type'] == 1){
- list($status, $msg) = $this->getSnListFormU8One($db, $u8,$data);
- }else{
- //发货出库单 sn码
- list($status, $msg) = $this->getSnListFormU8Two($db, $u8,$data);
- }
- return [$status, $msg];
- }
- public function getSnforMap($data){
- list($status, $msg) = $this->rule();
- // if(! $status) return [false, 'IP未入白名单'];
- if(empty($data['urlFromT9']) || $data['urlFromT9'] != "getSnMap") return [false,'API请求参数不能为空'];
- if(empty($data['sn'])) return [false, 'sn码不能为空'];
- if(empty($data['code'])) return [false, '产品编码不能为空'];
- list($status, $msg) = $this->connectYy();
- if(! $status) return [false, $msg];
- //数据库
- $db = $msg[0];
- $u8 = $msg[1];
- list($status, $msg) = $this->getSnListFormU8ForMap($db, $u8,$data);
- return [$status, $msg];
- }
- public function getSnForWarranty($data){
- list($status, $msg) = $this->rule();
- // if(! $status) return [false, 'IP未入白名单'];
- if(empty($data['urlFromT9']) || $data['urlFromT9'] != "getSnForWarranty") return [false,'API请求参数不能为空'];
- if(empty($data['sn'])) return [false, 'sn码不能为空'];
- list($status, $msg) = $this->connectYy();
- if(! $status) return [false, $msg];
- //数据库
- $db = $msg[0];
- $u8 = $msg[1];
- list($status, $msg) = $this->getSnForWarrantyData($db, $u8,$data);
- return [$status, $msg];
- }
- public function rule(){
- // 获取用户的IP地址
- $userIP = $_SERVER['REMOTE_ADDR'];
- // 获取设置的IP地址
- $ip = env("AliYUN");
- $allowedIPs = [$ip];
- $allowedIPs = array_filter($allowedIPs);
- if(empty($allowedIPs)) return [false, $userIP];
- // 校验用户IP是否在允许的范围内
- $isValidIP = false;
- foreach ($allowedIPs as $allowedIP) {
- if (strpos($allowedIP, '/') !== false) {
- // IP段表示法校验
- list($subnet, $mask) = explode('/', $allowedIP);
- if ((ip2long($userIP) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet)) {
- $isValidIP = true;
- break;
- }
- } else {
- // 单个IP地址校验
- if ($allowedIP === $userIP) {
- $isValidIP = true;
- break;
- }
- }
- }
- return [$isValidIP, $userIP];
- }
- public function connectYy(){
- $model_box = DB::connection("mysqlT9");
- $u8 = $model_box->table('setting')
- ->where('setting_name','u8')
- ->where('setting_value','<>','')
- ->first();
- if(empty($u8)) return [false, 'u8配置参数不存在!'];
- $u8 = $u8->setting_value;
- // 使用 eval() 函数执行字符串并转换为数组
- $u8 = eval("return {$u8};");
- 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不能为空!'];
- $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) {
- // 连接成功的逻辑代码
- $db = DB::connection('sqlsrvs');
- return [true, [$db, $u8]];
- } else {
- return [false, '连接失败!'];
- }
- } catch (\Throwable $e) {
- return [false, $e->getMessage()];
- }
- }
- public function getStock($db, $u8, $code = [], $warehouse = ""){
- if(empty($code) || empty($warehouse)) return [false, '存货以及仓库不能为空'];
- //映射ip是否通畅
- $bool = $this->isDomainAvailable($u8['domain']);
- if(! $bool) return [false, 'U8程序外部域名不可达'];
- $result = $db->table('CurrentStock')
- ->where("cWhCode", $warehouse)
- ->whereIn("cInvCode", $code)
- ->select('iQuantity as number', 'cInvCode as product_no')
- ->get()->toArray();
- $return = [];
- foreach ($result as $value){
- $return[] = [
- 'number' => floatval($value->number),
- 'product_no' => $value->product_no
- ];
- }
- return [true, $return];
- }
- public function getSnListFormU8One($db, $u8, $data){
- if(empty($data['code'])) return [false, '存货不能为空'];
- $sn = $data['sn'] ?? "";
- $construction_id = $data['construction_id'] ?? 0;
- $warehouse = [
- '001',
- '003',
- '010',
- ];
- //映射ip是否通畅
- $bool = $this->isDomainAvailable($u8['domain']);
- if(! $bool) return [false, 'U8程序外部域名不可达'];
- // $db->enableQueryLog();
- //检索条件 在库的
- $model = $db->table('ST_SNState')
- ->select('cinvCode as code','cInvSN as sn','AutoID as auto_id')
- ->whereIn("cWhCode", $warehouse)
- ->where("cInvCode", $data['code'])
- ->where("iSNState", 2)
- ->when(! empty($sn), function ($query) use ($sn) {
- return $query->where('cInvSN', 'LIKE', '%'.$sn.'%');
- })
- // ->when(! empty($construction_id), function ($query) use ($construction_id) {
- // return $query->whereNull('cSNDefine1')->orWhere('cSNDefine1', '')->orWhere('cSNDefine1', $construction_id);
- // })
- ->when(empty($construction_id), function ($query) {
- return $query->where(function ($q) {
- $q->whereNull('cSNDefine1')
- ->orWhere('cSNDefine1', '');
- });
- })
- ->orderBy('cSNDefine1','desc')
- ->orderBy('AutoID','asc');
- $list = $this->limit($model, '', $data);
- // dd($db->getQueryLog());
- return [true, $list];
- }
- public function getSnListFormU8Two($db, $u8, $data){
- if(empty($data['code']) || empty($data['depart_title'])) return [false, '存货以及门店信息不能为空'];
- $sn = $data['sn'] ?? "";
- $construction_id = $data['construction_id'] ?? 0;
- // $db->enableQueryLog();
- //映射ip是否通畅
- $bool = $this->isDomainAvailable($u8['domain']);
- if(! $bool) return [false, 'U8程序外部域名不可达'];
- $model = $db->table('rdrecord32 as a')
- ->leftJoin('rdrecords32 as b','b.ID','a.ID')
- ->leftJoin('ST_SNDetail_SaleOut as c','c.iVouchsID','b.AutoID')
- ->select("c.cInvCode as code",'c.cinvSN as sn','c.AutoID as auto_id') //,'c.cSNDefine1','a.ID'
- ->whereNotNull('a.cHandler')
- ->where("b.cInvCode", $data['code'])
- ->where("b.iQuantity", '>', 0)
- ->where("b.cDefine31", $data['depart_title'])
- ->whereNotNull("c.cinvSN")
- ->when(! empty($sn), function ($query) use ($sn) {
- return $query->where('c.cInvSN', 'LIKE', '%'.$sn.'%');
- })
- // ->when(! empty($construction_id), function ($query) use ($construction_id) {
- // return $query->whereNull('c.cSNDefine1')->orWhere('c.cSNDefine1', '')->orWhere('c.cSNDefine1', $construction_id);
- // })
- ->when(empty($construction_id), function ($query) {
- return $query->where(function ($q) {
- $q->whereNull('c.cSNDefine1')
- ->orWhere('c.cSNDefine1', '');
- });
- })
- ->orderBy('c.cSNDefine1','desc')
- ->orderBy('a.ID','desc')
- ->orderBy('c.AutoID','asc');
- $list = $this->limit($model, '', $data);
- // $logs = $db->getQueryLog();dd($logs);
- return [true, $list];
- }
- public function getSnListFormU8ForMap($db, $u8, $data){
- //映射ip是否通畅
- $bool = $this->isDomainAvailable($u8['domain']);
- if(! $bool) return [false, 'U8程序外部域名不可达'];
- $warehouse = [
- '001',
- '003',
- '010',
- ];
- $list = $db->table('ST_SNState')
- ->select("cInvCode as code",'cinvSN as sn')
- ->whereIn("cWhCode", $warehouse)
- ->whereIn("cInvCode", $data['code'])
- ->whereIn('cInvSN', $data['sn'])
- // ->where("iSNState", 2)
- ->get()->toArray();
- return [true, $list];
- }
- public function getSnForWarrantyData($db, $u8, $data){
- //映射ip是否通畅
- $bool = $this->isDomainAvailable($u8['domain']);
- if(! $bool) return [false, 'U8程序外部域名不可达'];
- $warehouse = [
- '001',
- '003',
- '010',
- ];
- $list = $db->table('ST_SNState')
- ->select("cInvCode as code",'cinvSN as sn','AutoID as auto_id')
- ->whereIn("cWhCode", $warehouse)
- ->where('cInvSN', $data['sn'])
- // ->where("iSNState", 2)
- ->first();
- return [true, $list];
- }
- public function saveSnUseData($data){
- list($status, $msg) = $this->rule();
- // if(! $status) return [false, 'IP未入白名单'];
- if(empty($data['urlFromT9']) || $data['urlFromT9'] != "saveSnUseData") return [false,'API请求参数不能为空'];
- if(empty($data['sn_type'])) return [false,'sn码来源依据不能为空'];
- // if(empty($data['sn_for_u8'])) return [false, 'sn码更新信息不能为空'];
- if(empty($data['data_id'])) return [false, 'dataID信息不能为空'];
- list($status, $msg) = $this->connectYy();
- if(! $status) return [false, $msg];
- //数据库
- $db = $msg[0];
- $u8 = $msg[1];
- list($status, $msg) = $this->saveSnUseDataDetail($db, $u8,$data);
- return [$status, $msg];
- }
- public function saveSnUseDataDetail($db, $u8, $data){
- //映射ip是否通畅 data_id = 1
- $bool = $this->isDomainAvailable($u8['domain']);
- if(! $bool) return [false, 'U8程序外部域名不可达'];
- $sn_for_u8 = $data['sn_for_u8'] ?? [];
- try {
- DB::beginTransaction();
- if(empty($sn_for_u8)){//删除
- if($data['sn_type'] == 1){
- $db->table('ST_SNState')
- ->where('cSNDefine1', $data['data_id'])
- ->update(['cSNDefine1' => ""]);
- }else{
- $db->table('ST_SNDetail_SaleOut')
- ->where('cSNDefine1', $data['data_id'])
- ->update(['cSNDefine1' => ""]);
- }
- }else{//增加或更新
- if($data['sn_type'] == 1){
- $db->table('ST_SNState')
- ->whereIn('AutoID', $sn_for_u8)
- ->update(['cSNDefine1' => $data['data_id']]);
- }else{
- $db->table('ST_SNDetail_SaleOut')
- ->whereIn('AutoID', $sn_for_u8)
- ->update(['cSNDefine1' => $data['data_id']]);
- }
- }
- DB::commit();
- }catch (\Exception $exception){
- DB::rollBack();
- return [false, $exception->getMessage()];
- }
- return [true, ''];
- }
- public function getToken(){
- list($status, $msg) = $this->SetU8();
- if(! $status) return [false , $msg];
- $host = $msg;
- $key = "lf_u8_long_token_demo";
- if(! Cache::has($key)){
- $url = $host . "/api/System/GetToken";
- $date = date("Y-m-d");
- $json = [
- "U8DbName"=> "UFDATA_001_2025",
- "sUserId"=> "demo",
- "sPassword"=> "DEMO",
- "LoginDateTime"=> $date,
- "bPersist"=> true
- ];
- $header = ['Content-Type:application/json'];
- list($status, $result) = $this->post_helper($url,json_encode($json), $header, 30);
- if(! $status) return [false, $result];
- if(! isset($result['code'])) return [false, '异常错误,请联系开发者'];
- if($result['code'] != 0) return [false, $result['msg']];
- $token = $result['data']['Token'] ?? "";
- Cache::forever($key, $token);
- }else{
- $token = Cache::get($key);
- }
- return [true, [$host, $token]];
- }
- //-----------------------------------朗峰u8-----
- public function salesOrderGet($data){
- list($status, $msg) = $this->getToken();
- if(! $status) return [false, $msg];
- list($host, $token) = $msg;
- $header = ["Authorization: {$token}",'Content-Type:application/json'];;
- $url = $host . "/api/System/SqlQuery";
- $json = '{
- "customSQLFileName": "U8SQL",
- "customSQLPath": "U8API/SO_SOMain/Get",
- "paramObj": {
- "@pagesize": 3,
- }
- }';
- list($status, $result) = $this->post_helper($url,$json, $header, 30);
- if(! $status) return [false, $result];
- if(! isset($result['code'])) return [false, '异常错误,请联系开发者'];
- if($result['code'] != 0) return [false, $result['msg']];
- if(empty($result['data'])) return [true, []];
- $return = [];
- $r_data = $result['data'];
- foreach ($r_data as $value){
- list($status, $detail) = $this->getSalesDetail($value, $msg);
- if(! $status) return [false, $detail];
- $return_detail = [];
- $total_qty = $money = 0;
- foreach ($detail as $d_value){
- $return_detail[] = [
- 'item_no' => $d_value['irowno'],
- 'material_code' => $d_value['cinvcode'],
- 'decor' => $d_value['cdefine30'] ?? '',
- 'craft_type_code' => $d_value['cdefine31'] ?? '',
- 'decor_b' => $d_value['cdefine32'] ?? '',
- 'craft_type_code_b' => $d_value['cdefine33'] ?? '',
- 'unit' => $d_value['cinvm_unit'],
- 'price' => $d_value['itaxunitprice'],
- 'not_tax_price' => $d_value['itaxunitprice'],
- 'tax_price' => $d_value['itaxunitprice'],
- 'qty' => $d_value['iquantity'],
- 'money' => $d_value['isum'],
- 'tax_amount' => $d_value['isum'],
- 'total_tax_amount' => $d_value['isum'],
- 'tax_rate' => $d_value['itaxrate'],
- 'expected_delivery_date' => date('Y-m-d',strtotime($d_value['dpredate'])),
- 'remark' => $d_value['cmemo'] ?? '',
- ];
- $total_qty = bcadd($total_qty,$d_value['iquantity'],3);
- $money = bcadd($money,$d_value['isum'],3);
- }
- $return[] = [
- 'no' => $value['csocode'],
- 'order_date' => date("Y-m-d",strtotime($value['ddate'])),
- 'customer' => $value['ccuscode'] ?? '',
- 'salesman' => $value['cpersoncode'] ?? '',
- 'sale_department' => $value['cdepcode'] ?? '',
- 'total_qty' => $total_qty,
- 'total_money' => $money,
- 'remark' => $value['cmemo'] ?? '',
- 'detail' => $return_detail,
- ];
- }
- return [true, $return];
- }
- private function SetU8(){
- $api_host = env('API_HOST');
- if(empty($api_host)) return [false, '用友对外域名不存在'];
- $api_port = env('API_PORT');
- if(empty($api_port)) return [false, '用友对外域名端口不存在'];
- //映射ip是否通畅
- $bool = $this->isDomainAvailable($api_host);
- if(! $bool) return [false, '用友对外域名不可达'];
- $host = $api_host . ":" . $api_port;
- return [true, $host];
- }
- private function getSalesDetail($sale_order, $msg){
- list($host, $token) = $msg;
- $header = ["Authorization: {$token}",'Content-Type:application/json'];;
- $url = $host . "/api/System/SqlQuery2";
- $json = [
- "customSQLFileName"=> "U8SQL",
- "customSQLPath"=> "U8API/SO_SOMain/GetWithDetail",
- "paramObj"=> [
- "@code"=> $sale_order["csocode"]
- ]
- ];
- list($status, $result) = $this->post_helper($url, json_encode($json), $header, 30);
- if(! $status) return [false, $result];
- if(! isset($result['code'])) return [false, '异常错误,请联系开发者'];
- if($result['code'] != 0) return [false, $result['msg']];
-
- return [true, $result['data']['DataTable1']];
- }
- public function materialAddU8($data){
- list($status, $msg) = $this->getToken();
- if(! $status) return [false, $msg];
- list($host, $token) = $msg;
- if(empty($data['iHead'])) return [false, '领料单表头信息不能为空'];
- if(empty($data['iBody'])) return [false, '领料单表体信息不能为空'];
- $header = ["Authorization: {$token}",'Content-Type:application/json'];;
- $url = $host . "/api/MaterialRequest/Add";
- $json[] = [
- "Inum" => "MaterialRequest",
- "data" =>[
- "iHead" => $data['iHead'],
- "iBody" => $data['iBody'],
- ],
- ];
- list($status, $result) = $this->post_helper($url, json_encode($json), $header, 30);
- if(! $status) return [false, $result];
- if(! isset($result['code'])) return [false, '异常错误,请联系开发者'];
- if($result['code'] != 0) return [false, $result['msg']];
- return [true, $result['data']];
- }
- public function productInAddU8($data){
- list($status, $msg) = $this->getToken();
- if(! $status) return [false, $msg];
- list($host, $token) = $msg;
- if(empty($data['iHead'])) return [false, '产成品入库单单表头信息不能为空'];
- if(empty($data['iBody'])) return [false, '产成品入库单表体信息不能为空'];
- $header = ["Authorization: {$token}",'Content-Type:application/json'];;
- $url = $host . "/api/ProductIn/Add";
- $json[] = [
- "Inum" => "ProductIn",
- "data" =>[
- "iHead" => $data['iHead'],
- "iBody" => $data['iBody'],
- ],
- ];
- list($status, $result) = $this->post_helper($url, json_encode($json), $header, 30);
- if(! $status) return [false, $result];
- if(! isset($result['code'])) return [false, '异常错误,请联系开发者'];
- if($result['code'] != 0) return [false, $result['msg']];
- return [true, $result['data']];
- }
- public function dispatchAddU8($data){
- list($status, $msg) = $this->getToken();
- if(! $status) return [false, $msg];
- list($host, $token) = $msg;
- if(empty($data['iHead'])) return [false, '发货单单表头信息不能为空'];
- if(empty($data['iBody'])) return [false, '发货单表体信息不能为空'];
- foreach ($data['iBody'] as $key => $value){
- $data['iBody'][$key] = $this->fillYonyouDispatchDetail($value);
- }
- $header = ["Authorization: {$token}",'Content-Type:application/json'];;
- $url = $host . "/api/Dispatch/Add";
- $json[] = [
- "Inum" => "DispatchList",
- "data" =>[
- "iHead" => $data['iHead'],
- "iBody" => $data['iBody'],
- ]
- ];
- list($status, $result) = $this->post_helper($url, json_encode($json), $header, 30);
- if(! $status) return [false, $result];
- if(! isset($result['code'])) return [false, '异常错误,请联系开发者'];
- if($result['code'] != 0) return [false, $result['msg']];
- return [true, $result['data']];
- }
- /**
- * 补全用友发货单子表金额字段(含换算率)
- * 输入示例:
- * [
- * 'iQuantity' => 1, // 输入单位数量
- * 'iunitprice' => 10, // 无税单价(按主计量单位)
- * 'iTaxRate' => 0, // 税率
- * 'iInvExchRate' => 12 // 换算率(1箱=12个)
- * ]
- */
- function fillYonyouDispatchDetail(array $item)
- {
- $qty = floatval($item['iQuantity']);
- $price = floatval($item['iunitprice']);
- $rate = floatval($item['iTaxRate']);
- $exchRate = floatval($item['iInvExchRate']);
- // 实际参与金额计算的基本数量(用友内部用这个)
- $qtyBase = $qty * $exchRate;
- // 税率
- $taxRate = $rate / 100;
- // 原币(人民币)
- $imoney = round($qtyBase * $price, 2);
- $itax = round($imoney * $taxRate, 2);
- $iSum = round($imoney + $itax, 2);
- $itaxunitprice = round($price * (1 + $taxRate), 6);
- // 本币 = 原币
- return array_merge($item, [
- 'imoney' => $imoney,
- 'itax' => $itax,
- 'iSum' => $iSum,
- 'itaxunitprice' => $itaxunitprice,
- 'idiscount' => 0,
- 'inatunitprice' => $price,
- 'inatmoney' => $imoney,
- 'inattax' => $itax,
- 'inatsum' => $iSum,
- 'inatdiscount' => 0,
- ]);
- }
- //-----------------------------------朗峰u8-----
- public function post_helper($url, $data, $header = [], $timeout = 20){
- Log::channel('apiLog')->info('朗峰POST', ["api" => $url , "param" => $data ,"header" => $header]);
- $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}";
- Log::channel('apiLog')->info('朗峰POST结果', ["message" => $message ]);
- return [false, $message];
- }
- curl_close($ch);
- Log::channel('apiLog')->info('朗峰POST结果', ["message" => json_decode($r, true) ]);
- return [true, json_decode($r, true)];
- }
- public function get_helper($url,$header=[],$timeout = 20){
- $ch = curl_init();
- curl_setopt_array($ch, array(
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_ENCODING => '',
- CURLOPT_MAXREDIRS => 10,
- CURLOPT_TIMEOUT => $timeout,
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
- CURLOPT_CUSTOMREQUEST => 'GET',
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_HTTPHEADER => $header,
- ));
- $r = curl_exec($ch);
- if ($r === false) {
- // 获取错误号
- $errorNumber = curl_errno($ch);
- // 获取错误信息
- $errorMessage = curl_error($ch);
- $message = "cURL Error #{$errorNumber}: {$errorMessage}";
- Log::channel('apiLog')->info('朗峰GET结果', ["message" => $message]);
- return [false, $message];
- }
- curl_close($ch);
- Log::channel('apiLog')->info('朗峰GET结果', ["message" => json_decode($r, true)]);
- return [true, json_decode($r, true)];
- }
- public function put_helper($url, $data, $header = [], $timeout = 20){
- Log::channel('apiLog')->info('朗峰PUT', ["api" => $url , "param" => $data ,"header" => $header]);
- $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, 'PUT');
- 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}";
- Log::channel('apiLog')->info('朗峰PUT结果', ["message" => $message]);
- return [false, $message];
- }
- curl_close($ch);
- Log::channel('apiLog')->info('朗峰PUT结果', ["message" => json_decode($r, true)]);
- return [true, json_decode($r, true)];
- }
- }
|