123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Devicemaster extends Start_Controller {
- public function __construct(){
- parent::__construct();
- $this->load->library('session');
- $this->load->_model('Model_devicemaster','devicemaster');
-
- }
- //定义方法的调用规则 获取URI第二段值
- public function _remap($arg,$arg_array)
- {
- if($arg == 'add')
- {
- $this->_add();
- }
- else if($arg == 'edit')
- {
- $this->_edit($arg_array);
- }
- else if($arg == 'see')
- {
- $this->_see($arg_array);
- }
- else if($arg == 'data')
- {
-
- $this->_data();
- }
- else if($arg == 'del')
- {
- $this->_del();
- }
- else if($arg == 'indexexcel'){
- $this->_indexexcel();
- }
- else
- {
- $this->_index();
- }
- }
- public $depart_list =[
- 1=>"独立站",
- 2=>"Tiktok",
- 3=>"亚马逊",
- 4=>"速卖通",
- 5=>"其他",
- ];
- public $plat_list = [
- 1=>"独立站",
- 2=>"Tiktok",
- 3=>"亚马逊",
- 4=>"速卖通",
- 5=>"其他",
- ];
- public $type_list = [
- 1=>"站内",
- 2=>"站外",
- ];
- public $shop_list = [
- 1=>"Alipearl",
- 2=>"WestKiss",
- 3=>"Asteria",
- 4=>"Wiggins",
- 5=>"Yolissa",
- 6=>"SuperNova",
- 7=>"无",
- ];
- public function _index(){
-
- $this->data['depart_list'] = $this->depart_list;
- $this->data['plat_list'] = $this->plat_list;
- $this->data['type_list'] = $this->type_list;
- $this->data['shop_list']=$this->shop_list;
-
- $this->_Template("devicemaster",$this->data);
- }
- public function _add(){
-
-
- $post = $this->input->post(NULL, TRUE);
- if(!empty($post))
- {
- $information = [];
- $tmp = $this->input->post('information',true);
- foreach($tmp as $v){
- if(!empty($v)){
- $information[] = $v;
- }
-
- }
- $time = date("Y-m-d H:i:s",time());
- $insert_data =[
- 'depart_id'=>$this->input->post('depart_id',true),
- 'type_id'=>$this->input->post('type_id',true),
- 'plat_id'=>$this->input->post('plat_id',true),
- 'shop_id'=>$this->input->post('shop_id',true),
- 'mobile_type'=>$this->input->post('mobile_type',true),
- 'mobile_color'=>$this->input->post('mobile_color',true),
- 'mobile'=>$this->input->post('mobile',true),
- 'mobile_user'=>$this->input->post('mobile_user',true),
- 'id_account'=>$this->input->post('id_account',true),
- 'id_password'=>$this->input->post('id_password',true),
- 'unlock_password'=>$this->input->post('unlock_password',true),
- 'remarks'=>$this->input->post('remarks',true),
- 'purpose'=>$this->input->post('purpose',true),
- "information"=>json_encode($information,JSON_UNESCAPED_UNICODE),
- "is_delete"=>0,
- "create_time"=>$time,
- "update_time"=>$time
- ];
-
- if($this->devicemaster->insert( $insert_data))
- {
- echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
- }
- else
- {
- echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
- }
- }
- $this->data['depart_list'] = $this->depart_list;
- $this->data['plat_list'] = $this->plat_list;
- $this->data['type_list'] = $this->type_list;
- $this->data['shop_list']=$this->shop_list;
- $this->_Template('devicemaster_add',$this->data);
- }
- public function _edit($arg_array){
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['id'])){
- $id = $this->input->post('id',true);
- $information = [];
- $tmp = $this->input->post('information',true);
- foreach($tmp as $v){
- if(!empty($v)){
- $information[] = $v;
- }
-
- }
- $time = date("Y-m-d H:i:s",time());
- $update_data =[
- 'depart_id'=>$this->input->post('depart_id',true),
- 'type_id'=>$this->input->post('type_id',true),
- 'plat_id'=>$this->input->post('plat_id',true),
- 'shop_id'=>$this->input->post('shop_id',true),
- 'mobile_type'=>$this->input->post('mobile_type',true),
- 'mobile_color'=>$this->input->post('mobile_color',true),
- 'mobile'=>$this->input->post('mobile',true),
- 'mobile_user'=>$this->input->post('mobile_user',true),
- 'id_account'=>$this->input->post('id_account',true),
- 'id_password'=>$this->input->post('id_password',true),
- 'unlock_password'=>$this->input->post('unlock_password',true),
- 'remarks'=>$this->input->post('remarks',true),
- 'purpose'=>$this->input->post('purpose',true),
- "information"=>json_encode($information,JSON_UNESCAPED_UNICODE),
- "is_delete"=>0,
- "update_time"=>$time
- ];
- if($this->devicemaster->save($update_data,$id))
- {
- echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
- }
- else
- {
- echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
- }
- }
- $id= $arg_array[0];
- $info = $this->devicemaster->read($id);
- $info['information'] = json_decode($info['information'],true);
- $this->data['depart_list'] = $this->depart_list;
- $this->data['plat_list'] = $this->plat_list;
- $this->data['type_list'] = $this->type_list;
- $this->data['shop_list']=$this->shop_list;
- $this->data['info'] = $info;
- $this->_Template('devicemaster_edit',$this->data);
- }
- public function _see(){
-
- }
- 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;
- }
- $time = date("Y-m-d H:i:s",time());
- //循环删除记录
- foreach ($id_arr as $v)
- {
- if(!empty($v)){
- $this->devicemaster->save(['is_delete'=>1,'delete_time'=>$time],$v);
- }
-
- }
- echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
-
-
- }
- }
- public function _data(){
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['page']))
- {
- $page = $this->input->post('page',true);
- $perpage = $this->input->post('perpage',true);
-
- $depart_id = $this->input->post('depart_id',true);
- $type_id = $this->input->post('type_id',true);
- $plat_id = $this->input->post('plat_id',true);
- $shop_id = $this->input->post('shop_id',true);
- $mobile= $this->input->post('mobile',true);
- $mobile_user = $this->input->post('mobile_user',true);
- $where = " is_delete = 0";
- if($depart_id)
- {
- $where .= " and depart_id = '$depart_id'";
- }
- if($type_id)
- {
- $where .= " and type_id = '$type_id'";
- }
- if($plat_id)
- {
- $where .= " and plat_id = '$plat_id'";
- }
- if( $shop_id)
- {
- $where .= " and shop_id = ' $shop_id'";
- }
- if($mobile)
- {
- $where .= " and mobile like '%$mobile%'";
- }
- if($mobile_user)
- {
- $where .= " and mobile_user like '%$mobile_user%'";
- }
- //数据排序
- $order_str = "id asc";
- if(empty($page))
- {
- $start = 0;
- $perpage = 1;
- }
- else
- {
- $start = ($page - 1)*$perpage;
- }
- //取得信息列表
- $info_list = $this->devicemaster->find_all($where,'id,mobile,mobile_user,depart_id,type_id,shop_id,plat_id,mobile_type,mobile_color,id_account,id_password,unlock_password,remarks,purpose,information',$order_str,$start,$perpage);
- //格式化数据
- foreach ($info_list as $key=>$value)
- {
- // if($value['status'] == 1)
- // {
- // $info_list[$key]['status'] = '正常';
- // }
- // else
- // {
- // $info_list[$key]['status'] = '禁用';
- // }
-
- if(isset($this->depart_list[$info_list[$key]['depart_id']])){
- $info_list[$key]['depart_id'] = $this->depart_list[$info_list[$key]['depart_id']];
- }
- if(isset($this->plat_list[$info_list[$key]['plat_id']])){
- $info_list[$key]['plat_id'] =$this->plat_list[$info_list[$key]['plat_id']];
- }
- if(isset($this->shop_list[$info_list[$key]['shop_id']])){
- $info_list[$key]['shop_id'] = $this->shop_list[$info_list[$key]['shop_id']];
- }
- if(isset($this->type_list[$info_list[$key]['type_id']])){
- $info_list[$key]['type_id'] = $this->type_list[$info_list[$key]['type_id']];
- }
- $information_str = "";
- $information = json_decode($info_list[$key]['information'],true);
- if(empty($information)){
- $info_list[$key]['information'] = "";
- }else{
- foreach($information as $index=>$item){
- $information_str .="<div style='margin-bottom:3px;border:1px dashed #000'>".$item."</div>";
- }
- $info_list[$key]['information'] = $information_str;
- }
-
- }
- $total = $this->devicemaster->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;
- }
- }
- public function _indexexcel(){
- $depart_id = $this->input->post('depart_id',true);
- $type_id = $this->input->post('type_id',true);
- $plat_id = $this->input->post('plat_id',true);
- $shop_id = $this->input->post('shop_id',true);
- $mobile= $this->input->post('mobile',true);
- $mobile_user = $this->input->post('mobile_user',true);
- $where = " is_delete = 0";
- if($depart_id)
- {
- $where .= " and depart_id = '$depart_id'";
- }
- if($type_id)
- {
- $where .= " and type_id = '$type_id'";
- }
- if($plat_id)
- {
- $where .= " and plat_id = '$plat_id'";
- }
- if( $shop_id)
- {
- $where .= " and shop_id = ' $shop_id'";
- }
- if($mobile)
- {
- $where .= " and mobile like '%$mobile%'";
- }
- if($mobile_user)
- {
- $where .= " and mobile_user like '%$mobile_user%'";
- }
- //数据排序
- $order_str = "id asc";
-
- //取得信息列表
- $info_list = $this->devicemaster->find_all($where,'id,mobile,mobile_user,depart_id,type_id,shop_id,plat_id,mobile_type,mobile_color,id_account,id_password,unlock_password,remarks,purpose,information',$order_str,0,null);
- //格式化数据
- $final_list = [];
- foreach ($info_list as $key=>$value)
- {
- $final_list[$key]['ID'] = $value['id'];
- $final_list[$key]['手机号'] = $value['mobile'];
- $final_list[$key]['手机用户'] = $value['mobile_user'];
- $final_list[$key]['部门'] = isset($this->depart_list[$value['depart_id']])?$this->depart_list[$value['depart_id']]:'';
- $final_list[$key]['平台'] = isset($this->plat_list[$value['plat_id']])?$this->plat_list[$value['plat_id']]:'';
- $final_list[$key]['店铺'] = isset($this->shop_list[$value['shop_id']])?$this->shop_list[$value['shop_id']]:'';
- $final_list[$key]['手机类型'] = $value['mobile_type'];
- $final_list[$key]['手机颜色'] = $value['mobile_color'];
- $final_list[$key]['ID账号'] = $value['id_account'];
- $final_list[$key]['ID密码'] = $value['id_password'];
- $final_list[$key]['解锁密码'] = $value['unlock_password'];
- $final_list[$key]['备注'] = $value['remarks'];
- $final_list[$key]['用途'] = $value['purpose'];
-
-
- $information_str = "";
- $information = json_decode($info_list[$key]['information'],true);
- if(empty($information)){
- $information_str = "";
- }else{
- // foreach($information as $index=>$item){
- // $information_str .= $item.";";
- // }
- $information_str = json_encode($information,JSON_UNESCAPED_UNICODE);
- }
- $final_list[$key]['信息'] = $information_str;
-
- }
- echo json_encode(['data'=>$final_list,'success'=>true,'msg'=>'导出成功']);exit;
-
- }
- }
|