DeclarationUpgradeForm.php 25 KB

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