业务经理

微信扫描以上二维码

028-61286886

技术咨询

模块表单中些批量审核通过方法,怎么关联主题中length的字段值

迅睿框架 更新 2021-12-10 17:18:20 zooxen
//我在模块表单中些批量审核通过方法,审核完后更新关联主题中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('关联主题不存在');
 }

方案

  • 天天向上 #1 · 2021-12-10 15:26:35
    思路有问题,你这种就不是很准确了,先查询出全部的子内容的列表,然后统一计算相加,然后在更新到主表中,不要你这样一条条的加了
  • zooxen #2 · 2021-12-10 15:31:37
    天天向上 我是直接复制官方模块表单的方法过来修改的
  • zooxen #3 · 2021-12-10 15:33:03
    天天向上 所以我是想弄明白,现在更新为啥出现问题,这个批量其实用的很少,审核都需要进去看内容的。这个功能不需要考虑性能问题
  • zooxen #4 · 2021-12-10 16:03:31
    天天向上
    	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']);
    		}
    	}
    我组合数组,但是得到的结果还是一条。所以跟你说的这个问题不相干啊。官方还给你点赞。。。。问题的点没有找到不是?
  • zooxen #5 · 2021-12-10 17:18:06
    满意答案
    过来结帖,但是那个foreach为啥没起作用还是没搞明白哪里除了问题,换成以下代码可以解决。
    	//组合数组 [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('操作成功'));
  • zooxen #6 · 2021-12-10 17:18:20
    @zooxen:完结之后本帖将不再提供回复

迅睿系统漏洞

GEO系统
GEO系统(2026-09-15)
运营客户端,防止误触阴影处关闭对话框
独立站群系统
独立站群系统(2026-09-14)
子站独立部署时修复同步附件失败问题
在线客服
在线客服(2026-09-13)
修复删除会话报错问题 删除会话时联动删除聊天图片
在线考试竞赛系统
在线考试竞赛系统(2026-09-12)
增加投票功能 考试功能拓展 注意:更新后需要执行系统更新,更新数...
网上信箱
网上信箱(2026-09-12)
修复新版本兼容问题
GeoSeo收录宝
GeoSeo收录宝(2026-09-12)
1 优化Update.php文件,解决版本在线升级不完整问题 2 ...
GeoSeo工具箱
GeoSeo工具箱(2026-09-11)
修正历史记录推送
微信系统
微信系统(2026-09-11)
增加数据统计总览界面 账号管理增加服务和公众号的区别 菜单管理支持更...
答题系统
答题系统(2026-09-11)
一站式在线答题系统,支持真题考试、题库练习和错题本,适合培训、考证、...
阿里云滑动验证码
阿里云滑动验证码(2026-09-10)
采用阿里云验证码替换迅睿系统自带的图片验证码和滑动验证码。后台设置方...