|
@@ -0,0 +1,131 @@
|
|
|
+<?php
|
|
|
+declare (strict_types=1);
|
|
|
+
|
|
|
+namespace app\command;
|
|
|
+
|
|
|
+use app\admin\model\OrderImportFromC as OIFCModel;
|
|
|
+use think\console\Command;
|
|
|
+use think\console\Input;
|
|
|
+use think\console\input\Argument;
|
|
|
+use think\console\input\Option;
|
|
|
+use think\console\Output;
|
|
|
+use think\facade\Db;
|
|
|
+use think\facade\Validate;
|
|
|
+
|
|
|
+//C端订单导入
|
|
|
+class ImportOrderFromC extends Command
|
|
|
+{
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ // 指令配置
|
|
|
+ $this->setName('analysisData')
|
|
|
+ ->setDescription('批量解析C端导入的订单数据');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //【脚本1】解析用户导入的数据
|
|
|
+ protected function execute(Input $input, Output $output)
|
|
|
+ {
|
|
|
+ //解析信息存到extend表,其中customer_code字段根据订单编号去customer_info查,其他根据商品编号查询
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $order_import_from_c_db = Db::name('order_import_from_c');
|
|
|
+
|
|
|
+ $order_import_from_c_extend_db = Db::name('order_import_from_c_extend');
|
|
|
+// $customer_info_db = Db::name('customer_info')->field('companyNo')->where(['is_del' => 0]);
|
|
|
+
|
|
|
+ $rs = $order_import_from_c_db
|
|
|
+ ->where([
|
|
|
+ 'is_del' => OIFCModel::$is_del_normal,
|
|
|
+ 'status' => OIFCModel::$status_wait_validate
|
|
|
+ ])->find();
|
|
|
+
|
|
|
+ //加写锁
|
|
|
+
|
|
|
+ //1.数据校验
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'platform_code|平台订单号' => 'require',
|
|
|
+ 'platform_time|平台下单时间' => 'require|date',
|
|
|
+ 'sale_source|销售渠道' => 'require',
|
|
|
+ 'plat_code|平台商品编号' => 'require',
|
|
|
+ 'price|单价' => 'require|float',
|
|
|
+ 'num|数量' => 'require|number',
|
|
|
+ 'before_discount_all_price|优惠前总金额' => 'require|float',
|
|
|
+ 'mode|收费模式' => 'require',
|
|
|
+ 'contactor|收货人' => 'require',
|
|
|
+ 'mobile|联系电话' => 'require',
|
|
|
+ 'addr|联系地址' => 'require',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $update_c_data = ['updatetime' => date('Y-m-d H:i:s')];
|
|
|
+ if (!$val->check($rs)) {
|
|
|
+ $update_c_data['status'] = OIFCModel::$status_wait_confirm;
|
|
|
+ $update_c_data['remark'] = '数据格式不对,' . $val->getError();
|
|
|
+ }
|
|
|
+
|
|
|
+ $extend_insert_data = [
|
|
|
+ 'order_import_from_c_id' => $rs['id'],
|
|
|
+ 'createrid' => 0,
|
|
|
+ 'creater' => 'system',
|
|
|
+ 'discount_reason' => $rs['activity_name']
|
|
|
+ ];
|
|
|
+
|
|
|
+ //组织extend的数据
|
|
|
+ $good_platform_info = Db::name('good_platform')
|
|
|
+ ->field('id,spuCode,platform_code,skuCode')
|
|
|
+ ->where(['is_del' => 0])
|
|
|
+ ->where('plat_code', $rs['plat_code'])
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ if (!empty($good_platform_info)) {
|
|
|
+ $extend_insert_data['spuCode'] = $good_platform_info['spuCode'];
|
|
|
+ $extend_insert_data['platform_codes'] = $good_platform_info['platform_code'];
|
|
|
+
|
|
|
+ $good_info = Db::name('good')
|
|
|
+ ->field('good_name,good_code,companyNo,supplierNo,is_stock,packing_fee,cert_fee,open_fee,cost_fee,mark_fee,demo_fee,cat_id')
|
|
|
+ ->where(['is_del' => 0])
|
|
|
+ ->where('spuCode', $extend_insert_data['spuCode'])
|
|
|
+ ->find();
|
|
|
+ if (!empty($good_info)) {
|
|
|
+ $extend_insert_data['companyNo'] = $good_info['companyNo'];
|
|
|
+ $extend_insert_data['supplierNo'] = $good_info['supplierNo'];
|
|
|
+ $extend_insert_data['good_name'] = $good_info['good_name'];
|
|
|
+ } else {
|
|
|
+ $update_c_data['status'] = OIFCModel::$status_wait_confirm;
|
|
|
+ $update_c_data['remark'] = isset($update_c_data['remark']) ? $update_c_data['remark'] . ',在上线商品表中查不到spuCode对应的商品信息' : '在上线商品表中查不到spuCode对应的商品信息';
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ $update_c_data['status'] = OIFCModel::$status_wait_confirm;
|
|
|
+ $update_c_data['remark'] = isset($update_c_data['remark']) ? $update_c_data['remark'] . ',在商品平台表中查不到平台商品编号对应的spuCode' : '在商品平台表中查不到平台商品编号对应的spuCode';
|
|
|
+ }
|
|
|
+
|
|
|
+ $order_import_from_c_extend_db->insertGetId($extend_insert_data);
|
|
|
+
|
|
|
+ if (!isset($update_c_data['status'])) $update_c_data['status'] = OIFCModel::$status_wait_relation;
|
|
|
+
|
|
|
+ $order_import_from_c_db
|
|
|
+ ->where([
|
|
|
+ 'id' => $rs['id'],
|
|
|
+ 'is_del' => OIFCModel::$is_del_normal,
|
|
|
+ 'status' => OIFCModel::$status_wait_validate
|
|
|
+ ])->update($update_c_data);
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+
|
|
|
+ // 指令输出
|
|
|
+ $output->writeln('解析成功');
|
|
|
+
|
|
|
+ } catch (\think\Exception $exception) {
|
|
|
+ Db::rollback();
|
|
|
+ // 指令输出
|
|
|
+ $output->writeln('解析失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|