FyySqlServerService.php 24 KB

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