|
@@ -149,11 +149,18 @@ class Filing
|
|
|
//转单
|
|
|
public static function transfer(array $data = [])
|
|
|
{
|
|
|
- $rs = Db::name('filing')
|
|
|
+ $filing = Db::name('filing')
|
|
|
->field(true)
|
|
|
->where(['is_del' => 0, 'id' => $data['id'], 'supplierNo' => $data['supplierNo'], 'status' => 2])
|
|
|
->findOrEmpty();
|
|
|
- if (empty($rs)) json_show(1005, '该报备单不存在或不允许转单');
|
|
|
+ if (empty($filing)) return json_show(1005, '该报备单不存在或不允许转单');
|
|
|
+
|
|
|
+ if (array_sum(array_column($data['addr_list'], 'receipt_quantity')) != $filing['num']) return json_show(1004, '收货地址的收货总数不符合');
|
|
|
+
|
|
|
+ $supplier = Db::name('supplier')
|
|
|
+ ->field('id,person,personid,name,code')
|
|
|
+ ->where(['code' => $filing['supplierNo']])
|
|
|
+ ->findOrEmpty();
|
|
|
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
|
@@ -161,19 +168,261 @@ class Filing
|
|
|
|
|
|
try {
|
|
|
|
|
|
+ $spuCode = makeNo('SKU');
|
|
|
+
|
|
|
+ //商品表
|
|
|
+ Db::name('good_zixun')
|
|
|
+ ->insert([
|
|
|
+ 'spuCode' => $spuCode,
|
|
|
+ 'good_name' => $filing['good_name'],
|
|
|
+ 'brand_id' => $filing['brand_id'],
|
|
|
+ 'cat_id' => $filing['cat_id'],
|
|
|
+ 'good_unit' => $filing['unit_id'],
|
|
|
+ 'good_type' => 0,
|
|
|
+ 'moq' => 1,
|
|
|
+ 'customized' => $filing['make_day'],
|
|
|
+ 'tax' => $filing['tax'],
|
|
|
+ 'platform_id' => 0,//平台???@todo
|
|
|
+ 'supplierNo' => $filing['supplierNo'],
|
|
|
+ 'is_auth' => 0,
|
|
|
+ 'craft_desc' => $filing['good_name'],
|
|
|
+ 'good_remark' => '',
|
|
|
+ 'good_img' => $filing['good_img'],
|
|
|
+ 'good_thumb_img' => '',
|
|
|
+ 'good_info_img' => '',
|
|
|
+ 'status' => 1,
|
|
|
+ 'createrid' => $filing['apply_id'],
|
|
|
+ 'creater' => $filing['apply_name'],
|
|
|
+ 'is_del' => 0,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ 'specinfo' => $filing['specinfo'],
|
|
|
+ 'work_day' => $filing['make_day'],
|
|
|
+ 'noble_metal' => $filing['noble_metal'],
|
|
|
+ 'is_gold_price' => $filing['is_gold_price'],
|
|
|
+ 'good_weight' => $filing['gold_weight'],
|
|
|
+ 'config' => $filing['config'],
|
|
|
+ 'other_config' => $filing['other_config'],
|
|
|
+ 'weight' => $filing['weight'],
|
|
|
+ 'supply_area' => $filing['supply_area'],
|
|
|
+ 'is_diff' => $filing['is_diff'],
|
|
|
+ 'pay_way' => $filing['pay_way'],
|
|
|
+ 'send_way' => $filing['send_way'],
|
|
|
+ 'companyNo' => $filing['customerCode'],
|
|
|
+ 'proof_type' => '',
|
|
|
+ 'proof_url' => '',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $orderCode = makeNo('QR');
|
|
|
+ //订单表
|
|
|
+ //sale
|
|
|
+ $sale_id = Db::name('sale')->insertGetId([
|
|
|
+ 'orderCode' => $orderCode,
|
|
|
+ 'apply_id' => $filing['apply_id'],
|
|
|
+ 'apply_name' => $filing['apply_name'],
|
|
|
+ 'order_type' => 2,//非库存品
|
|
|
+ 'order_source' => 2,//咨询
|
|
|
+ 'platform_id' => 0,//平台id@todo
|
|
|
+ 'good_code' => $spuCode,
|
|
|
+ 'skuCode' => '',
|
|
|
+ 'cat_id' => $filing['cat_id'],
|
|
|
+ 'good_name' => $filing['good_name'],
|
|
|
+ 'good_num' => $filing['num'],
|
|
|
+ 'good_type' => 1,
|
|
|
+ 'origin_price' => $filing['cgd_charge'],
|
|
|
+ 'sale_price' => $filing['price'],
|
|
|
+ 'total_price' => round(bcmul($filing['price'], $filing['num'], 3), 2),
|
|
|
+ 'post_fee' => 0,
|
|
|
+ 'is_diff' => $filing['is_diff'],
|
|
|
+ 'is_activity' => 0,
|
|
|
+ 'activity_code' => '',
|
|
|
+ 'is_stock' => 0,
|
|
|
+ 'customer_code' => $filing['companyCode'],
|
|
|
+ 'supplierNo' => $filing['supplierNo'],
|
|
|
+ 'zxNo' => '',//@todo 咨询单号
|
|
|
+ 'platform_order' => '',//@todo
|
|
|
+ 'send_num' => 0,
|
|
|
+ 'wsend_num' => $filing['num'],
|
|
|
+ 'th_num' => 0,
|
|
|
+ 'th_fee' => 0,
|
|
|
+ 'send_status' => 1,
|
|
|
+ 'send_type' => 1,//直接发货
|
|
|
+ 'remark' => '',
|
|
|
+ 'status' => 0,
|
|
|
+ 'is_del' => 0,
|
|
|
+ 'proof_id' => 0,
|
|
|
+ 'other_orderNo' => '',
|
|
|
+ 'workNo' => '',
|
|
|
+ 'poNo' => '',
|
|
|
+ 'use_order' => 0,
|
|
|
+ 'good_weight' => 0,
|
|
|
+ 'gold_price' => 0,
|
|
|
+ 'cost_price' => $filing['cost_fee'],
|
|
|
+ 'diff_weight' => 0,
|
|
|
+ 'diff_fee' => 0,
|
|
|
+ 'returnCode' => '',
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ 'cgderid' => $supplier['personid'],
|
|
|
+ 'cgder' => $supplier['person'],
|
|
|
+ 'good_createrid' => $filing['apply_id'],
|
|
|
+ 'good_creater' => $filing['apply_name'],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ //仓库
|
|
|
+ $wsm = Db::name('warehouse_info')
|
|
|
+ ->field('id,wsm_code')
|
|
|
+ ->where(['supplierNo' => $filing['supplierNo'], 'companyNo' => $filing['customerCode'], 'is_del' => 0])
|
|
|
+ ->findOrEmpty();
|
|
|
+ if (empty($wsm)) {
|
|
|
+ $wsm_code = makeNo('WSM');
|
|
|
+
|
|
|
+ Db::name('warehouse_info')->insert([
|
|
|
+ 'wsm_code' => $wsm_code,
|
|
|
+ 'name' => $supplier['name'],
|
|
|
+ 'wsm_type' => 2,
|
|
|
+ 'supplierNo' => $supplier['code'],
|
|
|
+ 'addr' => '',
|
|
|
+ 'addrs_code' => '',
|
|
|
+ 'contactor' => 0,
|
|
|
+ 'contactor_name' => 0,
|
|
|
+ 'mobile' => '',
|
|
|
+ 'position' => '',
|
|
|
+ 'companyNo' => $filing['supplierNo'],
|
|
|
+ 'status' => 1,
|
|
|
+ 'is_del' => 0,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ } else $wsm_code = $wsm['wsm_code'];
|
|
|
+
|
|
|
+ //采购单
|
|
|
+ $cgdCode = makeNo('CG');
|
|
|
+
|
|
|
+ Db::name('purchease_order')->insert([
|
|
|
+ 'cgdNo' => $cgdCode,
|
|
|
+ 'bkcode' => '',
|
|
|
+ 'wsm_code' => $wsm_code,
|
|
|
+ 'cgder' => $supplier['person'],
|
|
|
+ 'cgder_id' => $supplier['personid'],
|
|
|
+ 'spuCode' => $spuCode,
|
|
|
+ 'good_name' => $filing['good_name'],
|
|
|
+ 'good_num' => $filing['num'],
|
|
|
+ 'good_price' => $filing['cgd_charge'],
|
|
|
+ 'total_fee' => round(bcmul($filing['cgd_charge'], $filing['num']), 2),
|
|
|
+ 'pakge_fee' => $filing['pakge_fee'],
|
|
|
+ 'cert_fee' => $filing['cert_fee'],
|
|
|
+ 'open_fee' => $filing['open_fee'],
|
|
|
+ 'delivery_fee' => $filing['delivery_fee'],
|
|
|
+ 'mark_fee' => $filing['mark_fee'],
|
|
|
+ 'demo_fee' => $filing['demo_fee'],
|
|
|
+ 'diff_weight' => '0',
|
|
|
+ 'diff_fee' => '0',
|
|
|
+ 'gold_price' => '0',
|
|
|
+ 'supplierNo' => $filing['supplierNo'],
|
|
|
+ 'supplier_name' => $filing['supplierName'],
|
|
|
+ 'companyNo' => $filing['customerCode'],
|
|
|
+ 'send_status' => 1,
|
|
|
+ 'send_num' => '0',
|
|
|
+ 'wsend_num' => $filing['num'],
|
|
|
+ 'remark' => '',
|
|
|
+ 'status' => 0,
|
|
|
+ 'lasttime' => $date,
|
|
|
+ 'is_del' => 0,
|
|
|
+ 'order_type' => 2,
|
|
|
+ 'order_source' => 2,
|
|
|
+ 'good_type' => 1,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ 'good_createrid' => $filing['apply_id'],
|
|
|
+ 'good_creater' => $filing['apply_name'],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ //台账
|
|
|
+ $standing_bood_data = [
|
|
|
+ 'standBookNo' => makeNo('IO'),
|
|
|
+ 'orderCode' => $orderCode,
|
|
|
+ 'sale_id' => $sale_id,
|
|
|
+ 'customer_code' => $filing['companyCode'],
|
|
|
+ 'supplierNo' => $filing['supplierNo'],
|
|
|
+ 'order_type' => 2,
|
|
|
+ 'order_source' => 2,
|
|
|
+ 'spuCode' => $spuCode,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ 'cgdNo' => $cgdCode,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $i = 0;
|
|
|
+ foreach ($data['addr_list'] as $addr) {
|
|
|
+ //地址addr
|
|
|
+ $addrid = Db::name('order_addr')->insertGetId([
|
|
|
+ 'orderCode' => $orderCode,
|
|
|
+ 'addr' => $addr['addr'],
|
|
|
+ 'addr_code' => implode(',', $addr['addr_code']),
|
|
|
+ 'contactor' => $addr['contactor'],
|
|
|
+ 'mobile' => $addr['mobile'],
|
|
|
+ 'customer_code' => $filing['companyCode'],
|
|
|
+ 'post_fee' => 0,
|
|
|
+ 'arrive_time' => $addr['arrive_time'],
|
|
|
+ 'receipt_quantity' => $addr['receipt_quantity'],
|
|
|
+ 'is_del' => 0,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ //发货单
|
|
|
+ $outCode = makeNo('DF');
|
|
|
+ //改变编码规则,将原来的编码后两位换成序列号
|
|
|
+ //str_pad字符串填充
|
|
|
+ $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
|
|
|
+ Db::name('order_out')->insert([
|
|
|
+ 'orderCode' => $orderCode,
|
|
|
+ 'outCode' => $outCode,
|
|
|
+ 'apply_id' => request()->user['uid'],
|
|
|
+ 'apply_name' => request()->user['nickname'],
|
|
|
+ 'addrid' => $addrid,
|
|
|
+ 'post_name' => '',
|
|
|
+ 'post_code' => '',
|
|
|
+ 'post_fee' => 0,
|
|
|
+ 'sendtime' => $date,
|
|
|
+ 'send_num' => $addr['receipt_quantity'],
|
|
|
+ 'check_num' => 0,
|
|
|
+ 'error_num' => 0,
|
|
|
+ 'wsm_code' => '',
|
|
|
+ 'order_type' => 2,
|
|
|
+ 'status' => 0,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ]);
|
|
|
+ $standing_bood_data['outCode'][] = $outCode;
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新报备单
|
|
|
Db::name('filing')
|
|
|
->where(['is_del' => 0, 'id' => $data['id'], 'supplierNo' => $data['supplierNo'], 'status' => 2])
|
|
|
- ->update(['status' => 3, 'updatetime' => $date]);
|
|
|
+ ->update(['status' => 3, 'updatetime' => $date, 'orderCode' => $orderCode, 'reason' => '']);
|
|
|
+
|
|
|
+
|
|
|
+ //待办已办先不处理
|
|
|
|
|
|
|
|
|
+ //处理台账
|
|
|
+ if (isset($standing_bood_data['outCode']) && is_array($standing_bood_data['outCode'])) $standing_bood_data['outCode'] = implode(',', $standing_bood_data['outCode']);
|
|
|
+
|
|
|
+ Db::name('standing_book')->insert($standing_bood_data);
|
|
|
+
|
|
|
Db::commit();
|
|
|
return json_show(0, '转单成功');
|
|
|
+
|
|
|
} catch (Exception $exception) {
|
|
|
Db::rollback();
|
|
|
Db::name('filing')
|
|
|
->where(['is_del' => 0, 'id' => $data['id'], 'supplierNo' => $data['supplierNo'], 'status' => 2])
|
|
|
->update(['status' => 4, 'updatetime' => $date, 'reason' => $exception->getMessage()]);
|
|
|
- return json_show(1005, $exception->getMessage());
|
|
|
+ return json_show(1005, '转单失败,' . $exception->getMessage());
|
|
|
}
|
|
|
|
|
|
}
|