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