UserController.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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 = Cache::getDecLevelConfig();
  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. // 分期的总期数
  250. $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
  251. // 查询是否有FX的分期订单
  252. $stageFX = Instalment::getOneStage($baseInfo['ID'], 'FX');
  253. if ($stageFX && $stageFX < $instalmentConfig) {
  254. $instalment = false;
  255. } else {
  256. // 是否有未完成的BD类型的分期订单
  257. $stage = Instalment::getOneStage($userId, 'BD');
  258. if ($stage && $stage < $instalmentConfig) {
  259. $instalment = true;
  260. } else if ($isMax && $stage == $instalmentConfig) {
  261. $instalment = false;
  262. } else {
  263. $instalment = false;
  264. }
  265. }
  266. // 如果用户已经是最高级别,则只展示用户信息
  267. $userInfo = [
  268. 'DEC_NAME' => $baseInfo['DEC_LV_NAME'], // 用户级别中文
  269. 'DEC_ID' => $userDecId, // 用户级别id
  270. 'REAL_NAME' => $baseInfo['REAL_NAME'], // 真实姓名
  271. 'ADD_AT' => date('Y-m-d', $baseInfo['CREATED_AT']), // 加入时间
  272. 'COUNTRY_NAME' => $baseInfo['COUNTRY_NAME'], // 国家
  273. 'IS_OBSERVE' => $isObserve, // 是否是观察期 true为是观察期
  274. 'IS_MAX' => $isMax, // 是否已是最大级别 最大级别不需要判断报单总PV是多少 只展示基本信息
  275. 'INSTALMENT' => $instalment,
  276. 'NOW_PERF' => User::sumDevPvByUserId($userId), // 用户所有报单PV总和
  277. ];
  278. // 如果是最高级别了,则无需升级
  279. if ($isMax) {
  280. return static::notice(['baseInfo' => $userInfo]);
  281. }
  282. $levelPerf = $userDecInfo['PERF'];// 用户当前级别对应的业绩值
  283. if (!$isMax) {
  284. $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
  285. // // 如果总和小于级别业绩 去掉这校验直接补比如3000-980的差值
  286. // if ($userDecPvSum < $levelPerf) {
  287. // return static::notice('请联系客服人员核对业绩',400);
  288. // }
  289. // 下一级业绩
  290. $nextLevelPerf = DeclarationLevel::getNextDecPref($levelPerf)['PERF'];
  291. // 如果总和超过了下一级业绩
  292. if ($userDecPvSum >= $nextLevelPerf) {
  293. return static::notice(Yii::t('app', 'checkPerformance'), 400);
  294. }
  295. $type = $isObserve ? 1 : 2;
  296. $userInfo['UPGRADE_FUNC'] = $isObserve ? Yii::t('app', 'fillingUpOfADeficit') : Yii::t('app', 'fullPayment');
  297. $upgradeType = UpgradeType::getOneByType($type);
  298. // 如果用户不是最大级别,则需要获取是否观察期,算出PV是否有问题,应该补多少,
  299. $userInfo['UPGRADE_TYPE'] = $upgradeType;
  300. $userInfo['NOW_PERF'] = $userDecPvSum;
  301. $userInfo['NEXT_PERF'] = $nextLevelPerf;
  302. // 用户可选择的级别列表
  303. $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll($levelPerf);// 用户可选择的级别列表
  304. // 如果用户正处于报单分期中,则可以升级到Elite
  305. $userInstalmentInfo = Instalment::getInfo($userId);
  306. if($userInstalmentInfo){
  307. if ($userInstalmentInfo['ORDER_TYPE']=='BD' && $userInstalmentInfo['STAGE'] < 3){
  308. $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll(12);// 用户可选择的级别列表
  309. unset($userInfo['LEVEL_LIST'][$userDecId]);
  310. }
  311. }
  312. // 循环列表,补充升级所需要的补差
  313. foreach ($userInfo['LEVEL_LIST'] as &$v) {
  314. $v['REPAIR_PV'] = $isObserve ? $v['PERF'] - $userInfo['NOW_PERF'] : $v['PERF'];
  315. }
  316. }
  317. return static::notice(['baseInfo' => $userInfo]);
  318. }
  319. // 会员升级管理
  320. public function actionUpgrade() {
  321. $isMax = \Yii::$app->request->get('isMax');
  322. $userNumber = \Yii::$app->request->get('userName');
  323. $isSwitchUpgrade = Config::find()
  324. ->where("CONFIG_NAME='isOpenUpgrade'")
  325. ->asArray()
  326. ->one();
  327. $isOpen = !empty($isSwitchUpgrade) && isset($isSwitchUpgrade['VALUE']) ? $isSwitchUpgrade['VALUE'] : 0;
  328. if ($isOpen < 1) {
  329. return static::notice(Yii::t('app', 'theFunctionIsNotAvailable'), 400);
  330. }
  331. // 开始升级
  332. if (\Yii::$app->request->isPost) {
  333. $post = \Yii::$app->request->post();
  334. // 根据支付方式区分逻辑
  335. $payMethod = \Yii::$app->request->post('payType', '');
  336. if ($payMethod === 'pay_stack') {
  337. $formModel = new ApproachDeclarationUpgradeForm();
  338. } else {
  339. unset($post['payType']);
  340. $formModel = new DeclarationUpgradeForm();
  341. }
  342. $post['type'] = DeclarationForm::TYPE_ZC;
  343. if ($formModel->load($post, '') && $result = $formModel->add($post)) {
  344. return static::notice($result);// Upgrade declaration succeeded升级报单成功
  345. } else {
  346. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  347. }
  348. }
  349. // 升级的会员
  350. $userName = \Yii::$app->request->get('userName');
  351. // 会员信息
  352. $user = User::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => trim($userName)]);
  353. if (!$user) {
  354. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  355. }
  356. //所有报单套餐
  357. $allDecPackage = DeclarationPackage::getAllData();
  358. $decLevels = Cache::getDecLevelConfig();
  359. foreach ($allDecPackage as $k=>$v){
  360. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  361. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  362. }
  363. $baseInfo = Info::baseInfoZhByUserName($userNumber);
  364. // 分期的总期数
  365. $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
  366. // 查询是否有FX的分期订单
  367. $stageFX = Instalment::getOneStage($baseInfo['ID'], 'FX');
  368. if ($stageFX && $stageFX < $instalmentConfig) {
  369. if ($isMax === "true") {
  370. $condition = ") AND S.INSTALMENT = 1000";
  371. } else {
  372. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = 1000)";
  373. }
  374. } else {
  375. // 是否有未完成的BD类型的分期订单
  376. $stageBD = Instalment::getOneStage($baseInfo['ID'], 'BD');
  377. if ($isMax === "true") {
  378. if ($stageBD > 0 && $stageBD < $instalmentConfig) {
  379. $condition = ") AND (S.INSTALMENT = " . ($stageBD + 1) . ")";
  380. } else {
  381. $condition = ") AND S.INSTALMENT = 0";
  382. }
  383. } else {
  384. if ($stageBD > 0 && $stageBD < $instalmentConfig) {
  385. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = " . ($stageBD + 1) . ")";
  386. } else {
  387. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = 1)";
  388. }
  389. }
  390. }
  391. //所有自选商品
  392. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  393. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  394. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  395. $decUserName = User::getEnCodeInfo(\Yii::$app->user->id)['USER_NAME'];
  396. $query_condition= " AND (1<>1";
  397. if(!$isDecReg || ($isDecReg && $isDec==1)){
  398. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  399. }
  400. if($isStudio==1){
  401. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  402. }
  403. $query_condition .= $condition . ' AND N.COUNTRY_ID=:COUNTRY_ID ';
  404. $allGoods = ShopGoods::find()
  405. ->alias('S')
  406. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  407. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  408. ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  409. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $user['COUNTRY_ID']])
  410. ->orderBy('SORT ASC')
  411. ->asArray()
  412. ->all();
  413. foreach ($allGoods as &$goods) {
  414. $goods['TAX'] = Tool::calculateTax($goods['SELL_PRICE'], $goods['TAX_RATE']);
  415. }
  416. // 报单中心汇率
  417. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  418. $decCountry = Countries::getById($decCountryId);
  419. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  420. // 升级会员汇率
  421. $country = Countries::getById($user['COUNTRY_ID']);
  422. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  423. // 升级会员币种
  424. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  425. $userBalance = [
  426. 'cash' => 0,
  427. 'localCash' => 0,
  428. 'coin' => '',
  429. ];
  430. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  431. if ($userCash) {
  432. $userBalance['cash'] = $userCash['CASH'];
  433. $userBalance['coin'] = $currency['CODE'] ?? '';
  434. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  435. }
  436. // 行政区划
  437. $region = Region::getByCountryId($user['COUNTRY_ID']);
  438. return static::notice([
  439. 'allDecPackage' => $allDecPackage,
  440. 'allGoods' => $allGoods,
  441. 'decUserName'=>$decUserName,
  442. 'payList' => ShopGoods::payTypes(),
  443. 'sellType' => ShopGoods::getCategoryType(),
  444. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  445. 'userBalance' => $userBalance,
  446. 'decUserCurrencyRate' => $decUserCurrencyRate,
  447. 'userCurrencyRate' => $currencyRate,
  448. 'region' => $region,
  449. ]);
  450. }
  451. /**
  452. * 报单管理
  453. */
  454. public function actionDec() {
  455. $redis = \Yii::$app->redis;
  456. $post = \Yii::$app->request->post();
  457. if (\Yii::$app->request->isPost) {
  458. $userInfo = User::getEnCodeInfo(\Yii::$app->user->id);
  459. if($userInfo['IS_DEC'] == 1 && !empty($post['decUserName']) && $post['decUserName'] != $userInfo['USER_NAME']){
  460. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  461. }
  462. if($userInfo['IS_DEC'] == 0 && $post['decUserName']){
  463. //查询报单编号是否存在
  464. $userId = Info::getUserIdByUserName($post['decUserName']);
  465. if(!$userId){
  466. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  467. }
  468. $isDec = User::getEnCodeInfo($userId)['IS_DEC'];
  469. if(!$isDec){
  470. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  471. }
  472. }
  473. // 实际推荐人必须是推荐人上级的校验
  474. // 实际推荐人必须是推荐人的推荐网上级
  475. $sqlUp =<<<SQL
  476. WITH recursive t_rec AS
  477. (
  478. SELECT
  479. m.USER_ID,
  480. U.USER_NAME,
  481. m.PARENT_UID,
  482. U2.USER_NAME AS PARENT_NAME,
  483. 1 AS node_level
  484. FROM
  485. AR_USER_RELATION_NEW m
  486. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  487. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  488. WHERE
  489. U.USER_NAME = :USER_NAME
  490. UNION ALL
  491. SELECT
  492. t1.USER_ID,
  493. U.USER_NAME,
  494. t1.PARENT_UID,
  495. U2.USER_NAME AS PARENT_NAME,
  496. t2.node_level + 1 -- 结点层级
  497. FROM
  498. AR_USER_RELATION_NEW t1
  499. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  500. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  501. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  502. )
  503. SELECT
  504. *
  505. FROM
  506. t_rec
  507. SQL;
  508. // 查询推荐人的所有上级
  509. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  510. ->bindValue(':USER_NAME' , $post['recUserName'])
  511. ->queryAll();
  512. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  513. unset($relationNodeUp[$post['recUserName']]);
  514. if (!in_array($post['conUserName'], $relationNodeUp)) {
  515. return static::notice(Yii::t('app', 'fillSponsorUpline'), 400);
  516. }
  517. // 根据支付方式区分逻辑
  518. $payMethod = \Yii::$app->request->post('payType', '');
  519. if ($payMethod === 'pay_stack') {
  520. $formModel = new ApproachDeclarationLoopForm();
  521. } else {
  522. unset($post['payType']);
  523. $formModel = new DeclarationLoopForm();
  524. }
  525. $formModel->scenario = 'userDec';
  526. $post['province'] = $post['province'] ? :1;
  527. $post['city'] = $post['city'] ? :1;
  528. $post['county'] = $post['county'] ? :1;
  529. $conUserName = trim($post['conUserName']); // 实际推荐人
  530. $recUserName = trim($post['recUserName']);
  531. $post['cityName'] = trim($post['cityName']);
  532. $post['lgaName'] = trim($post['lgaName']);
  533. // 针对那群沙雕移除安置网络的行为,强制增加自动安置左侧
  534. $recUserId = Info::getUserIdByUserName($conUserName);
  535. $bottomPlace = UserNetwork::getBottomPlace($recUserId,'', 'left');
  536. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  537. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  538. $bottomUser = $bottomUser['USER_NAME']; // 推算出的安置人
  539. $post['conUserName'] = $bottomUser; // 安置人
  540. $post['recUserName'] = $conUserName; // 实际推荐人
  541. $post['bottomUserName'] = $recUserName; // 推荐人
  542. $post['location'] = 1;
  543. // 针对于会员编号的判断
  544. if($post['decType']=='normal'){ // 普通报单,判断Redis中的用户名是否一致
  545. $insertUserName = strtoupper($post['insertUserName']);
  546. $getRedisUserName = $redis->get('key_' . $insertUserName);
  547. if (!$getRedisUserName){
  548. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  549. }
  550. if ($insertUserName != $getRedisUserName){
  551. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  552. }
  553. }else{ // BA升级,需要判断BA用户是否存在
  554. $insertUserName = $post['insertUserName'];
  555. }
  556. $post['insertUserName'] = $insertUserName;
  557. $post['type'] = DeclarationForm::TYPE_ZC;
  558. $allData['data'][] = $post;
  559. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  560. return static::notice($result);//报单成功
  561. } else {
  562. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  563. }
  564. }
  565. // 默认国家
  566. $countryId = \Yii::$app->request->get('countryId');
  567. if (!$countryId) {
  568. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  569. }
  570. // 生成随机码 , 初始化redis
  571. $userName = Info::generateWebName($countryId);
  572. //所有报单套餐
  573. $allDecPackage = DeclarationPackage::getAllData();
  574. $decLevels = Cache::getDecLevelConfig();
  575. foreach ($allDecPackage as $k=>$v){
  576. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  577. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  578. }
  579. //所有自选商品
  580. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  581. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  582. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  583. $query_condition = " AND (1<>1";
  584. if(!$isDecReg || ($isDecReg && $isDec==1)){
  585. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  586. }
  587. if($isStudio==1){
  588. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  589. }
  590. $query_condition .= ") AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=:COUNTRY_ID";
  591. // 只查询普通商品
  592. $allGoods = ShopGoods::find()
  593. ->alias('S')
  594. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  595. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  596. ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  597. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $countryId])
  598. ->orderBy('SORT ASC')
  599. ->asArray()
  600. ->all();
  601. // 银行开户行
  602. $allOpenBank = OpenBank::find()
  603. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  604. ->orderBy('BANK_NAME ASC')
  605. ->asArray()
  606. ->all();
  607. if (!$userName) {
  608. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  609. }
  610. //随机码保存在redis中方便进行比对
  611. $redis->setex('key_'.$userName , 3600 , $userName);
  612. // 报单中心会员的本地汇率
  613. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  614. $decCountry = Countries::getById($decCountryId);
  615. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  616. // 新会员的本地汇率
  617. $country = Countries::getById($countryId);
  618. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  619. // 新会员币种
  620. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  621. // 会员账户
  622. $userBalance = [
  623. 'cash' => 0,
  624. 'localCash' => 0,
  625. 'coin' => '',
  626. ];
  627. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  628. if ($userCash) {
  629. $userBalance['cash'] = $userCash['CASH'];
  630. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  631. $userBalance['coin'] = $currency['CODE'] ?? '';
  632. }
  633. // 行政区划
  634. $region = Region::getByCountryId($countryId);
  635. return static::notice([
  636. 'allDecPackage' => $allDecPackage,
  637. 'allGoods' => $allGoods,
  638. 'allOpenBank' => $allOpenBank,
  639. 'userName' => $userName,
  640. 'payList' => ShopGoods::payTypes(),
  641. 'sellType' => ShopGoods::getCategoryType(),
  642. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  643. 'userBalance' => $userBalance,
  644. 'isDec' => $isDec,
  645. 'decUserCurrencyRate' => $decUserCurrencyRate,
  646. 'userCurrencyRate' => $currencyRate,
  647. 'region' => $region,
  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. }