123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- class Check extends BaseController
- {
- public $post = "";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post=$this->request->post();
- }
- public function list()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $where = ['is_del' => 0];
- $addtime = isset($this->post['addtime']) && $this->post['addtime'] !== "" ? intval($this->post['addtime']) : "";
- if ($addtime !== "") {
- $where['check_code'] = $addtime;
- }
- $check_code = isset($this->post['check_code']) && $this->post['check_code'] !== "" ? intval($this->post['check_code']) : "";
- if ($check_code !== "") {
- $where['check_code'] = $check_code;
- }
- $wsm_code = isset($this->post['wsm_code ']) && $this->post['wsm_code '] !== "" ? intval($this->post['wsm_code ']) : "";
- if ($wsm_code !== "") {
- $where['wsm_code '] = $wsm_code;
- }
- $status= isset($this->post['status ']) && $this->post['status '] !== "" ? intval($this->post['status ']) : "";
- if ($status !== "") {
- $where['status '] = $status;
- }
- $count = Db::name('good_check')->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $page : $total;
- $list = Db::name('good_check')->field('apply_id,apply_name,type,addtime')->where($where)->page($page,$size)->select();
- return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
- }
- public function goodlist(){
- $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
- $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
- $where = ['is_del'=>0,'status'=>0];
- $count = Db::name('check_item')->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $page : $total;
- $list = Db::name('check_item')->where($where)->page($page,$size)->select();
- return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
- }
- // $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code'] !=="" ? $this->post['good_type_code']:"";
- // if($good_type_code==""){
- // return error_show(1002,"商品属性不能为空");
- // }
- // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? $this->post['good_name'] : "";
- // if($good_name==""){
- // return error_show(1002,"商品名称不能为空");
- // }
- // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !=="" ? $this->post['origin_price'] :"";
- // $origin_num = isset($this->post['origin_num']) && $this->post['origin_num'] !=="" ? $this->post['origin_num'] :"";
- // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
- // $diff_num = isset($this->post['diff_num']) && $this->post['diff_num'] !=="" ? $this->post['diff_num'] :"";
- // $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? $this->post['remark'] :"";
- // $check_time = isset($this->post['check_time']) && $this->post['check_time'] !=="" ? $this->post['startTime']:date("Y-m-d H:i:s");
- public function create(){
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
- if($wsm_code==""){
- return error_show(1002,"盘点仓库编号不能为空");
- }
- $type = isset($this->post['type']) && $this->post['type'] !=="" ? trim($this->post['type']) :"";
- if($type==""){
- return error_show(1002,"盘点类型不能为空");
- }
- $check_code = isset($this->post['check_code']) && $this->post['check_code'] !=="" ? trim($this->post['check_code']) : "";
- if($check_code==""){
- return error_show(1002,"盘点编号不能为空");
- }
- $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !=="" ? trim($this->post['apply_id']):"";
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name']):"";
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0";
- $dain=isset($this->post['good']) && $this->post['good'] !=="" ? trim($this->post['good']):"";
- if($type===2){
- if($dain==""||empty($dain)){
- return error_show(1002,"商品不能为空");
- }
- }else{
- if($type===1) {
- $do = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
- ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
- ->field("b.type_code,a.good_name")->select();
- }
- }
- Db::startTrans();
- try{
- $data=[
- "check_code"=>$check_code,
- "wsm_code"=>$wsm_code,
- "type"=>$type,
- "status"=>$status,
- "apply_id"=>$apply_id,
- "apply_name"=>$apply_name,
- "is_del"=>0,
- "addtime"=>date('Y-m-d H:i:s'),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $da= Db::name('good_check')->insert($data,true);
- $dain=[];
- if($da>0){
- foreach ($do as $value){
- $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
- ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
- ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_")->select();
- $dain[] =$value;
- }
- $in= Db::name('check_item')->insertAll($dain);
- }
- if($in){
- Db::commit();
- return error_show(0,"盘点创建成功");
- }else{
- Db::rollback();
- return error_show(1002,"创建失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- public function info(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"盘点单号不能为空");
- }
- $fo = Db::name('good_check')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($fo)){
- return error_show(1002,"未找到盘点编号");
- }else{
- return app_show(0,"获取成功",$fo);
- }
- }
- public function edit()
- {
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- $eid = Db::name('good_check')->where(['id' => $id, 'is_del' => 0])->find();
- if ($eid ==="") {
- return error_show(1002, "未找到盘点编号信息");
- }
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
- if ($wsm_code == "") {
- return error_show(1002, "盘点仓库不能为空");
- }
- $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
- if ($type == "") {
- return error_show(1002, "盘点类型不能为空");
- }
- $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code'] !== "" ? trim($this->post['good_type_code']) : "";
- if ($good_type_code == "") {
- return error_show(1002, "商品属性不能为空");
- }
- $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
- if ($good_name == "") {
- return error_show(1002, "商品名称不能为空");
- }
- $check_code = isset($this->post['check_code']) && $this->post['check_code'] !== "" ? trim($this->post['check_code']) : "";
- if ($check_code == "") {
- return error_show(1002, "盘点编号不能为空");
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
- Db::startTrans();
- try {
- $var = [
- "id" => $id,
- "check_code" => $check_code,
- "wsm_code" => $wsm_code,
- "type" => $type,
- "status" => $status,
- "is_del" => 0,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $up = Db::name('good_check')->where(['id'=>$id,'is_del' => 0])->save($var);
- if($up){
- $varn = [
- "good_type_code" => $good_type_code,
- "good_name" => $good_name,
- "status" => $status,
- // "check_time" => $check_time,
- "is_del" => 0,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $np = Db::name('check_item')->where(["id"=>$eid['id']])->save($varn);
- //var_dump(Db::name('check_item')->getLastSql());
- if ($np) {
- Db::commit();
- return error_show(0, "盘点更新成功");
- } else {
- Db::rollback();
- return error_show(1002, "盘点更新失败");
- }
- }
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function dell(){
- $id = $this->post['id'] && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id===""){
- return error_show(1004,"参数id不能为空");
- }
- $deln= Db::name('good_check')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($deln)){
- return error_show(1002,"未找到数据");
- }
- $sv = Db::name('good_check')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
- if($sv){
- return error_show(0,"删除成功");
- }else{
- return error_show(1002,"删除失败");
- }
- }
- }
|