BaDeclarationForm.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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\Reconsume;
  9. use common\helpers\user\Info;
  10. use common\models\DeclarationPackage;
  11. use common\models\BaDecOrder;
  12. use common\models\EmployLevel;
  13. use common\models\BaOrder;
  14. use common\models\BaOrderGoods;
  15. use common\models\Period;
  16. use common\models\ReceiveAddress;
  17. use common\models\ReconsumePool;
  18. use common\models\ReconsumePoolFlow;
  19. use common\models\DeclarationLevel;
  20. use common\models\Region;
  21. use common\models\ShopGoods;
  22. use common\models\BaUser;
  23. use common\models\UserInfo;
  24. use common\models\BaUserInfo;
  25. use common\models\UserNetwork;
  26. use common\models\UserRelation;
  27. use yii\base\Exception;
  28. /**
  29. * Login form
  30. */
  31. class BaDeclarationForm extends Model
  32. {
  33. public $type;
  34. public $decLv;
  35. public $decWay;
  36. public $packageId;
  37. public $goodsId;
  38. public $goodsNum;
  39. public $insertUserName;
  40. public $password;
  41. public $payPassword;
  42. public $realName;
  43. public $insertUserIdCard;
  44. public $mobile;
  45. public $email;
  46. public $address;
  47. public $openBank;
  48. public $bankAddress;
  49. public $bankNo;
  50. public $bankProvince;
  51. public $bankCity;
  52. public $bankCounty;
  53. public $conUserName;
  54. public $recUserName;
  55. public $decUserName;
  56. public $location;
  57. public $consignee;
  58. public $acceptMobile;
  59. public $province;
  60. public $city;
  61. public $county;
  62. public $cityName;
  63. public $lgaName;
  64. // 传过来的全部数据
  65. public $allData;
  66. private $_decId;
  67. public $_insertUserId;
  68. private $_decAmount;
  69. // private $_decPv;
  70. private $_orderGoods;
  71. // 批量报单时添加会员的REDIS里面缓存的添加的会员资料
  72. const REDIS_WAIT_ADD_USER = 'user:dec:waitAdd';
  73. const TYPE_ZC = 'ZC';
  74. // const TYPE_YH = 'YH';
  75. const TYPE_ZG = 'ZG';
  76. const TYPE_LS = 'LS';
  77. const TYPE_FX = 'FX';
  78. // private $_modelClass = null;
  79. private $_oneOrder = null;
  80. private $_userForm = null;
  81. // 全部的上级(安置网和开拓网)
  82. private $_tempParentUser = [];
  83. // 全部的安置网上级
  84. private $_tempNetworkParentUser = [];
  85. // 全部的开拓网上级
  86. private $_tempRelationParentUser = [];
  87. private $_types = [
  88. self::TYPE_ZC => [
  89. 'name' => '首购单',
  90. ],
  91. // self::TYPE_YH => [
  92. // 'class' => DeclarationYH::class,
  93. // 'table' => '{{%DECLARATION_YH}}',
  94. // 'name' => '优惠单',
  95. // ],
  96. self::TYPE_ZG => [
  97. 'name' => '升级增购单',
  98. ],
  99. self::TYPE_LS => [
  100. 'name' => '零售单',
  101. ],
  102. self::TYPE_FX => [
  103. 'name' => '复销单',
  104. ],
  105. ];
  106. /**
  107. * @inheritdoc
  108. */
  109. public function rules()
  110. {
  111. return [
  112. [['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'],
  113. [['type','decWay','insertUserName',/* 'insertUserIdCard',*/'password','payPassword','decUserName'], 'required'],
  114. // [['type'], 'isType', 'on'=>['userDec', 'canDec']],
  115. // [['insertUserName'], 'isCanAddUser'],
  116. // [['decUserName'], 'issetDec'],
  117. // [['conUserName'], 'isConUserName'],
  118. // [['recUserName'], 'isRecUserName'],
  119. // [['location'], 'isLocation'],
  120. // [['insertUserIdCard'], 'isSameSystem'],
  121. ];
  122. }
  123. public function attributeLabels()
  124. {
  125. return [
  126. 'type' => 'Entry type', // 报单类型
  127. 'goodsId' => 'product ID', // 商品ID
  128. 'goodsNum' => 'Product quantity', // 商品数量
  129. 'insertUserName' => 'Member user name', // 会员用户名
  130. 'password' => 'Login password', // 登陆密码
  131. 'payPassword' => 'Payment password', // 支付密码
  132. 'realName' => 'Member name', // 会员姓名
  133. 'mobile' => 'Phone Number', // 手机号
  134. 'recUserName' => 'Developer user name', // 开拓人用户名
  135. 'decUserName' => 'Stockist user name', // 报单中心用户名
  136. 'conUid' => 'Instructor Member ID', // 指导老师会员ID
  137. 'recUid' => 'Sponsor Member ID', // 开拓人会员ID
  138. 'location' => 'market', // 市场
  139. 'consignee' => 'Recipient', // 收货人
  140. 'acceptMobile' => 'Recipient Phone Number', // 收货人手机
  141. 'province' => 'Receiving Province',//收货省
  142. 'address' => 'Receiving detailed address',//收货详细地址
  143. ];
  144. }
  145. /**
  146. * 指定场景
  147. * @return array
  148. */
  149. public function scenarios()
  150. {
  151. $parentScenarios = parent::scenarios();
  152. $customScenarios = [
  153. 'userDec' => ['type','allData', 'decLv','decWay','insertUserName','password','payPassword', 'realName', 'mobile', 'address', 'consignee','acceptMobile','province','decUserName', 'location', 'email'],
  154. ];
  155. return array_merge($parentScenarios, $customScenarios);
  156. }
  157. /**
  158. * 判断报单中心是否存在
  159. * @param $attribute
  160. */
  161. public function issetDec($attribute){
  162. if (!$decUser = BaUser::find()->select('ID')->where('IS_DEC=1 AND USER_NAME=:USER_NAME', [':USER_NAME' => $this->decUserName])->asArray()->one()) {
  163. $this->addError($attribute, 'Stockist does not exist'); // 报单中心不存在
  164. return false;
  165. } else {
  166. $this->_decId = $decUser['ID'];
  167. }
  168. }
  169. /**
  170. * 判断开拓人
  171. * @param $attribute
  172. */
  173. public function isRecUserName($attribute){
  174. if($this->type == self::TYPE_ZC){
  175. // 开拓人
  176. // if(!isset($this->_tempParentUser[$this->recUserName])){
  177. // $recUserTemp = UserInfo::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => $this->recUserName]);
  178. // if(!$recUserTemp){
  179. // if($this->insertUserName){
  180. // //$this->addError($attribute, '为'.$this->insertUserName.'报单,开拓人'.$this->recUserName.'不存在');
  181. // $this->addError($attribute, 'To'.$this->insertUserName.'Entry, Sponsor'.$this->recUserName.'not in exist');
  182. // } else {
  183. // // $this->addError($attribute, '开拓人'.$this->recUserName.'不存在');
  184. // $this->addError($attribute, 'Sponsor'.$this->recUserName.'not in exist');
  185. // }
  186. //
  187. // return ;
  188. // }
  189. // $recUserTemp['CON_NUM'] = UserNetwork::firstFloorChildNum($recUserTemp['USER_ID']);
  190. // $recUserTemp['REC_NUM'] = UserRelation::firstFloorChildNum($recUserTemp['USER_ID']);
  191. // $this->_tempParentUser[$this->recUserName] = [
  192. // 'USER_NAME' => $this->recUserName,
  193. // 'ZC_PV' => $recUserTemp['ZC_PV'],
  194. // 'CON_USER_NAME' => Info::getUserNameByUserId($recUserTemp['CON_UID']),
  195. // 'REC_USER_NAME' => Info::getUserNameByUserId($recUserTemp['REC_UID']),
  196. // 'CON_NUM' => $recUserTemp['CON_NUM'],
  197. // 'REC_NUM' => $recUserTemp['REC_NUM'],
  198. // 'SYSTEM_ID' => $recUserTemp['SYSTEM_ID'],
  199. // 'LOCATION' => UserNetwork::getLocation($recUserTemp['USER_ID'], $recUserTemp['CON_UID']),
  200. // ];
  201. // // 把该会员下面的5个区是否存在会员都付上
  202. // for($i=1;$i<=5;$i++){
  203. // $this->_tempParentUser[$this->recUserName]["LOCATION$i"] = UserNetwork::issetUserInLocation($recUserTemp['USER_ID'], $i);
  204. // }
  205. // }
  206. $recUser = $this->_tempParentUser[$this->recUserName];
  207. $this->_tempParentUser[$this->recUserName]['REC_NUM'] += 1;
  208. // 存在新加入会员时查看开拓人是否在新加入会员的安置网上级中
  209. // if($this->insertUserName) {
  210. // $this->loopFindParentToNetwork($this->insertUserName);
  211. // if (!$this->recUserIsInNetworkParent()) {
  212. // // $this->addError($attribute, '为' . $this->insertUserName . '报单,开拓人' . $this->recUserName . '不在' . $this->insertUserName . '的安置网上级中');
  213. // $this->addError($attribute, 'To' . $this->insertUserName . 'Entry, Sponsor' . $this->recUserName . 'not in exist' . $this->insertUserName . 'in the placement superiors');
  214. // return ;
  215. // }
  216. // }
  217. //
  218. // // 把自己加入到临时上级会员数组中
  219. // $this->_tempParentUser[$this->insertUserName] = [
  220. // 'USER_NAME' => $this->insertUserName,
  221. // //'ZC_PV' => $this->decPv,
  222. // 'CON_USER_NAME' => $this->conUserName,
  223. // 'REC_USER_NAME' => $this->recUserName,
  224. // 'CON_NUM' => 0,
  225. // 'REC_NUM' => 0,
  226. // 'SYSTEM_ID' => $recUser['SYSTEM_ID'],
  227. // 'LOCATION' => $this->location,
  228. // 'LOCATION1' => 0,
  229. // 'LOCATION2' => 0,
  230. // 'LOCATION3' => 0,
  231. // 'LOCATION4' => 0,
  232. // 'LOCATION5' => 0,
  233. // ];
  234. }
  235. }
  236. /**
  237. * 添加报单
  238. * @param $allData
  239. * @return bool|null
  240. * @throws Exception
  241. * @throws \yii\db\Exception
  242. */
  243. public function add($allData){
  244. if(!$this->validate()){
  245. return null;
  246. }
  247. // 首购单,需要添加会员操作
  248. if($this->type == self::TYPE_ZC){
  249. if (preg_match("/[\x7f-\xff]/", $this->insertUserName)) { // 判断字符串中是否有中文
  250. throw new Exception('Member number cannot contain Chinese characters'); // 会员编号中不能含有汉字
  251. }
  252. // //报单商品及PV判断
  253. // $decLevelConfig = Cache::getDecLevelConfig();
  254. // $decLevel = $decLevelConfig[$this->decLv];
  255. // $toDecLevel = $this->decLv;
  256. // if(!$this->decLv){
  257. // throw new Exception('Please select the entry level'); // 请选择报单级别
  258. // }
  259. $ids = $this->goodsId;
  260. $totalAmount = 0;
  261. $totalPv = 0;
  262. foreach ($this->goodsNum as $k => $v) {
  263. if ($v) {
  264. $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
  265. if($goods['STORE_NUMS']>0){
  266. $totalAmount += $goods['SELL_PRICE'] * intval($v);
  267. $totalPv += $goods['PRICE_PV'] * intval($v);
  268. $this->_orderGoods[] = [
  269. 'GOODS_ID' => $goods['ID'],
  270. 'PRICE' => $goods['SELL_PRICE'],
  271. 'REAL_PRICE' => $goods['SELL_PRICE'],
  272. 'PV' => $goods['PRICE_PV'],
  273. 'REAL_PV' => $goods['PRICE_PV'],
  274. 'POINT' => $goods['POINT'],
  275. 'BUY_NUMS' => intval($v),
  276. 'SKU_CODE' => $goods['GOODS_NO'],
  277. 'GOODS_TITLE' => $goods['GOODS_NAME'],
  278. 'EMAIL' => $this->email,
  279. 'TAX_RATE' => $goods['TAX_RATE'],
  280. ];
  281. }
  282. }
  283. }
  284. // if($totalPv<$decLevel['PERF']){
  285. // throw new Exception('The total BV of self selected goods cannot be less than the BV of the selected entry level');//自选商品总BV不能小于所选报单级别BV
  286. // }
  287. // foreach ($decLevelConfig as $key=>$val){
  288. // if($totalPv>=$val['PERF']){
  289. // $toDecLevel = $key;
  290. // }
  291. // }
  292. // if($this->decLv!=$toDecLevel){
  293. // throw new Exception('The total BV of self selected goods cannot exceed the BV value of the next level under the selected level');//自选商品总BV不能超过已选级别下一个级别的BV值
  294. // }
  295. $this->_decAmount = $totalAmount;
  296. // $this->_decPv = $totalPv;
  297. //看现金余额是否充足
  298. $loginUserId = \Yii::$app->user->id;
  299. if (Cash::getAvailableBalance($loginUserId) < $this->_decAmount){
  300. throw new Exception('The applicant is short of cash and cannot complete the declaration');//报单人现金不足,无法完成报单
  301. }
  302. // print_r($allData);exit;
  303. if(!($zcResult = $this->addBaUser($allData))) {
  304. throw new Exception(Form::formatErrorsForApi($this->_userForm->getErrors()));
  305. }
  306. // print_r($allData);exit;
  307. if(!($decResult = $this->addBaDecOrder())) {
  308. throw new Exception(Form::formatErrorsForApi($decResult->getErrors()));
  309. }
  310. }
  311. return true;
  312. }
  313. /**
  314. * 添加会员
  315. * @param $allData
  316. * @return bool|UserInfo|null
  317. * @throws \yii\db\Exception
  318. * @throws \Exception
  319. */
  320. public function addBaUser($allData){
  321. $period = Period::instance();
  322. try {
  323. // 增加会员
  324. $user = new BaUser();
  325. $user->USER_NAME = $this->insertUserName;
  326. $user->PASSWORD_HASH = \Yii::$app->security->generatePasswordHash($this->password);
  327. $user->PAY_PASSWORD = \Yii::$app->security->generatePasswordHash($this->payPassword);
  328. $user->NATION = 0;
  329. $user->REAL_NAME = $this->realName;
  330. $user->ID_CARD = $this->mobile;
  331. $user->MOBILE = $this->mobile;
  332. $user->EMAIL = $this->email;
  333. $user->ADDRESS = $this->address ? $this->address : 'nothing';//无
  334. // $user->OPEN_BANK = $this->openBank;
  335. // $user->BANK_ADDRESS = $this->bankAddress;
  336. // $user->BANK_NO = $this->bankNo;
  337. // $user->BANK_PROVINCE = $this->bankProvince ?? 0;
  338. // $user->BANK_CITY = $this->bankCity ?? 0;
  339. // $user->BANK_COUNTY = $this->bankCounty ?? 0;
  340. $user->CREATED_AT = Date::nowTime();
  341. $user->STATUS = 1;
  342. // $user->DEC_LV = $this->decLv;
  343. // $user->LAST_DEC_LV = $this->decLv;
  344. // $user->EMP_LV = EmployLevel::getDefaultLevelId();
  345. $user->PROVINCE = $this->province ?? 0;
  346. $user->LGA_NAME = $this->lgaName;
  347. $user->CITY_NAME = $this->cityName;
  348. $user->AVATAR = 'avatar/1.png';
  349. $user->IS_DEC = 0;
  350. $user->DEC_ID = $this->_decId ?? '';
  351. $user->DEC_ROLE_ID = $this->decRoleId ?? '';
  352. $user->PERIOD_AT = $period->getNowPeriodNum();
  353. $user->IS_DIRECT_SELLER = 0;
  354. $user->VERIFIED = 1;
  355. $user->VERIFIED_AT = Date::nowTime();
  356. if (!$user->save()) {
  357. throw new Exception(Form::formatErrorsForApi($user->getErrors()));
  358. }
  359. $this->_insertUserId = $user->ID;
  360. $userForm = new BaUserForm();
  361. $this->_userForm = $userForm;
  362. $userForm->scenario = 'addWithUserName';
  363. $userForm->userId = $this->_insertUserId;
  364. $userForm->userName = $this->insertUserName;
  365. // $userForm->zcPv = $this->_decPv;
  366. $userForm->zcAmount = $this->_decAmount;
  367. // $userForm->conUserName = $this->conUserName;
  368. $userForm->recUserName = $this->recUserName;
  369. // $userForm->location = $this->location;
  370. $userForm->idCard = $this->mobile;
  371. $userForm->allData = $allData;
  372. // print_r($userForm);exit;
  373. if (!$userForm->validate()) {
  374. $this->addErrors($userForm->getErrors());
  375. return false;
  376. }
  377. if ($result = $userForm->add()) {
  378. return $result;
  379. } else {
  380. return false;
  381. }
  382. } catch (\Exception $e) {
  383. LoggerTool::info($e->getMessage());
  384. throw new \Exception($e->getMessage());
  385. }
  386. }
  387. /**
  388. * 添加报单订单
  389. * @return bool|UserInfo|null
  390. * @throws \yii\db\Exception
  391. */
  392. public function addBaDecOrder(){
  393. $periodObj = Period::instance();
  394. $nowPeriodNum = $periodObj->getNowPeriodNum();
  395. $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
  396. $ord = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 10);
  397. // 加入报单信息
  398. $decOrderModel = new BaDecOrder();
  399. $decOrderModel->DEC_SN = 'DS'.$ord;
  400. $decOrderModel->ORDER_SN = 'OS'.$ord;
  401. $decOrderModel->TYPE = $this->type;
  402. $decOrderModel->USER_ID = \Yii::$app->user->id;
  403. $decOrderModel->TO_USER_ID = $this->_insertUserId;
  404. $decOrderModel->DEC_AMOUNT = $this->_decAmount;
  405. // $decOrderModel->DEC_PV = $this->_decPv;
  406. $decOrderModel->PERIOD_NUM = $nowPeriodNum;
  407. $decOrderModel->CALC_MONTH = $nowCalcMonth;
  408. $decOrderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  409. $decOrderModel->PAID_WALLET = 'cash';
  410. // $decOrderModel->CON_USER_ID = Info::getUserIdByUserName($this->conUserName);
  411. $decOrderModel->REC_USER_ID = Info::getUserIdByUserName($this->recUserName);
  412. // $decOrderModel->DEC_ID = $this->_decId;
  413. $decOrderModel->IS_DEL = 0;
  414. $decOrderModel->CREATED_AT = Date::nowTime();
  415. if(!$decOrderModel->save()){
  416. throw new Exception(Form::formatErrorsForApi($decOrderModel->getErrors()));
  417. }
  418. // 加入订单信息
  419. if($this->province!=1){
  420. $warehouse = Region::getWarehouseByCode($this->province);//仓库
  421. if(!$warehouse){
  422. throw new Exception('Delivery is temporarily not supported in the region. Contact customer service for details');//地区暂时不支持配送,具体联系客服
  423. }
  424. }else{
  425. $warehouse = '01';
  426. }
  427. $orderModel = new BaOrder();
  428. $orderModel->SN = 'OS'.$ord;
  429. $orderModel->DEC_SN = 'DS'.$ord;
  430. $orderModel->ORDER_TYPE = $this->type;
  431. $orderModel->USER_ID = $this->_insertUserId;
  432. $orderModel->USER_NAME = $this->insertUserName;
  433. $orderModel->ORDER_AMOUNT = $this->_decAmount;
  434. // $orderModel->PV = $this->_decPv;
  435. $orderModel->PAY_AMOUNT = $this->_decAmount;
  436. // $orderModel->PAY_PV = $this->_decPv;
  437. $orderModel->PAY_AT = Date::nowTime();
  438. $orderModel->PAY_TYPE = 'cash';
  439. $orderModel->PERIOD_NUM = $nowPeriodNum;
  440. $orderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  441. $orderModel->FREIGHT = 0;
  442. $orderModel->PAY_FREIGHT = 0;
  443. $orderModel->CONSIGNEE = $this->consignee;
  444. $orderModel->MOBILE = $this->acceptMobile;
  445. $orderModel->EMAIL = $this->email;
  446. $orderModel->PROVINCE = $this->province;
  447. $orderModel->LGA_NAME = $this->lgaName;
  448. $orderModel->CITY_NAME = $this->cityName;
  449. $orderModel->ADDRESS = $this->address;
  450. $orderModel->WAREHOUSE = $warehouse;
  451. $orderModel->STATUS = 1;
  452. $orderModel->CREATED_AT = Date::nowTime();
  453. $orderModel->CREATE_USER = Info::getUserNameByUserId(\Yii::$app->user->id);
  454. if($this->province==1){
  455. $orderModel->EXPRESS_TYPE = 1;
  456. }
  457. if(!$orderModel->save()){
  458. throw new Exception(Form::formatErrorsForApi($orderModel->getErrors()));
  459. }
  460. // 加入商品到订单商品表
  461. foreach($this->_orderGoods as $key=>$value){
  462. $this->_orderGoods[$key]['ORDER_SN'] = $orderModel->SN;
  463. $this->_orderGoods[$key]['P_CALC_MONTH'] = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  464. }
  465. BaOrderGoods::batchInsert($this->_orderGoods);
  466. //写入收货地址信息,判断province字段,当不为1时,插入收货地址信息
  467. if($this->province!=1){
  468. $addressModel = new ReceiveAddress();
  469. $addressModel->USER_ID = $this->_insertUserId;
  470. $addressModel->USER_NAME = $this->insertUserName;
  471. $addressModel->CONSIGNEE = $this->consignee;
  472. $addressModel->MOBILE = $this->acceptMobile;
  473. $addressModel->PROVINCE = $this->province;
  474. $addressModel->CITY_NAME = $this->cityName;
  475. $addressModel->LGA_NAME = $this->lgaName;
  476. $addressModel->ADDRESS = $this->address;
  477. $addressModel->IS_DEFAULT = 1;
  478. if(!$addressModel->save()){
  479. throw new Exception(Form::formatErrorsForApi($addressModel->getErrors()));
  480. }
  481. }else{
  482. $addressModel = new ReceiveAddress();
  483. }
  484. //扣报单人现金钱包
  485. Cash::changeUserCash(\Yii::$app->user->id, 'CASH', -abs($this->_decAmount), ['REMARK' =>'To'.$this->insertUserName.'Entry']); // 报单
  486. return $addressModel;
  487. }
  488. /**
  489. * 删单
  490. * @return bool
  491. * @throws \yii\db\Exception
  492. */
  493. public function delete(){
  494. if(!$this->validate()){
  495. return false;
  496. }
  497. $transaction = \Yii::$app->db->beginTransaction();
  498. try {
  499. $oneOrder = $this->_oneOrder;
  500. // 首购单要删除会员
  501. if($this->type == self::TYPE_ZC){
  502. BaUserInfo::deleteUser($oneOrder['TO_USER_ID']);
  503. }
  504. // 如果是复销单的话,还需要考虑给会员的复销池减去金额
  505. elseif($this->type == self::TYPE_FX){
  506. // Reconsume::changePoolPV($oneOrder['TO_USER_ID'], -abs($oneOrder['DEC_PV']), ['REMARK'=>'删单扣除', 'DEAL_TYPE'=>Reconsume::TYPE_AUDIT_PV]);
  507. Reconsume::changePoolPV($oneOrder['TO_USER_ID'], -abs($oneOrder['DEC_PV']), ['REMARK'=>'Deletion deduction', 'DEAL_TYPE'=>Reconsume::TYPE_AUDIT_PV]);
  508. }
  509. $transaction->commit();
  510. } catch (Exception $e) {
  511. $transaction->rollBack();
  512. $this->addError('delete', $e->getMessage());
  513. return false;
  514. }
  515. return true;
  516. }
  517. }