InterOrder.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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_price|销售单价"=>"require|float|gt:0",
  47. "cgd_price|采购单价"=>"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"=>$item['sale_price'],
  85. "cgd_price"=>$item['cgd_price'],
  86. "cgd_tax"=>round(1-($item['cgd_price']/$item['sale_price']),4)*100 ,
  87. "sale_total"=>round($item['good_num']*$item['sale_price'],2),
  88. "contactor"=>$item['contactor'],
  89. "mobile"=>$item['mobile'],
  90. "addr"=>$item['addr'],
  91. "sendtime"=>$item['sendtime'],
  92. "poCode"=>$item['poCode'],
  93. "workCode"=>$item['workCode']
  94. ];
  95. }
  96. $up =Db::name("inter_order")->insertAll($data);
  97. if($up==false) return error_show(1004,"订单录入失败");
  98. return error_show(0,"订单录入成功");
  99. }
  100. /**
  101. * 保存新建的资源
  102. *
  103. * @param \think\Request $request
  104. * @return \think\Response
  105. */
  106. public function save()
  107. {
  108. }
  109. /**
  110. * 显示指定的资源
  111. *
  112. * @param int $id
  113. * @return \think\Response
  114. */
  115. public function read()
  116. {
  117. $param=$this->request->only([
  118. "interNo"=>"",
  119. "supplier"=>'',
  120. "customer"=>'',
  121. "company"=>'',
  122. "good_name"=>'',
  123. "status"=>'',
  124. "page"=>1,
  125. "size"=>10,
  126. ],"post","trim");
  127. $condition=[["is_del","=",0]];
  128. if($param['interNo']!=='')$condition[]=["interNo","like","%{$param['interNo']}%"];
  129. if($param['supplier']!=='')$condition[]=["supplierNo|supplierName","like","%{$param['supplier']}%"];
  130. if($param['customer']!=='')$condition[]=["customerNo|customerName","like","%{$param['customer']}%"];
  131. if($param['company']!=='')$condition[]=["companyNo|companyName","like","%{$param['company']}%"];
  132. if($param['good_name']!=='')$condition[]=["good_name","like","%{$param['good_name']}%"];
  133. if($param['status']!=='')$condition[]=["status","=",$param['status']];
  134. $count=Db::name("inter_order")->where($condition)->count();
  135. $total=ceil($count/$param['size']);
  136. $page=$param['page']>=$total ? $total:$param['page'];
  137. $list = Db::name("inter_order")->where($condition)
  138. ->field("*,cat_id as cat_info")
  139. ->page(intval($page),intval($param['size']))
  140. ->withAttr("cat_info",function ($v){return made($v);})
  141. ->withAttr("good_unit",function ($v){return Db::name("unit")->where(["id"=>$v])->value("unit",'');})
  142. ->order("id desc")
  143. ->select();
  144. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  145. }
  146. /**
  147. * 显示编辑资源表单页.
  148. *
  149. * @param int $id
  150. * @return \think\Response
  151. */
  152. public function edit($id)
  153. {
  154. //
  155. }
  156. /**
  157. * 保存更新的资源
  158. *
  159. * @param \think\Request $request
  160. * @param int $id
  161. * @return \think\Response
  162. */
  163. public function update(Request $request, $id)
  164. {
  165. //
  166. }
  167. /**
  168. * 删除指定资源
  169. *
  170. * @param int $id
  171. * @return \think\Response
  172. */
  173. public function delete()
  174. {
  175. $param =$this->request->only(["interNo"=>""],"post","trim");
  176. if($param['interNo']=='') return error_show(1004,"参数interNo不能为空");
  177. $info =Db::name("inter_order")->where(["interNo"=>$param["interNo"]])->findOrEmpty();
  178. if(empty($info)) return error_show(1004,"录单数据未找到");
  179. if($info['is_del']==1) return error_show(1004,"录单数据已删除");
  180. if($info['status']!=1) return error_show(1004,"录单数据状态已更改无法删除");
  181. $del= Db::name("inter_order")->where(["interNo"=>$param["interNo"]])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  182. if($del==false)return error_show(1004,"录单数据删除失败");
  183. return app_show(0,"数据删除成功");
  184. }
  185. }