UserController.php 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  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. // $query_condition = " AND (1<>1";
  504. // if(!$isDecReg || ($isDecReg && $isDec==1)){
  505. // $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  506. // }
  507. // if($isStudio==1){
  508. // $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  509. // }
  510. // $query_condition .= ") AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=:COUNTRY_ID";
  511. // 只查询普通商品
  512. // $allGoods = ShopGoods::find()
  513. // ->alias('S')
  514. // ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  515. // ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  516. // ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  517. // ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $countryId])
  518. // ->orderBy('SORT ASC')
  519. // ->asArray()
  520. // ->all();
  521. $goods = ShopGoods::find()
  522. ->alias('S')
  523. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  524. ->innerJoin(ShopGoodsNature::tableName() . ' N', 'N.GOODS_ID=S.ID')
  525. ->innerJoin(Currency::tableName() . ' C', 'C.ID=N.LOCAL_CURRENCY_ID')
  526. ->where('S.STATUS=1 AND S.CATEGORY_TYPE=1 AND FIND_IN_SET(1,S.GIFT_TYPE)>0 AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=:COUNTRY_ID', [':COUNTRY_ID' => $countryId])
  527. ->orderBy('S.SORT ASC')
  528. ->asArray()->all();
  529. // 银行开户行
  530. $allOpenBank = OpenBank::find()
  531. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  532. ->orderBy('BANK_NAME ASC')
  533. ->asArray()
  534. ->all();
  535. // 售卖方式
  536. $sellType = ShopGoods::getCategoryType();
  537. unset($sellType[0]['sell_type'][1]);
  538. return static::notice([
  539. 'draft' => $draft,
  540. 'allDecPackage' => $packages,
  541. 'allGoods' => $goods,
  542. 'allOpenBank' => $allOpenBank,
  543. 'sellType' => $sellType,
  544. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  545. 'region' => Region::getByCountryId($countryId),
  546. 'payList' => ['pay_stack' => ['name' => 'PayStack']],
  547. 'decLevel' => DeclarationLevel::getData(),
  548. ]);
  549. } catch (\Throwable $e) {
  550. LoggerTool::error([
  551. 'event' => 'guestDec_failed',
  552. 'exception' => get_class($e),
  553. 'message' => $e->getMessage(),
  554. 'file' => basename($e->getFile()),
  555. 'line' => $e->getLine(),
  556. ]);
  557. if ($e instanceof \yii\web\HttpException) {
  558. return static::notice($e->getMessage(), $e->statusCode);
  559. }
  560. return static::notice('Unable to process guest order.', 500);
  561. }
  562. }
  563. public function actionGuestDecDebugPaid()
  564. {
  565. var_dump(1);die();
  566. try {
  567. $input = Yii::$app->request->post();
  568. $result = (new GuestDeclarationOrderService())->debugCompletePaidDraft(
  569. (string) ($input['draftId'] ?? ''),
  570. (string) ($input['accessToken'] ?? '')
  571. );
  572. return static::notice($result);
  573. } catch (\Throwable $e) {
  574. LoggerTool::error([
  575. 'event' => 'guestDec_debug_paid_failed',
  576. 'exception' => get_class($e),
  577. 'message' => $e->getMessage(),
  578. 'file' => basename($e->getFile()),
  579. 'line' => $e->getLine(),
  580. ]);
  581. if ($e instanceof \yii\web\HttpException) {
  582. return static::notice($e->getMessage(), $e->statusCode);
  583. }
  584. return static::notice('Unable to debug-complete guest order.', 500);
  585. }
  586. }
  587. public function actionGuestDecStatus()
  588. {
  589. try {
  590. $result = (new GuestDeclarationOrderService())->getDraftStatus(
  591. (string) Yii::$app->request->get('draftId', ''),
  592. (string) Yii::$app->request->get('accessToken', '')
  593. );
  594. return static::notice($result);
  595. } catch (\Throwable $e) {
  596. return static::notice('Guest order draft was not found.', 404);
  597. }
  598. }
  599. public function actionDec() {
  600. $redis = \Yii::$app->redis;
  601. $post = \Yii::$app->request->post();
  602. if (\Yii::$app->request->isPost) {
  603. $email = $post['email'] ?? '';
  604. if ($email && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
  605. return static::notice(Yii::t('app', 'invalidEmail'), 400);
  606. }
  607. $stockist = $post['decUserName'] ?? '';
  608. if (!$stockist) {
  609. return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
  610. }
  611. $loginUserInfo = User::getEnCodeInfo(\Yii::$app->user->id);
  612. if($loginUserInfo['IS_DEC'] == 1 && !empty($post['decUserName']) && $post['decUserName'] != $loginUserInfo['USER_NAME']){
  613. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  614. }
  615. if($loginUserInfo['IS_DEC'] == 0 && $post['decUserName']){
  616. //查询报单编号是否存在
  617. $userId = Info::getUserIdByUserName($post['decUserName']);
  618. if(!$userId){
  619. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  620. }
  621. $isDec = User::getEnCodeInfo($userId)['IS_DEC'];
  622. if(!$isDec){
  623. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  624. }
  625. }
  626. $conUserName = trim($post['conUserName']); // 实际推荐人
  627. $recUserName = trim($post['recUserName']);
  628. // 如果推荐人和实际推荐人是同一人,则跳过检查
  629. if ($recUserName != $conUserName) {
  630. // 实际推荐人必须是推荐人的推荐网上级
  631. $sqlUp = <<<SQL
  632. WITH recursive t_rec AS
  633. (
  634. SELECT
  635. m.USER_ID,
  636. U.USER_NAME,
  637. m.PARENT_UID,
  638. U2.USER_NAME AS PARENT_NAME,
  639. 1 AS node_level
  640. FROM
  641. AR_USER_RELATION_NEW m
  642. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  643. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  644. WHERE
  645. U.USER_NAME = :USER_NAME
  646. UNION ALL
  647. SELECT
  648. t1.USER_ID,
  649. U.USER_NAME,
  650. t1.PARENT_UID,
  651. U2.USER_NAME AS PARENT_NAME,
  652. t2.node_level + 1 -- 结点层级
  653. FROM
  654. AR_USER_RELATION_NEW t1
  655. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  656. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  657. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  658. )
  659. SELECT
  660. *
  661. FROM
  662. t_rec
  663. SQL;
  664. // 查询推荐人的所有上级
  665. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  666. ->bindValue(':USER_NAME', $post['recUserName'])
  667. ->queryAll();
  668. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  669. unset($relationNodeUp[$post['recUserName']]);
  670. if (!in_array($post['conUserName'], $relationNodeUp)) {
  671. return static::notice(Yii::t('app', 'fillSponsorUpline'), 400);
  672. }
  673. }
  674. // 根据支付方式区分逻辑
  675. $payMethod = \Yii::$app->request->post('payType', '');
  676. if ($payMethod === 'pay_stack') {
  677. $formModel = new ApproachDeclarationLoopForm();
  678. } else {
  679. unset($post['payType']);
  680. $formModel = new DeclarationLoopForm();
  681. }
  682. $formModel->scenario = 'userDec';
  683. $post['province'] = $post['province'] ? :1;
  684. $post['city'] = $post['city'] ? :1;
  685. $post['county'] = $post['county'] ? :1;
  686. $post['cityName'] = trim($post['cityName']);
  687. $post['lgaName'] = trim($post['lgaName']);
  688. // 针对那群沙雕移除安置网络的行为,强制增加自动安置左侧
  689. $recUserId = Info::getUserIdByUserName($conUserName);
  690. $bottomPlace = UserNetwork::getBottomPlace($recUserId,'', 'left');
  691. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  692. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  693. $bottomUser = $bottomUser['USER_NAME']; // 推算出的安置人
  694. $post['conUserName'] = $bottomUser; // 安置人
  695. $post['recUserName'] = $conUserName; // 实际推荐人
  696. $post['bottomUserName'] = $recUserName; // 推荐人
  697. $post['location'] = 1;
  698. // 针对于会员编号的判断
  699. $insertUserName = strtoupper($post['insertUserName']);
  700. $getRedisUserName = $redis->get('key_' . $insertUserName);
  701. if (!$getRedisUserName){
  702. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  703. }
  704. if ($insertUserName != $getRedisUserName){
  705. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  706. }
  707. $post['insertUserName'] = $insertUserName;
  708. $post['type'] = DeclarationForm::TYPE_ZC;
  709. $allData['data'][] = $post;
  710. try {
  711. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  712. //发送邮件
  713. // Email::sendRegistrationEmail($post['email'], $post['insertUserName'], $post['password']);
  714. return static::notice($result);//报单成功
  715. } else {
  716. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  717. }
  718. } catch (\Exception $e) {
  719. LoggerTool::error($e->getMessage() . '; ' . $e->getLine() . '; ' . $e->getFile());
  720. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  721. }
  722. }
  723. // 默认国家
  724. $countryId = \Yii::$app->request->get('countryId');
  725. if (!$countryId) {
  726. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  727. }
  728. // 生成随机码 , 初始化redis
  729. $userName = Info::generateWebName($countryId);
  730. //所有报单套餐
  731. $allDecPackage = DeclarationPackage::getAllData();
  732. $decLevels = Cache::getDecLevelConfig();
  733. foreach ($allDecPackage as $k=>$v){
  734. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  735. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  736. }
  737. //所有自选商品
  738. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  739. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  740. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  741. $query_condition = " AND (1<>1";
  742. if(!$isDecReg || ($isDecReg && $isDec==1)){
  743. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  744. }
  745. if($isStudio==1){
  746. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  747. }
  748. $query_condition .= ") AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=:COUNTRY_ID";
  749. // 只查询普通商品
  750. $allGoods = ShopGoods::find()
  751. ->alias('S')
  752. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  753. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  754. ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  755. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $countryId])
  756. ->orderBy('SORT ASC')
  757. ->asArray()
  758. ->all();
  759. // 银行开户行
  760. $allOpenBank = OpenBank::find()
  761. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  762. ->orderBy('BANK_NAME ASC')
  763. ->asArray()
  764. ->all();
  765. if (!$userName) {
  766. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  767. }
  768. //随机码保存在redis中方便进行比对
  769. $redis->setex('key_'.$userName , 3600 , $userName);
  770. // 报单中心会员的本地汇率
  771. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  772. $decCountry = Countries::getById($decCountryId);
  773. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  774. // 新会员的本地汇率
  775. $country = Countries::getById($countryId);
  776. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  777. // 新会员币种
  778. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  779. // 会员账户
  780. $userBalance = [
  781. 'cash' => 0,
  782. 'localCash' => 0,
  783. 'coin' => '',
  784. ];
  785. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  786. if ($userCash) {
  787. $userBalance['cash'] = $userCash['CASH'];
  788. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  789. $userBalance['coin'] = $currency['CODE'] ?? '';
  790. }
  791. // 行政区划
  792. $region = Region::getByCountryId($countryId);
  793. // 支付方式
  794. $payList = ShopGoods::payTypes();
  795. unset($payList['prp']);
  796. // 售卖方式
  797. $sellType = ShopGoods::getCategoryType();
  798. unset($sellType[0]['sell_type'][1]);
  799. return static::notice([
  800. 'allDecPackage' => $allDecPackage,
  801. 'allGoods' => $allGoods,
  802. 'allOpenBank' => $allOpenBank,
  803. 'userName' => $userName,
  804. 'payList' => $payList,
  805. 'sellType' => $sellType,
  806. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  807. 'userBalance' => $userBalance,
  808. 'isDec' => $isDec,
  809. 'decUserCurrencyRate' => $decUserCurrencyRate,
  810. 'userCurrencyRate' => $currencyRate,
  811. 'region' => $region,
  812. 'decLevel' => DeclarationLevel::getData(),
  813. ]);
  814. }
  815. /**
  816. * 报单级别套餐
  817. */
  818. public function actionDecPackage() {
  819. $decLv = \Yii::$app->request->get('id');
  820. //所有报单级别套餐
  821. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  822. return static::notice(['allDecPackage' => $allDecPackage]);
  823. }
  824. /*
  825. * 从会员名和左右,获取底部安置人
  826. *
  827. */
  828. public function actionGetAutoPlace() {
  829. $userName = \Yii::$app->request->get('userName');
  830. $side = \Yii::$app->request->get('side');
  831. $userId = Info::getUserIdByUserName($userName);
  832. $bottomPlace = UserNetwork::getBottomPlace($userId,'', $side);
  833. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  834. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  835. return static::notice($bottomUser);
  836. }
  837. /**
  838. * 会员信息查询
  839. * @return mixed
  840. * @throws \yii\web\HttpException
  841. */
  842. public function actionFullInfo()
  843. {
  844. $userName = \Yii::$app->request->get('userName');
  845. $userId = Info::getUserIdByUserName($userName);
  846. $userInfo['REAL_NAME'] = '';
  847. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  848. $loginUserInfo = User::getEnCodeInfo(\Yii::$app->user->id);
  849. if ($user['COUNTRY_ID'] !== $loginUserInfo['COUNTRY_ID']) {
  850. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  851. }
  852. if($user){
  853. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  854. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  855. $isLocation = [1 => 'Left-Null', 2 => 'Right-Null'];
  856. if($allChildUser) {
  857. foreach ($allChildUser as $child) {
  858. if ($child['RELATIVE_LOCATION']<'3'){
  859. // $isLocation[$child['RELATIVE_LOCATION']].= 'Full';
  860. $isLocation[$child['RELATIVE_LOCATION']] = str_replace('Null', 'Full', $isLocation[$child['RELATIVE_LOCATION']]);
  861. }
  862. }
  863. }
  864. $userInfo['countryId'] = $user['COUNTRY_ID'];
  865. $userInfo['userId'] = $userId;
  866. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  867. return static::notice($userInfo);
  868. }else{
  869. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  870. }
  871. }
  872. /**
  873. * Public member information lookup for guest declaration flows.
  874. * @return mixed
  875. */
  876. public function actionGuestFullInfo()
  877. {
  878. $userName = trim((string) \Yii::$app->request->get('userName', ''));
  879. $userId = Info::getUserIdByUserName($userName);
  880. $user = $userId ? User::findOneAsArray('ID=:ID', [':ID' => $userId]) : null;
  881. if (!$user) {
  882. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  883. }
  884. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  885. $isLocation = [1 => 'Left-Null', 2 => 'Right-Null'];
  886. if ($allChildUser) {
  887. foreach ($allChildUser as $child) {
  888. if ($child['RELATIVE_LOCATION'] < '3' && isset($isLocation[$child['RELATIVE_LOCATION']])) {
  889. $isLocation[$child['RELATIVE_LOCATION']] = str_replace('Null', 'Full', $isLocation[$child['RELATIVE_LOCATION']]);
  890. }
  891. }
  892. }
  893. return static::notice([
  894. 'REAL_NAME' => $user['REAL_NAME'],
  895. 'countryId' => $user['COUNTRY_ID'],
  896. 'userId' => $userId,
  897. 'isLocation' => '(' . implode(',', $isLocation) . ')',
  898. ]);
  899. }
  900. public function actionInspectNetwork()
  901. {
  902. // 推荐人信息
  903. $recommenderName= \Yii::$app->request->get('recommenderName');
  904. $userId = Info::getUserIdByUserName($recommenderName);
  905. $recommender = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  906. if (!$recommender) {
  907. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  908. }
  909. // 实际推荐人信息
  910. $recommenderActualName= \Yii::$app->request->get('recommenderActualName');
  911. $actualId = Info::getUserIdByUserName($recommenderActualName);
  912. $recommenderActual = User::findOneAsArray('ID=:ID', [':ID' => $actualId]);
  913. if (!$recommenderActual) {
  914. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  915. }
  916. // 实际推荐人是否是推荐人本人
  917. if ($actualId == $userId) {
  918. return static::notice([
  919. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  920. 'userId' => $recommenderActual['ID'],
  921. ]);
  922. }
  923. // 实际推荐人必须是推荐人的推荐网上级
  924. $sqlUp =<<<SQL
  925. WITH recursive t_rec AS
  926. (
  927. SELECT
  928. m.USER_ID,
  929. U.USER_NAME,
  930. m.PARENT_UID,
  931. U2.USER_NAME AS PARENT_NAME,
  932. 1 AS node_level
  933. FROM
  934. AR_USER_RELATION_NEW m
  935. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  936. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  937. WHERE
  938. U.USER_NAME = :USER_NAME
  939. UNION ALL
  940. SELECT
  941. t1.USER_ID,
  942. U.USER_NAME,
  943. t1.PARENT_UID,
  944. U2.USER_NAME AS PARENT_NAME,
  945. t2.node_level + 1 -- 结点层级
  946. FROM
  947. AR_USER_RELATION_NEW t1
  948. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  949. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  950. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  951. )
  952. SELECT
  953. *
  954. FROM
  955. t_rec
  956. SQL;
  957. // 查询推荐人的所有上级
  958. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  959. ->bindValue(':USER_NAME' , $recommenderName)
  960. ->queryAll();
  961. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  962. unset($relationNodeUp[$recommenderName]);
  963. if (in_array($recommenderActualName, $relationNodeUp)) {
  964. return static::notice([
  965. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  966. 'userId' => $recommenderActual['ID'],
  967. ]);
  968. }
  969. return static::notice(Yii::t('ctx', 'fillSponsorUpline'), 400);
  970. }
  971. /**
  972. * Public sponsor relationship validation for guest declaration flows.
  973. * @return mixed
  974. */
  975. public function actionGuestInspectNetwork()
  976. {
  977. $recommenderName = trim((string) \Yii::$app->request->get('recommenderName', ''));
  978. $recommenderActualName = trim((string) \Yii::$app->request->get('recommenderActualName', ''));
  979. if ($recommenderName === '' || $recommenderActualName === '') {
  980. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  981. }
  982. $userId = Info::getUserIdByUserName($recommenderName);
  983. $recommender = $userId ? User::findOneAsArray('ID=:ID', [':ID' => $userId]) : null;
  984. if (!$recommender) {
  985. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  986. }
  987. $actualId = Info::getUserIdByUserName($recommenderActualName);
  988. $recommenderActual = $actualId ? User::findOneAsArray('ID=:ID', [':ID' => $actualId]) : null;
  989. if (!$recommenderActual) {
  990. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  991. }
  992. if ($actualId == $userId) {
  993. return static::notice([
  994. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  995. 'userId' => $recommenderActual['ID'],
  996. ]);
  997. }
  998. $sqlUp = <<<SQL
  999. WITH recursive t_rec AS
  1000. (
  1001. SELECT m.USER_ID, U.USER_NAME, m.PARENT_UID, U2.USER_NAME AS PARENT_NAME, 1 AS node_level
  1002. FROM AR_USER_RELATION_NEW m
  1003. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  1004. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  1005. WHERE U.USER_NAME = :USER_NAME
  1006. UNION ALL
  1007. SELECT t1.USER_ID, U.USER_NAME, t1.PARENT_UID, U2.USER_NAME AS PARENT_NAME,
  1008. t2.node_level + 1
  1009. FROM AR_USER_RELATION_NEW t1
  1010. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  1011. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  1012. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  1013. )
  1014. SELECT * FROM t_rec
  1015. SQL;
  1016. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  1017. ->bindValue(':USER_NAME', $recommenderName)
  1018. ->queryAll();
  1019. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  1020. if (in_array($recommenderActualName, $relationNodeUp, true)) {
  1021. return static::notice([
  1022. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  1023. 'userId' => $recommenderActual['ID'],
  1024. ]);
  1025. }
  1026. return static::notice(Yii::t('ctx', 'fillSponsorUpline'), 400);
  1027. }
  1028. /**
  1029. * 复消会员信息查询
  1030. * @return mixed
  1031. * @throws \yii\web\HttpException
  1032. */
  1033. public function actionUserBaseInfo()
  1034. {
  1035. $userName = \Yii::$app->request->get('userName');
  1036. $userId = Info::getUserIdByUserName($userName);
  1037. if($userId){
  1038. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  1039. if($allAddress) {
  1040. foreach ($allAddress as $key => $row) {
  1041. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  1042. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  1043. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  1044. }
  1045. }
  1046. $userInfo = Info::baseInfoWithNet($userId);
  1047. // $decLevelConfig = Cache::getDecLevelConfig();
  1048. // $empLevelConfig = Cache::getEmpLevelConfig();
  1049. $arr = [
  1050. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  1051. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  1052. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  1053. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  1054. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  1055. 'allAddress'=>$allAddress
  1056. ];
  1057. return static::notice($arr);
  1058. }else{
  1059. return static::notice(Yii::t('app', 'repeatSalesMemberNoDoesNotExist'), 400);
  1060. }
  1061. }
  1062. /**
  1063. * 会员资料
  1064. * @return mixed
  1065. * @throws \yii\web\HttpException
  1066. */
  1067. public function actionBaInfo()
  1068. {
  1069. $data['userInfo'] = BaUser::getEnCodeInfo(\Yii::$app->user->id);
  1070. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  1071. // 推荐人
  1072. $baUserInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id]);
  1073. $sponsor = User::findOneAsArray('ID=:USER_ID', [':USER_ID' => $baUserInfo['REC_UID']]);
  1074. $data['userInfo']['SponsorCode'] = $sponsor['USER_NAME'];
  1075. $data['userInfo']['SponsorName'] = $sponsor['REAL_NAME'];
  1076. return static::notice($data);
  1077. }
  1078. /**
  1079. * 编辑会员资料
  1080. * @return mixed
  1081. * @throws \yii\web\HttpException
  1082. */
  1083. public function actionBaEdit()
  1084. {
  1085. if(\Yii::$app->request->isPost)
  1086. {
  1087. $form = new BaUserForm();
  1088. $post = \Yii::$app->request->post();
  1089. $form->scenario = 'modifyProfile';
  1090. if ($form->load($post, '') && $result = $form->modifyProfile()){
  1091. return static::notice(Yii::t('app', 'personalDataModifiedSuccessfully'), 400);
  1092. } else {
  1093. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1094. }
  1095. }
  1096. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  1097. }
  1098. /**
  1099. * 修改登录密码
  1100. */
  1101. public function actionBaPassword(){
  1102. if(\Yii::$app->request->isPost) {
  1103. $form = new BaUserForm();
  1104. $form->scenario = 'modifyPassword';
  1105. $post = \Yii::$app->request->post();
  1106. if($form->load($post, '') && $result = $form->modifyPassword()){
  1107. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  1108. } else {
  1109. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1110. }
  1111. }
  1112. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  1113. }
  1114. /**
  1115. * 修改支付密码
  1116. */
  1117. public function actionBaPayPassword(){
  1118. if(\Yii::$app->request->isPost){
  1119. $form = new BaUserForm();
  1120. $form->scenario = 'modifyPasswordPay';
  1121. $post = \Yii::$app->request->post();
  1122. $form->userId = \Yii::$app->user->id;
  1123. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  1124. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  1125. } else {
  1126. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1127. }
  1128. }
  1129. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  1130. }
  1131. /**
  1132. * BA报单管理
  1133. */
  1134. public function actionBaDec() {
  1135. // 生成随机码 , 初始化redis
  1136. $userName = Info::generateWebUserName('NG',9);
  1137. $redis = \Yii::$app->redis;
  1138. $post = \Yii::$app->request->post();
  1139. if (\Yii::$app->request->isPost) {
  1140. // 根据支付方式区分逻辑
  1141. $payMethod = \Yii::$app->request->post('payType', '');
  1142. if ($payMethod === 'pay_stack') {
  1143. $formModel = new BaApproachDeclarationLoopForm();
  1144. } else {
  1145. unset($post['payType']);
  1146. $formModel = new BaDeclarationLoopForm();
  1147. }
  1148. $formModel->scenario = 'userDec';
  1149. $post['province'] = $post['province'] ? :1;
  1150. $post['city'] = $post['city'] ? :1;
  1151. $post['county'] = $post['county'] ? :1;
  1152. // $post['conUserName'] = trim($post['conUserName']);
  1153. $post['recUserName'] = trim($post['recUserName']);
  1154. $post['cityName'] = trim($post['cityName']);
  1155. $post['lgaName'] = trim($post['lgaName']);
  1156. // 针对于会员编号的判断
  1157. $insertUserName = strtoupper($post['insertUserName']);
  1158. $getRedisUserName = $redis->get('key_' . $insertUserName);
  1159. if (!$getRedisUserName){
  1160. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  1161. }
  1162. if ($insertUserName != $getRedisUserName){
  1163. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  1164. }
  1165. $post['insertUserName'] = $insertUserName;
  1166. $post['type'] = BaDeclarationForm::TYPE_ZC;
  1167. $allData['data'][] = $post;
  1168. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  1169. return static::notice($result); // 报单成功
  1170. } else {
  1171. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  1172. }
  1173. }
  1174. // 只查询普通商品
  1175. $allGoods = ShopGoods::find()->where("ID='375895243322691584'")->orderBy('SORT ASC')->asArray()->all();
  1176. if (!$userName) {
  1177. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  1178. }
  1179. //随机码保存在redis中方便进行比对
  1180. $redis->setex('key_'.$userName , 3600 , $userName);
  1181. // 会员账户
  1182. $userBalance = [
  1183. 'cash' => 0,
  1184. // 'tourism_points' => 0,
  1185. // 'garage_points' => 0,
  1186. // 'villa_points' => 0,
  1187. ];
  1188. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  1189. if ($userCash) {
  1190. $userBalance['cash'] = $userCash['CASH'];
  1191. }
  1192. return static::notice([
  1193. 'allGoods' => $allGoods,
  1194. 'userName' => $userName,
  1195. 'payList' => ShopGoods::payTypes(),
  1196. 'sellType' => ShopGoods::getCategoryType(),
  1197. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  1198. 'userBalance' => $userBalance,
  1199. ]);
  1200. }
  1201. /**
  1202. * BA会员信息
  1203. * @return mixed
  1204. * @throws \yii\web\HttpException
  1205. */
  1206. public function actionBaUserInfo()
  1207. {
  1208. $userName = \Yii::$app->request->get('userName');
  1209. $userId = Info::getBaUserIdByUserName($userName);
  1210. $userInfo['REAL_NAME'] = '';
  1211. $user = BaUser::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  1212. $uInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'REC_UID');
  1213. if($user){
  1214. $rec_user = UserInfo::findOneAsArray('USER_ID=:USER_ID',[':USER_ID' => $uInfo['REC_UID']], 'USER_ID, USER_NAME');
  1215. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  1216. $userInfo['REC_USER_ID'] = $rec_user['USER_ID'];
  1217. $userInfo['REC_USER_NAME'] = $rec_user['USER_NAME'];
  1218. return static::notice($userInfo);
  1219. }else{
  1220. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  1221. }
  1222. }
  1223. }