| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use Monolog\Handler\IFTTTHandler;
- use Overtrue\Socialite\Providers\WeWorkProvider;
- use think\Db;
- use think\Request;
- use function fast\e;
- /**
- *
- * 生产单衣进度管理
- */
- class MonthlyGarments extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 样衣进度左侧数据
- */
- public function getDateTree()
- {
- if (!$this->request->isGet()) {
- $this->error('请求错误');
- }
- $results = \db('月度样衣进度')
- ->field([
- 'DATE_FORMAT(Sys_rq, "%Y-%m")' => '年月',
- '客户编号',
- 'COUNT(*) as total'
- ])
- ->whereNull('Mod_rq')
- ->group('年月, 客户编号')
- ->order('年月 DESC')
- ->select();
- $formattedData = [];
- foreach ($results as $row) {
- $yearMonth = $row['年月'];
- $customerCode = $row['客户编号'];
- $total = $row['total'];
- if (!isset($formattedData[$yearMonth])) {
- $formattedData[$yearMonth] = [];
- }
- $formattedData[$yearMonth][] = [
- '客户编号' => $customerCode,
- 'total' => $total
- ];
- }
- krsort($formattedData);
- $this->success('成功', $formattedData);
- }
- /**
- * 样衣进度列表数据
- */
- public function getMonthlyGarmentsList()
- {
- if (!$this->request->isGet()) {
- $this->error('请求错误');
- }
- $yearMonth = $this->request->param('sys_rq', '');
- $customerCode = $this->request->param('customer', '');
- $search = $this->request->param('search', '');
- $query = \db('月度样衣进度')
- ->whereNull('Mod_rq');
- if ($yearMonth) {
- $query->where('DATE_FORMAT(Sys_rq, "%Y-%m")', $yearMonth);
- }
- if ($customerCode === '__EMPTY__') {
- $query->where(function ($q) {
- $q->whereNull('客户编号')->whereOr('客户编号', '');
- });
- } elseif ($customerCode) {
- $query->where('客户编号', $customerCode);
- }
- if ($search) {
- $query->where(function ($q) use ($search) {
- $q->where('客户编号', 'like', "%{$search}%")
- ->whereOr('款号', 'like', "%{$search}%")
- ->whereOr('款式', 'like', "%{$search}%");
- });
- }
- $results = $query->order('UniqId DESC')->select();
- $this->success('成功', [
- 'result' => $results,
- 'total' => count($results)
- ]);
- }
- /**
- * 样衣进度新增数据
- */
- public function saveMonthlyGarments()
- {
- if (!$this->request->isPost()) {
- $this->error('请求错误');
- }
- $data = $this->request->post();
- $customerCode = $data['客户编号'] ?? '';
- $styleNo = $data['款号'] ?? '';
- $style = $data['款式'] ?? '';
- $sampleType = $data['样办种类'] ?? '';
- $department = $data['做办部门'] ?? '';
- $quantity = isset($data['数量']) && $data['数量'] !== '' ? (int)$data['数量'] : 0;
- $orderDate = (!empty($data['下单日期'])) ? "'{$data['下单日期']}'" : 'NULL';
- $fabricProgress = $data['面料进度'] ?? '';
- $auxiliaryProgress = $data['辅料进度'] ?? '';
- $planDeliveryDate = (!empty($data['计划交办日期'])) ? "'{$data['计划交办日期']}'" : 'NULL';
- $actualDeliveryDate = (!empty($data['实际交办日期'])) ? "'{$data['实际交办日期']}'" : 'NULL';
- $remark = $data['备注'] ?? '';
- $sysId = $data['Sys_id'] ?? '';
- $sysRq = date('Y-m-d H:i:s');
- $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)";
-
- $result = \db()->execute($sql);
- if ($result !== false) {
- $lastId = \db('月度样衣进度')->getLastInsID();
- $this->success('保存成功', ['id' => $lastId]);
- } else {
- $this->error('保存失败');
- }
- }
- /**
- * 样衣进度修改数据
- */
- public function updateMonthlyGarments()
- {
- if (!$this->request->isPost()) {
- $this->error('请求错误');
- }
- $data = $this->request->post();
- $uniqId = $data['UniqId'] ?? '';
- $nickName = $data['nickName'] ?? '';
- if (!$uniqId) {
- $this->error('UniqId不能为空');
- }
- $oldData = \db('月度样衣进度')->where('UniqId', $uniqId)->find();
- $customerCode = $data['客户编号'] ?? '';
- $styleNo = $data['款号'] ?? '';
- $style = $data['款式'] ?? '';
- $sampleType = $data['样办种类'] ?? '';
- $department = $data['做办部门'] ?? '';
- $quantity = isset($data['数量']) && $data['数量'] !== '' ? (int)$data['数量'] : 0;
- $orderDate = (!empty($data['下单日期'])) ? "'{$data['下单日期']}'" : 'NULL';
- $fabricProgress = $data['面料进度'] ?? '';
- $auxiliaryProgress = $data['辅料进度'] ?? '';
- $planDeliveryDate = (!empty($data['计划交办日期'])) ? "'{$data['计划交办日期']}'" : 'NULL';
- $actualDeliveryDate = (!empty($data['实际交办日期'])) ? "'{$data['实际交办日期']}'" : 'NULL';
- $remark = $data['备注'] ?? '';
- $sysRq = date('Y-m-d H:i:s');
- $sql = "UPDATE `月度样衣进度` SET `客户编号`='{$customerCode}', `款号`='{$styleNo}', `款式`='{$style}', `样办种类`='{$sampleType}', `做办部门`='{$department}', `数量`={$quantity}, `下单日期`={$orderDate}, `面料进度`='{$fabricProgress}', `辅料进度`='{$auxiliaryProgress}', `计划交办日期`={$planDeliveryDate}, `实际交办日期`={$actualDeliveryDate}, `备注`='{$remark}', `Sys_rq`='{$sysRq}' WHERE `UniqId`='{$uniqId}'";
- $result = \db()->query($sql);
- if ($result !== false) {
- $this->saveLogs($uniqId, $oldData, $data, $nickName);
- $this->success('修改成功');
- } else {
- $this->error('修改失败');
- }
- }
-
- public function deleteMonthlyGarments()
- {
- if (!$this->request->isPost()) {
- $this->error('请求错误');
- }
- $data = $this->request->post();
- $uniqId = $data['UniqId'] ?? '';
- $nickName = $data['nickName'] ?? '';
- if (!$uniqId) {
- $this->error('UniqId不能为空');
- }
- $modRq = date('Y-m-d H:i:s');
- $sql = "UPDATE `月度样衣进度` SET `Mod_rq`='{$modRq}' WHERE `UniqId`='{$uniqId}'";
- $result = \db()->query($sql);
- if ($result !== false) {
- $this->success('删除成功');
- } else {
- $this->error('删除失败');
- }
- }
- /**
- * 样衣进度存储日志数据
- */
- private function saveLogs($uniqId, $oldData, $newData, $operator)
- {
- $fields = ['客户编号', '款号', '款式', '样办种类', '做办部门', '数量', '下单日期', '面料进度', '辅料进度', '计划交办日期', '实际交办日期', '备注'];
- $modifyTime = date('Y-m-d H:i:s');
- foreach ($fields as $field) {
- $oldValue = $oldData[$field] ?? '';
- $newValue = $newData[$field] ?? '';
- if ((string)$oldValue !== (string)$newValue) {
- $sql = "INSERT INTO `样衣进度日志` (`Uniqid`, `ModifyField`, `OriginalValue`, `Modified`, `修改人`, `修改日期`) VALUES ('{$uniqId}', '{$field}', '{$oldValue}', '{$newValue}', '{$operator}', '{$modifyTime}')";
- \db()->query($sql);
- }
- }
- }
- /**
- * 样衣进度日志数据
- */
- public function getLogs()
- {
- if (!$this->request->isGet()) {
- $this->error('请求错误');
- }
- $uniqId = $this->request->get('UniqId') ?? '';
- if (!$uniqId) {
- $this->error('UniqId不能为空');
- }
- $logs = \db('样衣进度日志')
- ->where('Uniqid', $uniqId)
- ->order('修改日期', 'desc')
- ->select();
- $this->success('获取成功', ['result' => $logs, 'total' => count($logs)]);
- }
- }
|