UserController.php 44 KB

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