//我在模塊表單中些批量審核通過方法,審核完后更新關聯(lián)主題中l(wèi)ength的字段值,現(xiàn)在測試完,數(shù)據(jù)表只更新一個所選內(nèi)容的字數(shù),不知道哪里除了問題。。
// 后臺批量審核
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('所選數(shù)據(jù)不存在'));
}
// 格式化
$in = [];
foreach ($ids as $i) {
$i && $in[] = intval($i);
}
if (!$in) {
$this->_json(0, dr_lang('所選數(shù)據(jù)不存在'));
}
$rows = \Phpcmf\Service::M()->db->table($this->init['table'])->whereIn('id', $in)->get()->getResultArray();
if (!$rows) {
$this->_json(0, dr_lang('所選數(shù)據(jù)不存在'));
}
foreach ($rows as $row) {
if ($row['status'] != 1) {
if ($tid) {
// 拒絕
$this->_verify_refuse($row);
} else {
// 通過
//本章字數(shù)
$slength = $row['length'];
//書籍原字數(shù)
$clength = \Phpcmf\Service::L('vwbook',APP_DIR)->cdata($row['cid'],'length');
//|--更新書籍字數(shù)
///*
\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方法(此項數(shù)據(jù)無誤,我一并貼出來方便尋找錯誤根源):
// 用于列表關聯(lián)字段
public function cdata($cid, $field = 'id') {
if (!$cid) {
return dr_lang('未關聯(lián)');
}
$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('關聯(lián)主題不存在');
}
回復@天天向上 我是直接復制官方模塊表單的方法過來修改的
回復@天天向上 所以我是想弄明白,現(xiàn)在更新為啥出現(xiàn)問題,這個批量其實用的很少,審核都需要進去看內(nèi)容的。這個功能不需要考慮性能問題
回復@天天向上
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']); } }我組合數(shù)組,但是得到的結果還是一條。所以跟你說的這個問題不相干啊。官方還給你點贊。。。。
問題的點沒有找到不是?
過來結帖,但是那個foreach為啥沒起作用還是沒搞明白哪里除了問題,換成以下代碼可以解決。
//組合數(shù)組 [cid]=>提交字數(shù) 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數(shù)據(jù) $vwkeys = array_keys($vwsons); //根據(jù)cid分別累加字數(shù) foreach ($vwkeys as $vwkey) { //書籍原字數(shù) $clength = \Phpcmf\Service::L('vwbook',APP_DIR)->cdata($vwkey,'length'); //更新書籍字數(shù) \Phpcmf\Service::M()->table(dr_module_table_prefix(APP_DIR))->update($vwkey, [ 'length' => $clength + $vwsons[$vwkey] ]); } $this->_json(1, dr_lang('操作成功'));