UserController.php 44 KB

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