Allot.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. public function create(){
  41. $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !=="" ? trim($this->post['wsm_out']) :"";
  42. if($wsm_out==""){
  43. return error_show(1002,"出库仓库编号不能为空");
  44. }
  45. $wsm_in = isset($this->post['wsm_in']) && $this->post['wsm_in'] !=="" ? trim($this->post['wsm_in']) :"";
  46. if($wsm_in==""){
  47. return error_show(1002,"入库仓库不能为空");
  48. }
  49. $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code'] !=="" ? trim($this->post['good_type_code']) :"";
  50. if($good_type_code==""){
  51. return error_show(1002,"商品属性不能为空");
  52. }
  53. $allot_num = isset($this->post['allot_num']) && $this->post['allot_num'] !=="" ? intval($this->post['allot_num']):"";
  54. if($allot_num==""){
  55. return error_show(1002,"出库数量不能为空");
  56. }
  57. $apply_name= isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name']) :"";
  58. $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !=="" ? intval($this->post['apply_id']) :"" ;
  59. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :"" ;
  60. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  61. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  62. $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) : "";
  63. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) :"0";
  64. $good_name= isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']) :"";
  65. $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :"";
  66. $usable_num = isset($this->post['usable_num']) && $this->post['usable_num'] !=="" ? intval($this->post['allot_code']) :"0";
  67. $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? intval($this->post['error_num']) :"0";
  68. $error_remark = isset($this->post['error_remark']) && $this->post['error_remark'] !=="" ? trim($this->post['error_remark']) :"";
  69. $stock_num = isset($this->post['stock_num']) && $this->post['error_num'] !=="" ? intval($this->post['error_num']) : "0";
  70. Db::startTrans();
  71. try {
  72. $data=[
  73. "allot_code"=>$allot_code,
  74. "wsm_out"=>$wsm_out,
  75. "wsm_in"=>$wsm_in,
  76. "apply_name"=>$apply_name,
  77. "apply_id"=>$apply_id,
  78. "post_name"=>$post_name,
  79. "post_code"=>$post_code,
  80. "post_fee"=>$post_fee,
  81. "remark"=>$remark,
  82. "status"=>$status,
  83. "is_del"=>0,
  84. "addtime"=>date("Y-m-d H:i:s"),
  85. "updatetime"=>date("Y-m-d H:i:s"),
  86. ];
  87. $pd=Db::name('allot_stock')->insert($data,true);
  88. if($pd>0){
  89. $pdinfo=[
  90. "good_type_code"=>$good_type_code,
  91. "allot_num"=>$allot_num,
  92. "good_name"=>$good_name,
  93. "allot_code"=>$allot_code,
  94. "usable_num"=>$usable_num,
  95. "error_num"=>$error_num,
  96. "error_remark"=>$error_remark,
  97. "stock_num"=>$stock_num,
  98. "addtime"=>date("Y-m-d H:i:s"),
  99. "updatetime"=>date("Y-m-d H:i:s"),
  100. ];
  101. $cpd = Db::name('allot_info')->insert($pdinfo);
  102. if($cpd){
  103. DB::commit();
  104. error_show(0,"调拨创建成功");
  105. }
  106. }
  107. Db::rollback();
  108. return error_show(1002,"调拨创建失败");
  109. }catch(\Exception $e){
  110. Db::rollback();
  111. return error_show(1005,$e->getMessage());
  112. }
  113. }
  114. public function info(){
  115. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  116. if($id==""){
  117. return error_show(1002,"调拨编号不能为空");
  118. }
  119. $fio = Db::name('allot_stock')->alias('a')->join("allot_info b","a.allot_code=b.allot_code","left")
  120. ->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,
  121. b.good_type_code,b.allot_code,b.allot_num")
  122. ->find();
  123. if(empty($fio)){
  124. return error_show(1002,"未找到调拨编号");
  125. }else{
  126. return app_show(0,"获取成功",$fio);
  127. }
  128. }
  129. public function edit(){
  130. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  131. if($id===""){
  132. return error_show(1002,"参数id不能为空");
  133. }
  134. $etid = Db::name("allot_stock")->where(["id"=>$id,"is_del"=>0])->find();
  135. if(empty($etid)){
  136. return error_show(1002,"未找到数据");
  137. }
  138. $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :"";
  139. if($allot_code==""){
  140. return error_show(1002,"调拨单编号不能为空");
  141. }
  142. $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !=="" ? intval($this->post['apply_id']) :"" ;
  143. if($apply_id==""){
  144. return error_show(1002,"申请人id不能为空");
  145. }
  146. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name']) :"" ;
  147. if($apply_name==""){
  148. return error_show(1002,"申请人名称不能为空");
  149. }
  150. $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !=="" ? trim($this->post['wsm_out']) :"" ;
  151. if($wsm_out==""){
  152. return error_show(1002,"出库仓库不能为空");
  153. }
  154. $wsm_in= isset($this->post['wsm_in']) && $this->post['wsm_in'] !=="" ? trim($this->post['wsm_in']) :"" ;
  155. if($wsm_in==""){
  156. return error_show(1002,"入库仓库不能为空");
  157. }
  158. $post_fee= isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? trim($this->post['post_fee']) :"" ;
  159. if($post_fee==""){
  160. return error_show(1002,"物流费用不能为空");
  161. }
  162. $status= isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']) :"" ;
  163. if($status==""){
  164. return error_show(1002,"状态不能为空");
  165. }
  166. try{
  167. $data=[
  168. "allot_code"=>$allot_code,
  169. "apply_id"=>$apply_id,
  170. "apply_name"=>$apply_name,
  171. "wsm_out"=>$wsm_out,
  172. "wsm_in"=>$wsm_in,
  173. "post_fee"=>$post_fee,
  174. "status"=>$status,
  175. "updatetime"=>date('Y-m-d H:i:s'),
  176. ];
  177. $da = Db::name('allot_stock')->where(["id"=>$id,"is_del"=>0])->save($data);
  178. }catch (\Exception $e){
  179. Db::rollback();
  180. return error_show(1005,$e->getMessage());
  181. }
  182. }
  183. }