WorkOrderVerification.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. * 生产产量进度月报表(Excel)
  74. */
  75. public function getOneWorkOrder() {
  76. if (!$this->request->isGet()) {
  77. $this->error('请求方式错误');
  78. }
  79. $param = $this->request->param();
  80. // 查询当前订单的生产总数和整单总数
  81. $totals = db()->table('工单_印件资料')->alias('y')
  82. ->field('y.订单编号, SUM(y.sctotal) as sctotal, SUM(y.zdtotal) as zdtotal')
  83. ->group('y.订单编号')
  84. ->whereNull('y.Mod_rq')
  85. ->order('y.订单编号')
  86. ->select();
  87. // 保存当前订单的生产总数和整单总数到一个数组,以便后续关联
  88. $totalsMap = [];
  89. foreach ($totals as $total) {
  90. $totalsMap[$total['订单编号']] = [
  91. 'sctotal' => $total['sctotal'],
  92. 'zdtotal' => $total['zdtotal'],
  93. ];
  94. }
  95. // 获取上个月的日期,格式为 Y-m
  96. $lastMonth = date('Y-m', strtotime($param['riqi'] . ' -1 month'));
  97. // 构造查询条件
  98. $wheres['sczl_rq'] = ['like', '%' . $lastMonth . '%']; // 查询上个月的数据
  99. $wheres['sczl_bh'] = ['neq', '']; // 根据需要加上你想要的工序条件(假设 sczl_bh 是工序字段)
  100. $sql = db()->table('设备_产量计酬')
  101. ->field('订单编号, sczl_jtbh, sczl_bh,
  102. CASE
  103. WHEN 工序名称 IN ("裁剪", "车缝") THEN SUM(数量)
  104. ELSE SUM(s_num)
  105. END as 上月累计') // 加上工序字段
  106. ->where($wheres)
  107. ->whereNull('mod_rq') // 确保 mod_rq 字段为空
  108. ->group('订单编号, sczl_jtbh, sczl_bh') // 按 订单编号, sczl_jtbh, sczl_bh 分组
  109. ->select();
  110. // 将上个月的累计数据保存到一个数组,确保按订单编号和机台号保存
  111. $lastMonthMap = [];
  112. foreach ($sql as $lastRow) {
  113. $lastMonthMap[$lastRow['订单编号']][$lastRow['sczl_jtbh']] = (int)$lastRow['上月累计'];
  114. }
  115. $currentMonth = date('Y-m', strtotime($param['riqi'])); // 获取前端传来的日期所在月份,格式为 Y-m
  116. $lastMonth = date('Y-m', strtotime($param['riqi'] . ' -1 month')); // 获取前端日期的上个月,格式为 Y-m
  117. // 当前月份的查询条件
  118. $where['c.sczl_rq'] = ['like', '%' . $currentMonth . '%'];
  119. // 查询每天的上报数量,并关联生产总数和整单总数
  120. $rows = db()->table('设备_产量计酬')->alias('c')
  121. ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
  122. ->field('
  123. c.订单编号, j.款式, j.生产款号, j.客户编号,
  124. c.sczl_jtbh, c.工序名称 as 工序, c.sczl_bh,
  125. CASE
  126. WHEN c.工序名称 IN ("裁剪", "车缝") THEN c.数量
  127. ELSE c.s_num
  128. END as 上报数量,
  129. c.sczl_rq as 上报时间
  130. ')
  131. ->where($where)
  132. ->whereNull('c.mod_rq')
  133. ->order('c.sczl_rq desc')
  134. ->select();
  135. // 初始化
  136. $result = [];
  137. // 处理当前月份的数据
  138. foreach ($rows as $row) {
  139. $key = $row['款式'] . '_' . $row['生产款号'] . '_' . $row['订单编号'] . '_' . $row['sczl_jtbh'];
  140. // 获取当前订单编号的生产总数和整单总数
  141. $sctotal = isset($totalsMap[$row['订单编号']]) ? $totalsMap[$row['订单编号']]['sctotal'] : 0;
  142. $zdtotal = isset($totalsMap[$row['订单编号']]) ? $totalsMap[$row['订单编号']]['zdtotal'] : 0;
  143. // 获取上个月的累计数量,按机台号获取
  144. $lastMonthTotal = isset($lastMonthMap[$row['订单编号']][$row['sczl_jtbh']]) ? $lastMonthMap[$row['订单编号']][$row['sczl_jtbh']] : 0;
  145. // 初始化当前订单编号和组别的数据
  146. if (!isset($result[$key])) {
  147. $result[$key] = [
  148. '订单编号' => $row['订单编号'],
  149. '客户编号' => $row['客户编号'],
  150. '机台号' => $row['sczl_jtbh'],
  151. '款式' => $row['款式'],
  152. '款号' => $row['生产款号'],
  153. '工序' => $row['工序'],
  154. '组别' => $row['sczl_bh'],
  155. '制单数' => $zdtotal,
  156. '裁剪数' => $sctotal,
  157. '上月累计' => $lastMonthTotal,
  158. '上报数量' => 0,
  159. ];
  160. // 初始化每一天的数据
  161. for ($day = 1; $day <= 31; $day++) {
  162. $result[$key][$day] = 0;
  163. }
  164. }
  165. // 获取上报的具体日期
  166. $day = (int)date('d', strtotime($row['上报时间']));
  167. // 按天累加上报数量
  168. $result[$key][$day] += (int)$row['上报数量'];
  169. // 累计上报数量
  170. $result[$key]['上报数量'] += (int)$row['上报数量'];
  171. }
  172. // 计算本月累计数据
  173. foreach ($result as &$item) {
  174. $item['本月累计'] = 0;
  175. // 累计本月每天的数据
  176. for ($day = 1; $day <= 31; $day++) {
  177. $item['本月累计'] += $item[$day];
  178. if ($item[$day] === 0) {
  179. $item[$day] = '';
  180. }
  181. }
  182. }
  183. // 排序
  184. usort($result, function ($a, $b) {
  185. // 先按客户编号排序
  186. $clientComparison = strcmp($a['客户编号'], $b['客户编号']);
  187. if ($clientComparison !== 0) {
  188. return $clientComparison;
  189. }
  190. // 再按组别排序
  191. $groupComparison = strcmp($a['组别'], $b['组别']);
  192. if ($groupComparison !== 0) {
  193. return $groupComparison;
  194. }
  195. // 最后按订单编号排序
  196. return strcmp($a['订单编号'], $b['订单编号']);
  197. });
  198. $result = array_values($result);
  199. $this->success('成功', $result);
  200. }
  201. /**
  202. *
  203. */
  204. public function getInfo()
  205. {
  206. }
  207. /**
  208. *
  209. */
  210. public function getOrderInfo(){
  211. }
  212. /**
  213. *
  214. */
  215. public function getYjInfo(){
  216. }
  217. /**
  218. *
  219. */
  220. public function getWastInfo(){
  221. }
  222. /**
  223. *
  224. */
  225. public function getGxAndLeader(){
  226. }
  227. /**
  228. *
  229. */
  230. public function edit(){
  231. }
  232. /**
  233. *
  234. */
  235. public function add(){
  236. }
  237. /**
  238. *
  239. */
  240. public function wasteDistribution(){
  241. }
  242. /**
  243. *
  244. */
  245. public function getOrderDate(){
  246. }
  247. /**
  248. *
  249. */
  250. public function editOrderFinishDate(){
  251. }
  252. /**
  253. *
  254. */
  255. public function getOrderProcessLeft(){
  256. }
  257. /**
  258. *
  259. */
  260. public function getOrderProcessRight(){
  261. }
  262. /**
  263. *
  264. */
  265. public function getDaysWast()
  266. {
  267. }
  268. /**
  269. *
  270. */
  271. public function getMonthPeopleTotal(){
  272. }
  273. /**
  274. *
  275. */
  276. public function getOrderWasteTotal(){
  277. }
  278. /**
  279. *
  280. */
  281. public function del()
  282. {
  283. }
  284. }