assign('breadcrumb1','拉新活动'); $this->assign('breadcrumb2','拉新活动奖励配置'); } /** * 修改 * * */ public function edit(Model $Model,Coupon $Coupon){ // 接收参数 $id = request('id',0); $activeId = request('active_id',0); // 错误告知 if( !$activeId ) return $this->error('缺失活动id'); $oldData = $Model->where(['active_id'=>$activeId])->first(); // 修改 if(request()->isMethod('post')){ // 接收数据 $data['old_prize_type'] = request('old_prize_type',''); $data['old_prize'] = request('old_prize',''); $data['new_prize_type'] = request('new_prize_type',''); $data['new_prize'] = request('new_prize',''); $data['higher_prize_type'] = request('higher_prize_type',''); $data['higher_prize'] = request('higher_prize',''); $data['active_id'] = $activeId; if ($data['old_prize_type'] == 2){ $data['old_prize'] = $Coupon->codeToId($data['old_prize']); } if ($data['new_prize_type'] == 2){ $data['new_prize'] = $Coupon->codeToId($data['new_prize']); } if ($oldData){ // 写入数据表 $result = $Model->edit($oldData['id'],$data); }else{ $result = $Model->add($data); } // 如果操作失败 if( !$result ) return json_send(['code'=>'error','msg'=>'修改失败']); // 记录行为 $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data); // 告知结果 return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']); } $this->assign('oldData',$oldData); $this->assign('activeId',$activeId); $this->assign('crumbs','修改'); // 加载模板 return $this->fetch(); } }