MonthlyGarments.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Monolog\Handler\IFTTTHandler;
  5. use Overtrue\Socialite\Providers\WeWorkProvider;
  6. use think\Db;
  7. use think\Request;
  8. use function fast\e;
  9. /**
  10. *
  11. * 生产单衣进度管理
  12. */
  13. class MonthlyGarments extends Api
  14. {
  15. protected $noNeedLogin = ['*'];
  16. protected $noNeedRight = ['*'];
  17. /**
  18. * 样衣进度左侧数据
  19. */
  20. public function getDateTree()
  21. {
  22. if (!$this->request->isGet()) {
  23. $this->error('请求错误');
  24. }
  25. $results = \db('月度样衣进度')
  26. ->field([
  27. 'DATE_FORMAT(Sys_rq, "%Y-%m")' => '年月',
  28. '客户编号',
  29. 'COUNT(*) as total'
  30. ])
  31. ->whereNull('Mod_rq')
  32. ->group('年月, 客户编号')
  33. ->order('年月 DESC')
  34. ->select();
  35. $formattedData = [];
  36. foreach ($results as $row) {
  37. $yearMonth = $row['年月'];
  38. $customerCode = $row['客户编号'];
  39. $total = $row['total'];
  40. if (!isset($formattedData[$yearMonth])) {
  41. $formattedData[$yearMonth] = [];
  42. }
  43. $formattedData[$yearMonth][] = [
  44. '客户编号' => $customerCode,
  45. 'total' => $total
  46. ];
  47. }
  48. krsort($formattedData);
  49. $this->success('成功', $formattedData);
  50. }
  51. /**
  52. * 样衣进度列表数据
  53. */
  54. public function getMonthlyGarmentsList()
  55. {
  56. if (!$this->request->isGet()) {
  57. $this->error('请求错误');
  58. }
  59. $yearMonth = $this->request->param('sys_rq', '');
  60. $customerCode = $this->request->param('customer', '');
  61. $search = $this->request->param('search', '');
  62. $query = \db('月度样衣进度')
  63. ->whereNull('Mod_rq');
  64. if ($yearMonth) {
  65. $query->where('DATE_FORMAT(Sys_rq, "%Y-%m")', $yearMonth);
  66. }
  67. if ($customerCode) {
  68. $query->where('客户编号', $customerCode);
  69. }
  70. if ($search) {
  71. $query->where(function ($q) use ($search) {
  72. $q->where('客户编号', 'like', "%{$search}%")
  73. ->whereOr('款号', 'like', "%{$search}%")
  74. ->whereOr('款式', 'like', "%{$search}%");
  75. });
  76. }
  77. $results = $query->order('Sys_rq DESC')->select();
  78. $this->success('成功', [
  79. 'result' => $results,
  80. 'total' => count($results)
  81. ]);
  82. }
  83. /**
  84. * 样衣进度新增数据
  85. */
  86. public function saveMonthlyGarments()
  87. {
  88. if (!$this->request->isPost()) {
  89. $this->error('请求错误');
  90. }
  91. $data = $this->request->post();
  92. $customerCode = $data['客户编号'] ?? '';
  93. $styleNo = $data['款号'] ?? '';
  94. $style = $data['款式'] ?? '';
  95. $sampleType = $data['样办种类'] ?? '';
  96. $department = $data['做办部门'] ?? '';
  97. $quantity = isset($data['数量']) && $data['数量'] !== '' ? (int)$data['数量'] : 0;
  98. $orderDate = (!empty($data['下单日期'])) ? "'{$data['下单日期']}'" : 'NULL';
  99. $fabricProgress = $data['面料进度'] ?? '';
  100. $auxiliaryProgress = $data['辅料进度'] ?? '';
  101. $planDeliveryDate = (!empty($data['计划交办日期'])) ? "'{$data['计划交办日期']}'" : 'NULL';
  102. $actualDeliveryDate = (!empty($data['实际交办日期'])) ? "'{$data['实际交办日期']}'" : 'NULL';
  103. $remark = $data['备注'] ?? '';
  104. $sysId = $data['Sys_id'] ?? '';
  105. $sysRq = date('Y-m-d H:i:s');
  106. $sql = "INSERT INTO `月度样衣进度` (`客户编号`, `款号`, `款式`, `样办种类`, `做办部门`, `数量`, `下单日期`, `面料进度`, `辅料进度`, `计划交办日期`, `实际交办日期`, `备注`, `Sys_id`, `Sys_rq`, `Mod_rq`) VALUES ('{$customerCode}', '{$styleNo}', '{$style}', '{$sampleType}', '{$department}', {$quantity}, {$orderDate}, '{$fabricProgress}', '{$auxiliaryProgress}', {$planDeliveryDate}, {$actualDeliveryDate}, '{$remark}', '{$sysId}', '{$sysRq}', NULL)";
  107. $result = \db()->execute($sql);
  108. if ($result !== false) {
  109. $lastId = \db('月度样衣进度')->getLastInsID();
  110. $this->success('保存成功', ['id' => $lastId]);
  111. } else {
  112. $this->error('保存失败');
  113. }
  114. }
  115. /**
  116. * 样衣进度修改数据
  117. */
  118. public function updateMonthlyGarments()
  119. {
  120. if (!$this->request->isPost()) {
  121. $this->error('请求错误');
  122. }
  123. $data = $this->request->post();
  124. $uniqId = $data['UniqId'] ?? '';
  125. $nickName = $data['nickName'] ?? '';
  126. if (!$uniqId) {
  127. $this->error('UniqId不能为空');
  128. }
  129. $oldData = \db('月度样衣进度')->where('UniqId', $uniqId)->find();
  130. $customerCode = $data['客户编号'] ?? '';
  131. $styleNo = $data['款号'] ?? '';
  132. $style = $data['款式'] ?? '';
  133. $sampleType = $data['样办种类'] ?? '';
  134. $department = $data['做办部门'] ?? '';
  135. $quantity = isset($data['数量']) && $data['数量'] !== '' ? (int)$data['数量'] : 0;
  136. $orderDate = (!empty($data['下单日期'])) ? "'{$data['下单日期']}'" : 'NULL';
  137. $fabricProgress = $data['面料进度'] ?? '';
  138. $auxiliaryProgress = $data['辅料进度'] ?? '';
  139. $planDeliveryDate = (!empty($data['计划交办日期'])) ? "'{$data['计划交办日期']}'" : 'NULL';
  140. $actualDeliveryDate = (!empty($data['实际交办日期'])) ? "'{$data['实际交办日期']}'" : 'NULL';
  141. $remark = $data['备注'] ?? '';
  142. $sysRq = date('Y-m-d H:i:s');
  143. $sql = "UPDATE `月度样衣进度` SET `客户编号`='{$customerCode}', `款号`='{$styleNo}', `款式`='{$style}', `样办种类`='{$sampleType}', `做办部门`='{$department}', `数量`={$quantity}, `下单日期`={$orderDate}, `面料进度`='{$fabricProgress}', `辅料进度`='{$auxiliaryProgress}', `计划交办日期`={$planDeliveryDate}, `实际交办日期`={$actualDeliveryDate}, `备注`='{$remark}', `Sys_rq`='{$sysRq}' WHERE `UniqId`='{$uniqId}'";
  144. $result = \db()->query($sql);
  145. if ($result !== false) {
  146. $this->saveLogs($uniqId, $oldData, $data, $nickName);
  147. $this->success('修改成功');
  148. } else {
  149. $this->error('修改失败');
  150. }
  151. }
  152. public function deleteMonthlyGarments()
  153. {
  154. if (!$this->request->isPost()) {
  155. $this->error('请求错误');
  156. }
  157. $data = $this->request->post();
  158. $uniqId = $data['UniqId'] ?? '';
  159. $nickName = $data['nickName'] ?? '';
  160. if (!$uniqId) {
  161. $this->error('UniqId不能为空');
  162. }
  163. $modRq = date('Y-m-d H:i:s');
  164. $sql = "UPDATE `月度样衣进度` SET `Mod_rq`='{$modRq}' WHERE `UniqId`='{$uniqId}'";
  165. $result = \db()->query($sql);
  166. if ($result !== false) {
  167. $this->success('删除成功');
  168. } else {
  169. $this->error('删除失败');
  170. }
  171. }
  172. /**
  173. * 样衣进度存储日志数据
  174. */
  175. private function saveLogs($uniqId, $oldData, $newData, $operator)
  176. {
  177. $fields = ['客户编号', '款号', '款式', '样办种类', '做办部门', '数量', '下单日期', '面料进度', '辅料进度', '计划交办日期', '实际交办日期', '备注'];
  178. $modifyTime = date('Y-m-d H:i:s');
  179. foreach ($fields as $field) {
  180. $oldValue = $oldData[$field] ?? '';
  181. $newValue = $newData[$field] ?? '';
  182. if ((string)$oldValue !== (string)$newValue) {
  183. $sql = "INSERT INTO `样衣进度日志` (`Uniqid`, `ModifyField`, `OriginalValue`, `Modified`, `修改人`, `修改日期`) VALUES ('{$uniqId}', '{$field}', '{$oldValue}', '{$newValue}', '{$operator}', '{$modifyTime}')";
  184. \db()->query($sql);
  185. }
  186. }
  187. }
  188. /**
  189. * 样衣进度日志数据
  190. */
  191. public function getLogs()
  192. {
  193. if (!$this->request->isGet()) {
  194. $this->error('请求错误');
  195. }
  196. $uniqId = $this->request->get('UniqId') ?? '';
  197. if (!$uniqId) {
  198. $this->error('UniqId不能为空');
  199. }
  200. $logs = \db('样衣进度日志')
  201. ->where('Uniqid', $uniqId)
  202. ->order('修改日期', 'desc')
  203. ->select();
  204. $this->success('获取成功', ['result' => $logs, 'total' => count($logs)]);
  205. }
  206. }