UserController.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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\Cache;
  10. use common\helpers\Form;
  11. use common\helpers\LoggerTool;
  12. use common\helpers\Tool;
  13. use common\helpers\user\Info;
  14. use common\models\BaUser;
  15. use common\models\Config;
  16. use common\models\Countries;
  17. use common\models\CurrencyConversions;
  18. use common\models\DeclarationLevel;
  19. use common\models\DeclarationPackage;
  20. use common\models\DecOrder;
  21. use common\models\forms\ApproachDeclarationLoopForm;
  22. use common\models\forms\BaApproachDeclarationLoopForm;
  23. use common\models\forms\ApproachDeclarationUpgradeForm;
  24. use common\models\forms\BaUserForm;
  25. use common\models\forms\DeclarationForm;
  26. use common\models\forms\BaDeclarationForm;
  27. use common\models\forms\DeclarationLoopForm;
  28. use common\models\forms\BaDeclarationLoopForm;
  29. use common\models\forms\UploadForm;
  30. use common\models\forms\UserBindForm;
  31. use common\models\forms\UserForm;
  32. use common\models\Instalment;
  33. use common\models\OpenBank;
  34. use common\models\ReceiveAddress;
  35. use common\models\Region;
  36. use common\models\ShopGoods;
  37. use common\models\ShopGoodsNature;
  38. use common\models\UpgradeType;
  39. use common\models\User;
  40. use common\models\UserBind;
  41. use common\models\UserBonus;
  42. use common\models\UserInfo;
  43. use common\models\BaUserInfo;
  44. use common\models\UserNetwork;
  45. use common\models\forms\DeclarationUpgradeForm;
  46. use common\models\UserWallet;
  47. use Yii;
  48. use yii\db\Exception;
  49. use yii\web\UploadedFile;
  50. class UserController extends BaseController {
  51. public $modelClass = UserInfo::class;
  52. /**
  53. * 会员资料
  54. * @return mixed
  55. * @throws \yii\web\HttpException
  56. */
  57. public function actionIndex() {
  58. $allNation = \Yii::$app->params['nation'];
  59. $allOpenBank = OpenBank::findAllAsArray('STATUS=1');
  60. $data['allNation'] = $allNation;
  61. $data['allOpenBank'] = $allOpenBank;
  62. $data['userInfo'] = User::getEnCodeInfo(\Yii::$app->user->id);
  63. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  64. return static::notice($data);
  65. }
  66. /**
  67. * 编辑会员资料
  68. * @return mixed
  69. * @throws \yii\web\HttpException
  70. */
  71. public function actionEdit() {
  72. if(\Yii::$app->request->isPost){
  73. $form = new UserForm();
  74. $post = \Yii::$app->request->post();
  75. $form->scenario = 'modifyProfile';
  76. if($form->load($post, '') && $result = $form->modifyProfile()){
  77. return static::notice(Yii::t('app', 'personalDataModifiedSuccessfully'), 400);
  78. } else {
  79. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  80. }
  81. }
  82. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  83. }
  84. /**
  85. * 修改登录密码
  86. */
  87. public function actionPassword(){
  88. if(\Yii::$app->request->isPost){
  89. $form = new UserForm();
  90. $form->scenario = 'modifyPassword';
  91. $post = \Yii::$app->request->post();
  92. if($form->load($post, '') && $result = $form->modifyPassword()){
  93. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  94. } else {
  95. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  96. }
  97. }
  98. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  99. }
  100. /**
  101. * 修改支付密码
  102. */
  103. public function actionPayPassword(){
  104. if(\Yii::$app->request->isPost){
  105. $form = new UserForm();
  106. $form->scenario = 'modifyPasswordPay';
  107. $post = \Yii::$app->request->post();
  108. $form->userId = \Yii::$app->user->id;
  109. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  110. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'));
  111. } else {
  112. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  113. }
  114. }
  115. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  116. }
  117. /**
  118. * 直推会员列表
  119. * @return mixed
  120. * @throws \yii\web\HttpException
  121. */
  122. public function actionRecUser() {
  123. $allData = UserInfo::lists('AND REC_UID=:REC_UID', [':REC_UID' => \Yii::$app->user->id], ['useSlaves' => true, 'select'=>'USER_ID,CREATED_AT']);
  124. foreach ($allData['list'] as $key => $data) {
  125. $userBaseInfo = User::getEnCodeInfo($data['USER_ID']);
  126. $userBaseInfo['NATION'] = \Yii::$app->params['nation'][$userBaseInfo['NATION']]['name'] ?? '';
  127. $allData['list'][$key]['BASE_INFO'] = $userBaseInfo;
  128. }
  129. return static::notice($allData);
  130. }
  131. /**
  132. * 上传身份证
  133. * @return mixed
  134. * @throws \yii\base\Exception
  135. * @throws \yii\web\HttpException
  136. */
  137. public function actionIdCard() {
  138. if (\Yii::$app->request->isPost) {
  139. $formModel = new UploadForm();
  140. $formModel->scenario = 'idCardFront';
  141. $formModel->file = UploadedFile::getInstanceByName('file');
  142. //$formModel->token = \Yii::$app->request->post('uploadToken');
  143. $formModel->token = \Yii::$app->request->request('uploadToken');
  144. if ($formModel->file && $formModel->upload()) {
  145. return static::notice(Yii::t('app', 'successfully'));
  146. } else {
  147. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  148. }
  149. }
  150. // 查看该用户是否已经上传过身份证
  151. $oneData = User::find()->select('ID_IMAGE')->where('ID=:ID', [':ID' => \Yii::$app->user->id])->asArray()->one();
  152. if ($oneData['ID_IMAGE']) {
  153. return static::notice($oneData);
  154. } else {
  155. $token = Cache::setUploadToken();
  156. return static::notice($token);
  157. }
  158. }
  159. /**
  160. * 点位绑定
  161. * @return mixed
  162. * @throws \yii\base\Exception
  163. * @throws \yii\web\HttpException
  164. */
  165. public function actionBind() {
  166. $userBind = UserBind::findOneAsArray('USER_ID=:USER_ID AND IS_DEL=0', [':USER_ID' => \Yii::$app->user->id]);
  167. $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');
  168. foreach ($allData['list'] as $key => $value) {
  169. $baseInfo = Info::baseInfoZh($value['USER_ID']);
  170. if ($baseInfo['STATUS'] != 1) {
  171. unset($allData['list'][$key]);
  172. continue;
  173. }
  174. $allData['list'][$key]['USER_NAME'] = $baseInfo['USER_NAME'];
  175. $allData['list'][$key]['REAL_NAME'] = $baseInfo['REAL_NAME'];
  176. $allData['list'][$key]['BANK_PROVINCE_NAME'] = $baseInfo['BANK_PROVINCE_NAME'];
  177. $allData['list'][$key]['BANK_CITY_NAME'] = $baseInfo['BANK_CITY_NAME'];
  178. $allData['list'][$key]['BANK_COUNTY_NAME'] = $baseInfo['BANK_COUNTY_NAME'];
  179. $allData['list'][$key]['OPEN_BANK_NAME'] = $baseInfo['OPEN_BANK_NAME'];
  180. $allData['list'][$key]['BANK_NO'] = $baseInfo['BANK_NO'];
  181. $allData['list'][$key]['MAIN_USER_NAME'] =Info::getUserNameByUserId($value['MAIN_UID']);
  182. }
  183. $allData['list'] = array_values($allData['list']);
  184. return static::notice($allData);
  185. }
  186. /**
  187. * 编辑点位绑定
  188. * @return mixed
  189. * @throws \yii\web\HttpException
  190. */
  191. public function actionBindEdit(){
  192. $id = \Yii::$app->request->get('id');
  193. if(\Yii::$app->request->isPost) {
  194. return parent::edit(UserBindForm::class, Yii::t('app', 'successfully'), 'frontEdit', ['frontEdit'], null, function($form, $result){
  195. //log
  196. });
  197. }
  198. // 获得当前会员的用户名等信息
  199. $userBind = UserBind::findOneAsArray('ID=:ID AND IS_DEL=0', [':ID' => $id]);
  200. $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');
  201. foreach($userBinds as $key=>$value){
  202. $status = Info::getStatusByUserId($value['USER_ID']);
  203. if ($status != 1) {
  204. unset($userBinds[$key]);
  205. continue;
  206. }
  207. $userBinds[$key]['USER_NAME'] = Info::getUserNameByUserId($value['USER_ID']);
  208. }
  209. $userBinds = array_values($userBinds);
  210. return static::notice(['userBinds' => $userBinds,'mainUid'=>$userBind['MAIN_UID']]);
  211. }
  212. // 会员升级,通过会员的编号,获取会员信息
  213. public function actionUpgradeInfo() {
  214. $isSwitchUpgrade = Config::find()
  215. ->where("CONFIG_NAME='isOpenUpgrade'")
  216. ->asArray()
  217. ->one();
  218. $isOpen = !empty($isSwitchUpgrade) && isset($isSwitchUpgrade['VALUE']) ? $isSwitchUpgrade['VALUE'] : 0;
  219. if ($isOpen < 1) {
  220. return static::notice(Yii::t('app', 'theFunctionIsNotAvailable'), 400);
  221. }
  222. $userNumber = \Yii::$app->request->request('userName');
  223. $baseInfo = Info::baseInfoZhByUserName($userNumber);
  224. if ($baseInfo['STATUS'] != 1) {
  225. return static::notice(Yii::t('app', 'inactiveUser'), 400);
  226. }
  227. // 1. 如果是最高级别,则只显示用户基本信息
  228. // 2. 如果不是最高级别,如果用户累计报单数据是0, 或者用户累计报单业绩不符合级别信息,则提示 请联系客服核对业绩
  229. $userId = $baseInfo['ID'];
  230. $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
  231. // 获取系统中的DEC 报单级别配置
  232. $decConfig = Cache::getDecLevelConfig();
  233. $userDecInfo = $decConfig[$userDecId]; // 会员的级别具体信息
  234. $maxPerfInfo = DeclarationLevel::getMaxDecPref();
  235. $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
  236. $observe = Config::getConfigByType('observe'); // 获取观察期配置信息
  237. $observeLimit = $observe['observePeriodLimit']['value']; // 月份限制
  238. $isObserve = User::checkIsObserve($baseInfo['CREATED_AT'], $observeLimit); // 判断用户是否再观察期中
  239. // 如果用户已经是最高级别,则只展示用户信息
  240. $isMax = false;
  241. if ($maxDecId == $userDecId) {
  242. $isMax = true;
  243. }
  244. // 分期的总期数
  245. $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
  246. // 查询是否有FX的分期订单
  247. $stageFX = Instalment::getOneStage($baseInfo['ID'], 'FX');
  248. if ($stageFX && $stageFX < $instalmentConfig) {
  249. $instalment = false;
  250. } else {
  251. // 是否有未完成的BD类型的分期订单
  252. $stage = Instalment::getOneStage($userId, 'BD');
  253. if ($stage && $stage < $instalmentConfig) {
  254. $instalment = true;
  255. } else if ($isMax && $stage == $instalmentConfig) {
  256. $instalment = false;
  257. } else {
  258. $instalment = false;
  259. }
  260. }
  261. // 如果用户已经是最高级别,则只展示用户信息
  262. $userInfo = [
  263. 'DEC_NAME' => $baseInfo['DEC_LV_NAME'], // 用户级别中文
  264. 'DEC_ID' => $userDecId, // 用户级别id
  265. 'REAL_NAME' => $baseInfo['REAL_NAME'], // 真实姓名
  266. 'ADD_AT' => date('Y-m-d', $baseInfo['CREATED_AT']), // 加入时间
  267. 'COUNTRY_NAME' => $baseInfo['COUNTRY_NAME'], // 国家
  268. 'IS_OBSERVE' => $isObserve, // 是否是观察期 true为是观察期
  269. 'IS_MAX' => $isMax, // 是否已是最大级别 最大级别不需要判断报单总PV是多少 只展示基本信息
  270. 'INSTALMENT' => $instalment,
  271. 'NOW_PERF' => User::sumDevPvByUserId($userId), // 用户所有报单PV总和
  272. ];
  273. // 如果是最高级别了,则无需升级
  274. if ($isMax) {
  275. return static::notice(['baseInfo' => $userInfo]);
  276. }
  277. $levelPerf = $userDecInfo['PERF'];// 用户当前级别对应的业绩值
  278. if (!$isMax) {
  279. $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
  280. // // 如果总和小于级别业绩 去掉这校验直接补比如3000-980的差值
  281. // if ($userDecPvSum < $levelPerf) {
  282. // return static::notice('请联系客服人员核对业绩',400);
  283. // }
  284. // 下一级业绩
  285. $nextLevelPerf = DeclarationLevel::getNextDecPref($levelPerf)['PERF'];
  286. // 如果总和超过了下一级业绩
  287. if ($userDecPvSum >= $nextLevelPerf) {
  288. return static::notice(Yii::t('app', 'checkPerformance'), 400);
  289. }
  290. $type = $isObserve ? 1 : 2;
  291. $userInfo['UPGRADE_FUNC'] = $isObserve ? Yii::t('app', 'fillingUpOfADeficit') : Yii::t('app', 'fullPayment');
  292. $upgradeType = UpgradeType::getOneByType($type);
  293. // 如果用户不是最大级别,则需要获取是否观察期,算出PV是否有问题,应该补多少,
  294. $userInfo['UPGRADE_TYPE'] = $upgradeType;
  295. $userInfo['NOW_PERF'] = $userDecPvSum;
  296. $userInfo['NEXT_PERF'] = $nextLevelPerf;
  297. // 用户可选择的级别列表
  298. $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll($levelPerf);// 用户可选择的级别列表
  299. // 如果用户正处于报单分期中,则可以升级到Elite
  300. $userInstalmentInfo = Instalment::getInfo($userId);
  301. if($userInstalmentInfo){
  302. if ($userInstalmentInfo['ORDER_TYPE']=='BD' && $userInstalmentInfo['STAGE'] < 3){
  303. $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll(12);// 用户可选择的级别列表
  304. unset($userInfo['LEVEL_LIST'][$userDecId]);
  305. }
  306. }
  307. // 循环列表,补充升级所需要的补差
  308. foreach ($userInfo['LEVEL_LIST'] as &$v) {
  309. $v['REPAIR_PV'] = $isObserve ? $v['PERF'] - $userInfo['NOW_PERF'] : $v['PERF'];
  310. }
  311. }
  312. return static::notice(['baseInfo' => $userInfo]);
  313. }
  314. // 会员升级管理
  315. public function actionUpgrade() {
  316. $isMax = \Yii::$app->request->get('isMax');
  317. $userNumber = \Yii::$app->request->get('userName');
  318. $isSwitchUpgrade = Config::find()
  319. ->where("CONFIG_NAME='isOpenUpgrade'")
  320. ->asArray()
  321. ->one();
  322. $isOpen = !empty($isSwitchUpgrade) && isset($isSwitchUpgrade['VALUE']) ? $isSwitchUpgrade['VALUE'] : 0;
  323. if ($isOpen < 1) {
  324. return static::notice(Yii::t('app', 'theFunctionIsNotAvailable'), 400);
  325. }
  326. // 开始升级
  327. if (\Yii::$app->request->isPost) {
  328. $post = \Yii::$app->request->post();
  329. // 根据支付方式区分逻辑
  330. $payMethod = \Yii::$app->request->post('payType', '');
  331. if ($payMethod === 'pay_stack') {
  332. $formModel = new ApproachDeclarationUpgradeForm();
  333. } else {
  334. unset($post['payType']);
  335. $formModel = new DeclarationUpgradeForm();
  336. }
  337. $post['type'] = DeclarationForm::TYPE_ZC;
  338. if ($formModel->load($post, '') && $result = $formModel->add($post)) {
  339. return static::notice($result);// Upgrade declaration succeeded升级报单成功
  340. } else {
  341. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  342. }
  343. }
  344. // 升级的会员
  345. $userName = \Yii::$app->request->get('userName');
  346. // 会员信息
  347. $user = User::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => trim($userName)]);
  348. if (!$user) {
  349. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  350. }
  351. //所有报单套餐
  352. $allDecPackage = DeclarationPackage::getAllData();
  353. $decLevels = Cache::getDecLevelConfig();
  354. foreach ($allDecPackage as $k=>$v){
  355. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  356. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  357. }
  358. $baseInfo = Info::baseInfoZhByUserName($userNumber);
  359. // 分期的总期数
  360. $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
  361. // 查询是否有FX的分期订单
  362. $stageFX = Instalment::getOneStage($baseInfo['ID'], 'FX');
  363. if ($stageFX && $stageFX < $instalmentConfig) {
  364. if ($isMax === "true") {
  365. $condition = ") AND S.INSTALMENT = 1000";
  366. } else {
  367. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = 1000)";
  368. }
  369. } else {
  370. // 是否有未完成的BD类型的分期订单
  371. $stageBD = Instalment::getOneStage($baseInfo['ID'], 'BD');
  372. if ($isMax === "true") {
  373. if ($stageBD > 0 && $stageBD < $instalmentConfig) {
  374. $condition = ") AND (S.INSTALMENT = " . ($stageBD + 1) . ")";
  375. } else {
  376. $condition = ") AND S.INSTALMENT = 0";
  377. }
  378. } else {
  379. if ($stageBD > 0 && $stageBD < $instalmentConfig) {
  380. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = " . ($stageBD + 1) . ")";
  381. } else {
  382. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = 1)";
  383. }
  384. }
  385. }
  386. //所有自选商品
  387. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  388. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  389. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  390. $decUserName = User::getEnCodeInfo(\Yii::$app->user->id)['USER_NAME'];
  391. $query_condition= " AND (1<>1";
  392. if(!$isDecReg || ($isDecReg && $isDec==1)){
  393. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  394. }
  395. if($isStudio==1){
  396. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  397. }
  398. $query_condition .= $condition . ' AND N.COUNTRY_ID = ' . $user['COUNTRY_ID'];
  399. $allGoods = ShopGoods::find()
  400. ->alias('S')
  401. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID')
  402. ->join('LEFT JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  403. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition)
  404. ->orderBy('SORT ASC')
  405. ->asArray()
  406. ->all();
  407. LoggerTool::info(json_encode(["STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition]));
  408. foreach ($allGoods as &$goods) {
  409. $goods['TAX'] = Tool::calculateTax($goods['SELL_PRICE'], $goods['TAX_RATE']);
  410. }
  411. // 报单中心汇率
  412. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  413. $decCountry = Countries::getById($decCountryId);
  414. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  415. // 升级会员汇率
  416. $country = Countries::getById($user['COUNTRY_ID']);
  417. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  418. $userBalance = [
  419. 'cash' => 0,
  420. 'localCash' => 0
  421. ];
  422. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  423. if ($userCash) {
  424. $userBalance['cash'] = $userCash['CASH'];
  425. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  426. }
  427. // 行政区划
  428. $region = Region::getByCountryId($user['COUNTRY_ID']);
  429. return static::notice([
  430. 'allDecPackage' => $allDecPackage,
  431. 'allGoods' => $allGoods,
  432. 'decUserName'=>$decUserName,
  433. 'payList' => ShopGoods::payTypes(),
  434. 'sellType' => ShopGoods::getCategoryType(),
  435. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  436. 'userBalance' => $userBalance,
  437. 'decUserCurrencyRate' => $decUserCurrencyRate,
  438. 'userCurrencyRate' => $currencyRate,
  439. 'region' => $region,
  440. ]);
  441. }
  442. /**
  443. * 报单管理
  444. */
  445. public function actionDec() {
  446. // 默认国家
  447. $countryId = \Yii::$app->request->get('countryId');
  448. if (!$countryId) {
  449. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  450. }
  451. // 生成随机码 , 初始化redis
  452. $userName = Info::generateWebName($countryId);
  453. $redis = \Yii::$app->redis;
  454. $post = \Yii::$app->request->post();
  455. if (\Yii::$app->request->isPost) {
  456. $userInfo = User::getEnCodeInfo(\Yii::$app->user->id);
  457. if($userInfo['IS_DEC'] == 1 && !empty($post['decUserName']) && $post['decUserName'] != $userInfo['USER_NAME']){
  458. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  459. }
  460. if($userInfo['IS_DEC'] == 0 && $post['decUserName']){
  461. //查询报单编号是否存在
  462. $userId = Info::getUserIdByUserName($post['decUserName']);
  463. if(!$userId){
  464. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  465. }
  466. $isDec = User::getEnCodeInfo($userId)['IS_DEC'];
  467. if(!$isDec){
  468. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  469. }
  470. }
  471. // 根据支付方式区分逻辑
  472. $payMethod = \Yii::$app->request->post('payType', '');
  473. if ($payMethod === 'pay_stack') {
  474. $formModel = new ApproachDeclarationLoopForm();
  475. } else {
  476. unset($post['payType']);
  477. $formModel = new DeclarationLoopForm();
  478. }
  479. $formModel->scenario = 'userDec';
  480. $post['province'] = $post['province'] ? :1;
  481. $post['city'] = $post['city'] ? :1;
  482. $post['county'] = $post['county'] ? :1;
  483. $post['conUserName'] = trim($post['conUserName']);
  484. $post['recUserName'] = trim($post['recUserName']);
  485. $post['cityName'] = trim($post['cityName']);
  486. $post['lgaName'] = trim($post['lgaName']);
  487. // 针对于会员编号的判断
  488. if($post['decType']=='normal'){ // 普通报单,判断Redis中的用户名是否一致
  489. $insertUserName = strtoupper($post['insertUserName']);
  490. $getRedisUserName = $redis->get('key_' . $insertUserName);
  491. if (!$getRedisUserName){
  492. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  493. }
  494. if ($insertUserName != $getRedisUserName){
  495. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  496. }
  497. }else{ // BA升级,需要判断BA用户是否存在
  498. $insertUserName = $post['insertUserName'];
  499. }
  500. $post['insertUserName'] = $insertUserName;
  501. $post['type'] = DeclarationForm::TYPE_ZC;
  502. $allData['data'][] = $post;
  503. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  504. return static::notice($result);//报单成功
  505. } else {
  506. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  507. }
  508. }
  509. //所有报单套餐
  510. $allDecPackage = DeclarationPackage::getAllData();
  511. $decLevels = Cache::getDecLevelConfig();
  512. foreach ($allDecPackage as $k=>$v){
  513. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  514. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  515. }
  516. //所有自选商品
  517. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  518. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  519. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  520. $query_condition = " AND (1<>1";
  521. if(!$isDecReg || ($isDecReg && $isDec==1)){
  522. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  523. }
  524. if($isStudio==1){
  525. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  526. }
  527. $query_condition .= ") AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=" . $countryId;
  528. LoggerTool::info(json_encode(["STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition]));
  529. // 只查询普通商品
  530. $allGoods = ShopGoods::find()
  531. ->alias('S')
  532. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID')
  533. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  534. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition)
  535. ->orderBy('SORT ASC')
  536. ->asArray()
  537. ->all();
  538. // 银行开户行
  539. $allOpenBank = OpenBank::find()
  540. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  541. ->orderBy('LIST_ORDER ASC')
  542. ->asArray()
  543. ->all();
  544. if (!$userName) {
  545. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  546. }
  547. //随机码保存在redis中方便进行比对
  548. $redis->setex('key_'.$userName , 3600 , $userName);
  549. // 报单中心会员的本地汇率
  550. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  551. $decCountry = Countries::getById($decCountryId);
  552. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  553. // 新会员的本地汇率
  554. $country = Countries::getById($countryId);
  555. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  556. // 会员账户
  557. $userBalance = [
  558. 'cash' => 0,
  559. 'localCash' => 0
  560. ];
  561. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  562. if ($userCash) {
  563. $userBalance['cash'] = $userCash['CASH'];
  564. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  565. }
  566. // 行政区划
  567. $region = Region::getByCountryId($countryId);
  568. return static::notice([
  569. 'allDecPackage' => $allDecPackage,
  570. 'allGoods' => $allGoods,
  571. 'allOpenBank' => $allOpenBank,
  572. 'userName' => $userName,
  573. 'payList' => ShopGoods::payTypes(),
  574. 'sellType' => ShopGoods::getCategoryType(),
  575. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  576. 'userBalance' => $userBalance,
  577. 'isDec' => $isDec,
  578. 'decUserCurrencyRate' => $decUserCurrencyRate,
  579. 'userCurrencyRate' => $currencyRate,
  580. 'region' => $region,
  581. ]);
  582. }
  583. /**
  584. * 报单级别套餐
  585. */
  586. public function actionDecPackage() {
  587. $decLv = \Yii::$app->request->get('id');
  588. //所有报单级别套餐
  589. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  590. return static::notice(['allDecPackage' => $allDecPackage]);
  591. }
  592. /*
  593. * 从会员名和左右,获取底部安置人
  594. *
  595. */
  596. public function actionGetAutoPlace() {
  597. $userName = \Yii::$app->request->get('userName');
  598. $side = \Yii::$app->request->get('side');
  599. $userId = Info::getUserIdByUserName($userName);
  600. // print_r($userId);
  601. $bottomPlace = UserNetwork::getBottomPlace($userId,'', $side);
  602. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  603. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  604. // print_r($bottomUser);
  605. return static::notice($bottomUser);
  606. }
  607. /**
  608. * 会员信息查询
  609. * @return mixed
  610. * @throws \yii\web\HttpException
  611. */
  612. public function actionFullInfo()
  613. {
  614. $userName = \Yii::$app->request->get('userName');
  615. $userId = Info::getUserIdByUserName($userName);
  616. $userInfo['REAL_NAME'] = '';
  617. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  618. if($user){
  619. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  620. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  621. $isLocation = [1 => 'Left-Null', 2 => 'Right-Null'];
  622. if($allChildUser) {
  623. foreach ($allChildUser as $child) {
  624. if ($child['RELATIVE_LOCATION']<'3'){
  625. // $isLocation[$child['RELATIVE_LOCATION']].= 'Full';
  626. $isLocation[$child['RELATIVE_LOCATION']] = str_replace('Null', 'Full', $isLocation[$child['RELATIVE_LOCATION']]);
  627. }
  628. }
  629. }
  630. $userInfo['countryId'] = $user['COUNTRY_ID'];
  631. $userInfo['userId'] = $userId;
  632. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  633. return static::notice($userInfo);
  634. }else{
  635. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  636. }
  637. }
  638. /**
  639. * 复消会员信息查询
  640. * @return mixed
  641. * @throws \yii\web\HttpException
  642. */
  643. public function actionUserBaseInfo()
  644. {
  645. $userName = \Yii::$app->request->get('userName');
  646. $userId = Info::getUserIdByUserName($userName);
  647. if($userId){
  648. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  649. if($allAddress) {
  650. foreach ($allAddress as $key => $row) {
  651. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  652. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  653. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  654. }
  655. }
  656. $userInfo = Info::baseInfoWithNet($userId);
  657. // $decLevelConfig = Cache::getDecLevelConfig();
  658. // $empLevelConfig = Cache::getEmpLevelConfig();
  659. $arr = [
  660. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  661. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  662. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  663. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  664. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  665. 'allAddress'=>$allAddress
  666. ];
  667. return static::notice($arr);
  668. }else{
  669. return static::notice(Yii::t('app', 'repeatSalesMemberNoDoesNotExist'), 400);
  670. }
  671. }
  672. /**
  673. * 会员资料
  674. * @return mixed
  675. * @throws \yii\web\HttpException
  676. */
  677. public function actionBaInfo()
  678. {
  679. $data['userInfo'] = BaUser::getEnCodeInfo(\Yii::$app->user->id);
  680. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  681. // 推荐人
  682. $baUserInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id]);
  683. $sponsor = User::findOneAsArray('ID=:USER_ID', [':USER_ID' => $baUserInfo['REC_UID']]);
  684. $data['userInfo']['SponsorCode'] = $sponsor['USER_NAME'];
  685. $data['userInfo']['SponsorName'] = $sponsor['REAL_NAME'];
  686. return static::notice($data);
  687. }
  688. /**
  689. * 编辑会员资料
  690. * @return mixed
  691. * @throws \yii\web\HttpException
  692. */
  693. public function actionBaEdit()
  694. {
  695. if(\Yii::$app->request->isPost)
  696. {
  697. $form = new BaUserForm();
  698. $post = \Yii::$app->request->post();
  699. $form->scenario = 'modifyProfile';
  700. if ($form->load($post, '') && $result = $form->modifyProfile()){
  701. return static::notice(Yii::t('app', 'personalDataModifiedSuccessfully'), 400);
  702. } else {
  703. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  704. }
  705. }
  706. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  707. }
  708. /**
  709. * 修改登录密码
  710. */
  711. public function actionBaPassword(){
  712. if(\Yii::$app->request->isPost) {
  713. $form = new BaUserForm();
  714. $form->scenario = 'modifyPassword';
  715. $post = \Yii::$app->request->post();
  716. if($form->load($post, '') && $result = $form->modifyPassword()){
  717. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  718. } else {
  719. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  720. }
  721. }
  722. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  723. }
  724. /**
  725. * 修改支付密码
  726. */
  727. public function actionBaPayPassword(){
  728. if(\Yii::$app->request->isPost){
  729. $form = new BaUserForm();
  730. $form->scenario = 'modifyPasswordPay';
  731. $post = \Yii::$app->request->post();
  732. $form->userId = \Yii::$app->user->id;
  733. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  734. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  735. } else {
  736. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  737. }
  738. }
  739. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  740. }
  741. /**
  742. * BA报单管理
  743. */
  744. public function actionBaDec() {
  745. // 生成随机码 , 初始化redis
  746. $userName = Info::generateWebUserName('NG',9);
  747. $redis = \Yii::$app->redis;
  748. $post = \Yii::$app->request->post();
  749. if (\Yii::$app->request->isPost) {
  750. // 根据支付方式区分逻辑
  751. $payMethod = \Yii::$app->request->post('payType', '');
  752. if ($payMethod === 'pay_stack') {
  753. $formModel = new BaApproachDeclarationLoopForm();
  754. } else {
  755. unset($post['payType']);
  756. $formModel = new BaDeclarationLoopForm();
  757. }
  758. $formModel->scenario = 'userDec';
  759. $post['province'] = $post['province'] ? :1;
  760. $post['city'] = $post['city'] ? :1;
  761. $post['county'] = $post['county'] ? :1;
  762. // $post['conUserName'] = trim($post['conUserName']);
  763. $post['recUserName'] = trim($post['recUserName']);
  764. $post['cityName'] = trim($post['cityName']);
  765. $post['lgaName'] = trim($post['lgaName']);
  766. // 针对于会员编号的判断
  767. $insertUserName = strtoupper($post['insertUserName']);
  768. $getRedisUserName = $redis->get('key_' . $insertUserName);
  769. if (!$getRedisUserName){
  770. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  771. }
  772. if ($insertUserName != $getRedisUserName){
  773. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  774. }
  775. $post['insertUserName'] = $insertUserName;
  776. $post['type'] = BaDeclarationForm::TYPE_ZC;
  777. $allData['data'][] = $post;
  778. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  779. return static::notice($result); // 报单成功
  780. } else {
  781. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  782. }
  783. }
  784. // 只查询普通商品
  785. $allGoods = ShopGoods::find()->where("ID='375895243322691584'")->orderBy('SORT ASC')->asArray()->all();
  786. if (!$userName) {
  787. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  788. }
  789. //随机码保存在redis中方便进行比对
  790. $redis->setex('key_'.$userName , 3600 , $userName);
  791. // 会员账户
  792. $userBalance = [
  793. 'cash' => 0,
  794. // 'tourism_points' => 0,
  795. // 'garage_points' => 0,
  796. // 'villa_points' => 0,
  797. ];
  798. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  799. if ($userCash) {
  800. $userBalance['cash'] = $userCash['CASH'];
  801. }
  802. return static::notice([
  803. 'allGoods' => $allGoods,
  804. 'userName' => $userName,
  805. 'payList' => ShopGoods::payTypes(),
  806. 'sellType' => ShopGoods::getCategoryType(),
  807. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  808. 'userBalance' => $userBalance,
  809. ]);
  810. }
  811. /**
  812. * BA会员信息
  813. * @return mixed
  814. * @throws \yii\web\HttpException
  815. */
  816. public function actionBaUserInfo()
  817. {
  818. $userName = \Yii::$app->request->get('userName');
  819. $userId = Info::getBaUserIdByUserName($userName);
  820. $userInfo['REAL_NAME'] = '';
  821. $user = BaUser::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  822. $uInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'REC_UID');
  823. if($user){
  824. $rec_user = UserInfo::findOneAsArray('USER_ID=:USER_ID',[':USER_ID' => $uInfo['REC_UID']], 'USER_ID, USER_NAME');
  825. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  826. $userInfo['REC_USER_ID'] = $rec_user['USER_ID'];
  827. $userInfo['REC_USER_NAME'] = $rec_user['USER_NAME'];
  828. return static::notice($userInfo);
  829. }else{
  830. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  831. }
  832. }
  833. }