ApproachDeclarationForm.php 44 KB

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