| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use \think\Request;
- use \think\Db;
- /**
- * 客户管理接口
- */
- class Custom extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function index()
- {
- $this->success('请求成功');
- }
- /**
- * 获取客户信息
- *
- * @ApiMethod GET
- *
- */
- public function getCustom(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $field = 'rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称';
- $list = db('产品_基本资料')->distinct(true)->field($field)->order('客户编号 asc')->select();
- $this->success('请求成功',$list);
- }
- /**
- * 客户资料管理
- *
- * @ApiMethod GET
- *
- */
- public function getCustomInfo(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- if (!isset($params['class'])){
- $this->error('参数错误');
- }
- $class = '';
- if ($params['class'] == 1){
- $class = '客户';
- }else{
- $class = '供应商';
- }
- $search = $params['search'];
- $limit = $params['limit'];
- if (empty($limit)){
- $limit = 15;
- }
- $pages = $params['page'];
- if (empty($pages)){
- $pages = 1;
- }
- $where['类型'] = $class;
- if (!empty($search)){
- $where['编号|名称|地址|联系人|业务员'] = array('like','%'.$search.'%');
- }
- $field = 'rtrim(编号) as 编号,rtrim(名称) as 名称,rtrim(简称) as 简称,rtrim(地址) as 地址,rtrim(联系人) as 联系人,rtrim(电话) as 电话,业务员,rtrim(币种) as 币种,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqId';
- $list = db('erp_客户供应商')->where($where)->field($field)->limit($limit)->page($pages)->select();
- $total = db('erp_客户供应商')->where($where)->count();
- $data['data'] = $list;
- $data['total'] = $total;
- $this->success('请求成功',$data);
- }
- /**
- * 供应商资料查改
- *
- * @ApiMethod POST
- * @params array data
- */
- public function edit(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (empty($params) || !isset($params['UniqId'])){
- $this->error('参数不能为空');
- }
- $data = [];
- if (!empty($params['code'])){
- $data['编号'] = $params['code'];
- }
- if (!empty($params['name'])){
- $data['名称'] = $params['name'];
- }
- if (!empty($params['refer'])){
- $data['简称'] = $params['refer'];
- }
- if (!empty($params['add'])){
- $data['地址'] = $params['add'];
- }
- if (!empty($params['department_code'])){
- $data['对口部门'] = $params['department_code'];
- }
- if (!empty($params['contacts'])){
- $data['联系人'] = $params['contacts'];
- }
- if (!empty($params['phone'])){
- $data['电话'] = $params['phone'];
- }
- if (!empty($params['salesman'])){
- $data['业务员'] = $params['salesman'];
- }
- if (!empty($params['currency'])){
- $data['币种'] = $params['currency'];
- }
- $sql = db('erp_客户供应商')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
- $res = Db::query($sql);
- if ($res !== false){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- }
|