|
@@ -1129,22 +1129,80 @@ class Product extends Api
|
|
|
*/
|
|
*/
|
|
|
public function ProcessDetailDel()
|
|
public function ProcessDetailDel()
|
|
|
{
|
|
{
|
|
|
- if ($this->request->isGet() === false) {
|
|
|
|
|
- $this->error('请求错误');
|
|
|
|
|
|
|
+ // 1. 请求方法检查 - 删除操作建议使用POST方法
|
|
|
|
|
+ if (!$this->request->isGet()) {
|
|
|
|
|
+ $this->error('请求方法错误');
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 参数获取与验证
|
|
|
$param = $this->request->param();
|
|
$param = $this->request->param();
|
|
|
- if (isset($param['UniqId']) === false) {
|
|
|
|
|
- $this->error('参数错误');
|
|
|
|
|
|
|
+ if (empty($param['UniqId'])) {
|
|
|
|
|
+ $this->error('参数错误: 缺少UniqId参数');
|
|
|
}
|
|
}
|
|
|
- $printId = explode(',', $param['UniqId']);
|
|
|
|
|
- $res = \db('产品_工艺资料')->where('UniqID','in',$printId)->delete();
|
|
|
|
|
- if ($res){
|
|
|
|
|
- $this->success('删除成功');
|
|
|
|
|
- }else{
|
|
|
|
|
- $this->error('删除失败');
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 参数处理
|
|
|
|
|
+ $uniqIds = explode(',', $param['UniqId']);
|
|
|
|
|
+ $uniqIds = array_filter(array_map('trim', $uniqIds)); // 过滤空值并去除空格
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($uniqIds)) {
|
|
|
|
|
+ $this->error('参数错误: UniqId不能为空');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 获取当前用户ID
|
|
|
|
|
+ $userId = $param['sys_id'] ?? '';
|
|
|
|
|
+ if (empty($userId)) {
|
|
|
|
|
+ $this->error('参数错误: 缺少用户标识');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 查询要删除的工艺详情
|
|
|
|
|
+ $processDetails = Db::name('产品_工艺资料')
|
|
|
|
|
+ ->where('UniqID', 'in', $uniqIds)
|
|
|
|
|
+ ->field('UniqID, Gy0_cpdh, Gy0_yjno, Gy0_gxh')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($processDetails)) {
|
|
|
|
|
+ $this->error('未找到要删除的工艺详情');
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
+ // 6. 准备日志记录
|
|
|
|
|
+ $logArray = [];
|
|
|
|
|
+ $currentTime = date('Y-m-d H:i:s');
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($processDetails as $item) {
|
|
|
|
|
+ $logArray[] = [
|
|
|
|
|
+ 'Gd_gdbh' => $item['Gy0_cpdh'] ?? '',
|
|
|
|
|
+ 'yjno' => $item['Gy0_yjno'] ?? '',
|
|
|
|
|
+ 'gxh' => $item['Gy0_gxh'] ?? '',
|
|
|
|
|
+ 'ModifyUser' => $userId,
|
|
|
|
|
+ 'ModifyTime' => $currentTime,
|
|
|
|
|
+ 'FieldName' => '产品工艺删除',
|
|
|
|
|
+ 'OldValue' => '存在', // 记录删除前的状态
|
|
|
|
|
+ 'NewValue' => '已删除',
|
|
|
|
|
+ 'ModifySource' => '产品工艺删除'
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 7. 执行删除操作
|
|
|
|
|
+ $deleteResult = Db::name('产品_工艺资料')
|
|
|
|
|
+ ->where('UniqID', 'in', $uniqIds)
|
|
|
|
|
+ ->delete();
|
|
|
|
|
+
|
|
|
|
|
+ if ($deleteResult === false) {
|
|
|
|
|
+ $this->error('删除工艺详情失败');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 8. 记录操作日志(即使日志记录失败,也不影响主操作)
|
|
|
|
|
+ if (!empty($logArray)) {
|
|
|
|
|
+ $logResult = Db::name('系统操作日志表')->insertAll($logArray);
|
|
|
|
|
+ if ($logResult === false) {
|
|
|
|
|
+ // 记录日志失败,但不影响主操作
|
|
|
|
|
+ \think\Log::write('记录操作日志失败: ' . Db::name('系统操作日志表')->getLastSql());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 9. 返回成功
|
|
|
|
|
+ $this->success('成功删除 ' . $deleteResult . ' 条工艺详情');
|
|
|
|
|
+ }
|
|
|
/**
|
|
/**
|
|
|
* 产品印件资料删除
|
|
* 产品印件资料删除
|
|
|
* @return void
|
|
* @return void
|
|
@@ -1247,26 +1305,105 @@ class Product extends Api
|
|
|
* @ApiMethod POST
|
|
* @ApiMethod POST
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
|
- public function productEdit(){
|
|
|
|
|
- if (Request::instance()->isPost() == false){
|
|
|
|
|
|
|
+ public function productEdit()
|
|
|
|
|
+ {
|
|
|
|
|
+ // 1. 请求方法检查
|
|
|
|
|
+ if (!Request::instance()->isPost()) {
|
|
|
$this->error('非法请求');
|
|
$this->error('非法请求');
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 参数获取与验证
|
|
|
$params = Request::instance()->post();
|
|
$params = Request::instance()->post();
|
|
|
- if (empty($params)){
|
|
|
|
|
|
|
+ if (empty($params)) {
|
|
|
$this->error('参数不能为空');
|
|
$this->error('参数不能为空');
|
|
|
}
|
|
}
|
|
|
- $UniqId = $params['UniqID'];
|
|
|
|
|
- unset($params['UniqID']);
|
|
|
|
|
- $params['Mod_rq'] = date('Y-m-d H:i:s');
|
|
|
|
|
- $sql = \db('产品_工艺资料')->where('UniqID',$UniqId)->fetchSql(true)->update($params);
|
|
|
|
|
- $res = Db::query($sql);
|
|
|
|
|
- if ($res !== false){
|
|
|
|
|
- $this->success('修改成功');
|
|
|
|
|
- }else{
|
|
|
|
|
- $this->error('修改失败');
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 必需参数验证
|
|
|
|
|
+ if (empty($params['UniqID'])) {
|
|
|
|
|
+ $this->error('产品唯一标识不能为空');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $uniqId = trim($params['UniqID']);
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 查询原始数据
|
|
|
|
|
+ $processDetail = Db::name('产品_工艺资料')
|
|
|
|
|
+ ->where('UniqID', $uniqId)
|
|
|
|
|
+ ->find();
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($processDetail)) {
|
|
|
|
|
+ $this->error('找不到对应的产品工艺资料');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 准备更新数据
|
|
|
|
|
+ $updateData = [];
|
|
|
|
|
+ $logArray = [];
|
|
|
|
|
+ $currentTime = date('Y-m-d H:i:s');
|
|
|
|
|
+ $modifyUser = $params['Sys_id'] ?? '';
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 构建更新数据和日志记录
|
|
|
|
|
+ foreach ($params as $key => $value) {
|
|
|
|
|
+ // 跳过不需要更新的字段
|
|
|
|
|
+ if (in_array($key, ['UniqID', 'Sys_id'])) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 只处理表中存在的字段
|
|
|
|
|
+ if (array_key_exists($key, $processDetail)) {
|
|
|
|
|
+ $oldValue = $processDetail[$key] ?? '';
|
|
|
|
|
+ $newValue = trim($value);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查值是否发生变化
|
|
|
|
|
+ if ($oldValue != $newValue) {
|
|
|
|
|
+ $updateData[$key] = $newValue;
|
|
|
|
|
+
|
|
|
|
|
+ $logArray[] = [
|
|
|
|
|
+ 'Gd_gdbh' => $processDetail['Gy0_cpdh'] ?? '',
|
|
|
|
|
+ 'yjno' => $processDetail['Gy0_yjno'] ?? '',
|
|
|
|
|
+ 'gxh' => $processDetail['Gy0_gxh'] ?? '',
|
|
|
|
|
+ 'ModifyUser' => $modifyUser,
|
|
|
|
|
+ 'ModifyTime' => $currentTime,
|
|
|
|
|
+ 'FieldName' => $key,
|
|
|
|
|
+ 'OldValue' => $oldValue,
|
|
|
|
|
+ 'NewValue' => $newValue,
|
|
|
|
|
+ 'ModifySource' => '产品工艺调整'
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 7. 如果没有需要更新的字段
|
|
|
|
|
+ if (empty($updateData)) {
|
|
|
|
|
+ $this->success('没有检测到数据变化');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 8. 添加更新时间
|
|
|
|
|
+ $updateData['Mod_rq'] = $currentTime;
|
|
|
|
|
+
|
|
|
|
|
+ // 9. 更新产品工艺资料
|
|
|
|
|
+ $updateResult = Db::name('产品_工艺资料')
|
|
|
|
|
+ ->where('UniqID', $uniqId)
|
|
|
|
|
+ ->update($updateData);
|
|
|
|
|
+
|
|
|
|
|
+ // 10. 检查更新结果
|
|
|
|
|
+ // ThinkPHP的update方法成功时返回影响的行数(>=0),失败返回false
|
|
|
|
|
+ if ($updateResult === false) {
|
|
|
|
|
+ $this->error('更新产品工艺资料失败');
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
+ // 11. 记录操作日志(即使日志记录失败,也不影响主操作)
|
|
|
|
|
+ if (!empty($logArray)) {
|
|
|
|
|
+ $logResult = Db::name('系统操作日志表')
|
|
|
|
|
+ ->insertAll($logArray);
|
|
|
|
|
+
|
|
|
|
|
+ if ($logResult === false) {
|
|
|
|
|
+ // 记录日志失败,但不影响主操作
|
|
|
|
|
+ \think\Log::write('记录操作日志失败: ' . Db::name('系统操作日志表')->getLastSql());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 12. 返回成功
|
|
|
|
|
+ $this->success('修改成功');
|
|
|
|
|
+ }
|
|
|
/**
|
|
/**
|
|
|
* 获取联数
|
|
* 获取联数
|
|
|
* @return void
|
|
* @return void
|
|
@@ -1346,7 +1483,4 @@ class Product extends Api
|
|
|
}
|
|
}
|
|
|
$this->success('成功');
|
|
$this->success('成功');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|