|
|
@@ -2836,57 +2836,58 @@ class WorkOrderSpotCheck extends Api{
|
|
|
if (empty($param)){
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
+ foreach ($param as $item){
|
|
|
+ //搜索批次号库存表中中数据
|
|
|
+ $number = \db('物料_库存')
|
|
|
+ ->where('批次号',$item['批次号'])
|
|
|
+ ->where('关联号',$item['关联编号'])
|
|
|
+ ->where('物料编号',$item['物料编码'])
|
|
|
+ ->field('库存数量,退还数量')
|
|
|
+ ->find();
|
|
|
+ if ($item['type'] === '退面料'){
|
|
|
+ //构建库存表数据
|
|
|
+ $InventoryData = [
|
|
|
+ '退还数量' => $number['退还数量'] + (int)$item['number'],
|
|
|
+ '库存数量' => $number['库存数量'] + (int)$item['number'],
|
|
|
+ ];
|
|
|
+ }elseif ($item['type'] === '退厂商'){
|
|
|
+ $InventoryData = [
|
|
|
+ '退还数量' => $number['退还数量'],
|
|
|
+ '库存数量' => $number['库存数量'] - (int)$item['number'],
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ $InventoryData = [
|
|
|
+ '退还数量' => $number['退还数量'],
|
|
|
+ '库存数量' => $number['库存数量'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $ReportData = $item;
|
|
|
+ unset($ReportData['关联编号']);
|
|
|
+ unset($ReportData['实际门幅']);
|
|
|
+ $ReportData['批次号'] = $item['批次号'];
|
|
|
+ $ReportData['rq'] = date('Y-m-d H:i:s',time());
|
|
|
+ $ReportData['库存数量'] = $InventoryData['库存数量'];
|
|
|
+ //创建事务,存储库存表数据和入库报工表数据
|
|
|
+ db()->startTrans();
|
|
|
+ try {
|
|
|
+ //存储库存表数据
|
|
|
+ $InventorySql = \db('物料_库存')
|
|
|
+ ->where('批次号',$item['批次号'])
|
|
|
+ ->where('关联号',$item['关联编号'])
|
|
|
+ ->where('物料编号',$item['物料编码'])
|
|
|
+ ->fetchSql(true)
|
|
|
+ ->update($InventoryData);
|
|
|
+ \db()->query($InventorySql);
|
|
|
+ //存储入库报工表数据
|
|
|
+ $ReportSql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
|
|
|
+ \db()->query($ReportSql);
|
|
|
|
|
|
- //搜索批次号库存表中中数据
|
|
|
- $number = \db('物料_库存')
|
|
|
- ->where('批次号',$param['批次号'])
|
|
|
- ->where('关联号',$param['关联编号'])
|
|
|
- ->where('物料编号',$param['物料编码'])
|
|
|
- ->field('库存数量,退还数量')
|
|
|
- ->find();
|
|
|
- if ($param['type'] === '退面料'){
|
|
|
- //构建库存表数据
|
|
|
- $InventoryData = [
|
|
|
- '退还数量' => $number['退还数量'] + (int)$param['number'],
|
|
|
- '库存数量' => $number['库存数量'] + (int)$param['number'],
|
|
|
- ];
|
|
|
- }elseif ($param['type'] === '退厂商'){
|
|
|
- $InventoryData = [
|
|
|
- '退还数量' => $number['退还数量'],
|
|
|
- '库存数量' => $number['库存数量'] - (int)$param['number'],
|
|
|
- ];
|
|
|
- }else{
|
|
|
- $InventoryData = [
|
|
|
- '退还数量' => $number['退还数量'],
|
|
|
- '库存数量' => $number['库存数量'],
|
|
|
- ];
|
|
|
- }
|
|
|
- $ReportData = $param;
|
|
|
- unset($ReportData['关联编号']);
|
|
|
- unset($ReportData['实际门幅']);
|
|
|
- $ReportData['批次号'] = $param['批次号'];
|
|
|
- $ReportData['rq'] = date('Y-m-d H:i:s',time());
|
|
|
- $ReportData['库存数量'] = $InventoryData['库存数量'];
|
|
|
- //创建事务,存储库存表数据和入库报工表数据
|
|
|
- db()->startTrans();
|
|
|
- try {
|
|
|
- //存储库存表数据
|
|
|
- $InventorySql = \db('物料_库存')
|
|
|
- ->where('批次号',$param['批次号'])
|
|
|
- ->where('关联号',$param['关联编号'])
|
|
|
- ->where('物料编号',$param['物料编码'])
|
|
|
- ->fetchSql(true)
|
|
|
- ->update($InventoryData);
|
|
|
- \db()->query($InventorySql);
|
|
|
- //存储入库报工表数据
|
|
|
- $ReportSql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
|
|
|
- \db()->query($ReportSql);
|
|
|
-
|
|
|
- //提交事务
|
|
|
- \db()->commit();
|
|
|
- }catch (\Exception $e){
|
|
|
- \db()->rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
+ //提交事务
|
|
|
+ \db()->commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ \db()->rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
$this->success('成功');
|
|
|
}
|