BaDeclarationForm.php 22 KB

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