UserController.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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. return static::notice([
  443. 'allDecPackage' => $allDecPackage,
  444. 'allGoods' => $allGoods,
  445. 'decUserName'=>$decUserName,
  446. 'payList' => ShopGoods::payTypes(),
  447. 'sellType' => ShopGoods::getCategoryType(),
  448. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  449. 'userBalance' => $userBalance,
  450. 'decUserCurrencyRate' => $decUserCurrencyRate,
  451. 'userCurrencyRate' => $currencyRate,
  452. 'region' => $region,
  453. ]);
  454. }
  455. /**
  456. * 报单管理
  457. */
  458. public function actionDec() {
  459. $redis = \Yii::$app->redis;
  460. $post = \Yii::$app->request->post();
  461. if (\Yii::$app->request->isPost) {
  462. $userInfo = User::getEnCodeInfo(\Yii::$app->user->id);
  463. if($userInfo['IS_DEC'] == 1 && !empty($post['decUserName']) && $post['decUserName'] != $userInfo['USER_NAME']){
  464. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  465. }
  466. if($userInfo['IS_DEC'] == 0 && $post['decUserName']){
  467. //查询报单编号是否存在
  468. $userId = Info::getUserIdByUserName($post['decUserName']);
  469. if(!$userId){
  470. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  471. }
  472. $isDec = User::getEnCodeInfo($userId)['IS_DEC'];
  473. if(!$isDec){
  474. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  475. }
  476. }
  477. // 实际推荐人必须是推荐人的推荐网上级
  478. $sqlUp =<<<SQL
  479. WITH recursive t_rec AS
  480. (
  481. SELECT
  482. m.USER_ID,
  483. U.USER_NAME,
  484. m.PARENT_UID,
  485. U2.USER_NAME AS PARENT_NAME,
  486. 1 AS node_level
  487. FROM
  488. AR_USER_RELATION_NEW m
  489. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  490. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  491. WHERE
  492. U.USER_NAME = :USER_NAME
  493. UNION ALL
  494. SELECT
  495. t1.USER_ID,
  496. U.USER_NAME,
  497. t1.PARENT_UID,
  498. U2.USER_NAME AS PARENT_NAME,
  499. t2.node_level + 1 -- 结点层级
  500. FROM
  501. AR_USER_RELATION_NEW t1
  502. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  503. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  504. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  505. )
  506. SELECT
  507. *
  508. FROM
  509. t_rec
  510. SQL;
  511. // 查询推荐人的所有上级
  512. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  513. ->bindValue(':USER_NAME' , $post['recUserName'])
  514. ->queryAll();
  515. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  516. unset($relationNodeUp[$post['recUserName']]);
  517. if (!in_array($post['conUserName'], $relationNodeUp)) {
  518. return static::notice(Yii::t('app', 'fillSponsorUpline'), 400);
  519. }
  520. // 根据支付方式区分逻辑
  521. $payMethod = \Yii::$app->request->post('payType', '');
  522. if ($payMethod === 'pay_stack') {
  523. $formModel = new ApproachDeclarationLoopForm();
  524. } else {
  525. unset($post['payType']);
  526. $formModel = new DeclarationLoopForm();
  527. }
  528. $formModel->scenario = 'userDec';
  529. $post['province'] = $post['province'] ? :1;
  530. $post['city'] = $post['city'] ? :1;
  531. $post['county'] = $post['county'] ? :1;
  532. $conUserName = trim($post['conUserName']); // 实际推荐人
  533. $recUserName = trim($post['recUserName']);
  534. $post['cityName'] = trim($post['cityName']);
  535. $post['lgaName'] = trim($post['lgaName']);
  536. // 针对那群沙雕移除安置网络的行为,强制增加自动安置左侧
  537. $recUserId = Info::getUserIdByUserName($conUserName);
  538. $bottomPlace = UserNetwork::getBottomPlace($recUserId,'', 'left');
  539. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  540. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  541. $bottomUser = $bottomUser['USER_NAME']; // 推算出的安置人
  542. $post['conUserName'] = $bottomUser; // 安置人
  543. $post['recUserName'] = $conUserName; // 实际推荐人
  544. $post['bottomUserName'] = $recUserName; // 推荐人
  545. $post['location'] = 1;
  546. // 针对于会员编号的判断
  547. $insertUserName = strtoupper($post['insertUserName']);
  548. $getRedisUserName = $redis->get('key_' . $insertUserName);
  549. if (!$getRedisUserName){
  550. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  551. }
  552. if ($insertUserName != $getRedisUserName){
  553. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  554. }
  555. $post['insertUserName'] = $insertUserName;
  556. $post['type'] = DeclarationForm::TYPE_ZC;
  557. $allData['data'][] = $post;
  558. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  559. return static::notice($result);//报单成功
  560. } else {
  561. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  562. }
  563. }
  564. // 默认国家
  565. $countryId = \Yii::$app->request->get('countryId');
  566. if (!$countryId) {
  567. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  568. }
  569. // 生成随机码 , 初始化redis
  570. $userName = Info::generateWebName($countryId);
  571. //所有报单套餐
  572. $allDecPackage = DeclarationPackage::getAllData();
  573. $decLevels = Cache::getDecLevelConfig();
  574. foreach ($allDecPackage as $k=>$v){
  575. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  576. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  577. }
  578. //所有自选商品
  579. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  580. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  581. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  582. $query_condition = " AND (1<>1";
  583. if(!$isDecReg || ($isDecReg && $isDec==1)){
  584. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  585. }
  586. if($isStudio==1){
  587. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  588. }
  589. $query_condition .= ") AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=:COUNTRY_ID";
  590. // 只查询普通商品
  591. $allGoods = ShopGoods::find()
  592. ->alias('S')
  593. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  594. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  595. ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  596. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $countryId])
  597. ->orderBy('SORT ASC')
  598. ->asArray()
  599. ->all();
  600. // 银行开户行
  601. $allOpenBank = OpenBank::find()
  602. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  603. ->orderBy('BANK_NAME ASC')
  604. ->asArray()
  605. ->all();
  606. if (!$userName) {
  607. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  608. }
  609. //随机码保存在redis中方便进行比对
  610. $redis->setex('key_'.$userName , 3600 , $userName);
  611. // 报单中心会员的本地汇率
  612. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  613. $decCountry = Countries::getById($decCountryId);
  614. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  615. // 新会员的本地汇率
  616. $country = Countries::getById($countryId);
  617. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  618. // 新会员币种
  619. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  620. // 会员账户
  621. $userBalance = [
  622. 'cash' => 0,
  623. 'localCash' => 0,
  624. 'coin' => '',
  625. ];
  626. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  627. if ($userCash) {
  628. $userBalance['cash'] = $userCash['CASH'];
  629. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  630. $userBalance['coin'] = $currency['CODE'] ?? '';
  631. }
  632. // 行政区划
  633. $region = Region::getByCountryId($countryId);
  634. return static::notice([
  635. 'allDecPackage' => $allDecPackage,
  636. 'allGoods' => $allGoods,
  637. 'allOpenBank' => $allOpenBank,
  638. 'userName' => $userName,
  639. 'payList' => ShopGoods::payTypes(),
  640. 'sellType' => ShopGoods::getCategoryType(),
  641. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  642. 'userBalance' => $userBalance,
  643. 'isDec' => $isDec,
  644. 'decUserCurrencyRate' => $decUserCurrencyRate,
  645. 'userCurrencyRate' => $currencyRate,
  646. 'region' => $region,
  647. 'decLevel' => DeclarationLevel::getData()
  648. ]);
  649. }
  650. /**
  651. * 报单级别套餐
  652. */
  653. public function actionDecPackage() {
  654. $decLv = \Yii::$app->request->get('id');
  655. //所有报单级别套餐
  656. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  657. return static::notice(['allDecPackage' => $allDecPackage]);
  658. }
  659. /*
  660. * 从会员名和左右,获取底部安置人
  661. *
  662. */
  663. public function actionGetAutoPlace() {
  664. $userName = \Yii::$app->request->get('userName');
  665. $side = \Yii::$app->request->get('side');
  666. $userId = Info::getUserIdByUserName($userName);
  667. $bottomPlace = UserNetwork::getBottomPlace($userId,'', $side);
  668. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  669. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  670. return static::notice($bottomUser);
  671. }
  672. /**
  673. * 会员信息查询
  674. * @return mixed
  675. * @throws \yii\web\HttpException
  676. */
  677. public function actionFullInfo()
  678. {
  679. $userName = \Yii::$app->request->get('userName');
  680. $userId = Info::getUserIdByUserName($userName);
  681. $userInfo['REAL_NAME'] = '';
  682. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  683. if($user){
  684. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  685. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  686. $isLocation = [1 => 'Left-Null', 2 => 'Right-Null'];
  687. if($allChildUser) {
  688. foreach ($allChildUser as $child) {
  689. if ($child['RELATIVE_LOCATION']<'3'){
  690. // $isLocation[$child['RELATIVE_LOCATION']].= 'Full';
  691. $isLocation[$child['RELATIVE_LOCATION']] = str_replace('Null', 'Full', $isLocation[$child['RELATIVE_LOCATION']]);
  692. }
  693. }
  694. }
  695. $userInfo['countryId'] = $user['COUNTRY_ID'];
  696. $userInfo['userId'] = $userId;
  697. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  698. return static::notice($userInfo);
  699. }else{
  700. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  701. }
  702. }
  703. public function actionInspectNetwork()
  704. {
  705. // 推荐人信息
  706. $recommenderName= \Yii::$app->request->get('recommenderName');
  707. $userId = Info::getUserIdByUserName($recommenderName);
  708. $recommender = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  709. if (!$recommender) {
  710. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  711. }
  712. // 实际推荐人信息
  713. $recommenderActualName= \Yii::$app->request->get('recommenderActualName');
  714. $actualId = Info::getUserIdByUserName($recommenderActualName);
  715. $recommenderActual = User::findOneAsArray('ID=:ID', [':ID' => $actualId]);
  716. if (!$recommenderActual) {
  717. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  718. }
  719. // 实际推荐人是否是推荐人本人
  720. if ($actualId == $userId) {
  721. return static::notice([
  722. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  723. 'userId' => $recommenderActual['ID'],
  724. ]);
  725. }
  726. // 实际推荐人必须是推荐人的推荐网上级
  727. $sqlUp =<<<SQL
  728. WITH recursive t_rec AS
  729. (
  730. SELECT
  731. m.USER_ID,
  732. U.USER_NAME,
  733. m.PARENT_UID,
  734. U2.USER_NAME AS PARENT_NAME,
  735. 1 AS node_level
  736. FROM
  737. AR_USER_RELATION_NEW m
  738. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  739. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  740. WHERE
  741. U.USER_NAME = :USER_NAME
  742. UNION ALL
  743. SELECT
  744. t1.USER_ID,
  745. U.USER_NAME,
  746. t1.PARENT_UID,
  747. U2.USER_NAME AS PARENT_NAME,
  748. t2.node_level + 1 -- 结点层级
  749. FROM
  750. AR_USER_RELATION_NEW t1
  751. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  752. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  753. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  754. )
  755. SELECT
  756. *
  757. FROM
  758. t_rec
  759. SQL;
  760. // 查询推荐人的所有上级
  761. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  762. ->bindValue(':USER_NAME' , $recommenderName)
  763. ->queryAll();
  764. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  765. unset($relationNodeUp[$recommenderName]);
  766. if (in_array($recommenderActualName, $relationNodeUp)) {
  767. return static::notice([
  768. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  769. 'userId' => $recommenderActual['ID'],
  770. ]);
  771. }
  772. return static::notice(Yii::t('ctx', 'fillSponsorUpline'), 400);
  773. }
  774. /**
  775. * 复消会员信息查询
  776. * @return mixed
  777. * @throws \yii\web\HttpException
  778. */
  779. public function actionUserBaseInfo()
  780. {
  781. $userName = \Yii::$app->request->get('userName');
  782. $userId = Info::getUserIdByUserName($userName);
  783. if($userId){
  784. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  785. if($allAddress) {
  786. foreach ($allAddress as $key => $row) {
  787. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  788. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  789. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  790. }
  791. }
  792. $userInfo = Info::baseInfoWithNet($userId);
  793. // $decLevelConfig = Cache::getDecLevelConfig();
  794. // $empLevelConfig = Cache::getEmpLevelConfig();
  795. $arr = [
  796. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  797. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  798. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  799. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  800. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  801. 'allAddress'=>$allAddress
  802. ];
  803. return static::notice($arr);
  804. }else{
  805. return static::notice(Yii::t('app', 'repeatSalesMemberNoDoesNotExist'), 400);
  806. }
  807. }
  808. /**
  809. * 会员资料
  810. * @return mixed
  811. * @throws \yii\web\HttpException
  812. */
  813. public function actionBaInfo()
  814. {
  815. $data['userInfo'] = BaUser::getEnCodeInfo(\Yii::$app->user->id);
  816. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  817. // 推荐人
  818. $baUserInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id]);
  819. $sponsor = User::findOneAsArray('ID=:USER_ID', [':USER_ID' => $baUserInfo['REC_UID']]);
  820. $data['userInfo']['SponsorCode'] = $sponsor['USER_NAME'];
  821. $data['userInfo']['SponsorName'] = $sponsor['REAL_NAME'];
  822. return static::notice($data);
  823. }
  824. /**
  825. * 编辑会员资料
  826. * @return mixed
  827. * @throws \yii\web\HttpException
  828. */
  829. public function actionBaEdit()
  830. {
  831. if(\Yii::$app->request->isPost)
  832. {
  833. $form = new BaUserForm();
  834. $post = \Yii::$app->request->post();
  835. $form->scenario = 'modifyProfile';
  836. if ($form->load($post, '') && $result = $form->modifyProfile()){
  837. return static::notice(Yii::t('app', 'personalDataModifiedSuccessfully'), 400);
  838. } else {
  839. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  840. }
  841. }
  842. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  843. }
  844. /**
  845. * 修改登录密码
  846. */
  847. public function actionBaPassword(){
  848. if(\Yii::$app->request->isPost) {
  849. $form = new BaUserForm();
  850. $form->scenario = 'modifyPassword';
  851. $post = \Yii::$app->request->post();
  852. if($form->load($post, '') && $result = $form->modifyPassword()){
  853. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  854. } else {
  855. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  856. }
  857. }
  858. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  859. }
  860. /**
  861. * 修改支付密码
  862. */
  863. public function actionBaPayPassword(){
  864. if(\Yii::$app->request->isPost){
  865. $form = new BaUserForm();
  866. $form->scenario = 'modifyPasswordPay';
  867. $post = \Yii::$app->request->post();
  868. $form->userId = \Yii::$app->user->id;
  869. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  870. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  871. } else {
  872. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  873. }
  874. }
  875. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  876. }
  877. /**
  878. * BA报单管理
  879. */
  880. public function actionBaDec() {
  881. // 生成随机码 , 初始化redis
  882. $userName = Info::generateWebUserName('NG',9);
  883. $redis = \Yii::$app->redis;
  884. $post = \Yii::$app->request->post();
  885. if (\Yii::$app->request->isPost) {
  886. // 根据支付方式区分逻辑
  887. $payMethod = \Yii::$app->request->post('payType', '');
  888. if ($payMethod === 'pay_stack') {
  889. $formModel = new BaApproachDeclarationLoopForm();
  890. } else {
  891. unset($post['payType']);
  892. $formModel = new BaDeclarationLoopForm();
  893. }
  894. $formModel->scenario = 'userDec';
  895. $post['province'] = $post['province'] ? :1;
  896. $post['city'] = $post['city'] ? :1;
  897. $post['county'] = $post['county'] ? :1;
  898. // $post['conUserName'] = trim($post['conUserName']);
  899. $post['recUserName'] = trim($post['recUserName']);
  900. $post['cityName'] = trim($post['cityName']);
  901. $post['lgaName'] = trim($post['lgaName']);
  902. // 针对于会员编号的判断
  903. $insertUserName = strtoupper($post['insertUserName']);
  904. $getRedisUserName = $redis->get('key_' . $insertUserName);
  905. if (!$getRedisUserName){
  906. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  907. }
  908. if ($insertUserName != $getRedisUserName){
  909. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  910. }
  911. $post['insertUserName'] = $insertUserName;
  912. $post['type'] = BaDeclarationForm::TYPE_ZC;
  913. $allData['data'][] = $post;
  914. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  915. return static::notice($result); // 报单成功
  916. } else {
  917. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  918. }
  919. }
  920. // 只查询普通商品
  921. $allGoods = ShopGoods::find()->where("ID='375895243322691584'")->orderBy('SORT ASC')->asArray()->all();
  922. if (!$userName) {
  923. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  924. }
  925. //随机码保存在redis中方便进行比对
  926. $redis->setex('key_'.$userName , 3600 , $userName);
  927. // 会员账户
  928. $userBalance = [
  929. 'cash' => 0,
  930. // 'tourism_points' => 0,
  931. // 'garage_points' => 0,
  932. // 'villa_points' => 0,
  933. ];
  934. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  935. if ($userCash) {
  936. $userBalance['cash'] = $userCash['CASH'];
  937. }
  938. return static::notice([
  939. 'allGoods' => $allGoods,
  940. 'userName' => $userName,
  941. 'payList' => ShopGoods::payTypes(),
  942. 'sellType' => ShopGoods::getCategoryType(),
  943. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  944. 'userBalance' => $userBalance,
  945. ]);
  946. }
  947. /**
  948. * BA会员信息
  949. * @return mixed
  950. * @throws \yii\web\HttpException
  951. */
  952. public function actionBaUserInfo()
  953. {
  954. $userName = \Yii::$app->request->get('userName');
  955. $userId = Info::getBaUserIdByUserName($userName);
  956. $userInfo['REAL_NAME'] = '';
  957. $user = BaUser::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  958. $uInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'REC_UID');
  959. if($user){
  960. $rec_user = UserInfo::findOneAsArray('USER_ID=:USER_ID',[':USER_ID' => $uInfo['REC_UID']], 'USER_ID, USER_NAME');
  961. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  962. $userInfo['REC_USER_ID'] = $rec_user['USER_ID'];
  963. $userInfo['REC_USER_NAME'] = $rec_user['USER_NAME'];
  964. return static::notice($userInfo);
  965. }else{
  966. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  967. }
  968. }
  969. }