UserController.php 49 KB

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