FyySqlServerService.php 26 KB

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