UserController.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  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. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  591. //发送邮件
  592. Email::sendRegistrationEmail($post['email'], $post['insertUserName'], $post['password']);
  593. return static::notice($result);//报单成功
  594. } else {
  595. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  596. }
  597. }
  598. // 默认国家
  599. $countryId = \Yii::$app->request->get('countryId');
  600. if (!$countryId) {
  601. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  602. }
  603. // 生成随机码 , 初始化redis
  604. $userName = Info::generateWebName($countryId);
  605. //所有报单套餐
  606. $allDecPackage = DeclarationPackage::getAllData();
  607. $decLevels = Cache::getDecLevelConfig();
  608. foreach ($allDecPackage as $k=>$v){
  609. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  610. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  611. }
  612. //所有自选商品
  613. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  614. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  615. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  616. $query_condition = " AND (1<>1";
  617. if(!$isDecReg || ($isDecReg && $isDec==1)){
  618. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  619. }
  620. if($isStudio==1){
  621. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  622. }
  623. $query_condition .= ") AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=:COUNTRY_ID";
  624. // 只查询普通商品
  625. $allGoods = ShopGoods::find()
  626. ->alias('S')
  627. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  628. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  629. ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  630. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $countryId])
  631. ->orderBy('SORT ASC')
  632. ->asArray()
  633. ->all();
  634. // 银行开户行
  635. $allOpenBank = OpenBank::find()
  636. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  637. ->orderBy('BANK_NAME ASC')
  638. ->asArray()
  639. ->all();
  640. if (!$userName) {
  641. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  642. }
  643. //随机码保存在redis中方便进行比对
  644. $redis->setex('key_'.$userName , 3600 , $userName);
  645. // 报单中心会员的本地汇率
  646. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  647. $decCountry = Countries::getById($decCountryId);
  648. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  649. // 新会员的本地汇率
  650. $country = Countries::getById($countryId);
  651. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  652. // 新会员币种
  653. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  654. // 会员账户
  655. $userBalance = [
  656. 'cash' => 0,
  657. 'localCash' => 0,
  658. 'coin' => '',
  659. ];
  660. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  661. if ($userCash) {
  662. $userBalance['cash'] = $userCash['CASH'];
  663. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  664. $userBalance['coin'] = $currency['CODE'] ?? '';
  665. }
  666. // 行政区划
  667. $region = Region::getByCountryId($countryId);
  668. // 支付方式
  669. $payList = ShopGoods::payTypes();
  670. unset($payList['prp']);
  671. // 售卖方式
  672. $sellType = ShopGoods::getCategoryType();
  673. unset($sellType[0]['sell_type'][1]);
  674. return static::notice([
  675. 'allDecPackage' => $allDecPackage,
  676. 'allGoods' => $allGoods,
  677. 'allOpenBank' => $allOpenBank,
  678. 'userName' => $userName,
  679. 'payList' => $payList,
  680. 'sellType' => $sellType,
  681. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  682. 'userBalance' => $userBalance,
  683. 'isDec' => $isDec,
  684. 'decUserCurrencyRate' => $decUserCurrencyRate,
  685. 'userCurrencyRate' => $currencyRate,
  686. 'region' => $region,
  687. 'decLevel' => DeclarationLevel::getData(),
  688. ]);
  689. }
  690. /**
  691. * 报单级别套餐
  692. */
  693. public function actionDecPackage() {
  694. $decLv = \Yii::$app->request->get('id');
  695. //所有报单级别套餐
  696. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  697. return static::notice(['allDecPackage' => $allDecPackage]);
  698. }
  699. /*
  700. * 从会员名和左右,获取底部安置人
  701. *
  702. */
  703. public function actionGetAutoPlace() {
  704. $userName = \Yii::$app->request->get('userName');
  705. $side = \Yii::$app->request->get('side');
  706. $userId = Info::getUserIdByUserName($userName);
  707. $bottomPlace = UserNetwork::getBottomPlace($userId,'', $side);
  708. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  709. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  710. return static::notice($bottomUser);
  711. }
  712. /**
  713. * 会员信息查询
  714. * @return mixed
  715. * @throws \yii\web\HttpException
  716. */
  717. public function actionFullInfo()
  718. {
  719. $userName = \Yii::$app->request->get('userName');
  720. $userId = Info::getUserIdByUserName($userName);
  721. $userInfo['REAL_NAME'] = '';
  722. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  723. $loginUserInfo = User::getEnCodeInfo(\Yii::$app->user->id);
  724. if ($user['COUNTRY_ID'] !== $loginUserInfo['COUNTRY_ID']) {
  725. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  726. }
  727. if($user){
  728. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  729. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  730. $isLocation = [1 => 'Left-Null', 2 => 'Right-Null'];
  731. if($allChildUser) {
  732. foreach ($allChildUser as $child) {
  733. if ($child['RELATIVE_LOCATION']<'3'){
  734. // $isLocation[$child['RELATIVE_LOCATION']].= 'Full';
  735. $isLocation[$child['RELATIVE_LOCATION']] = str_replace('Null', 'Full', $isLocation[$child['RELATIVE_LOCATION']]);
  736. }
  737. }
  738. }
  739. $userInfo['countryId'] = $user['COUNTRY_ID'];
  740. $userInfo['userId'] = $userId;
  741. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  742. return static::notice($userInfo);
  743. }else{
  744. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  745. }
  746. }
  747. public function actionInspectNetwork()
  748. {
  749. // 推荐人信息
  750. $recommenderName= \Yii::$app->request->get('recommenderName');
  751. $userId = Info::getUserIdByUserName($recommenderName);
  752. $recommender = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  753. if (!$recommender) {
  754. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  755. }
  756. // 实际推荐人信息
  757. $recommenderActualName= \Yii::$app->request->get('recommenderActualName');
  758. $actualId = Info::getUserIdByUserName($recommenderActualName);
  759. $recommenderActual = User::findOneAsArray('ID=:ID', [':ID' => $actualId]);
  760. if (!$recommenderActual) {
  761. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  762. }
  763. // 实际推荐人是否是推荐人本人
  764. if ($actualId == $userId) {
  765. return static::notice([
  766. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  767. 'userId' => $recommenderActual['ID'],
  768. ]);
  769. }
  770. // 实际推荐人必须是推荐人的推荐网上级
  771. $sqlUp =<<<SQL
  772. WITH recursive t_rec AS
  773. (
  774. SELECT
  775. m.USER_ID,
  776. U.USER_NAME,
  777. m.PARENT_UID,
  778. U2.USER_NAME AS PARENT_NAME,
  779. 1 AS node_level
  780. FROM
  781. AR_USER_RELATION_NEW m
  782. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  783. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  784. WHERE
  785. U.USER_NAME = :USER_NAME
  786. UNION ALL
  787. SELECT
  788. t1.USER_ID,
  789. U.USER_NAME,
  790. t1.PARENT_UID,
  791. U2.USER_NAME AS PARENT_NAME,
  792. t2.node_level + 1 -- 结点层级
  793. FROM
  794. AR_USER_RELATION_NEW t1
  795. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  796. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  797. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  798. )
  799. SELECT
  800. *
  801. FROM
  802. t_rec
  803. SQL;
  804. // 查询推荐人的所有上级
  805. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  806. ->bindValue(':USER_NAME' , $recommenderName)
  807. ->queryAll();
  808. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  809. unset($relationNodeUp[$recommenderName]);
  810. if (in_array($recommenderActualName, $relationNodeUp)) {
  811. return static::notice([
  812. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  813. 'userId' => $recommenderActual['ID'],
  814. ]);
  815. }
  816. return static::notice(Yii::t('ctx', 'fillSponsorUpline'), 400);
  817. }
  818. /**
  819. * 复消会员信息查询
  820. * @return mixed
  821. * @throws \yii\web\HttpException
  822. */
  823. public function actionUserBaseInfo()
  824. {
  825. $userName = \Yii::$app->request->get('userName');
  826. $userId = Info::getUserIdByUserName($userName);
  827. if($userId){
  828. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  829. if($allAddress) {
  830. foreach ($allAddress as $key => $row) {
  831. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  832. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  833. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  834. }
  835. }
  836. $userInfo = Info::baseInfoWithNet($userId);
  837. // $decLevelConfig = Cache::getDecLevelConfig();
  838. // $empLevelConfig = Cache::getEmpLevelConfig();
  839. $arr = [
  840. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  841. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  842. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  843. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  844. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  845. 'allAddress'=>$allAddress
  846. ];
  847. return static::notice($arr);
  848. }else{
  849. return static::notice(Yii::t('app', 'repeatSalesMemberNoDoesNotExist'), 400);
  850. }
  851. }
  852. /**
  853. * 会员资料
  854. * @return mixed
  855. * @throws \yii\web\HttpException
  856. */
  857. public function actionBaInfo()
  858. {
  859. $data['userInfo'] = BaUser::getEnCodeInfo(\Yii::$app->user->id);
  860. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  861. // 推荐人
  862. $baUserInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id]);
  863. $sponsor = User::findOneAsArray('ID=:USER_ID', [':USER_ID' => $baUserInfo['REC_UID']]);
  864. $data['userInfo']['SponsorCode'] = $sponsor['USER_NAME'];
  865. $data['userInfo']['SponsorName'] = $sponsor['REAL_NAME'];
  866. return static::notice($data);
  867. }
  868. /**
  869. * 编辑会员资料
  870. * @return mixed
  871. * @throws \yii\web\HttpException
  872. */
  873. public function actionBaEdit()
  874. {
  875. if(\Yii::$app->request->isPost)
  876. {
  877. $form = new BaUserForm();
  878. $post = \Yii::$app->request->post();
  879. $form->scenario = 'modifyProfile';
  880. if ($form->load($post, '') && $result = $form->modifyProfile()){
  881. return static::notice(Yii::t('app', 'personalDataModifiedSuccessfully'), 400);
  882. } else {
  883. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  884. }
  885. }
  886. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  887. }
  888. /**
  889. * 修改登录密码
  890. */
  891. public function actionBaPassword(){
  892. if(\Yii::$app->request->isPost) {
  893. $form = new BaUserForm();
  894. $form->scenario = 'modifyPassword';
  895. $post = \Yii::$app->request->post();
  896. if($form->load($post, '') && $result = $form->modifyPassword()){
  897. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  898. } else {
  899. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  900. }
  901. }
  902. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  903. }
  904. /**
  905. * 修改支付密码
  906. */
  907. public function actionBaPayPassword(){
  908. if(\Yii::$app->request->isPost){
  909. $form = new BaUserForm();
  910. $form->scenario = 'modifyPasswordPay';
  911. $post = \Yii::$app->request->post();
  912. $form->userId = \Yii::$app->user->id;
  913. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  914. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  915. } else {
  916. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  917. }
  918. }
  919. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  920. }
  921. /**
  922. * BA报单管理
  923. */
  924. public function actionBaDec() {
  925. // 生成随机码 , 初始化redis
  926. $userName = Info::generateWebUserName('NG',9);
  927. $redis = \Yii::$app->redis;
  928. $post = \Yii::$app->request->post();
  929. if (\Yii::$app->request->isPost) {
  930. // 根据支付方式区分逻辑
  931. $payMethod = \Yii::$app->request->post('payType', '');
  932. if ($payMethod === 'pay_stack') {
  933. $formModel = new BaApproachDeclarationLoopForm();
  934. } else {
  935. unset($post['payType']);
  936. $formModel = new BaDeclarationLoopForm();
  937. }
  938. $formModel->scenario = 'userDec';
  939. $post['province'] = $post['province'] ? :1;
  940. $post['city'] = $post['city'] ? :1;
  941. $post['county'] = $post['county'] ? :1;
  942. // $post['conUserName'] = trim($post['conUserName']);
  943. $post['recUserName'] = trim($post['recUserName']);
  944. $post['cityName'] = trim($post['cityName']);
  945. $post['lgaName'] = trim($post['lgaName']);
  946. // 针对于会员编号的判断
  947. $insertUserName = strtoupper($post['insertUserName']);
  948. $getRedisUserName = $redis->get('key_' . $insertUserName);
  949. if (!$getRedisUserName){
  950. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  951. }
  952. if ($insertUserName != $getRedisUserName){
  953. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  954. }
  955. $post['insertUserName'] = $insertUserName;
  956. $post['type'] = BaDeclarationForm::TYPE_ZC;
  957. $allData['data'][] = $post;
  958. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  959. return static::notice($result); // 报单成功
  960. } else {
  961. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  962. }
  963. }
  964. // 只查询普通商品
  965. $allGoods = ShopGoods::find()->where("ID='375895243322691584'")->orderBy('SORT ASC')->asArray()->all();
  966. if (!$userName) {
  967. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  968. }
  969. //随机码保存在redis中方便进行比对
  970. $redis->setex('key_'.$userName , 3600 , $userName);
  971. // 会员账户
  972. $userBalance = [
  973. 'cash' => 0,
  974. // 'tourism_points' => 0,
  975. // 'garage_points' => 0,
  976. // 'villa_points' => 0,
  977. ];
  978. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  979. if ($userCash) {
  980. $userBalance['cash'] = $userCash['CASH'];
  981. }
  982. return static::notice([
  983. 'allGoods' => $allGoods,
  984. 'userName' => $userName,
  985. 'payList' => ShopGoods::payTypes(),
  986. 'sellType' => ShopGoods::getCategoryType(),
  987. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  988. 'userBalance' => $userBalance,
  989. ]);
  990. }
  991. /**
  992. * BA会员信息
  993. * @return mixed
  994. * @throws \yii\web\HttpException
  995. */
  996. public function actionBaUserInfo()
  997. {
  998. $userName = \Yii::$app->request->get('userName');
  999. $userId = Info::getBaUserIdByUserName($userName);
  1000. $userInfo['REAL_NAME'] = '';
  1001. $user = BaUser::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  1002. $uInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'REC_UID');
  1003. if($user){
  1004. $rec_user = UserInfo::findOneAsArray('USER_ID=:USER_ID',[':USER_ID' => $uInfo['REC_UID']], 'USER_ID, USER_NAME');
  1005. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  1006. $userInfo['REC_USER_ID'] = $rec_user['USER_ID'];
  1007. $userInfo['REC_USER_NAME'] = $rec_user['USER_NAME'];
  1008. return static::notice($userInfo);
  1009. }else{
  1010. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  1011. }
  1012. }
  1013. }