<?php
namespace app\station\controller\v1;
use app\station\model\DemandSourceModel;
use think\Controller;
/**
 * 需求来源API接口控制器
 * 负责需求来源的增删改查
 * Class DemandSource
 * @package app\station\controller
 */
class DemandSource extends Controller
{
    /**
 * 基站需求来源数据列表
 */
    public function demandSource_list()
    {
    	  $model=new DemandSourceModel;
    	  $data=$model->selectDemandSource();
          if($data['code']==200){
             if($data['data']){
               return jsonSucc('','suceeess',$data['data']);
             }else{
               return jsonSucc('20065','Business line data does not exist');
             }
          }else{
               return jsonSucc('20063','Query error please try again');
          }
    	  
    }
/**
 * 添加基站需求来源
 */
      public function demandSource_add()
    {
    	$parem=$this->request->post();
    	if($parem){
    	 $model=new DemandSourceModel;
    	 $result=$model->insertDemandSource($parem);
    	 if($result['code']==200){
           return jsonSucc('200','suceess');
    	 }else{
    	   return jsonSucc('200001','error');
    	 }
    	}else{
    		return jsonSucc('1000001','error');
    	}
    }
/**
 * 修改基站需求来源
 */
     public function demandSource_edit()
    {
    	 $parem=$this->request->post();
    	if($parem){
    	 $model=new DemandSourceModel;
    	 $result=$model->updDemandSource($parem);
    	 if($result['code']==10001){
    	 	return jsonSucc('200001','id不存在');
    	 }
    	 if($result['code']==200){
           return jsonSucc('200','suceess');
    	 }else{
    	   return jsonSucc('200001','error');
    	 }
    	}else{
    		return jsonSucc('1000001','error');
    	}
    }
/**
 * 获取修改基站需求来源数据
 */
    public function geteditdemandSource()
    {
    	$parem=$this->request->post();
    	 $model=new DemandSourceModel;
    	 $result=$model->updselectDemandSource($parem);
    	  if($result['code']==10001){
    	  	return jsonSucc('200001','暂无找到id');
    	  }else{
    	  	 return jsonSucc('','suceess',$result['data']);
    	  }
    	 
    }
/**
 * 删除需求来源数据（软删除）
 */
     public function demandSource_del()
    { 
      $parem=$this->request->post();
    	if($parem){
    	 $model=new DemandSourceModel;
    	 $result=$model->delDemandSource($parem);
    	 switch ($result['code']) {
    	 	case '10001':
    	 		 return jsonSucc('200001','暂无找到id');
    	 		break;
    	 	
    	 	case '200':
    	 		 return jsonSucc('200','suceess');
    	 		break;

    	 	default:
    	 		return jsonSucc('1000001','error');
    	 		break;
    	 }
    	}else{
    		return jsonSucc('1000001','error');
    	}
    }
}