|
@@ -15,7 +15,7 @@ class AfterChild extends Base
|
|
public function getList()
|
|
public function getList()
|
|
{
|
|
{
|
|
|
|
|
|
- $param = $this->request->only(['page' => 1, 'size' => 10, 'returnCode' => '', 'status' => '', 'orderCode' => '', 'outCode' => '', 'order_type' => '', 'supplierNo' => '', 'is_authority' => 0], 'post', 'trim');
|
|
|
|
|
|
+ $param = $this->request->only(['page' => 1, 'size' => 10, 'returnCode' => '', 'status' => '', 'orderCode' => '', 'outCode' => '', 'order_type' => '', 'supplierNo' => '', 'is_authority' => 0,'type'=>''], 'post', 'trim');
|
|
|
|
|
|
$db = Db::name('order_return_child')
|
|
$db = Db::name('order_return_child')
|
|
->alias('a')
|
|
->alias('a')
|
|
@@ -30,6 +30,7 @@ class AfterChild extends Base
|
|
if ($param['outCode'] != '') $db->whereLike('a.outCode', '%' . $param['outCode'] . '%');
|
|
if ($param['outCode'] != '') $db->whereLike('a.outCode', '%' . $param['outCode'] . '%');
|
|
if ($param['order_type'] !== '') $db->where('d.order_type', $param['order_type']);
|
|
if ($param['order_type'] !== '') $db->where('d.order_type', $param['order_type']);
|
|
if ($param['supplierNo'] != '') $db->whereLike('d.supplierNo', '%' . $param['supplierNo'] . '%');
|
|
if ($param['supplierNo'] != '') $db->whereLike('d.supplierNo', '%' . $param['supplierNo'] . '%');
|
|
|
|
+ if ($param['type'] !== '') $db->where('a.type', $param['type']);
|
|
|
|
|
|
if ($param['is_authority'] == '0' && $param['returnCode'] == '' && $param['orderCode'] == '' && $param['outCode'] == '') return json_show('请选择筛选条件');
|
|
if ($param['is_authority'] == '0' && $param['returnCode'] == '' && $param['orderCode'] == '' && $param['outCode'] == '') return json_show('请选择筛选条件');
|
|
|
|
|
|
@@ -62,7 +63,7 @@ class AfterChild extends Base
|
|
->count('a.id');
|
|
->count('a.id');
|
|
|
|
|
|
$list = $db
|
|
$list = $db
|
|
- ->field('a.id,a.returnCode,a.orderCode,a.outCode,a.order_out_child_status,a.outChildCode,b.supplierName send_supplierName,b.supplierNo send_supplierNo,b.name send_wsm_name,a.send_wsm_code,b.contactor_name send_contactor_name,a.send_num,a.return_num,c.supplierName return_supplierName,c.supplierNo return_supplierNo,c.name return_wsm_name,a.return_wsm_code,c.contactor_name return_contactor_name,a.status,d.companyNo,d.companyName,d.customer_code,d.customer_name,d.order_type,d.apply_id,d.apply_name')
|
|
|
|
|
|
+ ->field('a.id,a.returnCode,a.orderCode,a.outCode,a.order_out_child_status,a.outChildCode,b.supplierName send_supplierName,b.supplierNo send_supplierNo,b.name send_wsm_name,a.send_wsm_code,b.contactor_name send_contactor_name,a.send_num,a.return_num,c.supplierName return_supplierName,c.supplierNo return_supplierNo,c.name return_wsm_name,a.return_wsm_code,c.contactor_name return_contactor_name,a.status,d.companyNo,d.companyName,d.customer_code,d.customer_name,d.order_type,d.apply_id,d.apply_name,a.type,a.can_sell_num,a.defective_num,a.loss_num,a.return_num_total')
|
|
->order(['a.addtime' => 'desc', 'a.id' => 'desc'])
|
|
->order(['a.addtime' => 'desc', 'a.id' => 'desc'])
|
|
->page($param['page'], $param['size'])
|
|
->page($param['page'], $param['size'])
|
|
->select()
|
|
->select()
|
|
@@ -99,7 +100,7 @@ class AfterChild extends Base
|
|
|
|
|
|
$val_child = Validate::rule([
|
|
$val_child = Validate::rule([
|
|
'outChildCode|发货工单号' => 'require',
|
|
'outChildCode|发货工单号' => 'require',
|
|
- 'return_num|退货数量' => 'require|number|gt:0|max:999999999999',
|
|
|
|
|
|
+ 'return_num|退货数量' => 'require|number|egt:0|max:999999999999',
|
|
'return_wsm_code|退货仓库编码' => 'require'
|
|
'return_wsm_code|退货仓库编码' => 'require'
|
|
]);
|
|
]);
|
|
|
|
|
|
@@ -126,6 +127,7 @@ class AfterChild extends Base
|
|
if (!isset($order_out_child[$value['outChildCode']])) throw new Exception($value['outChildCode'] . '发货工单不存在');
|
|
if (!isset($order_out_child[$value['outChildCode']])) throw new Exception($value['outChildCode'] . '发货工单不存在');
|
|
if (!isset($wsm_info[$value['return_wsm_code']])) throw new Exception($value['return_wsm_code'] . '退货仓库不存在');
|
|
if (!isset($wsm_info[$value['return_wsm_code']])) throw new Exception($value['return_wsm_code'] . '退货仓库不存在');
|
|
|
|
|
|
|
|
+ if ($value['return_num'] <= 0) continue;//数量为0的不再处理
|
|
$insert[] = [
|
|
$insert[] = [
|
|
'returnCode' => $param['returnCode'],
|
|
'returnCode' => $param['returnCode'],
|
|
'orderCode' => $order_out['orderCode'],
|
|
'orderCode' => $order_out['orderCode'],
|
|
@@ -146,6 +148,8 @@ class AfterChild extends Base
|
|
'remark' => '',
|
|
'remark' => '',
|
|
'addtime' => $date,
|
|
'addtime' => $date,
|
|
'updatetime' => $date,
|
|
'updatetime' => $date,
|
|
|
|
+ 'type' => 1,
|
|
|
|
+ 'return_num_total' => 0
|
|
];
|
|
];
|
|
|
|
|
|
}
|
|
}
|
|
@@ -191,8 +195,9 @@ class AfterChild extends Base
|
|
$info = Db::name('order_return_child')
|
|
$info = Db::name('order_return_child')
|
|
->alias('a')
|
|
->alias('a')
|
|
->leftJoin('order_out_child b', 'b.outChildCode=a.outChildCode')
|
|
->leftJoin('order_out_child b', 'b.outChildCode=a.outChildCode')
|
|
|
|
+ ->leftJoin('warehouse_info c', 'c.wsm_code=a.return_wsm_code')
|
|
->where(['a.is_del' => 0, 'a.returnCode' => $param['returnCode'], 'a.id' => array_column($param['list'], 'id')])
|
|
->where(['a.is_del' => 0, 'a.returnCode' => $param['returnCode'], 'a.id' => array_column($param['list'], 'id')])
|
|
- ->column('a.id,a.return_wsm_code,a.outChildCode,b.wsm_code,a.status,a.return_num', 'a.id');
|
|
|
|
|
|
+ ->column('a.*,b.wsm_code,c.addr,c.addrs_code,c.mobile,c.contactor_name', 'a.id');
|
|
if (empty($info)) return json_show(1004, '退货工单不存在');
|
|
if (empty($info)) return json_show(1004, '退货工单不存在');
|
|
|
|
|
|
$val_child = Validate::rule([
|
|
$val_child = Validate::rule([
|
|
@@ -207,6 +212,8 @@ class AfterChild extends Base
|
|
try {
|
|
try {
|
|
|
|
|
|
$date = date('Y-m-d H:i:s');
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
+
|
|
|
|
+ $insert = [];
|
|
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());
|
|
if (!isset($info[$value['id']])) throw new Exception($value['id'] . '退货工单不存在');
|
|
if (!isset($info[$value['id']])) throw new Exception($value['id'] . '退货工单不存在');
|
|
@@ -221,7 +228,8 @@ class AfterChild extends Base
|
|
'loss_num' => $value['loss_num'],
|
|
'loss_num' => $value['loss_num'],
|
|
'remark' => $value['remark'] ?? '',
|
|
'remark' => $value['remark'] ?? '',
|
|
'updatetime' => $date,
|
|
'updatetime' => $date,
|
|
- 'status' => 2
|
|
|
|
|
|
+ 'status' => 2,
|
|
|
|
+ 'return_num_total' => $value['can_sell_num']
|
|
]);
|
|
]);
|
|
|
|
|
|
//发货工单数量减少
|
|
//发货工单数量减少
|
|
@@ -229,8 +237,35 @@ class AfterChild extends Base
|
|
->where(['is_del' => 0, 'outChildCode' => $info[$value['id']]['outChildCode']])
|
|
->where(['is_del' => 0, 'outChildCode' => $info[$value['id']]['outChildCode']])
|
|
->dec('num', $info[$value['id']]['return_num'])
|
|
->dec('num', $info[$value['id']]['return_num'])
|
|
->update(['updatetime' => $date]);
|
|
->update(['updatetime' => $date]);
|
|
|
|
+
|
|
|
|
+ //如果次品仓入库数量大于0,另生成退货工单,以类型区分
|
|
|
|
+ if ($value['defective_num'] > 0) {
|
|
|
|
+ $temp = $info[$value['id']];
|
|
|
|
+ unset($temp['wsm_code']);
|
|
|
|
+ unset($temp['addr']);
|
|
|
|
+ unset($temp['addrs_code']);
|
|
|
|
+ unset($temp['mobile']);
|
|
|
|
+ unset($temp['contactor_name']);
|
|
|
|
+
|
|
|
|
+ $insert[] = array_merge($temp, [
|
|
|
|
+ 'id' => null,
|
|
|
|
+ 'addtime' => $date,
|
|
|
|
+ 'updatetime' => $date,
|
|
|
|
+ 'return_wsm_code' => Db::name('order_returninfo')->where('returnCode', $param['returnCode'])->value('return_wsm', ''),//取之前次品仓的编码
|
|
|
|
+ 'type' => 2,
|
|
|
|
+ 'return_num_total' => $value['defective_num'],
|
|
|
|
+ 'can_sell_num' => $value['can_sell_num'],
|
|
|
|
+ 'defective_num' => $value['defective_num'],
|
|
|
|
+ 'loss_num' => $value['loss_num'],
|
|
|
|
+ 'remark' => $value['remark'] ?? '',
|
|
|
|
+ 'status' => 2,
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if ($insert) Db::name('order_return_child')->insertAll($insert);
|
|
|
|
+
|
|
$total = array_sum(array_column($param['list'], 'can_sell_num'));
|
|
$total = array_sum(array_column($param['list'], 'can_sell_num'));
|
|
|
|
|
|
if ($total > 0) {
|
|
if ($total > 0) {
|
|
@@ -249,14 +284,16 @@ class AfterChild extends Base
|
|
if (!empty($good)) {
|
|
if (!empty($good)) {
|
|
Db::name('good_basic')->insert(array_merge($good, [
|
|
Db::name('good_basic')->insert(array_merge($good, [
|
|
'id' => null,
|
|
'id' => null,
|
|
|
|
+ 'is_stock' => 1,
|
|
'spuCode' => $spuCode,
|
|
'spuCode' => $spuCode,
|
|
'addtime' => $date,
|
|
'addtime' => $date,
|
|
'updatetime' => $date,
|
|
'updatetime' => $date,
|
|
|
|
+ 'status' => 0
|
|
]));
|
|
]));
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
$good = Db::name('good_zixun')
|
|
$good = Db::name('good_zixun')
|
|
- ->where([])
|
|
|
|
|
|
+ ->where(['spuCode' => $order_return['good_code']])
|
|
->findOrEmpty();
|
|
->findOrEmpty();
|
|
if (!empty($good)) {
|
|
if (!empty($good)) {
|
|
Db::name('good_basic')->insert([
|
|
Db::name('good_basic')->insert([
|
|
@@ -504,7 +541,7 @@ class AfterChild extends Base
|
|
//维护商品层面的库存数
|
|
//维护商品层面的库存数
|
|
Db::name('good')
|
|
Db::name('good')
|
|
->where(['is_del' => 0, 'spuCode' => $order_return['good_code']])
|
|
->where(['is_del' => 0, 'spuCode' => $order_return['good_code']])
|
|
- ->inc('usable_stock', array_sum(array_column($info, 'return_num')) - array_sum(array_column($param['list'], 'loss_num')))
|
|
|
|
|
|
+ ->inc('usable_stock', array_sum(array_column($param['list'], 'can_sell_num')))
|
|
->update(['updatetime' => $date]);
|
|
->update(['updatetime' => $date]);
|
|
|
|
|
|
}
|
|
}
|