|
@@ -88,7 +88,7 @@ class ReorderChild extends Base
|
|
|
'returnCode' => $param['returnCode'],
|
|
|
'outCode' => $param['outCode'],
|
|
|
'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),
|
|
|
// 'type' => $param['type'],
|
|
|
'companyNo' => $saleReturn['companyNo'],
|
|
@@ -101,8 +101,8 @@ class ReorderChild extends Base
|
|
|
'addtime' => $date,
|
|
|
'updatetime' => $date,
|
|
|
'record' => '',
|
|
|
- 'send_wsm_code' => isset($value['outChildCode'])?($orderOutChild[$value['outChildCode']]['wsm_code'] ?? ''):"",
|
|
|
- 'send_num' => isset($value['outChildCode'])?($orderOutChild[$value['outChildCode']]['num'] ?? 0):"",
|
|
|
+ 'send_wsm_code' => isset($value['outChildCode']) ? ($orderOutChild[$value['outChildCode']]['wsm_code'] ?? '') : "",
|
|
|
+ 'send_num' => isset($value['outChildCode']) ? ($orderOutChild[$value['outChildCode']]['num'] ?? 0) : "",
|
|
|
'return_num' => $value['return_num'],
|
|
|
'return_wsm_code' => $value['return_wsm_code'],
|
|
|
'good_receive_type' => 0,
|
|
@@ -207,11 +207,11 @@ class ReorderChild extends Base
|
|
|
'remark|备注' => 'max:255'
|
|
|
]);
|
|
|
|
|
|
- if ($val->check($param)==false) return json_show(1004, $val->getError());
|
|
|
+ if ($val->check($param) == false) return json_show(1004, $val->getError());
|
|
|
|
|
|
$info = Db::name('sale_return_child')
|
|
|
->alias('a')
|
|
|
- ->field('a.id,a.num,a.status,a.returnCode,a.outChildCode,a.return_num,a.return_wsm_code,a.orderCode,a.outCode,a.saleReturnChildCode,a.apply_id,b.good_code spuCode,c.status order_out_status,b.id saleid,d.num thnum,d.id sr_id,d.apply_id sr_apply_id')
|
|
|
+ ->field('a.id,a.num,a.status,a.returnCode,a.outChildCode,a.return_num,a.return_wsm_code,a.orderCode,a.outCode,a.saleReturnChildCode,a.apply_id,b.good_code spuCode,c.status order_out_status,b.id saleid,d.num thnum,d.id sr_id,d.apply_id sr_apply_id,b.is_stock,b.order_type')
|
|
|
->leftJoin('sale b', 'b.orderCode=a.orderCode')
|
|
|
->leftJoin('order_out_child c', 'c.outChildCode=a.outChildCode AND c.is_del=0')
|
|
|
->leftJoin('sale_return d', 'd.returnCode=a.returnCode')
|
|
@@ -341,13 +341,202 @@ class ReorderChild extends Base
|
|
|
"before_status" => $old_status
|
|
|
]);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //非库存品转存为库存品
|
|
|
+ if ($info['is_stock'] != 1) {
|
|
|
+ //根据转化表判断该非库存品是否转化为库存品
|
|
|
+ $spuCode = Db::name('good_change_stock')
|
|
|
+ ->where(['old_spuCode' => $info['spuCode'], 'old_order_type' => $info['order_type']])
|
|
|
+ ->value('spuCode', '');
|
|
|
+ if ($spuCode == '') {
|
|
|
+ //将非库存品转化为库存品
|
|
|
+ $spuCode = makeNo('SKU');
|
|
|
+ if ($info['order_type'] == 2) {
|
|
|
+ $good = Db::name('good_basic')
|
|
|
+ ->where('spuCode', $info['spuCode'])
|
|
|
+ ->findOrEmpty();
|
|
|
+ if (!empty($good)) {
|
|
|
+ Db::name('good_basic')->insert(array_merge($good, [
|
|
|
+ 'id' => null,
|
|
|
+ 'spuCode' => $spuCode,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ 'status'=>0,
|
|
|
+ 'is_stock' => 1,
|
|
|
+ ]));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $good = Db::name('good_zixun')
|
|
|
+ ->where(['spuCode' => $info['spuCode']])
|
|
|
+ ->findOrEmpty();
|
|
|
+ if (!empty($good)) {
|
|
|
+ Db::name('good_basic')->insert([
|
|
|
+ 'spuCode' => $spuCode,
|
|
|
+ 'good_code' => $good['good_code'],
|
|
|
+ 'good_name' => $good['good_name'],
|
|
|
+ 'cat_id' => $good['cat_id'],
|
|
|
+ 'brand_id' => $good['brand_id'],
|
|
|
+ 'companyNo' => $good['companyNo'],
|
|
|
+ 'companyName' => $good['companyName'],
|
|
|
+ 'good_unit' => $good['good_unit'],
|
|
|
+ 'good_type' => $good['good_type'],
|
|
|
+ 'moq' => $good['moq'],
|
|
|
+ 'is_exclusive' => 0,
|
|
|
+ 'customized' => $good['customized'],
|
|
|
+ 'tax' => $good['tax'],
|
|
|
+ 'supplierNo' => $good['supplierNo'],
|
|
|
+ 'supplierName' => $good['supplierName'],
|
|
|
+ 'is_auth' => $good['is_auth'],
|
|
|
+ 'auth_img' => $good['auth_img'],
|
|
|
+ 'is_stock' => 1,
|
|
|
+ 'after_sales' => '',
|
|
|
+ 'craft_desc' => $good['craft_desc'],
|
|
|
+ 'good_remark' => $good['good_remark'],
|
|
|
+ 'good_size' => '',
|
|
|
+ 'weight' => $good['weight'],
|
|
|
+ 'packing_way' => '',
|
|
|
+ 'packing_size' => '',
|
|
|
+ 'packing_spec' => '',
|
|
|
+ 'packing_list' => '',
|
|
|
+ 'packing_weight' => 0,
|
|
|
+ 'good_bar' => '',
|
|
|
+ 'supply_area' => $good['supply_area'],
|
|
|
+ 'delivery_place' => '',
|
|
|
+ 'origin_place' => '',
|
|
|
+ 'delivery_day' => '',
|
|
|
+ 'lead_time' => '',
|
|
|
+ 'sample_day' => '',
|
|
|
+ 'sample_fee' => '',
|
|
|
+ 'good_img' => $good['good_img'],
|
|
|
+ 'good_thumb_img' => $good['good_thumb_img'],
|
|
|
+ 'good_info_img' => $good['good_info_img'],
|
|
|
+ 'cert_fee' => 0,
|
|
|
+ 'packing_fee' => 0,
|
|
|
+ 'cost_fee' => 0,
|
|
|
+ 'mark_fee' => 0,
|
|
|
+ 'demo_fee' => 0,
|
|
|
+ 'open_fee' => 0,
|
|
|
+ 'noble_metal' => $good['noble_metal'],
|
|
|
+ 'noble_weight' => 0,
|
|
|
+ 'is_gold_price' => $good['is_gold_price'],
|
|
|
+ 'cgd_gold_price' => 0,
|
|
|
+ 'market_price' => 0,
|
|
|
+ 'nake_price' => 0,
|
|
|
+ 'is_step' => 0,
|
|
|
+ 'is_online' => 0,
|
|
|
+ 'status' => 0,
|
|
|
+ 'createrid' => $good['createrid'],
|
|
|
+ 'creater' => $good['creater'],
|
|
|
+ 'field_change' => '',
|
|
|
+ 'is_del' => 0,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ 'is_diff' => 0,
|
|
|
+ 'config' => '',
|
|
|
+ 'other_config' => '',
|
|
|
+ 'stock_moq' => 0,
|
|
|
+ 'is_support_barter' => 1,
|
|
|
+ 'chargerid' => $good['createrid'],
|
|
|
+ 'charger' => $good['creater'],
|
|
|
+ 'is_support_stock' => 1
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($good)) {
|
|
|
+ //关联表增数据
|
|
|
+ Db::name('good_change_stock')
|
|
|
+ ->insert([
|
|
|
+ 'old_spuCode' => $info['spuCode'],
|
|
|
+ 'old_order_type' => $info['order_type'],
|
|
|
+ 'spuCode' => $spuCode,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ } else throw new Exception('未找到对应的商品数据');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增bn记录,维护旧有bn记录
|
|
|
+ $child_bns = Db::name('child_bn')
|
|
|
+ ->field('id,num,origin_price')
|
|
|
+ ->where(['orderCode' => $info['orderCode'], 'outCode' => $info['outCode']])
|
|
|
+ ->order(['num' => 'desc', 'id' => 'asc'])
|
|
|
+ ->cursor();
|
|
|
+
|
|
|
+ $total = $info['return_num'];
|
|
|
+ $origin_price = $j = 0;
|
|
|
+ foreach ($child_bns as $child_bn) {
|
|
|
+ if ($origin_price === 0) $origin_price = $child_bn['origin_price'];
|
|
|
+ Db::name('child_bn')
|
|
|
+ ->where(['id' => $child_bn['id']])
|
|
|
+ ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
|
|
|
+ ->update(['updatetime' => $date]);
|
|
|
+ $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
|
|
|
+ if ($total == 0) break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (($info['return_num'] - $info['loss_num']) > 0) {
|
|
|
+ $stockid = Db::name('good_stock')
|
|
|
+ ->insertGetId([
|
|
|
+ 'project_code' => '',
|
|
|
+ 'spuCode' => $spuCode,
|
|
|
+ 'wsm_code' => $info['return_wsm_code'],
|
|
|
+ 'wait_in_stock' => 0,
|
|
|
+ 'wait_out_stock' => 0,
|
|
|
+ 'usable_stock' => $info['return_num'] - $info['loss_num'],
|
|
|
+ 'intra_stock' => 0,
|
|
|
+ 'total_stock' => $info['return_num'] - $info['loss_num'],
|
|
|
+ 'status' => 1,
|
|
|
+ 'is_del' => 0,
|
|
|
+ 'warn_stock' => 0,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ Db::name('good_stock_info')
|
|
|
+ ->insert([
|
|
|
+ 'stockid' => $stockid,
|
|
|
+ 'bnCode' => substr(makeNo("BN"), 0, -2) . str_pad($j++, 2, '0', STR_PAD_LEFT),
|
|
|
+ 'total_num' => $info['return_num'] - $info['loss_num'],
|
|
|
+ 'used_num' => 0,
|
|
|
+ 'balance_num' => $info['return_num'] - $info['loss_num'],
|
|
|
+ 'origin_price' => $origin_price,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//发货工单数量减少
|
|
|
- Db::name('order_out_child')
|
|
|
+ $tmp = Db::name('order_out_child')
|
|
|
->where(['is_del' => 0, 'outChildCode' => $info['outChildCode']])
|
|
|
- ->dec('num', $info['return_num'])
|
|
|
- ->update(['updatetime' => $date]);
|
|
|
+ ->field('id,num')
|
|
|
+ ->findOrEmpty();
|
|
|
+ $tmp['num'] -= $info['return_num'];
|
|
|
+ $tmp['updatetime'] = $date;
|
|
|
+ if ($tmp['num'] <= 0) $tmp['is_del'] = 1;
|
|
|
+
|
|
|
+ Db::name('order_out_child')
|
|
|
+ ->where(['is_del' => 0, 'id' => $tmp['id']])
|
|
|
+ ->update($tmp);
|
|
|
+
|
|
|
+ //维护发货单
|
|
|
+ $temp = Db::name('order_out')
|
|
|
+ ->field('id,send_num')
|
|
|
+ ->where(['is_del' => 0, 'outCode' => $info['outCode']])
|
|
|
+ ->findOrEmpty();
|
|
|
+
|
|
|
+ $temp['send_num'] -= $info['return_num'];
|
|
|
+ $temp['updatetime'] = $date;
|
|
|
+ if ($temp['send_num'] <= 0) $temp['is_del'] = 1;
|
|
|
+
|
|
|
+ Db::name('order_out')
|
|
|
+ ->where('id', $temp['id'])
|
|
|
+ ->update($temp);
|
|
|
|
|
|
//维护bn
|
|
|
if ($info['order_out_status'] == 1) {
|