WareHouse.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. public function add(){
  23. $post =$this->request->post();
  24. $name = isset($post['name'])&& $post['name']!='' ?trim($post['name']) :'';
  25. if($name==''){
  26. return error_show(1004,'参数name 不能为空');
  27. }
  28. $supplier = isset($post['supplierNo'])&& $post['supplierNo']!='' ?trim($post['supplierNo']) :'';
  29. if($supplier==''){
  30. return error_show(1004,'参数supplierNo 不能为空');
  31. }
  32. $supplierinfo = Db::name("supplier")->where(["code"=>$supplier])->find();
  33. if(empty($supplierinfo)){
  34. return error_show(1004,'未找到供应商数据');
  35. }
  36. $wsmtype = isset($post['wsmtype'])&& $post['wsmtype']!='' ?intval($post['wsmtype']) :'';
  37. if($wsmtype==''){
  38. return error_show(1004,'参数wsmtype 不能为空');
  39. }
  40. $isT = Db::name('warehouse_info')->where([['name',"=",$name],["is_del","=",0]])->find();
  41. if(!empty($isT)){
  42. return error_show(1004,'仓库名称已存在');
  43. }
  44. $addr = isset($post['addr'])&& $post['addr']!='' ?trim($post['addr']) :'';
  45. if($addr==''){
  46. return error_show(1004,'参数addr 不能为空');
  47. }
  48. $contactor = isset($post['contactor'])&& $post['contactor']!='' ?trim($post['contactor']) :'';
  49. if($contactor==''){
  50. return error_show(1004,'参数contactor 不能为空');
  51. }
  52. $mobile = isset($post['mobile'])&& $post['mobile']!='' ?trim($post['mobile']) :'';
  53. if($mobile==''){
  54. return error_show(1004,'参数mobile 不能为空');
  55. }
  56. $position = isset($post['position'])&& $post['position']!='' ?trim($post['position']) :'';
  57. $wsm_type = isset($post['wsm_type']) && $post['wsm_type']!=="" ? intval($post['wsm_type']):"";
  58. $wsm_name = isset($post['wsm_name']) && $post['wsm_name']!=="" ? trim($post['wsm_name']):"";
  59. $wsm_mobile = isset($post['wsm_mobile']) && $post['wsm_mobile']!=="" ? trim($post['wsm_mobile']):"";
  60. $addr_code = isset($post['addr_code']) && $post['addr_code']!=="" ? trim($post['addr_code']):"";
  61. try{
  62. $data =[
  63. 'wsm_code'=>makeNo("WSM"),
  64. 'name'=>$name,
  65. 'wsm_type'=>$wsmtype,
  66. 'supplierNo'=>$supplier,
  67. 'addr'=>$addr,
  68. 'contactor'=>$contactor,
  69. 'mobile'=>$mobile,
  70. 'position'=>$position,
  71. 'status'=>1,
  72. 'addtime'=>date("Y-m-d H:i:s"),
  73. 'updatetime'=>date("Y-m-d H:i:s")
  74. ];
  75. $add = Db::name('warehouse_info')->insert($data);
  76. if($add){}
  77. }catch (\Exception $e){
  78. return error_show(1005,$e->getMessage());
  79. }
  80. return $add ? app_show(0,'仓库创建成功'): error_show(1005,'仓库创建失败');
  81. }
  82. public function list(){
  83. $post =$this->request->post();
  84. $condition= [['is_del',"=",0]];
  85. $supplier = isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :"";
  86. if($supplier!=""){
  87. $condition[]=["supplierNo","=",$supplier];
  88. }
  89. $wsm_code = isset($post['wsm_code'])&&$post['wsm_code']!="" ? trim($post['wsm_code']) :"";
  90. if($wsm_code!=""){
  91. $condition[]=["wsm_code","=",$wsm_code];
  92. }
  93. $start = isset($post['start'])&&$post['start']!="" ? $post['start'] :"";
  94. if($start!=""){
  95. $condition[]=["addtime",">=",$start];
  96. }
  97. $end = isset($post['end'])&&$post['end']!="" ? $post['end'] :"";
  98. if($end!=""){
  99. $condition[]=["addtime","<=",$end];
  100. }
  101. $mobile = isset($post['mobile'])&&$post['mobile']!="" ? trim($post['mobile']) :"";
  102. if($mobile!=""){
  103. $condition[]=["mobile","like","%{$mobile}%"];
  104. }
  105. $contactor = isset($post['contactor'])&&$post['contactor']!="" ? trim($post['contactor']) :"";
  106. if($contactor!=""){
  107. $condition[]=["contactor","like","%{$contactor}%"];
  108. }
  109. $page = isset($post['page']) &&$post['page']!=='' ?intval($post['page']) :1;
  110. $size = isset($post['size']) &&$post['size']!=='' ?intval($post['size']) :10;
  111. $count = Db::name("warehouse_info")->where($condition)->count();
  112. $page>=ceil($count/$size) ? $page = ceil($count/$size): '';
  113. $list = Db::name("warehouse_info")->where($condition)->page($page,$size)->order("addtime desc")->select();
  114. foreach ($list as $key=>$value){
  115. if($value['supplierNo']!=""){
  116. $supplierinfo = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  117. $value['supplier_name'] = isset($supplierinfo['name']) ? $supplierinfo['name'] :"";
  118. }else{
  119. $value['supplier_name']="";
  120. }
  121. if($value['wsm_type']!=""){
  122. $type = Db::name("warehouse_type")->where(["id"=>$value['wsm_type']])->find();
  123. $value['type_name'] = isset($type['name']) ? $type['name'] :"";
  124. }else{
  125. $value['type_name']="";
  126. }
  127. $list[$key]=$value;
  128. }
  129. return app_show(0,"获取成功",['list'=>$list,"count"=>$count]);
  130. }
  131. public function info(){
  132. $post =$this->request->post();
  133. $id = isset($post['id']) && $post['id']!==''?intval($post['id']): "";
  134. if($id===""){
  135. return error_show(1004,"参数id不能为空");
  136. };
  137. $warse = Db::name("warehouse_info")->where(["id"=>$id,"is_del"=>0])->find();
  138. if(empty($warse)){
  139. return error_show(1004,"未找到数据");
  140. }
  141. if($warse['supplierNo']!=""){
  142. $supplierinfo = Db::name("supplier")->where(["code"=>$warse['supplierNo']])->find();
  143. $warse['supplier_name'] = isset($supplierinfo['name']) ? $supplierinfo['name'] :"";
  144. }else{
  145. $warse['supplier_name']="";
  146. }
  147. if($warse['wsm_type']!=""){
  148. $type = Db::name("warehouse_type")->where(["id"=>$warse['wsm_type']])->find();
  149. $warse['type_name'] = isset($type['name']) ? $type['name'] :"";
  150. }else{
  151. $warse['type_name']="";
  152. }
  153. return app_show(0,"获取成功",$warse);
  154. }
  155. public function save(){
  156. $post =$this->request->post();
  157. $id = isset($post['id']) && $post['id']!==''?intval($post['id']): "";
  158. if($id===""){
  159. return error_show(1004,"参数id不能为空");
  160. };
  161. $warse = Db::name("warehouse_info")->where(["id"=>$id,"is_del"=>0])->find();
  162. if(empty($warse)){
  163. return error_show(1004,"未找到数据");
  164. }
  165. $name = isset($post['name'])&& $post['name']!='' ?trim($post['name']) :'';
  166. if($name==''){
  167. return error_show(1004,'参数name 不能为空');
  168. }
  169. $isT = Db::name('warehouse_info')->where([['name',"=",$name],["is_del","=",0],["id","<>",$id]])->find();
  170. if(!empty($isT)){
  171. return error_show(1004,'仓库名称已存在');
  172. }
  173. $addr = isset($post['addr'])&& $post['addr']!='' ?trim($post['addr']) :'';
  174. if($addr==''){
  175. return error_show(1004,'参数addr 不能为空');
  176. }
  177. $contactor = isset($post['contactor'])&& $post['contactor']!='' ?trim($post['contactor']) :'';
  178. if($contactor==''){
  179. return error_show(1004,'参数contactor 不能为空');
  180. }
  181. $mobile = isset($post['mobile'])&& $post['mobile']!='' ?trim($post['mobile']) :'';
  182. if($mobile==''){
  183. return error_show(1004,'参数mobile 不能为空');
  184. }
  185. $position = isset($post['position'])&& $post['position']!='' ?trim($post['position']) :'';
  186. $data =[
  187. 'name'=>$name,
  188. 'addr'=>$addr,
  189. 'contactor'=>$contactor,
  190. 'mobile'=>$mobile,
  191. 'position'=>$position,
  192. 'updatetime'=>date("Y-m-d H:i:s")
  193. ];
  194. $add = Db::name('warehouse_info')->where($warse)->update($data);
  195. return $add ? app_show(0,'仓库修改成功'): error_show(1005,'仓库修改失败');
  196. }
  197. public function delete(){
  198. $post =$this->request->post();
  199. $id = isset($post['id']) && $post['id']!==''?intval($post['id']): "";
  200. if($id===""){
  201. return error_show(1004,"参数id不能为空");
  202. };
  203. $warse = Db::name("warehouse_info")->where(["id"=>$id,"is_del"=>0])->find();
  204. if(empty($warse)){
  205. return error_show(1004,"未找到数据");
  206. }
  207. $warse['is_del'] = 1;
  208. $warse['updatetime'] = date("Y-m-d H:i:s");
  209. $Del= Db::name("warehouse_info")->save($warse);
  210. return $Del? app_show(0,'仓库删除成功'): error_show(1005,'仓库删除失败');
  211. }
  212. public function status(){
  213. $post =$this->request->post();
  214. $id = isset($post['id']) && $post['id']!==''?intval($post['id']): "";
  215. if($id===""){
  216. return error_show(1004,"参数id不能为空");
  217. };
  218. $warse = Db::name("warehouse_info")->where(["id"=>$id,"is_del"=>0])->find();
  219. if(empty($warse)){
  220. return error_show(1004,"未找到数据");
  221. }
  222. $status = isset($post['status']) && $post['status']!=="" ? intval($post['status']) : "";
  223. if($status===""){
  224. return error_show(1005,"参数status 不能为空");
  225. }
  226. $warse['status'] = $status;
  227. $warse['updatetime'] = date("Y-m-d H:i:s");
  228. $Del= Db::name("warehouse_info")->save($warse);
  229. return $Del? app_show(0,'仓库状态修改成功'): error_show(1005,'仓库状态修改失败');
  230. }
  231. }