InterOrder.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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|number|in:0,1,3,6,9,13",
  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. $comArr= $userCom->handle("getCodeAndName",["code"=>array_unique(array_merge(array_column($param['list'],"companyNo"),array_column($param['list'],"customerNo"),array_column($param['list'],"supplierNo")
  58. ))]);
  59. if(!isset($comArr['code'])|| $comArr['code']!=0){
  60. return error_show(1004,"公司信息获取失败");
  61. }
  62. $compAr= $comArr['data']??[];
  63. $platform = Db::name("platform")->where(["id"=>array_unique(array_column($param['list'] , "platform_id"))])->column("platform_name",'id');
  64. $cat = Db::name("cat")->where(["id"=>array_unique(array_column($param['list'] , "cat_id"))])->column("cat_name",'id');
  65. $unit = Db::name("unit")->where(["id"=>array_unique(array_column($param['list'] , "good_unit"))])->column("unit",'id');
  66. foreach ($param['list'] as $item){
  67. $i++;
  68. if($valid->check($item)==false) return error_show(1004,$valid->getError());
  69. if(!isset($compAr[$item['companyNo']]))return error_show(1004,"企业编码:".$item['companyNo']."不存在");
  70. if(!isset($compAr[$item['customerNo']]))return error_show(1004,"客户编码:".$item['customerNo']."不存在");
  71. if(!isset($compAr[$item['supplierNo']]))return error_show(1004,"供应商编码:".$item['supplierNo']."不存在");
  72. $interNo = makeNo("RE");
  73. $interNo .=str_pad($i.'', 3, '0', STR_PAD_LEFT);
  74. // $platname = Db::name("platform")->where(["id"=>$item["platform_id"]])->value("platform_name",'');
  75. if(!isset($platform[$item['platform_id']]))return error_show(1004,"平台ID:".$item['platform_id']."不存在");
  76. // $cat = Db::name("cat")->where(["id"=>$item["cat_id"]])->value("cat_name",'');
  77. if(!isset($cat[$item['cat_id']]))return error_show(1004,"分类ID:".$item['cat_id']."不存在");
  78. // $unit = Db::name("unit")->where(["id"=>$item["good_unit"]])->value("unit",'');
  79. if(!isset($unit[$item['good_unit']]))return error_show(1004,"单位ID:".$item['good_unit']."不存在");
  80. $data[] =[
  81. "interNo"=>$interNo,
  82. "apply_id"=>$this->uid,
  83. "apply_name"=>$this->uname,
  84. "companyNo"=>$item['companyNo'],
  85. "companyName"=>$compAr[$item['companyNo']]??"",
  86. "customerNo"=>$item['customerNo'],
  87. "customerName"=>$compAr[$item['customerNo']]??"",
  88. "supplierNo"=>$item['supplierNo'],
  89. "supplierName"=>$compAr[$item['supplierNo']]??"",
  90. "platform_name"=>$platform[$item['platform_id']]??"",
  91. "cat_id"=>$item['cat_id'],
  92. "platform_id"=>$item['platform_id'],
  93. "good_name"=>$item['good_name'],
  94. "good_unit"=>$item['good_unit'],
  95. "good_tax"=>$item['good_tax'],
  96. "good_num"=>$item['good_num'],
  97. "sale_price"=>round($item['sale_total']/$item['good_num'],2),
  98. "cgd_price"=>round($item['cgd_total']/$item['good_num'],2),
  99. "cgd_tax"=>round(1-($item['cgd_total']/$item['sale_total']),4)*100 ,
  100. "sale_total"=>$item['sale_total'],
  101. "cgd_total"=>$item['cgd_total'],
  102. "contactor"=>$item['contactor'],
  103. "mobile"=>$item['mobile'],
  104. "addr"=>$item['addr'],
  105. "sendtime"=>$item['sendtime'],
  106. "poCode"=>$item['poCode'],
  107. "workCode"=>$item['workCode']
  108. ];
  109. }
  110. try{
  111. $up =Db::name("inter_order")->insertAll($data);
  112. if($up==false) return error_show(1004,"订单录入失败");
  113. return app_show(0,"订单录入成功");
  114. }catch (\Exception $e){
  115. return error_show(1004,$e->getMessage());
  116. }
  117. }
  118. /**
  119. * 显示指定的资源
  120. *
  121. * @param int $id
  122. * @return \think\Response
  123. */
  124. public function read()
  125. {
  126. $param=$this->request->only([
  127. "interNo"=>"",
  128. "supplier"=>'',
  129. "customer"=>'',
  130. "company"=>'',
  131. "good_name"=>'',
  132. "status"=>'',
  133. "use_type"=>'',
  134. "platform_id"=>'',
  135. "page"=>1,
  136. "size"=>10,
  137. ],"post","trim");
  138. $condition=[["a.is_del","=",0]];
  139. if($param['interNo']!=='')$condition[]=["interNo","like","%{$param['interNo']}%"];
  140. if($param['supplier']!=='')$condition[]=["supplierNo|supplierName","like","%{$param['supplier']}%"];
  141. if($param['customer']!=='')$condition[]=["customerNo|customerName","like","%{$param['customer']}%"];
  142. if($param['company']!=='')$condition[]=["companyNo|companyName","like","%{$param['company']}%"];
  143. if($param['good_name']!=='')$condition[]=["good_name","like","%{$param['good_name']}%"];
  144. if($param['status']!=='')$condition[]=["a.status","=",$param['status']];
  145. if($param['platform_id']!=='')$condition[]=["a.platform_id","=",$param['platform_id']];
  146. if($param['use_type']!=='')$condition[]=["b.use_type","=",$param['use_type']];
  147. $count=Db::name("inter_order")
  148. ->alias("a")
  149. ->leftJoin("platform b","a.platform_id =b.id")
  150. ->where($condition)
  151. ->count();
  152. $total=ceil($count/$param['size']);
  153. $page=$param['page']>=$total ? $total:$param['page'];
  154. $list = Db::name("inter_order")->where($condition)
  155. ->alias("a")
  156. ->leftJoin("platform b","a.platform_id =b.id")
  157. ->field("a.*,cat_id as cat_info,b.platform_name,b.use_type")
  158. ->page(intval($page),intval($param['size']))
  159. ->withAttr("cat_info",function ($v){return made($v);})
  160. ->withAttr("good_unit",function ($v){return Db::name("unit")->where(["id"=>$v])->value("unit",'');})
  161. ->order("a.id desc")
  162. ->select();
  163. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  164. }
  165. /**
  166. * 删除指定资源
  167. *
  168. * @param int $id
  169. * @return \think\Response
  170. */
  171. public function delete()
  172. {
  173. $param =$this->request->only(["interNo"=>""],"post","trim");
  174. if($param['interNo']=='') return error_show(1004,"参数interNo不能为空");
  175. $info =Db::name("inter_order")->where(["interNo"=>$param["interNo"]])->findOrEmpty();
  176. if(empty($info)) return error_show(1004,"录单数据未找到");
  177. if($info['is_del']==1) return error_show(1004,"录单数据已删除");
  178. if($info['status']!=1) return error_show(1004,"录单数据状态已更改无法删除");
  179. $del= Db::name("inter_order")->where(["interNo"=>$param["interNo"]])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  180. if($del==false)return error_show(1004,"录单数据删除失败");
  181. return app_show(0,"数据删除成功");
  182. }
  183. }