InterOrder.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use think\App;
  5. use think\facade\Validate;use think\Request;
  6. use think\facade\Db;
  7. class InterOrder extends Base
  8. {
  9. public function __construct(App $app) {parent::__construct($app);}
  10. /**
  11. * 显示资源列表
  12. *
  13. * @return \think\Response
  14. */
  15. public function index()
  16. {
  17. $param=$this->request->only(["interNo"=>""],"post","trim");
  18. if($param['interNo']=='')return error_show(1005,"录单编号不能为空");
  19. $info =Db::name("inter_order")->where(["interNo"=>$param['interNo'],"is_del"=>0])->findOrEmpty();
  20. if(empty($info)) return error_show(1005,"录单信息未找到");
  21. $info['cat_info'] =made($info['cat_id']);
  22. $info['unit_name'] = Db::name("unit")->where(["id"=>$info['good_unit']])->value("unit",'');
  23. return app_show(0,"获取成功",$info);
  24. }
  25. /**
  26. * 显示创建资源表单页.
  27. *
  28. * @return \think\Response
  29. */
  30. public function create()
  31. {
  32. $param =$this->request->only(["list"=>[]],"post","trim");
  33. $val =Validate::rule(["list|数据集合"=>"require|array"]);
  34. if($val->check($param)==false) return error_show(1004,$val->getError());
  35. $userCom=\app\admin\common\User::getIns();
  36. $valid =Validate::rule([
  37. "companyNo|业务公司"=>"require|max:255|min:1",
  38. "customerNo|客户公司"=>"require|max:255|min:1",
  39. "supplierNo|供应商公司"=>"require|max:255|min:1",
  40. "platform_id|业务平台"=>"require|max:255|min:1",
  41. "cat_id|商品分类"=>"require|number|gt:0",
  42. "good_name|商品名称"=>"require|max:255|min:1",
  43. "good_unit|商品单位"=>"require|max:255|min:1",
  44. "good_tax|商品税率"=>"require|float",
  45. "good_num|商品数量"=>"require|number|gt:0",
  46. "sale_total|销售总价"=>"require|float|gt:0",
  47. "cgd_total|采购总价"=>"require|float|gt:0",
  48. "contactor|收货联系人"=>"require|max:255|min:1",
  49. "mobile|收货联系方式"=>"require|max:255|min:1",
  50. "addr|收货地址"=>"require|max:255|min:1",
  51. "sendtime|发货时间"=>"require|date|dateFormat:Y-m-d H:i:s",
  52. "poCode|业务单号"=>"max:255|min:1",
  53. "workCode|单据号"=>"max:255|min:1",
  54. ]);
  55. $data=[];
  56. $i=0;
  57. foreach ($param['list'] as $item){
  58. $i++;
  59. if($valid->check($item)==false) return error_show(1004,$valid->getError());
  60. $comArr= $userCom->handle("getCodeAndName",["code"=>[$item['companyNo'],$item['customerNo'],$item['supplierNo']]]);
  61. if(!isset($comArr['code'])|| $comArr['code']!=0){
  62. return error_show(1004,"公司信息未找到");
  63. }
  64. $compAr= $comArr['data']??[];
  65. $interNo = makeNo("RE");
  66. $interNo .=str_pad($i.'', 3, '0', STR_PAD_LEFT);
  67. $data[] =[
  68. "interNo"=>$interNo,
  69. "apply_id"=>$this->uid,
  70. "apply_name"=>$this->uname,
  71. "companyNo"=>$item['companyNo'],
  72. "companyName"=>$compAr[$item['companyNo']],
  73. "customerNo"=>$item['customerNo'],
  74. "customerName"=>$compAr[$item['customerNo']],
  75. "supplierNo"=>$item['supplierNo'],
  76. "supplierName"=>$compAr[$item['supplierNo']],
  77. "platform_name"=>Db::name("platform")->where(["id"=>$item["platform_id"]])->value("platform_name",''),
  78. "cat_id"=>$item['cat_id'],
  79. "platform_id"=>$item['platform_id'],
  80. "good_name"=>$item['good_name'],
  81. "good_unit"=>$item['good_unit'],
  82. "good_tax"=>$item['good_tax'],
  83. "good_num"=>$item['good_num'],
  84. "sale_price"=>round($item['sale_total']/$item['good_num'],2),
  85. "cgd_price"=>round($item['cgd_total']/$item['good_num'],2),
  86. "cgd_tax"=>round(1-($item['cgd_total']/$item['sale_total']),4)*100 ,
  87. "sale_total"=>$item['sale_total'],
  88. "cgd_total"=>$item['cgd_total'],
  89. "contactor"=>$item['contactor'],
  90. "mobile"=>$item['mobile'],
  91. "addr"=>$item['addr'],
  92. "sendtime"=>$item['sendtime'],
  93. "poCode"=>$item['poCode'],
  94. "workCode"=>$item['workCode']
  95. ];
  96. }
  97. $up =Db::name("inter_order")->insertAll($data);
  98. if($up==false) return error_show(1004,"订单录入失败");
  99. return error_show(0,"订单录入成功");
  100. }
  101. /**
  102. * 显示指定的资源
  103. *
  104. * @param int $id
  105. * @return \think\Response
  106. */
  107. public function read()
  108. {
  109. $param=$this->request->only([
  110. "interNo"=>"",
  111. "supplier"=>'',
  112. "customer"=>'',
  113. "company"=>'',
  114. "good_name"=>'',
  115. "status"=>'',
  116. "page"=>1,
  117. "size"=>10,
  118. ],"post","trim");
  119. $condition=[["is_del","=",0]];
  120. if($param['interNo']!=='')$condition[]=["interNo","like","%{$param['interNo']}%"];
  121. if($param['supplier']!=='')$condition[]=["supplierNo|supplierName","like","%{$param['supplier']}%"];
  122. if($param['customer']!=='')$condition[]=["customerNo|customerName","like","%{$param['customer']}%"];
  123. if($param['company']!=='')$condition[]=["companyNo|companyName","like","%{$param['company']}%"];
  124. if($param['good_name']!=='')$condition[]=["good_name","like","%{$param['good_name']}%"];
  125. if($param['status']!=='')$condition[]=["status","=",$param['status']];
  126. $count=Db::name("inter_order")->where($condition)->count();
  127. $total=ceil($count/$param['size']);
  128. $page=$param['page']>=$total ? $total:$param['page'];
  129. $list = Db::name("inter_order")->where($condition)
  130. ->field("*,cat_id as cat_info")
  131. ->page(intval($page),intval($param['size']))
  132. ->withAttr("cat_info",function ($v){return made($v);})
  133. ->withAttr("good_unit",function ($v){return Db::name("unit")->where(["id"=>$v])->value("unit",'');})
  134. ->order("id desc")
  135. ->select();
  136. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  137. }
  138. /**
  139. * 删除指定资源
  140. *
  141. * @param int $id
  142. * @return \think\Response
  143. */
  144. public function delete()
  145. {
  146. $param =$this->request->only(["interNo"=>""],"post","trim");
  147. if($param['interNo']=='') return error_show(1004,"参数interNo不能为空");
  148. $info =Db::name("inter_order")->where(["interNo"=>$param["interNo"]])->findOrEmpty();
  149. if(empty($info)) return error_show(1004,"录单数据未找到");
  150. if($info['is_del']==1) return error_show(1004,"录单数据已删除");
  151. if($info['status']!=1) return error_show(1004,"录单数据状态已更改无法删除");
  152. $del= Db::name("inter_order")->where(["interNo"=>$param["interNo"]])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  153. if($del==false)return error_show(1004,"录单数据删除失败");
  154. return app_show(0,"数据删除成功");
  155. }
  156. }