Custom.php 4.4 KB

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