【做了个订单批量打款】第一种方式
思路:
- 判断需要打款订单前面添加复选框再添加一个全选按钮和批量打款事件按钮
- 点击批量打款按钮触发事件获取checked选中订单发送ajax处理数据
html代码:
//添加一个全选按钮和批量打款事件按钮
全选
//遍历订单判断需要打款订单前面添加复选框
{$vo.id}
{$vo.id}
js代码
//多选控制
$('.all-select').change(function () {
if($(this).attr('checked') == 'checked'){
$('.all-select').prop('checked','checked');
$('.select').prop('checked','checked');
}else{
$('.all-select').prop('checked','');
$('.select').prop('checked','');
}
});
//批量打款
$('#money-all').click(function(){
var ids = [];
$('.select:checked').each(function(index,value){
ids[index] = $(this).val();
});
if(ids.length == 0){
alert('没有打款条目');
return false;
}
$.ajax({
url:"http://"+document.domain+"/index.php/Admin/Yushou/guandaimais",
dataType:"json",
data:{
ids:ids,
},
type:"POST",
success:function(req){
console.log(req);
if(req['code'] == 0){
alert('批量打款错误');
}else{
window.location.href = https://www.it610.com/article/req.url+"?ids="+req.ids;
}
},
error:function(){
alert('网络错误');
}
});
});
php代码
public function guandaimais(){
$ids = I('ids');
if($ids){
$url = __ROOT__.'/index.php/Admin/Yushou/guandaimai.html';
echo json_encode(array('code'=>1,'url'=>$url,'ids'=>$ids));
}else{
echo json_encode(array('code'=>0));
}
}
这里跳了一个定时页面
php代码
public function guandaimai_post(){
$Order=M('Order');
$Users=M('Users');
$Daimaijie=M('Daimaijie');
$idstr = I('order_ids');
$yingdakuan_time = I('yingdakuan_time');
$caozuo_name=session('nickname');
$caozuo_id=session('uid');
$caozuo_hao=session('username');
if(empty($caozuo_hao)){
$this->redirect('Login/login');
}
if($idstr){
//批量
$ids = explode(',', $idstr);
$map_o = array(
'id' => array('in',$ids),
);
$data_o = $Order->where($map_o)->select();
$data = https://www.it610.com/article/array();
$data['caozuo_id'] = $caozuo_id;
$data['yingdakuan_time'] = $yingdakuan_time;
$data['caozuo_name'] = $caozuo_name;
$data['caozuo_hao'] = $caozuo_hao;
$data['posttime'] = date('Y-m-d H:i:s');
$data['state'] = 1;
foreach($data_o as $k => $v){
$data['order_id'] =$v['id'];
$data['order_hao'] = $v['order_id'];
$data['daimai_tuikuan'] = number_format($v['daimai_tuikuan'],2,'.',"");
$data['order_title'] = $v['name'];
$data['qian'] = number_format($v['dai_qian'],2,"." ,"");
$data['user_id'] = $v['user_id'];
$data_u = $Users->where(array('id'=>array('eq',$v['user_id'])))->getField('username');
if($data_u == ''){
$data_u = "";
}
$data['user_name'] = $data_u;
$result = $Daimaijie->add($data);
if($result){
$data_o = array(
'daimai_jie' => 1,
'yingdakuan_time' => $yingdakuan_time,
);
$res[$k] = $Order->where(array('id'=>array('eq',$v['id'])))->save($data_o);
}}
$count = count($res);
if($count>0){
$this->redirect('Yushou/daimailist',array('count'=>$count));
}else{
$this->error('改变订单状态失败','',3);
}}else{
//单个订单
$order_id=I('order_id');
$order_hao=I('order_hao');
$posttime=date("Y-m-d H:i:s");
$order_title=I('order_title');
$user_id = I('user_id');
$user_name = I('user_name');
$yingdakuan_time=I('yingdakuan_time');
$map_o=array(
'id'=>array('eq',$order_id)
);
$data_order=$Order->where($map_o)->find();
$dai_qian=number_format($data_order['dai_qian'],2,".","");
$daimai_tuikuan=number_format($data_order['daimai_tuikuan'],2,'.',"");
$Daimaijie=M('Daimaijie');
$data = https://www.it610.com/article/array('order_id'=>$order_id,
'order_hao'=>$order_hao,
'caozuo_id'=>$caozuo_id,
'yingdakuan_time'=>$yingdakuan_time,
'caozuo_name'=>$caozuo_name,
'caozuo_hao'=>$caozuo_hao,
'daimai_tuikuan'=>$daimai_tuikuan,
'order_title'=>$order_title,
'qian'=>$dai_qian,
'posttime'=>$posttime,
'user_id'=>$user_id,
'user_name'=>$user_name,
'state'=>1,
);
$result = $Daimaijie->add($data);
if($result){
$data_o=array(
'daimai_jie'=>1,
'yingdakuan_time'=>$yingdakuan_time,
);
$res=$Order->where($map_o)->save($data_o);
if($res){
$this->redirect('Yushou/daimailist');
}else{
$this->error('改变订单状态失败','',3);
}}else{
$this->error('退款失败','',3);
}
}
}
推荐阅读
- spring boot log 多环境配置
- 记录|RateLimiter限流
- 记录--NPM卸载命令
- jquery.printarea.js 局部打印去掉页眉页脚
- PHP 选择时间获取当前 年,月,日
- php支付宝手机网站支付接口爆缺少签名错误
- 记录|给APP接入极光推送——后端(PHP)
- 使用GIT删除新增的文件