|
|
@@ -71,6 +71,7 @@ class UploadForm extends Model {
|
|
|
'article' => ['file', 'token'],
|
|
|
'excel' => ['file', 'token', 'excelOption'],
|
|
|
'goodsImg' => ['file', 'token'],
|
|
|
+ 'order' => ['file', 'token'],
|
|
|
];
|
|
|
return array_merge($parentScenarios, $customScenarios);
|
|
|
}
|
|
|
@@ -122,7 +123,6 @@ class UploadForm extends Model {
|
|
|
|
|
|
/**
|
|
|
* 上传
|
|
|
- * @return bool
|
|
|
* @throws \yii\db\Exception
|
|
|
*/
|
|
|
public function upload() {
|
|
|
@@ -133,6 +133,8 @@ class UploadForm extends Model {
|
|
|
$db = \Yii::$app->db;
|
|
|
$transaction = $db->beginTransaction();
|
|
|
try {
|
|
|
+ $fileName = '';
|
|
|
+
|
|
|
switch ($this->scenario) {
|
|
|
case 'invoiceFront':
|
|
|
$uploadCategory = Uploads::CATEGORY_INVOICE;
|
|
|
@@ -156,11 +158,23 @@ class UploadForm extends Model {
|
|
|
$uploadCategory = Uploads::CATEGORY_EXCEL;
|
|
|
$uploadRemark = $this->file->baseName;
|
|
|
break;
|
|
|
+ case 'order':
|
|
|
+ if ($this->file->extension != 'csv') {
|
|
|
+ LoggerTool::info($this->file->extension);
|
|
|
+ throw new Exception('只能导入csv文件');
|
|
|
+ }
|
|
|
+
|
|
|
+ $uploadCategory = Uploads::CATEGORY_ORDER;
|
|
|
+ $fileName = date('YmdHis') . mt_rand(1000, 9999);
|
|
|
+ $uploadRemark = $this->file->baseName;
|
|
|
+ break;
|
|
|
default :
|
|
|
$uploadCategory = Uploads::CATEGORY_UN_KNOW;
|
|
|
$uploadRemark = $this->file->baseName;
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
+ $localPath = '';
|
|
|
// 上传图片到远程服务器
|
|
|
if (in_array($this->scenario, $this->_remoteScenario)) {
|
|
|
$remoteUploadApi = RemoteUploadApi::instance();
|
|
|
@@ -179,10 +193,10 @@ class UploadForm extends Model {
|
|
|
unlink($this->file->tempName);
|
|
|
} else {
|
|
|
// 生成文件名
|
|
|
-// $fileName = Tool::generateId(false);
|
|
|
- $fileName = $this->file->baseName;
|
|
|
+ $fileName = $fileName ?: $this->file->baseName;
|
|
|
// 保存在本地
|
|
|
$localPath = '/ng/Volumes/HDD/workshop/old/ar.upload.ming/files/' . $fileName . '.' . $this->file->extension;
|
|
|
+// $localPath = \Yii::getAlias('@common/runtime') . __DS__ . 'excelExport' . __DS__ . 'excel_upload' . __DS__ . $fileName . '.' . $this->file->extension;
|
|
|
if (!$this->file->saveAs($localPath)) {
|
|
|
throw new Exception('Failed');
|
|
|
}
|
|
|
@@ -192,6 +206,7 @@ class UploadForm extends Model {
|
|
|
'url' => $fileName . '.' . $this->file->extension,
|
|
|
'fileSize' => null,
|
|
|
'md5' => null,
|
|
|
+ 'localPath' => $localPath,
|
|
|
];
|
|
|
}
|
|
|
// 把上传的文件写入数据库记录中
|
|
|
@@ -285,17 +300,37 @@ class UploadForm extends Model {
|
|
|
}
|
|
|
}elseif ($this->scenario == 'proveFront') {
|
|
|
// 如果是上传充值凭证,绑定充值记录
|
|
|
- $recharge = Recharge::findOne(['ID' => $this->rechargeId]);
|
|
|
- if(!$recharge){
|
|
|
- throw new Exception("缺少参数ID");
|
|
|
- }
|
|
|
- //写入充值表
|
|
|
- $recharge->BANK_PROVE = $uploadInfo['url'];
|
|
|
- $recharge->AUDIT_STATUS = Recharge::STATUS_PROVED;
|
|
|
- if (!$recharge->save()) {
|
|
|
- throw new Exception(Form::formatErrorsForApi($recharge->getErrors()));
|
|
|
- }
|
|
|
+ $recharge = Recharge::findOne(['ID' => $this->rechargeId]);
|
|
|
+ if(!$recharge){
|
|
|
+ throw new Exception("缺少参数ID");
|
|
|
+ }
|
|
|
+ //写入充值表
|
|
|
+ $recharge->BANK_PROVE = $uploadInfo['url'];
|
|
|
+ $recharge->AUDIT_STATUS = Recharge::STATUS_PROVED;
|
|
|
+ if (!$recharge->save()) {
|
|
|
+ throw new Exception(Form::formatErrorsForApi($recharge->getErrors()));
|
|
|
+ }
|
|
|
+ } elseif ($this->scenario == 'order') {
|
|
|
+ // 执行订单上传服务
|
|
|
+ $orderForm = new ExcelOrderForm();
|
|
|
+ $run = $orderForm->run($uploadInfo['localPath']);
|
|
|
+ if ($run !== true) {
|
|
|
+ throw new Exception(Form::formatErrorsForApi($run));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 把上传的文件写入到导入记录中
|
|
|
+ $excelImport = new ExcelImport();
|
|
|
+ $excelImport->OPTION_NAME = '订单上传';
|
|
|
+ $excelImport->TABLE_NAME = '';
|
|
|
+ $excelImport->UPLOAD_ID = $uploads->ID;
|
|
|
+ $excelImport->AUDIT_STATUS = \Yii::$app->params['auditStatus']['true']['value'];
|
|
|
+ $excelImport->IMPORT_ADMIN_ID = \Yii::$app->user->id;
|
|
|
+ $excelImport->AUDIT_ADMIN_ID = \Yii::$app->user->id;
|
|
|
+ $excelImport->CREATED_AT = Date::nowTime();
|
|
|
+ if (!$excelImport->save()) {
|
|
|
+ throw new Exception(Form::formatErrorsForApi($excelImport->getErrors()));
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
$transaction->commit();
|
|
|
} catch (Exception $e) {
|
|
|
@@ -304,6 +339,10 @@ class UploadForm extends Model {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ if ($this->scenario == 'order') {
|
|
|
+ $uploads->URL = $localPath;
|
|
|
+ }
|
|
|
+
|
|
|
return $uploads;
|
|
|
}
|
|
|
}
|