|
@@ -27,7 +27,7 @@ class ReorderChild extends Base
|
|
if ($val->check($param) == false) return json_show(1004, $val->getError());
|
|
if ($val->check($param) == false) return json_show(1004, $val->getError());
|
|
|
|
|
|
$saleReturn = Db::name('sale_return')
|
|
$saleReturn = Db::name('sale_return')
|
|
- ->field('id,orderCode,status,companyNo,companyName,customer_code,customer_name,num')
|
|
|
|
|
|
+ ->field('id,orderCode,status,companyNo,companyName,customer_code,customer_name,num,apply_id')
|
|
->where(['is_del' => 0, 'returnCode' => $param['returnCode']])
|
|
->where(['is_del' => 0, 'returnCode' => $param['returnCode']])
|
|
->findOrEmpty();
|
|
->findOrEmpty();
|
|
if (empty($saleReturn)) return json_show(1004, '该退货单不存在');
|
|
if (empty($saleReturn)) return json_show(1004, '该退货单不存在');
|
|
@@ -77,19 +77,19 @@ class ReorderChild extends Base
|
|
}
|
|
}
|
|
|
|
|
|
//生成售前退货工单
|
|
//生成售前退货工单
|
|
- $insert = [];
|
|
|
|
$i = 0;
|
|
$i = 0;
|
|
foreach ($param['list'] as $value) {
|
|
foreach ($param['list'] as $value) {
|
|
|
|
|
|
if ($val_child->check($value) == false) throw new Exception($val_child->getError());
|
|
if ($val_child->check($value) == false) throw new Exception($val_child->getError());
|
|
|
|
|
|
- $insert[] = [
|
|
|
|
|
|
+ $saleReturnChildCode = substr(makeNo('KCC'), 0, -2) . str_pad($i++, 2, '0', STR_PAD_LEFT);
|
|
|
|
+ $insert = [
|
|
'orderCode' => $saleReturn['orderCode'],
|
|
'orderCode' => $saleReturn['orderCode'],
|
|
'returnCode' => $param['returnCode'],
|
|
'returnCode' => $param['returnCode'],
|
|
'outCode' => $param['outCode'],
|
|
'outCode' => $param['outCode'],
|
|
'outChildCode' => $value['outChildCode'] ?? '',
|
|
'outChildCode' => $value['outChildCode'] ?? '',
|
|
'order_out_child_status' => isset($value['outChildCode']) ? ($orderOutChild[$value['outChildCode']]['status'] ?? 0) : 0,
|
|
'order_out_child_status' => isset($value['outChildCode']) ? ($orderOutChild[$value['outChildCode']]['status'] ?? 0) : 0,
|
|
- 'saleReturnChildCode' => substr(makeNo('KCC'), 0, -2) . str_pad($i++, 2, '0', STR_PAD_LEFT),
|
|
|
|
|
|
+ 'saleReturnChildCode' => $saleReturnChildCode,
|
|
// 'type' => $param['type'],
|
|
// 'type' => $param['type'],
|
|
'companyNo' => $saleReturn['companyNo'],
|
|
'companyNo' => $saleReturn['companyNo'],
|
|
'companyName' => $saleReturn['companyName'],
|
|
'companyName' => $saleReturn['companyName'],
|
|
@@ -113,16 +113,55 @@ class ReorderChild extends Base
|
|
'apply_id' => $this->uid,
|
|
'apply_id' => $this->uid,
|
|
'apply_name' => $this->uname,
|
|
'apply_name' => $this->uname,
|
|
];
|
|
];
|
|
|
|
+
|
|
|
|
+ $id = Db::name('sale_return_child')->insertGetId($insert);
|
|
|
|
+
|
|
|
|
+ //修改状态,添加待办
|
|
|
|
+ ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
|
|
|
|
+ "order_code" => $saleReturnChildCode,//单号
|
|
|
|
+ "status" => 0,//这里的status是之前的值
|
|
|
|
+ "action_remark" => '',//备注
|
|
|
|
+ "action_type" => "create"//新建create,编辑edit,更改状态status
|
|
|
|
+ ], "THGD", 1, $insert);
|
|
|
|
+
|
|
|
|
+ ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
|
|
|
|
+ "order_type" => 'THGD',
|
|
|
|
+ "order_code" => $saleReturnChildCode,//单号
|
|
|
|
+ "order_id" => $id,
|
|
|
|
+ "order_status" => 1,
|
|
|
|
+ "before_status" => 0,
|
|
|
|
+ 'holder_id' => $this->uid
|
|
|
|
+ ]);
|
|
}
|
|
}
|
|
|
|
|
|
- if ($insert) Db::name('sale_return_child')->insertAll($insert);
|
|
|
|
|
|
|
|
//维护售前退货单
|
|
//维护售前退货单
|
|
- $total_return_num = Db::name('sale_return_child')->where(['is_del' => 0, 'returnCode' => $param['returnCode'], 'status' => 1])->sum('return_num');
|
|
|
|
|
|
+ $total_return_num = Db::name('sale_return_child')
|
|
|
|
+ ->where(['is_del' => 0, 'returnCode' => $param['returnCode'], 'status' => 1])
|
|
|
|
+ ->sum('return_num');
|
|
|
|
+
|
|
if ($total_return_num >= $saleReturn['num']) {
|
|
if ($total_return_num >= $saleReturn['num']) {
|
|
Db::name('sale_return')
|
|
Db::name('sale_return')
|
|
->where(['is_del' => 0, 'id' => $saleReturn['id'], 'status' => 11])
|
|
->where(['is_del' => 0, 'id' => $saleReturn['id'], 'status' => 11])
|
|
->update(['status' => 12, 'updatetime' => $date]);
|
|
->update(['status' => 12, 'updatetime' => $date]);
|
|
|
|
+
|
|
|
|
+ //修改状态,添加待办
|
|
|
|
+ ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
|
|
|
|
+ "order_code" => $param['returnCode'],//单号
|
|
|
|
+ "status" => 11,//这里的status是之前的值
|
|
|
|
+ "action_remark" => '',//备注
|
|
|
|
+ "action_type" => "status"//新建create,编辑edit,更改状态status
|
|
|
|
+ ], "XSTHD", 12, ['status' => 12, 'updatetime' => $date]);
|
|
|
|
+
|
|
|
|
+ ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
|
|
|
|
+ "order_type" => 'XSTHD',
|
|
|
|
+ "order_code" => $param['returnCode'],//单号
|
|
|
|
+ "order_id" => $saleReturn['id'],
|
|
|
|
+ "order_status" => 12,
|
|
|
|
+ "before_status" => 11,
|
|
|
|
+ 'holder_id' => $saleReturn['apply_id']
|
|
|
|
+ ]);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
Db::commit();
|
|
Db::commit();
|
|
@@ -241,7 +280,6 @@ class ReorderChild extends Base
|
|
'remark' => $param['remark'],
|
|
'remark' => $param['remark'],
|
|
]);
|
|
]);
|
|
|
|
|
|
-
|
|
|
|
//修改状态,添加待办
|
|
//修改状态,添加待办
|
|
ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
|
|
ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
|
|
"order_code" => $info['saleReturnChildCode'],//单号
|
|
"order_code" => $info['saleReturnChildCode'],//单号
|
|
@@ -304,7 +342,11 @@ class ReorderChild extends Base
|
|
|
|
|
|
$old_status = $order['status'];
|
|
$old_status = $order['status'];
|
|
|
|
|
|
- $thnum = $info['thnum'];//退货总数量
|
|
|
|
|
|
+// $thnum = $info['thnum'];//退货总数量
|
|
|
|
+ $all_loss_num = Db::name('sale_return_child')
|
|
|
|
+ ->where(['is_del' => 0, 'returnCode' => $info['returnCode']])
|
|
|
|
+ ->sum('loss_num');
|
|
|
|
+ $thnum = $info['thnum'] - $all_loss_num;//退货总数量-丢失总数量
|
|
// if ($order['wsend_num'] < $thnum) throw new Exception("销售单未发货数量不足退货");
|
|
// if ($order['wsend_num'] < $thnum) throw new Exception("销售单未发货数量不足退货");
|
|
|
|
|
|
//如果 发货 维护销售单的
|
|
//如果 发货 维护销售单的
|
|
@@ -345,7 +387,6 @@ class ReorderChild extends Base
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
//非库存品转存为库存品
|
|
//非库存品转存为库存品
|
|
if ($info['is_stock'] != 1) {
|
|
if ($info['is_stock'] != 1) {
|
|
//根据转化表判断该非库存品是否转化为库存品
|
|
//根据转化表判断该非库存品是否转化为库存品
|
|
@@ -511,6 +552,20 @@ class ReorderChild extends Base
|
|
'updatetime' => $date,
|
|
'updatetime' => $date,
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ //维护商品层面的库存数
|
|
|
|
+ $has_good = Db::name('good')
|
|
|
|
+ ->field('id')
|
|
|
|
+ ->where(['is_del' => 0, 'spuCode' => $info['spuCode']])
|
|
|
|
+ ->findOrEmpty();
|
|
|
|
+ if (empty($has_good)) throw new Exception('未找到商品上线记录');
|
|
|
|
+ else {
|
|
|
|
+ Db::name('good')
|
|
|
|
+ ->where('id', $has_good['id'])
|
|
|
|
+ ->inc('usable_stock', $thnum)
|
|
|
|
+ ->update(['updatetime' => $date]);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|