thinkphp6 + 微信小程序 实现支付功能

我们用到的数据表:concert(演唱会)hall(场位表)seat(座位表)ticket(票)user(用户表)

concert(演唱会):

 hall(场位表)

 seat(座位表)

 ticket(票)

 user(用户表)

 微信小程序 手机验证码登录:

https://blog.csdn.net/lh25946/article/details/120495963?spm=1001.2014.3001.5501

首页搜索 下拉刷新:

<navigator url="/pages/time/time"><button>时间搜索</button></navigator>
<view>
  <form catchsubmit="formSubmit" catchreset="formReset">
      <input class="weui-input" name="title" placeholder="这是一个输入框" />
        <button style="margin: 30rpx 0" type="primary" formType="submit">搜索</button>
    </form>
 
 
    <block wx:for="{{str}}" wx:key='key'>
    <view>
     标题: <rich-text nodes="{{item.title}}"></rich-text>
      <view>观影人数{{item.place_no}}</view>
    </view>
  
  </block>
</view>

    <block wx:for="{{allOrder}}">
<navigator url="/pages/mysfind/mysfind?id={{item.id}}">
        <l-card type="avatar"l-class="card"
    title="{{item.title}}" describe="{{item.start_time}}">
        <!-- 此处为content -->
        <view class="avter-content">
        <!-- {{item.id}} -->
        <image src="{{item.image}}"></image>
        <view>作者:{{item.singger}}</view>
        <view>价格:{{item.price}}</view>
        <view>结束时间:{{item.end_time}}</view>
        <view>人数:{{item.place_no}}</view>
        </view>
        <view class="avter-share-container">
        </view>
  </l-card>
</navigator>
</block>

js页面 

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    allOrder:[],
    page:1,
    str:[]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    wx.request({
      url: 'http://www.ceshi.com/api/concert',
      dataType:'json',
      header:{
        'token':wx.getStorageSync('token')
      },success:res=>{
        console.log(res.data)
        this.setData({
          allOrder:res.data.allOrder
        })
      }
    })
  },

  onReachBottom:function(e){
    this.setData({
        page:this.data.page+1
    })
    wx.request({
      url: 'http://www.ceshi.com/api/concert',
      dataType:'json',
      header:{
        'token':wx.getStorageSync('token')
      },
      data:{
        page:this.data.page
      },
      success:res=>{
          console.log()
          if(res.data.allOrder.length ==0){
            wx.showToast({
              title: '没有数据了',
              icon:'none'
            })
          }
          var allOrder = this.data.allOrder
          var vm = allOrder.concat(res.data.allOrder)
          this.setData({
            allOrder:vm
          })  
      }
    })
  },  
  //搜索
  formSubmit(e) {
    console.log(e);
    var _this = this;
    //console.log(e.detail.value.title)
    var title = e.detail.value.title;
    wx.request({
      url: 'http://www.ceshi.com/api/showtime',
      data:{
        title:title
      },
      success:function(add){
        console.log(add.data)
        console.log(add.data.data)
        var fang = add.data;
        _this.setData({
          fang,
          str:add.data.data
        })
      }
    })
  },

})

php后台处理:

 public function concert(Request $request)
    {
        //接收page页面
        $page = $request->get('page')??1;
        $limit = $request->get('limit')??10;
        $offset = ($page-1)*$limit;
        $id = 1;
        try {
            $allOrder = Concert::order('place_no desc')->limit($offset,$limit)->select();
            return json(['code'=>0,'msg'=>'数据库查询成功','allOrder'=>$allOrder]);
        }catch(\Exception $e){
            $allOrder = Cache::get('ahao')->limit($offset,$limit)->select();
            return json(['code'=>0,'msg'=>'缓存查询成功','allOrder'=>$allOrder]);
        }
    }
public function showtime()
    {
        $info=\request()->get('title');
        $data=Concert::where('title','like','%'.$info.'%')->select()->toArray();
        try {
            if($data){
                return json(['code'=>200,'msg'=>'查询成功','data'=>$data]);
            }else{
                return json(['code'=>400,'msg'=>'查询失败','data'=>'']);
            }
        }catch (\Exception $e){

        }
    }

时间搜索:

<view class="section">
  <picker mode="date" value="{{startTime}}" start="2019-09-01" end="2022-09-01" bindchange="startTimeChange">
    <view class="picker">
      开始日期: {{startTime}}
    </view>
  </picker>
</view>
<view class="section">
  <picker mode="date" value="{{stopTime}}" start="2019-09-01" end="2022-09-01" bindchange="stopTimeChange">
    <view class="picker">
      结束日期: {{stopTime}}
    </view>
  </picker>
</view>
<button bindtap="show">搜索</button>
<block wx:for="{{detailList}}">
<view style="height: 80px;">
 转账<text>{{item.user.nikcname}}</text>
 <text>{{item.price}}元</text>
 <view>演唱者:{{item.singger}}</view>
 <view>标题:{{item.title}}</view>
</view>
</block>

js处理处理事件

// pages/time/time.js
Page({

  data: {
    detailList:[],
    startTime:'',
    stopTime:''
},
startTimeChange(e){
    console.log(e);
    this.setData({
            startTime:e.detail.value
    })
},
stopTimeChange(e){
    console.log(e);
    this.setData({
            stopTime:e.detail.value
    })
},
show(e){
    wx.request({
            url: 'http://www.ceshi.com/api/detail',
            data:{
                    startime:this.data.startTime,
                    stoptime:this.data.stopTime
            },
            header:{
                    token:wx.getStorageSync('token')
            },
            success:res=>{
                    console.log(res.data.data);
                    this.setData({
                          detailList:res.data.data
                    })
            }
          })
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
    wx.request({
      url: 'http://www.ceshi.com/api/detail',
      header:{
              token:wx.getStorageSync('token')
      },
      success:res=>{
              console.log(res.data.data);
              this.setData({
                    detailList:res.data.data
              })
      }
    })
  }
})
public function detail(Request $request)
    {
        //接收传递过来的开始时间
        $startime=$request['startime'];
        //接收传递过来的结束时间
        $stoptime=$request['stoptime'];
        //定义一个空数组,把要查询的数据放进去
        $where[]=['startime','between',"$startime,$stoptime"];
        //进行查询
        $data=Concert::where($where)->select()->toArray();

        if($data){
            return json(['code'=>200,'msg'=>'搜索成功','data'=>$data]);
        }else{
            return json(['code'=>400,'msg'=>'搜索失败','data'=>null]);
        }

    }

详情页面:


        <l-card type="avatar"l-class="card"
    title="{{list.title}}" describe="{{list.start_time}}">
        <!-- 此处为content -->
        <view class="avter-content">
        <!-- {{item.id}} -->
        <image src="{{list.image}}"></image>
        <view>作者:{{list.singger}}</view>
        <view>价格:{{list.price}}</view>
        <view>结束时间:{{list.end_time}}</view>
        <view>观影人数:{{list.place_no}}</view>
        </view>
        <view class="avter-share-container">
        </view>
        <navigator url="/pages/order/order?price={{list.price}}&place_no={{list.place_no}}"><l-button>立即购买</l-button>  </navigator>
  </l-card>

js处理事件:

// pages/mysfind/mysfind.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id=options.id
    // console.log(id)
    wx.request({
      url: 'http://www.ceshi.com/api/concert_find?id='+id,
      header: {
        'token':wx.getStorageSync('token')
    },
      success :res=>{
        console.log(res.data.data)
        this.setData({
          list:res.data.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
public function concertFind()
    {
        $id=\request()->get('id');

        $data=Concert::find($id);
        try {
            if($data){
                return json(['code'=>200,'msg'=>'查询成功','data'=>$data]);
            }else{
                return json(['code'=>400,'msg'=>'查询成功','data'=>'']);
            }
        }catch (\Exception $e){

        }
    }

订单页面:

<view>恭喜您!已抢票成功,您的座位是{{list.ticket_no}},请您留意您的短信</view>
<view>订单号:{{list.order}}</view>
<navigator url="/pages/grabbing/grabbing"><button>查看订单</button></navigator>
// pages/order/order.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let token=wx.getStorageSync('token');
    let phone=wx.getStorageSync('phone');
    if(token==""||phone==""){
        wx.redirectTo({
          url:"/pages/my/my"
        })
        return
    }
    let price=options.price
    let place_no=options.place_no
    
    // console.log(id)
    wx.request({
      
      url: 'http://www.ceshi.com/api/concert_select',
      data:{
        price:price,
        place_no:place_no
      },
      header: {
        token:wx.getStorageSync('token')
      },
     
        success :res=>{
          console.log(res.data.data)
          this.setData({
            list:res.data.data
          })
        }
  
      
    })
  },
})
 public function concertSelect()
    {
        $data=\request()->get('');
        $arr['ticket_no']=rand(1,99).'号';
        $ticket_no=$arr['ticket_no'];
        $arr['order']=rand(11111111111,99999999999);
        $arr['price']=$data['price'];
        $arr['place_no']=$data['place_no'];
        $dataInfo=Ticket::where('ticket_no',$arr['ticket_no'])->find();
        if(empty($dataInfo)){
            $info=Ticket::create($arr);
            if($info){
                $phone="要填写的手机号";
                $statusStr = array(
                    "0" => "短信发送成功",
                    "-1" => "参数不全",
                    "-2" => "服务器空间不支 持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
                    "30" => "密码错误",
                    "40" => "账号不存在",
                    "41" => "余额不足",
                    "42" => "帐户已过期",
                    "43" => "IP地址限制",
                    "50" => "内容含有敏感词"
                );
//                $yzm=rand(1111,9999);
                $smsapi = "http://api.smsbao.com/";
                $user = "lh259486"; //短信平台帐号
                $pass = md5("lh259486"); //短信平台密码
                $content="我是您的客服助理锕豪,您已在我公司抢票成功,观影码是$ticket_no,过时不候,请您合理安排自己的宝贵时间";//要发送的短信内容
                $dataPhone = $phone;//要发送短信的手机号码
//                $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$dataPhone."&c=".urlencode($content);
//                $result =file_get_contents($sendurl) ;
//                echo $statusStr[$result];
                return json(['code'=>'200','data'=>$info,'msg'=>'购买成功并成功发送短信']);
            }else{
                return json(['code'=>400,'msg'=>'生成订单失败','data'=>'']);
            }

        }else{
            $info=Ticket::where('ticket_no',$arr['ticket_no'])->find();
            return json(['code'=>513,'msg'=>'查询订单成功','data'=>$info]);
        }
    }

查看订单页面:
 

<l-tabs bind:linchange="changeTabs">
        <l-tabpanel tab="全部订单" key="one" slot="one">
          
<l-card type="primary" wx:for="{{grabbing}}" wx:key="item"
          plaintext="{{true}}"
          title="{{item.place_no}}">
    <view class="content">
     价格:{{item.price}}
     座位号:{{item.ticket_no}}
    状态:   <navigator url="/pages/refund/refund?id={{item.id}}&status={{item.status}}&price={{item.price}}"><l-button>{{item.status==1?'已支付':'已退款'}}</l-button> </navigator> 
    </view>
  </l-card>
        </l-tabpanel>
        <l-tabpanel tab="已支付订单" key="two" slot="two">
          <l-card type="primary" wx:for="{{list}}" wx:key="item"
          plaintext="{{true}}"
          title="{{item.place_no}}">
    <view class="content">
     价格:{{item.price}}
     座位号:{{item.ticket_no}}
    状态:   <navigator url="/pages/refund/refund?id={{item.id}}&status={{item.status}}&price={{item.price}}"><l-button>{{item.status==1?'已支付':'已退款'}}</l-button> </navigator> 
    </view>
  </l-card>
        </l-tabpanel>
      </l-tabs>
// pages/grabbing/grabbing.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    grabbing:[],
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.request({
      url: 'http://www.ceshi.com/api/ticker_select',
      success :res=>{
        console.log(res.data.data)
        this.setData({
          grabbing:res.data.data
        })
      }
    })
    wx.request({
      url: 'http://www.ceshi.com/api/ticker_status_success',
      success :res=>{
        console.log(res.data.data)
        this.setData({
          list:res.data.data
        })
      }
    })
  },

})

php后端处理事件:

public function tickerSelect()
    {
        $data=Ticket::select();
        try {
            if($data){
                return json(['code'=>200,'msg'=>'查询成功','data'=>$data]);
            }else{
                return json(['code'=>400,'msg'=>'查询失败','data'=>'']);
            }
        }catch (\Exception $e){
            echo "异常捕获".$e;
        }
    }

支付成功处理事件:

public function tickerStatusSuccess()
    {
        $data=Ticket::where('status','1')->select();
        try {
            if($data){
                return json(['code'=>200,'msg'=>'查询成功','data'=>$data]);
            }else{
                return json(['code'=>400,'msg'=>'查询失败','data'=>'']);
            }
        }catch (\Exception $e){
            echo "异常捕获".$e;
        }
    }

退款js处理事件:

// pages/refund/refund.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    refund:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      let id=options.id;
      let status=options.status;
      let price=options.price
      wx.request({
        url: 'http://www.ceshi.com/api/ticker_status',
        header:{
            token:wx.getStorageSync('token')
        },
        data:{
          id:id,
          status:status,
          price:price
        },
        success :res=>{
          if(res.data.code==200){
            wx.redirectTo({
              url:"/pages/grabbing/grabbing"
            })
          }
        }
      })
  },

})
public function tickerStatus()
    {
        $id=request()->get('id');
        $status=request()->get('status');
        $price=\request()->get('price');
        if($status==1){
//
            $status=3;
        }else{
            $status=2;
        }
        //开启事物
        Db::startTrans();
        try {
            $data=Ticket::where('id',$id)->update(['status'=>$status]);
//            $info=User::where('name','马云')->save(['price'-$price]);
//            $infos=User::where('name','马云')->save(['price'.'+'.$price]);

            Db::commit();
            return json(['code'=>200,['data'=>$data],'msg'=>'退款成功']);
        }catch (\Exception $e){
            // 回滚事务
            Db::rollback();
            return json(['code'=>2010,'data'=>'','msg'=>$e->getMessage()]);
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值