|
@@ -15,6 +15,7 @@ use Illuminate\Support\Facades\Redis;
|
|
|
class FyySqlServerService extends Service
|
|
|
{
|
|
|
public $db = null;
|
|
|
+ public $db2 = null;
|
|
|
public $error = null;
|
|
|
public $host = "192.168.0.157";//数据库外网域名
|
|
|
public $host_api = '192.168.0.157';//用友接口外网域名
|
|
@@ -25,7 +26,7 @@ class FyySqlServerService extends Service
|
|
|
public $sUserID = "0001";
|
|
|
public $sPassword = "";
|
|
|
|
|
|
- public function __construct($user_id = [])
|
|
|
+ public function __construct($user_id = [], $is_db2 = false)
|
|
|
{
|
|
|
try {
|
|
|
//用户信息校验
|
|
@@ -57,7 +58,7 @@ class FyySqlServerService extends Service
|
|
|
$this->sPassword = $emp->sqlserver_password ?? '';
|
|
|
$this->url = $this->host_api . "/U8Sys/U8API";
|
|
|
|
|
|
- if (!$this->db) {
|
|
|
+ if(!$this->db) {
|
|
|
$config = [
|
|
|
'driver' => 'sqlsrv',
|
|
|
'host' => $this->host,
|
|
@@ -79,6 +80,29 @@ class FyySqlServerService extends Service
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if($is_db2){
|
|
|
+ $config = [
|
|
|
+ 'driver' => 'sqlsrv',
|
|
|
+ 'host' => $this->host,
|
|
|
+ 'port' => $this->port,
|
|
|
+ 'database' => 'UFSystem',
|
|
|
+ 'username' => env('SQLSRV_USERNAME'),
|
|
|
+ 'password' => env('SQLSRV_PASSWORD'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 进行数据库连接
|
|
|
+ Config::set('database.connections.sqlsrvs', $config);
|
|
|
+
|
|
|
+ $pdo = DB::connection('sqlsrvs')->getPdo();
|
|
|
+ if ($pdo instanceof \PDO) {
|
|
|
+ // 连接成功的逻辑代码
|
|
|
+ $this->db2 = DB::connection('sqlsrvs');
|
|
|
+ } else {
|
|
|
+ $this->error = '连接失败!';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (\Throwable $e) {
|
|
|
$this->error = $e->getMessage();
|
|
|
}
|
|
@@ -261,8 +285,21 @@ class FyySqlServerService extends Service
|
|
|
return [true, $message, $product];
|
|
|
}
|
|
|
|
|
|
+ //获取用友账号的人名
|
|
|
+ public function getYongyouName(){
|
|
|
+ if (!empty($this->error)) return [false, $this->error, ''];
|
|
|
+
|
|
|
+ $str = "";
|
|
|
+ $model = $this->db->table('UA_User')
|
|
|
+ ->where('cUser_Id',$this->sUserID)
|
|
|
+ ->select('cUser_Name')
|
|
|
+ ->first();
|
|
|
+ if(! empty($model)) $str = $model->cUser_Name;
|
|
|
+ return $str;
|
|
|
+ }
|
|
|
+
|
|
|
//产成品入库单保存接口以及审核
|
|
|
- public function U8Rdrecord10Save($data, $data_detail, $bredvouch = 0)
|
|
|
+ public function U8Rdrecord10Save($data, $data_detail, $bredvouch = 0)
|
|
|
{
|
|
|
if (! empty($this->error)) return [false, $this->error];
|
|
|
|
|
@@ -275,24 +312,31 @@ class FyySqlServerService extends Service
|
|
|
//数据
|
|
|
$bodys = [];
|
|
|
foreach ($data_detail as $value){
|
|
|
- $bodys[] = [
|
|
|
- "cinvcode" => $value["ext_1"],
|
|
|
- "cposition" => "",
|
|
|
- "cbatch" => "",
|
|
|
- "iquantity" => $value["num"],
|
|
|
- "inum" => $value["num"],
|
|
|
- "iunitcost" => $value["price"] * 0.95,
|
|
|
- "iprice" => $value["price"] * 0.95 * $value['num'],
|
|
|
- "iinvexchrate" => "1.00",
|
|
|
- "impoids" => "",
|
|
|
- "cmocode" => "",
|
|
|
- "imoseq" => "",
|
|
|
- "cbmemo" => "",
|
|
|
- "cfree1" => $value['ext_3'], //颜色
|
|
|
- "cfree2" => "",
|
|
|
- "cdefine28" => "",
|
|
|
- ];
|
|
|
+ $key = $value['ext_1'] . $value['ext_3'];
|
|
|
+ if(! isset($bodys[$key])){
|
|
|
+ $bodys[$key] = [
|
|
|
+ "cinvcode" => $value["ext_1"],
|
|
|
+ "cposition" => "",
|
|
|
+ "cbatch" => "",
|
|
|
+ "iquantity" => $value["num"],
|
|
|
+ "inum" => $value["num"],
|
|
|
+ "iunitcost" => 0,
|
|
|
+ "iprice" => 0,
|
|
|
+ "iinvexchrate" => 0,
|
|
|
+ "impoids" => "",
|
|
|
+ "cmocode" => "",
|
|
|
+ "imoseq" => "",
|
|
|
+ "cbmemo" => "",
|
|
|
+ "cfree1" => $value['ext_3'], //颜色
|
|
|
+ "cfree2" => "",
|
|
|
+ "cdefine28" => "",
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ $bodys[$key]['iquantity'] += $value['num'];
|
|
|
+ $bodys[$key]['inum'] += $value['num'];
|
|
|
+ }
|
|
|
}
|
|
|
+ $bodys = array_values($bodys);
|
|
|
|
|
|
$post = [
|
|
|
"password" => "cloud@123456",
|
|
@@ -308,7 +352,7 @@ class FyySqlServerService extends Service
|
|
|
"data" => [
|
|
|
"ccode" => '',
|
|
|
"ddate" => date("Y-m-d"),
|
|
|
- "cmaker" => $this->sUserID,
|
|
|
+ "cmaker" => $data['create_name'],
|
|
|
"dnmaketime" => date("Y-m-d"),
|
|
|
"IsExamine" => true,
|
|
|
"bredvouch" => $bredvouch,
|
|
@@ -332,46 +376,37 @@ class FyySqlServerService extends Service
|
|
|
}
|
|
|
|
|
|
//销售出库单保存接口给以及审核
|
|
|
- public function U8Rdrecord32Save($data, $bredvouch = 0)
|
|
|
+ public function U8Rdrecord32Save($data,$create_name, $bredvouch = 0)
|
|
|
{
|
|
|
if (!empty($this->error)) return [false, $this->error];
|
|
|
|
|
|
if ($bredvouch) {
|
|
|
- $cmemo = '来源:恒诚塑业';
|
|
|
+ $cmemo = '来源:恒诚塑业发货出库操作(撤回)';
|
|
|
} else {
|
|
|
$cmemo = '来源:恒诚塑业发货出库操作';
|
|
|
}
|
|
|
-
|
|
|
- $new = [];
|
|
|
foreach ($data as $value) {
|
|
|
- $keys = $value['id'] . $value['cwhcode'];
|
|
|
- $new[$keys][] = $value;
|
|
|
- }
|
|
|
-
|
|
|
- foreach ($new as $value) {
|
|
|
- $main_tmp = $value[0];
|
|
|
$bodys_tmp = [];
|
|
|
- foreach ($value as $val) {
|
|
|
+ foreach ($value['product'] as $v){
|
|
|
$bodys_tmp[] = [
|
|
|
- "idlsid" => $val['idlsid'],
|
|
|
+ "idlsid" => "",
|
|
|
"cdlcode" => "",
|
|
|
"dlrowno" => "",
|
|
|
"cbdlcode" => "",
|
|
|
- "cinvcode" => $val['cinvcode'],
|
|
|
- "cposition" => $val['cposition'] ?? "",
|
|
|
- "cbatch" => $val['cbatch'] ?? "",
|
|
|
- "iquantity" => $val['iquantity'],
|
|
|
- "inum" => $val['inum'],
|
|
|
- "iinvexchrate" => $val['iinvexchrate'] ?? 0,
|
|
|
- "iunitcost" => $val['iunitcost'] * 0.95,
|
|
|
- "iprice" => $val['iunitcost'] * 0.95 * $val['iquantity'],
|
|
|
+ "cinvcode" => $v['cinvcode'],
|
|
|
+ "cposition" => "",
|
|
|
+ "cbatch" => "",
|
|
|
+ "iquantity" => $v['iquantity'],
|
|
|
+ "inum" => 0,
|
|
|
+ "iinvexchrate" => 0,
|
|
|
+ "iunitcost" => 0,
|
|
|
+ "iprice" => 0,
|
|
|
"cbmemo" => "",
|
|
|
- "cfree1" => $val['cfree1'],
|
|
|
- "cfree2" => $val['cfree2'],
|
|
|
- "cdefine28" => $val['technology_material'],
|
|
|
- "cdefine30" => $val['process_mark'],
|
|
|
+ "cfree1" => $v['cfree1'],
|
|
|
+ "cfree2" => "",
|
|
|
];
|
|
|
}
|
|
|
+ $cmemo = $cmemo . '(发货单信息:' . $value['cdlcode_string'] . ')';
|
|
|
$post_tmp = [
|
|
|
"password" => "cloud@123456",
|
|
|
"entity" => "U8Rdrecord32Save",
|
|
@@ -386,26 +421,27 @@ class FyySqlServerService extends Service
|
|
|
"data" => [
|
|
|
"ccode" => '',
|
|
|
"ddate" => date("Y-m-d"),
|
|
|
- "cmaker" => $this->sUserID,
|
|
|
+ "cmaker" => $create_name,
|
|
|
"dnmaketime" => date("Y-m-d"),
|
|
|
"IsExamine" => true,
|
|
|
"bredvouch" => $bredvouch,
|
|
|
- "cwhcode" => $main_tmp['cwhcode'],
|
|
|
- "cdepcode" => $main_tmp['cdepcode'],
|
|
|
- "ccuscode" => $main_tmp['cuscode'],
|
|
|
+ "cdepcode" => "03",
|
|
|
+ "ccuscode" => $value['customer_code'],
|
|
|
"crdcode" => '202',
|
|
|
"cmemo" => $cmemo,
|
|
|
- "cdefine10" => $main_tmp['customer_name'], //客户名称
|
|
|
+ "cwhcode" => "002",
|
|
|
"bodys" => $bodys_tmp,
|
|
|
]
|
|
|
];
|
|
|
+ }
|
|
|
|
|
|
- $return = $this->post_helper($this->url, json_encode($post_tmp), ['Content-Type:application/json']);
|
|
|
- file_put_contents('record.txt', json_encode($new) . PHP_EOL . json_encode($post_tmp) . PHP_EOL, 8);
|
|
|
+ Log::channel('apiLog')->info('销售出库单:源数据', ["param" => $post_tmp]);
|
|
|
+ $return = $this->post_helper($this->url, json_encode($post_tmp), ['Content-Type:application/json']);
|
|
|
|
|
|
- if (empty($return)) return [false, '异常错误,请确认请求接口地址!'];
|
|
|
- if (!$return['flag']) return [false, $return['msg']];
|
|
|
- }
|
|
|
+ Log::channel('apiLog')->info('产成品入库:返回结果', ["param" => $return]);
|
|
|
+
|
|
|
+ if (empty($return)) return [false, '异常错误,请确认请求接口地址!'];
|
|
|
+ if (! $return['flag']) return [false, $return['msg']];
|
|
|
|
|
|
return [true, ''];
|
|
|
}
|
|
@@ -438,7 +474,7 @@ class FyySqlServerService extends Service
|
|
|
if (!empty($data['order_no'])) $model->where('b.cSOcode', $data['order_no']);
|
|
|
if (!empty($data['out_order_no'])) $model->where('b.cSOcode', $data['out_order_no']);
|
|
|
|
|
|
- $message = $model->select('a.cDLCode as cdlcode', 'a.DLID as id', 'a.cDefine10 as customer_name', 'b.cSOCode as csocode', 'a.cDepCode as cdepcode', 'a.cCusCode as cuscode', 'b.iDLsID as idlsid', 'b.cWhCode as cwhcode', 'b.cInvCode as cinvcode', 'b.cInvName as product_title', 'b.cFree1 as cfree1', 'b.cFree2 as cfree2', 'b.cPosition as cposition', 'b.cBatch as cbatch', 'b.iQuantity as iquantity', 'b.iNum as inum', 'b.iInvExchRate as iinvexchrate', 'b.fOutQuantity as out_quantity', 'b.iUnitPrice as iunitcost', 'b.iMoney as imoney', 'b.cDefine28 as technology_material', 'b.cDefine30 as process_mark', 'c.cInvStd as product_size')
|
|
|
+ $message = $model->select('a.cDLCode as cdlcode', 'a.DLID as id', 'a.cCusName as customer_name', 'b.cSOCode as csocode', 'a.cDepCode as cdepcode', 'a.cCusCode as cuscode', 'b.iDLsID as idlsid', 'b.cWhCode as cwhcode', 'b.cInvCode as cinvcode', 'b.cInvName as product_title', 'b.cFree1 as cfree1', 'b.cFree2 as cfree2', 'b.cPosition as cposition', 'b.cBatch as cbatch', 'b.iQuantity as iquantity', 'b.iNum as inum', 'b.iInvExchRate as iinvexchrate', 'b.fOutQuantity as out_quantity', 'b.iUnitPrice as iunitcost', 'b.iMoney as imoney', 'b.cDefine28 as technology_material', 'b.cDefine30 as process_mark', 'c.cInvStd as product_size')
|
|
|
->get()->toArray();
|
|
|
|
|
|
if (!empty($message)) {
|
|
@@ -476,10 +512,10 @@ class FyySqlServerService extends Service
|
|
|
if(empty($data['page_size'])) $data['page_size'] = 20;
|
|
|
if(empty($data['page_index'])) $data['page_index'] = 1;
|
|
|
|
|
|
- $model = $this->db->table('DispatchList as a')
|
|
|
+ $model = $this->db->table('DispatchList as a')
|
|
|
->leftJoin('DispatchLists as b', 'b.DLID', 'a.DLID')
|
|
|
->leftJoin('Inventory as c', 'c.cInvCode', 'b.cInvCode')
|
|
|
- ->select('a.cDLCode as cdlcode', 'a.DLID as id', 'a.cDefine10 as customer_name', 'b.cSOCode as csocode', 'a.cDepCode as cdepcode', 'a.cCusCode as cuscode', 'a.dDate as date', 'b.iDLsID as idlsid', 'b.cWhCode as cwhcode', 'b.cInvCode as cinvcode', 'b.cInvName as product_title', 'b.cFree1 as cfree1', 'b.cFree2 as cfree2', 'b.cPosition as cposition', 'b.cBatch as cbatch', 'b.iQuantity as iquantity', 'b.iNum as inum', 'b.iInvExchRate as iinvexchrate', 'b.fOutQuantity as out_quantity', 'b.iUnitPrice as iunitcost', 'b.iMoney as imoney', 'b.cDefine28 as technology_material', 'b.cDefine30 as process_mark', 'c.cInvStd as product_size', DB::raw('(b.iQuantity - b.fOutQuantity) as quantity'), 'a.cMemo as table_header_mark', 'b.cMemo as table_body_mark')
|
|
|
+ ->select('a.cDLCode as cdlcode', 'a.DLID as id', 'a.cCusName as customer_name', 'b.cSOCode as csocode', 'a.cDepCode as cdepcode', 'a.cCusCode as cuscode', 'a.dDate as date', 'b.iDLsID as idlsid', 'b.cWhCode as cwhcode', 'b.cInvCode as cinvcode', 'b.cInvName as product_title', 'b.cFree1 as cfree1', 'b.cFree2 as cfree2', 'b.cPosition as cposition', 'b.cBatch as cbatch', 'b.iQuantity as iquantity', 'b.iNum as inum', 'b.iInvExchRate as iinvexchrate', 'b.fOutQuantity as out_quantity', 'b.iUnitPrice as iunitcost', 'b.iMoney as imoney', 'b.cDefine28 as technology_material', 'b.cDefine30 as process_mark', 'c.cInvStd as product_size', DB::raw('(b.iQuantity - b.fOutQuantity) as quantity'), 'a.cMemo as table_header_mark', 'b.cMemo as table_body_mark')
|
|
|
->whereNotNull('a.cVerifier')
|
|
|
// ->whereColumn('b.iQuantity', '>', 'b.fOutQuantity')
|
|
|
->where('a.dDate', '>=', $data['time'][0])
|
|
@@ -535,6 +571,7 @@ class FyySqlServerService extends Service
|
|
|
$new_data[$value['cdlcode']] = [
|
|
|
"cdlcode" => $value['cdlcode'],
|
|
|
"csocode" => $value['csocode'],
|
|
|
+ "customer_code" => $value['cuscode'] ?? "",
|
|
|
"customer_name" => $value['customer_name'] ?? "",
|
|
|
"product" => [$pro]
|
|
|
];
|
|
@@ -547,6 +584,57 @@ class FyySqlServerService extends Service
|
|
|
return $list;
|
|
|
}
|
|
|
|
|
|
+ //获取发货单数据 做校验
|
|
|
+ public function getDataFromDispatchListForCheck($data)
|
|
|
+ {
|
|
|
+ $model = $this->db->table('DispatchList as a')
|
|
|
+ ->leftJoin('DispatchLists as b', 'b.DLID', 'a.DLID')
|
|
|
+ ->select('a.cDLCode as cdlcode', 'a.cCusName as customer_name', 'b.cSOCode as csocode', 'a.cCusCode as cuscode','b.cInvCode as cinvcode', 'b.cInvName as product_title', 'b.cFree1 as cfree1','b.iQuantity as iquantity', 'b.iNum as inum', 'b.iInvExchRate as iinvexchrate', 'b.fOutQuantity as out_quantity', 'b.iUnitPrice as iunitcost', 'b.iMoney as imoney');
|
|
|
+
|
|
|
+ if (!empty($data['cdlcode'])) $model->whereIn('a.cDLCode', $data['cdlcode']);
|
|
|
+ //颜色
|
|
|
+ if (!empty($data['cfree1'])) $model->where('b.cFree1', 'Like', '%' . $data['cfree1'] . '%');
|
|
|
+
|
|
|
+ $list = $model->get()->toArray();
|
|
|
+
|
|
|
+ if (! empty($list)) {
|
|
|
+ $list = Collect($list)->map(function ($object) {
|
|
|
+ return (array)$object;
|
|
|
+ })->toArray();
|
|
|
+
|
|
|
+ $new_data = [];
|
|
|
+ foreach ($list as $value) {
|
|
|
+ $iquantity = intval($value['iquantity']);
|
|
|
+ $out_quantity = intval($value['out_quantity']);
|
|
|
+ $inum = intval($value['inum']);
|
|
|
+ $pro = [
|
|
|
+ "cinvcode" => $value['cinvcode'],
|
|
|
+ "product_title" => $value['product_title'],
|
|
|
+ "cfree1" => $value['cfree1'],
|
|
|
+ "iquantity" => $iquantity,
|
|
|
+ "inum" => $inum,
|
|
|
+ "out_quantity" => $out_quantity,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if(isset($new_data[$value['cdlcode']])){
|
|
|
+ $new_data[$value['cdlcode']]['product'][] = $pro;
|
|
|
+ }else{
|
|
|
+ $new_data[$value['cdlcode']] = [
|
|
|
+ "cdlcode" => $value['cdlcode'],
|
|
|
+ "csocode" => $value['csocode'],
|
|
|
+ "customer_code" => $value['cuscode'] ?? "",
|
|
|
+ "customer_name" => $value['customer_name'] ?? "",
|
|
|
+ "product" => [$pro]
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = $new_data;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
public function recordErrorTable($msg,$user,$data,$time,$type){
|
|
|
// 连接到指定数据库连接
|
|
|
ErrorTable::insert([
|