WorkOrderVerification.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use \think\Request;
  5. use \think\Db;
  6. use \think\cache;
  7. /**
  8. * 工单核验单维护接口
  9. */
  10. class WorkOrderVerification extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. /**
  15. * 首页
  16. *
  17. */
  18. public function index()
  19. {
  20. $this->success('请求成功');
  21. }
  22. /**
  23. * 获取报工历史几记录
  24. *
  25. */
  26. public function getTab(){
  27. //get请求
  28. if(!$this->request->isGet()){
  29. $this->error('请求方式错误');
  30. }
  31. $param = $this->request->param();
  32. $where = [
  33. '子订单编号' => $param['order_id'],
  34. 'sczl_jtbh' => $param['sczl_jtbh']
  35. ];
  36. //通过当前子订单编号和机台查看历史记录数据
  37. $table_list = \db('设备_产量计酬')->alias('c')
  38. ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.数量, c.sczl_jtbh, c.尾包,c.UniqId,c.ci_num,c.s_num,
  39. c.sys_rq, c.serial, y.zdtotal, y.sctotal, j.款式, y.颜色')
  40. ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
  41. ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
  42. ->where('c.子订单编号', $param['order_id'])
  43. ->where('c.sczl_jtbh', $param['sczl_jtbh'])
  44. ->whereNull('c.mod_rq') // 查询未删除数据
  45. ->where(function($query) {
  46. $query->whereNotNull('y.ck_rq')->where('y.ck_rq', '<>', '');
  47. }) // 查询出库数据
  48. ->order('c.UniqId', 'desc')
  49. ->distinct('c.子订单编号')
  50. ->select();
  51. $output = [];
  52. foreach ($table_list as $record) {
  53. $output[] = [
  54. 'serial' => $record['serial'],
  55. 'sys_rq' => $record['sys_rq'],
  56. '订单编号' => $record['订单编号'],
  57. '子订单编号' => $record['子订单编号'],
  58. '颜色' => $record['颜色'],
  59. '尺码' => $record['尺码'],
  60. '数量' => $record['数量'],
  61. '上报数量' => $record['s_num'],
  62. '尾包' => $record['尾包'],
  63. '组别' => $record['sczl_jtbh'],
  64. ];
  65. }
  66. $this->success('请求成功', [
  67. 'records' => $output
  68. ]);
  69. }
  70. /**
  71. * 记录报工日志历史记录
  72. */
  73. public function getTabByGdbh()
  74. {
  75. if (Request::instance()->isPost() === false){
  76. $this->error('请求错误');
  77. }
  78. $param = Request::instance()->post();
  79. if (empty($param)){
  80. $this->error('参数错误');
  81. }
  82. $rows = db()->table('工单_基本资料')
  83. ->where('订单编号',$param['订单编号'])
  84. ->find();
  85. $param['客户编号'] = $rows['客户编号'];
  86. $sql= \db('设备_报工记录')->fetchSql(true)->insert($param);
  87. $res = \db()->query($sql);
  88. if ($res !== false){
  89. $this->success('成功');
  90. }else{
  91. $this->error('失败');
  92. }
  93. }
  94. /**
  95. * 获取报工日志
  96. * @ApiMethod (GET)
  97. */
  98. public function getList()
  99. {
  100. if(!$this->request->isGet()){
  101. $this->error('请求方式错误');
  102. }
  103. $param = $this->request->param();
  104. // 判断订单编号是否包含 '-'
  105. if (strpos($param['order'], '-') !== false) {
  106. // 如果订单包含 '-',则按子订单编号精确匹配
  107. $where['子订单编号'] = $param['order'];
  108. } else {
  109. // 如果订单不包含 '-',则按订单编号进行模糊匹配
  110. $where['订单编号'] = ['like', '%' . $param['order'] . '%'];
  111. }
  112. // 过滤条件中的 code
  113. $where['code'] = $param['code'];
  114. // 查询数据库
  115. $rows = db()->table('设备_报工记录')
  116. ->where($where)
  117. ->order('子订单编号 desc')
  118. ->select();
  119. // 提取 cm1 到 cm10 的数据
  120. $headers = [];
  121. if (!empty($rows)) {
  122. foreach ($rows as $row) {
  123. for ($i = 1; $i <= 10; $i++) {
  124. $cmField = 'cm' . $i;
  125. if (isset($row[$cmField]) && $row[$cmField] !== '') {
  126. // 仅在字段不为空时添加到 headers
  127. $headers[] = $row[$cmField];
  128. }
  129. }
  130. }
  131. // 去重,避免重复值
  132. $headers = array_unique($headers);
  133. sort($headers);
  134. }
  135. $data = [
  136. 'table' => $rows,
  137. 'headers' => $headers,
  138. 'total' => count($rows),
  139. ];
  140. $this->success('成功', $data);
  141. }
  142. /**
  143. * 生产产量进度月报表(Excel)
  144. */
  145. public function getOneWorkOrder() {
  146. if (!$this->request->isGet()) {
  147. $this->error('请求方式错误');
  148. }
  149. $param = $this->request->param();
  150. $currentMonth = date('Y-m', strtotime($param['riqi'])); // 获取前端传来的日期所在月份,格式为 Y-m
  151. $lastMonth = date('Y-m', strtotime($param['riqi'] . ' -1 month')); // 获取前端日期的上个月,格式为 Y-m
  152. // 当前月份的查询条件
  153. $where['c.sczl_rq'] = ['like', '%' . $currentMonth . '%'];
  154. // 查询当前订单的生产总数和整单总数
  155. $totals = db()->table('工单_印件资料')->alias('y')
  156. ->field('y.订单编号, SUM(y.sctotal) as sctotal, SUM(y.zdtotal) as zdtotal')
  157. ->group('y.订单编号')
  158. ->order('y.订单编号')
  159. ->select();
  160. // 保存当前订单的生产总数和整单总数到一个数组,以便后续关联
  161. $totalsMap = [];
  162. foreach ($totals as $total) {
  163. $totalsMap[$total['订单编号']] = [
  164. 'sctotal' => $total['sctotal'],
  165. 'zdtotal' => $total['zdtotal'],
  166. ];
  167. }
  168. // 查询上月累计数据
  169. $wheres['sczl_rq'] = ['like', '%' . $lastMonth . '%'];
  170. $sql = db()->table('设备_产量计酬')
  171. ->field('订单编号, SUM(数量) as 上月累计') // 使用SUM函数统计上月累计数量
  172. ->where($wheres)
  173. ->group('订单编号')
  174. ->select();
  175. // 将上个月的累计数据保存到一个数组
  176. $lastMonthMap = [];
  177. foreach ($sql as $lastRow) {
  178. $lastMonthMap[$lastRow['订单编号']] = $lastRow['上月累计'];
  179. }
  180. // 查询每天的上报数量,并关联生产总数和整单总数
  181. $rows = db()->table('设备_产量计酬')->alias('c')
  182. ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
  183. ->field('
  184. c.订单编号, j.款式, j.生产款号, j.客户编号,
  185. c.sczl_jtbh, c.工序名称 as 工序,c.sczl_bh,
  186. c.数量 as 上报数量,
  187. c.sczl_rq as 上报时间
  188. ')
  189. ->where($where)
  190. ->order('c.sczl_rq desc')
  191. ->select();
  192. // 初始化
  193. $result = [];
  194. // 处理当前月份的数据
  195. foreach ($rows as $row) {
  196. $key = $row['款式'] . '_' . $row['生产款号'] . '_' . $row['订单编号'] . '_' . $row['sczl_jtbh'];
  197. // 获取当前订单编号的生产总数和整单总数
  198. $sctotal = isset($totalsMap[$row['订单编号']]) ? $totalsMap[$row['订单编号']]['sctotal'] : 0;
  199. $zdtotal = isset($totalsMap[$row['订单编号']]) ? $totalsMap[$row['订单编号']]['zdtotal'] : 0;
  200. // 获取上个月的累计数量
  201. $lastMonthTotal = isset($lastMonthMap[$row['订单编号']]) ? $lastMonthMap[$row['订单编号']] : 0;
  202. // 初始化当前订单编号和组别的数据
  203. if (!isset($result[$key])) {
  204. $result[$key] = [
  205. '订单编号' => $row['订单编号'],
  206. '客户编号' => $row['客户编号'],
  207. '机台号' => $row['sczl_jtbh'],
  208. '款式' => $row['款式'],
  209. '款号' => $row['生产款号'],
  210. '工序' => $row['工序'],
  211. '组别' => $row['sczl_bh'],
  212. '制单数' => $zdtotal,
  213. '裁剪数' => $sctotal,
  214. '上个月累计数量' => $lastMonthTotal, // 上个月累计数量
  215. '上报数量' => 0,
  216. ];
  217. // 初始化每一天的数据
  218. for ($day = 1; $day <= 31; $day++) {
  219. $result[$key][$day] = 0;
  220. }
  221. }
  222. // 获取上报的具体日期
  223. $day = (int)date('d', strtotime($row['上报时间']));
  224. // 按天累加上报数量
  225. $result[$key][$day] += (int)$row['上报数量'];
  226. // 累计上报数量
  227. $result[$key]['上报数量'] += (int)$row['上报数量'];
  228. }
  229. // 计算本月累计数据
  230. foreach ($result as &$item) {
  231. $item['本月累计'] = 0;
  232. // 累计本月每天的数据
  233. for ($day = 1; $day <= 31; $day++) {
  234. $item['本月累计'] += $item[$day];
  235. if ($item[$day] === 0) {
  236. $item[$day] = '';
  237. }
  238. }
  239. }
  240. //排序
  241. usort($result, function ($a, $b) {
  242. $clientComparison = strcmp($a['客户编号'], $b['客户编号']);
  243. if ($clientComparison !== 0) {
  244. return $clientComparison;
  245. }
  246. $groupComparison = strcmp($a['组别'], $b['组别']);
  247. if ($groupComparison !== 0) {
  248. return $groupComparison;
  249. }
  250. return strcmp($a['订单编号'], $b['订单编号']);
  251. });
  252. $result = array_values($result);
  253. $this->success('成功', $result);
  254. }
  255. /**
  256. *
  257. */
  258. public function getInfo()
  259. {
  260. }
  261. /**
  262. *
  263. */
  264. public function getOrderInfo(){
  265. }
  266. /**
  267. *
  268. */
  269. public function getYjInfo(){
  270. }
  271. /**
  272. *
  273. */
  274. public function getWastInfo(){
  275. }
  276. /**
  277. *
  278. */
  279. public function getGxAndLeader(){
  280. }
  281. /**
  282. *
  283. */
  284. public function edit(){
  285. }
  286. /**
  287. *
  288. */
  289. public function add(){
  290. }
  291. /**
  292. *
  293. */
  294. public function wasteDistribution(){
  295. }
  296. /**
  297. *
  298. */
  299. public function getOrderDate(){
  300. }
  301. /**
  302. *
  303. */
  304. public function editOrderFinishDate(){
  305. }
  306. /**
  307. *
  308. */
  309. public function getOrderProcessLeft(){
  310. }
  311. /**
  312. *
  313. */
  314. public function getOrderProcessRight(){
  315. }
  316. /**
  317. *
  318. */
  319. public function getDaysWast()
  320. {
  321. }
  322. /**
  323. *
  324. */
  325. public function getMonthPeopleTotal(){
  326. }
  327. /**
  328. *
  329. */
  330. public function getOrderWasteTotal(){
  331. }
  332. /**
  333. *
  334. */
  335. public function del()
  336. {
  337. }
  338. }