wugg 1 year ago
parent
commit
fceeacab4b
1 changed files with 188 additions and 0 deletions
  1. 188 0
      app/admin/controller/InterOrder.php

+ 188 - 0
app/admin/controller/InterOrder.php

@@ -0,0 +1,188 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\controller;
+
+use think\App;
+use think\facade\Validate;use think\Request;
+use think\facade\Db;
+
+class InterOrder extends Base
+{
+	public function __construct(App $app) {parent::__construct($app);}
+    /**
+     * 显示资源列表
+     *
+     * @return \think\Response
+     */
+    public function index()
+    {
+		$param=$this->request->only(["interNo"=>""],"post","trim");
+		if($param['interNo']=='')return error_show(1005,"录单编号不能为空");
+		$info =Db::name("inter_order")->where(["interNo"=>$param['interNo'],"is_del"=>0])->findOrEmpty();
+		if(empty($info)) return error_show(1005,"录单信息未找到");
+		$info['cat_info'] =made($info['cat_id']);
+		return app_show(0,"获取成功",$info);
+    }
+
+    /**
+     * 显示创建资源表单页.
+     *
+     * @return \think\Response
+     */
+    public function create()
+    {
+
+		$param =$this->request->only(["list"=>[]],"post","trim");
+		$val =Validate::rule(["list|数据集合"=>"require|array"]);
+		if($val->check($param)==false) return error_show(1004,$val->getError());
+		$userCom=\app\admin\common\User::getIns();
+			$valid =Validate::rule([
+			"companyNo|业务公司"=>"require|max:255|min:1",
+			"customerNo|客户公司"=>"require|max:255|min:1",
+			"supplierNo|供应商公司"=>"require|max:255|min:1",
+			"platform_id|业务平台"=>"require|max:255|min:1",
+			"cat_id|商品分类"=>"require|number|gt:0",
+			"good_name|商品名称"=>"require|max:255|min:1",
+			"good_unit|商品单位"=>"require|max:255|min:1",
+			"good_tax|商品税率"=>"require|float",
+			"good_num|商品数量"=>"require|number|gt:0",
+			"sale_price|销售单价"=>"require|float|gt:0",
+			"cgd_price|采购单价"=>"require|float|gt:0",
+			"contactor|收货联系人"=>"require|max:255|min:1",
+			"mobile|收货联系方式"=>"require|max:255|min:1",
+			"addr|收货地址"=>"require|max:255|min:1",
+			"sendtime|发货时间"=>"require|date|dateFormat:Y-m-d H:i:s",
+			"poCode|业务单号"=>"max:255|min:1",
+			"workCode|单据号"=>"max:255|min:1",
+			]);
+			$data=[];
+		foreach ($param['list'] as $item){
+			if($valid->check($item)==false) return error_show(1004,$valid->getError());
+			$comArr= $userCom->handle("getCodeAndName",["code"=>[$item['companyNo'],$item['customerNo'],$item['supplierNo']]]);
+			if(!isset($comArr['code'])|| $comArr['code']!=0){
+				 return error_show(1004,"公司信息未找到");
+			}
+			$compAr= $comArr['data']??[];
+			$interNo = makeNo("RE");
+			$data[] =[
+				"interNo"=>$interNo,
+				"apply_id"=>$this->uid,
+				"apply_name"=>$this->uname,
+				"companyNo"=>$item['companyNo'],
+				"companyName"=>$compAr[$item['companyNo']],
+				"customerNo"=>$item['customerNo'],
+				"customerName"=>$compAr[$item['customerNo']],
+				"supplierNo"=>$item['supplierNo'],
+				"supplierName"=>$compAr[$item['supplierNo']],
+				"platform_name"=>Db::name("platform")->where(["id"=>$item["platform_id"]])->value("platform_name",''),
+				"good_name"=>$item['good_name'],
+				"good_unit"=>$item['good_unit'],
+				"good_tax"=>$item['good_tax'],
+				"good_num"=>$item['good_num'],
+				"sale_price"=>$item['sale_price'],
+				"cgd_price"=>$item['cgd_price'],
+				"cgd_tax"=>round(1-($item['cgd_price']/$item['sale_price']),4)*100 ,
+				"sale_total"=>round($item['good_num']*$item['sale_price'],2),
+				"contactor"=>$item['contactor'],
+				"mobile"=>$item['mobile'],
+				"addr"=>$item['addr'],
+				"sendtime"=>$item['sendtime'],
+				"poCode"=>$item['poCode'],
+				"workCode"=>$item['workCode']
+			];
+		}
+		$up =Db::name("inter_order")->insertAll($data);
+		if($up==false) return error_show(1004,"订单录入失败");
+		return error_show(0,"订单录入成功");
+    }
+
+    /**
+     * 保存新建的资源
+     *
+     * @param  \think\Request  $request
+     * @return \think\Response
+     */
+    public function save()
+    {
+
+    }
+
+    /**
+     * 显示指定的资源
+     *
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function read()
+    {
+      	$param=$this->request->only([
+      		"interNo"=>"",
+      		"supplier"=>'',
+      		"customer"=>'',
+      		"company"=>'',
+      		"good_name"=>'',
+      		"status"=>'',
+      		"page"=>1,
+      		"size"=>10,
+      		],"post","trim");
+      	$condition=[["is_del","=",0]];
+		if($param['interNo']=='')$condition[]=["interNo","like","%{$param['interNo']}%"];
+		if($param['supplier']=='')$condition[]=["supplierNo|supplierName","like","%{$param['supplier']}%"];
+		if($param['customer']=='')$condition[]=["customerNo|customerName","like","%{$param['customer']}%"];
+		if($param['company']=='')$condition[]=["companyNo|companyName","like","%{$param['company']}%"];
+		if($param['good_name']=='')$condition[]=["good_name","like","%{$param['good_name']}%"];
+		if($param['status']=='')$condition[]=["status","=",$param['status']];
+		$count=Db::name("inter_order")->where($condition)->count();
+		$total=ceil($count/$param['size']);
+		$page=$param['page']>=$total ? $total:$param['page'];
+		$list = Db::name("inter_order")->where($condition)
+		->field("*,cat_id as cat_info")
+		->page(intval($page),intval($param['size']))
+		->withAttr("cat_info",function ($v){return made($v);})
+		->select();
+		return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
+    }
+
+    /**
+     * 显示编辑资源表单页.
+     *
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function edit($id)
+    {
+        //
+    }
+
+    /**
+     * 保存更新的资源
+     *
+     * @param  \think\Request  $request
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function update(Request $request, $id)
+    {
+        //
+    }
+
+    /**
+     * 删除指定资源
+     *
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function delete()
+    {
+       $param =$this->request->only(["interNo"=>""],"post","trim");
+       if($param['interNo']=='') return error_show(1004,"参数interNo不能为空");
+       $info =Db::name("inter_order")->where(["interNo"=>$param["interNo"]])->findOrEmpty();
+       if(empty($info)) return error_show(1004,"录单数据未找到");
+       if($info['is_del']==1)  return error_show(1004,"录单数据已删除");
+       if($info['status']!=1)  return error_show(1004,"录单数据状态已更改无法删除");
+       $del= Db::name("inter_order")->where(["interNo"=>$param["interNo"]])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
+       if($del==false)return error_show(1004,"录单数据删除失败");
+       return app_show(0,"数据删除成功");
+    }
+}