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