Przeglądaj źródła

Merge branch 'feature/mod-import-order-excel' of http://16.162.42.175:8014/guanli/aklast into feature/mod-import-order-excel

kevin_zhangl 3 lat temu
rodzic
commit
19b0c4d216

+ 16 - 0
common/helpers/Excel.php

@@ -25,6 +25,7 @@ use common\models\forms\RegInfoAuditForm;
 use common\models\forms\WithdrawForm;
 use common\models\Uploads;
 use common\models\UserNetwork;
+use common\models\User;
 use yii\base\BaseObject;
 use yii\base\Exception;
 use yii\base\StaticInstanceTrait;
@@ -829,6 +830,21 @@ class Excel extends BaseObject {
                 'storeFile' => $tempFileName,
                 'dropKeysRow' => $startRow == 1 ? false : true,
             ]);
+            $errUserArray = [];
+            foreach ($data as $u){ // 记录了导入中不存在的会员
+                $u['USER_NAME'] = trim($u['会员编号']);
+                if(!$u['USER_NAME']){
+                    continue;
+                }
+                $userInfo = User::checkUser($u['USER_NAME']);
+                if(!$userInfo){
+                    $errUserArray[] = $u['USER_NAME'];
+                }
+            }
+            if(count($errUserArray)>0){
+                $errUserStr = implode(', ', $errUserArray);
+                throw new Exception(count($errUserArray).'个用户不存在:'.substr($errUserStr,0, 600).'...');
+            }
         } catch (\Exception $e) {
             throw new Exception($e->getMessage());
         }

+ 4 - 0
common/models/User.php

@@ -224,6 +224,10 @@ class User extends \common\components\ActiveRecord
         return $this->hasOne(UserInfo::class, ['USER_ID' => 'ID']);
     }
 
+    public static function checkUser($userName){
+        return self::find()->select('ID')->where('USER_NAME=:USER_NAME', [':USER_NAME'=>$userName])->asArray()->one();
+    }
+
     /**
      * 获取会员基本信息
      * @param $userId

+ 5 - 5
common/models/forms/ExcelOrderShopForm.php

@@ -80,13 +80,13 @@ class ExcelOrderShopForm extends \common\components\ActiveRecord
 
             $formatOrderData = [];
             $formatOrderGoodsData = [];
-            foreach ($everyData as $key => $value) {
+            foreach ($everyData as $key => $value) { // 读取excel内容
                 if(isset(self::EXCEL_ORDER_SHOP_FIELD[$key])) {
-                    $formatOrderData[self::EXCEL_ORDER_SHOP_FIELD[$key]] = $value;
+                    $formatOrderData[self::EXCEL_ORDER_SHOP_FIELD[$key]] = trim($value);
                 }
 
                 if(isset(self::EXCEL_ORDER_SHOP_GOODS_FIELD[$key])) {
-                    $formatOrderGoodsData[self::EXCEL_ORDER_SHOP_GOODS_FIELD[$key]] = $value;
+                    $formatOrderGoodsData[self::EXCEL_ORDER_SHOP_GOODS_FIELD[$key]] = trim($value);
                 }
             }
 
@@ -103,10 +103,10 @@ class ExcelOrderShopForm extends \common\components\ActiveRecord
             }
 
             //判断商城订单是表中是否已经存在该订单
-            $one = OrderShop::find()->select(["USER_ID", "PERIOD_NUM", "SN", "ORDER_AMOUNT", "PV", "PAY_AMOUNT", "PAY_PV"])->where('SN=:SN', ['SN' => $formatOrderGoodsData['ORDER_SN']])->asArray()->one();
+            $one = OrderShop::find()->select(["USER_ID", "PERIOD_NUM", "ORDER_DAY", "SN", "ORDER_AMOUNT", "PV", "PAY_AMOUNT", "PAY_PV"])->where('SN=:SN', ['SN' => $formatOrderGoodsData['ORDER_SN']])->asArray()->one();
             if ($one) {
 
-                if ( $one['PERIOD_NUM'] != $formatOrderData['PERIOD_NUM'] ) {
+                if ( $one['PERIOD_NUM'] != $formatOrderData['PERIOD_NUM'] || $one['ORDER_DAY'] != $orderDay) {
                     throw new \Exception(sprintf('订单号【%s】重复不可以导入', $formatOrderGoodsData['ORDER_SN']));
                 }