UserController.php 48 KB

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