|
@@ -17,13 +17,12 @@ class ReorderChild extends Base
|
|
|
public function add()
|
|
|
{
|
|
|
|
|
|
- $param = $this->request->only(['returnCode', 'outCode', 'list', 'type'], 'post', 'trim');
|
|
|
+ $param = $this->request->only(['returnCode', 'outCode', 'list'], 'post', 'trim');
|
|
|
|
|
|
$val = Validate::rule([
|
|
|
'returnCode|退货单编号' => 'require',
|
|
|
- 'outCode|发货单编号' => 'requireIf:type,2',
|
|
|
+ 'outCode|发货单编号' => 'require',
|
|
|
'list|退货工单集合' => 'require|array|max:100',
|
|
|
- 'type|工单退货类型' => 'require|number|in:1,2',
|
|
|
]);
|
|
|
if ($val->check($param) == false) return json_show(1004, $val->getError());
|
|
|
|
|
@@ -40,7 +39,6 @@ class ReorderChild extends Base
|
|
|
->findOrEmpty();
|
|
|
if (empty($sale)) return json_show(1004, '销售单不存在');
|
|
|
|
|
|
- if ($param['type'] == 2) {
|
|
|
//所有发货工单
|
|
|
$orderOutChild = Db::name('order_out_child')
|
|
|
->where(['is_del' => 0, 'outChildCode' => array_unique(array_column($param['list'], 'outChildCode'))])
|
|
@@ -53,15 +51,15 @@ class ReorderChild extends Base
|
|
|
if (empty($saleReturnAddr)) return json_show(1004, '该退货地址不存在');
|
|
|
if ($saleReturnAddr['is_sale_return_child'] == 1) return json_show(1004, '该退货地址不能重复设置退货工单');
|
|
|
if ($saleReturnAddr['return_num'] != array_sum(array_column($param['list'], 'return_num'))) return json_show(1004, '数量错误');
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
$val_child = Validate::rule([
|
|
|
- 'outChildCode|发货工单号' => 'requireIf:type,2',
|
|
|
+ 'outChildCode|发货工单号' => 'require',
|
|
|
'return_num|退货数量' => 'require|number|gt:0|max:999999999999',
|
|
|
'return_wsm_code|退货仓库编码' => 'require'
|
|
|
]);
|
|
|
|
|
|
- if ($saleReturn['sale_return'] < array_sum(array_column($param['list'], 'return_num'))) return json_show(1004, '数量错误');
|
|
|
+ if ($saleReturn['num'] < array_sum(array_column($param['list'], 'return_num'))) return json_show(1004, '数量错误');
|
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
@@ -70,29 +68,25 @@ class ReorderChild extends Base
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
|
|
//维护退货地址
|
|
|
- if ($param['type'] == 2) {
|
|
|
- Db::name('sale_returnaddr')
|
|
|
- ->where(['id' => $saleReturnAddr['id'], 'is_del' => 0, 'is_sale_return_child' => 0])
|
|
|
- ->update(['is_sale_return_child' => 1, 'updatetime' => $date]);
|
|
|
- }
|
|
|
+ Db::name('sale_returnaddr')
|
|
|
+ ->where(['id' => $saleReturnAddr['id'], 'is_del' => 0, 'is_sale_return_child' => 0])
|
|
|
+ ->update(['is_sale_return_child' => 1, 'updatetime' => $date]);
|
|
|
|
|
|
//生成售前退货工单
|
|
|
$insert = [];
|
|
|
$i = 0;
|
|
|
foreach ($param['list'] as $value) {
|
|
|
|
|
|
- $value['type'] = $param['type'];
|
|
|
-
|
|
|
if ($val_child->check($value) == false) throw new Exception($val_child->getError());
|
|
|
|
|
|
$insert[] = [
|
|
|
'orderCode' => $saleReturn['orderCode'],
|
|
|
'returnCode' => $param['returnCode'],
|
|
|
- 'outCode' => $param['type'] == 2 ? $param['outCode'] : '',
|
|
|
+ 'outCode' => $param['outCode'],
|
|
|
'outChildCode' => $value['outChildCode'] ?? '',
|
|
|
- 'order_out_child_status' => $param['type'] == 2 ? $orderOutChild[$value['outChildCode']]['status'] : '',
|
|
|
+ 'order_out_child_status' => $orderOutChild[$value['outChildCode']]['status'],
|
|
|
'saleReturnChildCode' => substr(makeNo('KCC'), 0, -2) . str_pad($i++, 2, '0', STR_PAD_LEFT),
|
|
|
- 'type' => $param['type'],
|
|
|
+// 'type' => $param['type'],
|
|
|
'companyNo' => $saleReturn['companyNo'],
|
|
|
'companyName' => $saleReturn['companyName'],
|
|
|
'customer_code' => $saleReturn['customer_code'],
|
|
@@ -103,8 +97,8 @@ class ReorderChild extends Base
|
|
|
'addtime' => $date,
|
|
|
'updatetime' => $date,
|
|
|
'record' => '',
|
|
|
- 'send_wsm_code' => $param['type'] == 2 ? $orderOutChild[$value['outChildCode']]['wsm_code'] : '',
|
|
|
- 'send_num' => $param['type'] == 2 ? $orderOutChild[$value['outChildCode']]['num'] : '',
|
|
|
+ 'send_wsm_code' => $orderOutChild[$value['outChildCode']]['wsm_code'],
|
|
|
+ 'send_num' => $orderOutChild[$value['outChildCode']]['num'],
|
|
|
'return_num' => $value['return_num'],
|
|
|
'return_wsm_code' => $value['return_wsm_code'],
|
|
|
'good_receive_type' => 0,
|
|
@@ -182,7 +176,7 @@ class ReorderChild extends Base
|
|
|
$count = $db->count('a.id');
|
|
|
|
|
|
$list = $db
|
|
|
- ->field('a.id,a.saleReturnChildCode,a.type,a.outChildCode,a.outCode,a.companyNo,a.companyName,a.customer_code,a.customerName,a.num,a.sale_price,a.total_price,a.status,a.addtime,b.supplierNo,b.supplierName,a.return_wsm_code,c.name return_wsm_name,c.supplierNo return_supplierNo,c.supplierName return_supplierName,c.contactor_name return_contactor_name,b.order_type,a.orderCode,a.returnCode,b.apply_name,b.apply_id')
|
|
|
+ ->field('a.id,a.saleReturnChildCode,a.outChildCode,a.outCode,a.companyNo,a.companyName,a.customer_code,a.customerName,a.num,a.sale_price,a.total_price,a.status,a.addtime,b.supplierNo,b.supplierName,a.return_wsm_code,c.name return_wsm_name,c.supplierNo return_supplierNo,c.supplierName return_supplierName,c.contactor_name return_contactor_name,b.order_type,a.orderCode,a.returnCode,b.apply_name,b.apply_id')
|
|
|
->order(['a.addtime' => 'desc', 'a.id' => 'desc'])
|
|
|
->page($param['page'], $param['size'])
|
|
|
->select()
|