Index.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 首页接口
  7. */
  8. class Index extends Api
  9. {
  10. protected $noNeedLogin = ['banner'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 首页
  14. *
  15. */
  16. public function index()
  17. {
  18. $this->success('请求成功');
  19. }
  20. public function banner(){
  21. $list = Db::name('banner')->order('weigh desc')->select();
  22. $list = list_domain_image($list,['image']);
  23. $this->success(1,$list);
  24. }
  25. //我的邀请
  26. public function myintro(){
  27. $introme = Db::name('user')->field('id,nickname,avatar,jointime')->where('id',$this->auth->intro_uid)->find();
  28. $introme = info_domain_image($introme,['avatar']);
  29. $myintro = Db::name('user')->field('id,nickname,avatar,jointime')->where('intro_uid',$this->auth->id)->select();
  30. $myintro = list_domain_image($myintro,['avatar']);
  31. $rs = [
  32. 'introme' => $introme,
  33. 'myintro' => $myintro,
  34. ];
  35. $this->success(1,$rs);
  36. }
  37. //用户积分日志
  38. public function user_score_log(){
  39. $type = input('type',1);
  40. $where = [
  41. 'user_id' => $this->auth->id,
  42. ];
  43. if($type == 1){
  44. $where['change_value'] = ['gt',0];
  45. }else{
  46. $where['change_value'] = ['lt',0];
  47. }
  48. $list = Db::name('user_score_log')->field('id,change_value,remark,createtime')->where($where)->order('id desc')->autopage()->select();
  49. if(!empty($list)){
  50. foreach($list as $key => &$val){
  51. $val['createdate'] = date('Y-m-d',$val['createtime']);
  52. }
  53. }
  54. $this->success(1,$list);
  55. }
  56. //积分提现配置
  57. public function takecash_config(){
  58. $list = Db::name('exchmoney_config')->order('weigh desc')->select();
  59. $this->success(1,$list);
  60. }
  61. //积分提现
  62. public function takecash(){
  63. $con_id = input('config_id',0);
  64. $info = Db::name('exchmoney_config')->where('id',$con_id)->find();
  65. Db::startTrans();
  66. //日志
  67. $data = [
  68. 'user_id' => $this->auth->id,
  69. 'score' => $info['score'],
  70. 'money' => $info['money'],
  71. 'createtime' => time(),
  72. 'status' => 0,
  73. ];
  74. $order_id = Db::name('user_exchangemoney_log')->insertGetId($data);
  75. if(!$order_id){
  76. Db::rollback();
  77. $this->error('申请提现失败');
  78. }
  79. //扣钱
  80. $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$info['score'],4,'提现','user_exchangemoney_log',$order_id);
  81. if($rs_wallet['status'] == false){
  82. Db::rollback();
  83. $this->error($rs_wallet['msg']);
  84. }
  85. Db::commit();
  86. $this->success('申请提现成功',$order_id);
  87. }
  88. }