UserController.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace frontendApi\modules\v1\controllers;
  9. use common\helpers\bonus\CalcCache;
  10. use common\helpers\Cache;
  11. use common\helpers\Email;
  12. use common\helpers\Form;
  13. use common\helpers\LoggerTool;
  14. use common\helpers\Tool;
  15. use common\helpers\user\Info;
  16. use common\models\BaUser;
  17. use common\models\Config;
  18. use common\models\Countries;
  19. use common\models\Currency;
  20. use common\models\CurrencyConversions;
  21. use common\models\DeclarationLevel;
  22. use common\models\DeclarationPackage;
  23. use common\models\DecOrder;
  24. use common\models\forms\ApproachDeclarationLoopForm;
  25. use common\models\forms\BaApproachDeclarationLoopForm;
  26. use common\models\forms\ApproachDeclarationUpgradeForm;
  27. use common\models\forms\BaUserForm;
  28. use common\models\forms\DeclarationForm;
  29. use common\models\forms\BaDeclarationForm;
  30. use common\models\forms\DeclarationLoopForm;
  31. use common\models\forms\BaDeclarationLoopForm;
  32. use common\models\forms\UploadForm;
  33. use common\models\forms\UserBindForm;
  34. use common\models\forms\UserForm;
  35. use common\models\Instalment;
  36. use common\models\OpenBank;
  37. use common\models\Period;
  38. use common\models\ReceiveAddress;
  39. use common\models\Region;
  40. use common\models\ShopGoods;
  41. use common\models\ShopGoodsNature;
  42. use common\models\UpgradeType;
  43. use common\models\User;
  44. use common\models\UserBind;
  45. use common\models\UserBonus;
  46. use common\models\UserInfo;
  47. use common\models\BaUserInfo;
  48. use common\models\UserNetwork;
  49. use common\models\forms\DeclarationUpgradeForm;
  50. use common\models\UserPerformance;
  51. use common\models\UserWallet;
  52. use frontendApi\modules\v1\models\Relation;
  53. use Yii;
  54. use yii\db\Exception;
  55. use yii\web\UploadedFile;
  56. class UserController extends BaseController {
  57. public $modelClass = UserInfo::class;
  58. const LOOP_FINISH = 1;
  59. /**
  60. * 会员资料
  61. * @return mixed
  62. * @throws \yii\web\HttpException
  63. */
  64. public function actionIndex() {
  65. $allNation = \Yii::$app->params['nation'];
  66. $allOpenBank = OpenBank::findAllAsArray('STATUS=1');
  67. $data['allNation'] = $allNation;
  68. $data['allOpenBank'] = $allOpenBank;
  69. $data['userInfo'] = User::getEnCodeInfo(\Yii::$app->user->id);
  70. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  71. return static::notice($data);
  72. }
  73. /**
  74. * 编辑会员资料
  75. * @return mixed
  76. * @throws \yii\web\HttpException
  77. */
  78. public function actionEdit() {
  79. if(\Yii::$app->request->isPost){
  80. $form = new UserForm();
  81. $post = \Yii::$app->request->post();
  82. $form->scenario = 'modifyProfile';
  83. if($form->load($post, '') && $result = $form->modifyProfile()){
  84. return static::notice(Yii::t('app', 'personalDataModifiedSuccessfully'), 400);
  85. } else {
  86. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  87. }
  88. }
  89. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  90. }
  91. /**
  92. * 修改登录密码
  93. */
  94. public function actionPassword(){
  95. if(\Yii::$app->request->isPost){
  96. $form = new UserForm();
  97. $form->scenario = 'modifyPassword';
  98. $post = \Yii::$app->request->post();
  99. if($form->load($post, '') && $result = $form->modifyPassword()){
  100. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  101. } else {
  102. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  103. }
  104. }
  105. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  106. }
  107. /**
  108. * 修改支付密码
  109. */
  110. public function actionPayPassword(){
  111. if(\Yii::$app->request->isPost){
  112. $form = new UserForm();
  113. $form->scenario = 'modifyPasswordPay';
  114. $post = \Yii::$app->request->post();
  115. $form->userId = \Yii::$app->user->id;
  116. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  117. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'));
  118. } else {
  119. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  120. }
  121. }
  122. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  123. }
  124. /**
  125. * 直推会员列表
  126. * @return mixed
  127. * @throws \yii\web\HttpException
  128. */
  129. public function actionRecUser() {
  130. $allData = UserInfo::lists('AND REC_UID=:REC_UID', [':REC_UID' => \Yii::$app->user->id], ['useSlaves' => true, 'select'=>'USER_ID,CREATED_AT']);
  131. foreach ($allData['list'] as $key => $data) {
  132. $userBaseInfo = User::getEnCodeInfo($data['USER_ID']);
  133. $userBaseInfo['NATION'] = \Yii::$app->params['nation'][$userBaseInfo['NATION']]['name'] ?? '';
  134. $allData['list'][$key]['BASE_INFO'] = $userBaseInfo;
  135. }
  136. return static::notice($allData);
  137. }
  138. /**
  139. * 上传身份证
  140. * @return mixed
  141. * @throws \yii\base\Exception
  142. * @throws \yii\web\HttpException
  143. */
  144. public function actionIdCard() {
  145. if (\Yii::$app->request->isPost) {
  146. $formModel = new UploadForm();
  147. $formModel->scenario = 'idCardFront';
  148. $formModel->file = UploadedFile::getInstanceByName('file');
  149. //$formModel->token = \Yii::$app->request->post('uploadToken');
  150. $formModel->token = \Yii::$app->request->request('uploadToken');
  151. if ($formModel->file && $formModel->upload()) {
  152. return static::notice(Yii::t('app', 'successfully'));
  153. } else {
  154. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  155. }
  156. }
  157. // 查看该用户是否已经上传过身份证
  158. $oneData = User::find()->select('ID_IMAGE')->where('ID=:ID', [':ID' => \Yii::$app->user->id])->asArray()->one();
  159. if ($oneData['ID_IMAGE']) {
  160. return static::notice($oneData);
  161. } else {
  162. $token = Cache::setUploadToken();
  163. return static::notice($token);
  164. }
  165. }
  166. /**
  167. * 点位绑定
  168. * @return mixed
  169. * @throws \yii\base\Exception
  170. * @throws \yii\web\HttpException
  171. */
  172. public function actionBind() {
  173. $userBind = UserBind::findOneAsArray('USER_ID=:USER_ID AND IS_DEL=0', [':USER_ID' => \Yii::$app->user->id]);
  174. $allData['list']=UserBind::findAllAsArray('MAIN_UID=:MAIN_UID AND IS_DEL=0', [':MAIN_UID' => $userBind['MAIN_UID']], 'ID,USER_ID,MAIN_UID,CREATED_AT,UPDATED_AT');
  175. foreach ($allData['list'] as $key => $value) {
  176. $baseInfo = Info::baseInfoZh($value['USER_ID']);
  177. if ($baseInfo['STATUS'] != 1) {
  178. unset($allData['list'][$key]);
  179. continue;
  180. }
  181. $allData['list'][$key]['USER_NAME'] = $baseInfo['USER_NAME'];
  182. $allData['list'][$key]['REAL_NAME'] = $baseInfo['REAL_NAME'];
  183. $allData['list'][$key]['BANK_PROVINCE_NAME'] = $baseInfo['BANK_PROVINCE_NAME'];
  184. $allData['list'][$key]['BANK_CITY_NAME'] = $baseInfo['BANK_CITY_NAME'];
  185. $allData['list'][$key]['BANK_COUNTY_NAME'] = $baseInfo['BANK_COUNTY_NAME'];
  186. $allData['list'][$key]['OPEN_BANK_NAME'] = $baseInfo['OPEN_BANK_NAME'];
  187. $allData['list'][$key]['BANK_NO'] = $baseInfo['BANK_NO'];
  188. $allData['list'][$key]['MAIN_USER_NAME'] =Info::getUserNameByUserId($value['MAIN_UID']);
  189. }
  190. $allData['list'] = array_values($allData['list']);
  191. return static::notice($allData);
  192. }
  193. /**
  194. * 编辑点位绑定
  195. * @return mixed
  196. * @throws \yii\web\HttpException
  197. */
  198. public function actionBindEdit(){
  199. $id = \Yii::$app->request->get('id');
  200. if(\Yii::$app->request->isPost) {
  201. return parent::edit(UserBindForm::class, Yii::t('app', 'successfully'), 'frontEdit', ['frontEdit'], null, function($form, $result){
  202. //log
  203. });
  204. }
  205. // 获得当前会员的用户名等信息
  206. $userBind = UserBind::findOneAsArray('ID=:ID AND IS_DEL=0', [':ID' => $id]);
  207. $userBinds = UserBind::findAllAsArray('MAIN_UID=:MAIN_UID AND IS_DEL=0',[':MAIN_UID'=>$userBind['MAIN_UID']], 'ID,USER_ID,MAIN_UID,CREATED_AT,UPDATED_AT');
  208. foreach($userBinds as $key=>$value){
  209. $status = Info::getStatusByUserId($value['USER_ID']);
  210. if ($status != 1) {
  211. unset($userBinds[$key]);
  212. continue;
  213. }
  214. $userBinds[$key]['USER_NAME'] = Info::getUserNameByUserId($value['USER_ID']);
  215. }
  216. $userBinds = array_values($userBinds);
  217. return static::notice(['userBinds' => $userBinds,'mainUid'=>$userBind['MAIN_UID']]);
  218. }
  219. // 会员升级,通过会员的编号,获取会员信息
  220. public function actionUpgradeInfo() {
  221. $isSwitchUpgrade = Config::find()
  222. ->where("CONFIG_NAME='isOpenUpgrade'")
  223. ->asArray()
  224. ->one();
  225. $isOpen = !empty($isSwitchUpgrade) && isset($isSwitchUpgrade['VALUE']) ? $isSwitchUpgrade['VALUE'] : 0;
  226. if ($isOpen < 1) {
  227. return static::notice(Yii::t('app', 'theFunctionIsNotAvailable'), 400);
  228. }
  229. $userNumber = \Yii::$app->request->request('userName');
  230. $baseInfo = Info::baseInfoZhByUserName($userNumber);
  231. if ($baseInfo['STATUS'] != 1) {
  232. return static::notice(Yii::t('app', 'inactiveUser'), 400);
  233. }
  234. // 1. 如果是最高级别,则只显示用户基本信息
  235. // 2. 如果不是最高级别,如果用户累计报单数据是0, 或者用户累计报单业绩不符合级别信息,则提示 请联系客服核对业绩
  236. $userId = $baseInfo['ID'];
  237. $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
  238. // 获取系统中的DEC 报单级别配置
  239. $decConfig = DeclarationLevel::getAllData();
  240. $userDecInfo = $decConfig[$userDecId]; // 会员的级别具体信息
  241. $maxPerfInfo = DeclarationLevel::getMaxDecPref();
  242. $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
  243. $observe = Config::getConfigByType('observe'); // 获取观察期配置信息
  244. $observeLimit = $observe['observePeriodLimit']['value']; // 月份限制
  245. $isObserve = User::checkIsObserve($baseInfo['CREATED_AT'], $observeLimit); // 判断用户是否再观察期中
  246. // 如果用户已经是最高级别,则只展示用户信息
  247. $isMax = false;
  248. if ($maxDecId == $userDecId) {
  249. $isMax = true;
  250. }
  251. // NA级别暂时不提供升级
  252. if ($userDecInfo['ID'] == '67ABC6AO8YTK2LN0E055736AECE8644D') {
  253. return static::notice(Yii::t('app', 'upgradeNotSupport'), 400);
  254. }
  255. // 分期的总期数
  256. $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
  257. // 查询是否有FX的分期订单
  258. $stageFX = Instalment::getOneStage($baseInfo['ID'], 'FX');
  259. if ($stageFX && $stageFX < $instalmentConfig) {
  260. $instalment = false;
  261. } else {
  262. // 是否有未完成的BD类型的分期订单
  263. $stage = Instalment::getOneStage($userId, 'BD');
  264. if ($stage && $stage < $instalmentConfig) {
  265. $instalment = true;
  266. } else if ($isMax && $stage == $instalmentConfig) {
  267. $instalment = false;
  268. } else {
  269. $instalment = false;
  270. }
  271. }
  272. // 如果用户已经是最高级别,则只展示用户信息
  273. $userInfo = [
  274. 'DEC_NAME' => $baseInfo['DEC_LV_NAME'], // 用户级别中文
  275. 'DEC_ID' => $userDecId, // 用户级别id
  276. 'REAL_NAME' => $baseInfo['REAL_NAME'], // 真实姓名
  277. 'ADD_AT' => date('Y-m-d', $baseInfo['CREATED_AT']), // 加入时间
  278. 'COUNTRY_NAME' => $baseInfo['COUNTRY_NAME'], // 国家
  279. 'IS_OBSERVE' => $isObserve, // 是否是观察期 true为是观察期
  280. 'IS_MAX' => $isMax, // 是否已是最大级别 最大级别不需要判断报单总PV是多少 只展示基本信息
  281. 'INSTALMENT' => $instalment,
  282. 'NOW_PERF' => User::sumDevPvByUserId($userId), // 用户所有报单PV总和
  283. ];
  284. // 如果是最高级别了,则无需升级
  285. if ($isMax) {
  286. return static::notice(['baseInfo' => $userInfo]);
  287. }
  288. $levelPerf = $userDecInfo['PERF'];// 用户当前级别对应的业绩值
  289. if (!$isMax) {
  290. $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
  291. // // 如果总和小于级别业绩 去掉这校验直接补比如3000-980的差值
  292. // if ($userDecPvSum < $levelPerf) {
  293. // return static::notice('请联系客服人员核对业绩',400);
  294. // }
  295. // 下一级业绩
  296. $nextLevelPerf = DeclarationLevel::getNextDecPref($levelPerf)['PERF'];
  297. // 如果总和超过了下一级业绩
  298. if ($userDecPvSum >= $nextLevelPerf) {
  299. return static::notice(Yii::t('app', 'checkPerformance'), 400);
  300. }
  301. $type = $isObserve ? 1 : 2;
  302. $userInfo['UPGRADE_FUNC'] = $isObserve ? Yii::t('app', 'fillingUpOfADeficit') : Yii::t('app', 'fullPayment');
  303. $upgradeType = UpgradeType::getOneByType($type);
  304. // 如果用户不是最大级别,则需要获取是否观察期,算出PV是否有问题,应该补多少,
  305. $userInfo['UPGRADE_TYPE'] = $upgradeType;
  306. $userInfo['NOW_PERF'] = $userDecPvSum;
  307. $userInfo['NEXT_PERF'] = $nextLevelPerf;
  308. // 用户可选择的级别列表
  309. $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll($levelPerf);// 用户可选择的级别列表
  310. // 如果用户正处于报单分期中,则可以升级到Elite
  311. $userInstalmentInfo = Instalment::getInfo($userId);
  312. if($userInstalmentInfo){
  313. if ($userInstalmentInfo['ORDER_TYPE']=='BD' && $userInstalmentInfo['STAGE'] < 3){
  314. $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll(12);// 用户可选择的级别列表
  315. unset($userInfo['LEVEL_LIST'][$userDecId]);
  316. }
  317. }
  318. // 循环列表,补充升级所需要的补差
  319. foreach ($userInfo['LEVEL_LIST'] as &$v) {
  320. $v['REPAIR_PV'] = $isObserve ? $v['PERF'] - $userInfo['NOW_PERF'] : $v['PERF'];
  321. }
  322. }
  323. return static::notice(['baseInfo' => $userInfo]);
  324. }
  325. // 会员升级管理
  326. public function actionUpgrade() {
  327. $isMax = \Yii::$app->request->get('isMax');
  328. $userNumber = \Yii::$app->request->get('userName');
  329. $isSwitchUpgrade = Config::find()
  330. ->where("CONFIG_NAME='isOpenUpgrade'")
  331. ->asArray()
  332. ->one();
  333. $isOpen = !empty($isSwitchUpgrade) && isset($isSwitchUpgrade['VALUE']) ? $isSwitchUpgrade['VALUE'] : 0;
  334. if ($isOpen < 1) {
  335. return static::notice(Yii::t('app', 'theFunctionIsNotAvailable'), 400);
  336. }
  337. // 开始升级
  338. if (\Yii::$app->request->isPost) {
  339. $post = \Yii::$app->request->post();
  340. // 根据支付方式区分逻辑
  341. $payMethod = \Yii::$app->request->post('payType', '');
  342. if ($payMethod === 'pay_stack') {
  343. $formModel = new ApproachDeclarationUpgradeForm();
  344. } else {
  345. unset($post['payType']);
  346. $formModel = new DeclarationUpgradeForm();
  347. }
  348. $post['type'] = DeclarationForm::TYPE_ZC;
  349. if ($formModel->load($post, '') && $result = $formModel->add($post)) {
  350. return static::notice($result);// Upgrade declaration succeeded升级报单成功
  351. } else {
  352. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  353. }
  354. }
  355. // 升级的会员
  356. $userName = \Yii::$app->request->get('userName');
  357. // 会员信息
  358. $user = User::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => trim($userName)]);
  359. if (!$user) {
  360. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  361. }
  362. //所有报单套餐
  363. $allDecPackage = DeclarationPackage::getAllData();
  364. $decLevels = Cache::getDecLevelConfig();
  365. foreach ($allDecPackage as $k=>$v){
  366. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  367. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  368. }
  369. $baseInfo = Info::baseInfoZhByUserName($userNumber);
  370. // 分期的总期数
  371. $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
  372. // 查询是否有FX的分期订单
  373. $stageFX = Instalment::getOneStage($baseInfo['ID'], 'FX');
  374. if ($stageFX && $stageFX < $instalmentConfig) {
  375. if ($isMax === "true") {
  376. $condition = ") AND S.INSTALMENT = 1000";
  377. } else {
  378. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = 1000)";
  379. }
  380. } else {
  381. // 是否有未完成的BD类型的分期订单
  382. $stageBD = Instalment::getOneStage($baseInfo['ID'], 'BD');
  383. if ($isMax === "true") {
  384. if ($stageBD > 0 && $stageBD < $instalmentConfig) {
  385. $condition = ") AND (S.INSTALMENT = " . ($stageBD + 1) . ")";
  386. } else {
  387. $condition = ") AND S.INSTALMENT = 0";
  388. }
  389. } else {
  390. if ($stageBD > 0 && $stageBD < $instalmentConfig) {
  391. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = " . ($stageBD + 1) . ")";
  392. } else {
  393. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = 1)";
  394. }
  395. }
  396. }
  397. //所有自选商品
  398. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  399. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  400. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  401. $decUserName = User::getEnCodeInfo(\Yii::$app->user->id)['USER_NAME'];
  402. $query_condition= " AND (1<>1";
  403. if(!$isDecReg || ($isDecReg && $isDec==1)){
  404. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  405. }
  406. if($isStudio==1){
  407. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  408. }
  409. $query_condition .= $condition . ' AND N.COUNTRY_ID=:COUNTRY_ID ';
  410. $allGoods = ShopGoods::find()
  411. ->alias('S')
  412. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  413. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  414. ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  415. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $user['COUNTRY_ID']])
  416. ->orderBy('SORT ASC')
  417. ->asArray()
  418. ->all();
  419. foreach ($allGoods as &$goods) {
  420. $goods['TAX'] = Tool::calculateTax($goods['SELL_PRICE'], $goods['TAX_RATE']);
  421. }
  422. // 报单中心汇率
  423. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  424. $decCountry = Countries::getById($decCountryId);
  425. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  426. // 升级会员汇率
  427. $country = Countries::getById($user['COUNTRY_ID']);
  428. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  429. // 升级会员币种
  430. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  431. $userBalance = [
  432. 'cash' => 0,
  433. 'localCash' => 0,
  434. 'coin' => '',
  435. ];
  436. // 会员余额
  437. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  438. if ($userCash) {
  439. $userBalance['cash'] = $userCash['CASH'];
  440. $userBalance['coin'] = $currency['CODE'] ?? '';
  441. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  442. }
  443. // 会员绩效奖金
  444. $userPerformanceAmount = UserPerformance::getAmounts(\Yii::$app->user->id);
  445. $userBalance['prp'] = $userPerformanceAmount ?? 0;
  446. $userBalance['localPrp'] = Tool::convertAmount($userPerformanceAmount, $decUserCurrencyRate, $currencyRate);
  447. // 行政区划
  448. $region = Region::getByCountryId($user['COUNTRY_ID']);
  449. // 支付方式
  450. $payList = ShopGoods::payTypes();
  451. unset($payList['prp']);
  452. // 售卖方式
  453. $sellType = ShopGoods::getCategoryType();
  454. unset($sellType[0]['sell_type'][1]);
  455. return static::notice([
  456. 'allDecPackage' => $allDecPackage,
  457. 'allGoods' => $allGoods,
  458. 'decUserName'=>$decUserName,
  459. 'payList' => $payList,
  460. 'sellType' => $sellType,
  461. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  462. 'userBalance' => $userBalance,
  463. 'decUserCurrencyRate' => $decUserCurrencyRate,
  464. 'userCurrencyRate' => $currencyRate,
  465. 'region' => $region,
  466. ]);
  467. }
  468. /**
  469. * 报单管理
  470. */
  471. public function actionDec() {
  472. $redis = \Yii::$app->redis;
  473. $post = \Yii::$app->request->post();
  474. if (\Yii::$app->request->isPost) {
  475. $userInfo = User::getEnCodeInfo(\Yii::$app->user->id);
  476. if($userInfo['IS_DEC'] == 1 && !empty($post['decUserName']) && $post['decUserName'] != $userInfo['USER_NAME']){
  477. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  478. }
  479. if($userInfo['IS_DEC'] == 0 && $post['decUserName']){
  480. //查询报单编号是否存在
  481. $userId = Info::getUserIdByUserName($post['decUserName']);
  482. if(!$userId){
  483. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  484. }
  485. $isDec = User::getEnCodeInfo($userId)['IS_DEC'];
  486. if(!$isDec){
  487. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  488. }
  489. }
  490. $conUserName = trim($post['conUserName']); // 实际推荐人
  491. $recUserName = trim($post['recUserName']);
  492. // 如果推荐人和实际推荐人是同一人,则跳过检查
  493. if ($recUserName != $conUserName) {
  494. // 实际推荐人必须是推荐人的推荐网上级
  495. $sqlUp = <<<SQL
  496. WITH recursive t_rec AS
  497. (
  498. SELECT
  499. m.USER_ID,
  500. U.USER_NAME,
  501. m.PARENT_UID,
  502. U2.USER_NAME AS PARENT_NAME,
  503. 1 AS node_level
  504. FROM
  505. AR_USER_RELATION_NEW m
  506. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  507. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  508. WHERE
  509. U.USER_NAME = :USER_NAME
  510. UNION ALL
  511. SELECT
  512. t1.USER_ID,
  513. U.USER_NAME,
  514. t1.PARENT_UID,
  515. U2.USER_NAME AS PARENT_NAME,
  516. t2.node_level + 1 -- 结点层级
  517. FROM
  518. AR_USER_RELATION_NEW t1
  519. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  520. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  521. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  522. )
  523. SELECT
  524. *
  525. FROM
  526. t_rec
  527. SQL;
  528. // 查询推荐人的所有上级
  529. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  530. ->bindValue(':USER_NAME', $post['recUserName'])
  531. ->queryAll();
  532. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  533. unset($relationNodeUp[$post['recUserName']]);
  534. if (!in_array($post['conUserName'], $relationNodeUp)) {
  535. return static::notice(Yii::t('app', 'fillSponsorUpline'), 400);
  536. }
  537. }
  538. // 根据支付方式区分逻辑
  539. $payMethod = \Yii::$app->request->post('payType', '');
  540. if ($payMethod === 'pay_stack') {
  541. $formModel = new ApproachDeclarationLoopForm();
  542. } else {
  543. unset($post['payType']);
  544. $formModel = new DeclarationLoopForm();
  545. }
  546. $formModel->scenario = 'userDec';
  547. $post['province'] = $post['province'] ? :1;
  548. $post['city'] = $post['city'] ? :1;
  549. $post['county'] = $post['county'] ? :1;
  550. $post['cityName'] = trim($post['cityName']);
  551. $post['lgaName'] = trim($post['lgaName']);
  552. // 针对那群沙雕移除安置网络的行为,强制增加自动安置左侧
  553. $recUserId = Info::getUserIdByUserName($conUserName);
  554. $bottomPlace = UserNetwork::getBottomPlace($recUserId,'', 'left');
  555. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  556. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  557. $bottomUser = $bottomUser['USER_NAME']; // 推算出的安置人
  558. $post['conUserName'] = $bottomUser; // 安置人
  559. $post['recUserName'] = $conUserName; // 实际推荐人
  560. $post['bottomUserName'] = $recUserName; // 推荐人
  561. $post['location'] = 1;
  562. // 针对于会员编号的判断
  563. $insertUserName = strtoupper($post['insertUserName']);
  564. $getRedisUserName = $redis->get('key_' . $insertUserName);
  565. if (!$getRedisUserName){
  566. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  567. }
  568. if ($insertUserName != $getRedisUserName){
  569. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  570. }
  571. $post['insertUserName'] = $insertUserName;
  572. $post['type'] = DeclarationForm::TYPE_ZC;
  573. $allData['data'][] = $post;
  574. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  575. //发送邮件
  576. try {
  577. Email::sendRegistrationEmail($post['email'], $post['insertUserName'], $post['password']);
  578. } catch (\Exception $e) {
  579. //Yii::error($e->getMessage());
  580. Yii::$app->log->info('邮箱:'.$post['email'].'----错误信息:'.$e->getMessage());
  581. }
  582. return static::notice($result);//报单成功
  583. } else {
  584. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  585. }
  586. }
  587. // 默认国家
  588. $countryId = \Yii::$app->request->get('countryId');
  589. if (!$countryId) {
  590. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  591. }
  592. // 生成随机码 , 初始化redis
  593. $userName = Info::generateWebName($countryId);
  594. //所有报单套餐
  595. $allDecPackage = DeclarationPackage::getAllData();
  596. $decLevels = Cache::getDecLevelConfig();
  597. foreach ($allDecPackage as $k=>$v){
  598. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  599. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  600. }
  601. //所有自选商品
  602. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  603. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  604. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  605. $query_condition = " AND (1<>1";
  606. if(!$isDecReg || ($isDecReg && $isDec==1)){
  607. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  608. }
  609. if($isStudio==1){
  610. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  611. }
  612. $query_condition .= ") AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=:COUNTRY_ID";
  613. // 只查询普通商品
  614. $allGoods = ShopGoods::find()
  615. ->alias('S')
  616. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  617. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  618. ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  619. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $countryId])
  620. ->orderBy('SORT ASC')
  621. ->asArray()
  622. ->all();
  623. // 银行开户行
  624. $allOpenBank = OpenBank::find()
  625. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  626. ->orderBy('BANK_NAME ASC')
  627. ->asArray()
  628. ->all();
  629. if (!$userName) {
  630. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  631. }
  632. //随机码保存在redis中方便进行比对
  633. $redis->setex('key_'.$userName , 3600 , $userName);
  634. // 报单中心会员的本地汇率
  635. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  636. $decCountry = Countries::getById($decCountryId);
  637. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  638. // 新会员的本地汇率
  639. $country = Countries::getById($countryId);
  640. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  641. // 新会员币种
  642. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  643. // 会员账户
  644. $userBalance = [
  645. 'cash' => 0,
  646. 'localCash' => 0,
  647. 'coin' => '',
  648. ];
  649. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  650. if ($userCash) {
  651. $userBalance['cash'] = $userCash['CASH'];
  652. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  653. $userBalance['coin'] = $currency['CODE'] ?? '';
  654. }
  655. // 行政区划
  656. $region = Region::getByCountryId($countryId);
  657. // 支付方式
  658. $payList = ShopGoods::payTypes();
  659. unset($payList['prp']);
  660. // 售卖方式
  661. $sellType = ShopGoods::getCategoryType();
  662. unset($sellType[0]['sell_type'][1]);
  663. return static::notice([
  664. 'allDecPackage' => $allDecPackage,
  665. 'allGoods' => $allGoods,
  666. 'allOpenBank' => $allOpenBank,
  667. 'userName' => $userName,
  668. 'payList' => $payList,
  669. 'sellType' => $sellType,
  670. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  671. 'userBalance' => $userBalance,
  672. 'isDec' => $isDec,
  673. 'decUserCurrencyRate' => $decUserCurrencyRate,
  674. 'userCurrencyRate' => $currencyRate,
  675. 'region' => $region,
  676. 'decLevel' => DeclarationLevel::getData(),
  677. ]);
  678. }
  679. /**
  680. * 报单级别套餐
  681. */
  682. public function actionDecPackage() {
  683. $decLv = \Yii::$app->request->get('id');
  684. //所有报单级别套餐
  685. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  686. return static::notice(['allDecPackage' => $allDecPackage]);
  687. }
  688. /*
  689. * 从会员名和左右,获取底部安置人
  690. *
  691. */
  692. public function actionGetAutoPlace() {
  693. $userName = \Yii::$app->request->get('userName');
  694. $side = \Yii::$app->request->get('side');
  695. $userId = Info::getUserIdByUserName($userName);
  696. $bottomPlace = UserNetwork::getBottomPlace($userId,'', $side);
  697. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  698. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  699. return static::notice($bottomUser);
  700. }
  701. /**
  702. * 会员信息查询
  703. * @return mixed
  704. * @throws \yii\web\HttpException
  705. */
  706. public function actionFullInfo()
  707. {
  708. $userName = \Yii::$app->request->get('userName');
  709. $userId = Info::getUserIdByUserName($userName);
  710. $userInfo['REAL_NAME'] = '';
  711. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  712. if($user){
  713. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  714. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  715. $isLocation = [1 => 'Left-Null', 2 => 'Right-Null'];
  716. if($allChildUser) {
  717. foreach ($allChildUser as $child) {
  718. if ($child['RELATIVE_LOCATION']<'3'){
  719. // $isLocation[$child['RELATIVE_LOCATION']].= 'Full';
  720. $isLocation[$child['RELATIVE_LOCATION']] = str_replace('Null', 'Full', $isLocation[$child['RELATIVE_LOCATION']]);
  721. }
  722. }
  723. }
  724. $userInfo['countryId'] = $user['COUNTRY_ID'];
  725. $userInfo['userId'] = $userId;
  726. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  727. return static::notice($userInfo);
  728. }else{
  729. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  730. }
  731. }
  732. public function actionInspectNetwork()
  733. {
  734. // 推荐人信息
  735. $recommenderName= \Yii::$app->request->get('recommenderName');
  736. $userId = Info::getUserIdByUserName($recommenderName);
  737. $recommender = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  738. if (!$recommender) {
  739. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  740. }
  741. // 实际推荐人信息
  742. $recommenderActualName= \Yii::$app->request->get('recommenderActualName');
  743. $actualId = Info::getUserIdByUserName($recommenderActualName);
  744. $recommenderActual = User::findOneAsArray('ID=:ID', [':ID' => $actualId]);
  745. if (!$recommenderActual) {
  746. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  747. }
  748. // 实际推荐人是否是推荐人本人
  749. if ($actualId == $userId) {
  750. return static::notice([
  751. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  752. 'userId' => $recommenderActual['ID'],
  753. ]);
  754. }
  755. // 实际推荐人必须是推荐人的推荐网上级
  756. $sqlUp =<<<SQL
  757. WITH recursive t_rec AS
  758. (
  759. SELECT
  760. m.USER_ID,
  761. U.USER_NAME,
  762. m.PARENT_UID,
  763. U2.USER_NAME AS PARENT_NAME,
  764. 1 AS node_level
  765. FROM
  766. AR_USER_RELATION_NEW m
  767. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  768. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  769. WHERE
  770. U.USER_NAME = :USER_NAME
  771. UNION ALL
  772. SELECT
  773. t1.USER_ID,
  774. U.USER_NAME,
  775. t1.PARENT_UID,
  776. U2.USER_NAME AS PARENT_NAME,
  777. t2.node_level + 1 -- 结点层级
  778. FROM
  779. AR_USER_RELATION_NEW t1
  780. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  781. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  782. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  783. )
  784. SELECT
  785. *
  786. FROM
  787. t_rec
  788. SQL;
  789. // 查询推荐人的所有上级
  790. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  791. ->bindValue(':USER_NAME' , $recommenderName)
  792. ->queryAll();
  793. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  794. unset($relationNodeUp[$recommenderName]);
  795. if (in_array($recommenderActualName, $relationNodeUp)) {
  796. return static::notice([
  797. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  798. 'userId' => $recommenderActual['ID'],
  799. ]);
  800. }
  801. return static::notice(Yii::t('ctx', 'fillSponsorUpline'), 400);
  802. }
  803. /**
  804. * 复消会员信息查询
  805. * @return mixed
  806. * @throws \yii\web\HttpException
  807. */
  808. public function actionUserBaseInfo()
  809. {
  810. $userName = \Yii::$app->request->get('userName');
  811. $userId = Info::getUserIdByUserName($userName);
  812. if($userId){
  813. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  814. if($allAddress) {
  815. foreach ($allAddress as $key => $row) {
  816. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  817. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  818. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  819. }
  820. }
  821. $userInfo = Info::baseInfoWithNet($userId);
  822. // $decLevelConfig = Cache::getDecLevelConfig();
  823. // $empLevelConfig = Cache::getEmpLevelConfig();
  824. $arr = [
  825. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  826. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  827. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  828. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  829. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  830. 'allAddress'=>$allAddress
  831. ];
  832. return static::notice($arr);
  833. }else{
  834. return static::notice(Yii::t('app', 'repeatSalesMemberNoDoesNotExist'), 400);
  835. }
  836. }
  837. /**
  838. * 会员资料
  839. * @return mixed
  840. * @throws \yii\web\HttpException
  841. */
  842. public function actionBaInfo()
  843. {
  844. $data['userInfo'] = BaUser::getEnCodeInfo(\Yii::$app->user->id);
  845. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  846. // 推荐人
  847. $baUserInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id]);
  848. $sponsor = User::findOneAsArray('ID=:USER_ID', [':USER_ID' => $baUserInfo['REC_UID']]);
  849. $data['userInfo']['SponsorCode'] = $sponsor['USER_NAME'];
  850. $data['userInfo']['SponsorName'] = $sponsor['REAL_NAME'];
  851. return static::notice($data);
  852. }
  853. /**
  854. * 编辑会员资料
  855. * @return mixed
  856. * @throws \yii\web\HttpException
  857. */
  858. public function actionBaEdit()
  859. {
  860. if(\Yii::$app->request->isPost)
  861. {
  862. $form = new BaUserForm();
  863. $post = \Yii::$app->request->post();
  864. $form->scenario = 'modifyProfile';
  865. if ($form->load($post, '') && $result = $form->modifyProfile()){
  866. return static::notice(Yii::t('app', 'personalDataModifiedSuccessfully'), 400);
  867. } else {
  868. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  869. }
  870. }
  871. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  872. }
  873. /**
  874. * 修改登录密码
  875. */
  876. public function actionBaPassword(){
  877. if(\Yii::$app->request->isPost) {
  878. $form = new BaUserForm();
  879. $form->scenario = 'modifyPassword';
  880. $post = \Yii::$app->request->post();
  881. if($form->load($post, '') && $result = $form->modifyPassword()){
  882. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  883. } else {
  884. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  885. }
  886. }
  887. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  888. }
  889. /**
  890. * 修改支付密码
  891. */
  892. public function actionBaPayPassword(){
  893. if(\Yii::$app->request->isPost){
  894. $form = new BaUserForm();
  895. $form->scenario = 'modifyPasswordPay';
  896. $post = \Yii::$app->request->post();
  897. $form->userId = \Yii::$app->user->id;
  898. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  899. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  900. } else {
  901. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  902. }
  903. }
  904. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  905. }
  906. /**
  907. * BA报单管理
  908. */
  909. public function actionBaDec() {
  910. // 生成随机码 , 初始化redis
  911. $userName = Info::generateWebUserName('NG',9);
  912. $redis = \Yii::$app->redis;
  913. $post = \Yii::$app->request->post();
  914. if (\Yii::$app->request->isPost) {
  915. // 根据支付方式区分逻辑
  916. $payMethod = \Yii::$app->request->post('payType', '');
  917. if ($payMethod === 'pay_stack') {
  918. $formModel = new BaApproachDeclarationLoopForm();
  919. } else {
  920. unset($post['payType']);
  921. $formModel = new BaDeclarationLoopForm();
  922. }
  923. $formModel->scenario = 'userDec';
  924. $post['province'] = $post['province'] ? :1;
  925. $post['city'] = $post['city'] ? :1;
  926. $post['county'] = $post['county'] ? :1;
  927. // $post['conUserName'] = trim($post['conUserName']);
  928. $post['recUserName'] = trim($post['recUserName']);
  929. $post['cityName'] = trim($post['cityName']);
  930. $post['lgaName'] = trim($post['lgaName']);
  931. // 针对于会员编号的判断
  932. $insertUserName = strtoupper($post['insertUserName']);
  933. $getRedisUserName = $redis->get('key_' . $insertUserName);
  934. if (!$getRedisUserName){
  935. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  936. }
  937. if ($insertUserName != $getRedisUserName){
  938. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  939. }
  940. $post['insertUserName'] = $insertUserName;
  941. $post['type'] = BaDeclarationForm::TYPE_ZC;
  942. $allData['data'][] = $post;
  943. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  944. return static::notice($result); // 报单成功
  945. } else {
  946. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  947. }
  948. }
  949. // 只查询普通商品
  950. $allGoods = ShopGoods::find()->where("ID='375895243322691584'")->orderBy('SORT ASC')->asArray()->all();
  951. if (!$userName) {
  952. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  953. }
  954. //随机码保存在redis中方便进行比对
  955. $redis->setex('key_'.$userName , 3600 , $userName);
  956. // 会员账户
  957. $userBalance = [
  958. 'cash' => 0,
  959. // 'tourism_points' => 0,
  960. // 'garage_points' => 0,
  961. // 'villa_points' => 0,
  962. ];
  963. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  964. if ($userCash) {
  965. $userBalance['cash'] = $userCash['CASH'];
  966. }
  967. return static::notice([
  968. 'allGoods' => $allGoods,
  969. 'userName' => $userName,
  970. 'payList' => ShopGoods::payTypes(),
  971. 'sellType' => ShopGoods::getCategoryType(),
  972. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  973. 'userBalance' => $userBalance,
  974. ]);
  975. }
  976. /**
  977. * BA会员信息
  978. * @return mixed
  979. * @throws \yii\web\HttpException
  980. */
  981. public function actionBaUserInfo()
  982. {
  983. $userName = \Yii::$app->request->get('userName');
  984. $userId = Info::getBaUserIdByUserName($userName);
  985. $userInfo['REAL_NAME'] = '';
  986. $user = BaUser::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  987. $uInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'REC_UID');
  988. if($user){
  989. $rec_user = UserInfo::findOneAsArray('USER_ID=:USER_ID',[':USER_ID' => $uInfo['REC_UID']], 'USER_ID, USER_NAME');
  990. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  991. $userInfo['REC_USER_ID'] = $rec_user['USER_ID'];
  992. $userInfo['REC_USER_NAME'] = $rec_user['USER_NAME'];
  993. return static::notice($userInfo);
  994. }else{
  995. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  996. }
  997. }
  998. }