ppypp伦理天堂,91手机在线视频,免费在线观看黄色毛片,夜夜穞天天穞狠狠穞AV美女按摩

聯系官方銷售客服

1835022288

028-61286886

投訴 已解決 模塊表單中些批量審核通過方法,怎么關聯主題中length的字段值 5 0
迅睿CMS版本:4.5.3 #模塊表單 #return
//我在模塊表單中些批量審核通過方法,審核完后更新關聯主題中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('關聯主題不存在');
 }
解決方案
  • 思路有問題,你這種就不是很準確了,先查詢出全部的子內容的列表,然后統一計算相加,然后在更新到主表中,不要你這樣一條條的加了
    官方點評:贊同此解答      獎勵2元現金抵扣券
    精通ThinkPHP框架,精通CI框架,接單開發請私聊
  • 回復@天天向上 我是直接復制官方模塊表單的方法過來修改的

  • 回復@天天向上 所以我是想弄明白,現在更新為啥出現問題,這個批量其實用的很少,審核都需要進去看內容的。這個功能不需要考慮性能問題

  • 回復@天天向上

    	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']);
    		}
    	}

    我組合數組,但是得到的結果還是一條。所以跟你說的這個問題不相干啊。官方還給你點贊。。。。

    問題的點沒有找到不是?

  • 過來結帖,但是那個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:完結之后本帖將不再提供回復