UserController.php 45 KB

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