UserController.php 55 KB

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