UserController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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\DeclarationPackage;
  13. use common\models\forms\DeclarationForm;
  14. use common\models\forms\DeclarationLoopForm;
  15. use common\models\forms\UploadForm;
  16. use common\models\forms\UserBindForm;
  17. use common\models\forms\UserForm;
  18. use common\models\OpenBank;
  19. use common\models\ReceiveAddress;
  20. use common\models\Region;
  21. use common\models\ShopGoods;
  22. use common\models\User;
  23. use common\models\UserBind;
  24. use common\models\UserInfo;
  25. use common\models\UserNetwork;
  26. use yii\web\UploadedFile;
  27. class UserController extends BaseController {
  28. public $modelClass = UserInfo::class;
  29. /**
  30. * 会员资料
  31. * @return mixed
  32. * @throws \yii\web\HttpException
  33. */
  34. public function actionIndex() {
  35. $allNation = \Yii::$app->params['nation'];
  36. $allOpenBank = OpenBank::findAllAsArray('STATUS=1');
  37. $data['allNation'] = $allNation;
  38. $data['allOpenBank'] = $allOpenBank;
  39. $data['userInfo'] = User::getEnCodeInfo(\Yii::$app->user->id);
  40. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  41. return static::notice($data);
  42. }
  43. /**
  44. * 编辑会员资料
  45. * @return mixed
  46. * @throws \yii\web\HttpException
  47. */
  48. public function actionEdit() {
  49. if(\Yii::$app->request->isPost){
  50. $form = new UserForm();
  51. $post = \Yii::$app->request->post();
  52. $form->scenario = 'modifyProfile';
  53. if($form->load($post, '') && $result = $form->modifyProfile()){
  54. return static::notice('个人资料修改成功');
  55. } else {
  56. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  57. }
  58. }
  59. return static::notice('非法访问', 400);
  60. }
  61. /**
  62. * 修改登录密码
  63. */
  64. public function actionPassword(){
  65. if(\Yii::$app->request->isPost){
  66. $form = new UserForm();
  67. $form->scenario = 'modifyPassword';
  68. $post = \Yii::$app->request->post();
  69. if($form->load($post, '') && $result = $form->modifyPassword()){
  70. return static::notice('密码修改成功');
  71. } else {
  72. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  73. }
  74. }
  75. return static::notice('非法访问', 400);
  76. }
  77. /**
  78. * 修改支付密码
  79. */
  80. public function actionPayPassword(){
  81. if(\Yii::$app->request->isPost){
  82. $form = new UserForm();
  83. $form->scenario = 'modifyPasswordPay';
  84. $post = \Yii::$app->request->post();
  85. $form->userId = \Yii::$app->user->id;
  86. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  87. return static::notice('支付密码修改成功');
  88. } else {
  89. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  90. }
  91. }
  92. return static::notice('非法访问', 400);
  93. }
  94. /**
  95. * 直推会员列表
  96. * @return mixed
  97. * @throws \yii\web\HttpException
  98. */
  99. public function actionRecUser() {
  100. $allData = UserInfo::lists('AND REC_UID=:REC_UID', [':REC_UID' => \Yii::$app->user->id], ['useSlaves' => true, 'select'=>'USER_ID,CREATED_AT']);
  101. foreach ($allData['list'] as $key => $data) {
  102. $userBaseInfo = User::getEnCodeInfo($data['USER_ID']);
  103. $userBaseInfo['NATION'] = \Yii::$app->params['nation'][$userBaseInfo['NATION']]['name'] ?? '';
  104. $allData['list'][$key]['BASE_INFO'] = $userBaseInfo;
  105. }
  106. return static::notice($allData);
  107. }
  108. /**
  109. * 上传身份证
  110. * @return mixed
  111. * @throws \yii\base\Exception
  112. * @throws \yii\web\HttpException
  113. */
  114. public function actionIdCard() {
  115. if (\Yii::$app->request->isPost) {
  116. $formModel = new UploadForm();
  117. $formModel->scenario = 'idCardFront';
  118. $formModel->file = UploadedFile::getInstanceByName('file');
  119. //$formModel->token = \Yii::$app->request->post('uploadToken');
  120. $formModel->token = \Yii::$app->request->request('uploadToken');;
  121. if ($formModel->file && $formModel->upload()) {
  122. return static::notice('上传成功');
  123. } else {
  124. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  125. }
  126. }
  127. // 查看该用户是否已经上传过身份证
  128. $oneData = User::find()->select('ID_IMAGE')->where('ID=:ID', [':ID' => \Yii::$app->user->id])->asArray()->one();
  129. if ($oneData['ID_IMAGE']) {
  130. return static::notice($oneData);
  131. } else {
  132. $token = Cache::setUploadToken();
  133. return static::notice($token);
  134. }
  135. }
  136. /**
  137. * 点位绑定
  138. * @return mixed
  139. * @throws \yii\base\Exception
  140. * @throws \yii\web\HttpException
  141. */
  142. public function actionBind() {
  143. $userBind = UserBind::findOneAsArray('USER_ID=:USER_ID AND IS_DEL=0', [':USER_ID' => \Yii::$app->user->id]);
  144. $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');
  145. foreach ($allData['list'] as $key => $value) {
  146. $baseInfo = Info::baseInfoZh($value['USER_ID']);
  147. if ($baseInfo['STATUS'] != 1) {
  148. unset($allData['list'][$key]);
  149. continue;
  150. }
  151. $allData['list'][$key]['USER_NAME'] = $baseInfo['USER_NAME'];
  152. $allData['list'][$key]['REAL_NAME'] = $baseInfo['REAL_NAME'];
  153. $allData['list'][$key]['BANK_PROVINCE_NAME'] = $baseInfo['BANK_PROVINCE_NAME'];
  154. $allData['list'][$key]['BANK_CITY_NAME'] = $baseInfo['BANK_CITY_NAME'];
  155. $allData['list'][$key]['BANK_COUNTY_NAME'] = $baseInfo['BANK_COUNTY_NAME'];
  156. $allData['list'][$key]['OPEN_BANK_NAME'] = $baseInfo['OPEN_BANK_NAME'];
  157. $allData['list'][$key]['BANK_NO'] = $baseInfo['BANK_NO'];
  158. $allData['list'][$key]['MAIN_USER_NAME'] =Info::getUserNameByUserId($value['MAIN_UID']);
  159. }
  160. $allData['list'] = array_values($allData['list']);
  161. return static::notice($allData);
  162. }
  163. /**
  164. * 编辑点位绑定
  165. * @return mixed
  166. * @throws \yii\web\HttpException
  167. */
  168. public function actionBindEdit(){
  169. $id = \Yii::$app->request->get('id');
  170. if(\Yii::$app->request->isPost) {
  171. return parent::edit(UserBindForm::class, '修改主点位成功', 'frontEdit', ['frontEdit'], null, function($form, $result){
  172. //log
  173. });
  174. }
  175. // 获得当前会员的用户名等信息
  176. $userBind = UserBind::findOneAsArray('ID=:ID AND IS_DEL=0', [':ID' => $id]);
  177. $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');
  178. foreach($userBinds as $key=>$value){
  179. $status = Info::getStatusByUserId($value['USER_ID']);
  180. if ($status != 1) {
  181. unset($userBinds[$key]);
  182. continue;
  183. }
  184. $userBinds[$key]['USER_NAME'] = Info::getUserNameByUserId($value['USER_ID']);
  185. }
  186. $userBinds = array_values($userBinds);
  187. return static::notice(['userBinds' => $userBinds,'mainUid'=>$userBind['MAIN_UID']]);
  188. }
  189. /**
  190. * 报单管理
  191. */
  192. public function actionDec() {
  193. // 生成随机码 , 初始化redis
  194. $userName = Info::generateWebUserName('CQ',9);
  195. $redis = \Yii::$app->redis;
  196. if (\Yii::$app->request->isPost) {
  197. $formModel = new DeclarationLoopForm();
  198. $formModel->scenario = 'userDec';
  199. $post = \Yii::$app->request->post();
  200. $post['province'] = $post['province'] ? :1;
  201. $post['city'] = $post['city'] ? :1;
  202. $post['county'] = $post['county'] ? :1;
  203. // 针对于会员编号的判断
  204. $insertUserName = strtoupper($post['insertUserName']);
  205. $getRedisUserName = $redis->get('key_'.$insertUserName);
  206. if (!$getRedisUserName){
  207. return static::notice('会员编号过期',400);
  208. }
  209. if ($insertUserName != $getRedisUserName){
  210. return static::notice('会员编号不符合',400);
  211. }
  212. $post['insertUserName'] = $insertUserName;
  213. $post['type'] = DeclarationForm::TYPE_ZC;
  214. $allData['data'][] = $post;
  215. if ($formModel->load($allData, '') && $formModel->add()) {
  216. return static::notice('报单成功');
  217. } else {
  218. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  219. }
  220. }
  221. //所有报单套餐
  222. $allDecPackage = DeclarationPackage::getAllData();
  223. $decLevels = Cache::getDecLevelConfig();
  224. foreach ($allDecPackage as $k=>$v){
  225. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  226. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  227. }
  228. //所有自选商品
  229. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  230. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  231. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  232. $query_condition= " AND (1<>1";
  233. if(!$isDecReg || ($isDecReg && $isDec==1)){
  234. $query_condition = " AND (FIND_IN_SET(1,GIFT_TYPE)>0";
  235. }
  236. if($isStudio==1){
  237. $query_condition.= " OR FIND_IN_SET(3,GIFT_TYPE)>0";
  238. }
  239. $query_condition.= ")";
  240. $allGoods = ShopGoods::find()->where("STATUS=1 ".$query_condition)->orderBy('SORT ASC')->asArray()->all();
  241. //$allGoods = ShopGoods::findAllAsArray('STATUS=1');
  242. // 所有开户行
  243. $allOpenBank = OpenBank::find()->where('STATUS=1')->orderBy('LIST_ORDER ASC')->asArray()->all();
  244. if (!$userName) {
  245. return static::notice('会员编号生成失败', 400);
  246. }
  247. //随机码保存在redis中方便进行比对
  248. $msg = $redis->setex('key_'.$userName , 1800 , $userName);
  249. return static::notice(['allDecPackage' => $allDecPackage,'allGoods' => $allGoods,'allOpenBank' => $allOpenBank, 'userName' => $userName]);
  250. }
  251. /**
  252. * 报单级别套餐
  253. */
  254. public function actionDecPackage() {
  255. $decLv = \Yii::$app->request->get('id');
  256. //所有报单级别套餐
  257. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  258. return static::notice(['allDecPackage' => $allDecPackage]);
  259. }
  260. /**
  261. * 会员信息查询
  262. * @return mixed
  263. * @throws \yii\web\HttpException
  264. */
  265. public function actionFullInfo()
  266. {
  267. $userName = \Yii::$app->request->get('userName');
  268. $userId = Info::getUserIdByUserName($userName);
  269. $userInfo['REAL_NAME'] = '';
  270. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  271. if($user){
  272. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  273. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  274. $isLocation = [1 => '左-', 2 => '中-', 3 => '右-'];
  275. if($allChildUser) {
  276. foreach ($allChildUser as $child) {
  277. $isLocation[$child['RELATIVE_LOCATION']].= '满';
  278. }
  279. }
  280. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  281. return static::notice($userInfo);
  282. }else{
  283. return static::notice('会员编号不存在', 400);
  284. }
  285. }
  286. /**
  287. * 复消会员信息查询
  288. * @return mixed
  289. * @throws \yii\web\HttpException
  290. */
  291. public function actionUserBaseInfo()
  292. {
  293. $userName = \Yii::$app->request->get('userName');
  294. $userId = Info::getUserIdByUserName($userName);
  295. if($userId){
  296. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  297. if($allAddress) {
  298. foreach ($allAddress as $key => $row) {
  299. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  300. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  301. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  302. }
  303. }
  304. $userInfo = Info::baseInfoWithNet($userId);
  305. // $decLevelConfig = Cache::getDecLevelConfig();
  306. // $empLevelConfig = Cache::getEmpLevelConfig();
  307. $arr = [
  308. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  309. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  310. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  311. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  312. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  313. 'allAddress'=>$allAddress
  314. ];
  315. return static::notice($arr);
  316. }else{
  317. return static::notice('复消会员编号不存在', 400);
  318. }
  319. }
  320. }