Supplier.php 8.9 KB

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