首选节后健全登录 可以看之前的代码
https://blog.csdn.net/that_were_you/article/details/119112689?spm=1001.2014.3001.5501
点开我的钱包按钮后
获取我的钱包余额
html
<view>
可用余额:<text style="color:red">{{pice}}</text>元
</view>
<navigator url="/pages/transfer/transfer">
<button>转账</button>
</navigator>
<navigator url="/pages/detail/detail">
<button>明细</button>
</navigator>js:
data: {
pice:''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.request({
url: '接口',
header:{token:wx.getStorageSync('token')},
success:res=>{
console.log(res.data.data);
this.setData({
pice:res.data.data
})
}
})接口
public function pice(Request $request)
{
$pice=User::where('id',$request->uid)->value('pice');
return json(['code'=>200,'data'=>$pice,'msg'=>'ok']);
}点击进去转账功能
html:
<form bindsubmit="formSubmit" bindreset="formReset">
<view class="section">
<view class="section__title">手机号</view>
<input name="phone" placeholder="手机号" />
</view>
<view class="section">
<view class="section__title">金额</view>
<input name="pice" placeholder="金额" />
</view>
<view class="btn-area">
<button formType="submit">下一步</button>
</view>
</form>js:
formSubmit(e){
console.log(e.detail.value);
wx.request({
url: 'http://www.week2.com/api/order',
data:{
phone:e.detail.value.phone,
pice:e.detail.value.pice
},
header:{
token:wx.getStorageSync('token')
},
success:res=>{
console.log(res.data);
if(res.data.code==200){
wx.navigateTo({
url: '/pages/transfer_do/transfer_do?id='+res.data.data,
})
}
wx.showToast({
title: res.data.msg,
})
}
})接口:(validate自己加)
public function order(Request $request)
{
// dd($request->param());
$pice=User::where('id',$request->uid)->value('pice');
$pid=User::where('phone',$request['phone'])->value('id');
if (empty($pid)){
return json(['code'=>2000,'data'=>'','msg'=>'用户不存在']);
}
$number=strtotime(date('Y-m-d')).md5(md5("date().$request->uid"));
$result=Order::create([
'uid'=>$request->uid,
'number'=>$number,
'pid'=>$pid,
'time'=>date('Y-m-d H:i:s'),
'pice'=>$request['pice']
]);
// dd($result->id);
if ($result){
return json(['code'=>200,'data'=>$result->id,'msg'=>'ok']);
}
return json(['code'=>2005,'data'=>'','msg'=>'转账失败']);
}生成订单:去支付按钮
html
<view>
¥{{showorder.pice}}
</view>
<view wx:if="{{showorder.state=='1'}}">
<button bindtap="go">去支付</button>
<button bindtap="no">取消订单</button>
</view>
<view wx:else>
转账成功
</view>
<view>
<view>对方账户:{{showorder.pid}}</view>
<view>订单:{{showorder.number}}</view>
<view>创建时间{{showorder.time}}</view>
</view>js
data: {
showorder:[],
id:''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var id=options.id
console.log(id);
wx.request({
url: '接口',
data:{id:id},
header:{
token:wx.getStorageSync('token')
},
success:res=>{
console.log(res.data);
this.setData({
showorder:res.data.data,
id:id
})
}
})
},
go(e){
wx.request({
url: '接口',
data:{id:this.data.id},
header:{
token:wx.getStorageSync('token')
},
success:res=>{
console.log(res.data);
if(res.data.code==200){
wx.navigateTo({
url: '/pages/detail/detail',
})
}
wx.showToast({
title: res.data.msg,
})
}
})
},后台
public function showOrder($id)
{
$data=Order::find($id);
return json(['code'=>200,'data'=>$data,'msg'=>'ok']);
}
public function goOrder(Request $request)
{
$order=Order::find($request['id']);
$pice=$order['pice'];
$order&&$order=$order->toArray();
$uidUser=User::where('id',$order['uid'])->find();
$pidUser=User::where('id',$order['pid'])->find();
if ($order['pice']>$uidUser->pice){
return json(['code'=>2015,'data'=>'','msg'=>'约不住']);
}
// 启动事务
// dd($order,$data);
Db::startTrans();
try {
User::where('id',$order['uid'])->update(['pice'=>$uidUser['pice']-$order['pice']]);
User::where('id',$order['pid'])->update(['pice'=>$pidUser['pice']+$order['pice']]);
Order::where('id',$request['id'])->update(['state'=>'2']);
// 提交事务
Db::commit();
return json(['code'=>200,'data'=>'','msg'=>'ok']);
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return json(['code'=>2010,'data'=>'','msg'=>$e->getMessage()]);
}
}查看明细
<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.pice}}元</text>
<view>{{item.time}}</view>
<view wx:if="{{item.state==1}}">待支付</view>
<view wx:if="{{item.state==2}}">转账成功</view>
</view>
</block>js
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: 接口',
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: '接口',
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'];
// dd($stoptime,$startime);
$data=Order::with(['user'])->where('uid',$request->uid);
if (empty($startime)&&empty($stoptime)){
$data=$data->select();
}
if (!empty($startime)&&!empty($stoptime)){
$data=$data->where('time','between',[$startime,$stoptime])->select();
}
if (!empty($stoptime)&&empty($stoptime)){
$data=$data->where('time','>=',$startime)->select();
}
if (empty($stoptime)&&!empty($stoptime)){
$data=$data->where('time','<=',$stoptime)->select();
}
return json(['code'=>200,'data'=>$data,'msg'=>'ok']);
// dd($data->toArray());
}后台搜索代码可以实现但应该有更好的方式呈现出来 欢迎留言
版权声明:本文为that_were_you原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。