FyySqlServerService.php 22 KB

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