UserController.php 45 KB

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