Allot.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Allot extends BaseController
  7. {
  8. public $post= "";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post=$this->request->post();
  13. }
  14. public function list(){
  15. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  16. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  17. $where =['is_del'=>0];
  18. $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !== "" ? trim($this->post['allot_code']) : "";
  19. if ($allot_code !== "") {
  20. $where['allot_code'] = $allot_code;
  21. }
  22. $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !== "" ? trim($this->post['wsm_out']) : "";
  23. if ($wsm_out !== "") {
  24. $where['wsm_out'] = $wsm_out;
  25. }
  26. $wsm_in = isset($this->post['wsm_in']) && $this->post['wsm_in'] !== "" ? trim($this->post['wsm_in']) : "";
  27. if ($wsm_in !== "") {
  28. $where['wsm_in'] = $wsm_in;
  29. }
  30. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  31. if ($start !="") {
  32. $where = ["addtime"=>Db::raw(">= '{$start}'")];
  33. }
  34. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  35. if($end !=""){
  36. $where = ["addtime"=>Db::raw("<= '{$end}'")];
  37. }
  38. $count = Db::name('allot_stock')->where($where)->count();
  39. $total = ceil($count/$size);
  40. $page = $page >= $total ? $total : $page;
  41. $list = Db::name('allot_stock')->where($where)->page($page,$size)->select();
  42. // var_dump(Db::name('allot_stock')->getLastSql());
  43. return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
  44. }
  45. public function create(){
  46. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  47. $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !=="" ? trim($this->post['wsm_out']) :"";
  48. if($wsm_out==""){
  49. return error_show(1002,"出库仓库编号不能为空");
  50. }
  51. $wsm_in = isset($this->post['wsm_in']) && $this->post['wsm_in'] !=="" ? trim($this->post['wsm_in']) :"";
  52. if($wsm_in==""){
  53. return error_show(1002,"入库仓库不能为空");
  54. }
  55. // $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code'] !=="" ? trim($this->post['good_type_code']) :"";
  56. // if($good_type_code==""){
  57. // return error_show(1002,"商品属性不能为空");
  58. // }
  59. $allot_code=makeNo("XK");
  60. // $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :"";
  61. // if($allot_code==""){
  62. // return error_show(1002,"调拨编号不能为空");
  63. // }
  64. $apply_id =GetUserInfo($token);
  65. if(empty($apply_id)||$apply_id['code']!=0){
  66. return error_show(1002,"申请人数据不存在");
  67. }
  68. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  69. $ri= isset($apply_name["data"]['nickname']) ? $apply_name["data"]['nickname'] : "";
  70. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :"" ;
  71. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  72. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  73. $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) : "";
  74. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) :"0";
  75. if($status==""){
  76. return error_show(1002,"状态不能为空");
  77. }
  78. $dain = isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
  79. if($dain==""){
  80. return error_show(1002,"商品不能为空");
  81. }
  82. Db::startTrans();
  83. try {
  84. $data=[
  85. "allot_code"=>$allot_code,
  86. "wsm_out"=>$wsm_out,
  87. "wsm_in"=>$wsm_in,
  88. "apply_name"=>$ri,
  89. "apply_id"=>$rm,
  90. "post_name"=>$post_name,
  91. "post_code"=>$post_code,
  92. "post_fee"=>$post_fee,
  93. "remark"=>$remark,
  94. "status"=>$status,
  95. "is_del"=>0,
  96. "addtime"=>date("Y-m-d H:i:s"),
  97. "updatetime"=>date("Y-m-d H:i:s"),
  98. ];
  99. $pd=Db::name('allot_stock')->insert($data,true);
  100. $dm=[];
  101. if($pd>0) {
  102. foreach ($dain as $value) {
  103. $st = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
  104. ->join("good_stock c", "c.good_type_code = b.type_code", "left")
  105. ->join("warehouse_info v","v.wsm_code=c.wsm_code","left")
  106. ->join("supplier n","n.code=v.supplierNo","left")
  107. ->where(['c.wsm_code' => $wsm_out, 'good_type_code' => $value['good_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
  108. ->field("b.type_code,a.good_name,a.unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock,n.name")->find();
  109. //var_dump(Db::name("good_type")->getLastSql());
  110. if (empty($st)) {
  111. Db::rollback();
  112. return error_show(1003, "商品不能为空");
  113. }
  114. $temp = [];
  115. $temp['good_name'] = $st['good_name'];
  116. $temp['allot_code'] =$allot_code;
  117. $temp['good_type_code'] = $value['good_code'];
  118. $temp['allot_num'] = $value['allot_num'];
  119. $temp['usable_num'] = 0;
  120. $temp['error_num'] = 0;
  121. $temp['error_remark'] = "";
  122. $temp['stock_num'] = 0;
  123. $temp['addtime'] = date("Y-m-d H:i:s");
  124. $temp['updatetime'] = date("Y-m-d H:i:s");
  125. $dm[]=$temp;
  126. $io = db::name('allot_info')->insertAll($dm);
  127. if ($io) {
  128. DB::commit();
  129. return error_show(0, "调拨创建成功");
  130. }
  131. }
  132. }
  133. Db::rollback();
  134. return error_show(1002,"调拨创建失败");
  135. }catch(\Exception $e){
  136. Db::rollback();
  137. return error_show(1005,$e->getMessage());
  138. }
  139. }
  140. public function info(){
  141. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  142. if($id==""){
  143. return error_show(1002,"调拨编号不能为空");
  144. }
  145. $str = Db::name('allot_stock')->where(['id'=>$id,'is_del'=>0])->find();
  146. // var_dump( Db::name('allot_stock')->getLastSql());
  147. if(empty($str)){
  148. return error_show(1003,"未找到调拨数据");
  149. }
  150. $vmp = Db::name('allot_info')->where(['allot_code'=>$str['allot_code']])->select();
  151. $str['item']=$vmp;
  152. if(empty($str)){
  153. return error_show(1002,"未找到调拨编号");
  154. }else{
  155. return app_show(0,"获取成功",$str);
  156. }
  157. }
  158. public function edit(){
  159. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  160. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  161. if($id===""){
  162. return error_show(1002,"参数id不能为空");
  163. }
  164. $etid = Db::name("allot_stock")->where(["id"=>$id,"is_del"=>0])->find();
  165. if(empty($etid)){
  166. return error_show(1002,"未找到数据");
  167. }
  168. $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :"";
  169. if($allot_code==""){
  170. return error_show(1002,"调拨单编号不能为空");
  171. }
  172. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :"";
  173. if($post_name==""){
  174. return error_show(1002,"物流公司不能为空");
  175. }
  176. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !=="" ? trim($this->post['post_code']) :"";
  177. if($post_code==""){
  178. return error_show(1002,"物流单号不能为空");
  179. }
  180. $apply_id =GetUserInfo($token);
  181. if(empty($apply_id)||$apply_id['code']!=0){
  182. return error_show(1002,"申请人数据不存在");
  183. }
  184. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  185. $ri= isset($apply_name["data"]['nickname']) ? $apply_name["data"]['nickname'] : "";
  186. $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !=="" ? trim($this->post['wsm_out']) :"" ;
  187. if($wsm_out==""){
  188. return error_show(1002,"出库仓库不能为空");
  189. }
  190. $wsm_in= isset($this->post['wsm_in']) && $this->post['wsm_in'] !=="" ? trim($this->post['wsm_in']) :"" ;
  191. if($wsm_in==""){
  192. return error_show(1002,"入库仓库不能为空");
  193. }
  194. $post_fee= isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? trim($this->post['post_fee']) :"" ;
  195. if($post_fee==""){
  196. return error_show(1002,"物流费用不能为空");
  197. }
  198. $status= isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']) :"" ;
  199. if($status==""){
  200. return error_show(1002,"状态不能为空");
  201. }
  202. $dain = isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
  203. if($dain==""){
  204. return error_show(1002,"商品不能为空");
  205. }
  206. try{
  207. $data=[
  208. "allot_code"=>$allot_code,
  209. "apply_id"=>$rm,
  210. "apply_name"=>$ri,
  211. "wsm_out"=>$wsm_out,
  212. "wsm_in"=>$wsm_in,
  213. "post_fee"=>$post_fee,
  214. "post_name"=>$post_name,
  215. "post_code"=>$post_code,
  216. "status"=>$status,
  217. "updatetime"=>date('Y-m-d H:i:s'),
  218. ];
  219. $da = Db::name('allot_stock')->where(["id"=>$id,"is_del"=>0])->save($data);
  220. if($da>0) {
  221. foreach ($dain as $value) {
  222. $st = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
  223. ->join("good_stock c", "c.good_type_code = b.type_code", "left")->where(['wsm_code' => $wsm_out, 'good_type_code' => $value['type_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
  224. ->field("b.type_code,a.good_name,a.unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock")->find();
  225. // var_dump(Db::name("good_type")->getLastSql());
  226. if (empty($st)) {
  227. Db::rollback();
  228. return error_show(1003, "商品不能为空");
  229. }
  230. $temp = [];
  231. isset($value['id']) ? $temp['id'] = $value['id']:'';
  232. $temp['good_name'] = $st['good_name'];
  233. $temp['good_type_code'] = $value['good_code'];
  234. $temp['allot_num'] = $value['allot_num'];
  235. $temp['usable_num'] = 0;
  236. $temp['error_num'] = 0;
  237. $temp['error_remark'] = "";
  238. $temp['allot_code'] = $etid['allot_code'];
  239. $temp['stock_num'] = 0;
  240. isset($value['id']) ? '' :$temp['addtime'] = date("Y-m-d H:i:s");
  241. $temp['updatetime'] = date("Y-m-d H:i:s");
  242. $np = Db::name('allot_info')->save($temp);
  243. if ($np) {
  244. Db::commit();
  245. return error_show(0, "调拨更新成功");
  246. }
  247. }
  248. }
  249. Db::rollback();
  250. return error_show(1003, "调拨更新失败");
  251. }catch (\Exception $e){
  252. Db::rollback();
  253. return error_show(1005,$e->getMessage());
  254. }
  255. }
  256. public function del(){
  257. $id = $this->post['id'] && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  258. if($id===""){
  259. return error_show(1004,"参数id不能为空");
  260. }
  261. $str= Db::name('allot_stock')->where(['id'=>$id,'is_del'=>0])->find();
  262. if(empty($str)){
  263. return error_show(1002,"未找到数据");
  264. }
  265. $end = Db::name('allot_stock')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  266. if($end){
  267. return error_show(0,"删除成功");
  268. }else{
  269. return error_show(1002,"删除失败");
  270. }
  271. }
  272. public function status(){
  273. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"" ;
  274. if($id==""){
  275. return error_show(1002,"调拨编号不能为空");
  276. }
  277. $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) :"";
  278. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  279. if($status===""){
  280. return error_show(1002,"审核状态不能为空");
  281. }
  282. $st = Db::name('allot_stock')->where(['id'=>$id,"is_del"=>0])->find();
  283. if(empty($st)){
  284. return error_show(1002,"调拨信息未找到");
  285. }
  286. $st['remark']=$remark;
  287. $st['status']=$status;
  288. $st['updatetime']= date('Y-m-d H:i:s');
  289. $sv = Db::name('allot_stock')->save($st);
  290. if($sv){
  291. return error_show(0,"状态更新成功");
  292. }else{
  293. return error_show(1002,"状态更新失败");
  294. }
  295. }
  296. }