UserController.php 43 KB

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