UserController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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\user\Info;
  12. use common\models\Config;
  13. use common\models\DeclarationLevel;
  14. use common\models\DeclarationPackage;
  15. use common\models\forms\DeclarationForm;
  16. use common\models\forms\DeclarationLoopForm;
  17. use common\models\forms\UploadForm;
  18. use common\models\forms\UserBindForm;
  19. use common\models\forms\UserForm;
  20. use common\models\OpenBank;
  21. use common\models\ReceiveAddress;
  22. use common\models\Region;
  23. use common\models\ShopGoods;
  24. use common\models\User;
  25. use common\models\UserBind;
  26. use common\models\UserInfo;
  27. use common\models\UserNetwork;
  28. use yii\web\UploadedFile;
  29. class UserController extends BaseController {
  30. public $modelClass = UserInfo::class;
  31. /**
  32. * 会员资料
  33. * @return mixed
  34. * @throws \yii\web\HttpException
  35. */
  36. public function actionIndex() {
  37. $allNation = \Yii::$app->params['nation'];
  38. $allOpenBank = OpenBank::findAllAsArray('STATUS=1');
  39. $data['allNation'] = $allNation;
  40. $data['allOpenBank'] = $allOpenBank;
  41. $data['userInfo'] = User::getEnCodeInfo(\Yii::$app->user->id);
  42. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  43. return static::notice($data);
  44. }
  45. /**
  46. * 编辑会员资料
  47. * @return mixed
  48. * @throws \yii\web\HttpException
  49. */
  50. public function actionEdit() {
  51. if(\Yii::$app->request->isPost){
  52. $form = new UserForm();
  53. $post = \Yii::$app->request->post();
  54. $form->scenario = 'modifyProfile';
  55. if($form->load($post, '') && $result = $form->modifyProfile()){
  56. return static::notice('个人资料修改成功');
  57. } else {
  58. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  59. }
  60. }
  61. return static::notice('非法访问', 400);
  62. }
  63. /**
  64. * 修改登录密码
  65. */
  66. public function actionPassword(){
  67. if(\Yii::$app->request->isPost){
  68. $form = new UserForm();
  69. $form->scenario = 'modifyPassword';
  70. $post = \Yii::$app->request->post();
  71. if($form->load($post, '') && $result = $form->modifyPassword()){
  72. return static::notice('密码修改成功');
  73. } else {
  74. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  75. }
  76. }
  77. return static::notice('非法访问', 400);
  78. }
  79. /**
  80. * 修改支付密码
  81. */
  82. public function actionPayPassword(){
  83. if(\Yii::$app->request->isPost){
  84. $form = new UserForm();
  85. $form->scenario = 'modifyPasswordPay';
  86. $post = \Yii::$app->request->post();
  87. $form->userId = \Yii::$app->user->id;
  88. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  89. return static::notice('支付密码修改成功');
  90. } else {
  91. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  92. }
  93. }
  94. return static::notice('非法访问', 400);
  95. }
  96. /**
  97. * 直推会员列表
  98. * @return mixed
  99. * @throws \yii\web\HttpException
  100. */
  101. public function actionRecUser() {
  102. $allData = UserInfo::lists('AND REC_UID=:REC_UID', [':REC_UID' => \Yii::$app->user->id], ['useSlaves' => true, 'select'=>'USER_ID,CREATED_AT']);
  103. foreach ($allData['list'] as $key => $data) {
  104. $userBaseInfo = User::getEnCodeInfo($data['USER_ID']);
  105. $userBaseInfo['NATION'] = \Yii::$app->params['nation'][$userBaseInfo['NATION']]['name'] ?? '';
  106. $allData['list'][$key]['BASE_INFO'] = $userBaseInfo;
  107. }
  108. return static::notice($allData);
  109. }
  110. /**
  111. * 上传身份证
  112. * @return mixed
  113. * @throws \yii\base\Exception
  114. * @throws \yii\web\HttpException
  115. */
  116. public function actionIdCard() {
  117. if (\Yii::$app->request->isPost) {
  118. $formModel = new UploadForm();
  119. $formModel->scenario = 'idCardFront';
  120. $formModel->file = UploadedFile::getInstanceByName('file');
  121. //$formModel->token = \Yii::$app->request->post('uploadToken');
  122. $formModel->token = \Yii::$app->request->request('uploadToken');
  123. if ($formModel->file && $formModel->upload()) {
  124. return static::notice('上传成功');
  125. } else {
  126. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  127. }
  128. }
  129. // 查看该用户是否已经上传过身份证
  130. $oneData = User::find()->select('ID_IMAGE')->where('ID=:ID', [':ID' => \Yii::$app->user->id])->asArray()->one();
  131. if ($oneData['ID_IMAGE']) {
  132. return static::notice($oneData);
  133. } else {
  134. $token = Cache::setUploadToken();
  135. return static::notice($token);
  136. }
  137. }
  138. /**
  139. * 点位绑定
  140. * @return mixed
  141. * @throws \yii\base\Exception
  142. * @throws \yii\web\HttpException
  143. */
  144. public function actionBind() {
  145. $userBind = UserBind::findOneAsArray('USER_ID=:USER_ID AND IS_DEL=0', [':USER_ID' => \Yii::$app->user->id]);
  146. $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');
  147. foreach ($allData['list'] as $key => $value) {
  148. $baseInfo = Info::baseInfoZh($value['USER_ID']);
  149. if ($baseInfo['STATUS'] != 1) {
  150. unset($allData['list'][$key]);
  151. continue;
  152. }
  153. $allData['list'][$key]['USER_NAME'] = $baseInfo['USER_NAME'];
  154. $allData['list'][$key]['REAL_NAME'] = $baseInfo['REAL_NAME'];
  155. $allData['list'][$key]['BANK_PROVINCE_NAME'] = $baseInfo['BANK_PROVINCE_NAME'];
  156. $allData['list'][$key]['BANK_CITY_NAME'] = $baseInfo['BANK_CITY_NAME'];
  157. $allData['list'][$key]['BANK_COUNTY_NAME'] = $baseInfo['BANK_COUNTY_NAME'];
  158. $allData['list'][$key]['OPEN_BANK_NAME'] = $baseInfo['OPEN_BANK_NAME'];
  159. $allData['list'][$key]['BANK_NO'] = $baseInfo['BANK_NO'];
  160. $allData['list'][$key]['MAIN_USER_NAME'] =Info::getUserNameByUserId($value['MAIN_UID']);
  161. }
  162. $allData['list'] = array_values($allData['list']);
  163. return static::notice($allData);
  164. }
  165. /**
  166. * 编辑点位绑定
  167. * @return mixed
  168. * @throws \yii\web\HttpException
  169. */
  170. public function actionBindEdit(){
  171. $id = \Yii::$app->request->get('id');
  172. if(\Yii::$app->request->isPost) {
  173. return parent::edit(UserBindForm::class, '修改主点位成功', 'frontEdit', ['frontEdit'], null, function($form, $result){
  174. //log
  175. });
  176. }
  177. // 获得当前会员的用户名等信息
  178. $userBind = UserBind::findOneAsArray('ID=:ID AND IS_DEL=0', [':ID' => $id]);
  179. $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');
  180. foreach($userBinds as $key=>$value){
  181. $status = Info::getStatusByUserId($value['USER_ID']);
  182. if ($status != 1) {
  183. unset($userBinds[$key]);
  184. continue;
  185. }
  186. $userBinds[$key]['USER_NAME'] = Info::getUserNameByUserId($value['USER_ID']);
  187. }
  188. $userBinds = array_values($userBinds);
  189. return static::notice(['userBinds' => $userBinds,'mainUid'=>$userBind['MAIN_UID']]);
  190. }
  191. // 会员升级,通过会员的编号,获取会员信息
  192. public function actionUpgradeInfo() {
  193. $userNumber = \Yii::$app->request->request('userName');
  194. $baseInfo = Info::baseInfoZhByUserName($userNumber);
  195. // 1. 如果是最高级别,则只显示用户基本信息
  196. // 2. 如果不是最高级别,如果用户累计报单数据是0, 或者用户累计报单业绩不符合级别信息,则提示 请联系客服核对业绩
  197. $userId = $baseInfo['ID'];
  198. $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
  199. // 获取系统中的DEC 报单级别配置
  200. $decConfig = Cache::getDecLevelConfig();
  201. $decInfo = $decConfig[$userDecId]; // 会员的级别具体信息
  202. $maxPerfInfo = DeclarationLevel::getMaxDecPref();
  203. $maxPerf = $maxPerfInfo['PERF']; // 级别配置中最高级别业绩
  204. $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
  205. $observe = Config::getConfigByType('observe'); // 获取观察期配置信息
  206. $observeLimit = $observe['observePeriodLimit']['value']; // 月份限制
  207. $isObserve = User::checkIsObserve($baseInfo['CREATED_AT'], $observeLimit); // 判断用户是否再观察期中
  208. // 如果用户已经是最高级别,则只展示用户信息
  209. $userInfo = [
  210. 'DEC_NAME' => $baseInfo['DEC_LV_NAME'], // 用户级别中文
  211. 'DEC_ID' => $userDecId, // 用户级别id
  212. 'REAL_NAME' => $baseInfo['REAL_NAME'], // 真实姓名
  213. 'ADD_AT' => date('Y-m-d', $baseInfo['CREATED_AT']), // 加入时间
  214. 'IS_OBSERVE' => 1, // 是否是观察期
  215. ];
  216. if ($maxDecId == $userDecId) {
  217. echo 11;exit;
  218. }
  219. return static::notice(['baseInfo' => $baseInfo]);
  220. }
  221. // 会员升级管理
  222. public function actionUpgrade() {
  223. // 生成随机码 , 初始化redis
  224. $userName = Info::generateWebUserName('CQ',9);
  225. $redis = \Yii::$app->redis;
  226. if (\Yii::$app->request->isPost) {
  227. $formModel = new DeclarationLoopForm();
  228. $formModel->scenario = 'userDec';
  229. $post = \Yii::$app->request->post();
  230. // 针对于会员编号的判断
  231. $insertUserName = strtoupper($post['insertUserName']);
  232. $getRedisUserName = $redis->get('key_'.$insertUserName);
  233. if (!$getRedisUserName){
  234. return static::notice('会员编号过期',400);
  235. }
  236. if ($insertUserName != $getRedisUserName){
  237. return static::notice('会员编号不符合',400);
  238. }
  239. $post['insertUserName'] = $insertUserName;
  240. $post['type'] = DeclarationForm::TYPE_ZC;
  241. $allData['data'][] = $post;
  242. if ($formModel->load($allData, '') && $formModel->add()) {
  243. return static::notice('报单成功');
  244. } else {
  245. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  246. }
  247. }
  248. //所有报单套餐
  249. $allDecPackage = DeclarationPackage::getAllData();
  250. $decLevels = Cache::getDecLevelConfig();
  251. foreach ($allDecPackage as $k=>$v){
  252. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  253. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  254. }
  255. //所有自选商品
  256. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  257. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  258. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  259. $query_condition= " AND (1<>1";
  260. if(!$isDecReg || ($isDecReg && $isDec==1)){
  261. $query_condition = " AND (FIND_IN_SET(1,GIFT_TYPE)>0";
  262. }
  263. if($isStudio==1){
  264. $query_condition.= " OR FIND_IN_SET(3,GIFT_TYPE)>0";
  265. }
  266. $query_condition.= ")";
  267. $allGoods = ShopGoods::find()->where("STATUS=1 ".$query_condition)->orderBy('SORT ASC')->asArray()->all();
  268. //$allGoods = ShopGoods::findAllAsArray('STATUS=1');
  269. // 所有开户行
  270. $allOpenBank = OpenBank::find()->where('STATUS=1')->orderBy('LIST_ORDER ASC')->asArray()->all();
  271. if (!$userName) {
  272. return static::notice('会员编号生成失败', 400);
  273. }
  274. //随机码保存在redis中方便进行比对
  275. $msg = $redis->setex('key_'.$userName , 1800 , $userName);
  276. return static::notice(['allDecPackage' => $allDecPackage,'allGoods' => $allGoods,'allOpenBank' => $allOpenBank, 'userName' => $userName]);
  277. }
  278. /**
  279. * 报单管理
  280. */
  281. public function actionDec() {
  282. // 生成随机码 , 初始化redis
  283. $userName = Info::generateWebUserName('CQ',9);
  284. $redis = \Yii::$app->redis;
  285. if (\Yii::$app->request->isPost) {
  286. $formModel = new DeclarationLoopForm();
  287. $formModel->scenario = 'userDec';
  288. $post = \Yii::$app->request->post();
  289. // 针对于会员编号的判断
  290. $insertUserName = strtoupper($post['insertUserName']);
  291. $getRedisUserName = $redis->get('key_'.$insertUserName);
  292. if (!$getRedisUserName){
  293. return static::notice('会员编号过期',400);
  294. }
  295. if ($insertUserName != $getRedisUserName){
  296. return static::notice('会员编号不符合',400);
  297. }
  298. $post['insertUserName'] = $insertUserName;
  299. $post['type'] = DeclarationForm::TYPE_ZC;
  300. $allData['data'][] = $post;
  301. if ($formModel->load($allData, '') && $formModel->add()) {
  302. return static::notice('报单成功');
  303. } else {
  304. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  305. }
  306. }
  307. //所有报单套餐
  308. $allDecPackage = DeclarationPackage::getAllData();
  309. $decLevels = Cache::getDecLevelConfig();
  310. foreach ($allDecPackage as $k=>$v){
  311. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  312. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  313. }
  314. //所有自选商品
  315. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  316. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  317. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  318. $query_condition= " AND (1<>1";
  319. if(!$isDecReg || ($isDecReg && $isDec==1)){
  320. $query_condition = " AND (FIND_IN_SET(1,GIFT_TYPE)>0";
  321. }
  322. if($isStudio==1){
  323. $query_condition.= " OR FIND_IN_SET(3,GIFT_TYPE)>0";
  324. }
  325. $query_condition.= ")";
  326. $allGoods = ShopGoods::find()->where("STATUS=1 ".$query_condition)->orderBy('SORT ASC')->asArray()->all();
  327. //$allGoods = ShopGoods::findAllAsArray('STATUS=1');
  328. // 所有开户行
  329. $allOpenBank = OpenBank::find()->where('STATUS=1')->orderBy('LIST_ORDER ASC')->asArray()->all();
  330. if (!$userName) {
  331. return static::notice('会员编号生成失败', 400);
  332. }
  333. //随机码保存在redis中方便进行比对
  334. $msg = $redis->setex('key_'.$userName , 1800 , $userName);
  335. return static::notice(['allDecPackage' => $allDecPackage,'allGoods' => $allGoods,'allOpenBank' => $allOpenBank, 'userName' => $userName]);
  336. }
  337. /**
  338. * 报单级别套餐
  339. */
  340. public function actionDecPackage() {
  341. $decLv = \Yii::$app->request->get('id');
  342. //所有报单级别套餐
  343. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  344. return static::notice(['allDecPackage' => $allDecPackage]);
  345. }
  346. /**
  347. * 会员信息查询
  348. * @return mixed
  349. * @throws \yii\web\HttpException
  350. */
  351. public function actionFullInfo()
  352. {
  353. $userName = \Yii::$app->request->get('userName');
  354. $userId = Info::getUserIdByUserName($userName);
  355. $userInfo['REAL_NAME'] = '';
  356. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  357. if($user){
  358. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  359. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  360. $isLocation = [1 => '左-', 2 => '中-', 3 => '右-'];
  361. if($allChildUser) {
  362. foreach ($allChildUser as $child) {
  363. $isLocation[$child['RELATIVE_LOCATION']].= '满';
  364. }
  365. }
  366. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  367. return static::notice($userInfo);
  368. }else{
  369. return static::notice('会员编号不存在', 400);
  370. }
  371. }
  372. /**
  373. * 复消会员信息查询
  374. * @return mixed
  375. * @throws \yii\web\HttpException
  376. */
  377. public function actionUserBaseInfo()
  378. {
  379. $userName = \Yii::$app->request->get('userName');
  380. $userId = Info::getUserIdByUserName($userName);
  381. if($userId){
  382. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  383. if($allAddress) {
  384. foreach ($allAddress as $key => $row) {
  385. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  386. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  387. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  388. }
  389. }
  390. $userInfo = Info::baseInfoWithNet($userId);
  391. // $decLevelConfig = Cache::getDecLevelConfig();
  392. // $empLevelConfig = Cache::getEmpLevelConfig();
  393. $arr = [
  394. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  395. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  396. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  397. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  398. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  399. 'allAddress'=>$allAddress
  400. ];
  401. return static::notice($arr);
  402. }else{
  403. return static::notice('复消会员编号不存在', 400);
  404. }
  405. }
  406. }