ApproachDeclarationUpgradeForm.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  140. $decCountry = Countries::getById($decCountryId);
  141. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  142. // 升级会员汇率
  143. $country = Countries::getById($baseInfo['COUNTRY_ID']);
  144. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  145. if($this->decWay==1) {
  146. // 先不加套餐升级方式
  147. // $decPackage = DeclarationPackage::findOneAsArray('ID=:ID', [':ID'=>$this->packageId]);
  148. // $this->_decAmount = $decPackage['AMOUNT'];
  149. // $this->_decPv = $decPackage['PV'];
  150. // $this->_orderGoods[] = [
  151. // 'GOODS_ID' => $this->packageId,
  152. // 'PRICE' => $this->_decAmount,
  153. // 'REAL_PRICE' => $this->_decAmount,
  154. // 'PV' => $this->_decPv,
  155. // 'REAL_PV' => $this->_decPv,
  156. // 'BUY_NUMS' => 1,
  157. // 'SKU_CODE' => $decPackage['PACKAGE_NO'],
  158. // 'GOODS_TITLE' => $decPackage['PACKAGE_NAME']
  159. // ];
  160. } else {
  161. $ids = $this->goodsId;
  162. $totalAmount = 0;
  163. $totalAmountStandard = 0;
  164. $totalPv = 0;
  165. foreach ($this->goodsNum as $k => $v) {
  166. if ($v) {
  167. $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
  168. if (!$goods) {
  169. throw new Exception('Products does not exists!');
  170. }
  171. $goodsNature = ShopGoodsNature::findOneAsArray('GOODS_ID=:GOODS_ID AND COUNTRY_ID=:COUNTRY_ID',
  172. [':GOODS_ID' => $ids[$k], ':COUNTRY_ID' => $baseInfo['COUNTRY_ID']]);
  173. if (!$goodsNature) {
  174. throw new Exception(Yii::t('app', 'productsDoesSoldOut'));
  175. }
  176. if($goods['STORE_NUMS']>0){
  177. $totalAmount += $goodsNature['SELL_PRICE'] * intval($v);
  178. $totalAmountStandard += $goods['SELL_PRICE_STANDARD'] * intval($v);
  179. $realPriceStandard = $goods['SELL_PRICE_STANDARD'];
  180. $totalPv += $goods['PRICE_PV'] * intval($v);
  181. $this->_orderGoods[] = [
  182. 'GOODS_ID' => $goods['ID'],
  183. 'PRICE' => $goodsNature['SELL_PRICE'],
  184. 'REAL_PRICE' => $goodsNature['SELL_PRICE'],
  185. 'PV' => $goods['PRICE_PV'],
  186. 'REAL_PV' => $goods['PRICE_PV'],
  187. 'POINT' => $goods['POINT'],
  188. 'BUY_NUMS' => intval($v),
  189. 'SKU_CODE' => $goods['GOODS_NO'],
  190. 'GOODS_TITLE' => $goods['GOODS_NAME'],
  191. 'EMAIL' => Info::getUserEmailByUserId(\Yii::$app->user->id) ?? '',
  192. 'STANDARD_PRICE' => $goods['SELL_PRICE_STANDARD'],
  193. 'REAL_STANDARD_PRICE' => $realPriceStandard,
  194. 'EXCHANGE_RATE' => $currencyRate,
  195. 'TAX_RATE' => $goodsNature['TAX_RATE'],
  196. ];
  197. }
  198. if($goods['INSTALMENT']>0){ // 如果有分期付款商品,检查用户的分期付款状态
  199. if($v>1){ // 不可以购买多个
  200. throw new Exception(Yii::t('app', 'allowOnlyOne'));
  201. }
  202. // 分期的总期数
  203. $instalment = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
  204. // 分期商品的期数不能大于总分期数限制
  205. if (intval($goods['INSTALMENT']) > $instalment) {
  206. throw new Exception(Yii::t('app', 'instalmentGoodsNoError'));
  207. }
  208. $userStage = Instalment::getStage($userId);
  209. $userInstalmentInfo = Instalment::getInfo($userId);
  210. if (!$userInstalmentInfo){ // 如果没有分期付款记录
  211. throw new Exception(Yii::t('app', 'canNotBuy'));
  212. } else if ($userInstalmentInfo['ORDER_TYPE']!='BD' || (($userStage == $instalment) && ($goods['INSTALMENT'] != 1))) { // 如果分期付款记录中,不是报单,或已是最后一期
  213. throw new Exception(Yii::t('app', 'canNotBuy'));
  214. }
  215. if($userStage + 1 != $goods['INSTALMENT']){ // 若用户分期阶段+1不等于商品的分期阶段,则报异常
  216. throw new Exception(Yii::t('app', 'canNotBuy'));
  217. }
  218. if ($userStage + 1 > $instalment){ // 若用户分期阶段+1大于总分期阶段,则报异常
  219. throw new Exception(Yii::t('app', 'canNotBuy'));
  220. }
  221. $hasInstalment = $goods['INSTALMENT'];
  222. }
  223. }
  224. }
  225. // 这里特殊是用户原报单PV之和+用户购买的商品总PV
  226. $checkPv = $totalPv + $diffPerf;
  227. if ($hasInstalment){ // 如果买了分期付款商品,则不判断总pv
  228. $allData['hasInstalment'] = 1;
  229. }else if($checkPv < $decLevel['PERF']) {
  230. throw new Exception(Yii::t('app', 'totalPVLessThan'), 400);
  231. }
  232. foreach ($decLevelConfig as $key=>$val){
  233. if($checkPv>=$val['PERF']){
  234. $toDecLevel = $key;
  235. }
  236. }
  237. if($this->decLv!=$toDecLevel){
  238. throw new Exception(Yii::t('app', 'totalPvExceedPv'), 400);
  239. }
  240. $this->_decAmount = $totalAmount;
  241. $this->_decPv = $totalPv;
  242. $this->_decAmountStandard = $totalAmountStandard;
  243. $this->_standardAmount = $this->_decAmountStandard;
  244. }
  245. $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
  246. $this->_insertUserId = $baseInfo['ID']; // 被报单人,通过insername 查找用户id
  247. $insertConId = $baseInfo['CON_UID'];
  248. $insertRecId = $baseInfo['REC_UID'];
  249. $decResult = $this->addDecOrder($insertConId, $insertRecId, $baseInfo['DEC_LV'], $isObserve, $this->remark);
  250. if (!$decResult) {
  251. throw new Exception(Yii::t('app', 'failed'), 400);
  252. }
  253. if ($hasInstalment){ // 如果有分期付款的商品,写入信息至分期付款表
  254. $instalmentModel = Instalment::findOne(['USER_ID'=>$userId]);
  255. if(!$instalmentModel) {
  256. $instalmentModel = new Instalment();
  257. }
  258. $instalmentModel->USER_ID = $userId;
  259. $instalmentModel->STAGE = $hasInstalment;
  260. $instalmentModel->ORDER_TYPE = 'BD';
  261. $instalmentModel->UPDATE_TIME = time();
  262. $instalmentModel->save();
  263. }
  264. return $decResult;
  265. }
  266. return true;
  267. }
  268. /**
  269. * 添加报单订单
  270. * @throws Exception|\Throwable
  271. */
  272. public function addDecOrder($insertConId, $insertRecId, $oriDecLv, $isObserve, $remark = ''): ApproachOrder
  273. {
  274. $warehouse = Region::getWarehouseByCode($this->province);//仓库
  275. if(!$warehouse){
  276. throw new Exception(Yii::t('app', 'deliveryTemporarilyNotSupported'), 400);
  277. }
  278. $upgradeType = $isObserve ? 1 : 2; // 1补差 2全额
  279. $periodObj = Period::instance();
  280. $nowPeriodNum = $periodObj->getNowPeriodNum();
  281. $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
  282. $ord = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 10);
  283. // 加入报单信息
  284. $db = \Yii::$app->db;
  285. $transaction = $db->beginTransaction();
  286. try {
  287. $decOrderModel = new ApproachDecOrder();
  288. $decOrderModel->DEC_SN = 'DS'.$ord;
  289. $decOrderModel->ORDER_SN = 'OS'.$ord;
  290. $decOrderModel->TYPE = $this->type;
  291. $decOrderModel->USER_ID = \Yii::$app->user->id; // 报单人
  292. $decOrderModel->TO_USER_ID = $this->_insertUserId; // 被报单人
  293. $decOrderModel->DEC_AMOUNT = $this->_decAmount;
  294. $decOrderModel->DEC_PV = $this->_decPv;
  295. $decOrderModel->PERIOD_NUM = $nowPeriodNum;
  296. $decOrderModel->CALC_MONTH = $nowCalcMonth;
  297. $decOrderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  298. $decOrderModel->PAID_WALLET = 'cash';
  299. $decOrderModel->CON_USER_ID = $insertConId;
  300. $decOrderModel->REC_USER_ID = $insertRecId;
  301. $decOrderModel->DEC_ID = $this->_decId;
  302. $decOrderModel->IS_DEL = 0;
  303. $decOrderModel->DETAIL_TYPE = 2;
  304. $decOrderModel->CREATED_AT = Date::nowTime();
  305. $decOrderModel->UPGRADE_TYPE = $upgradeType;
  306. $decOrderModel->REMARK = $remark;
  307. $decOrderModel->ORI_LV = $oriDecLv; // 变更前的级别
  308. $decOrderModel->UPGRADE_LV = $this->decLv; // 变更后的级别
  309. if (!$decOrderModel->save()) {
  310. $transaction->rollBack();
  311. throw new Exception(Form::formatErrorsForApi($decOrderModel->getErrors()));
  312. }
  313. // 升级会员
  314. $userCountryId = User::getEnCodeInfo($this->_insertUserId)['COUNTRY_ID'];
  315. $userCountry = Countries::getById($userCountryId);
  316. $userCurrencyRate = CurrencyConversions::getToUSDRate($userCountry['LOCAL_CURRENCY_ID']);
  317. // 报单中心汇率
  318. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  319. $decCountry = Countries::getById($decCountryId);
  320. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  321. $orderModel = new ApproachOrder();
  322. $orderModel->SN = 'OS' . $ord;
  323. $orderModel->DEC_SN = 'DS' . $ord;
  324. $orderModel->ORDER_TYPE = $this->type;
  325. $orderModel->USER_ID = $this->_insertUserId;
  326. $orderModel->USER_NAME = $this->insertUserName; // 要升级的用户
  327. $orderModel->ORDER_AMOUNT = $this->_decAmount;
  328. $orderModel->PV = $this->_decPv;
  329. $orderModel->PAY_AMOUNT = $this->_decAmount;
  330. $orderModel->PAY_PV = $this->_decPv;
  331. $orderModel->PAY_AT = 0;
  332. $orderModel->PAY_TYPE = 'pay_stack';
  333. $orderModel->PERIOD_NUM = $nowPeriodNum;
  334. $orderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  335. $orderModel->FREIGHT = 0;
  336. $orderModel->PAY_FREIGHT = 0;
  337. $orderModel->CONSIGNEE = $this->consignee;
  338. $orderModel->MOBILE = $this->acceptMobile;
  339. $orderModel->PROVINCE = $this->province;
  340. $orderModel->LGA_NAME = $this->lgaName;
  341. $orderModel->CITY_NAME = $this->cityName;
  342. $orderModel->ADDRESS = $this->address;
  343. $orderModel->WAREHOUSE = $warehouse;
  344. $orderModel->STATUS = \Yii::$app->params['orderStatus']['notPaid']['value'];
  345. $orderModel->CREATED_AT = Date::nowTime();
  346. $orderModel->CREATE_USER = Info::getUserNameByUserId(\Yii::$app->user->id);
  347. $orderModel->EMAIL = Info::getUserEmailByUserId(\Yii::$app->user->id) ?? '';
  348. $orderModel->ORDER_AMOUNT_STANDARD = $this->_decAmountStandard;
  349. $orderModel->PAY_AMOUNT_STANDARD = $this->_standardAmount;
  350. $orderModel->EXCHANGE_RATE = $userCurrencyRate;
  351. $orderModel->DEC_USER_ID = Info::getUserNameByUserId(\Yii::$app->user->id);
  352. $orderModel->COUNTRY_ID = $userCountryId;
  353. $orderModel->CURRENCY_ID = $userCountry['LOCAL_CURRENCY_ID'] ?? 0;
  354. if(!$orderModel->save()){
  355. $transaction->rollBack();
  356. throw new Exception(Form::formatErrorsForApi($orderModel->getErrors()));
  357. }
  358. foreach ($this->goodsNum as $k => $v) {
  359. if ($v) {
  360. $goods = ShopGoods::findOneAsArray('ID=:ID',[':ID'=> $this->goodsId[$k]]);
  361. $storenums = $goods['STORE_NUMS'] - $this->goodsNum[$k];
  362. if($goods['STATUS']==1){
  363. if($goods['STORE_NUMS'] >=$this->goodsNum[$k]) {
  364. $data = ShopGoods::find()->where(['ID' => $this->goodsId[$k]])->one();
  365. $data->STORE_NUMS = $storenums;
  366. $data->update();
  367. if ($storenums==0) {
  368. $data->STATUS = 0;
  369. $data->UPDATED_AT = Date::nowTime();
  370. $data->update();
  371. }
  372. } else {
  373. throw new Exception("product".$goods['GOODS_NAME']."Insufficient inventory");//"商品".$goods['GOODS_NAME']."库存不足"
  374. }
  375. } else {
  376. throw new Exception("product".$goods['GOODS_NAME']."Removed from the shelf");// "商品".$goods['GOODS_NAME']."已下架"
  377. }
  378. }
  379. }
  380. // 加入商品到订单商品表
  381. foreach($this->_orderGoods as $key=>$value){
  382. $this->_orderGoods[$key]['ORDER_SN'] = $orderModel->SN;
  383. $this->_orderGoods[$key]['P_CALC_MONTH'] = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  384. }
  385. ApproachOrderGoods::batchInsert($this->_orderGoods);
  386. //写入收货地址信息
  387. $addressModel = new ReceiveAddress();
  388. $addressModel->USER_ID = $this->_insertUserId;
  389. $addressModel->USER_NAME = $this->insertUserName;
  390. $addressModel->CONSIGNEE = $this->consignee;
  391. $addressModel->MOBILE = $this->acceptMobile;
  392. $addressModel->COUNTRY_ID = $userCountryId;
  393. $addressModel->PROVINCE = $this->province;
  394. $addressModel->LGA_NAME = $this->lgaName;
  395. $addressModel->CITY_NAME = $this->cityName;
  396. $addressModel->ADDRESS = $this->address;
  397. $addressModel->IS_DEFAULT = 0;
  398. if (!$addressModel->save()) {
  399. $transaction->rollBack();
  400. throw new Exception(Form::formatErrorsForApi($addressModel->getErrors()));
  401. }
  402. $transaction->commit();
  403. return $orderModel;
  404. } catch(Exception $e) {
  405. $transaction->rollBack();
  406. throw new Exception($e->getMessage());
  407. }
  408. }
  409. /**
  410. * 判断报单中心是否存在
  411. * @param $attribute
  412. * @return false|void
  413. */
  414. public function issetDec($attribute){
  415. $decUser = User::find()
  416. ->select('ID')
  417. ->where('IS_DEC=1 AND USER_NAME=:USER_NAME', [':USER_NAME' => $this->decUserName])
  418. ->asArray()
  419. ->one();
  420. if (!$decUser) {
  421. $this->addError($attribute, 'Entry center does not exist');//报单中心不存在
  422. return false;
  423. } else {
  424. // 判断报单中心是否在新加入会员的安置网上级中
  425. // $this->loopFindParentToNetwork($this->insertUserName);
  426. //反转数组,in_array搜索错误
  427. //in_array($this->decUserName, $this->_tempNetworkParentUser[$this->insertUserName]);
  428. // $flipParent = array_flip(array_filter($this->_tempNetworkParentUser[$this->insertUserName]));
  429. // if (!isset($flipParent[$this->decUserName])) {
  430. //// $this->addError($attribute, '为' . $this->insertUserName . '升级报单,报单中心' . $this->decUserName . '不在' . $this->insertUserName . '的安置网上级中');
  431. // $this->addError($attribute, 'by' . $this->insertUserName . 'Upgrade declaration, declaration Center' . $this->decUserName . 'be not in' . $this->insertUserName . 'Online level of resettlement');
  432. // return ;
  433. // }
  434. $this->_decId = $decUser['ID'];
  435. }
  436. }
  437. // 判断是否已选择商品或套餐
  438. public function hasProduct($attribute) {
  439. if ($this->decWay==1 && empty($this->packageId)) {
  440. $this->addError($attribute, 'Purchase package upgrade, please select package');//购买套餐升级,请选择套餐
  441. return false;
  442. }
  443. if ($this->decWay!=1 && empty($this->goodsId)) {
  444. $this->addError($attribute, 'Purchase product upgrade, please select product');//购买商品升级,请选择商品'
  445. return false;
  446. }
  447. return true;
  448. }
  449. // 判断要升级的会员,是否已是最高级别
  450. public function alreadyMaxDec($attribute) {
  451. $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
  452. $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
  453. $maxPerfInfo = DeclarationLevel::getMaxDecPref();
  454. $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
  455. if ($maxDecId == $userDecId) {
  456. $this->addError($attribute, 'It is already the highest level and no upgrade is required');//已是最高级别,无需升级
  457. return false;
  458. }
  459. return true;
  460. }
  461. /**
  462. * 寻找被升级人的上级
  463. * @param null $conUserName
  464. * @return bool
  465. */
  466. private function loopFindParentToNetwork($conUserName = null) {
  467. if($conUserName == null ){
  468. $conUserName = $this->insertUserName;
  469. }
  470. $baseUser = Info::getBaseUserByUserName($conUserName);
  471. $userNetworkInfo = UserNetwork::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $baseUser['ID']]);
  472. unset($baseUser);
  473. $allParentUserIdsArr = explode(',', $userNetworkInfo['PARENT_UIDS']);
  474. unset($userNetworkInfo);
  475. $allParentUserIds = array_reverse($allParentUserIdsArr);
  476. unset($allParentUserIdsArr);
  477. if($allParentUserIds){
  478. foreach($allParentUserIds as $parentUserId) {
  479. $parentBaseUser = Info::getBaseUserById($parentUserId);
  480. if (is_null($parentBaseUser)) {
  481. continue;
  482. }
  483. $this->_tempNetworkParentUser[$this->insertUserName][] = $parentBaseUser['USER_NAME'] ;
  484. unset($parentUserId, $parentBaseUser);
  485. }
  486. }
  487. unset($allParentUserIds);
  488. return true;
  489. }
  490. }