ApproachDeclarationUpgradeForm.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <?php
  2. namespace common\models\forms;
  3. use common\components\Model;
  4. use common\helpers\Cache;
  5. use common\helpers\Date;
  6. use common\helpers\Form;
  7. use common\helpers\user\Cash;
  8. use common\helpers\user\Info;
  9. use common\models\ApproachDecOrder;
  10. use common\models\ApproachOrder;
  11. use common\models\ApproachOrderGoods;
  12. use common\models\Config;
  13. use common\models\Countries;
  14. use common\models\CurrencyConversions;
  15. use common\models\DeclarationLevel;
  16. use common\models\DeclarationPackage;
  17. use common\models\DecLevelLog;
  18. use common\models\DecOrder;
  19. use common\models\EmployLevel;
  20. use common\models\Instalment;
  21. use common\models\Order;
  22. use common\models\OrderGoods;
  23. use common\models\Period;
  24. use common\models\ReceiveAddress;
  25. use common\models\Region;
  26. use common\models\ShopGoods;
  27. use common\models\ShopGoodsNature;
  28. use common\models\User;
  29. use common\models\UserInfo;
  30. use common\models\UserNetwork;
  31. use Yii;
  32. use yii\base\Exception;
  33. /**
  34. * 升级管理,进行升级
  35. */
  36. class ApproachDeclarationUpgradeForm extends Model
  37. {
  38. public $type;
  39. public $decLv;
  40. public $decWay;
  41. public $packageId;
  42. public $goodsId;
  43. public $goodsNum;
  44. public $insertUserName;
  45. public $consignee;
  46. public $acceptMobile;
  47. public $province;
  48. public $city;
  49. public $county;
  50. public $lgaName;
  51. public $cityName;
  52. public $address;
  53. public $nowPerf;
  54. public $nextPerf;
  55. public $decUserName;
  56. public $remark;
  57. public $payType;
  58. // 传过来的全部数据
  59. public $allData;
  60. private $_decId;
  61. public $_insertUserId;
  62. private $_decAmount;
  63. private $_decPv;
  64. private $_orderGoods;
  65. private $_standardAmount;
  66. private $_decAmountStandard;
  67. const TYPE_ZC = 'ZC';
  68. private $_userForm = null;
  69. // 全部的安置网上级
  70. private $_tempNetworkParentUser = [];
  71. /**
  72. * @inheritdoc
  73. */
  74. public function rules()
  75. {
  76. return [
  77. [['remark','type','decLv','decWay','packageId','goodsId', 'goodsNum', 'insertUserName','consignee','acceptMobile','province',/*'city','county',*/'lgaName','cityName','address','nowPerf','nextPerf'], 'trim'],
  78. [['type','decLv','decWay','insertUserName','nowPerf','province',/*'city','county',*/'address','acceptMobile'], 'required'],
  79. [['decUserName'], 'issetDec'], // 必须是报单中心
  80. [['decWay'], 'hasProduct'],// 必须选择商品
  81. [['decLv'], 'alreadyMaxDec'], //判断要升级用户是否已经是最高级
  82. ];
  83. }
  84. public function attributeLabels()
  85. {
  86. return [
  87. 'type' => 'Upgrade type',//升级类型
  88. 'decLv' => 'Upgrade level',//升级级别
  89. 'decWay' => 'Declaration method',//报单方式
  90. 'packageId' => 'Upgrade package',//升级套餐
  91. 'goodsId' => 'Product ID',//商品ID
  92. 'goodsNum' => 'Product quantity',//商品数量
  93. 'insertUserName' => 'Member number to be upgraded',//要升级的会员编号
  94. 'consignee' => 'consignee',//收货人
  95. 'acceptMobile' => 'The phone number of Consignee',//收货人手机
  96. 'province' => 'Receiving Province',//收货省
  97. 'city' => 'Receiving City',//收货市
  98. 'county' => 'Receiving area / county',//收货区县
  99. 'lgaName' => 'Local Government Area',
  100. 'cityName' => 'City',
  101. 'address' => 'Receiving detailed address',//收货详细地址
  102. ];
  103. }
  104. /**
  105. * 添加报单
  106. * @param $allData
  107. * @throws Exception
  108. * @throws \yii\db\Exception
  109. */
  110. public function add($allData){
  111. if(!$this->validate()){
  112. return null;
  113. }
  114. $hasInstalment = 0;
  115. // 首购单
  116. if($this->type == self::TYPE_ZC){
  117. //报单商品及PV判断
  118. $decLevelConfig = Cache::getDecLevelConfig();
  119. $decLevel = $decLevelConfig[$this->decLv];
  120. $toDecLevel = $this->decLv;
  121. if(!$this->decLv){
  122. throw new Exception(Yii::t('app', 'pleaseSelectUpgradeLevel'), 400);
  123. }
  124. $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
  125. $userId = $baseInfo['ID'];
  126. $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
  127. if ($userDecPvSum != $this->nowPerf) {
  128. throw new Exception(Yii::t('app', 'checkPerformanceOfUpgradedMember'), 400);
  129. }
  130. // 获取用户是否是观察期
  131. $observe = Config::getConfigByType('observe'); // 获取观察期配置信息
  132. $observeLimit = $observe['observePeriodLimit']['value']; // 月份限制
  133. $isObserve = User::checkIsObserve($baseInfo['CREATED_AT'], $observeLimit); // 判断用户是否再观察期中
  134. $diffPerf = $isObserve ? $this->nowPerf : 0; // 观察期内升级要加上用户累计的PV,全额则基础PV为0,全额购买
  135. if ($this->decWay != 2) {
  136. throw new Exception(Yii::t('app', 'upgradeMethodIncorrect'), 400);
  137. }
  138. // 报单中心汇率
  139. $decCountry = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  140. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  141. // 升级会员汇率
  142. $country = Countries::getById($baseInfo['COUNTRY_ID']);
  143. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  144. if($this->decWay==1) {
  145. // 先不加套餐升级方式
  146. // $decPackage = DeclarationPackage::findOneAsArray('ID=:ID', [':ID'=>$this->packageId]);
  147. // $this->_decAmount = $decPackage['AMOUNT'];
  148. // $this->_decPv = $decPackage['PV'];
  149. // $this->_orderGoods[] = [
  150. // 'GOODS_ID' => $this->packageId,
  151. // 'PRICE' => $this->_decAmount,
  152. // 'REAL_PRICE' => $this->_decAmount,
  153. // 'PV' => $this->_decPv,
  154. // 'REAL_PV' => $this->_decPv,
  155. // 'BUY_NUMS' => 1,
  156. // 'SKU_CODE' => $decPackage['PACKAGE_NO'],
  157. // 'GOODS_TITLE' => $decPackage['PACKAGE_NAME']
  158. // ];
  159. } else {
  160. $ids = $this->goodsId;
  161. $totalAmount = 0;
  162. $totalAmountStandard = 0;
  163. $totalPv = 0;
  164. foreach ($this->goodsNum as $k => $v) {
  165. if ($v) {
  166. $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
  167. if (!$goods) {
  168. throw new Exception('Products does not exists!');
  169. }
  170. $goodsNature = ShopGoodsNature::findOneAsArray('GOODS_ID=:GOODS_ID AND COUNTRY_ID=:COUNTRY_ID',
  171. [':GOODS_ID' => $ids[$k], ':COUNTRY_ID' => $baseInfo['COUNTRY_ID']]);
  172. if (!$goodsNature) {
  173. throw new Exception(Yii::t('app', 'productsDoesSoldOut'));
  174. }
  175. if($goods['STORE_NUMS']>0){
  176. $totalAmount += $goodsNature['SELL_PRICE'] * intval($v);
  177. $totalAmountStandard += $goods['SELL_PRICE_STANDARD'] * intval($v);
  178. $realPriceStandard = $goods['SELL_PRICE_STANDARD'];
  179. $totalPv += $goods['PRICE_PV'] * intval($v);
  180. $this->_orderGoods[] = [
  181. 'GOODS_ID' => $goods['ID'],
  182. 'PRICE' => $goodsNature['SELL_PRICE'],
  183. 'REAL_PRICE' => $goodsNature['SELL_PRICE'],
  184. 'PV' => $goods['PRICE_PV'],
  185. 'REAL_PV' => $goods['PRICE_PV'],
  186. 'POINT' => $goods['POINT'],
  187. 'BUY_NUMS' => intval($v),
  188. 'SKU_CODE' => $goods['GOODS_NO'],
  189. 'GOODS_TITLE' => $goods['GOODS_NAME'],
  190. 'EMAIL' => Info::getUserEmailByUserId(\Yii::$app->user->id) ?? '',
  191. 'STANDARD_PRICE' => $goods['SELL_PRICE_STANDARD'],
  192. 'REAL_STANDARD_PRICE' => $realPriceStandard,
  193. 'EXCHANGE_RATE' => $currencyRate,
  194. 'TAX_RATE' => $goodsNature['TAX_RATE'],
  195. ];
  196. }
  197. if($goods['INSTALMENT']>0){ // 如果有分期付款商品,检查用户的分期付款状态
  198. if($v>1){ // 不可以购买多个
  199. throw new Exception(Yii::t('app', 'allowOnlyOne'));
  200. }
  201. // 分期的总期数
  202. $instalment = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
  203. // 分期商品的期数不能大于总分期数限制
  204. if (intval($goods['INSTALMENT']) > $instalment) {
  205. throw new Exception(Yii::t('app', 'instalmentGoodsNoError'));
  206. }
  207. $userStage = Instalment::getStage($userId);
  208. $userInstalmentInfo = Instalment::getInfo($userId);
  209. if (!$userInstalmentInfo){ // 如果没有分期付款记录
  210. throw new Exception(Yii::t('app', 'canNotBuy'));
  211. } else if ($userInstalmentInfo['ORDER_TYPE']!='BD' || (($userStage == $instalment) && ($goods['INSTALMENT'] != 1))) { // 如果分期付款记录中,不是报单,或已是最后一期
  212. throw new Exception(Yii::t('app', 'canNotBuy'));
  213. }
  214. if($userStage + 1 != $goods['INSTALMENT']){ // 若用户分期阶段+1不等于商品的分期阶段,则报异常
  215. throw new Exception(Yii::t('app', 'canNotBuy'));
  216. }
  217. if ($userStage + 1 > $instalment){ // 若用户分期阶段+1大于总分期阶段,则报异常
  218. throw new Exception(Yii::t('app', 'canNotBuy'));
  219. }
  220. $hasInstalment = $goods['INSTALMENT'];
  221. }
  222. }
  223. }
  224. // 这里特殊是用户原报单PV之和+用户购买的商品总PV
  225. $checkPv = $totalPv + $diffPerf;
  226. if ($hasInstalment){ // 如果买了分期付款商品,则不判断总pv
  227. $allData['hasInstalment'] = 1;
  228. }else if($checkPv < $decLevel['PERF']) {
  229. throw new Exception(Yii::t('app', 'totalPVLessThan'), 400);
  230. }
  231. foreach ($decLevelConfig as $key=>$val){
  232. if($checkPv>=$val['PERF']){
  233. $toDecLevel = $key;
  234. }
  235. }
  236. if($this->decLv!=$toDecLevel){
  237. throw new Exception(Yii::t('app', 'totalPvExceedPv'), 400);
  238. }
  239. $this->_decAmount = $totalAmount;
  240. $this->_decPv = $totalPv;
  241. $this->_decAmountStandard = $totalAmountStandard;
  242. $this->_standardAmount = $this->_decAmountStandard;
  243. }
  244. $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
  245. $this->_insertUserId = $baseInfo['ID']; // 被报单人,通过insername 查找用户id
  246. $insertConId = $baseInfo['CON_UID'];
  247. $insertRecId = $baseInfo['REC_UID'];
  248. $decResult = $this->addDecOrder($insertConId, $insertRecId, $baseInfo['DEC_LV'], $isObserve, $this->remark);
  249. if (!$decResult) {
  250. throw new Exception(Yii::t('app', 'failed'), 400);
  251. }
  252. if ($hasInstalment){ // 如果有分期付款的商品,写入信息至分期付款表
  253. $instalmentModel = Instalment::findOne(['USER_ID'=>$userId]);
  254. if(!$instalmentModel) {
  255. $instalmentModel = new Instalment();
  256. }
  257. $instalmentModel->USER_ID = $userId;
  258. $instalmentModel->STAGE = $hasInstalment;
  259. $instalmentModel->ORDER_TYPE = 'BD';
  260. $instalmentModel->UPDATE_TIME = time();
  261. $instalmentModel->save();
  262. }
  263. return $decResult;
  264. }
  265. return true;
  266. }
  267. /**
  268. * 添加报单订单
  269. * @throws Exception|\Throwable
  270. */
  271. public function addDecOrder($insertConId, $insertRecId, $oriDecLv, $isObserve, $remark = ''): ApproachOrder
  272. {
  273. $warehouse = Region::getWarehouseByCode($this->province);//仓库
  274. if(!$warehouse){
  275. throw new Exception(Yii::t('app', 'deliveryTemporarilyNotSupported'), 400);
  276. }
  277. $upgradeType = $isObserve ? 1 : 2; // 1补差 2全额
  278. $periodObj = Period::instance();
  279. $nowPeriodNum = $periodObj->getNowPeriodNum();
  280. $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
  281. $ord = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 10);
  282. // 加入报单信息
  283. $db = \Yii::$app->db;
  284. $transaction = $db->beginTransaction();
  285. try {
  286. $decOrderModel = new ApproachDecOrder();
  287. $decOrderModel->DEC_SN = 'DS'.$ord;
  288. $decOrderModel->ORDER_SN = 'OS'.$ord;
  289. $decOrderModel->TYPE = $this->type;
  290. $decOrderModel->USER_ID = \Yii::$app->user->id; // 报单人
  291. $decOrderModel->TO_USER_ID = $this->_insertUserId; // 被报单人
  292. $decOrderModel->DEC_AMOUNT = $this->_decAmount;
  293. $decOrderModel->DEC_PV = $this->_decPv;
  294. $decOrderModel->PERIOD_NUM = $nowPeriodNum;
  295. $decOrderModel->CALC_MONTH = $nowCalcMonth;
  296. $decOrderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  297. $decOrderModel->PAID_WALLET = 'cash';
  298. $decOrderModel->CON_USER_ID = $insertConId;
  299. $decOrderModel->REC_USER_ID = $insertRecId;
  300. $decOrderModel->DEC_ID = $this->_decId;
  301. $decOrderModel->IS_DEL = 0;
  302. $decOrderModel->DETAIL_TYPE = 2;
  303. $decOrderModel->CREATED_AT = Date::nowTime();
  304. $decOrderModel->UPGRADE_TYPE = $upgradeType;
  305. $decOrderModel->REMARK = $remark;
  306. $decOrderModel->ORI_LV = $oriDecLv; // 变更前的级别
  307. $decOrderModel->UPGRADE_LV = $this->decLv; // 变更后的级别
  308. if (!$decOrderModel->save()) {
  309. $transaction->rollBack();
  310. throw new Exception(Form::formatErrorsForApi($decOrderModel->getErrors()));
  311. }
  312. // 升级会员
  313. $userCountry = User::getEnCodeInfo($this->_insertUserId);
  314. $userCurrencyRate = CurrencyConversions::getToUSDRate($userCountry['LOCAL_CURRENCY_ID']);
  315. // 报单中心汇率
  316. $decCountry = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  317. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  318. $orderModel = new ApproachOrder();
  319. $orderModel->SN = 'OS' . $ord;
  320. $orderModel->DEC_SN = 'DS' . $ord;
  321. $orderModel->ORDER_TYPE = $this->type;
  322. $orderModel->USER_ID = $this->_insertUserId;
  323. $orderModel->USER_NAME = $this->insertUserName; // 要升级的用户
  324. $orderModel->ORDER_AMOUNT = $this->_decAmount;
  325. $orderModel->PV = $this->_decPv;
  326. $orderModel->PAY_AMOUNT = $this->_decAmount;
  327. $orderModel->PAY_PV = $this->_decPv;
  328. $orderModel->PAY_AT = 0;
  329. $orderModel->PAY_TYPE = 'pay_stack';
  330. $orderModel->PERIOD_NUM = $nowPeriodNum;
  331. $orderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  332. $orderModel->FREIGHT = 0;
  333. $orderModel->PAY_FREIGHT = 0;
  334. $orderModel->CONSIGNEE = $this->consignee;
  335. $orderModel->MOBILE = $this->acceptMobile;
  336. $orderModel->PROVINCE = $this->province;
  337. $orderModel->LGA_NAME = $this->lgaName;
  338. $orderModel->CITY_NAME = $this->cityName;
  339. $orderModel->ADDRESS = $this->address;
  340. $orderModel->WAREHOUSE = $warehouse;
  341. $orderModel->STATUS = \Yii::$app->params['orderStatus']['notPaid']['value'];
  342. $orderModel->CREATED_AT = Date::nowTime();
  343. $orderModel->CREATE_USER = Info::getUserNameByUserId(\Yii::$app->user->id);
  344. $orderModel->EMAIL = Info::getUserEmailByUserId(\Yii::$app->user->id) ?? '';
  345. $orderModel->ORDER_AMOUNT_STANDARD = $this->_decAmountStandard;
  346. $orderModel->PAY_AMOUNT_STANDARD = $this->_standardAmount;
  347. $orderModel->EXCHANGE_RATE = $userCurrencyRate;
  348. $orderModel->COUNTRY_ID = $userCountry['COUNTRY_ID'];
  349. $orderModel->CURRENCY_ID = $userCountry['LOCAL_CURRENCY_ID'] ?? 0;
  350. if(!$orderModel->save()){
  351. $transaction->rollBack();
  352. throw new Exception(Form::formatErrorsForApi($orderModel->getErrors()));
  353. }
  354. foreach ($this->goodsNum as $k => $v) {
  355. if ($v) {
  356. $goods = ShopGoods::findOneAsArray('ID=:ID',[':ID'=> $this->goodsId[$k]]);
  357. $storenums = $goods['STORE_NUMS'] - $this->goodsNum[$k];
  358. if($goods['STATUS']==1){
  359. if($goods['STORE_NUMS'] >=$this->goodsNum[$k]) {
  360. $data = ShopGoods::find()->where(['ID' => $this->goodsId[$k]])->one();
  361. $data->STORE_NUMS = $storenums;
  362. $data->update();
  363. if ($storenums==0) {
  364. $data->STATUS = 0;
  365. $data->UPDATED_AT = Date::nowTime();
  366. $data->update();
  367. }
  368. } else {
  369. throw new Exception("product".$goods['GOODS_NAME']."Insufficient inventory");//"商品".$goods['GOODS_NAME']."库存不足"
  370. }
  371. } else {
  372. throw new Exception("product".$goods['GOODS_NAME']."Removed from the shelf");// "商品".$goods['GOODS_NAME']."已下架"
  373. }
  374. }
  375. }
  376. // 加入商品到订单商品表
  377. foreach($this->_orderGoods as $key=>$value){
  378. $this->_orderGoods[$key]['ORDER_SN'] = $orderModel->SN;
  379. $this->_orderGoods[$key]['P_CALC_MONTH'] = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  380. }
  381. ApproachOrderGoods::batchInsert($this->_orderGoods);
  382. //写入收货地址信息
  383. $addressModel = new ReceiveAddress();
  384. $addressModel->USER_ID = $this->_insertUserId;
  385. $addressModel->USER_NAME = $this->insertUserName;
  386. $addressModel->CONSIGNEE = $this->consignee;
  387. $addressModel->MOBILE = $this->acceptMobile;
  388. $addressModel->COUNTRY_ID = $userCountry['COUNTRY_ID'];
  389. $addressModel->PROVINCE = $this->province;
  390. $addressModel->LGA_NAME = $this->lgaName;
  391. $addressModel->CITY_NAME = $this->cityName;
  392. $addressModel->ADDRESS = $this->address;
  393. $addressModel->IS_DEFAULT = 0;
  394. if (!$addressModel->save()) {
  395. $transaction->rollBack();
  396. throw new Exception(Form::formatErrorsForApi($addressModel->getErrors()));
  397. }
  398. $transaction->commit();
  399. return $orderModel;
  400. } catch(Exception $e) {
  401. $transaction->rollBack();
  402. throw new Exception($e->getMessage());
  403. }
  404. }
  405. /**
  406. * 判断报单中心是否存在
  407. * @param $attribute
  408. * @return false|void
  409. */
  410. public function issetDec($attribute){
  411. $decUser = User::find()
  412. ->select('ID')
  413. ->where('IS_DEC=1 AND USER_NAME=:USER_NAME', [':USER_NAME' => $this->decUserName])
  414. ->asArray()
  415. ->one();
  416. if (!$decUser) {
  417. $this->addError($attribute, 'Entry center does not exist');//报单中心不存在
  418. return false;
  419. } else {
  420. // 判断报单中心是否在新加入会员的安置网上级中
  421. // $this->loopFindParentToNetwork($this->insertUserName);
  422. //反转数组,in_array搜索错误
  423. //in_array($this->decUserName, $this->_tempNetworkParentUser[$this->insertUserName]);
  424. // $flipParent = array_flip(array_filter($this->_tempNetworkParentUser[$this->insertUserName]));
  425. // if (!isset($flipParent[$this->decUserName])) {
  426. //// $this->addError($attribute, '为' . $this->insertUserName . '升级报单,报单中心' . $this->decUserName . '不在' . $this->insertUserName . '的安置网上级中');
  427. // $this->addError($attribute, 'by' . $this->insertUserName . 'Upgrade declaration, declaration Center' . $this->decUserName . 'be not in' . $this->insertUserName . 'Online level of resettlement');
  428. // return ;
  429. // }
  430. $this->_decId = $decUser['ID'];
  431. }
  432. }
  433. // 判断是否已选择商品或套餐
  434. public function hasProduct($attribute) {
  435. if ($this->decWay==1 && empty($this->packageId)) {
  436. $this->addError($attribute, 'Purchase package upgrade, please select package');//购买套餐升级,请选择套餐
  437. return false;
  438. }
  439. if ($this->decWay!=1 && empty($this->goodsId)) {
  440. $this->addError($attribute, 'Purchase product upgrade, please select product');//购买商品升级,请选择商品'
  441. return false;
  442. }
  443. return true;
  444. }
  445. // 判断要升级的会员,是否已是最高级别
  446. public function alreadyMaxDec($attribute) {
  447. $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
  448. $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
  449. $maxPerfInfo = DeclarationLevel::getMaxDecPref();
  450. $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
  451. if ($maxDecId == $userDecId) {
  452. $this->addError($attribute, 'It is already the highest level and no upgrade is required');//已是最高级别,无需升级
  453. return false;
  454. }
  455. return true;
  456. }
  457. /**
  458. * 寻找被升级人的上级
  459. * @param null $conUserName
  460. * @return bool
  461. */
  462. private function loopFindParentToNetwork($conUserName = null) {
  463. if($conUserName == null ){
  464. $conUserName = $this->insertUserName;
  465. }
  466. $baseUser = Info::getBaseUserByUserName($conUserName);
  467. $userNetworkInfo = UserNetwork::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $baseUser['ID']]);
  468. unset($baseUser);
  469. $allParentUserIdsArr = explode(',', $userNetworkInfo['PARENT_UIDS']);
  470. unset($userNetworkInfo);
  471. $allParentUserIds = array_reverse($allParentUserIdsArr);
  472. unset($allParentUserIdsArr);
  473. if($allParentUserIds){
  474. foreach($allParentUserIds as $parentUserId) {
  475. $parentBaseUser = Info::getBaseUserById($parentUserId);
  476. if (is_null($parentBaseUser)) {
  477. continue;
  478. }
  479. $this->_tempNetworkParentUser[$this->insertUserName][] = $parentBaseUser['USER_NAME'] ;
  480. unset($parentUserId, $parentBaseUser);
  481. }
  482. }
  483. unset($allParentUserIds);
  484. return true;
  485. }
  486. }