FyySqlServerService.php 23 KB

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