request->isGet()) { $this->mid = input('mid'); $this->project_id = input('project_id'); $this->merchant = $this->app->db->name('merchant_list')->where(array('id' => $this->mid))->find(); $this->project = $this->app->db->name('merchant_project')->where(array('id' => $this->project_id))->find(); $this->title = '商户通道关联渠道列表'; $w = array ( 'mid' => $this->mid, 'project_id' => $this->project_id, ); $relation = $this->app->db->name($this->table)->where($w)->select()->toArray(); foreach ($relation as $k => $v) { $this->relation[$v['pid']] = $v; } $w = array ( 'status' => 1, 'is_deleted' => 0, ); $this->list = $this->app->db->name('ChannelList')->where($w)->select()->toArray(); foreach ($this->list as $k => $v) { $this->list[$k]['product'] = $this->app->db->name('ChannelProduct')->where('cid',$v['id'])->where($w)->select()->toArray(); foreach ($this->list[$k]['product'] as $k1 => $v1) { # 可用面值 if ($this->list[$k]['product'][$k1]['value']) { $this->list[$k]['product'][$k1]['value'] = explode(',', $this->list[$k]['product'][$k1]['value']); } else { $this->list[$k]['product'][$k1]['value'] = array(); } if (isset($this->relation[$v1['id']]) && $this->relation[$v1['id']]) { $this->list[$k]['product'][$k1]['select'] = 1; $this->list[$k]['product'][$k1]['cash'] = explode(',', $this->relation[$v1['id']]['cash']); $this->list[$k]['product'][$k1]['sort'] = $this->relation[$v1['id']]['sort']; } else { $this->list[$k]['product'][$k1]['select'] = 0; $this->list[$k]['product'][$k1]['cash'] = array(); $this->list[$k]['product'][$k1]['sort'] = $v1['sort']; } } } $this->_form($this->table, 'setting','',[],$this->list); } else { $data = input(); $mid = $data['mid']; $project_id = $data['project_id']; $all = $this->app->db->name($this->table)->where(array('mid' => $mid, 'project_id' => $project_id))->select()->toArray(); $select = $product_key = array(); if ($all) { foreach ($all as $k => $v) { $select[$v['pid']] = $v; } } if ($data['pid']) { foreach ($data['pid'] as $k => $v) { $t = explode('|', $v); $pid = $t[0]; $cid = $t[1]; $product = $this->app->db->name('ChannelProduct')->where(array('id' => $pid))->find(); if ($product) { $update['product_key'] = $product['key']; if (isset($data['sort_' . $pid]) && $data['sort_' . $pid]) { $update['sort'] = $data['sort_' . $pid]; } if (isset($data['cash_' . $pid]) && $data['cash_' . $pid]) { $update['cash'] = implode(',', $data['cash_' . $pid]); } else { $update['cash'] = ''; } if (isset($select[$pid]) && $select[$pid]) { $update['mid'] = $mid; $update['project_id'] = $project_id; $update['cid'] = $cid; $update['pid'] = $pid; $this->app->db->name($this->table)->where(array('id' => $select[$pid]['id']))->update($update); unset($select[$pid]); } else { $update['mid'] = $mid; $update['project_id'] = $project_id; $update['cid'] = $cid; $update['pid'] = $pid; $this->app->db->name($this->table)->insert($update); } } } } if ($select) { # 删除 foreach ($select as $k => $v) { $this->app->db->name($this->table)->where(array('id' => $v['id']))->delete(); } } $this->success('操作成功', ''); } } }