my.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. (function (app) {
  2. app.controller('myCtrl', ["$scope","$ionicTabsDelegate", "$state", "$http", "storage", "myService", "common","userService", "config", "msg"
  3. , function ($scope,$ionicTabsDelegate, $state, $http, storage, myService, common,userService, config, msg) {
  4. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  5. $ionicTabsDelegate.showBar(true);
  6. myService.myInfo().then(function(result){
  7. $scope.user = result.data.data
  8. });
  9. $scope.showWithdraw = true;
  10. userService.isTest().then(function(res){
  11. if(res.data.data){
  12. $scope.showWithdraw = true;
  13. }
  14. else{
  15. $scope.showWithdraw = false;
  16. }
  17. })
  18. });
  19. $scope.setAvator = function () {
  20. common.setAvator().then(function (result) {
  21. var response = JSON.parse(result.response);
  22. console.log(response.data.file);
  23. $scope.user.avatar = config.imgServer + response.data.file;
  24. });
  25. };
  26. }]);
  27. app.controller('profileCtrl', ["$scope","$ionicTabsDelegate","$state","$filter", "storage", "myService", "msg", "config", "common"
  28. , function ($scope, $ionicTabsDelegate, $state, $filter, storage, myService, msg, config, common) {
  29. $scope.$on('$ionicView.beforeEnter', function () {
  30. $ionicTabsDelegate.showBar(false);
  31. msg.loading();
  32. myService.myInfo().then(function(result){
  33. $scope.vm = result.data.data;
  34. console.log($scope.vm.avatar);
  35. $scope.vm.sex = $scope.vm.sex+'';
  36. $scope.vm.emotion = $scope.vm.emotion+'';
  37. if($scope.vm.birthday){
  38. var arr1 = $scope.vm.birthday.split("-");
  39. $scope.vm.birthday1 = new Date(arr1[0],parseInt(arr1[1])-1,arr1[2]);
  40. }
  41. msg.hide();
  42. },function(error){
  43. msg.hide();
  44. // msg.error(error.data.message);
  45. })
  46. });
  47. $scope.setAvator = function () {
  48. common.setAvator().then(function (result) {
  49. var response = JSON.parse(result.response);
  50. $scope.vm.avatar = config.imgServer + response.data.file;
  51. });
  52. };
  53. //保存个人信息
  54. $scope.vm={
  55. pic:"",
  56. sex:"",
  57. signture:"",
  58. emotion:"",
  59. job:"",
  60. tall:"",
  61. nickname:"",
  62. birthday1:""
  63. };
  64. $scope.saveMaterial = function(){
  65. var data = {
  66. sex:$scope.vm.sex,
  67. signture:$scope.vm.signture,
  68. emotion:$scope.vm.emotion,
  69. work:$scope.vm.work,
  70. height:$scope.vm.height,
  71. city:$scope.vm.city,
  72. nickname:$scope.vm.nickname,
  73. birthday:$scope.vm.birthday1
  74. };
  75. if($scope.vm.birthday1){
  76. data.birthday = $filter('date')($scope.vm.birthday1, "yyyy-MM-dd");
  77. }
  78. if($scope.vm.avatar){
  79. data.pic = $scope.vm.avatar;
  80. }
  81. //msg.loading('提交中...');
  82. msg.loading();
  83. myService.saveMaterial(data).then(function(result){
  84. msg.hide();
  85. msg.success("保存成功!");
  86. $state.go('app.my');
  87. myService.myInfo();
  88. },function(error){
  89. msg.hide();
  90. msg.error(error.data.message);
  91. })
  92. }
  93. }]);
  94. app.controller('settingCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  95. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  96. $scope.$on('$ionicView.beforeEnter', function () {
  97. $ionicTabsDelegate.showBar(false);
  98. });
  99. //退出登陆
  100. $scope.logout = function(){
  101. storage.remove("token");
  102. storage.remove("user");
  103. $state.go("login");
  104. }
  105. }]);
  106. app.controller('aboutMiaoCtrl', ["$scope","$ionicTabsDelegate","$timeout", "$state", "myService", "msg","storage"
  107. , function ($scope,$ionicTabsDelegate,$timeout, $state,myService, msg, storage) {
  108. $scope.$on('$ionicView.beforeEnter', function () {
  109. $scope.aboutMiao();
  110. });
  111. $scope.aboutMiao = function(){
  112. myService.aboutMiao().then(function(result){
  113. $scope.items = result.data.data;
  114. },function(error){
  115. msg.error(error.data.message)
  116. })
  117. };
  118. }]);
  119. app.controller('withdrawCtrl', ["$scope","$ionicTabsDelegate","$ionicHistory","$timeout", "$state", "myService", "msg","storage"
  120. , function ($scope,$ionicTabsDelegate, $ionicHistory,$timeout,$state,myService, msg, storage) {
  121. $scope.vm={
  122. pay:"",
  123. cash:""
  124. };
  125. $scope.$on("$ionicView.enter",function(){
  126. myService.showAccount().then(function(result){
  127. $scope.accountId = result.data.data;
  128. var items = result.data.data;
  129. //if(items.length==0){
  130. // msg.text("请先添加账户");
  131. // $state.go("app.my_account_add");
  132. // return
  133. //}
  134. $scope.pays=[];
  135. angular.forEach(items,function(item){
  136. if(item.bank_name!=null) {
  137. var value=item.bank_name+"(";
  138. var len=item.bank_number.length;
  139. var txt1=item.bank_number.substr(0,len-4).replace(/\d+/g,'**');
  140. var txt2=item.bank_number.substr(len-4,4);
  141. value=value+txt1+txt2+")";
  142. }
  143. else {
  144. value=item.type;
  145. }
  146. $scope.pays.push({id:item.id,value:value});
  147. });
  148. $scope.vm.pay = $scope.pays[0]
  149. },function(error){
  150. msg.error(error.data.message)
  151. })
  152. });
  153. $scope.withdraw = function(){
  154. var data = {
  155. data:{
  156. bank_id:$scope.vm.pay.id,
  157. cash:$scope.vm.cash
  158. }
  159. };
  160. myService.withdraw(data).then(function(result){
  161. msg.text("提现申请已提交");
  162. $timeout(function () {
  163. $ionicHistory.goBack();
  164. },1000);
  165. },function(error){
  166. })
  167. }
  168. }]);
  169. app.controller('payoutCtrl', ["$scope","$ionicTabsDelegate","$timeout","$ionicHistory", "$state", "myService", "msg","storage"
  170. , function ($scope,$ionicTabsDelegate, $timeout, $ionicHistory,$state,myService, msg, storage) {
  171. $scope.vm={
  172. pay:"",
  173. cash:""
  174. };
  175. $scope.$on("$ionicView.enter",function(){
  176. myService.showAccount().then(function(result){
  177. $scope.accountId = result.data.data;
  178. var items = result.data.data;
  179. $scope.pays=[];
  180. angular.forEach(items,function(item){
  181. if(item.bank_name!=null) {
  182. var value=item.bank_name+"(";
  183. var len=item.bank_number.length;
  184. var txt1=item.bank_number.substr(0,len-4).replace(/\d+/g,'**');
  185. var txt2=item.bank_number.substr(len-4,4);
  186. value=value+txt1+txt2+")";
  187. }
  188. else {
  189. value=item.type;
  190. }
  191. $scope.pays.push({id:item.id,value:value});
  192. })
  193. },function(error){
  194. msg.error(error.data.message)
  195. })
  196. });
  197. $scope.withdraw = function(){
  198. var data = {
  199. data:{
  200. bank_id:$scope.vm.pay.id,
  201. cash:$scope.vm.cash
  202. }
  203. };
  204. myService.withdraw(data).then(function(result){
  205. msg.text("提现申请已提交");
  206. $timeout(function () {
  207. $ionicHistory.goBack();
  208. },1000);
  209. },function(error){
  210. })
  211. }
  212. }]);
  213. app.controller('payExplainCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  214. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  215. $scope.$on('$ionicView.beforeEnter', function () {
  216. $scope.payExplain();
  217. });
  218. $scope.payExplain = function(){
  219. myService.payExplain().then(function(result){
  220. $scope.items = result.data.data;
  221. },function(error){
  222. msg.error(error.data.message)
  223. })
  224. };
  225. }]);
  226. app.controller('paySuccessCtrl', ["$scope","$stateParams","$ionicTabsDelegate","$ionicHistory", "$state", "myService", "msg","storage"
  227. , function ($scope,$stateParams,$ionicTabsDelegate,$ionicHistory, $state,myService, msg, storage) {
  228. var item = $stateParams.item;
  229. alert(item.out_trade_no);
  230. $scope.goBack = function(){
  231. $ionicHistory.goBack();
  232. }
  233. }]);
  234. app.controller('contactCtrl', ["$scope","$ionicTabsDelegate","$location", "$ionicHistory","$timeout","$state", "myService", "msg","storage"
  235. , function ($scope,$ionicTabsDelegate,$location,$ionicHistory, $timeout,$state,myService, msg, storage) {
  236. $scope.vm={
  237. content:"",
  238. email:""
  239. };
  240. $scope.contact = function(){
  241. var data={
  242. data:{
  243. content:$scope.vm.content,
  244. email:$scope.vm.email
  245. }
  246. };
  247. myService.contact(data).then(function(result){
  248. msg.text("发送成功");
  249. $timeout(function(){
  250. if($location.path()=='/app/home/contact'){
  251. $ionicHistory.goBack();
  252. }
  253. else{
  254. $state.go("app.my");
  255. }
  256. },1000);
  257. $scope.vm={
  258. content:"",
  259. email:""
  260. }
  261. },function(error){
  262. msg.error(error.data.message);
  263. })
  264. }
  265. }]);
  266. app.controller('attentionCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  267. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  268. $scope.$on('$ionicView.beforeEnter', function () {
  269. $ionicTabsDelegate.showBar(false);
  270. myService.attention().then(function(result){
  271. $scope.users = result.data.data;
  272. },function(error){
  273. })
  274. });
  275. $scope.toMyUserDetail = function (id) {
  276. myService.toMyUserDetail(id).then(function(result){
  277. $scope.items = result.data.data;
  278. $state.go('app.attention_Detail',{id:id,items:$scope.items});
  279. },function(error){
  280. //msg.error(msg.data.error)
  281. })
  282. };
  283. }]);
  284. app.controller('careCtrl', ["$scope","$ionicTabsDelegate",'$ionicModal',"$state", "myService", "msg","storage"
  285. , function ($scope,$ionicTabsDelegate,$ionicModal, $state,myService, msg, storage) {
  286. $scope.$on('$ionicView.beforeEnter', function () {
  287. $ionicTabsDelegate.showBar(false);
  288. myService.careMe().then(function(result){
  289. $scope.users = result.data.data;
  290. },function(error){
  291. })
  292. });
  293. $scope.toMyUserDetail = function (id) {
  294. myService.toMyUserDetail(id).then(function(result){
  295. $scope.items = result.data.data;
  296. $state.go('app.attention_Detail',{id:id,items:$scope.items});
  297. },function(error){
  298. //msg.error(msg.data.error)
  299. })
  300. };
  301. $ionicModal.fromTemplateUrl('my-modal.html', {
  302. scope: $scope,
  303. animation: 'slide-in-up'
  304. }).then(function (modal) {
  305. $scope.modal = modal;
  306. });
  307. //发私信
  308. $scope.vm={
  309. content:"",
  310. comment_id:""
  311. };
  312. $scope.closeModal = function () {
  313. var data = {
  314. content: $scope.vm.content,
  315. to_user_id: $scope.item.id
  316. };
  317. myService.sendLetter(data).then(function (result) {
  318. msg.success('发送成功');
  319. $scope.vm.content = '';
  320. $scope.item = null;
  321. $scope.modal.hide();
  322. }, function (error) {
  323. msg.error('发送失败');
  324. });
  325. };
  326. $scope.hideModal = function(){
  327. $scope.modal.hide();
  328. };
  329. $scope.reply = function (user) {
  330. event.stopPropagation();
  331. $scope.item = user;
  332. $scope.modal.show();
  333. }
  334. }]);
  335. app.controller('blacklistCtrl', ["$scope","$ionicTabsDelegate",'$ionicModal',"$state", "myService", "msg","storage"
  336. , function ($scope,$ionicTabsDelegate,$ionicModal, $state,myService, msg, storage) {
  337. $scope.$on('$ionicView.beforeEnter', function () {
  338. $ionicTabsDelegate.showBar(false);
  339. $scope.users = storage.getObject("blackUsers");
  340. // $scope.reportUser = storage.getObject("reportUser");
  341. });
  342. $scope.cancelReport = function(id){
  343. var reportUser = storage.getObject("reportUser");
  344. var blackUsers = storage.getObject("blackUsers");
  345. for(var i = 0; i < reportUser.length; i++){
  346. if(reportUser[i] == id){
  347. reportUser.splice(i,1);
  348. }
  349. }
  350. for(var j = 0; j < blackUsers.length; j++){
  351. if(blackUsers[j].id == id){
  352. blackUsers.splice(j,1);
  353. }
  354. }
  355. msg.text('已取消');
  356. $scope.users = blackUsers;
  357. storage.setObject('reportUser',reportUser);
  358. storage.setObject('blackUsers',blackUsers);
  359. }
  360. }]);
  361. app.controller('mySupportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  362. , function ($scope,homeService,$stateParams, $state, msg) {
  363. var user_id = $stateParams.user_id;
  364. $scope.$on('$ionicView.beforeEnter',function(){
  365. $scope.toUserDetail(user_id);
  366. });
  367. $scope.toUserDetail = function(user_id){
  368. homeService.toUserDetail(user_id).then(function(result){
  369. $scope.items = result.data.data;
  370. $scope.user = result.data.data.user;
  371. $scope.dreams = $scope.user.sup_dream;
  372. },function(error){
  373. })
  374. };
  375. $scope.toDetail = function(id){
  376. $state.go('app.my_dreamdetail',{id:id});
  377. // $state.go("app.attention_Detail",{user_id:user_id,items:$scope.items})
  378. }
  379. }]);
  380. app.controller('myOldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  381. , function ($scope,homeService,$stateParams, $state, msg) {
  382. var user_id = $stateParams.user_id;
  383. $scope.$on('$ionicView.beforeEnter',function(){
  384. $scope.toUserDetail(user_id);
  385. });
  386. $scope.toUserDetail = function(user_id){
  387. homeService.toUserDetail(user_id).then(function(result){
  388. $scope.items = result.data.data;
  389. $scope.user = result.data.data.user;
  390. $scope.dreams = $scope.user.dreams;
  391. },function(error){
  392. })
  393. };
  394. $scope.toDetail = function(id){
  395. $state.go('app.my_dreamdetail',{id:id});
  396. // $state.go("app.attention_Detail",{user_id:user_id,items:$scope.items})
  397. };
  398. }]);
  399. app.controller('personalLetterCtrl', ["$scope","$ionicTabsDelegate", '$location',"$state", "myService", "msg","storage"
  400. , function ($scope,$ionicTabsDelegate,$location, $state,myService, msg, storage) {
  401. $scope.$on('$ionicView.beforeEnter', function () {
  402. $scope.loaddata(true);
  403. });
  404. $scope.loaddata = function(init){
  405. myService.letter().then(function(result){
  406. $scope.items = result.data.data;
  407. if (init) {
  408. $scope.$broadcast('scroll.refreshComplete');
  409. } else {
  410. $scope.$broadcast('scroll.infiniteScrollComplete');
  411. }
  412. },function(error){
  413. });
  414. }
  415. $scope.toLetter = function(id){
  416. if($location.path()=="/app/home/message/letter"){
  417. console.log($location.path());
  418. $state.go('app.letterDetail')
  419. }
  420. else {
  421. $state.go('app.myLetterDetail')
  422. }
  423. }
  424. }]);
  425. app.controller('letterDetailCtrl', ["$scope","$ionicTabsDelegate",'$stateParams',"$state", "myService", "msg","storage"
  426. , function ($scope,$ionicTabsDelegate,$stateParams, $state,myService, msg, storage) {
  427. var id = $stateParams.id;
  428. $scope.$on('$ionicView.beforeEnter', function () {
  429. myService.letter().then(function(result){
  430. $scope.items = result.data.data;
  431. },function(error){
  432. });
  433. });
  434. }]);
  435. app.controller('rechargeCtrl', ["$scope","$ionicModal","$timeout","$ionicHistory","$ionicTabsDelegate", "$state", "myService","userService", "msg"
  436. , function ($scope,$ionicModal,$timeout, $ionicHistory,$ionicTabsDelegate,$state, myService,userService, msg) {
  437. $scope.$on('$ionicView.beforeEnter', function () {
  438. $scope.showWithdraw = true;
  439. $ionicTabsDelegate.showBar(false);
  440. $scope.vm = {
  441. }
  442. myService.myInfo().then(function(result){
  443. $scope.vm = result.data.data;
  444. $scope.vm.number = '';
  445. $scope.vm.payType = 2;
  446. });
  447. userService.isTest().then(function(res){
  448. if(res.data.data){
  449. $scope.showWithdraw = true;
  450. }
  451. else{
  452. $scope.showWithdraw = false;
  453. }
  454. })
  455. userService.isTest().then(function(res){
  456. if(res.data.data){
  457. Wechat.auth(scope, state, function (response) {
  458. // var response={code:1231};
  459. if(response.code){
  460. msg.loading('登录中...');
  461. userService.wechat_login(response.code).then(function(result){
  462. msg.hide();
  463. if(result.data.data.user){
  464. storage.setObject('user', result.data.data.user);
  465. storage.set('token', result.data.data.token);
  466. $http.defaults.headers.common["Authorization"] = 'Bearer ' + result.data.data.token;
  467. $scope.user=storage.getObject('user');
  468. $state.go('app.home');
  469. if(localStorage['jpush']){
  470. console.log("jpush: " + localStorage['jpush']);
  471. userService.jpush({ jpush: localStorage['jpush']}).then(function (result) {}, function (error) {});
  472. }
  473. }else{
  474. $state.go("loginAccount",{wechat:result.data.data.openid})
  475. }
  476. },function(error){
  477. console.log("loginbywx Failed: " + JSON.stringify(error));
  478. $state.go("loginAccount");
  479. });
  480. }
  481. }, function (error) {
  482. console.log("Failed: " + JSON.stringify(error));
  483. })
  484. }
  485. else{
  486. $state.go("loginAccount",{wechat:'orrk51inhmfmQRXA8VvGEQfow3Es'});
  487. }
  488. })
  489. if($scope.ios.isIOS){
  490. var productIds = ['apple10001','apple102','apple103','apple104']; // <- Add your product Ids here
  491. msg.loading();
  492. // inAppPurchase
  493. // .getProducts(productIds)
  494. // .then(function (products) {
  495. // msg.hide();
  496. // $scope.products = products;
  497. // console.log('products:'+JSON.stringify(products));
  498. // })
  499. // .catch(function (err) {
  500. msg.hide();
  501. // console.log(err);
  502. // });
  503. }
  504. });
  505. $scope.payExplain = function(){
  506. $state.go("app.payExplain")
  507. };
  508. $scope.withdraw = function(){
  509. $state.go("app.withdraw")
  510. };
  511. $scope.testcharge = function(number){
  512. if (!number) {
  513. msg.text('请输入充值金额');
  514. return;
  515. }
  516. myService.testcharge(number,2).then(function (result) {
  517. msg.text("充值成功");
  518. $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
  519. // $timeout(function(){
  520. // $ionicHistory.goBack();
  521. // },500)
  522. });
  523. };
  524. $ionicModal.fromTemplateUrl('paysuccess-modal.html', {
  525. scope: $scope,
  526. animation: 'slide-in-up'
  527. }).then(function(modal) {
  528. $scope.modal = modal;
  529. });
  530. $scope.openModal = function() {
  531. $scope.modal.show();
  532. };
  533. $scope.closeModal = function() {
  534. $scope.modal.hide();
  535. };
  536. //当我们用到模型时,清除它!
  537. $scope.$on('$destroy', function() {
  538. $scope.modal.remove();
  539. });
  540. $scope.ios={
  541. isIOS:ionic.Platform.isIOS(),
  542. productid:'apple100001'
  543. }
  544. //充值
  545. $scope.charge = function(number){
  546. if($scope.ios.isIOS){
  547. if (number<2){
  548. msg.text('请选择充值金额');
  549. return;
  550. }
  551. console.log('购买productid:'+number);
  552. msg.loading();
  553. inAppPurchase
  554. .buy(number)
  555. .then(function (data) {
  556. msg.hide();
  557. console.log('购买then:'+JSON.stringify(data));
  558. return inAppPurchase.consume(data.productType, data.receipt, data.signature);
  559. })
  560. .then(function (data) {
  561. msg.hide();
  562. myService.orderIos(number).then(function (result) {
  563. console.log('服务器端购买成功:'+number);
  564. }, function (erro) {
  565. });
  566. console.log('购买成功:'+number);
  567. msg.success('购买成功');
  568. $ionicHistory.goBack();
  569. })
  570. .catch(function (err) {
  571. msg.hide();
  572. console.log('购买失败:'+JSON.stringify(err));
  573. // alert('购买失败:'+JSON.stringify(err));
  574. });
  575. }else{
  576. if (!number) {
  577. msg.text('请输入充值金额');
  578. return;
  579. }
  580. myService.charge(number,2).then(function (result) {
  581. //todo:result需要返回支付宝或者微信的签名信息
  582. console.log("result: " + JSON.stringify(result));
  583. var payInfo = result.data.data;
  584. var orderID = payInfo.transaction_id
  585. $scope.vm.transaction_id = payInfo.transaction_id;
  586. $scope.vm.price = payInfo.price;
  587. if ($scope.vm.payType == 1) { //支付宝
  588. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  589. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  590. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  591. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  592. //当e.resultStatus为9000时,请去服务端验证支付结果
  593. $scope.clicksub = false;
  594. if (e.resultStatus == '9000') {
  595. alert(orderID);
  596. //支付成功
  597. // $state.go('app.my');
  598. } else {
  599. msg.error("支付失败");
  600. // msg.error("支付失败:" + JSON.stringify(e));
  601. }
  602. }, function error(e) {
  603. $scope.clicksub = false;
  604. // msg.error("支付失败:" + JSON.stringify(e));
  605. msg.error("支付失败");
  606. });
  607. }
  608. if ($scope.vm.payType == 2) { //微信
  609. // var obj = JSON.parse(payInfo);
  610. var obj = payInfo.orderString;
  611. // console.log("obj: " + JSON.stringify(obj));
  612. var params = {
  613. partnerid: obj.partnerid, // merchant id
  614. prepayid: obj.prepayid, // prepay id
  615. noncestr: obj.noncestr, // nonce
  616. timestamp: obj.timestamp, // timestamp
  617. sign: obj.sign, // signed string
  618. };
  619. // console.log("result: " + JSON.stringify(params));
  620. Wechat.sendPaymentRequest(params, function (r) {
  621. $scope.clicksub = false;
  622. // $state.go("app.paySuccess")
  623. // $state.go('app.paySuccess',{item:payInfo})
  624. $scope.openModal();
  625. // alert(orderID);
  626. myService.orderStatus(orderID).then(function (result) {
  627. // alert(result);
  628. //支付成功
  629. // $state.go('app.my');
  630. }, function (erro) {
  631. // msg.alert("支付反馈失败:" + JSON.stringify(erro));
  632. });
  633. }, function (reason) {
  634. $scope.clicksub = false;
  635. // msg.alert("支付失败:" + JSON.stringify(reason));
  636. });
  637. }
  638. // msg.text("充值成功");
  639. // $state.go('app.my');
  640. });
  641. }
  642. }
  643. }]);
  644. app.controller('accountCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  645. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  646. $scope.$on('$ionicView.beforeEnter', function () {
  647. $ionicTabsDelegate.showBar(false);
  648. $scope.showAccount();
  649. });
  650. $scope.showAccount = function(){
  651. myService.showAccount().then(function(result){
  652. $scope.items = result.data.data;
  653. },function(error){
  654. msg.error(error.data.message);
  655. })
  656. };
  657. $scope.destroyAccount = function(id){
  658. myService.destroyAccount(id).then(function(result){
  659. msg.text("删除成功");
  660. $scope.showAccount();
  661. },function(error){
  662. msg.error(error.data.message);
  663. })
  664. }
  665. }]);
  666. app.controller('my_account_addCtrl', ["$scope","config","common","$timeout","$ionicTabsDelegate", "$state", "myService", "msg"
  667. , function ($scope,config,common,$timeout,$ionicTabsDelegate, $state, myService, msg) {
  668. $scope.addpict = function () {
  669. common.chooseImage().then(function (qrcode) {
  670. common.uploadFiles(qrcode,1).then(function (result) {
  671. var response = JSON.parse(result.response);
  672. var file = config.imgServer+response.data.file;
  673. $scope.vm.file = file;
  674. $scope.qrcode.push(file);
  675. }, function (error) {
  676. msg.error('图片上传失败');
  677. });
  678. }, function (error) {
  679. console.log('图片选择失败');
  680. });
  681. };
  682. $scope.qrcode=[];
  683. $scope.deletefile = function (file) {
  684. var index = $scope.qrcode.indexOf(file);
  685. $scope.qrcode.splice(index, 1);
  686. common.deletefile(file).then(function () {
  687. })
  688. };
  689. $scope.vm={
  690. bank_name:'',
  691. bank_number:'',
  692. bank_phone:'',
  693. bank_user:'',
  694. type:""
  695. };
  696. $scope.addAccount = function () {
  697. var data = {
  698. data:{
  699. bank_name:$scope.vm.bank_name,
  700. bank_number:$scope.vm.bank_number,
  701. bank_phone:$scope.vm.bank_phone,
  702. bank_user:$scope.vm.bank_user
  703. }
  704. };
  705. //msg.loading('保存中...');
  706. msg.loading();
  707. myService.addAccount(data).then(function (result) {
  708. msg.hide();
  709. $state.go('app.my_account');
  710. }, function (error) {
  711. msg.hide();
  712. msg.error(error.data.message);
  713. });
  714. };
  715. $scope.addQrcode = function(){
  716. var data = {
  717. data:{
  718. type:$scope.vm.type,
  719. qrcode:$scope.vm.file
  720. //qrcode:"https://www.baidu.com/img/bd_logo1.png"
  721. }
  722. };
  723. myService.addQrcode(data).then(function(result){
  724. msg.text("添加成功",true);
  725. $state.go("app.my_account");
  726. },function(error){
  727. msg.error(error.data.message);
  728. })
  729. }
  730. }]);
  731. app.controller('messageCtrl', ["$scope", "$location","$ionicTabsDelegate","$state", "myService", "msg"
  732. , function ($scope,$location,$ionicTabsDelegate, $state, myService, msg) {
  733. $scope.$on('$ionicView.beforeEnter', function () {
  734. $ionicTabsDelegate.showBar(false);
  735. myService.messageInfo().then(function(result){
  736. $scope.infos = result.data.data;
  737. },function(error){
  738. });
  739. });
  740. $scope.notRead = function(){
  741. myService.notRead().then(function(result){
  742. myService.messageInfo().then(function(result){
  743. $scope.infos = result.data.data;
  744. },function(error){
  745. });
  746. },function(error){
  747. })
  748. };
  749. //梦想消息
  750. $scope.systemInfo = function(){
  751. if($location.path()=='/app/my/message'){
  752. $state.go("app.my_message_sys");
  753. }
  754. else {
  755. $state.go("app.message_sys");
  756. }
  757. };
  758. //支持消息
  759. $scope.replyMy = function(){
  760. if($location.path()=='/app/my/message'){
  761. $state.go("app.my_message_reply");
  762. }
  763. else {
  764. $state.go("app.message_reply");
  765. }
  766. };
  767. //通知
  768. $scope.personalLetter = function(){
  769. if($location.path()=='/app/my/message'){
  770. $state.go("app.personalLetter");
  771. }
  772. else {
  773. $state.go("app.letter");
  774. }
  775. };
  776. }]);
  777. app.controller('dreamCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  778. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  779. $scope.$on('$ionicView.beforeEnter', function () {
  780. $ionicTabsDelegate.showBar(false);
  781. $scope.load(true);
  782. myService.myInfo().then(function(result){
  783. $scope.user = result.data.data
  784. });
  785. });
  786. $scope.filter = {
  787. hasMore: false,
  788. pageIndex: 1,
  789. pageSize: 25
  790. };
  791. $scope.load = function (init) {
  792. if (init) {
  793. $scope.filter.pageIndex = 1;
  794. $scope.dreams = [];
  795. }
  796. msg.loading();
  797. myService.myDream($scope.filter.pageIndex).then(function(result){
  798. msg.hide();
  799. $scope.filter.pageIndex++;
  800. var more = (result.data.data.data.length >= $scope.filter.pageSize);
  801. $scope.filter.hasMore = more;
  802. $scope.dreams = $scope.dreams.concat(result.data.data.data);
  803. if (init) {
  804. $scope.$broadcast('scroll.refreshComplete');
  805. } else {
  806. $scope.$broadcast('scroll.infiniteScrollComplete');
  807. }
  808. },function(error){
  809. msg.hide();
  810. });
  811. };
  812. $scope.toDetail = function (id) {
  813. $state.go('app.my_dreamdetail',{id:id});
  814. };
  815. $scope.time = function(){
  816. }
  817. }]);
  818. app.controller('collectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  819. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  820. $scope.$on('$ionicView.beforeEnter', function () {
  821. $ionicTabsDelegate.showBar(false);
  822. myService.collect().then(function(result){
  823. $scope.dreams = result.data.data.dreams;
  824. });
  825. });
  826. $scope.toDetail = function (id) {
  827. $state.go('app.my_dreamdetail',{id:id});
  828. };
  829. }]);
  830. app.controller('messageSysCtrl', ["$scope","common","config","$ionicPopup","$location", "$ionicTabsDelegate","$state", "myService", "msg"
  831. , function ($scope,common,config,$ionicPopup,$location,$ionicTabsDelegate, $state, myService, msg) {
  832. $scope.$on('$ionicView.beforeEnter', function () {
  833. $scope.loaddata(true);
  834. });
  835. $scope.vm = {
  836. content:""
  837. };
  838. $scope.imgs = [];
  839. $scope.video = {};
  840. $scope.loaddata = function(init){
  841. myService.systemInfo().then(function(result){
  842. $scope.sysInfos = result.data.data;
  843. if (init) {
  844. $scope.$broadcast('scroll.refreshComplete');
  845. } else {
  846. $scope.$broadcast('scroll.infiniteScrollComplete');
  847. }
  848. },function(error){
  849. });
  850. }
  851. $scope.addpict = function () {
  852. common.chooseImage().then(function (img) {
  853. common.uploadFiles(img,1).then(function (result) {
  854. var response = JSON.parse(result.response);
  855. var file = config.imgServer + response.data.file;
  856. $scope.imgs.push(file);
  857. }, function (error) {
  858. msg.error('图片上传失败');
  859. });
  860. }, function (error) {
  861. console.log('图片选择失败');
  862. });
  863. };
  864. $scope.deletefile = function (file) {
  865. var index = $scope.imgs.indexOf(file);
  866. $scope.imgs.splice(index, 1);
  867. common.deletefile(file).then(function () {
  868. })
  869. };
  870. $scope.addvideo = function () {
  871. common.chooseVideo().then(function (file) {
  872. msg.loading();
  873. common.uploadFiles(file, 2).then(function (result) {
  874. msg.hide();
  875. var response = JSON.parse(result.response);
  876. // var file = config.imgServer+response.data.file;
  877. // $scope.video.file = response.data.file;
  878. $scope.video.server = response.data.file;
  879. var file = response.data.file;
  880. $scope.video.isOK = true;
  881. $scope.video.file = file;
  882. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  883. }, function (error) {
  884. //msg.error('视频上传失败');
  885. msg.hide();
  886. msg.error(JSON.stringify(error));
  887. });
  888. }, function (erro) {
  889. console.log('选择视频失败');
  890. });
  891. };
  892. $scope.deletevideo = function (file) {
  893. $scope.video = {};
  894. common.deletefile(file).then(function (res) {
  895. },function(erro){
  896. //alert(JSON.stringify(erro));
  897. })
  898. };
  899. $scope.goMes = function(is_reply,is_url,dream_id,is_end,message,user_id,info,attr_id){
  900. //发送私信
  901. if(is_reply==1){
  902. $scope.vm.content='';
  903. $scope.imgs=[];
  904. $scope.video = {};
  905. var myPopup = $ionicPopup.show({
  906. template : '<div>' +
  907. '<textarea autofocus style="border: 1px solid #D0D0D0" name="" id="" cols="30" rows="8" ng-model="vm.content" placeholder="对他的好意给予感谢的回复"></textarea onf>' +
  908. '<a ng-if="!video.isOK&&imgs.length==0" class="btn-file-up" ng-click="addpict()">' +
  909. '<img src="img/icon_photo.svg" style="height: 40px; width: 40px; text-align: center; line-height: 40px" /><br>' +
  910. '<em style="font-size: 16px">添加图片</em>' +
  911. '</a>' +
  912. '<a ng-if="imgs.length==0&&!video.isOK" class="btn-file-up" ng-click="addvideo()">' +
  913. '<img src="img/icon_video.svg" style="height: 40px; width: 40px; text-align: center; line-height: 40px" /><br>' +
  914. '<em style="font-size: 16px">添加视频</em>' +
  915. '</a>' +
  916. '<a ng-repeat="item in imgs" ng-click="showImages(item)" class="img-file-up">' +
  917. '<b style="background-image:url({{item}});"><em ng-click="deletefile(item)" class="ion-ios-close-outline"></em></b>' +
  918. '</a>' +
  919. '<div class="img-file-up" ng-if="video.isOK">' +
  920. '<div style="position:relative;">' +
  921. '<em ng-click="deletevideo(video.file)" class="ion-ios-close-outline"></em>' +
  922. '<video ng-src="{{video.file | trustUrl}}" style="width: 100px; height: 100px; border: 1px solid #D0D0D0" poster="{{video.vpic}}" controls="controls"></video>' +
  923. '</div>' +
  924. '</div>' +
  925. '</div>',
  926. title: message,
  927. scope: $scope,
  928. buttons: [
  929. { text: '取消' },
  930. {
  931. text: '<b>确定</b>',
  932. type: 'button-positive',
  933. onTap: function(e) {
  934. var data = {
  935. to_user_id:user_id,
  936. content:$scope.vm.content,
  937. video:$scope.video.file,
  938. image:$scope.imgs,
  939. //image:['http://img0.imgtn.bdimg.com/it/u=2398075737,160631337&fm=214&gp=0.jpg'],
  940. };
  941. myService.sendLetter(data).then(function(result){
  942. if(result.data.status_code==0){
  943. msg.success('发送成功');
  944. }
  945. })
  946. }
  947. }
  948. ]
  949. });
  950. }
  951. //跳转
  952. else if(is_url==1){
  953. if($location.path()=="/app/home/message/sys"){
  954. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  955. }
  956. else {
  957. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  958. }
  959. }
  960. //梦想结束
  961. else if(is_end==1&&attr_id==6){
  962. var endTemplate = '<div style="text-align: center"><p>恭喜你成功地你的梦想迈出最大的一步,</p>' +
  963. '<p>要取出全部梦想资金,</p>' +
  964. '<p>你需要亲自问候你的梦主</p>' +
  965. '<p>致出最诚挚的感谢</p>' +
  966. '<p>点击《确定》我们会提供</p>' +
  967. '<p>《梦主》的资料</p>' +
  968. '<p>如果你觉得不合适,你可以点击《取消》,但是《梦主》的资金会被退还给他</p>' +
  969. '<p>你以后创建梦想也会比较难</p>' +
  970. '</div>';
  971. msg.confirm('恭喜你!',endTemplate,'拒绝').then(function(result){
  972. if(result==true){
  973. myService.sure_meet(dream_id,1).then(function(res){
  974. if(res.data.status_code==0){
  975. if(res.data.data==0){
  976. msg.success('该梦想暂无梦主!');
  977. }
  978. else {
  979. msg.success('确定见面,期待相见吧!');
  980. }
  981. }
  982. })
  983. }
  984. else {
  985. myService.sure_meet(dream_id,0).then(function(res){
  986. if(res.data.status_code==0){
  987. msg.success('已拒绝见面!');
  988. }
  989. })
  990. }
  991. })
  992. }
  993. }
  994. }]);
  995. app.controller('messageReplyCtrl', ["$scope","$location","$ionicPopup","$ionicTabsDelegate", "$state","config", "myService", "msg", "$ionicModal"
  996. , function ($scope,$location,$ionicPopup,$ionicTabsDelegate, $state,config, myService, msg, $ionicModal) {
  997. $scope.$on('$ionicView.beforeEnter', function () {
  998. $scope.load(true);
  999. });
  1000. $scope.load = function (init) {
  1001. myService.replyMy().then(function (result) {
  1002. $scope.comments = result.data.data;
  1003. if (init) {
  1004. $scope.$broadcast('scroll.refreshComplete');
  1005. } else {
  1006. $scope.$broadcast('scroll.infiniteScrollComplete');
  1007. }
  1008. }, function (error) {
  1009. });
  1010. };
  1011. $scope.goMes = function(info,img,is_max,mes,video,attr_id,dream_id,to_user_id,is_end,is_url){
  1012. //收到私信
  1013. if(attr_id==7){
  1014. if(video!=null){
  1015. var letterTemplate = '<div style="text-align: center">' +
  1016. '<video ng-src=" ' +config.imgServer+video+' " width="100%" style="height: 350px;" class="centerme" controls="controls" ></video>' +
  1017. '<p>'+info+'</p>' +
  1018. '</div>';
  1019. }
  1020. else if(img!='') {
  1021. var letterTemplate = '<div style="text-align: center;">' +
  1022. '<img src="'+img+'" style="width:100%; height: 100%;">' +
  1023. '<p>'+info+'</p>' +
  1024. '</div>';
  1025. }
  1026. else {
  1027. var letterTemplate = '<div style="text-align: center">' +
  1028. '<p>'+info+'</p>' +
  1029. '</div>';
  1030. }
  1031. msg.confirm('私信',letterTemplate,'','梦想页').then(function(result){
  1032. if(result==true){
  1033. if($location.path()=="/app/home/message/reply"){
  1034. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  1035. }
  1036. else {
  1037. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  1038. }
  1039. }
  1040. })
  1041. }
  1042. //成为梦主
  1043. else if(is_max==1&&is_end==1){
  1044. var maxTemplate = '<div style="text-align: center"><p>'+ mes +'</p>' +
  1045. '<p>'+ info +'</p>' +
  1046. '</div>';
  1047. msg.confirm('恭喜你!',maxTemplate).then(function(result){
  1048. if(result==true){
  1049. myService.sure_meet2(to_user_id,1).then(function(res){
  1050. if(res.data.status_code==0) {
  1051. msg.success('确定见面,期待相见吧!');
  1052. }
  1053. })
  1054. }
  1055. else {
  1056. myService.sure_meet2(to_user_id,0).then(function(res){
  1057. if(res.data.status_code==0){
  1058. msg.success('已取消见面!');
  1059. }
  1060. })
  1061. }
  1062. })
  1063. }//确认见面/扫一扫
  1064. else if(is_max==0&&is_url==0){
  1065. var maxTemplate = '<div style="text-align: center"><p>'+ mes +'</p>' +
  1066. '</div>';
  1067. msg.alert('恭喜你!',maxTemplate).then(function(result){
  1068. })
  1069. }
  1070. else if(is_end==0&&is_url==0){
  1071. }
  1072. else {
  1073. if($location.path()=="/app/home/message/reply"){
  1074. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  1075. }
  1076. else {
  1077. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  1078. }
  1079. }
  1080. };
  1081. //我的回复
  1082. $scope.vm = {
  1083. content: ""
  1084. };
  1085. $ionicModal.fromTemplateUrl('my-modal.html', {
  1086. scope: $scope,
  1087. animation: 'slide-in-up'
  1088. }).then(function (modal) {
  1089. $scope.modal = modal;
  1090. });
  1091. //$ionicModal.fromTemplateUrl('my-modal.html', {
  1092. // scope: $scope,
  1093. // animation: 'slide-in-up'
  1094. //}).then(function (modal) {
  1095. // $scope.modal = modal;
  1096. //});
  1097. //$scope.openModal = function () {
  1098. // $scope.modal.show();
  1099. //};
  1100. //$scope.closeModal = function () {
  1101. // $scope.modal.hide();
  1102. //
  1103. //};
  1104. $scope.goDetail = function (id,interaction_id){
  1105. $state.go('app.home_dreamdetail',{id:id,interaction_id:interaction_id,type:2});
  1106. };
  1107. //我的回复
  1108. //$scope.vm={
  1109. // content:"",
  1110. // comment_id:""
  1111. //};
  1112. //$scope.closeModal = function () {
  1113. // var data = {
  1114. // content: $scope.vm.content,
  1115. // comment_id: $scope.item.id,
  1116. // interaction_id: $scope.item.interaction_id
  1117. // };
  1118. // myService.myReplay(data).then(function (result) {
  1119. // msg.success('回复成功');
  1120. // $scope.load();
  1121. // }, function (error) {
  1122. // msg.error('回复失败');
  1123. // });
  1124. // $scope.vm.content = '';
  1125. // $scope.item = null;
  1126. // $scope.modal.hide();
  1127. //};
  1128. //
  1129. //$scope.reply = function (item) {
  1130. // $scope.item = item;
  1131. // $scope.modal.show();
  1132. //}
  1133. }]);
  1134. })(angular.module('app.controllers'));