WorkOrderVerification.php 12 KB

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