InterOrder.php 8.6 KB

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