InterOrder.php 6.6 KB

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