load->library('session'); $this->load->_model('Model_user','user'); $this->load->_model('Model_shop','shop'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_warehouse','warehouse'); $this->load->_model('Model_productprice','productprice'); $this->load->_model('Model_apiyy','apiyy'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'add')//添加 { $this->_add(); } else if($arg == 'edit')//修改 { $this->_edit($arg_array); } else if($arg == 'del')//修改 { $this->_del(); } else if($arg == 'rows')//修改 { $this->_rows(); } else if($arg == 'code')//修改 { $this->_code($arg_array); } else { $this->_index(); } } //管理 public function _index() { $post = $this->input->post(NULL, TRUE); if(isset($post['page'])) { $page = $this->input->post('page',true); $perpage = $this->input->post('perpage',true); $shopname = $this->input->post('shopname',true); $where = "1=1 "; //数据排序 $order_str = "id asc"; if($shopname) { $where .= " and shopname like '%$shopname%'"; } if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->shop->find_all($where,'id,type,shopname,shortname,estimaterate,mustba,shopid,yyid,tb',$order_str,$start,$perpage); //格式化数据 foreach ($info_list as $key=>$value) { $type = $this->typeclass->read($value['type']); $info_list[$key]['type'] = $type['title']; if($value['mustba'] == 1) { $info_list[$key]['mustba'] = '需要审核'; } else { $info_list[$key]['mustba'] = '不审核'; } if($value['tb'] == 1) { $info_list[$key]['tb'] = '同步'; } else { $info_list[$key]['tb'] = '不同步'; } } $total = $this->shop->find_count($where); $pagenum = ceil($total/$perpage); $over = $total-($start+$perpage); $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list)); echo json_encode($rows);exit; } $this->_Template('shop',$this->data); } //添加 public function _add() { $post = $this->input->post(NULL, TRUE); if(isset($post['shopid'])) { $post['type'] = $this->input->post('type',true); $post['notice'] = $this->input->post('notice',true); $post['shopid'] = $this->input->post('shopid',true); $post['shopname'] = $this->input->post('shopname',true); $post['shortname'] = $this->input->post('shortname',true); $post['shopuser'] = $this->input->post('shopuser',true); $post['shopphone'] = $this->input->post('shopphone',true); $post['brandname'] = $this->input->post('brandname',true); /** $post['companyname'] = $this->input->post('companyname',true); $post['country'] = $this->input->post('country',true); $post['province'] = $this->input->post('province',true); $post['city'] = $this->input->post('city',true); $post['zip'] = $this->input->post('zip',true); $post['adress'] = $this->input->post('adress',true); $post['defaultpricetype'] = $this->input->post('defaultpricetype',true); $post['updcycle'] = $this->input->post('updcycle',true); $post['taxrate'] = $this->input->post('taxrate',true); $post['uphone'] = $this->input->post('uphone',true); **/ $post['estimaterate'] = $this->input->post('estimaterate',true); $post['userexp'] = $this->input->post('userexp',true); $post['mustba'] = $this->input->post('mustba',true); $post['shopcost'] = $this->input->post('shopcost',true); $post['shopcosttext'] = $this->input->post('shopcosttext',true); $post['shopwh'] = $this->input->post('shopwh',true); $post['shopwhtext'] = $this->input->post('shopwhtext',true); $post['edittime'] = time(); $post['addtime'] = time(); $px = $this->shop->find_all("1=1",'*','px desc'); $post['px'] = $px[0]['px']+10; $s = $post; $s['id'] = $post['yyid']; $s['name'] = $post['shortname']; if($post['type'] == '1514') { $z = '跨境'; } else if($post['type'] == '269') { $z = '独-'; } else if($post['type'] == '1514') { $z = '速-'; } $tc = $this->apiyy->get_cjkh($s); if(isset($tc['Data'][0])) { } else { echo json_encode(array('msg'=>$tc['Data'][0]['ErrorMsg'],'success'=>false));exit; } if($this->shop->insert($post)) { echo json_encode(array('msg'=>'添加成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit; } } $this->_Template('shop_add',$this->data); } //修改 public function _edit($arg_array) { $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); $ps = $this->shop->read($id); $post['type'] = $this->input->post('type',true); $post['notice'] = $this->input->post('notice',true); $post['shopid'] = $this->input->post('shopid',true); $post['shopname'] = $this->input->post('shopname',true); $post['shortname'] = $this->input->post('shortname',true); $post['shopuser'] = $this->input->post('shopuser',true); $post['shopphone'] = $this->input->post('shopphone',true); $post['brandname'] = $this->input->post('brandname',true); /** $post['companyname'] = $this->input->post('companyname',true); $post['country'] = $this->input->post('country',true); $post['province'] = $this->input->post('province',true); $post['city'] = $this->input->post('city',true); $post['zip'] = $this->input->post('zip',true); $post['adress'] = $this->input->post('adress',true); $post['defaultpricetype'] = $this->input->post('defaultpricetype',true); $post['updcycle'] = $this->input->post('updcycle',true); $post['taxrate'] = $this->input->post('taxrate',true); $post['uphone'] = $this->input->post('uphone',true); **/ $post['estimaterate'] = $this->input->post('estimaterate',true); $post['userexp'] = $this->input->post('userexp',true); $post['mustba'] = $this->input->post('mustba',true); $post['shopcost'] = $this->input->post('shopcost',true); $post['shopcosttext'] = $this->input->post('shopcosttext',true); $post['shopwh'] = $this->input->post('shopwh',true); $post['shopwhtext'] = $this->input->post('shopwhtext',true); $post['edittime'] = time(); if($this->shop->save($post,$id)) { echo json_encode(array('msg'=>'修改成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit; } } $arg_array = $arg_array[0]; $shop = $this->shop->read($arg_array); $this->data['shop'] = $shop; $this->_Template('shop_edit',$this->data); } //删除 public function _del() { $post = $this->input->post(NULL, TRUE); if(isset($post['s'])) { $id_arr = $this->input->post('s'); $id_arr = explode(',',$id_arr); if(!$id_arr) { echo json_encode(array('msg'=>'参数错误!','success'=>false));exit; } //循环删除记录 foreach ($id_arr as $v) { $this->shop->remove($v); } echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true)); } } //数据 public function _rows() { $post = $this->input->post(NULL, TRUE); if(isset($post['shopcost'])) { $productprice = $this->input->post('shopcost',true); $data = $this->productprice->find_all('1=1'); $list = array(); foreach ($data as $key=>$value) { $list[] = array('id'=>$value['id'],'title'=>$value['name']); } $num = array(); if($productprice != "null") { $num = $this->shop->read($productprice);//找出内容 if($num['shopcost']) { $num = explode('|',trim($num['shopcost'],'|'));//数组化内容 } else { $num = array(); } } echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true)); } if(isset($post['shopwh'])) { $warehouse = $this->input->post('shopwh',true); $data = $this->warehouse->find_all('1=1'); $list = array(); foreach ($data as $key=>$value) { $list[] = array('id'=>$value['id'],'title'=>$value['title']); } $num = array(); if($warehouse != "null") { $num = $this->shop->read($warehouse);//找出内容 if($num['shopwh']) { $num = explode('|',trim($num['shopwh'],'|'));//数组化内容 } else { $num = array(); } } echo json_encode(array('msg'=>($list),'num'=>($num),'success'=>true)); } } public function _code($arg_array) { $shop = $this->shop->read($arg_array[0]); if($shop['type'] == 1514) { header('Location:https://services.us.tiktokshop.com/open/authorize?service_id='.$shop['codeid']);exit; } else { $setting['appkey'] = '26004389'; $setting['secret'] = 'd880d725c67b449c8a601e9b0766955d'; $setting['code'] = 'https://oauth.aliexpress.com/authorize'; $setting['token'] = 'https://oauth.aliexpress.com/token'; if(!$_GET['code']) { header('Location:'.$setting['code'].'?response_type=code&client_id='.$setting['appkey'].'&redirect_uri='.'http://'.$_SERVER['HTTP_HOST'].'/shop/code'.'&state='.$arg_array[0].'&view=web&sp=ae');exit; } $code = $_GET['code']; $url = $setting['token']; $postfields= array('grant_type'=>'authorization_code', 'client_id'=>$setting['appkey'], 'client_secret'=>$setting['secret'], 'code'=>$_GET['code'], 'sp'=>'ae', 'redirect_uri'=>'http://'.$_SERVER['HTTP_HOST'].'/shop/code'); $post_data = ''; foreach($postfields as $key=>$value){ $post_data .="$key=".urlencode($value)."&";} $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); //指定post数据 curl_setopt($ch, CURLOPT_POST, true); //添加变量 curl_setopt($ch, CURLOPT_POSTFIELDS, substr($post_data,0,-1)); $output = curl_exec($ch); $output = json_decode($output,true); print_r($output); $this->shop->save(array('code'=>$output["access_token"],'codetime'=>substr($output["expire_time"],0,10)),$_GET['state']); header('Location:http://'.$_SERVER['HTTP_HOST'].'/user/');exit; } } }