Custom.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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('产品_基本资料')->where('客户名称','not null')->distinct(true)->field($field)->order('客户编号 asc')->select();
  33. $Ydata = [];
  34. $Jdata = [];
  35. foreach ($list as $key => $value){
  36. if (substr($value['客户编号'],0,1) == 'Y'){
  37. array_push($Ydata,$value);
  38. }else{
  39. array_push($Jdata,$value);
  40. }
  41. }
  42. $data['印刷产品'] = $Ydata;
  43. $data['糊盒产品'] = $Jdata;
  44. $this->success('请求成功',$data);
  45. }
  46. /**
  47. * 客户资料管理
  48. *
  49. * @ApiMethod GET
  50. *
  51. */
  52. public function getCustomInfo(){
  53. if (Request::instance()->isGet() == false){
  54. $this->error('非法请求');
  55. }
  56. $params = Request::instance()->param();
  57. if (!isset($params['class'])){
  58. $this->error('参数错误');
  59. }
  60. $class = '';
  61. if ($params['class'] == 1){
  62. $class = '客户';
  63. }else{
  64. $class = '供应商';
  65. }
  66. $search = $params['search'];
  67. $limit = $params['limit'];
  68. if (empty($limit)){
  69. $limit = 15;
  70. }
  71. $pages = $params['page'];
  72. if (empty($pages)){
  73. $pages = 1;
  74. }
  75. $where['类型'] = $class;
  76. if (!empty($search)){
  77. $where['编号|名称|地址|联系人|业务员'] = array('like','%'.$search.'%');
  78. }
  79. $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';
  80. $list = db('erp_客户供应商')->where($where)->field($field)->limit($limit)->page($pages)->select();
  81. $total = db('erp_客户供应商')->where($where)->count();
  82. $data['data'] = $list;
  83. $data['total'] = $total;
  84. $this->success('请求成功',$data);
  85. }
  86. /**
  87. * 供应商资料查改
  88. *
  89. * @ApiMethod POST
  90. * @params array data
  91. */
  92. public function edit(){
  93. if (Request::instance()->isPost() == false){
  94. $this->error('非法请求');
  95. }
  96. $params = Request::instance()->post();
  97. if (empty($params) || !isset($params['UniqId'])){
  98. $this->error('参数不能为空');
  99. }
  100. $data = [];
  101. if (!empty($params['code'])){
  102. $data['编号'] = $params['code'];
  103. }
  104. if (!empty($params['name'])){
  105. $data['名称'] = $params['name'];
  106. }
  107. if (!empty($params['refer'])){
  108. $data['简称'] = $params['refer'];
  109. }
  110. if (!empty($params['add'])){
  111. $data['地址'] = $params['add'];
  112. }
  113. if (!empty($params['department_code'])){
  114. $data['对口部门'] = $params['department_code'];
  115. }
  116. if (!empty($params['contacts'])){
  117. $data['联系人'] = $params['contacts'];
  118. }
  119. if (!empty($params['phone'])){
  120. $data['电话'] = $params['phone'];
  121. }
  122. if (!empty($params['salesman'])){
  123. $data['业务员'] = $params['salesman'];
  124. }
  125. if (!empty($params['currency'])){
  126. $data['币种'] = $params['currency'];
  127. }
  128. $sql = db('erp_客户供应商')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
  129. $res = Db::query($sql);
  130. if ($res !== false){
  131. $this->success('更新成功');
  132. }else{
  133. $this->error('更新失败');
  134. }
  135. }
  136. }