Allot.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. if($pd>0){
  94. $pdinfo=[
  95. "good_type_code"=>$good_type_code,
  96. "allot_num"=>$allot_num,
  97. // "good_name"=>$good_name,
  98. "allot_code"=>$allot_code,
  99. // "usable_num"=>$usable_num,
  100. // "error_num"=>$error_num,
  101. // "error_remark"=>$error_remark,
  102. // "stock_num"=>$stock_num,
  103. "addtime"=>date("Y-m-d H:i:s"),
  104. "updatetime"=>date("Y-m-d H:i:s"),
  105. ];
  106. $cpd = Db::name('allot_info')->insert($pdinfo);
  107. if($cpd){
  108. DB::commit();
  109. error_show(0,"调拨创建成功");
  110. }
  111. }
  112. Db::rollback();
  113. return error_show(1002,"调拨创建失败");
  114. }catch(\Exception $e){
  115. Db::rollback();
  116. return error_show(1005,$e->getMessage());
  117. }
  118. }
  119. public function info(){
  120. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  121. if($id==""){
  122. return error_show(1002,"调拨编号不能为空");
  123. }
  124. $fio = Db::name('allot_stock')->alias('a')->join("allot_info b","a.allot_code=b.allot_code","left")
  125. ->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,
  126. b.good_type_code,b.allot_code,b.allot_num")
  127. ->find();
  128. if(empty($fio)){
  129. return error_show(1002,"未找到调拨编号");
  130. }else{
  131. return app_show(0,"获取成功",$fio);
  132. }
  133. }
  134. public function edit(){
  135. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  136. if($id===""){
  137. return error_show(1002,"参数id不能为空");
  138. }
  139. $etid = Db::name("allot_stock")->where(["id"=>$id,"is_del"=>0])->find();
  140. if(empty($etid)){
  141. return error_show(1002,"未找到数据");
  142. }
  143. $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :"";
  144. if($allot_code==""){
  145. return error_show(1002,"调拨单编号不能为空");
  146. }
  147. // $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !=="" ? intval($this->post['apply_id']) :"" ;
  148. // if($apply_id==""){
  149. // return error_show(1002,"申请人id不能为空");
  150. // }
  151. // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name']) :"" ;
  152. // if($apply_name==""){
  153. // return error_show(1002,"申请人名称不能为空");
  154. // }
  155. $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !=="" ? trim($this->post['wsm_out']) :"" ;
  156. if($wsm_out==""){
  157. return error_show(1002,"出库仓库不能为空");
  158. }
  159. $wsm_in= isset($this->post['wsm_in']) && $this->post['wsm_in'] !=="" ? trim($this->post['wsm_in']) :"" ;
  160. if($wsm_in==""){
  161. return error_show(1002,"入库仓库不能为空");
  162. }
  163. $post_fee= isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? trim($this->post['post_fee']) :"" ;
  164. if($post_fee==""){
  165. return error_show(1002,"物流费用不能为空");
  166. }
  167. $status= isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']) :"" ;
  168. if($status==""){
  169. return error_show(1002,"状态不能为空");
  170. }
  171. $dain = isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
  172. if($dain==""){
  173. return error_show(1002,"商品不能为空");
  174. }
  175. try{
  176. $data=[
  177. "allot_code"=>$allot_code,
  178. // "apply_id"=>$apply_id,
  179. // "apply_name"=>$apply_name,
  180. "wsm_out"=>$wsm_out,
  181. "wsm_in"=>$wsm_in,
  182. "post_fee"=>$post_fee,
  183. "status"=>$status,
  184. "updatetime"=>date('Y-m-d H:i:s'),
  185. ];
  186. $da = Db::name('allot_stock')->where(["id"=>$id,"is_del"=>0])->save($data);
  187. $dn = [];
  188. if($da>0) {
  189. foreach ($dain as $value) {
  190. $st = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
  191. ->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")
  192. ->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();
  193. if (empty($st)) {
  194. Db::rollback();
  195. return error_show(1003, "商品不能为空");
  196. }
  197. $temp = [];
  198. $temp['id'] = $value['id'];
  199. $temp['good_name'] = $st['good_name'];
  200. $temp['good_type_code'] = $value['good_type_code'];
  201. $temp['allot_num'] = $value['allot_num'];
  202. $temp['usable_num'] = 0;
  203. $temp['error_num'] = 0;
  204. $temp['error_remark'] = "";
  205. $temp['allot_code'] = $etid['allot_code'];
  206. $temp['stock_num'] = 0;
  207. $temp['updatetime'] = date("Y-m-d H:i:s");
  208. $dn [] = $temp;
  209. $np = Db::name('allot_info')->save(['updatetime' => date('Y-m-d H:i:s')]);
  210. $io = db::name('allot_info')->insertAll($dn);
  211. if ($io) {
  212. Db::commit();
  213. return error_show(0, "调拨更新成功");
  214. }
  215. }
  216. }
  217. Db::rollback();
  218. return error_show(1003, "调拨更新失败");
  219. }catch (\Exception $e){
  220. Db::rollback();
  221. return error_show(1005,$e->getMessage());
  222. }
  223. }
  224. }