ApproachDeclarationForm.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  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\Email;
  7. use common\helpers\Form;
  8. use common\helpers\LoggerTool;
  9. use common\helpers\user\Cash;
  10. use common\helpers\user\Reconsume;
  11. use common\helpers\user\Info;
  12. use common\models\ApproachDecOrder;
  13. use common\models\ApproachOrder;
  14. use common\models\ApproachOrderGoods;
  15. use common\models\DeclarationPackage;
  16. use common\models\DecOrder;
  17. use common\models\EmployLevel;
  18. use common\models\Order;
  19. use common\models\OrderGoods;
  20. use common\models\Period;
  21. use common\models\ReceiveAddress;
  22. use common\models\ReconsumePool;
  23. use common\models\ReconsumePoolFlow;
  24. use common\models\DeclarationLevel;
  25. use common\models\Region;
  26. use common\models\ShopGoods;
  27. use common\models\User;
  28. use common\models\UserInfo;
  29. use common\models\UserNetwork;
  30. use common\models\UserRelation;
  31. use common\models\Instalment;
  32. use Yii;
  33. use yii\base\Exception;
  34. /**
  35. * Login form
  36. */
  37. class ApproachDeclarationForm extends Model
  38. {
  39. public $type;
  40. public $decLv;
  41. public $decWay;
  42. public $packageId;
  43. public $goodsId;
  44. public $goodsNum;
  45. public $insertUserName;
  46. public $password;
  47. public $payPassword;
  48. public $realName;
  49. public $insertUserIdCard;
  50. public $mobile;
  51. public $email;
  52. public $address;
  53. public $openBank;
  54. public $bankAddress;
  55. public $bankNo;
  56. public $bankProvince;
  57. public $bankCity;
  58. public $bankCounty;
  59. public $conUserName;
  60. public $recUserName;
  61. public $decUserName;
  62. public $location;
  63. public $consignee;
  64. public $acceptMobile;
  65. public $province;
  66. public $city;
  67. public $county;
  68. public $cityName;
  69. public $lgaName;
  70. public $payType;
  71. public $decType;
  72. // 传过来的全部数据
  73. public $allData;
  74. private $_decId;
  75. public $_insertUserId;
  76. private $_decAmount;
  77. private $_decPv;
  78. private $_orderGoods;
  79. private $_standardAmount;
  80. private $_decAmountStandard;
  81. public $period;
  82. // 批量报单时添加会员的REDIS里面缓存的添加的会员资料
  83. const REDIS_WAIT_ADD_USER = 'user:dec:waitAdd';
  84. const TYPE_ZC = 'ZC';
  85. // const TYPE_YH = 'YH';
  86. const TYPE_ZG = 'ZG';
  87. const TYPE_LS = 'LS';
  88. const TYPE_FX = 'FX';
  89. // private $_modelClass = null;
  90. private $_oneOrder = null;
  91. private $_userForm = null;
  92. // 全部的上级(安置网和开拓网)
  93. private $_tempParentUser = [];
  94. // 全部的安置网上级
  95. private $_tempNetworkParentUser = [];
  96. // 全部的开拓网上级
  97. private $_tempRelationParentUser = [];
  98. private $_types = [
  99. self::TYPE_ZC => [
  100. 'name' => '首购单',
  101. ],
  102. // self::TYPE_YH => [
  103. // 'class' => DeclarationYH::class,
  104. // 'table' => '{{%DECLARATION_YH}}',
  105. // 'name' => '优惠单',
  106. // ],
  107. self::TYPE_ZG => [
  108. 'name' => '升级增购单',
  109. ],
  110. self::TYPE_LS => [
  111. 'name' => '零售单',
  112. ],
  113. self::TYPE_FX => [
  114. 'name' => '复销单',
  115. ],
  116. ];
  117. /**
  118. * @inheritdoc
  119. */
  120. public function rules()
  121. {
  122. return [
  123. [['type','decLv','decWay','packageId', 'insertUserName', 'realName',/* 'insertUserIdCard',*/ 'mobile', 'address', 'openBank', 'bankAddress', 'bankNo','bankProvince','bankCity','bankCounty','consignee','acceptMobile','province','city','county','cityName','lgaName','decUserName', 'conUserName', 'recUserName', 'location'], 'trim'],
  124. [['type','decLv','decWay','insertUserName',/* 'insertUserIdCard',*/'password','payPassword'], 'required'],
  125. [['type'], 'isType', 'on'=>['userDec', 'canDec']],
  126. [['insertUserName'], 'isCanAddUser'],
  127. [['decUserName', 'decType'], 'issetDec'],
  128. [['conUserName'], 'isConUserName'],
  129. [['recUserName'], 'isRecUserName'],
  130. [['location'], 'isLocation'],
  131. // [['insertUserIdCard'], 'isSameSystem'],
  132. ];
  133. }
  134. public function attributeLabels()
  135. {
  136. return [
  137. 'type' => 'Entry type',//报单类型
  138. 'decLv' => 'Entry level',//报单级别
  139. //'decPv' => '报单PV',
  140. 'decWay' => 'Entry method',//报单方式
  141. 'packageId' => 'Entry Package',//报单套餐
  142. 'goodsId' => 'product ID',//商品ID
  143. 'goodsNum' => 'Product quantity',//商品数量
  144. //'addType' => '新增会员方式',
  145. 'insertUserName' => 'Member user name',//会员用户名
  146. 'password' => 'Login password',//登陆密码
  147. 'payPassword' => 'Payment password',//支付密码
  148. 'realName' => 'Member Name',//会员姓名
  149. 'insertUserIdCard' => 'ID',//身份证号
  150. 'mobile' => 'Phone Number',//手机号
  151. 'openBank' => 'openBank',//开户行
  152. 'bankAddress' => 'bankAddress',//开户支行
  153. 'bankNo' => 'bankNo',//银行账号
  154. 'bankProvince' => 'bankProvince',//银行省份
  155. 'bankCity' => 'bankCity',//银行城市
  156. 'bankCounty' => 'bankCounty',//银行县区
  157. 'conUserName' => 'Instructor user name',//指导老师用户名
  158. 'recUserName' => 'Developer user name',//开拓人用户名
  159. 'decUserName' => 'Stockist user name',//报单中心用户名
  160. 'conUid' => 'Instructor member ID',//指导老师会员ID
  161. 'recUid' => 'Sponsor member ID',//'开拓人会员ID
  162. 'location' => 'market',//市场
  163. 'consignee' => 'consignee',//收货人
  164. 'acceptMobile' => 'Recipient Phone Number',//收货人手机
  165. 'province' => 'Receiving Province',//收货省
  166. 'city' => 'Receiving City',//收货市
  167. 'county' => 'Receiving area / county',//收货区县
  168. 'address' => 'Receiving detailed address',//收货详细地址
  169. ];
  170. }
  171. /**
  172. * 指定场景
  173. * @return array
  174. */
  175. public function scenarios()
  176. {
  177. $parentScenarios = parent::scenarios();
  178. $customScenarios = [
  179. 'userDec' => ['type','allData', 'decLv','decWay','insertUserName','password','payPassword', 'realName',/* 'insertUserIdCard',*/ 'mobile', 'address', 'openBank', 'bankAddress', 'bankNo', 'bankProvince','bankCity','bankCounty', 'consignee','acceptMobile','province',/*'city','county',*/ 'conUserName', 'recUserName','decUserName', 'location', 'email', 'decType'],
  180. 'canDec' => ['type', 'insertUserName',/* 'insertUserIdCard',*/ 'conUserName', 'recUserName', 'location', 'decType'],
  181. 'notFull' => ['type', 'insertUserName', 'conUserName', 'recUserName', 'location'],
  182. ];
  183. return array_merge($parentScenarios, $customScenarios);
  184. }
  185. /**
  186. * 判断报单中心是否存在
  187. * @param $attribute
  188. */
  189. public function issetDec($attribute){
  190. if(!$this->decUserName){
  191. $this->_decId = '';
  192. } else {
  193. if (!$decUser = User::find()->select('ID')->where('IS_DEC=1 AND USER_NAME=:USER_NAME', [':USER_NAME' => $this->decUserName])->asArray()->one()) {
  194. $this->addError($attribute, Yii::t('app', 'stockistDoesNotExist'));
  195. return false;
  196. } else {
  197. if ($this->decType !== 'ba') {
  198. // 判断报单中心是否在新加入会员的安置网上级中
  199. $this->loopFindParentToNetwork($this->insertUserName);
  200. //反转数组,in_array搜索错误
  201. //in_array($this->decUserName, $this->_tempNetworkParentUser[$this->insertUserName]);
  202. $flipParent = array_flip(array_filter($this->_tempNetworkParentUser[$this->insertUserName]));
  203. // if (!isset($flipParent[$this->decUserName])) {
  204. // //$this->addError($attribute, '为' . $this->insertUserName . '报单,报单中心' . $this->decUserName . '不在' . $this->insertUserName . '的安置网上级中');
  205. // $this->addError($attribute, 'To' . $this->insertUserName . 'Entry, Stockist' . $this->decUserName . 'not in exist' . $this->insertUserName . 'in the placement superiors');
  206. // return ;
  207. // }
  208. }
  209. $this->_decId = $decUser['ID'];
  210. }
  211. }
  212. }
  213. /**
  214. * 判断指导老师
  215. * @param $attribute
  216. */
  217. public function isConUserName($attribute){
  218. if($this->type == self::TYPE_ZC){
  219. // 从数据库查看接点会员是否在
  220. if(!isset($this->_tempParentUser[$this->conUserName])){
  221. $conUserTemp = UserInfo::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => $this->conUserName]);
  222. if(!$conUserTemp){
  223. if($this->insertUserName){
  224. //$this->addError($attribute, '为'.$this->insertUserName.'报单,指导老师'.$this->conUserName.'不存在');
  225. $this->addError($attribute, 'To'.$this->insertUserName.'Entry,Instructor'.$this->conUserName.'not in exist');
  226. } else {
  227. //$this->addError($attribute, '指导老师'.$this->conUserName.'不存在');
  228. $this->addError($attribute, 'Instructor'.$this->conUserName.'not in exist');
  229. }
  230. return ;
  231. }
  232. $conUserTemp['CON_NUM'] = UserNetwork::firstFloorChildNum($conUserTemp['USER_ID']);
  233. $conUserTemp['REC_NUM'] = UserRelation::firstFloorChildNum($conUserTemp['USER_ID']);
  234. $this->_tempParentUser[$this->conUserName] = [
  235. 'USER_NAME' => $this->conUserName,
  236. 'ZC_PV' => $conUserTemp['ZC_PV'],
  237. 'CON_USER_NAME' => Info::getUserNameByUserId($conUserTemp['CON_UID']),
  238. 'REC_USER_NAME' => Info::getUserNameByUserId($conUserTemp['REC_UID']),
  239. 'CON_NUM' => $conUserTemp['CON_NUM'],
  240. 'REC_NUM' => $conUserTemp['REC_NUM'],
  241. 'SYSTEM_ID' => $conUserTemp['SYSTEM_ID'],
  242. 'LOCATION' => UserNetwork::getLocation($conUserTemp['USER_ID'], $conUserTemp['CON_UID']),
  243. ];
  244. // 把该会员下面的5个区是否存在会员都付上
  245. for($i=1;$i<=5;$i++){
  246. $this->_tempParentUser[$this->conUserName]["LOCATION$i"] = UserNetwork::issetUserInLocation($conUserTemp['USER_ID'], $i);
  247. }
  248. }
  249. $conUser = $this->_tempParentUser[$this->conUserName];
  250. // 判断接点会员的下级会员是否大于三个,如果大于三个则不允许
  251. if($conUser['CON_NUM'] >= 3){
  252. if($this->insertUserName){
  253. // $this->addError($attribute, '为'.$this->insertUserName.'报单,指导老师'.$this->conUserName.'下级点位已满');
  254. $this->addError($attribute, 'To'.$this->insertUserName.'Entry,Instructor'.$this->conUserName.'lower level is full');
  255. } else {
  256. //$this->addError($attribute, '指导老师'.$this->conUserName.'下级点位已满');
  257. $this->addError($attribute, 'Instructor'.$this->conUserName.'lower level is full');
  258. }
  259. return;
  260. }
  261. if($this->insertUserName){
  262. // 把自己加入到临时上级会员数组中
  263. $this->_tempParentUser[$this->insertUserName] = [
  264. 'USER_NAME' => $this->insertUserName,
  265. //'ZC_PV' => $this->decPv,
  266. 'CON_USER_NAME' => $this->conUserName,
  267. 'REC_USER_NAME' => $this->recUserName,
  268. 'CON_NUM' => 0,
  269. 'REC_NUM' => 0,
  270. 'SYSTEM_ID' => $conUser['SYSTEM_ID'],
  271. 'LOCATION' => $this->location,
  272. 'LOCATION1' => 0,
  273. 'LOCATION2' => 0,
  274. 'LOCATION3' => 0,
  275. 'LOCATION4' => 0,
  276. 'LOCATION5' => 0,
  277. ];
  278. }
  279. }
  280. }
  281. /**
  282. * 判断开拓人
  283. * @param $attribute
  284. */
  285. public function isRecUserName($attribute){
  286. if($this->type == self::TYPE_ZC){
  287. // 开拓人
  288. if(!isset($this->_tempParentUser[$this->recUserName])){
  289. $recUserTemp = UserInfo::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => $this->recUserName]);
  290. if(!$recUserTemp){
  291. if($this->insertUserName){
  292. //$this->addError($attribute, '为'.$this->insertUserName.'报单,开拓人'.$this->recUserName.'不存在');
  293. $this->addError($attribute, 'To'.$this->insertUserName.'Entry, Sponsor'.$this->recUserName.'not in exist');
  294. } else {
  295. // $this->addError($attribute, '开拓人'.$this->recUserName.'不存在');
  296. $this->addError($attribute, 'Sponsor'.$this->recUserName.'not in exist');
  297. }
  298. return ;
  299. }
  300. $recUserTemp['CON_NUM'] = UserNetwork::firstFloorChildNum($recUserTemp['USER_ID']);
  301. $recUserTemp['REC_NUM'] = UserRelation::firstFloorChildNum($recUserTemp['USER_ID']);
  302. $this->_tempParentUser[$this->recUserName] = [
  303. 'USER_NAME' => $this->recUserName,
  304. 'ZC_PV' => $recUserTemp['ZC_PV'],
  305. 'CON_USER_NAME' => Info::getUserNameByUserId($recUserTemp['CON_UID']),
  306. 'REC_USER_NAME' => Info::getUserNameByUserId($recUserTemp['REC_UID']),
  307. 'CON_NUM' => $recUserTemp['CON_NUM'],
  308. 'REC_NUM' => $recUserTemp['REC_NUM'],
  309. 'SYSTEM_ID' => $recUserTemp['SYSTEM_ID'],
  310. 'LOCATION' => UserNetwork::getLocation($recUserTemp['USER_ID'], $recUserTemp['CON_UID']),
  311. ];
  312. // 把该会员下面的5个区是否存在会员都付上
  313. for($i=1;$i<=5;$i++){
  314. $this->_tempParentUser[$this->recUserName]["LOCATION$i"] = UserNetwork::issetUserInLocation($recUserTemp['USER_ID'], $i);
  315. }
  316. }
  317. $recUser = $this->_tempParentUser[$this->recUserName];
  318. $this->_tempParentUser[$this->recUserName]['REC_NUM'] += 1;
  319. // 存在新加入会员时查看开拓人是否在新加入会员的安置网上级中
  320. if($this->decType !== 'ba' && $this->insertUserName) {
  321. $this->loopFindParentToNetwork($this->insertUserName);
  322. if (!$this->recUserIsInNetworkParent()) {
  323. // $this->addError($attribute, '为' . $this->insertUserName . '报单,开拓人' . $this->recUserName . '不在' . $this->insertUserName . '的安置网上级中');
  324. $this->addError($attribute, 'To' . $this->insertUserName . 'Entry, Sponsor' . $this->recUserName . 'not in exist' . $this->insertUserName . 'in the placement superiors');
  325. return ;
  326. }
  327. }
  328. // 把自己加入到临时上级会员数组中
  329. $this->_tempParentUser[$this->insertUserName] = [
  330. 'USER_NAME' => $this->insertUserName,
  331. //'ZC_PV' => $this->decPv,
  332. 'CON_USER_NAME' => $this->conUserName,
  333. 'REC_USER_NAME' => $this->recUserName,
  334. 'CON_NUM' => 0,
  335. 'REC_NUM' => 0,
  336. 'SYSTEM_ID' => $recUser['SYSTEM_ID'],
  337. 'LOCATION' => $this->location,
  338. 'LOCATION1' => 0,
  339. 'LOCATION2' => 0,
  340. 'LOCATION3' => 0,
  341. 'LOCATION4' => 0,
  342. 'LOCATION5' => 0,
  343. ];
  344. }
  345. }
  346. /**
  347. * 循环把所有新加入的会员的上级加入到临时变量中
  348. * @param null $conUserName
  349. * @return bool
  350. */
  351. private function loopFindParentToNetwork($conUserName = null) {
  352. if($conUserName == null ){
  353. $conUserName = $this->insertUserName;
  354. }
  355. $findUserKey = array_search($conUserName, array_column($this->allData, 'insertUserName'));
  356. // 如果有这个新加入的会员,则查找其上级接点
  357. if($findUserKey !== false){
  358. if(strtoupper($this->allData[$findUserKey]['type']) == 'ZC'){
  359. $this->_tempNetworkParentUser[$this->insertUserName][] = $this->allData[$findUserKey]['conUserName'];
  360. $this->loopFindParentToNetwork($this->allData[$findUserKey]['conUserName']);
  361. }
  362. }
  363. // 如果没有这个新加入的接点,
  364. else {
  365. if($this->insertUserName == $conUserName){
  366. // $this->addError('recUserName', '新加入的会员不存在');
  367. $this->addError('recUserName', Yii::t('app', 'newMemberDoesNotExist'));
  368. return false;
  369. }
  370. // 去数据库里查找这个会员的所有上级
  371. // $allParentUser = UserNetwork::find()->select('PUI.USER_NAME')->where('UI.USER_NAME=:USER_NAME', [':USER_NAME'=>$conUserName])->from(UserNetwork::tableName().' AS UN')->join('LEFT JOIN', UserInfo::tableName().' AS UI', 'UN.USER_ID=UI.USER_ID')->join('LEFT JOIN', UserInfo::tableName().' AS PUI', 'UN.PARENT_UID=PUI.USER_ID')->orderBy('PUI.NETWORK_DEEP DESC')->asArray()->all();
  372. $baseUser = Info::getBaseUserByUserName($conUserName);
  373. $userNetworkInfo = UserNetwork::findOneAsArray('USER_ID=:USER_ID AND PARENT_UIDS <> ""', [':USER_ID' => $baseUser['ID']]);
  374. unset($baseUser);
  375. if ($userNetworkInfo) {
  376. $allParentUserIdsArr = explode(',', $userNetworkInfo['PARENT_UIDS']);
  377. unset($userNetworkInfo);
  378. $allParentUserIds = array_reverse($allParentUserIdsArr);
  379. unset($allParentUserIdsArr);
  380. if($allParentUserIds && count($allParentUserIds)){
  381. foreach($allParentUserIds as $parentUserId) {
  382. $parentBaseUser = Info::getBaseUserById($parentUserId);
  383. $this->_tempNetworkParentUser[$this->insertUserName][] = $parentBaseUser['USER_NAME'] ;
  384. unset($parentUserId, $parentBaseUser);
  385. }
  386. }
  387. unset($allParentUserIds);
  388. }
  389. }
  390. return true;
  391. }
  392. /**
  393. * 开拓人是否在新加入会员的上级中
  394. * @return bool
  395. */
  396. private function recUserIsInNetworkParent(){
  397. return in_array($this->recUserName, $this->_tempNetworkParentUser[$this->insertUserName]);
  398. }
  399. /**
  400. * 判断区域是否正确
  401. * @param $attribute
  402. */
  403. public function isLocation($attribute){
  404. if($this->type == self::TYPE_ZC){
  405. if(!in_array($this->location, [1, 2, 3])){
  406. //$this->addError($attribute, '市场必须在第1市场、第2市场或第三3市场');
  407. $this->addError($attribute, Yii::t('app', 'pleaseSelectMarket'));
  408. }
  409. $conUser = $recUser = null;
  410. if(isset($this->_tempParentUser[$this->conUserName])){
  411. $conUser = $this->_tempParentUser[$this->conUserName];
  412. }
  413. if(isset($this->_tempParentUser[$this->recUserName])){
  414. $recUser = $this->_tempParentUser[$this->recUserName];
  415. }
  416. if($conUser){
  417. // 判断指导老师相应的区位是否已满
  418. if($conUser['LOCATION'.$this->location]){
  419. if($this->insertUserName){
  420. // $this->addError($attribute, '为'.$this->insertUserName.'报单,指导老师'.$this->conUserName.'的第'.$this->location.'市场已存在会员');
  421. $this->addError($attribute, 'To'.$this->insertUserName.'Entry,Instructor'.$this->conUserName.'the'.($this->location == 1 ? 'left' : 'regiht').' superior already existing member');
  422. } else {
  423. // $this->addError($attribute, '指导老师'.$this->conUserName.'的第'.$this->location.'市场已存在会员');
  424. $this->addError($attribute, 'Instructor'.$this->conUserName.'the'.($this->location == 1 ? 'left' : 'regiht').'superior already existing member');
  425. }
  426. return;
  427. }
  428. $this->_tempParentUser[$this->conUserName]['CON_NUM'] += 1;
  429. $this->_tempParentUser[$this->conUserName]['LOCATION'.$this->location] = true;
  430. }
  431. }
  432. }
  433. /**
  434. * 判断会员是否可加入(通过redis结合数据库判断上级会员的情况)
  435. * @param $attribute
  436. */
  437. public function isCanAddUser($attribute){
  438. if($this->type == self::TYPE_ZC){
  439. // 从数据库查看接点会员是否在
  440. if(!isset($this->_tempParentUser[$this->conUserName])){
  441. $conUserTemp = UserInfo::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => $this->conUserName]);
  442. if(!$conUserTemp){
  443. // $this->addError($attribute, '为'.$this->insertUserName.'报单,指导老师'.$this->conUserName.'不存在');
  444. $this->addError($attribute, 'To'.$this->insertUserName.'Entry,Instructor'.$this->conUserName.'not in exist');
  445. return ;
  446. }
  447. $conUserTemp['CON_NUM'] = UserNetwork::firstFloorChildNum($conUserTemp['USER_ID']);
  448. $conUserTemp['REC_NUM'] = UserRelation::firstFloorChildNum($conUserTemp['USER_ID']);
  449. $this->_tempParentUser[$this->conUserName] = [
  450. 'USER_NAME' => $this->conUserName,
  451. //'ZC_PV' => $conUserTemp['ZC_PV'],
  452. 'CON_USER_NAME' => Info::getUserNameByUserId($conUserTemp['CON_UID']),
  453. 'REC_USER_NAME' => Info::getUserNameByUserId($conUserTemp['REC_UID']),
  454. 'CON_NUM' => $conUserTemp['CON_NUM'],
  455. 'REC_NUM' => $conUserTemp['REC_NUM'],
  456. 'SYSTEM_ID' => $conUserTemp['SYSTEM_ID'],
  457. 'LOCATION' => UserNetwork::getLocation($conUserTemp['USER_ID'], $conUserTemp['CON_UID']),
  458. ];
  459. // 把该会员下面的5个区是否存在会员都付上
  460. for($i=1;$i<=5;$i++){
  461. $this->_tempParentUser[$this->conUserName]["LOCATION$i"] = UserNetwork::issetUserInLocation($conUserTemp['USER_ID'], $i);
  462. }
  463. }
  464. $conUser = $this->_tempParentUser[$this->conUserName];
  465. // 开拓人
  466. if(!isset($this->_tempParentUser[$this->recUserName])){
  467. $recUserTemp = UserInfo::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => $this->recUserName]);
  468. if(!$recUserTemp){
  469. // $this->addError($attribute, '为'.$this->insertUserName.'报单,开拓人'.$this->recUserName.'不存在');
  470. $this->addError($attribute, 'To'.$this->insertUserName.'Entry, Sponsor'.$this->recUserName.'not in exist');
  471. return ;
  472. }
  473. $recUserTemp['CON_NUM'] = UserNetwork::firstFloorChildNum($recUserTemp['USER_ID']);
  474. $recUserTemp['REC_NUM'] = UserRelation::firstFloorChildNum($recUserTemp['USER_ID']);
  475. $this->_tempParentUser[$this->recUserName] = [
  476. 'USER_NAME' => $this->recUserName,
  477. //'ZC_PV' => $recUserTemp['ZC_PV'],
  478. 'CON_USER_NAME' => Info::getUserNameByUserId($recUserTemp['CON_UID']),
  479. 'REC_USER_NAME' => Info::getUserNameByUserId($recUserTemp['REC_UID']),
  480. 'CON_NUM' => $recUserTemp['CON_NUM'],
  481. 'REC_NUM' => $recUserTemp['REC_NUM'],
  482. 'SYSTEM_ID' => $recUserTemp['SYSTEM_ID'],
  483. 'LOCATION' => UserNetwork::getLocation($recUserTemp['USER_ID'], $recUserTemp['CON_UID']),
  484. ];
  485. // 把该会员下面的5个区是否存在会员都付上
  486. for($i=1;$i<=5;$i++){
  487. $this->_tempParentUser[$this->recUserName]["LOCATION$i"] = UserNetwork::issetUserInLocation($recUserTemp['USER_ID'], $i);
  488. }
  489. }
  490. $recUser = $this->_tempParentUser[$this->recUserName];
  491. // 判断接点会员的下级会员是否大于三个,如果大于三个则不允许
  492. if($conUser['CON_NUM'] >= 3){
  493. // $this->addError($attribute, '为'.$this->insertUserName.'报单,指导老师'.$this->conUserName.'下级点位已满');
  494. $this->addError($attribute, 'To'.$this->insertUserName.'Entry, Sponsor'.$this->conUserName.'lower level is full');
  495. return;
  496. }
  497. // 判断指导老师相应的区位是否已满
  498. if($conUser['LOCATION'.$this->location]){
  499. // $this->addError($attribute, '为'.$this->insertUserName.'报单,指导老师'.$this->conUserName.'该市场已存在会员');
  500. $this->addError($attribute, 'To'.$this->insertUserName.'Entry, Sponsor'.$this->conUserName.'Members already exist in this market');
  501. return;
  502. }
  503. // if($conUser['CON_NUM'] == 0 && $this->location != 1){
  504. // $this->addError($attribute, '为'.$this->insertUserName.'报单,市场必须为指导老师'.$this->conUserName.'下第一市场');
  505. // return;
  506. // }
  507. // 把指导老师的变量的相关数量增加数量
  508. // $this->_tempParentUser[$this->conUserName]['CON_NUM'] += 1;
  509. // $this->_tempParentUser[$this->conUserName]['LOCATION'.$this->location] = true;
  510. // $this->_tempParentUser[$this->recUserName]['REC_NUM'] += 1;
  511. // 把自己加入到临时上级会员数组中
  512. $this->_tempParentUser[$this->insertUserName] = [
  513. 'USER_NAME' => $this->insertUserName,
  514. //'ZC_PV' => $this->decPv,
  515. 'CON_USER_NAME' => $this->conUserName,
  516. 'REC_USER_NAME' => $this->recUserName,
  517. 'CON_NUM' => 0,
  518. 'REC_NUM' => 0,
  519. 'SYSTEM_ID' => $recUser['SYSTEM_ID'],
  520. 'LOCATION' => $this->location,
  521. 'LOCATION1' => 0,
  522. 'LOCATION2' => 0,
  523. 'LOCATION3' => 0,
  524. 'LOCATION4' => 0,
  525. 'LOCATION5' => 0,
  526. ];
  527. }
  528. }
  529. /**
  530. * 报单类型
  531. * @param $attribute
  532. * @param $params
  533. */
  534. public function isType($attribute, $params){
  535. if(array_key_exists($this->type, $this->_types)){
  536. if($this->type == self::TYPE_ZC){
  537. if($this->scenario == 'userDec'){
  538. if(!$this->insertUserName) $this->addError($attribute, Yii::t('app', 'MembershipNumberFilledInitialPurchase'));
  539. }
  540. if(!$this->insertUserName) $this->addError($attribute, Yii::t('app', 'MembershipNumberFilledInitialPurchase'));
  541. // if(!$this->insertUserIdCard) $this->addError($attribute, 'For the first purchase, the ID number of the member must be filled in');//首购必须填写加入会员的身份证号
  542. if(!$this->conUserName) $this->addError($attribute, Yii::t('app', 'fillTheInstructorNumberTheMember'));
  543. if(!$this->recUserName) $this->addError($attribute, Yii::t('app', 'sponsorNumberMustBeFilled'));
  544. if(!$this->location) $this->addError($attribute, Yii::t('app', 'beFilledTheMarketMember'));
  545. }
  546. } else {
  547. $this->addError($attribute, Yii::t('app', 'incorrectEntryType'));
  548. }
  549. }
  550. /**
  551. * 检验相同身份证 会员是否同一体系内(接点)
  552. * @param $attribute
  553. */
  554. // public function isSameSystem($attribute){
  555. // if(isset($this->_tempParentUser[$this->conUserName])){
  556. // // 新加入会员的身份证号对应网内的其他会员
  557. // $otherUser = User::findAllAsArray("ID_CARD=:ID_CARD AND IS_UNION=0 AND DELETED=0 AND (ID_CARD_PREFIX IS NULL OR ID_CARD_PREFIX='')", [':ID_CARD'=>$this->insertUserIdCard]);
  558. // if(count($otherUser)>=7){
  559. // $this->addError($attribute, 'Only 7 documents can be reported for the same ID card');//同一个身份证限制只能报7单
  560. // }
  561. // if($otherUser){
  562. // $flipParent = array_flip(array_filter($this->_tempNetworkParentUser[$this->insertUserName]));
  563. // $isExsit = false;
  564. // foreach ($otherUser as $conUser){
  565. // if(isset($flipParent[$conUser['USER_NAME']])){
  566. // $isExsit = true;
  567. // break;
  568. // }
  569. // }
  570. // if (!$isExsit) {
  571. //// $this->addError($attribute, '为' . $this->insertUserName . '报单,身份证号码相同的会员'.$otherUser[0]['USER_NAME'].'不在' . $this->insertUserName . '的安置网上级中');
  572. // $this->addError($attribute, 'To' . $this->insertUserName . 'Entry,Members with the same ID number'.$otherUser[0]['USER_NAME'].'not in exist' . $this->insertUserName . 'in the placement superiors');
  573. // return ;
  574. // }
  575. // }
  576. // } else {
  577. //// $this->addError($attribute, '为'.$this->insertUserName.'报单,接点人'.$this->conUserName.'不存在');
  578. // $this->addError($attribute, 'To'.$this->insertUserName.'Entry,Contact person'.$this->conUserName.'not in exist');
  579. // }
  580. // }
  581. /**
  582. * 添加报单
  583. * @param $allData
  584. * @return ApproachOrder
  585. * @throws Exception
  586. * @throws \yii\db\Exception
  587. */
  588. public function add($allData){
  589. if(!$this->validate()){
  590. return null;
  591. }
  592. $hasInstalment = 0;
  593. // 首购单,需要添加会员操作
  594. if($this->type == self::TYPE_ZC) {
  595. try {
  596. if (preg_match("/[\x7f-\xff]/", $this->insertUserName)) { //判断字符串中是否有中文
  597. throw new Exception(Yii::t('app', 'memberNumberCanNotContainChineseCharacters'));
  598. }
  599. //报单商品及PV判断
  600. $decLevelConfig = Cache::getDecLevelConfig();
  601. $decLevel = $decLevelConfig[$this->decLv];
  602. $toDecLevel = $this->decLv;
  603. if (!$this->decLv) {
  604. throw new Exception(Yii::t('app', 'pleaseSelectTheEntryLevel'));
  605. }
  606. if ($this->decWay == 1) {
  607. $decPackage = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $this->packageId]);
  608. $this->_decAmount = $decPackage['AMOUNT'];
  609. $this->_decPv = $decPackage['PV'];
  610. $this->_orderGoods[] = [
  611. 'GOODS_ID' => $this->packageId,
  612. 'PRICE' => $this->_decAmount,
  613. 'REAL_PRICE' => $this->_decAmount,
  614. 'PV' => $this->_decPv,
  615. 'REAL_PV' => $this->_decPv,
  616. 'BUY_NUMS' => 1,
  617. 'SKU_CODE' => $decPackage['PACKAGE_NO'],
  618. 'GOODS_TITLE' => $decPackage['PACKAGE_NAME'],
  619. 'EMAIL' => $this->email
  620. ];
  621. } else {
  622. $ids = $this->goodsId;
  623. $totalAmount = 0;
  624. $totalAmountStandard = 0;
  625. $totalPv = 0;
  626. $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0); // 汇率
  627. foreach ($this->goodsNum as $k => $v) {
  628. if ($v) {
  629. $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1', [':ID' => $ids[$k]]);
  630. if ($goods['STORE_NUMS'] > 0) {
  631. $totalAmount += $goods['SELL_PRICE'] * intval($v);
  632. $totalAmountStandard += $goods['SELL_PRICE_STANDARD'] * intval($v);
  633. $realPriceStandard = $goods['SELL_PRICE_STANDARD'];
  634. $totalPv += $goods['PRICE_PV'] * intval($v);
  635. $this->_orderGoods[] = [
  636. 'GOODS_ID' => $goods['ID'],
  637. 'PRICE' => $goods['SELL_PRICE'],
  638. 'REAL_PRICE' => $goods['SELL_PRICE'],
  639. 'PV' => $goods['PRICE_PV'],
  640. 'REAL_PV' => $goods['PRICE_PV'],
  641. 'POINT' => $goods['POINT'],
  642. 'BUY_NUMS' => intval($v),
  643. 'SKU_CODE' => $goods['GOODS_NO'],
  644. 'GOODS_TITLE' => $goods['GOODS_NAME'],
  645. 'EMAIL' => $this->email,
  646. 'STANDARD_PRICE' => $goods['SELL_PRICE_STANDARD'],
  647. 'REAL_STANDARD_PRICE' => $realPriceStandard,
  648. 'EXCHANGE_RATE' => $exchangeRate,
  649. 'TAX_RATE' => $goods['TAX_RATE'],
  650. ];
  651. }
  652. if($goods['INSTALMENT']>0){
  653. $hasInstalment = $goods['INSTALMENT'];
  654. }
  655. }
  656. }
  657. if($totalPv<$decLevel['PERF']){
  658. if ($hasInstalment && $decLevel['LEVEL_NAME'] == 'Elite'){
  659. }else{
  660. throw new Exception(Yii::t('app', 'totalBVCanNotLessThanSelectedBV'));
  661. }
  662. }
  663. foreach ($decLevelConfig as $key => $val) {
  664. if ($totalPv >= $val['PERF']) {
  665. $toDecLevel = $key;
  666. }
  667. }
  668. if ($this->decLv != $toDecLevel) {
  669. if ($hasInstalment && $decLevel['LEVEL_NAME'] == 'Elite'){
  670. }else{
  671. throw new Exception(Yii::t('app', 'totalBVCanNotLessThanNextSelectedLevelBV'));
  672. }
  673. }
  674. $this->_decAmount = $totalAmount;
  675. $this->_decPv = $totalPv;
  676. $this->_decAmountStandard = $totalAmountStandard;
  677. $this->_standardAmount = $this->_decAmountStandard;
  678. }
  679. if (!($zcResult = $this->addUser($allData))) {
  680. throw new Exception(Form::formatErrorsForApi($this->_userForm->getErrors()));
  681. }
  682. $decResult = $this->addDecOrder();
  683. if (!$decResult) {
  684. throw new Exception(Form::formatErrorsForApi($decResult->getErrors()));
  685. }
  686. if($hasInstalment){
  687. if(!($instalmentResult = $this->insertInstalment($zcResult))) {
  688. throw new Exception(Form::formatErrorsForApi('h'));
  689. }
  690. }
  691. return $decResult;
  692. } catch (\Exception $e) {
  693. // throw new Exception(Form::formatErrorsForApi($e->getFile() . ' ' . $e->getLine() . ' ' . $e->getMessage()));
  694. throw new Exception(Form::formatErrorsForApi($e->getMessage()));
  695. }
  696. }
  697. return true;
  698. }
  699. /**
  700. * 添加会员
  701. * @param $allData
  702. * @return bool|UserInfo|null
  703. * @throws \yii\db\Exception
  704. */
  705. public function addUser($allData){
  706. $periodObj = Period::instance();
  707. $nowPeriodNum = $this->period ?: $periodObj->getNowPeriodNum();
  708. // 增加会员
  709. $user = new User();
  710. $user->USER_NAME = $this->insertUserName;
  711. $user->PASSWORD_HASH = \Yii::$app->security->generatePasswordHash($this->password);
  712. $user->PAY_PASSWORD = \Yii::$app->security->generatePasswordHash($this->payPassword);
  713. $user->NATION = 0;
  714. $user->REAL_NAME = $this->realName;
  715. $user->ID_CARD = $this->mobile;
  716. $user->MOBILE = $this->mobile;
  717. $user->EMAIL = $this->email;
  718. $user->ADDRESS = $this->address ? $this->address : 'nothing';//无
  719. $user->OPEN_BANK = $this->openBank;
  720. $user->BANK_ADDRESS = $this->bankAddress;
  721. $user->BANK_NO = $this->bankNo;
  722. $user->BANK_PROVINCE = $this->bankProvince ?? 0;
  723. $user->BANK_CITY = $this->bankCity ?? 0;
  724. $user->BANK_COUNTY = $this->bankCounty ?? 0;
  725. $user->CREATED_AT = Date::nowTime();
  726. $user->STATUS = 0;
  727. $user->DEC_LV = $this->decLv;
  728. $user->LAST_DEC_LV = $this->decLv;
  729. $user->EMP_LV = EmployLevel::getDefaultLevelId();
  730. $user->PROVINCE = $this->province ?? 0;
  731. $user->LGA_NAME = $this->lgaName;
  732. $user->CITY_NAME = $this->cityName;
  733. // $user->CITY = $this->city ?? 0;
  734. // $user->COUNTY = intval($this->county) ?? 0;
  735. $user->AVATAR = 'avatar/1.png';
  736. $user->IS_DEC = 0;
  737. $user->DEC_ID = $this->_decId ?? null;
  738. $user->DEC_ROLE_ID = $this->decRoleId ?? null;
  739. $user->PERIOD_AT = $nowPeriodNum;
  740. $user->IS_DIRECT_SELLER = 0;
  741. $user->VERIFIED = 1;
  742. $user->VERIFIED_AT = Date::nowTime();
  743. $user->IS_RECHARGE = 1;
  744. if (!$user->save()) {
  745. throw new Exception(Form::formatErrorsForApi($user->getErrors()));
  746. }
  747. $this->_insertUserId = $user->ID;
  748. $userForm = new UserForm();
  749. $this->_userForm = $userForm;
  750. $userForm->scenario = 'addWithUserName';
  751. $userForm->userId = $this->_insertUserId;
  752. $userForm->userName = $this->insertUserName;
  753. $userForm->zcPv = $this->_decPv;
  754. $userForm->zcAmount = $this->_decAmount;
  755. $userForm->conUserName = $this->conUserName;
  756. $userForm->recUserName = $this->recUserName;
  757. $userForm->location = $this->location;
  758. $userForm->idCard = $this->mobile;
  759. $userForm->allData = $allData;
  760. if(!$userForm->validate()){
  761. $this->addErrors($userForm->getErrors());
  762. return false;
  763. }
  764. if($result = $userForm->add()){
  765. // 发送邮件
  766. Email::sendRegistrationEmail($this->email, $this->insertUserName, $this->password);
  767. return $result;
  768. } else {
  769. return false;
  770. }
  771. }
  772. /**
  773. * 添加报单订单
  774. * @throws \yii\db\Exception
  775. */
  776. public function addDecOrder(){
  777. $periodObj = Period::instance();
  778. $nowPeriodNum = $this->period ?: $periodObj->getNowPeriodNum();
  779. $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
  780. $ord = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 10);
  781. // 加入报单信息
  782. $decOrderModel = new ApproachDecOrder();
  783. $decOrderModel->DEC_SN = 'DS' . $ord;
  784. $decOrderModel->ORDER_SN = 'OS' . $ord;
  785. $decOrderModel->TYPE = $this->type;
  786. $decOrderModel->USER_ID = \Yii::$app->user->id;
  787. $decOrderModel->TO_USER_ID = $this->_insertUserId;
  788. $decOrderModel->DEC_AMOUNT = $this->_decAmount;
  789. $decOrderModel->DEC_PV = $this->_decPv;
  790. $decOrderModel->PERIOD_NUM = $nowPeriodNum;
  791. $decOrderModel->CALC_MONTH = $nowCalcMonth;
  792. $decOrderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  793. $decOrderModel->PAID_WALLET = $this->payType;
  794. $decOrderModel->CON_USER_ID = Info::getUserIdByUserName($this->conUserName);
  795. $decOrderModel->REC_USER_ID = Info::getUserIdByUserName($this->recUserName);
  796. $decOrderModel->DEC_ID = $this->_decId;
  797. $decOrderModel->IS_DEL = 0;
  798. $decOrderModel->CREATED_AT = Date::nowTime();
  799. if(!$decOrderModel->save()){
  800. throw new Exception(Form::formatErrorsForApi($decOrderModel->getErrors()));
  801. }
  802. // 加入订单信息
  803. if ($this->province!=1) {
  804. // 仓库
  805. $warehouse = Region::getWarehouseByCode($this->province);
  806. if (!$warehouse) {
  807. // 地区暂时不支持配送,具体联系客服
  808. throw new Exception(Yii::t('app', 'deliveryTemporarilyNotSupported'));
  809. }
  810. } else {
  811. $warehouse = '01';
  812. }
  813. $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0);
  814. $orderModel = new ApproachOrder();
  815. $orderModel->SN = 'OS' . $ord;
  816. $orderModel->DEC_SN = 'DS' . $ord;
  817. $orderModel->DEC_USER_ID = $this->_decId;
  818. $orderModel->ORDER_TYPE = $this->type;
  819. $orderModel->USER_ID = $this->_insertUserId;
  820. $orderModel->USER_NAME = $this->insertUserName;
  821. $orderModel->ORDER_AMOUNT = $this->_decAmount;
  822. $orderModel->PV = $this->_decPv;
  823. $orderModel->PAY_AMOUNT = $this->_decAmount;
  824. $orderModel->PAY_PV = $this->_decPv;
  825. $orderModel->PAY_AT = 0;
  826. $orderModel->PAY_TYPE = $this->payType;
  827. $orderModel->PERIOD_NUM = $nowPeriodNum;
  828. $orderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  829. $orderModel->FREIGHT = 0;
  830. $orderModel->PAY_FREIGHT = 0;
  831. $orderModel->CONSIGNEE = $this->consignee;
  832. $orderModel->MOBILE = $this->acceptMobile;
  833. $orderModel->EMAIL = $this->email ?: $this->insertUserName . '@elken.net';
  834. $orderModel->PROVINCE = $this->province;
  835. $orderModel->LGA_NAME = $this->lgaName;
  836. $orderModel->CITY_NAME = $this->cityName;
  837. $orderModel->ADDRESS = $this->address;
  838. $orderModel->WAREHOUSE = $warehouse;
  839. $orderModel->STATUS = \Yii::$app->params['orderStatus']['notPaid']['value'];
  840. $orderModel->CREATED_AT = Date::nowTime();
  841. $orderModel->CREATE_USER = Info::getUserNameByUserId(\Yii::$app->user->id);
  842. $orderModel->ORDER_AMOUNT_STANDARD = $this->_decAmountStandard;
  843. $orderModel->PAY_AMOUNT_STANDARD = $this->_standardAmount;
  844. $orderModel->EXCHANGE_RATE = $exchangeRate;
  845. if ($this->province==1) {
  846. $orderModel->EXPRESS_TYPE = 1;
  847. }
  848. if (!$orderModel->save()) {
  849. throw new Exception(Form::formatErrorsForApi($orderModel->getErrors()));
  850. }
  851. // 加入商品到订单商品表
  852. foreach($this->_orderGoods as $key=>$value){
  853. $this->_orderGoods[$key]['ORDER_SN'] = $orderModel->SN;
  854. $this->_orderGoods[$key]['P_CALC_MONTH'] = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  855. }
  856. ApproachOrderGoods::batchInsert($this->_orderGoods);
  857. // 写入收货地址信息,判断province字段,当不为1时,插入收货地址信息
  858. $addressModel = new ReceiveAddress();
  859. if ($this->province != 1) {
  860. $addressModel->USER_ID = $this->_insertUserId;
  861. $addressModel->USER_NAME = $this->insertUserName;
  862. $addressModel->CONSIGNEE = $this->consignee;
  863. $addressModel->MOBILE = $this->acceptMobile;
  864. $addressModel->PROVINCE = $this->province;
  865. $addressModel->CITY_NAME = $this->cityName;
  866. $addressModel->LGA_NAME = $this->lgaName;
  867. $addressModel->ADDRESS = $this->address;
  868. $addressModel->IS_DEFAULT = 1;
  869. if (!$addressModel->save()) {
  870. throw new Exception(Form::formatErrorsForApi($addressModel->getErrors()));
  871. }
  872. }
  873. return $orderModel;
  874. }
  875. /**
  876. * 删单
  877. * @return bool
  878. * @throws \yii\db\Exception
  879. */
  880. public function delete(){
  881. if(!$this->validate()){
  882. return false;
  883. }
  884. $transaction = \Yii::$app->db->beginTransaction();
  885. try {
  886. $oneOrder = $this->_oneOrder;
  887. // 首购单要删除会员
  888. if($this->type == self::TYPE_ZC){
  889. UserInfo::deleteUser($oneOrder['TO_USER_ID']);
  890. }
  891. // 如果是复销单的话,还需要考虑给会员的复销池减去金额
  892. elseif($this->type == self::TYPE_FX){
  893. // Reconsume::changePoolPV($oneOrder['TO_USER_ID'], -abs($oneOrder['DEC_PV']), ['REMARK'=>'删单扣除', 'DEAL_TYPE'=>Reconsume::TYPE_AUDIT_PV]);
  894. Reconsume::changePoolPV($oneOrder['TO_USER_ID'], -abs($oneOrder['DEC_PV']), ['REMARK'=>'Deletion deduction', 'DEAL_TYPE'=>Reconsume::TYPE_AUDIT_PV]);
  895. }
  896. $transaction->commit();
  897. } catch (Exception $e) {
  898. $transaction->rollBack();
  899. $this->addError('delete', $e->getMessage());
  900. return false;
  901. }
  902. return true;
  903. }
  904. /**
  905. * 添加会员分期付款记录
  906. * @param $allData
  907. * @return bool|UserInfo|null
  908. * @throws \yii\db\Exception
  909. */
  910. public function insertInstalment($zcResult){
  911. // 增加会员分期付款记录
  912. $instalment = new Instalment();
  913. $instalment->USER_ID = $zcResult->USER_ID;
  914. $instalment->STAGE = 1;
  915. $instalment->ORDER_TYPE = 'BD';
  916. $instalment->UPDATE_TIME = time();
  917. if (!$instalment->save()) {
  918. throw new Exception(Form::formatErrorsForApi($instalment->getErrors()));
  919. }
  920. return $instalment;
  921. }
  922. }