shish 6 лет назад
Родитель
Сommit
de001e121b

+ 6 - 6
app/business/controllers/UserController.php

@@ -89,11 +89,11 @@ class UserController extends BaseController
 		if (!empty($user)) {
 			util::fail('手机号已使用,客户已存在');
 		}
-		
-		$userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
-		$source = $userSource['name'];
-		
-		
+
+		$post['merchantId'] = $this->merchantId;
+		$post['member'] = $post['memberLevel'];
+		UserService::addUser($post);
+
 		util::ok();
 	}
 	
@@ -148,7 +148,7 @@ class UserController extends BaseController
 		if ($userAsset['member'] != -1 && $userAsset['member'] >= $member) {
 			util::fail('客户已经达到此级别了');
 		}
-
+		
 		$now = time();
 		$date = date("Y-m-d H:i", $now);
 		

+ 20 - 11
biz/user/services/UserService.php

@@ -291,30 +291,39 @@ class UserService extends BaseService
 	public static function addUser($data)
 	{
 		//merchantId $source $realName $member $growth $balance $mobile
-		validate::easyCheck(['merchantId','source','mobile'], $data);
+		//必传参数
+		validate::easyCheck(['merchantId', 'mobile'], $data);
 
 		$merchantId = $data['merchantId'];
-		$source = $data['source'];
+		$source = isset($data['source']) ? $data['source'] : 0;
 		$mobile = $data['mobile'];
 		$realName = isset($data['realName']) ? $data['realName'] : $mobile;
-
+		$member = isset($data['member']) ? $data['member'] : -1;
+		$balance = isset($data['balance']) ? $data['balance'] : 0;
+		
 		$originalInfo = [];
 		$originalInfo['merchantId'] = $merchantId;
 		$originalInfo['mobile'] = $mobile;
 		$originalInfo['realName'] = $realName;
-
+		
 		$user = UserService::replaceUser($originalInfo, $source, $merchantId);
-
-		//等级
+		
 		$extend = MerchantExtendService::getByMerchantId($merchantId);
-		$gradeList = xhMerchantExtendService::getGradeList($extend, 'desc');
-		$growth = isset($gradeList[$member]['growth']) ? $gradeList[$member]['growth'] : 0;
-
+		
+		//等级
+		$growth = 0;
+		if ($member > 0) {
+			$gradeList = xhMerchantExtendService::getGradeList($extend, 'desc');
+			$growth = isset($gradeList[$member]['growth']) ? $gradeList[$member]['growth'] : 0;
+		}
+		
 		//余额成长值更新
 		$userId = $user['id'];
-		$data = ['balance' => $balance, 'growth' => $growth];
+		$data = [];
+		$data['growth'] = $growth;
+		$data['balance'] = $balance > 0 ? $balance : 0;
 		UserAssetService::updateByUserId($userId, $data);
-
+		
 		//会员升级
 		UserIntegralService::increaseToUpgrade(0, $growth, 0, $userId, $merchantId, $extend);
 	}

+ 1 - 5
common/components/validate.php

@@ -11,15 +11,11 @@ class validate
 	public static function easyCheck($valid, $data)
 	{
 		$keyList = array_keys($data);
-		$validPass = true;
 		foreach ($valid as $val) {
 			if (in_array($val, $keyList) == false) {
-				error::instance()->setError('缺少必要参数:' . $val);
-				$validPass = false;
-				break;
+				util::fail('缺少必要参数:' . $val);
 			}
 		}
-		return $validPass;
 	}
 	
 	// 示例 $valid = [['title', 'numeric|min:2|max:40', '请确认标题'],['targetId', 'required|int', '目标不存在'],['type', 'required|int|min:2', '类型无效']];