编辑index方法:
~~~
public function index(){
if($this->request->method()=='POST')
{
$postdata = $this->request->only(['moderate','operation']);
}
}
~~~
添加代码如下:
~~~
if($postdata['operation']=='delete'){
foreach($postdata['moderate'] as $tid)
{
$this->destroy($tid);
}
return $this->success('删除成功');
}else if($postdata['operation']=='programmer'){
// 更新程序资料
$post = $this->request->only(['programmername','programmerrate']);
foreach($postdata['moderate'] as $tid)
{
$tpl = TplModel::get(['uid'=> $activeuser['uid'],'tid'=> $tid]);
$tpl->pnick = $post['programmername'];
$tpl->prate = $post['programmerrate'];
$tpl->save();
}
return $this->success('程序更新成功');
}else if($postdata['operation']=='designer'){
// 更新美工资料
$post = $this->request->only(['designername','designerrate']);
foreach($postdata['moderate'] as $tid)
{
$tpl = TplModel::get(['uid'=> $activeuser['uid'],'tid'=> $tid]);
$tpl->dnick = $post['designername'];
$tpl->drate = $post['designerrate'];
$tpl->save();
}
return $this->success('美工更新成功');
}else if($postdata['operation']=='other1'){
// 更新第三方一资料
$post = $this->request->only(['other1name','other1rate']);
foreach($postdata['moderate'] as $tid)
{
$tpl = TplModel::get(['uid'=> $activeuser['uid'],'tid'=> $tid]);
$tpl->onick1 = $post['other1name'];
$tpl->orate1 = $post['other1rate'];
$tpl->save();
}
return $this->success('第三方一更新成功');
}else if($postdata['operation']=='other2'){
// 更新第三方二资料
$post = $this->request->only(['other2name','other2rate']);
foreach($postdata['moderate'] as $tid)
{
$tpl = TplModel::get(['uid'=> $activeuser['uid'],'tid'=> $tid]);
$tpl->onick2 = $post['other2name'];
$tpl->orate2 = $post['other2rate'];
$tpl->save();
}
return $this->success('第三方二更新成功');
}else if($postdata['operation']=='highlight'){
// 高亮
$post = $this->request->only(['highlight_color']);
foreach($postdata['moderate'] as $tid)
{
$tpl = TplModel::get(['uid'=> $activeuser['uid'],'tid'=> $tid]);
$tpl->highlight = $post['highlight_color'];
$tpl->save();
}
return $this->success('高亮更新成功');
}else if($postdata['operation']=='type'){
// 状态
foreach($postdata['moderate'] as $tid)
{
$tpl = TplModel::get(['uid'=> $activeuser['uid'],'tid'=> $tid]);
$tpl->ttype = !$tpl->ttype;
$tpl->save();
}
return $this->success('状态更新成功');
}else{
echo 'none';
}
~~~
添加destroy方法:
~~~
protected function destroy($tid=0)
{
$activeuser = UserModel::where('status',1)->find();
if($activeuser){
$tpl = TplModel::where('uid',$activeuser['uid'])->where('tid',$tid)->delete();
}
}
~~~