WareHouse.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class WareHouse extends BaseController
  7. {
  8. public function __construct(App $app)
  9. {
  10. parent::__construct($app);
  11. $post =$this->request->post();
  12. $token = isset($post['token']) ? trim($post['token']) : "";
  13. // if($token==""){
  14. // return error_show(101,'token不能为空');
  15. //
  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 add(){
  24. $post =$this->request->post();
  25. $name = isset($post['name'])&& $post['name']!='' ?trim($post['name']) :'';
  26. if($name==''){
  27. return error_show(1004,'参数name 不能为空');
  28. }
  29. $supplier = isset($post['supplierNo'])&& $post['supplierNo']!='' ?trim($post['supplierNo']) :'';
  30. if($supplier==''){
  31. return error_show(1004,'参数supplierNo 不能为空');
  32. }
  33. $supplierinfo = Db::name("supplier")->where(["code"=>$supplier])->find();
  34. if(empty($supplierinfo)){
  35. return error_show(1004,'未找到供应商数据');
  36. }
  37. $wsmtype = isset($post['wsmtype'])&& $post['wsmtype']!='' ?intval($post['wsmtype']) :'';
  38. if($wsmtype==''){
  39. return error_show(1004,'参数wsmtype 不能为空');
  40. }
  41. $isT = Db::name('warehouse_info')->where([['name',"=",$name]])->find();
  42. if(!empty($isT)){
  43. return error_show(1004,'仓库名称已存在');
  44. }
  45. $addr = isset($post['addr'])&& $post['addr']!='' ?trim($post['addr']) :'';
  46. if($addr==''){
  47. return error_show(1004,'参数addr 不能为空');
  48. }
  49. $contactor = isset($post['contactor'])&& $post['contactor']!='' ?trim($post['contactor']) :'';
  50. if($contactor==''){
  51. return error_show(1004,'参数contactor 不能为空');
  52. }
  53. $mobile = isset($post['mobile'])&& $post['mobile']!='' ?trim($post['mobile']) :'';
  54. if($mobile==''){
  55. return error_show(1004,'参数mobile 不能为空');
  56. }
  57. $position = isset($post['position'])&& $post['position']!='' ?trim($post['position']) :'';
  58. $data =[
  59. 'wsm_code'=>makeNo("WSM"),
  60. 'name'=>$name,
  61. 'wsm_type'=>$wsmtype,
  62. 'supplierNo'=>$supplier,
  63. 'addr'=>$addr,
  64. 'contactor'=>$contactor,
  65. 'mobile'=>$mobile,
  66. 'position'=>$position,
  67. 'status'=>1,
  68. 'addtime'=>date("Y-m-d H:i:s"),
  69. 'updatetime'=>date("Y-m-d H:i:s")
  70. ];
  71. $add = Db::name('warehouse_info')->insert($data);
  72. return $add ? app_show(0,'仓库创建成功'): error_show(1005,'仓库创建失败');
  73. }
  74. public function list(){
  75. $post =$this->request->post();
  76. $condition = [['is_del'=>0]];
  77. $supplier = isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :"";
  78. if($supplier!=""){
  79. $condition[]=["supplierNo"=>$supplier];
  80. }
  81. $supplier = isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :"";
  82. if($supplier!=""){
  83. $condition[]=["supplierNo"=>$supplier];
  84. }
  85. $wsm_code = isset($post['wsm_code'])&&$post['wsm_code']!="" ? trim($post['wsm_code']) :"";
  86. if($wsm_code!=""){
  87. $condition[]=["wsm_code"=>$wsm_code];
  88. }
  89. $start = isset($post['start'])&&$post['start']!="" ? $post['start'] :"";
  90. if($start!=""){
  91. $condition[]=["addtime"=>[">=",$start]];
  92. }
  93. $end = isset($post['end'])&&$post['end']!="" ? $post['end'] :"";
  94. if($start!=""){
  95. $condition[]=["addtime"=>[">=",$end]];
  96. }
  97. $mobile = isset($post['mobile'])&&$post['mobile']!="" ? trim($post['mobile']) :"";
  98. if($mobile!=""){
  99. $condition[]=["mobile"=>["like","%{$mobile}%"]];
  100. }
  101. $contactor = isset($post['contactor'])&&$post['contactor']!="" ? trim($post['contactor']) :"";
  102. if($contactor!=""){
  103. $condition[]=["contactor"=>["like","%{$contactor}%"]];
  104. }
  105. $page = isset($post['page']) &&$post['page']!=='' ?intval($post['page']) :1;
  106. $size = isset($post['size']) &&$post['size']!=='' ?intval($post['size']) :10;
  107. $count = Db::name("warehouse_info")->where($condition)->count();
  108. $page>=ceil($count/$size) ? $page = ceil($count/$size): '';
  109. $list = Db::name("warehouse_info")->where($condition)->page($page,$size)->order("addtime desc")->select();
  110. return app_show(0,"获取成功",['list'=>$list,"count"=>$count]);
  111. }
  112. public function info(){
  113. $post =$this->request->post();
  114. }
  115. }