//我在模块表单中些批量审核通过方法,审核完后更新关联主题中length的字段值,现在测试完,数据表只更新一个所选内容的字数,不知道哪里除了问题。。
// 后台批量审核
protected function _Admin_Status() {
$tid = intval(\Phpcmf\Service::L('input')->get('tid'));
$ids = \Phpcmf\Service::L('input')->get_post_ids();
if (!$ids) {
$this->_json(0, dr_lang('所选数据不存在'));
}
// 格式化
$in = [];
foreach ($ids as $i) {
$i && $in[] = intval($i);
}
if (!$in) {
$this->_json(0, dr_lang('所选数据不存在'));
}
$rows = \Phpcmf\Service::M()->db->table($this->init['table'])->whereIn('id', $in)->get()->getResultArray();
if (!$rows) {
$this->_json(0, dr_lang('所选数据不存在'));
}
foreach ($rows as $row) {
if ($row['status'] != 1) {
if ($tid) {
// 拒绝
$this->_verify_refuse($row);
} else {
// 通过
//本章字数
$slength = $row['length'];
//书籍原字数
$clength = \Phpcmf\Service::L('vwbook',APP_DIR)->cdata($row['cid'],'length');
//|--更新书籍字数
///*
\Phpcmf\Service::M()->table(dr_module_table_prefix(APP_DIR))->update($row['cid'], [
'length' => $slength + $clength
]);
//*/
var_dump($row);
//$this->_verify($row);
}
$this->content_model->update_form_total($row['cid'], $this->form['table']);
}
}
//$this->_json(1, dr_lang('操作成功'));
}vwbook->cdata方法(此项数据无误,我一并贴出来方便寻找错误根源):
// 用于列表关联字段
public function cdata($cid, $field = 'id') {
if (!$cid) {
return dr_lang('未关联');
}
$mid = defined('MOD_DIR') ? MOD_DIR : '';
$this->cid_data[$cid] = isset($this->cid_data[$cid]) && $this->cid_data[$cid] ? $this->cid_data[$cid] : \Phpcmf\Service::M()->table_site($mid)->get($cid);
return $this->cid_data[$cid] ? $this->cid_data[$cid][$field] : dr_lang('关联主题不存在');
}
foreach ($rows as $row) { if ($row['status'] != 1) { if ($tid) { // 拒绝 $this->_verify_refuse($row); } else { // 通过 $vwsons = [ $row['cid'] => $vwson = [ $row['id'] => $row['length'] ], ]; } $this->content_model->update_form_total($row['cid'], $this->form['table']); } }我组合数组,但是得到的结果还是一条。所以跟你说的这个问题不相干啊。官方还给你点赞。。。。问题的点没有找到不是?//组合数组 [cid]=>提交字数 foreach ($rows as $row) { if ($row['status'] != 1) { if ($tid) { // 拒绝 $this->_verify_refuse($row); } else { // 通过 $vwsons[$row['cid']] = $clengths[$row['cid']] = $clengths[$row['cid']] + $row['length']; $this->_verify($row); } $this->content_model->update_form_total($row['cid'], $this->form['table']); } } //获取cid数据 $vwkeys = array_keys($vwsons); //根据cid分别累加字数 foreach ($vwkeys as $vwkey) { //书籍原字数 $clength = \Phpcmf\Service::L('vwbook',APP_DIR)->cdata($vwkey,'length'); //更新书籍字数 \Phpcmf\Service::M()->table(dr_module_table_prefix(APP_DIR))->update($vwkey, [ 'length' => $clength + $vwsons[$vwkey] ]); } $this->_json(1, dr_lang('操作成功'));