|
|
@@ -21,6 +21,7 @@ use common\models\DeclarationLevel;
|
|
|
use common\models\Region;
|
|
|
use common\models\ShopGoods;
|
|
|
use common\models\BaUser;
|
|
|
+use common\models\UserInfo;
|
|
|
use common\models\BaUserInfo;
|
|
|
use common\models\UserNetwork;
|
|
|
use common\models\UserRelation;
|
|
|
@@ -169,7 +170,7 @@ class BaDeclarationForm extends Model
|
|
|
* @param $attribute
|
|
|
*/
|
|
|
public function issetDec($attribute){
|
|
|
- if (!$decUser = User::find()->select('ID')->where('IS_DEC=1 AND USER_NAME=:USER_NAME', [':USER_NAME' => $this->decUserName])->asArray()->one()) {
|
|
|
+ if (!$decUser = BaUser::find()->select('ID')->where('IS_DEC=1 AND USER_NAME=:USER_NAME', [':USER_NAME' => $this->decUserName])->asArray()->one()) {
|
|
|
$this->addError($attribute, 'Stockist does not exist'); // 报单中心不存在
|
|
|
return false;
|
|
|
} else {
|
|
|
@@ -177,6 +178,76 @@ class BaDeclarationForm extends Model
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 判断开拓人
|
|
|
+ * @param $attribute
|
|
|
+ */
|
|
|
+ public function isRecUserName($attribute){
|
|
|
+ if($this->type == self::TYPE_ZC){
|
|
|
+ // 开拓人
|
|
|
+// if(!isset($this->_tempParentUser[$this->recUserName])){
|
|
|
+// $recUserTemp = UserInfo::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => $this->recUserName]);
|
|
|
+// if(!$recUserTemp){
|
|
|
+// if($this->insertUserName){
|
|
|
+// //$this->addError($attribute, '为'.$this->insertUserName.'报单,开拓人'.$this->recUserName.'不存在');
|
|
|
+// $this->addError($attribute, 'To'.$this->insertUserName.'Entry, Sponsor'.$this->recUserName.'not in exist');
|
|
|
+// } else {
|
|
|
+// // $this->addError($attribute, '开拓人'.$this->recUserName.'不存在');
|
|
|
+// $this->addError($attribute, 'Sponsor'.$this->recUserName.'not in exist');
|
|
|
+// }
|
|
|
+//
|
|
|
+// return ;
|
|
|
+// }
|
|
|
+// $recUserTemp['CON_NUM'] = UserNetwork::firstFloorChildNum($recUserTemp['USER_ID']);
|
|
|
+// $recUserTemp['REC_NUM'] = UserRelation::firstFloorChildNum($recUserTemp['USER_ID']);
|
|
|
+// $this->_tempParentUser[$this->recUserName] = [
|
|
|
+// 'USER_NAME' => $this->recUserName,
|
|
|
+// 'ZC_PV' => $recUserTemp['ZC_PV'],
|
|
|
+// 'CON_USER_NAME' => Info::getUserNameByUserId($recUserTemp['CON_UID']),
|
|
|
+// 'REC_USER_NAME' => Info::getUserNameByUserId($recUserTemp['REC_UID']),
|
|
|
+// 'CON_NUM' => $recUserTemp['CON_NUM'],
|
|
|
+// 'REC_NUM' => $recUserTemp['REC_NUM'],
|
|
|
+// 'SYSTEM_ID' => $recUserTemp['SYSTEM_ID'],
|
|
|
+// 'LOCATION' => UserNetwork::getLocation($recUserTemp['USER_ID'], $recUserTemp['CON_UID']),
|
|
|
+// ];
|
|
|
+// // 把该会员下面的5个区是否存在会员都付上
|
|
|
+// for($i=1;$i<=5;$i++){
|
|
|
+// $this->_tempParentUser[$this->recUserName]["LOCATION$i"] = UserNetwork::issetUserInLocation($recUserTemp['USER_ID'], $i);
|
|
|
+// }
|
|
|
+// }
|
|
|
+ $recUser = $this->_tempParentUser[$this->recUserName];
|
|
|
+ $this->_tempParentUser[$this->recUserName]['REC_NUM'] += 1;
|
|
|
+
|
|
|
+ // 存在新加入会员时查看开拓人是否在新加入会员的安置网上级中
|
|
|
+// if($this->insertUserName) {
|
|
|
+// $this->loopFindParentToNetwork($this->insertUserName);
|
|
|
+// if (!$this->recUserIsInNetworkParent()) {
|
|
|
+// // $this->addError($attribute, '为' . $this->insertUserName . '报单,开拓人' . $this->recUserName . '不在' . $this->insertUserName . '的安置网上级中');
|
|
|
+// $this->addError($attribute, 'To' . $this->insertUserName . 'Entry, Sponsor' . $this->recUserName . 'not in exist' . $this->insertUserName . 'in the placement superiors');
|
|
|
+// return ;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 把自己加入到临时上级会员数组中
|
|
|
+// $this->_tempParentUser[$this->insertUserName] = [
|
|
|
+// 'USER_NAME' => $this->insertUserName,
|
|
|
+// //'ZC_PV' => $this->decPv,
|
|
|
+// 'CON_USER_NAME' => $this->conUserName,
|
|
|
+// 'REC_USER_NAME' => $this->recUserName,
|
|
|
+// 'CON_NUM' => 0,
|
|
|
+// 'REC_NUM' => 0,
|
|
|
+// 'SYSTEM_ID' => $recUser['SYSTEM_ID'],
|
|
|
+// 'LOCATION' => $this->location,
|
|
|
+// 'LOCATION1' => 0,
|
|
|
+// 'LOCATION2' => 0,
|
|
|
+// 'LOCATION3' => 0,
|
|
|
+// 'LOCATION4' => 0,
|
|
|
+// 'LOCATION5' => 0,
|
|
|
+// ];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 添加报单
|
|
|
* @param $allData
|
|
|
@@ -201,47 +272,33 @@ class BaDeclarationForm extends Model
|
|
|
// if(!$this->decLv){
|
|
|
// throw new Exception('Please select the entry level'); // 请选择报单级别
|
|
|
// }
|
|
|
- if($this->decWay==1) {
|
|
|
-// $decPackage = BaDeclarationPackage::findOneAsArray('ID=:ID', [':ID'=>$this->packageId]);
|
|
|
-// $this->_decAmount = $decPackage['AMOUNT'];
|
|
|
-// $this->_decPv = $decPackage['PV'];
|
|
|
-// $this->_orderGoods[] = [
|
|
|
-// 'GOODS_ID' => $this->packageId,
|
|
|
-// 'PRICE' => $this->_decAmount,
|
|
|
-// 'REAL_PRICE' => $this->_decAmount,
|
|
|
-// 'PV' => $this->_decPv,
|
|
|
-// 'REAL_PV' => $this->_decPv,
|
|
|
-// 'BUY_NUMS' => 1,
|
|
|
-// 'SKU_CODE' => $decPackage['PACKAGE_NO'],
|
|
|
-// 'GOODS_TITLE' => $decPackage['PACKAGE_NAME'],
|
|
|
-// 'EMAIL' => $this->email
|
|
|
-// ];
|
|
|
- }else{
|
|
|
- $ids = $this->goodsId;
|
|
|
- $totalAmount = 0;
|
|
|
- $totalPv = 0;
|
|
|
- foreach ($this->goodsNum as $k => $v) {
|
|
|
- if ($v) {
|
|
|
- $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
|
|
|
- if($goods['STORE_NUMS']>0){
|
|
|
- $totalAmount += $goods['SELL_PRICE'] * intval($v);
|
|
|
- $totalPv += $goods['PRICE_PV'] * intval($v);
|
|
|
- $this->_orderGoods[] = [
|
|
|
- 'GOODS_ID' => $goods['ID'],
|
|
|
- 'PRICE' => $goods['SELL_PRICE'],
|
|
|
- 'REAL_PRICE' => $goods['SELL_PRICE'],
|
|
|
- 'PV' => $goods['PRICE_PV'],
|
|
|
- 'REAL_PV' => $goods['PRICE_PV'],
|
|
|
- 'POINT' => $goods['POINT'],
|
|
|
- 'BUY_NUMS' => intval($v),
|
|
|
- 'SKU_CODE' => $goods['GOODS_NO'],
|
|
|
- 'GOODS_TITLE' => $goods['GOODS_NAME'],
|
|
|
- 'EMAIL' => $this->email,
|
|
|
- 'TAX_RATE' => $goods['TAX_RATE'],
|
|
|
- ];
|
|
|
- }
|
|
|
+
|
|
|
+ $ids = $this->goodsId;
|
|
|
+ $totalAmount = 0;
|
|
|
+ $totalPv = 0;
|
|
|
+
|
|
|
+ foreach ($this->goodsNum as $k => $v) {
|
|
|
+ if ($v) {
|
|
|
+ $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
|
|
|
+ if($goods['STORE_NUMS']>0){
|
|
|
+ $totalAmount += $goods['SELL_PRICE'] * intval($v);
|
|
|
+ $totalPv += $goods['PRICE_PV'] * intval($v);
|
|
|
+ $this->_orderGoods[] = [
|
|
|
+ 'GOODS_ID' => $goods['ID'],
|
|
|
+ 'PRICE' => $goods['SELL_PRICE'],
|
|
|
+ 'REAL_PRICE' => $goods['SELL_PRICE'],
|
|
|
+ 'PV' => $goods['PRICE_PV'],
|
|
|
+ 'REAL_PV' => $goods['PRICE_PV'],
|
|
|
+ 'POINT' => $goods['POINT'],
|
|
|
+ 'BUY_NUMS' => intval($v),
|
|
|
+ 'SKU_CODE' => $goods['GOODS_NO'],
|
|
|
+ 'GOODS_TITLE' => $goods['GOODS_NAME'],
|
|
|
+ 'EMAIL' => $this->email,
|
|
|
+ 'TAX_RATE' => $goods['TAX_RATE'],
|
|
|
+ ];
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
// if($totalPv<$decLevel['PERF']){
|
|
|
// throw new Exception('The total BV of self selected goods cannot be less than the BV of the selected entry level');//自选商品总BV不能小于所选报单级别BV
|
|
|
// }
|
|
|
@@ -253,18 +310,19 @@ class BaDeclarationForm extends Model
|
|
|
// if($this->decLv!=$toDecLevel){
|
|
|
// throw new Exception('The total BV of self selected goods cannot exceed the BV value of the next level under the selected level');//自选商品总BV不能超过已选级别下一个级别的BV值
|
|
|
// }
|
|
|
- $this->_decAmount = $totalAmount;
|
|
|
+ $this->_decAmount = $totalAmount;
|
|
|
// $this->_decPv = $totalPv;
|
|
|
- }
|
|
|
+
|
|
|
//看现金余额是否充足
|
|
|
$loginUserId = \Yii::$app->user->id;
|
|
|
if (Cash::getAvailableBalance($loginUserId) < $this->_decAmount){
|
|
|
throw new Exception('The applicant is short of cash and cannot complete the declaration');//报单人现金不足,无法完成报单
|
|
|
}
|
|
|
-
|
|
|
+// print_r($allData);exit;
|
|
|
if(!($zcResult = $this->addBaUser($allData))) {
|
|
|
throw new Exception(Form::formatErrorsForApi($this->_userForm->getErrors()));
|
|
|
}
|
|
|
+// print_r($allData);exit;
|
|
|
if(!($decResult = $this->addBaDecOrder())) {
|
|
|
throw new Exception(Form::formatErrorsForApi($decResult->getErrors()));
|
|
|
}
|
|
|
@@ -325,12 +383,13 @@ class BaDeclarationForm extends Model
|
|
|
$userForm->userId = $this->_insertUserId;
|
|
|
$userForm->userName = $this->insertUserName;
|
|
|
// $userForm->zcPv = $this->_decPv;
|
|
|
-// $userForm->zcAmount = $this->_decAmount;
|
|
|
+ $userForm->zcAmount = $this->_decAmount;
|
|
|
// $userForm->conUserName = $this->conUserName;
|
|
|
$userForm->recUserName = $this->recUserName;
|
|
|
// $userForm->location = $this->location;
|
|
|
$userForm->idCard = $this->mobile;
|
|
|
$userForm->allData = $allData;
|
|
|
+// print_r($userForm);exit;
|
|
|
if(!$userForm->validate()){
|
|
|
$this->addErrors($userForm->getErrors());
|
|
|
return false;
|
|
|
@@ -361,14 +420,14 @@ class BaDeclarationForm extends Model
|
|
|
$decOrderModel->USER_ID = \Yii::$app->user->id;
|
|
|
$decOrderModel->TO_USER_ID = $this->_insertUserId;
|
|
|
$decOrderModel->DEC_AMOUNT = $this->_decAmount;
|
|
|
- $decOrderModel->DEC_PV = $this->_decPv;
|
|
|
+// $decOrderModel->DEC_PV = $this->_decPv;
|
|
|
$decOrderModel->PERIOD_NUM = $nowPeriodNum;
|
|
|
$decOrderModel->CALC_MONTH = $nowCalcMonth;
|
|
|
$decOrderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
|
|
|
$decOrderModel->PAID_WALLET = 'cash';
|
|
|
- $decOrderModel->CON_USER_ID = Info::getUserIdByUserName($this->conUserName);
|
|
|
+// $decOrderModel->CON_USER_ID = Info::getUserIdByUserName($this->conUserName);
|
|
|
$decOrderModel->REC_USER_ID = Info::getUserIdByUserName($this->recUserName);
|
|
|
- $decOrderModel->DEC_ID = $this->_decId;
|
|
|
+// $decOrderModel->DEC_ID = $this->_decId;
|
|
|
$decOrderModel->IS_DEL = 0;
|
|
|
$decOrderModel->CREATED_AT = Date::nowTime();
|
|
|
if(!$decOrderModel->save()){
|
|
|
@@ -391,9 +450,9 @@ class BaDeclarationForm extends Model
|
|
|
$orderModel->USER_ID = $this->_insertUserId;
|
|
|
$orderModel->USER_NAME = $this->insertUserName;
|
|
|
$orderModel->ORDER_AMOUNT = $this->_decAmount;
|
|
|
- $orderModel->PV = $this->_decPv;
|
|
|
+// $orderModel->PV = $this->_decPv;
|
|
|
$orderModel->PAY_AMOUNT = $this->_decAmount;
|
|
|
- $orderModel->PAY_PV = $this->_decPv;
|
|
|
+// $orderModel->PAY_PV = $this->_decPv;
|
|
|
$orderModel->PAY_AT = Date::nowTime();
|
|
|
$orderModel->PAY_TYPE = 'cash';
|
|
|
$orderModel->PERIOD_NUM = $nowPeriodNum;
|
|
|
@@ -439,14 +498,12 @@ class BaDeclarationForm extends Model
|
|
|
if(!$addressModel->save()){
|
|
|
throw new Exception(Form::formatErrorsForApi($addressModel->getErrors()));
|
|
|
}
|
|
|
- //扣报单人现金钱包
|
|
|
-// Cash::changeUserCash(\Yii::$app->user->id, 'CASH', -abs($this->_decAmount), ['REMARK' =>'为'.$this->insertUserName.'报单']);
|
|
|
- Cash::changeUserCash(\Yii::$app->user->id, 'CASH', -abs($this->_decAmount), ['REMARK' =>'To'.$this->insertUserName.'Entry']);
|
|
|
- return $addressModel;
|
|
|
}else{
|
|
|
$addressModel = new ReceiveAddress();
|
|
|
- return $addressModel;
|
|
|
}
|
|
|
+ //扣报单人现金钱包
|
|
|
+ Cash::changeUserCash(\Yii::$app->user->id, 'CASH', -abs($this->_decAmount), ['REMARK' =>'To'.$this->insertUserName.'Entry']); // 报单
|
|
|
+ return $addressModel;
|
|
|
}
|
|
|
|
|
|
/**
|