UserController.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  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. $post['type'] = DeclarationForm::TYPE_ZC;
  353. if ($formModel->load($post, '') && $result = $formModel->add($post)) {
  354. return static::notice($result);// Upgrade declaration succeeded升级报单成功
  355. } else {
  356. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  357. }
  358. }
  359. // 升级的会员
  360. $userName = \Yii::$app->request->get('userName');
  361. // 会员信息
  362. $user = User::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => trim($userName)]);
  363. if (!$user) {
  364. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  365. }
  366. //所有报单套餐
  367. $allDecPackage = DeclarationPackage::getAllData();
  368. $decLevels = Cache::getDecLevelConfig();
  369. foreach ($allDecPackage as $k=>$v){
  370. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  371. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  372. }
  373. $baseInfo = Info::baseInfoZhByUserName($userNumber);
  374. // 分期的总期数
  375. $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
  376. // 查询是否有FX的分期订单
  377. $stageFX = Instalment::getOneStage($baseInfo['ID'], 'FX');
  378. if ($stageFX && $stageFX < $instalmentConfig) {
  379. if ($isMax === "true") {
  380. $condition = ") AND S.INSTALMENT = 1000";
  381. } else {
  382. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = 1000)";
  383. }
  384. } else {
  385. // 是否有未完成的BD类型的分期订单
  386. $stageBD = Instalment::getOneStage($baseInfo['ID'], 'BD');
  387. if ($isMax === "true") {
  388. if ($stageBD > 0 && $stageBD < $instalmentConfig) {
  389. $condition = ") AND (S.INSTALMENT = " . ($stageBD + 1) . ")";
  390. } else {
  391. $condition = ") AND S.INSTALMENT = 0";
  392. }
  393. } else {
  394. if ($stageBD > 0 && $stageBD < $instalmentConfig) {
  395. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = " . ($stageBD + 1) . ")";
  396. } else {
  397. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = 1)";
  398. }
  399. }
  400. }
  401. //所有自选商品
  402. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  403. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  404. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  405. $decUserName = User::getEnCodeInfo(\Yii::$app->user->id)['USER_NAME'];
  406. $query_condition= " AND (1<>1";
  407. if(!$isDecReg || ($isDecReg && $isDec==1)){
  408. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  409. }
  410. if($isStudio==1){
  411. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  412. }
  413. $query_condition .= $condition . ' AND N.COUNTRY_ID=:COUNTRY_ID ';
  414. $allGoods = ShopGoods::find()
  415. ->alias('S')
  416. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  417. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  418. ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  419. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $user['COUNTRY_ID']])
  420. ->orderBy('SORT ASC')
  421. ->asArray()
  422. ->all();
  423. foreach ($allGoods as &$goods) {
  424. $goods['TAX'] = Tool::calculateTax($goods['SELL_PRICE'], $goods['TAX_RATE']);
  425. }
  426. // 报单中心汇率
  427. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  428. $decCountry = Countries::getById($decCountryId);
  429. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  430. // 升级会员汇率
  431. $country = Countries::getById($user['COUNTRY_ID']);
  432. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  433. // 升级会员币种
  434. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  435. $userBalance = [
  436. 'cash' => 0,
  437. 'localCash' => 0,
  438. 'coin' => '',
  439. ];
  440. // 会员余额
  441. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  442. if ($userCash) {
  443. $userBalance['cash'] = $userCash['CASH'];
  444. $userBalance['coin'] = $currency['CODE'] ?? '';
  445. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  446. }
  447. // 会员绩效奖金
  448. $userPerformanceAmount = UserPerformance::getAmounts(\Yii::$app->user->id);
  449. $userBalance['prp'] = $userPerformanceAmount ?? 0;
  450. $userBalance['localPrp'] = Tool::convertAmount($userPerformanceAmount, $decUserCurrencyRate, $currencyRate);
  451. // 行政区划
  452. $region = Region::getByCountryId($user['COUNTRY_ID']);
  453. // 支付方式
  454. $payList = ShopGoods::payTypes();
  455. unset($payList['prp']);
  456. // 售卖方式
  457. $sellType = ShopGoods::getCategoryType();
  458. unset($sellType[0]['sell_type'][1]);
  459. return static::notice([
  460. 'allDecPackage' => $allDecPackage,
  461. 'allGoods' => $allGoods,
  462. 'decUserName'=>$decUserName,
  463. 'payList' => $payList,
  464. 'sellType' => $sellType,
  465. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  466. 'userBalance' => $userBalance,
  467. 'decUserCurrencyRate' => $decUserCurrencyRate,
  468. 'userCurrencyRate' => $currencyRate,
  469. 'region' => $region,
  470. ]);
  471. }
  472. /**
  473. * 报单管理
  474. */
  475. public function actionDec() {
  476. $redis = \Yii::$app->redis;
  477. $post = \Yii::$app->request->post();
  478. if (\Yii::$app->request->isPost) {
  479. $userInfo = User::getEnCodeInfo(\Yii::$app->user->id);
  480. if($userInfo['IS_DEC'] == 1 && !empty($post['decUserName']) && $post['decUserName'] != $userInfo['USER_NAME']){
  481. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  482. }
  483. if($userInfo['IS_DEC'] == 0 && $post['decUserName']){
  484. //查询报单编号是否存在
  485. $userId = Info::getUserIdByUserName($post['decUserName']);
  486. if(!$userId){
  487. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  488. }
  489. $isDec = User::getEnCodeInfo($userId)['IS_DEC'];
  490. if(!$isDec){
  491. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  492. }
  493. }
  494. $conUserName = trim($post['conUserName']); // 实际推荐人
  495. $recUserName = trim($post['recUserName']);
  496. // 如果推荐人和实际推荐人是同一人,则跳过检查
  497. if ($recUserName != $conUserName) {
  498. // 实际推荐人必须是推荐人的推荐网上级
  499. $sqlUp = <<<SQL
  500. WITH recursive t_rec AS
  501. (
  502. SELECT
  503. m.USER_ID,
  504. U.USER_NAME,
  505. m.PARENT_UID,
  506. U2.USER_NAME AS PARENT_NAME,
  507. 1 AS node_level
  508. FROM
  509. AR_USER_RELATION_NEW m
  510. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  511. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  512. WHERE
  513. U.USER_NAME = :USER_NAME
  514. UNION ALL
  515. SELECT
  516. t1.USER_ID,
  517. U.USER_NAME,
  518. t1.PARENT_UID,
  519. U2.USER_NAME AS PARENT_NAME,
  520. t2.node_level + 1 -- 结点层级
  521. FROM
  522. AR_USER_RELATION_NEW t1
  523. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  524. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  525. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  526. )
  527. SELECT
  528. *
  529. FROM
  530. t_rec
  531. SQL;
  532. // 查询推荐人的所有上级
  533. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  534. ->bindValue(':USER_NAME', $post['recUserName'])
  535. ->queryAll();
  536. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  537. unset($relationNodeUp[$post['recUserName']]);
  538. if (!in_array($post['conUserName'], $relationNodeUp)) {
  539. return static::notice(Yii::t('app', 'fillSponsorUpline'), 400);
  540. }
  541. }
  542. // 根据支付方式区分逻辑
  543. $payMethod = \Yii::$app->request->post('payType', '');
  544. if ($payMethod === 'pay_stack') {
  545. $formModel = new ApproachDeclarationLoopForm();
  546. } else {
  547. unset($post['payType']);
  548. $formModel = new DeclarationLoopForm();
  549. }
  550. $formModel->scenario = 'userDec';
  551. $post['province'] = $post['province'] ? :1;
  552. $post['city'] = $post['city'] ? :1;
  553. $post['county'] = $post['county'] ? :1;
  554. $post['cityName'] = trim($post['cityName']);
  555. $post['lgaName'] = trim($post['lgaName']);
  556. // 针对那群沙雕移除安置网络的行为,强制增加自动安置左侧
  557. $recUserId = Info::getUserIdByUserName($conUserName);
  558. $bottomPlace = UserNetwork::getBottomPlace($recUserId,'', 'left');
  559. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  560. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  561. $bottomUser = $bottomUser['USER_NAME']; // 推算出的安置人
  562. $post['conUserName'] = $bottomUser; // 安置人
  563. $post['recUserName'] = $conUserName; // 实际推荐人
  564. $post['bottomUserName'] = $recUserName; // 推荐人
  565. $post['location'] = 1;
  566. // 针对于会员编号的判断
  567. $insertUserName = strtoupper($post['insertUserName']);
  568. $getRedisUserName = $redis->get('key_' . $insertUserName);
  569. if (!$getRedisUserName){
  570. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  571. }
  572. if ($insertUserName != $getRedisUserName){
  573. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  574. }
  575. $post['insertUserName'] = $insertUserName;
  576. $post['type'] = DeclarationForm::TYPE_ZC;
  577. $allData['data'][] = $post;
  578. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  579. //发送邮件
  580. Email::sendRegistrationEmail($post['email'], $post['insertUserName'], $post['password']);
  581. return static::notice($result);//报单成功
  582. } else {
  583. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  584. }
  585. }
  586. // 默认国家
  587. $countryId = \Yii::$app->request->get('countryId');
  588. if (!$countryId) {
  589. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  590. }
  591. // 生成随机码 , 初始化redis
  592. $userName = Info::generateWebName($countryId);
  593. //所有报单套餐
  594. $allDecPackage = DeclarationPackage::getAllData();
  595. $decLevels = Cache::getDecLevelConfig();
  596. foreach ($allDecPackage as $k=>$v){
  597. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  598. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  599. }
  600. //所有自选商品
  601. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  602. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  603. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  604. $query_condition = " AND (1<>1";
  605. if(!$isDecReg || ($isDecReg && $isDec==1)){
  606. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  607. }
  608. if($isStudio==1){
  609. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  610. }
  611. $query_condition .= ") AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=:COUNTRY_ID";
  612. // 只查询普通商品
  613. $allGoods = ShopGoods::find()
  614. ->alias('S')
  615. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  616. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  617. ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  618. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $countryId])
  619. ->orderBy('SORT ASC')
  620. ->asArray()
  621. ->all();
  622. // 银行开户行
  623. $allOpenBank = OpenBank::find()
  624. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  625. ->orderBy('BANK_NAME ASC')
  626. ->asArray()
  627. ->all();
  628. if (!$userName) {
  629. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  630. }
  631. //随机码保存在redis中方便进行比对
  632. $redis->setex('key_'.$userName , 3600 , $userName);
  633. // 报单中心会员的本地汇率
  634. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  635. $decCountry = Countries::getById($decCountryId);
  636. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  637. // 新会员的本地汇率
  638. $country = Countries::getById($countryId);
  639. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  640. // 新会员币种
  641. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  642. // 会员账户
  643. $userBalance = [
  644. 'cash' => 0,
  645. 'localCash' => 0,
  646. 'coin' => '',
  647. ];
  648. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  649. if ($userCash) {
  650. $userBalance['cash'] = $userCash['CASH'];
  651. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  652. $userBalance['coin'] = $currency['CODE'] ?? '';
  653. }
  654. // 行政区划
  655. $region = Region::getByCountryId($countryId);
  656. // 支付方式
  657. $payList = ShopGoods::payTypes();
  658. unset($payList['prp']);
  659. // 售卖方式
  660. $sellType = ShopGoods::getCategoryType();
  661. unset($sellType[0]['sell_type'][1]);
  662. return static::notice([
  663. 'allDecPackage' => $allDecPackage,
  664. 'allGoods' => $allGoods,
  665. 'allOpenBank' => $allOpenBank,
  666. 'userName' => $userName,
  667. 'payList' => $payList,
  668. 'sellType' => $sellType,
  669. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  670. 'userBalance' => $userBalance,
  671. 'isDec' => $isDec,
  672. 'decUserCurrencyRate' => $decUserCurrencyRate,
  673. 'userCurrencyRate' => $currencyRate,
  674. 'region' => $region,
  675. 'decLevel' => DeclarationLevel::getData(),
  676. ]);
  677. }
  678. /**
  679. * 报单级别套餐
  680. */
  681. public function actionDecPackage() {
  682. $decLv = \Yii::$app->request->get('id');
  683. //所有报单级别套餐
  684. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  685. return static::notice(['allDecPackage' => $allDecPackage]);
  686. }
  687. /*
  688. * 从会员名和左右,获取底部安置人
  689. *
  690. */
  691. public function actionGetAutoPlace() {
  692. $userName = \Yii::$app->request->get('userName');
  693. $side = \Yii::$app->request->get('side');
  694. $userId = Info::getUserIdByUserName($userName);
  695. $bottomPlace = UserNetwork::getBottomPlace($userId,'', $side);
  696. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  697. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  698. return static::notice($bottomUser);
  699. }
  700. /**
  701. * 会员信息查询
  702. * @return mixed
  703. * @throws \yii\web\HttpException
  704. */
  705. public function actionFullInfo()
  706. {
  707. $userName = \Yii::$app->request->get('userName');
  708. $userId = Info::getUserIdByUserName($userName);
  709. $userInfo['REAL_NAME'] = '';
  710. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  711. $loginUserInfo = User::getEnCodeInfo(\Yii::$app->user->id);
  712. if ($user['COUNTRY_ID'] !== $loginUserInfo['COUNTRY_ID']) {
  713. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  714. }
  715. if($user){
  716. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  717. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  718. $isLocation = [1 => 'Left-Null', 2 => 'Right-Null'];
  719. if($allChildUser) {
  720. foreach ($allChildUser as $child) {
  721. if ($child['RELATIVE_LOCATION']<'3'){
  722. // $isLocation[$child['RELATIVE_LOCATION']].= 'Full';
  723. $isLocation[$child['RELATIVE_LOCATION']] = str_replace('Null', 'Full', $isLocation[$child['RELATIVE_LOCATION']]);
  724. }
  725. }
  726. }
  727. $userInfo['countryId'] = $user['COUNTRY_ID'];
  728. $userInfo['userId'] = $userId;
  729. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  730. return static::notice($userInfo);
  731. }else{
  732. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  733. }
  734. }
  735. public function actionInspectNetwork()
  736. {
  737. // 推荐人信息
  738. $recommenderName= \Yii::$app->request->get('recommenderName');
  739. $userId = Info::getUserIdByUserName($recommenderName);
  740. $recommender = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  741. if (!$recommender) {
  742. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  743. }
  744. // 实际推荐人信息
  745. $recommenderActualName= \Yii::$app->request->get('recommenderActualName');
  746. $actualId = Info::getUserIdByUserName($recommenderActualName);
  747. $recommenderActual = User::findOneAsArray('ID=:ID', [':ID' => $actualId]);
  748. if (!$recommenderActual) {
  749. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  750. }
  751. // 实际推荐人是否是推荐人本人
  752. if ($actualId == $userId) {
  753. return static::notice([
  754. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  755. 'userId' => $recommenderActual['ID'],
  756. ]);
  757. }
  758. // 实际推荐人必须是推荐人的推荐网上级
  759. $sqlUp =<<<SQL
  760. WITH recursive t_rec AS
  761. (
  762. SELECT
  763. m.USER_ID,
  764. U.USER_NAME,
  765. m.PARENT_UID,
  766. U2.USER_NAME AS PARENT_NAME,
  767. 1 AS node_level
  768. FROM
  769. AR_USER_RELATION_NEW m
  770. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  771. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  772. WHERE
  773. U.USER_NAME = :USER_NAME
  774. UNION ALL
  775. SELECT
  776. t1.USER_ID,
  777. U.USER_NAME,
  778. t1.PARENT_UID,
  779. U2.USER_NAME AS PARENT_NAME,
  780. t2.node_level + 1 -- 结点层级
  781. FROM
  782. AR_USER_RELATION_NEW t1
  783. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  784. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  785. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  786. )
  787. SELECT
  788. *
  789. FROM
  790. t_rec
  791. SQL;
  792. // 查询推荐人的所有上级
  793. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  794. ->bindValue(':USER_NAME' , $recommenderName)
  795. ->queryAll();
  796. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  797. unset($relationNodeUp[$recommenderName]);
  798. if (in_array($recommenderActualName, $relationNodeUp)) {
  799. return static::notice([
  800. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  801. 'userId' => $recommenderActual['ID'],
  802. ]);
  803. }
  804. return static::notice(Yii::t('ctx', 'fillSponsorUpline'), 400);
  805. }
  806. /**
  807. * 复消会员信息查询
  808. * @return mixed
  809. * @throws \yii\web\HttpException
  810. */
  811. public function actionUserBaseInfo()
  812. {
  813. $userName = \Yii::$app->request->get('userName');
  814. $userId = Info::getUserIdByUserName($userName);
  815. if($userId){
  816. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  817. if($allAddress) {
  818. foreach ($allAddress as $key => $row) {
  819. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  820. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  821. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  822. }
  823. }
  824. $userInfo = Info::baseInfoWithNet($userId);
  825. // $decLevelConfig = Cache::getDecLevelConfig();
  826. // $empLevelConfig = Cache::getEmpLevelConfig();
  827. $arr = [
  828. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  829. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  830. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  831. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  832. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  833. 'allAddress'=>$allAddress
  834. ];
  835. return static::notice($arr);
  836. }else{
  837. return static::notice(Yii::t('app', 'repeatSalesMemberNoDoesNotExist'), 400);
  838. }
  839. }
  840. /**
  841. * 会员资料
  842. * @return mixed
  843. * @throws \yii\web\HttpException
  844. */
  845. public function actionBaInfo()
  846. {
  847. $data['userInfo'] = BaUser::getEnCodeInfo(\Yii::$app->user->id);
  848. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  849. // 推荐人
  850. $baUserInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id]);
  851. $sponsor = User::findOneAsArray('ID=:USER_ID', [':USER_ID' => $baUserInfo['REC_UID']]);
  852. $data['userInfo']['SponsorCode'] = $sponsor['USER_NAME'];
  853. $data['userInfo']['SponsorName'] = $sponsor['REAL_NAME'];
  854. return static::notice($data);
  855. }
  856. /**
  857. * 编辑会员资料
  858. * @return mixed
  859. * @throws \yii\web\HttpException
  860. */
  861. public function actionBaEdit()
  862. {
  863. if(\Yii::$app->request->isPost)
  864. {
  865. $form = new BaUserForm();
  866. $post = \Yii::$app->request->post();
  867. $form->scenario = 'modifyProfile';
  868. if ($form->load($post, '') && $result = $form->modifyProfile()){
  869. return static::notice(Yii::t('app', 'personalDataModifiedSuccessfully'), 400);
  870. } else {
  871. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  872. }
  873. }
  874. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  875. }
  876. /**
  877. * 修改登录密码
  878. */
  879. public function actionBaPassword(){
  880. if(\Yii::$app->request->isPost) {
  881. $form = new BaUserForm();
  882. $form->scenario = 'modifyPassword';
  883. $post = \Yii::$app->request->post();
  884. if($form->load($post, '') && $result = $form->modifyPassword()){
  885. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  886. } else {
  887. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  888. }
  889. }
  890. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  891. }
  892. /**
  893. * 修改支付密码
  894. */
  895. public function actionBaPayPassword(){
  896. if(\Yii::$app->request->isPost){
  897. $form = new BaUserForm();
  898. $form->scenario = 'modifyPasswordPay';
  899. $post = \Yii::$app->request->post();
  900. $form->userId = \Yii::$app->user->id;
  901. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  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. * BA报单管理
  911. */
  912. public function actionBaDec() {
  913. // 生成随机码 , 初始化redis
  914. $userName = Info::generateWebUserName('NG',9);
  915. $redis = \Yii::$app->redis;
  916. $post = \Yii::$app->request->post();
  917. if (\Yii::$app->request->isPost) {
  918. // 根据支付方式区分逻辑
  919. $payMethod = \Yii::$app->request->post('payType', '');
  920. if ($payMethod === 'pay_stack') {
  921. $formModel = new BaApproachDeclarationLoopForm();
  922. } else {
  923. unset($post['payType']);
  924. $formModel = new BaDeclarationLoopForm();
  925. }
  926. $formModel->scenario = 'userDec';
  927. $post['province'] = $post['province'] ? :1;
  928. $post['city'] = $post['city'] ? :1;
  929. $post['county'] = $post['county'] ? :1;
  930. // $post['conUserName'] = trim($post['conUserName']);
  931. $post['recUserName'] = trim($post['recUserName']);
  932. $post['cityName'] = trim($post['cityName']);
  933. $post['lgaName'] = trim($post['lgaName']);
  934. // 针对于会员编号的判断
  935. $insertUserName = strtoupper($post['insertUserName']);
  936. $getRedisUserName = $redis->get('key_' . $insertUserName);
  937. if (!$getRedisUserName){
  938. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  939. }
  940. if ($insertUserName != $getRedisUserName){
  941. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  942. }
  943. $post['insertUserName'] = $insertUserName;
  944. $post['type'] = BaDeclarationForm::TYPE_ZC;
  945. $allData['data'][] = $post;
  946. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  947. return static::notice($result); // 报单成功
  948. } else {
  949. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  950. }
  951. }
  952. // 只查询普通商品
  953. $allGoods = ShopGoods::find()->where("ID='375895243322691584'")->orderBy('SORT ASC')->asArray()->all();
  954. if (!$userName) {
  955. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  956. }
  957. //随机码保存在redis中方便进行比对
  958. $redis->setex('key_'.$userName , 3600 , $userName);
  959. // 会员账户
  960. $userBalance = [
  961. 'cash' => 0,
  962. // 'tourism_points' => 0,
  963. // 'garage_points' => 0,
  964. // 'villa_points' => 0,
  965. ];
  966. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  967. if ($userCash) {
  968. $userBalance['cash'] = $userCash['CASH'];
  969. }
  970. return static::notice([
  971. 'allGoods' => $allGoods,
  972. 'userName' => $userName,
  973. 'payList' => ShopGoods::payTypes(),
  974. 'sellType' => ShopGoods::getCategoryType(),
  975. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  976. 'userBalance' => $userBalance,
  977. ]);
  978. }
  979. /**
  980. * BA会员信息
  981. * @return mixed
  982. * @throws \yii\web\HttpException
  983. */
  984. public function actionBaUserInfo()
  985. {
  986. $userName = \Yii::$app->request->get('userName');
  987. $userId = Info::getBaUserIdByUserName($userName);
  988. $userInfo['REAL_NAME'] = '';
  989. $user = BaUser::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  990. $uInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'REC_UID');
  991. if($user){
  992. $rec_user = UserInfo::findOneAsArray('USER_ID=:USER_ID',[':USER_ID' => $uInfo['REC_UID']], 'USER_ID, USER_NAME');
  993. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  994. $userInfo['REC_USER_ID'] = $rec_user['USER_ID'];
  995. $userInfo['REC_USER_NAME'] = $rec_user['USER_NAME'];
  996. return static::notice($userInfo);
  997. }else{
  998. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  999. }
  1000. }
  1001. }