123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?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']);
- $info['unit_name'] = Db::name("unit")->where(["id"=>$info['good_unit']])->value("unit",'');
- 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|number|in:0,1,3,6,9,13",
- "good_num|商品数量"=>"require|number|gt:0",
- "sale_total|销售总价"=>"require|float|gt:0",
- "cgd_total|采购总价"=>"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",
- "manager|项目经理"=>"require|max:255|min:1",
- "managerid|项目经理ID"=>"require|number",
- ]);
- $data=[];
- $i=0;
- $comArr= $userCom->handle("getCodeAndName",["code"=>array_unique(array_merge(array_column($param['list'],"companyNo"),array_column($param['list'],"customerNo"),array_column($param['list'],"supplierNo")
- ))]);
- if(!isset($comArr['code'])|| $comArr['code']!=0){
- return error_show(1004,"公司信息获取失败");
- }
- $compAr= $comArr['data']??[];
- $platform = Db::name("platform")->where(["id"=>array_unique(array_column($param['list'] , "platform_id"))])->column("platform_name",'id');
- $cat = Db::name("cat")->where(["id"=>array_unique(array_column($param['list'] , "cat_id")),"level"=>3])->column("cat_name",'id');
- $unit = Db::name("unit")->where(["id"=>array_unique(array_column($param['list'] , "good_unit"))])->column("unit",'id');
- foreach ($param['list'] as $item){
- $i++;
- if($valid->check($item)==false) return error_show(1004,$valid->getError());
- if(!isset($compAr[$item['companyNo']]))return error_show(1004,"企业编码:".$item['companyNo']."不存在");
- if(!isset($compAr[$item['customerNo']]))return error_show(1004,"客户编码:".$item['customerNo']."不存在");
- if(!isset($compAr[$item['supplierNo']]))return error_show(1004,"供应商编码:".$item['supplierNo']."不存在");
- $interNo = makeNo("RE");
- $interNo .=str_pad($i.'', 3, '0', STR_PAD_LEFT);
- // $platname = Db::name("platform")->where(["id"=>$item["platform_id"]])->value("platform_name",'');
- if(!isset($platform[$item['platform_id']]))return error_show(1004,"平台ID:".$item['platform_id']."不存在");
- // $cat = Db::name("cat")->where(["id"=>$item["cat_id"]])->value("cat_name",'');
- if(!isset($cat[$item['cat_id']]))return error_show(1004,"分类ID:".$item['cat_id']."不存在或不是三级分类");
- // $unit = Db::name("unit")->where(["id"=>$item["good_unit"]])->value("unit",'');
- if(!isset($unit[$item['good_unit']]))return error_show(1004,"单位ID:".$item['good_unit']."不存在");
- $data[] =[
- "interNo"=>$interNo,
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- 'manager'=>$item['manager'],
- 'managerid'=>$item['managerid'],
- "companyNo"=>$item['companyNo'],
- "companyName"=>$compAr[$item['companyNo']]??"",
- "customerNo"=>$item['customerNo'],
- "customerName"=>$compAr[$item['customerNo']]??"",
- "supplierNo"=>$item['supplierNo'],
- "supplierName"=>$compAr[$item['supplierNo']]??"",
- "platform_name"=>$platform[$item['platform_id']]??"",
- "cat_id"=>$item['cat_id'],
- "platform_id"=>$item['platform_id'],
- "good_name"=>$item['good_name'],
- "good_unit"=>$item['good_unit'],
- "good_tax"=>$item['good_tax'],
- "good_num"=>$item['good_num'],
- "sale_price"=>round($item['sale_total']/$item['good_num'],2),
- "cgd_price"=>round($item['cgd_total']/$item['good_num'],2),
- "cgd_tax"=>round(1-($item['cgd_total']/$item['sale_total']),4)*100 ,
- "sale_total"=>$item['sale_total'],
- "cgd_total"=>$item['cgd_total'],
- "contactor"=>$item['contactor'],
- "mobile"=>$item['mobile'],
- "addr"=>$item['addr'],
- "sendtime"=>$item['sendtime'],
- "poCode"=>$item['poCode'],
- "workCode"=>$item['workCode']
- ];
- }
- try{
- $up =Db::name("inter_order")->insertAll($data);
- if($up==false) return error_show(1004,"订单录入失败");
- return app_show(0,"订单录入成功");
- }catch (\Exception $e){
- return error_show(1004,$e->getMessage());
- }
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read()
- {
- $param=$this->request->only([
- "interNo"=>"",
- "supplier"=>'',
- "customer"=>'',
- "company"=>'',
- "good_name"=>'',
- "status"=>'',
- "use_type"=>'',
- "start"=>'',
- "end"=>'',
- "platform_id"=>'',
- "page"=>1,
- "size"=>10,
- ],"post","trim");
- $condition=[["a.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[]=["a.status","=",$param['status']];
- if($param['platform_id']!=='')$condition[]=["a.platform_id","=",$param['platform_id']];
- if($param['use_type']!=='')$condition[]=["b.use_type","=",$param['use_type']];
- if($param['start']!=='')$condition[]=["a.addtime",">=",$param['start']." 00:00:00"];
- if($param['end']!=='')$condition[]=["a.addtime","<=",$param['end']." 23:59:59"];
- $count=Db::name("inter_order")
- ->alias("a")
- ->leftJoin("platform b","a.platform_id =b.id")
- ->where($condition)
- ->count();
- $total=ceil($count/$param['size']);
- $page=$param['page']>=$total ? $total:$param['page'];
- $list = Db::name("inter_order")->where($condition)
- ->alias("a")
- ->leftJoin("platform b","a.platform_id =b.id")
- ->field("a.*,cat_id as cat_info,b.platform_name,b.use_type")
- ->page(intval($page),intval($param['size']))
- ->withAttr("cat_info",function ($v){return made($v);})
- ->withAttr("good_unit",function ($v){return Db::name("unit")->where(["id"=>$v])->value("unit",'');})
- ->order("a.id desc")
- ->select();
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- /**
- * 删除指定资源
- *
- * @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,"数据删除成功");
- }
- }
|