|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
use app\BaseController;
|
|
|
+use Illuminate\Support\Facades\Date;
|
|
|
use think\facade\Db;
|
|
|
|
|
|
class Purchin extends BaseController
|
|
@@ -18,5 +19,263 @@ class Purchin extends BaseController
|
|
|
public function list(){
|
|
|
|
|
|
}
|
|
|
- public function add(){}
|
|
|
+ public function add(){
|
|
|
+ $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!=""? trim($this->post['cgdNo']):"";
|
|
|
+ if($cgdNo==""){
|
|
|
+ return error_show(1005,"参数cgdNo 不能为空");
|
|
|
+ }
|
|
|
+ $cgdinfo = Db::name("purchease_order")->where(['cgdNo'=>$cgdNo,'is_del'=>0])->find();
|
|
|
+ if(empty($cgdinfo)){
|
|
|
+ return error_show(1005,"未找到采购单数据");
|
|
|
+ }
|
|
|
+ if($cgdinfo['status']!=3){
|
|
|
+ return error_show(1005,"采购单未发货");
|
|
|
+ }
|
|
|
+ $wsm_in_code = makeNo("IC");
|
|
|
+ $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
|
|
|
+ if($wsm_code==""){
|
|
|
+ return error_show(1004,"参数 wsm_code 不能为空");
|
|
|
+ }
|
|
|
+ $wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find();
|
|
|
+ if(empty($wsminfo)){
|
|
|
+ return error_show(1004,"未找到仓库信息");
|
|
|
+ }
|
|
|
+ $recep = Db::name('warehouse_addr')->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find();
|
|
|
+
|
|
|
+ $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
|
|
|
+ if($wsm_code==""){
|
|
|
+ return error_show(1004,"参数 wsm_code 不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = GetUserInfo($this->post['token']);
|
|
|
+ if((!empty($data) && $data['code']!=0) ||empty($data) ){
|
|
|
+ return error_show($data['code'],$data['message']);
|
|
|
+ }
|
|
|
+ $userinfo = $data['data'];
|
|
|
+ $post_company = isset($this->post['post_company'])&&$this->post['post_company']!="" ? trim($this->post['post_company']):"";
|
|
|
+ $post_code = isset($this->post['post_code'])&&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
|
|
|
+ $post_fee = isset($this->post['post_fee'])&&$this->post['post_fee']!="" ? $this->post['post_fee']:"0";
|
|
|
+ $post_time = isset($this->post['post_time'])&&$this->post['post_time']!="" ? $this->post['post_time']:date("Y-m-d H:i:s");
|
|
|
+ $send_num = isset($this->post['send_num'])&&$this->post['send_num']!="" ? intval($this->post['send_num']):"";
|
|
|
+ $status = isset($this->post['status'])&&$this->post['status']!="" ? intval($this->post['status']):"0";
|
|
|
+ if($send_num==''){
|
|
|
+ return error_show(1004,"参数 send_num 不能为空或零");
|
|
|
+ }
|
|
|
+ if($send_num>$cgdinfo['wsend_num']){
|
|
|
+ return error_show(1004,"采购单剩余未发货数量不足");
|
|
|
+ }
|
|
|
+ $orin = [
|
|
|
+ "wsm_in_code"=>$wsm_in_code,
|
|
|
+ "cgdNo"=>$cgdNo,
|
|
|
+ "wsm_code"=>$wsm_in_code,
|
|
|
+ "wsm_reaper"=>isset($recep)&& $recep['wsm_name']!=''? $recep['wsm_name']:"",
|
|
|
+ "send_num"=>$send_num,
|
|
|
+ "post_company"=>$post_company,
|
|
|
+ "post_code"=>$post_code,
|
|
|
+ "post_fee"=>$post_fee,
|
|
|
+ "sendtime"=>$post_time,
|
|
|
+ "apply_id"=>$userinfo['id'],
|
|
|
+ "apply_name"=>$userinfo['nickname'],
|
|
|
+ "wait_num"=>0,
|
|
|
+ "status"=>$status,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+ $win = Db::name("purchease_in")->insert($orin);
|
|
|
+ if($win){
|
|
|
+ $cgdinfo['wsend_num']-=$send_num;
|
|
|
+ $cgdinfo['send_num']+=$send_num;
|
|
|
+ $cgdinfo['updatetime']=date("Y-m-d H:i:s");
|
|
|
+ $up=Db::name("purchease_order")->save($cgdinfo);
|
|
|
+ if($up){
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,'新建成功');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"新建失败");
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,$e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function info(){
|
|
|
+ $incode = isset($this->post['wsm_in_code'])&&$this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']) :"";
|
|
|
+ if($incode==""){
|
|
|
+ return error_show(1004,"参数wsm_in_code 不为空");
|
|
|
+ }
|
|
|
+ $info = Db::name("purchease_in")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find();
|
|
|
+ if(empty($info)){
|
|
|
+ return error_show(1004,"未找到数据");
|
|
|
+ }
|
|
|
+ $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where(["a.wsm_code"=>$info['wsm_code']])->field("a.name as wsm_name,b.name")->find();
|
|
|
+ $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
|
|
|
+ $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
|
|
|
+ $check = Db::name("purchease_info")->where(['wsm_in_code'=>$incode,"is_del"=>0])->select();
|
|
|
+ $info['checkinfo']= $check;
|
|
|
+ return app_show(0,'获取成功',$info);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function check(){
|
|
|
+ $incode = isset($this->post['wsm_in_code'])&&$this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']) :"";
|
|
|
+ if($incode==""){
|
|
|
+ return error_show(1004,"参数wsm_in_code 不为空");
|
|
|
+ }
|
|
|
+ $info = Db::name("purchease_in")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find();
|
|
|
+ if(empty($info)){
|
|
|
+ return error_show(1004,"未找到数据");
|
|
|
+ }
|
|
|
+ $order_num = isset($this->post['order_num']) && $this->post['order_num']!==''?intval($this->post['order_num'])
|
|
|
+ :"";
|
|
|
+ if($order_num!==""){
|
|
|
+ return error_show(1004,"参数 order_num 不为空");
|
|
|
+ }
|
|
|
+ $error_list = isset($this->post['error_list']) && $this->post['error_list']!==''?$this->post['error_list']:"";
|
|
|
+
|
|
|
+ $wait_num = isset($this->post['wait_num']) && $this->post['wait_num']!==''?intval($this->post['wait_num'])
|
|
|
+ :"";
|
|
|
+ if($wait_num===''){
|
|
|
+ return error_show(1004,"参数 wait_num 不为空");
|
|
|
+ }
|
|
|
+ $result = GetUserInfo($this->post['token']);
|
|
|
+ if((!empty($result) && $result['code']!=0) ||empty($result) ){
|
|
|
+ return error_show($result['code'],$result['message']);
|
|
|
+ }
|
|
|
+ $userinfo = $result['data'];
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+ $info['wsm_num'] = $order_num;
|
|
|
+ $info['wait_num'] = $wait_num;
|
|
|
+ $info['checkid'] = $userinfo['id'];
|
|
|
+ $info['check_name'] = $userinfo['nickname'];
|
|
|
+ $info['error_num'] = $info['send_num']-$wait_num;
|
|
|
+ $info['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $up =Db::name("purchease_in")->save($info);
|
|
|
+ if($up){
|
|
|
+ if(!empty($error_list)){
|
|
|
+ $data=[];
|
|
|
+ foreach ($error_list as $value ){
|
|
|
+ $temp=[];
|
|
|
+ $temp['wsm_in_code']=$info['wsm_in_code'];
|
|
|
+ $temp['num']=$info['num'];
|
|
|
+ $temp['error_code']=$info['error_code'];
|
|
|
+ $temp['error_img']=$info['error_img'];
|
|
|
+ $temp['remark']=$info['remark'];
|
|
|
+ $temp['is_del']=0;
|
|
|
+ $temp['addtime']=$info['addtime'];
|
|
|
+ $temp['updatetime']=$info['updatetime'];
|
|
|
+ $data[]=$temp;
|
|
|
+ }
|
|
|
+ $derr= Db::name("purchease_info")->insertAll($data);
|
|
|
+ if($derr){
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,"验货完成");
|
|
|
+ }else{
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"验货数据保存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,"验货完成");
|
|
|
+ }
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"验货数据保存失败");
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,$e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function status(){
|
|
|
+ $incode = isset($this->post['wsm_in_code'])&&$this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']) :"";
|
|
|
+ if($incode==""){
|
|
|
+ return error_show(1004,"参数wsm_in_code 不为空");
|
|
|
+ }
|
|
|
+ $info = Db::name("purchease_in")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find();
|
|
|
+ if(empty($info)){
|
|
|
+ return error_show(1004,"未找到数据");
|
|
|
+ }
|
|
|
+ $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
|
|
|
+ if($status===""){
|
|
|
+ return error_show(1004,"参数status 不为空");
|
|
|
+ }
|
|
|
+ $remark = isset($this->post['remark'])&&$this->post['remark']!="" ? trim($this->post['remark']) :"";
|
|
|
+ $info['status'] = $status;
|
|
|
+ $info['remark'] = $remark;
|
|
|
+ $info['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $update = Db::name("purchease_in")->save($info);
|
|
|
+ if($update){
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,"状态修改完成");
|
|
|
+ }else{
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"状态修改失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function ReturnAdd(){
|
|
|
+ $incode = isset($this->post['wsm_in_code'])&&$this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']) :"";
|
|
|
+ if($incode==""){
|
|
|
+ return error_show(1004,"参数wsm_in_code 不为空");
|
|
|
+ }
|
|
|
+ $info = Db::name("purchease_in")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find();
|
|
|
+ if(empty($info)){
|
|
|
+ return error_show(1004,"未找到数据");
|
|
|
+ }
|
|
|
+ $wsm_num = isset($this->post['wsm_num']) &&$this->post['wsm_num']!=="" ? intval($this->post['wsm_num']):"" ;
|
|
|
+ if($wsm_num===""){
|
|
|
+ return error_show(1004,"参数wsm_num 不为空");
|
|
|
+ }
|
|
|
+ $reissue_num = isset($this->post['reissue_num']) &&$this->post['reissue_num']!=="" ? intval($this->post['reissue_num']):"0" ;
|
|
|
+ $return_num = isset($this->post['return_num']) &&$this->post['return_num']!=="" ? intval($this->post['return_num']):"0" ;
|
|
|
+ $contactor = isset($this->post['contactor']) &&$this->post['contactor']!=="" ? trim($this->post['contactor']):"" ;
|
|
|
+ if($contactor==""){
|
|
|
+ return error_show(1004,"参数contactor 不为空");
|
|
|
+ }
|
|
|
+ $addr = isset($this->post['addr']) &&$this->post['addr']!=="" ? trim($this->post['addr']):"" ;
|
|
|
+ if($addr==""){
|
|
|
+ return error_show(1004,"参数addr 不为空");
|
|
|
+ }
|
|
|
+ $mobile = isset($this->post['mobile']) &&$this->post['mobile']!=="" ? trim($this->post['mobile']):"" ;
|
|
|
+ if($mobile==""){
|
|
|
+ return error_show(1004,"参数mobile 不为空");
|
|
|
+ }
|
|
|
+ $error_remark = isset($this->post['error_remark']) &&$this->post['error_remark']!=="" ? trim($this->post['error_remark']):"" ;
|
|
|
+ $post_code = isset($this->post['post_code']) &&$this->post['post_code']!=="" ? trim($this->post['post_code']):"" ;
|
|
|
+ $post_company = isset($this->post['post_company']) &&$this->post['post_company']!=="" ? trim($this->post['post_company']):"" ;
|
|
|
+ $result = GetUserInfo($this->post['token']);
|
|
|
+ if((!empty($result) && $result['code']!=0) ||empty($result) ){
|
|
|
+ return error_show($result['code'],$result['message']);
|
|
|
+ }
|
|
|
+ $userinfo = $result['data'];
|
|
|
+
|
|
|
+ $data=[
|
|
|
+ "wsm_in_code"=>$incode,
|
|
|
+ "wsm_num"=>$wsm_num,
|
|
|
+ "reissue_num"=>$reissue_num,
|
|
|
+ "return_num"=>$return_num,
|
|
|
+ "return_contactor"=>$contactor,
|
|
|
+ "return_addr"=>$addr,
|
|
|
+ "return_mobile"=>$mobile,
|
|
|
+ "error_remark"=>$error_remark,
|
|
|
+ "post_code"=>$post_code,
|
|
|
+ "post_company"=>$post_company,
|
|
|
+ "apply_id"=>$userinfo['id'],
|
|
|
+ "apply_name"=>$userinfo['nickname'],
|
|
|
+ "status"=>0,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $res = Db::name("purchease_return")->insert($data);
|
|
|
+ if($res){
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,"退货新建完成");
|
|
|
+ }else{
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"退货新建失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|