|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Support\Facades\Config;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
@@ -414,6 +415,267 @@ class TestService extends Service
|
|
|
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]);
|
|
|
|