UserController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. if (\Yii::$app->request->isPost) {
  194. $formModel = new DeclarationLoopForm();
  195. $formModel->scenario = 'userDec';
  196. $post = \Yii::$app->request->post();
  197. $post['insertUserName'] = strtoupper($post['insertUserName']);
  198. $post['type'] = DeclarationForm::TYPE_ZC;
  199. $allData['data'][] = $post;
  200. if ($formModel->load($allData, '') && $formModel->add()) {
  201. return static::notice('报单成功');
  202. } else {
  203. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  204. }
  205. }
  206. //所有报单套餐
  207. $allDecPackage = DeclarationPackage::getAllData();
  208. $decLevels = Cache::getDecLevelConfig();
  209. foreach ($allDecPackage as $k=>$v){
  210. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  211. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  212. }
  213. //所有自选商品
  214. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  215. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  216. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  217. $query_condition= " AND (1<>1";
  218. if(!$isDecReg || ($isDecReg && $isDec==1)){
  219. $query_condition = " AND (FIND_IN_SET(1,GIFT_TYPE)>0";
  220. }
  221. if($isStudio==1){
  222. $query_condition.= " OR FIND_IN_SET(3,GIFT_TYPE)>0";
  223. }
  224. $query_condition.= ")";
  225. $allGoods = ShopGoods::find()->where("STATUS=1 ".$query_condition)->orderBy('SORT ASC')->asArray()->all();
  226. //$allGoods = ShopGoods::findAllAsArray('STATUS=1');
  227. // 所有开户行
  228. $allOpenBank = OpenBank::find()->where('STATUS=1')->orderBy('LIST_ORDER ASC')->asArray()->all();
  229. if (!$userName = Info::generateUserName('LA',9)) {
  230. return static::notice('会员编号生成失败', 400);
  231. }
  232. return static::notice(['allDecPackage' => $allDecPackage,'allGoods' => $allGoods,'allOpenBank' => $allOpenBank, 'userName' => $userName]);
  233. }
  234. /**
  235. * 报单级别套餐
  236. */
  237. public function actionDecPackage() {
  238. $decLv = \Yii::$app->request->get('id');
  239. //所有报单级别套餐
  240. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  241. return static::notice(['allDecPackage' => $allDecPackage]);
  242. }
  243. /**
  244. * 会员信息查询
  245. * @return mixed
  246. * @throws \yii\web\HttpException
  247. */
  248. public function actionFullInfo()
  249. {
  250. $userName = \Yii::$app->request->get('userName');
  251. $userId = Info::getUserIdByUserName($userName);
  252. $userInfo['REAL_NAME'] = '';
  253. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  254. if($user){
  255. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  256. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  257. $isLocation = [1 => '左-', 2 => '中-', 3 => '右-'];
  258. if($allChildUser) {
  259. foreach ($allChildUser as $child) {
  260. $isLocation[$child['RELATIVE_LOCATION']].= '满';
  261. }
  262. }
  263. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  264. return static::notice($userInfo);
  265. }else{
  266. return static::notice('会员编号不存在', 400);
  267. }
  268. }
  269. /**
  270. * 复消会员信息查询
  271. * @return mixed
  272. * @throws \yii\web\HttpException
  273. */
  274. public function actionUserBaseInfo()
  275. {
  276. $userName = \Yii::$app->request->get('userName');
  277. $userId = Info::getUserIdByUserName($userName);
  278. if($userId){
  279. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  280. if($allAddress) {
  281. foreach ($allAddress as $key => $row) {
  282. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  283. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  284. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  285. }
  286. }
  287. $userInfo = Info::baseInfoWithNet($userId);
  288. // $decLevelConfig = Cache::getDecLevelConfig();
  289. // $empLevelConfig = Cache::getEmpLevelConfig();
  290. $arr = [
  291. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  292. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  293. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  294. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  295. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  296. 'allAddress'=>$allAddress
  297. ];
  298. return static::notice($arr);
  299. }else{
  300. return static::notice('复消会员编号不存在', 400);
  301. }
  302. }
  303. }