Custom.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use \think\Request;
  5. use \think\Db;
  6. /**
  7. * 客户管理接口
  8. */
  9. class Custom extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 首页
  15. *
  16. */
  17. public function index()
  18. {
  19. $this->success('请求成功');
  20. }
  21. /**
  22. * 获取客户信息
  23. *
  24. * @ApiMethod GET
  25. *
  26. */
  27. public function getCustom(){
  28. if (Request::instance()->isGet() == false){
  29. $this->error('非法请求');
  30. }
  31. $field = 'rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称';
  32. $list = db('产品_基本资料')->distinct(true)->field($field)->order('客户编号 asc')->select();
  33. $this->success('请求成功',$list);
  34. }
  35. /**
  36. * 客户资料管理
  37. *
  38. * @ApiMethod GET
  39. *
  40. */
  41. public function getCustomInfo(){
  42. if (Request::instance()->isGet() == false){
  43. $this->error('非法请求');
  44. }
  45. $params = Request::instance()->param();
  46. if (!isset($params['class'])){
  47. $this->error('参数错误');
  48. }
  49. $class = '';
  50. if ($params['class'] == 1){
  51. $class = '客户';
  52. }else{
  53. $class = '供应商';
  54. }
  55. $search = $params['search'];
  56. $limit = $params['limit'];
  57. if (empty($limit)){
  58. $limit = 15;
  59. }
  60. $pages = $params['page'];
  61. if (empty($pages)){
  62. $pages = 1;
  63. }
  64. $where['类型'] = $class;
  65. if (!empty($search)){
  66. $where['编号|名称|地址|联系人|业务员'] = array('like','%'.$search.'%');
  67. }
  68. $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';
  69. $list = db('erp_客户供应商')->where($where)->field($field)->limit($limit)->page($pages)->select();
  70. $total = db('erp_客户供应商')->where($where)->count();
  71. $data['data'] = $list;
  72. $data['total'] = $total;
  73. $this->success('请求成功',$data);
  74. }
  75. /**
  76. * 供应商资料查改
  77. *
  78. * @ApiMethod POST
  79. * @params array data
  80. */
  81. public function edit(){
  82. if (Request::instance()->isPost() == false){
  83. $this->error('非法请求');
  84. }
  85. $params = Request::instance()->post();
  86. if (empty($params) || !isset($params['UniqId'])){
  87. $this->error('参数不能为空');
  88. }
  89. $data = [];
  90. if (!empty($params['code'])){
  91. $data['编号'] = $params['code'];
  92. }
  93. if (!empty($params['name'])){
  94. $data['名称'] = $params['name'];
  95. }
  96. if (!empty($params['refer'])){
  97. $data['简称'] = $params['refer'];
  98. }
  99. if (!empty($params['add'])){
  100. $data['地址'] = $params['add'];
  101. }
  102. if (!empty($params['department_code'])){
  103. $data['对口部门'] = $params['department_code'];
  104. }
  105. if (!empty($params['contacts'])){
  106. $data['联系人'] = $params['contacts'];
  107. }
  108. if (!empty($params['phone'])){
  109. $data['电话'] = $params['phone'];
  110. }
  111. if (!empty($params['salesman'])){
  112. $data['业务员'] = $params['salesman'];
  113. }
  114. if (!empty($params['currency'])){
  115. $data['币种'] = $params['currency'];
  116. }
  117. $sql = db('erp_客户供应商')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
  118. $res = Db::query($sql);
  119. if ($res !== false){
  120. $this->success('更新成功');
  121. }else{
  122. $this->error('更新失败');
  123. }
  124. }
  125. }