FyySqlServerService.php 24 KB

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