FyySqlServerService.php 29 KB

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