FyySqlServerService.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BoxDetail;
  4. use App\Model\Employee;
  5. use App\Model\Orders;
  6. use App\Model\SaleOrdersProduct;
  7. use Illuminate\Support\Facades\Config;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Log;
  10. use Illuminate\Support\Facades\Redis;
  11. class FyySqlServerService extends Service
  12. {
  13. public $db = null;
  14. public $error = null;
  15. public $host = "s6j9560970.goho.co";//数据库外网域名
  16. public $host_api = '13083970779.gnway.cc:8000';//用友接口外网域名
  17. public $port = 29703;
  18. public $database = "UFDATA_999_2023";
  19. public $url = "";
  20. public $sAccID = "(default)@999";
  21. public $sUserID = "demo";
  22. public $sPassword = "";
  23. private $database_select = [
  24. '001' => 'UFDATA_001_2023',
  25. '002' => 'UFDATA_002_2023',
  26. '999' => 'UFDATA_999_2023'
  27. ];
  28. public function __construct($user_id = [])
  29. {
  30. //用户信息校验
  31. if(empty($user_id['id'])) {
  32. $this->error = '福羊羊数据库连接用户参数不能为空!';
  33. return;
  34. }
  35. //账套
  36. $zt = Request()->header('zt');
  37. if(! $zt && isset($user_id['zt'])) $zt = $user_id['zt'];
  38. $this->database = $this->database_select[$zt] ?? '';
  39. $this->sAccID = '(default)@' . $zt;
  40. //获取用友账号密码
  41. if(isset($user_id['zt'])){
  42. $database = (new FinishedOrderService())->getConnectionName($user_id['zt']);
  43. $model = new Employee();
  44. $model->setConnection($database);
  45. $emp = $model->where('id',$user_id['id'])->select('sqlserver_account','sqlserver_password')->first();
  46. }else{
  47. $emp = Employee::where('id',$user_id['id'])->select('sqlserver_account','sqlserver_password')->first();
  48. }
  49. if(empty($emp)) {
  50. $this->error = '福羊羊连接构造失败!';
  51. return;
  52. }
  53. //用友接口统一登录账号密码
  54. $this->sUserID = $emp->sqlserver_account ?? '';
  55. $this->sPassword = $emp->sqlserver_password ?? '';
  56. //之前测试留下的入口 现在没用
  57. $key = 'fyy_sql_server' . $user_id['id'];
  58. $fyy_array = Redis::get($key);
  59. if(! empty($fyy_array)) {
  60. $fyy_array = json_decode($fyy_array,true);
  61. if(! empty($fyy_array['sqlserver_database'])) $this->database = $this->database_select[$fyy_array['sqlserver_zt']];
  62. if(! empty($fyy_array['sqlserver_zt'])) $this->sAccID = '(default)@' . $fyy_array['sqlserver_zt'];
  63. if(! empty($fyy_array['sqlserver_host'])) $this->host = $fyy_array['sqlserver_host'];
  64. if(! empty($fyy_array['sqlserver_host_api'])) $this->host_api = $fyy_array['sqlserver_host_api'];
  65. if(! empty($fyy_array['sqlserver_port'])) $this->port = $fyy_array['sqlserver_port'];
  66. if(! empty($fyy_array['sqlserver_account'])) $this->sUserID = $fyy_array['sqlserver_account'];
  67. if(! empty($fyy_array['sqlserver_password'])) $this->sPassword = $fyy_array['sqlserver_password'];
  68. }
  69. $this->url = $this->host_api . "/U8Sys/U8API";
  70. //----------
  71. if(! $this->db){
  72. $config = [
  73. 'driver' => 'sqlsrv',
  74. 'host' => $this->host,
  75. 'port' => $this->port,
  76. 'database' => $this->database,
  77. 'username' => env('SQLSRV_USERNAME'),
  78. 'password' => env('SQLSRV_PASSWORD'),
  79. ];
  80. // 进行数据库连接
  81. Config::set('database.connections.sqlsrvs', $config);
  82. try {
  83. $pdo = DB::connection('sqlsrvs')->getPdo();
  84. if ($pdo instanceof \PDO) {
  85. // 连接成功的逻辑代码
  86. $this->db = DB::connection('sqlsrvs');
  87. } else {
  88. $this->error = '连接失败!';
  89. return;
  90. }
  91. } catch (\Throwable $e) {
  92. $this->error = $e->getMessage();
  93. }
  94. }
  95. }
  96. //假数据
  97. private function fakeData(){
  98. $return = [
  99. [
  100. 'out_order_no' => '001',
  101. 'out_order_no_time' => 1685928995,
  102. 'customer_no' => '201603012',
  103. 'customer_name' => '巴大胡',
  104. 'table_header_mark' => '表头备注',
  105. 'product_no' => '产品编码001',
  106. 'product_title' => '产品名称001',
  107. 'product_size' => '产品规格30c',
  108. 'product_unit' => '产品单位米',
  109. 'order_quantity' => 100,
  110. 'product_quantity_on_hand' => 50,
  111. 'technology_material' => '工艺材质',
  112. 'technology_name' => '工艺名称:同命',
  113. 'wood_name' => '木皮名称:梭梭树皮',
  114. 'process_mark' => '加工备注',
  115. 'table_body_mark' => '表体备注',
  116. 'out_crt_man' => '外部人员一',
  117. 'out_checker_man' => '外部人员二',
  118. 'out_checker_time' => 1685928995,
  119. ],
  120. [
  121. 'out_order_no' => '001',
  122. 'out_order_no_time' => 1685928995,
  123. 'customer_no' => '201603012',
  124. 'customer_name' => '巴大胡',
  125. 'table_header_mark' => '表头备注',
  126. 'product_no' => '产品编码002',
  127. 'product_title' => '产品名称002',
  128. 'product_size' => '产品规格30d',
  129. 'product_unit' => '产品单位米',
  130. 'order_quantity' => 100,
  131. 'product_quantity_on_hand' => 50,
  132. 'technology_material' => '工艺材质',
  133. 'technology_name' => '工艺名称:同命',
  134. 'wood_name' => '木皮名称:梭梭树皮',
  135. 'process_mark' => '加工备注',
  136. 'table_body_mark' => '表体备注',
  137. 'out_crt_man' => '外部人员一',
  138. 'out_checker_man' => '外部人员二',
  139. 'out_checker_time' => 1685928995,
  140. ],
  141. [
  142. 'out_order_no' => '002',
  143. 'out_order_no_time' => 1685928995,
  144. 'customer_no' => '201603012',
  145. 'customer_name' => '巴大胡',
  146. 'table_header_mark' => '表头备注',
  147. 'product_no' => '产品编码002',
  148. 'product_title' => '产品名称002',
  149. 'product_size' => '产品规格30d',
  150. 'product_unit' => '产品单位米',
  151. 'order_quantity' => 100,
  152. 'product_quantity_on_hand' => 50,
  153. 'technology_material' => '工艺材质',
  154. 'technology_name' => '工艺名称:同命',
  155. 'wood_name' => '木皮名称:梭梭树皮',
  156. 'process_mark' => '加工备注',
  157. 'table_body_mark' => '表体备注',
  158. 'out_crt_man' => '外部人员一',
  159. 'out_checker_man' => '外部人员二',
  160. 'out_checker_time' => 1685928995,
  161. ],
  162. ];
  163. return $return;
  164. }
  165. public function is_same_month($timestamp1,$timestamp2){
  166. // 格式化时间戳为年份和月份
  167. $year1 = date('Y', $timestamp1);
  168. $month1 = date('m', $timestamp1);
  169. $year2 = date('Y', $timestamp2);
  170. $month2 = date('m', $timestamp2);
  171. if ($year1 === $year2 && $month1 === $month2) {
  172. return true;
  173. } else {
  174. return false;
  175. }
  176. }
  177. //获取数据(点击引入)
  178. public function getDataFromSqlServer($data){
  179. if(! empty($this->error)) return [false,$this->error,''];
  180. if(empty($data['out_order_no_time'][0]) || empty($data['out_order_no_time'][1])) return [false,'制单日期不能为空!',''];
  181. $bool = $this->is_same_month($data['out_order_no_time'][0],$data['out_order_no_time'][1]);
  182. if(! $bool) return [false,'制单日期必须同月!',''];
  183. //查询产品主表副表数据
  184. $start = date('Y-m-d H:i:s.000',$data['out_order_no_time'][0]);
  185. $end = date('Y-m-d H:i:s.000',$data['out_order_no_time'][1]);
  186. $model = $this->db->table('SO_SOMain as a')
  187. ->leftJoin('SO_SODetails as b','b.cSOCode','a.cSOCode')
  188. ->whereBetween('a.dDate',[$start, $end])
  189. ->whereNotNull('a.cVerifier')
  190. ->select('a.cSOCode as out_order_no','a.dDate as out_order_no_time','a.cCusCode as customer_no','a.cCusName as customer_name','a.cMemo as table_header_mark','a.cMaker as out_crt_man','a.cVerifier as out_checker_man','a.dverifydate as out_checker_time','b.cInvCode as product_no','b.iQuantity as order_quantity','b.cDefine28 as technology_material','b.cFree1 as technology_name','b.cFree2 as wood_name','b.cDefine30 as process_mark','b.cMemo as table_body_mark','b.iTaxUnitPrice as price');
  191. if(! empty($data['out_order_no'])) $model->where('a.cSOCode', 'LIKE', '%'.$data['out_order_no'].'%');
  192. if(! empty($data['customer_no'])) $model->where('a.cCusCode', 'LIKE', '%'.$data['customer_no'].'%');
  193. if(! empty($data['customer_name'])) $model->where('a.cCusName', 'LIKE', '%'.$data['customer_name'].'%');
  194. if(! empty($data['table_header_mark'])) $model->where('a.cMemo', 'LIKE', '%'.$data['table_header_mark'].'%');
  195. if(! empty($data['out_crt_man'])) $model->where('a.cMaker', 'LIKE', '%'.$data['out_crt_man'].'%');
  196. if(! empty($data['out_checker_man'])) $model->where('a.cVerifier', 'LIKE', '%'.$data['out_checker_man'].'%');
  197. if(! empty($data['out_checker_time'][0]) && ! empty($data['out_checker_time'][1])) {
  198. $start1 = date('Y-m-d H:i:s.000',$data['out_checker_time'][0]);
  199. $end1 = date('Y-m-d H:i:s.000',$data['out_checker_time'][1]);
  200. $model->whereBetween('a.dverifydate',[$start1, $end1]);
  201. }
  202. $result = $model->get()->toArray();
  203. if(empty($result)) return [false,'暂无数据,更新结束!',''];
  204. list($status,$msg) = $this->orderRule($result);
  205. if(empty($msg)) return [false,'暂无数据,更新结束!',''];
  206. $result = $msg;
  207. //查询附带的一些信息(比较少)
  208. $product_no = array_filter(array_column($result,'product_no'));
  209. $chunkSize = 1000; // 每个子集的大小
  210. $chunks = array_chunk($product_no, $chunkSize); // 将原始数组拆分成多个较小的子数组
  211. $results = []; // 存储查询结果的数组
  212. foreach ($chunks as $chunk) {
  213. $tmp = $this->db->table('Inventory as a')
  214. ->join('ComputationUnit as b', function ($join) {
  215. $join->on('a.cGroupCode', '=', 'b.cGroupCode')
  216. ->on('a.cComUnitCode', '=', 'b.cComUnitCode');
  217. }, null, null, 'left')
  218. ->whereIn('a.cInvCode', $chunk)
  219. ->select('a.cInvCode as product_no', 'a.cInvName as product_title', 'a.cInvStd as product_size', 'b.cComUnitName as product_unit')
  220. ->get()
  221. ->toArray();
  222. $results = array_merge($results, $tmp); // 将每个子集的结果合并到总结果数组中
  223. }
  224. $messageMap = array_column($results,null,'product_no');
  225. unset($results);
  226. //现存量查询开始 ---组织查询条件
  227. $args = '';
  228. foreach ($result as $value){
  229. $product = $value->product_no;
  230. $technology_name = $value->technology_name ?? '';
  231. $wood_name = $value->wood_name ?? '';
  232. $args .= "(a.cInvCode = '{$product}' and a.cFree1 = '{$technology_name}' and a.cFree2 = '{$wood_name}') OR ";
  233. }
  234. $args = rtrim($args,'OR ');
  235. $messageTwo = $this->db->table('CurrentStock as a')
  236. ->leftJoin('Warehouse as b','b.cWhCode','a.cWhCode')
  237. ->whereRaw("($args)")
  238. ->where('a.iQuantity','>',0)
  239. ->select('a.iQuantity as product_quantity_on_hand','a.cInvCode as product_no','a.cFree1 as technology_name','a.cFree2 as wood_name','b.cWhName as warehouse_name')
  240. ->get()->toArray();
  241. if(! empty($messageTwo)){
  242. foreach ($messageTwo as $key => $value){
  243. $messageTwo[$key] = (array)$value;
  244. }
  245. }
  246. //现存量查询结束
  247. foreach ($result as $key => $value){
  248. $result[$key]->technology_material = $value->technology_material ?? '';
  249. $result[$key]->technology_name = $value->technology_name ?? '';
  250. $result[$key]->wood_name = $value->wood_name ?? '';
  251. $result[$key]->process_mark = $value->process_mark ?? '';
  252. $result[$key]->table_body_mark = $value->table_body_mark ?? '';
  253. $result[$key]->table_header_mark = $value->table_header_mark ?? '';
  254. $keys = $value->product_no . $value->technology_name . $value->wood_name;
  255. $result[$key]->out_order_no_time = $value->out_order_no_time ? strtotime($value->out_order_no_time) : 0;
  256. $result[$key]->out_checker_time = $value->out_checker_time ? strtotime($value->out_checker_time) : 0;
  257. $result[$key]->product_title = $messageMap[$value->product_no]->product_title ?? '';
  258. $result[$key]->product_size = $messageMap[$value->product_no]->product_size ?? '';
  259. $result[$key]->product_unit = $messageMap[$value->product_no]->product_unit ?? '';
  260. $result[$key] = (array)$value;
  261. }
  262. return [true,$result,$messageTwo];
  263. }
  264. public function orderRule($data){
  265. $result = Orders::where('del_time',0)
  266. ->whereIn('out_order_no',array_column($data,'out_order_no'))
  267. ->select('out_order_no')
  268. ->get()->toArray();
  269. $out_order_no = array_column($result,'out_order_no');
  270. if(! empty($out_order_no)) {
  271. foreach ($data as $key => $value){
  272. if(in_array($value->out_order_no,$out_order_no)){
  273. unset($data[$key]);
  274. }
  275. }
  276. }
  277. return [true,$data];
  278. }
  279. //获取数据(刷新现存量)
  280. public function getDataFromSqlServerForOnHand($data){
  281. if(! empty($this->error)) return [false,$this->error,''];
  282. if(empty($data['id'])) return [false,'数据不能为空!',''];
  283. $product = SaleOrdersProduct::whereIn('id',$data['id'])
  284. ->select('product_no','technology_name','wood_name')
  285. ->get()->toArray();
  286. //现存量查询开始 ---组织查询条件
  287. $args = '';
  288. foreach ($product as $value){
  289. $args .= "(a.cInvCode = '{$value['product_no']}' and a.cFree1 = '{$value['technology_name']}' and a.cFree2 = '{$value['wood_name']}') OR ";
  290. }
  291. $args = rtrim($args,'OR ');
  292. $message = $this->db->table('CurrentStock as a')
  293. ->leftJoin('Warehouse as b','b.cWhCode','a.cWhCode')
  294. ->whereRaw("($args)")
  295. ->where('a.iQuantity','>',0)
  296. ->select('a.iQuantity as product_quantity_on_hand','a.cInvCode as product_no','a.cFree1 as technology_name','a.cFree2 as wood_name','b.cWhName as warehouse_name')
  297. ->get()->toArray();
  298. if(! empty($message)){
  299. foreach ($message as $key => $value){
  300. $message[$key] = (array)$value;
  301. }
  302. }
  303. //现存量查询结束
  304. return [true,$message,$product];
  305. }
  306. //产成品入库单保存接口以及审核
  307. public function U8Rdrecord10Save($data,$bredvouch = 0){
  308. if(! empty($this->error)) return [false,$this->error];
  309. if($bredvouch){
  310. $cmemo = '来源:福羊羊完工操作撤回';
  311. }else{
  312. $cmemo = '来源:福羊羊完工操作 派工单号:'. $data['dispatch_no'];
  313. }
  314. //数据
  315. $bodys[] = [
  316. "cinvcode"=> $data["product_no"],
  317. "cposition"=> "",
  318. "cbatch"=> "",
  319. "iquantity"=> $data["quantity"],
  320. "inum"=> $data["quantity"],
  321. "iunitcost"=> $data["price"] * 0.95,
  322. "iprice"=> $data["price"] * 0.95 * $data['quantity'],
  323. "iinvexchrate"=> "1.00",
  324. "impoids"=> "",
  325. "cmocode"=> "",
  326. "imoseq"=> "",
  327. "cbmemo"=> "",
  328. "cfree1"=> $data['technology_name'],
  329. "cfree2"=> $data['wood_name'],
  330. "cdefine28" => $data['technology_material'],
  331. ];
  332. $post = [
  333. "password"=>"cloud@123456",
  334. "entity"=>"U8Rdrecord10Save",
  335. "login"=>[
  336. "sAccID"=> $this->sAccID,
  337. "sDate"=> date("Y-m-d"),
  338. "sServer"=> '127.0.0.1',
  339. "sUserID"=> $this->sUserID,
  340. "sSerial"=> "",
  341. "sPassword"=> $this->sPassword
  342. ],
  343. "data"=>[
  344. "ccode"=>'',
  345. "ddate"=>date("Y-m-d"),
  346. "cmaker"=>$this->sUserID,
  347. "dnmaketime"=> date("Y-m-d"),
  348. "IsExamine"=>true,
  349. "bredvouch"=> $bredvouch,
  350. "cwhcode"=>"02",
  351. "cdepcode"=>"06",
  352. "crdcode"=>"102", //生产入库
  353. "cmemo"=> $cmemo,
  354. "cdefine10" => $data['customer_name'], //客户名称
  355. "bodys"=>$bodys
  356. ]
  357. ]; file_put_contents('record_ss.txt',json_encode($post) . PHP_EOL,8);
  358. $return = $this->post_helper($this->url,json_encode($post), ['Content-Type:application/json']);
  359. file_put_contents('record_ss.txt',json_encode($return). PHP_EOL,8);
  360. if(empty($return)) return [false, '异常错误,请确认请求接口地址!'];
  361. return [$return['flag'], $return['msg']];
  362. }
  363. //销售出库单保存接口给以及审核
  364. public function U8Rdrecord32Save($data,$bredvouch = 0){
  365. if(! empty($this->error)) return [false,$this->error];
  366. $new = [];
  367. foreach ($data as $value){
  368. $keys = $value['id'] . $value['cwhcode'];
  369. $new[$keys][] = $value;
  370. }
  371. foreach ($new as $value){
  372. $main_tmp = $value[0];
  373. $bodys_tmp = [];
  374. foreach ($value as $val){
  375. $bodys_tmp[] = [
  376. "idlsid"=>$val['idlsid'],
  377. "cdlcode"=>"",
  378. "dlrowno"=>"",
  379. "cbdlcode"=>"",
  380. "cinvcode"=>$val['cinvcode'],
  381. "cposition"=>$val['cposition'] ?? "",
  382. "cbatch"=>$val['cbatch'] ?? "",
  383. "iquantity"=>$val['iquantity'],
  384. "inum"=>$val['inum'],
  385. "iinvexchrate"=> $val['iinvexchrate'] ?? 0,
  386. "iunitcost"=>$val['iunitcost'] * 0.95,
  387. "iprice"=>$val['iunitcost'] * 0.95 * $val['iquantity'],
  388. "cbmemo"=>"",
  389. "cfree1"=> $val['cfree1'],
  390. "cfree2"=> $val['cfree2'],
  391. "cdefine28" => $val['technology_material'],
  392. "cdefine30" => $val['process_mark'],
  393. ];
  394. }
  395. $post_tmp = [
  396. "password"=>"cloud@123456",
  397. "entity"=>"U8Rdrecord32Save",
  398. "login"=>[
  399. "sAccID"=> $this->sAccID,
  400. "sDate"=> date("Y-m-d"),
  401. "sServer"=> '127.0.0.1',
  402. "sUserID"=> $this->sUserID,
  403. "sSerial"=> "",
  404. "sPassword"=> $this->sPassword
  405. ],
  406. "data"=>[
  407. "ccode"=>'',
  408. "ddate"=>date("Y-m-d"),
  409. "cmaker"=>$this->sUserID,
  410. "dnmaketime"=> date("Y-m-d"),
  411. "IsExamine"=>true,
  412. "bredvouch"=> $bredvouch,
  413. "cwhcode"=>$main_tmp['cwhcode'],
  414. "cdepcode"=>$main_tmp['cdepcode'],
  415. "ccuscode"=>$main_tmp['cuscode'],
  416. "crdcode"=>'202',
  417. "cmemo"=> '',
  418. "cdefine10" => $main_tmp['customer_name'], //客户名称
  419. "bodys"=>$bodys_tmp,
  420. ]
  421. ];
  422. $return = $this->post_helper($this->url,json_encode($post_tmp), ['Content-Type:application/json']);
  423. file_put_contents('record.txt',json_encode($new). PHP_EOL .json_encode($post_tmp) . PHP_EOL,8);
  424. if(empty($return)) return [false, '异常错误,请确认请求接口地址!'];
  425. if(! $return['flag']) return [false,$return['msg']];
  426. }
  427. return [true,''];
  428. }
  429. public function getBoxData($data){
  430. $boxData = BoxDetail::from('box_detail as a')
  431. ->leftJoin('sale_orders_product as b','b.id','a.top_id')
  432. ->where('a.del_time',0)
  433. ->where('a.order_no',$data['order_number']) //包装单号
  434. ->select('a.num as iquantity','b.product_no as cinvcode','b.technology_name as cfree1','b.wood_name as cfree2','b.out_order_no as cSOCode');
  435. return $boxData;
  436. }
  437. //获取发货单数据 还没发的
  438. public function getDataFromDispatchList($data){
  439. $model = $this->db->table('DispatchList as a')
  440. ->leftJoin('DispatchLists as b','b.DLID','a.DLID')
  441. ->leftJoin('Inventory as c','c.cInvCode','b.cInvCode')
  442. ->whereNotNull('a.cVerifier')
  443. ->whereColumn('b.iQuantity', '>', 'b.fOutQuantity');
  444. //检索条件
  445. if(! empty($data['time'][0]) && ! empty($data['time'][1])) {
  446. $model->where('a.dDate','>=',$data['time'][0]);
  447. $model->where('a.dDate','<=',$data['time'][1]);
  448. }
  449. if(! empty($data['order_no'])) $model->where('b.cSOcode',$data['order_no']);
  450. if(! empty($data['out_order_no'])) $model->where('b.cSOcode',$data['out_order_no']);
  451. $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')
  452. ->get()->toArray();
  453. if(! empty($message)){
  454. foreach ($message as $key => $value){
  455. // $message[$key]->iquantity = $value->iquantity - $value->out_quantity;
  456. $message[$key] = (array)$value;
  457. }
  458. }
  459. return $message;
  460. }
  461. //产成品入库单单据号
  462. public function createOrderNumberAboutSCRK(){
  463. $current_month = date('m'); // 获取当前月份
  464. $date1 = date('y') . $current_month ; // 格式 "2307"
  465. $date2 = date('Y') . $current_month; // 格式 "202307"
  466. $record = $this->db->table('VoucherHistory')
  467. ->where('CardNumber','0411')
  468. ->whereRaw("(cSeed = '{$date1}' or cSeed = '{$date2}')")
  469. ->select('cNumber')
  470. ->first();
  471. $record = (array)$record;
  472. if(empty($record)) return [false,'未找到产成品入库当月流水号信息!'];
  473. $tmp = $record['cNumber'] + 1;
  474. if(strlen($tmp) > 4) return [false,'产成品入库当月流水号超过四位数!'];
  475. $number = str_pad($tmp,4,'0',STR_PAD_LEFT);
  476. $number = $tmp . $number;
  477. $ccode = "SCRK" . $date2 . $number;
  478. return [true,$ccode];
  479. }
  480. //销售出库单单据号
  481. public function createOrderNumberAboutXC(){
  482. $current_month = date('m'); // 获取当前月份
  483. $date1 = date('y') . $current_month ; // 格式 "2307"
  484. $date2 = date('Y') . $current_month; // 格式 "202307"
  485. $record = $this->db->table('VoucherHistory')
  486. ->where('CardNumber','0303')
  487. ->whereRaw("(cSeed = '{$date1}' or cSeed = '{$date2}')")
  488. ->select('cNumber')
  489. ->first();
  490. $record = (array)$record;
  491. if(empty($record)) return [false,'未找到销售出库单当月流水号信息!'];
  492. $tmp = $record['cNumber'] + 1;
  493. if(strlen($tmp) > 4) return [false,'销售出库单当月流水号超过四位数!'];
  494. $number = str_pad($tmp,4,'0',STR_PAD_LEFT);
  495. $number = $tmp . $number;
  496. $ccode = "XC" . $date2 . $number;
  497. return [true,$ccode];
  498. }
  499. public function post_helper($url, $data,$header = [],$timeout = 60){
  500. $ch = curl_init();
  501. curl_setopt($ch, CURLOPT_URL, $url);
  502. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  503. curl_setopt($ch, CURLOPT_ENCODING, '');
  504. curl_setopt($ch, CURLOPT_POST, 1);
  505. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  506. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  507. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  508. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  509. if(!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  510. $r = curl_exec($ch);
  511. curl_close($ch);
  512. return json_decode($r, true);
  513. }
  514. }