Supplier.php 8.1 KB

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