InterOrder.php 8.6 KB

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