load->library('session'); $this->load->model('Model_shop','shop'); $this->load->_model('Model_sdzxlist','sdzxlist'); $this->load->_model('Model_apitt','apitt'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'index'){ $this->_index(); }elseif($arg == 'edit'){ $this->_edit($arg_array); }elseif($arg == 'delsc'){ $this->_delsc(); }elseif($arg == 'zczxttznx'){ $this->_zczxttznx(); }else{ exit('No direct script access allowed'); } } private function _index(){ if($this->input->method() == 'post'){ $page = $this->input->post('page',true); $perpage = $this->input->post('perpage',true); $shop = $this->input->post('shop_id',true); $ktime = $this->input->post('ktime',true); $jtime = $this->input->post('jtime',true); $ktime = strtotime($ktime); $jtime = strtotime($jtime); $where = "create_time >= ".$ktime." and create_time < ".$jtime." "; if(!empty($shop)){ $where .= " and shop_id = ".$shop." "; }else{ //$where .= " and shop_id in (".$shop_ids.") "; } //数据排序 $order_str = "id desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } $list = $this->sdzxlist->find_all($where,"id,shop,number,type,status,err_desc,create_time,update_time",$order_str,$start,$perpage); if(empty($list)){ $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([])); echo json_encode($rows);exit; } $type_list = $this->sdzxlist->getType(); $status_list = $this->sdzxlist->getStatus(); $shop_list = $this->shop->find_all("type = 1514"); $shop_id_list = array_column($shop_list,'shopname','id'); foreach($list as $k=>$v){ $list[$k]['type'] = isset($type_list[$v['type']]) ? $type_list[$v['type']] : '无'; $list[$k]['status'] = isset($status_list[$v['status']]) ? $status_list[$v['status']] : '无'; $list[$k]['shop'] = isset($shop_id_list[$v['shop']]) ? $shop_id_list[$v['shop']] : ' '; $list[$k]['create_time'] = empty($v['create_time']) ? "" : date("Y-m-d H:i",$v['create_time']); $operate_str = ""; if(empty($v['status'])){ $operate_str .= "重发"; } $operate_str .= "删除"; $list[$k]['update_time'] = $operate_str; } $total = $this->sdzxlist->find_count($where); $pagenum = ceil($total/$perpage); $over = $total-($start+$perpage); $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list)); echo json_encode($rows);exit; }else{ $user = $this->user->get_api($_SESSION['api']); $usersp = explode('|',trim($user['shop'],'|')); $shop_tt_list = $this->shop->find_all("type = 1514"); $shop_tt_ids = array_column($shop_tt_list,'id'); $shop_allow_ids = array_intersect($usersp, $shop_tt_ids); $this->data['usersp'] = implode(",",$shop_allow_ids); $this->_Template('sdzxlist_index',$this->data); } } private function _edit($arg_array){ if($this->input->method() == 'post'){ exit("no post"); }else{ $id = $arg_array[0]; $info = $this->sdzxlist->read($id); $shop = $this->shop->read($info['shop']); $info['shopname'] = $shop['shopname']; $info['cont'] = json_decode($info['cont'],true); $this->data['info'] = $info; $this->_Template('sdzxlist_edit',$this->data); } } private function _delsc(){ if($this->input->method() == 'post'){ $id = $this->input->post('id'); $info = $this->sdzxlist->read($id); if(empty($info)){ echo json_encode([ 'code'=>-1, 'msg'=>'数据不存在' ],JSON_UNESCAPED_UNICODE); exit; } $id = (int)$id; $this->sdzxlist->remove($id); echo json_encode([ 'code'=>1, 'msg'=>'执行成功' ],JSON_UNESCAPED_UNICODE); exit; }else{ echo json_encode([ 'code'=>1, 'msg'=>'执行成功' ],JSON_UNESCAPED_UNICODE); exit; } } private function _zczxttznx(){ echo json_encode([ 'code'=>-1, 'msg'=>'执行失败' ]);exit; if($this->input->method() == 'post'){ $id = $this->input->post('id'); $info = $this->sdzxlist->read($id); $params = json_decode($info['cont'],true); $shop = $this->shop->read($info['shop']); $list = []; $list['user_id'] = $params['post']['buyer_user_id']; $res = $this->apitt->openZnxWindow($list,$shop); if(empty($res)){ echo json_encode([ 'code'=>-1, 'msg'=>'获取会话ID失败' ]);exit; } if(!isset($res['data']['conversation_id'])){ echo json_encode([ 'code'=>-1, 'msg'=>$res['message'] ]);exit; } $conversation_id = $res['data']['conversation_id']; $notice = $params['content']; $rr = $this->apitt->sendZnxMessage($shop,$notice,$conversation_id); if(empty($rr)){ echo json_encode([ 'code'=>-1, 'msg'=>'发送消息失败' ]);exit; } if(isset($rr['data']['message_id'])) { echo json_encode([ 'code'=>1, 'msg'=>'发送成功' ]);exit; } else { echo json_encode([ 'code'=>-1, 'msg'=>$rr['message'] ]);exit; } }else{ echo json_encode([ 'code'=>-1, 'msg'=>'执行失败' ]);exit; } } }