WorkOrderVerification.php 11 KB

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