Supplier.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. use app\admin\model\ActionLog;
  7. class Supplier extends Base
  8. {
  9. //该控制器,除了comprehensiveList方法之外,其他对供应商维护的接口都没用,对供应商维护的接口在Suppler控制器中
  10. /*列表*/
  11. public function list(){
  12. $param = $this->request->filter('trim')->only(['page'=>1,'size'=>10,'name'=>'','code'=>'','is_platform'=>''],'post');
  13. $where = [['is_del',"=",0]];
  14. if ($param['name'] !== "") $where[] = ["name","like", "%{$param['name']}%"];
  15. if ($param['code'] !== "") $where[] = ["code","=", $param['code']];
  16. if ($param['is_platform'] !== "") $where[] = ['is_platform',"=", $param['is_platform']];
  17. $count = Db::name("supplier")->where($where)->count();
  18. $total = ceil($count/$param['size']);
  19. $page = $param['page'] >= $total ? $total : $param['page'];
  20. $list = Db::name('supplier')
  21. ->where($where)
  22. ->page($page, $param['size'])
  23. ->select()
  24. ->toArray();
  25. //这些供应商是否有启用的账号
  26. $has_account = checkHasAccountBySupplierNos(array_column($list, 'code'));
  27. foreach ($list as &$value) {
  28. $value['has_account'] = (int)isset($has_account[$value['code']]);
  29. }
  30. return app_show(0,"获取成功",["list"=>$list,'count'=>$count]);
  31. }
  32. /*新建*/
  33. public function create(){
  34. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
  35. if($name==""){
  36. return error_show(1002,"数据标题不能为空");
  37. }
  38. $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find();
  39. if (!empty($rename)) {
  40. return error_show(1002, "公司名称已存在");
  41. }
  42. $code = rand(0000,9999);
  43. $str = sprintf("%04d",$code);
  44. $tr="GYS-".date("Ymd")."-".$str;
  45. $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :"";
  46. if($source==""){
  47. return error_show(1002,"供应商来源不能为空");
  48. }
  49. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  50. if($type==""){
  51. return error_show(1002,"申请类型不能为空");
  52. }
  53. $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
  54. if($area==""){
  55. return error_show(1002,"大区不能为空");
  56. }
  57. $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
  58. if($city==""){
  59. return error_show(1002,"城市不能为空");
  60. }
  61. $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  62. if($nature==""){
  63. return error_show(1002,"公司类型不能为空");
  64. }
  65. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform'])
  66. :"0";
  67. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :"";
  68. if($ticket_type==""){
  69. return error_show(1002,"回款方式不能为空");
  70. }
  71. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  72. if($legaler==""){
  73. return error_show(1002,"法人不能为空");
  74. }
  75. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  76. if($addr==""){
  77. return error_show(1002,"地址不能为空");
  78. }
  79. $data=[
  80. "name"=>$name,
  81. "source"=>$source,
  82. "code"=>$tr,
  83. "type"=>$type,
  84. "area"=>$area,
  85. "city"=>$city,
  86. "nature"=>$nature,
  87. "legaler"=>$legaler,
  88. "addr"=>$addr,
  89. "is_del"=>0,
  90. "ticket_type"=>$ticket_type,
  91. "addtime"=>date('Y-m-d H:i:s'),
  92. "updatetime"=>date("Y-m-d H:i:s"),
  93. "is_platform"=>$is_platform
  94. ];
  95. $join = Db::name('supplier')->insert($data);
  96. $st = ["order_code"=>"GYS","status"=>0,"action_remark"=>'',"action_type"=>"create"];
  97. ActionLog::logAdd($this->post['token'],$st,"role_share",0,$st);
  98. return $join? error_show(0,"添加成功") :error_show(1002,"添加失败");
  99. }
  100. /*编辑*/
  101. public function edit(){
  102. $id = isset($this->post['id']) && $this->post['id'] !==""? trim($this->post['id']):"";
  103. $ion = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  104. if(empty($ion)){
  105. return error_show(1004,"供应商不存在");
  106. }
  107. $name = isset($this->post['name']) && $this->post['name']!=="" ? $this->post['name']:"";
  108. if($name==""){
  109. return error_show(1002,'数据标题不能为空');
  110. }
  111. $rename =Db::name('supplier')->where(['name'=>$name,'is_del'=>0])->where('id','<>',$id)->find();
  112. if(!empty($rename)){
  113. return error_show(1004,"数据标题已存在");
  114. }
  115. $source = isset($this->post['source']) && $this->post['source'] !==""? $this->post['source']:"";
  116. if($source==""){
  117. return error_show(1002,"供应商来源不能为空");
  118. }
  119. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  120. if($type==""){
  121. return error_show(1002,"申请类型不能为空");
  122. }
  123. $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
  124. if($area==""){
  125. return error_show(1002,"大区不能为空");
  126. }
  127. $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
  128. if($city==""){
  129. return error_show(1002,"城市不能为空");
  130. }
  131. $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  132. if($nature==""){
  133. return error_show(1002,"公司类型不能为空");
  134. }
  135. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  136. if($legaler==""){
  137. return error_show(1002,"法人不能为空");
  138. }
  139. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform'])
  140. :"0";
  141. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  142. if($addr==""){
  143. return error_show(1002,"地址不能为空");
  144. }
  145. $vmp=[
  146. "id"=>$id,
  147. "legaler"=>$legaler,
  148. "name"=>$name,
  149. "source"=>$source,
  150. "type"=>$type,
  151. "area"=>$area,
  152. "city"=>$city,
  153. "nature"=>$nature,
  154. "addr"=>$addr,
  155. "is_del"=>0,
  156. "is_platform"=>$is_platform,
  157. "addtime"=>date('Y-m-d H:i:s'),
  158. "updatetime"=>date("Y-m-d H:i:s")
  159. ];
  160. $ed = Db::name('supplier')->where(['is_del'=>0,'id'=>$id])->save($vmp);
  161. $st = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
  162. ActionLog::logAdd($this->post['token'],$st,"GYS",0,$vmp);
  163. return $ed ? error_show(0,"编辑成功") : error_show(1002,"编辑失败");
  164. }
  165. /*查询*/
  166. public function selec(){
  167. $id= isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  168. if($id==""){
  169. return error_show(1002,"供应商不存在");
  170. }
  171. $se = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  172. return app_show(0,"获取成功",$se);
  173. }
  174. /*删除*/
  175. public function del(){
  176. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  177. $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
  178. if($sup==false){
  179. return error_show(1002,"供应商信息不存在");
  180. }
  181. $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  182. if($supp){
  183. // $st = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"del"];
  184. // ActionLog::logAdd($this->post['token'],$st,"GYS",0,$supp);
  185. return error_show(0,"供应商信息删除成功");
  186. }else{
  187. return error_show(1002,"供应商信息删除失败");
  188. }
  189. }
  190. //公司汇总列表(供应商、客户和公司合并)
  191. public function comprehensiveList()
  192. {
  193. $post = $this->request->only(['companyNo' => '', 'name' => '', 'type' => '', 'page' => 1, 'size' => 10], 'post', 'trim');
  194. $userCommon = \app\admin\common\User::getIns();
  195. $rs = $userCommon->handle('hqList', [
  196. 'code' => $post['companyNo'],
  197. 'name'=>$post['name'],
  198. 'type'=>$post['type'],
  199. 'page'=>$post['page'],
  200. 'size'=>$post['size'],
  201. 'level'=>$this->level,
  202. 'account_id'=>$this->uid
  203. ]);
  204. return json_show($rs['code'], $rs['message'],$rs['data']);
  205. }
  206. }