Allot.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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'] !== "" ? intval($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'] !== "" ? intval($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'] !== "" ? intval($this->post['wsm_in']) : "";
  27. if ($wsm_in !== "") {
  28. $where['wsm_in'] = $wsm_in;
  29. }
  30. $addtime = isset($this->post['addtime']) && $this->post['addtime'] !== "" ? intval($this->post['addtime']) : "";
  31. if ($addtime !== "") {
  32. $where['addtime'] = $addtime;
  33. }
  34. $count = Db::name('allot_stock')->count();
  35. $total = ceil($count/$size);
  36. $page = $page >= $total ? $total : $page;
  37. $list = Db::name('allot_stock')->where($where)->page($page,$size)->select();
  38. return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
  39. }
  40. // $good_name= isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']) :"";
  41. // $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :"";
  42. // $usable_num = isset($this->post['usable_num']) && $this->post['usable_num'] !=="" ? intval($this->post['allot_code']) :"0";
  43. // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? intval($this->post['error_num']) :"0";
  44. // $error_remark = isset($this->post['error_remark']) && $this->post['error_remark'] !=="" ? trim($this->post['error_remark']) :"";
  45. // $stock_num = isset($this->post['stock_num']) && $this->post['error_num'] !=="" ? intval($this->post['error_num']) : "0";
  46. public function create(){
  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_num = isset($this->post['allot_num']) && $this->post['allot_num'] !=="" ? intval($this->post['allot_num']):"";
  60. if($allot_num==""){
  61. return error_show(1002,"出库数量不能为空");
  62. }
  63. $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :"";
  64. $apply_name= isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name']) :"";
  65. $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !=="" ? intval($this->post['apply_id']) :"" ;
  66. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :"" ;
  67. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  68. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  69. $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) : "";
  70. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) :"0";
  71. $dain = isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
  72. if($dain==""){
  73. return error_show(1002,"商品不能为空");
  74. }
  75. Db::startTrans();
  76. try {
  77. $data=[
  78. "allot_code"=>$allot_code,
  79. "wsm_out"=>$wsm_out,
  80. "wsm_in"=>$wsm_in,
  81. "apply_name"=>$apply_name,
  82. "apply_id"=>$apply_id,
  83. "post_name"=>$post_name,
  84. "post_code"=>$post_code,
  85. "post_fee"=>$post_fee,
  86. "remark"=>$remark,
  87. "status"=>$status,
  88. "is_del"=>0,
  89. "addtime"=>date("Y-m-d H:i:s"),
  90. "updatetime"=>date("Y-m-d H:i:s"),
  91. ];
  92. $pd=Db::name('allot_stock')->insert($data,true);
  93. $dn = [];
  94. if($pd>0) {
  95. foreach ($dain as $value) {
  96. $st = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
  97. ->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")
  98. ->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();
  99. if (empty($st)) {
  100. Db::rollback();
  101. return error_show(1003, "商品不能为空");
  102. }
  103. $temp = [];
  104. $temp['good_name'] = $st['good_name'];
  105. $temp['good_type_code'] = $value['good_code'];
  106. $temp['allot_num'] = $value['allot_num'];
  107. $temp['usable_num'] = 0;
  108. $temp['error_num'] = 0;
  109. $temp['error_remark'] = "";
  110. $temp['stock_num'] = 0;
  111. $temp['addtime'] = date("Y-m-d H:i:s");
  112. $temp['updatetime'] = date("Y-m-d H:i:s");
  113. $dn[] = $temp;
  114. $io = db::name('allot_info')->insertAll($dn);
  115. if ($io) {
  116. DB::commit();
  117. return error_show(0, "调拨创建成功");
  118. }
  119. }
  120. }
  121. Db::rollback();
  122. return error_show(1002,"调拨创建失败");
  123. }catch(\Exception $e){
  124. Db::rollback();
  125. return error_show(1005,$e->getMessage());
  126. }
  127. }
  128. public function info(){
  129. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  130. if($id==""){
  131. return error_show(1002,"调拨编号不能为空");
  132. }
  133. $fio = Db::name('allot_stock')->alias('a')->join("allot_info b","a.allot_code=b.allot_code","left")
  134. ->where(['a.id'=>$id,'a.is_del'=>0])->field("a.allot_code,a.apply_id,a.apply_name,a.wsm_out,a.wsm_in,a.post_fee,a.status,a.addtime,
  135. b.good_type_code,b.allot_code,b.allot_num")
  136. ->find();
  137. if(empty($fio)){
  138. return error_show(1002,"未找到调拨编号");
  139. }else{
  140. return app_show(0,"获取成功",$fio);
  141. }
  142. }
  143. public function edit(){
  144. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  145. if($id===""){
  146. return error_show(1002,"参数id不能为空");
  147. }
  148. $etid = Db::name("allot_stock")->where(["id"=>$id,"is_del"=>0])->find();
  149. if(empty($etid)){
  150. return error_show(1002,"未找到数据");
  151. }
  152. $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :"";
  153. if($allot_code==""){
  154. return error_show(1002,"调拨单编号不能为空");
  155. }
  156. // $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !=="" ? intval($this->post['apply_id']) :"" ;
  157. // if($apply_id==""){
  158. // return error_show(1002,"申请人id不能为空");
  159. // }
  160. // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name']) :"" ;
  161. // if($apply_name==""){
  162. // return error_show(1002,"申请人名称不能为空");
  163. // }
  164. $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !=="" ? trim($this->post['wsm_out']) :"" ;
  165. if($wsm_out==""){
  166. return error_show(1002,"出库仓库不能为空");
  167. }
  168. $wsm_in= isset($this->post['wsm_in']) && $this->post['wsm_in'] !=="" ? trim($this->post['wsm_in']) :"" ;
  169. if($wsm_in==""){
  170. return error_show(1002,"入库仓库不能为空");
  171. }
  172. $post_fee= isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? trim($this->post['post_fee']) :"" ;
  173. if($post_fee==""){
  174. return error_show(1002,"物流费用不能为空");
  175. }
  176. $status= isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']) :"" ;
  177. if($status==""){
  178. return error_show(1002,"状态不能为空");
  179. }
  180. $dain = isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
  181. if($dain==""){
  182. return error_show(1002,"商品不能为空");
  183. }
  184. try{
  185. $data=[
  186. "allot_code"=>$allot_code,
  187. // "apply_id"=>$apply_id,
  188. // "apply_name"=>$apply_name,
  189. "wsm_out"=>$wsm_out,
  190. "wsm_in"=>$wsm_in,
  191. "post_fee"=>$post_fee,
  192. "status"=>$status,
  193. "updatetime"=>date('Y-m-d H:i:s'),
  194. ];
  195. $da = Db::name('allot_stock')->where(["id"=>$id,"is_del"=>0])->save($data);
  196. $dn = [];
  197. if($da>0) {
  198. foreach ($dain as $value) {
  199. $st = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
  200. ->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")
  201. ->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();
  202. if (empty($st)) {
  203. Db::rollback();
  204. return error_show(1003, "商品不能为空");
  205. }
  206. $temp = [];
  207. $temp['id'] = $value['id'];
  208. $temp['good_name'] = $st['good_name'];
  209. $temp['good_type_code'] = $value['good_code'];
  210. $temp['allot_num'] = $value['allot_num'];
  211. $temp['usable_num'] = 0;
  212. $temp['error_num'] = 0;
  213. $temp['error_remark'] = "";
  214. $temp['allot_code'] = $etid['allot_code'];
  215. $temp['stock_num'] = 0;
  216. $temp['updatetime'] = date("Y-m-d H:i:s");
  217. $dn[] = $temp;
  218. $np = Db::name('allot_info')->where(['allot_code' => $etid['id']])->save(['updatetime' => date('Y-m-d H:i:s')]);
  219. $io = db::name('allot_info')->insertAll($dn);
  220. if ($io) {
  221. Db::commit();
  222. return error_show(0, "调拨更新成功");
  223. }
  224. }
  225. }
  226. Db::rollback();
  227. return error_show(1003, "调拨更新失败");
  228. }catch (\Exception $e){
  229. Db::rollback();
  230. return error_show(1005,$e->getMessage());
  231. }
  232. }
  233. }