InterOrder.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\Db;
  4. use think\facade\Validate;
  5. use think\App;
  6. class InterOrder extends \app\admin\BaseController{
  7. public function __construct(App $app) {
  8. parent::__construct($app);
  9. }
  10. /**
  11. * @return \think\response\Json|void
  12. * @throws \think\db\exception\DataNotFoundException
  13. * @throws \think\db\exception\DbException
  14. * @throws \think\db\exception\ModelNotFoundException
  15. */
  16. public function list(){
  17. $param = $this->request->only(["page"=>1,"size"=>10,'cgdNo'=>"","qrdNo"=>"","khNo"=>"",
  18. "supplierNo"=>"","companyNo"=>"","starttime"=>"","endtime"=>"","sale_name"=>"","cgd_saler"=>""],"post","trim");
  19. $where=[["b.is_del","=",0],["c.is_del","=",0],["b.qrdSource","=",10],["c.cgdSource","=",10]];
  20. if($param['cgdNo']!="") $where[]=["a.cgdNo","like","%{$param['cgdNo']}%"];
  21. if($param['qrdNo']!="") $where[]=["a.orderCode","like","%{$param['qrdNo']}%"];
  22. if($param['khNo']!="") $where[]=["b.customerNo","like","%{$param['khNo']}%"];
  23. if($param['companyNo']!="") $where[]=["b.companyNo","like","%{$param['companyNo']}%"];
  24. if($param['supplierNo']!="") $where[]=["c.supplierNo","like","%{$param['supplierNo']}%"];
  25. if($param['starttime']!="") $where[]=["a.addtime",">=",date("Y-m-d 00:00:00",strtotime($param['starttime']))];
  26. if($param['endtime']!="") $where[]=["a.addtime","<=",date("Y-m-d 23:59:59",strtotime($param['endtime']))];
  27. if($param['sale_name']!="") $where[]=["b.ownerName","like","%{$param['sale_name']}%"];
  28. if($param['cgd_saler']!="") $where[]=["c.ownerName","like","%{$param['cgd_saler']}%"];
  29. $count= Db::name("inter_order")->alias("a")
  30. ->leftJoin("qrd_info b","a.orderCode=b.sequenceNo and b.is_del=0 and b.qrdSource=10")
  31. ->leftJoin("cgd_info c","b.cgdNo=c.sequenceNo and c.is_del=0 and c.cgdSource=10")->where($where)->count();
  32. $total =ceil($count/$param['size']);
  33. $page =$total>=$param['page'] ? intval($param['page']): intval($total);
  34. $list= Db::name("inter_order")->alias("a")
  35. ->leftJoin("qrd_info b","a.orderCode=b.sequenceNo and b.is_del=0 and b.qrdSource=10")
  36. ->leftJoin("cgd_info c","b.cgdNo=c.sequenceNo and c.is_del=0 and c.cgdSource=10")
  37. ->field("a.id,
  38. a.orderCode,
  39. b.customerName as khName,
  40. b.customerNo as khNo,
  41. b.companyName,
  42. b.companyNo,
  43. a.rate*100 as cgd_tax,
  44. c.supplierName,
  45. c.supplierNo,
  46. b.poCode,
  47. a.addtime as ordertime,
  48. b.ownerName as sale_name,
  49. c.ownerName as cgd_saler,
  50. c.department as cgd_depart,
  51. b.department as sale_depart,
  52. b.goodName,
  53. b.tax,
  54. b.goodPrice,
  55. b.goodNum,
  56. b.totalPrice,
  57. b.apay_fee,
  58. b.wpay_fee,
  59. b.ainv_fee,
  60. b.winv_fee,
  61. b.qrdType,
  62. b.catInfo,
  63. a.cgdNo,
  64. b.workCode")
  65. ->json(["catInfo"])
  66. ->where($where)->page($page,intval($param['size']))->order("id desc")
  67. ->select()->toArray();
  68. // echo Db::name("inter_order")->getLastSql();
  69. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  70. }
  71. public function create(){
  72. $param =$this->request->only([
  73. "sale_name"=>"","sale_id"=>"","companyNo"=>'',"poCode"=>"","workCode"=>"","khNo"=>"","qrdType"=>"","goodName"=>"",
  74. "tax"=>"","goodNum"=>"","goodPrice"=>"","mobile"=>"","addr"=>"","contactor"=>"",
  75. "buyer"=>"","buyerid"=>"","sendtime"=>"","cat"=>'',"supplierNo"=>"","cgd_tax"=>"","sale_depart"=>"","cgd_depart"=>""
  76. ],"post");
  77. $valid =Validate::rule([
  78. "sale_name|业务员名称"=>"require|max:255|min:1",
  79. "sale_id|业务员名称"=>"require|number|gt:0",
  80. "companyNo|业务公司编号"=>"require|max:255|min:1",
  81. "supplierNo|业务公司编号"=>"require|max:255|min:1",
  82. "poCode|PO编号"=>"require|max:255|min:1",
  83. "workCode|单据编号"=>"require|max:255|min:1",
  84. "khNo|客户公司编号"=>"require|max:255|min:1",
  85. "qrdType|订单类型"=>"require|number|in:[1,2,3]",
  86. "goodName|商品名称"=>"require|max:255|min:1",
  87. "tax|税率"=>"require|number|gt:0",
  88. "goodNum|商品数量"=>"require|number|gt:0",
  89. "goodPrice|商品单价"=>"require|float|gt:0",
  90. "mobile|联系人电话"=>"require|number|mobile",
  91. "contactor|联系人"=>"require|max:255|min:1",
  92. "addr|收货地址"=>"require|max:255|min:1",
  93. "buyer|销售员"=>"require|max:255|min:1",
  94. "buyerid|销售员"=>"require|number|gt:0",
  95. "sendtime|发货时间"=>"require|date",
  96. "cat|商品分类id"=>"require|number|gt:0",
  97. "cgd_tax|采购毛利率"=>"require|float|gt:0",
  98. "sale_depart|销售员部门"=>"require|max:255|min:1",
  99. "cgd_depart|采购员部门"=>"require|max:255|min:1",
  100. ]);
  101. if($valid->check($param)==false)return error_show(1004,$valid->getError());
  102. $qrdcode =makeNo("QRD");
  103. $cgddcode =makeNo("CGD");
  104. $goodCode =makeNo("SPU");
  105. $customer =Db::name("customer_info")->where('companyNo', "=", $param['khNo'])->find();
  106. $supplierName =Db::name("supplier_info")->where('code', "=", $param['supplierNo'])->value("name","");
  107. $companyName =Db::name("supplier_info")->where('code', "=", $param['companyNo'])->value("name","");
  108. $taxinfo = Db::name("order_rate")->where(["id"=>$param["tax"],"status"=>1])->value("rate",0);
  109. $param["cgd_tax"]=$param["cgd_tax"]/100;
  110. $cat = [];
  111. $this->cat($param['cat'],$cat);
  112. if(empty($cat)) return error_show(1004,'分类信息为找到');
  113. $inter=[
  114. "cgdNo"=>$cgddcode,
  115. "orderCode"=>$qrdcode,
  116. "rate"=>$param["cgd_tax"],
  117. "apply_id"=>$this->uid,
  118. "apply_name"=>$this->uname,
  119. "mobile"=>$param['mobile'],
  120. "contactor"=>$param['contactor'],
  121. "sendtime"=>$param['sendtime'],
  122. "addr"=>$param['addr'],
  123. ];
  124. $qrd =[
  125. 'name' => $param['sale_depart']."销售单",//确认单名称,
  126. 'sequenceNo' => $qrdcode,//确认单编号,
  127. 'ownerName' => $param['sale_name'],//销售员,
  128. 'ownerid' => $param['sale_id'],//销售员id,
  129. 'department' => $param['sale_depart'],//部门,
  130. 'createdTime' => date("Y-m-d H:i:s"),//销售单创建时间,
  131. 'qrdType' => $param['qrdType'],//销售单类型,
  132. 'qrdSource' => 10,//销售单来源,
  133. 'companyNo' => $param['companyNo'],//业务企业编号,
  134. 'companyName' => $companyName,//业务企业名称,
  135. 'customerNo' => $param['khNo'],//客户编号,
  136. 'customerName' =>$customer['companyName']??"",//客户名称,
  137. 'poCode' => $param['poCode'],//po编号,
  138. 'platName' => '',//平台名称,
  139. 'workCode' =>$param['workCode'],//业务编号,
  140. 'zxCode' => '',//咨询单编号,
  141. 'goodNo' => $goodCode,//商品编号,
  142. 'goodName' => $param['goodName'],//商品名称,
  143. 'goodBrand' =>'',//商品品牌,
  144. 'firstCat' => $cat[0]['cat_name']??"",//一级分类,
  145. 'secCat' => $cat[1]['cat_name']??"",//二级分类,
  146. 'thirdCat' => $cat[2]['cat_name']??"",//三级分类,
  147. 'catInfo' => json_encode($cat,JSON_UNESCAPED_UNICODE),//分类详情,
  148. 'fundCode' => $cat[2]['fund_code']??"",//核算编码,
  149. 'goodMaterial' => '',//商品材质,
  150. 'goodUnit' => '',//商品单位,
  151. 'goodDesc' => '',//工艺说明,
  152. 'goodType' =>1,//商品类型,
  153. 'goodModel' => '',//商品型号,
  154. 'isStock' => 0,//是否库存品,
  155. 'metalsType' =>'',//贵金属种类,
  156. 'weight' => 0,//商品重量,
  157. 'goldPrice' => 0,//贵金属单价,
  158. 'deliveryDay' =>'',//物流天数,
  159. 'workDay' => '',//工期,
  160. 'tax' => $taxinfo,//税率,
  161. 'goodNum' => $param['goodNum'],//销售数量,
  162. 'goodPrice' => $param['goodPrice'],//产品单价,
  163. 'totalPrice' =>round( $param['goodPrice']*$param['goodNum'],2),//货款总额,
  164. 'sendNum' => $param['goodNum'],//已发货数量,
  165. 'wsendNum' => 0,//未发货数量,
  166. 'apay_fee' => 0,//已付款,
  167. 'pay_fee' => 0,//付款中
  168. 'wpay_fee' => round( $param['goodPrice']*$param['goodNum'],2),
  169. 'inv_fee' => 0,//回票中
  170. 'ainv_fee' => 0,//已开票,
  171. 'winv_fee' =>round( $param['goodPrice']*$param['goodNum'],2),
  172. 'is_diff' =>0,//是否有工差,
  173. 'sendType' => 1,//发货方式,
  174. 'sendStatus' =>3,//发货状态,
  175. 'pay_status' =>1,//收款状态,1未付,2部分,3完结
  176. 'inv_status' => 1,//开票状态,,1未付,2部分,3完结
  177. 'remark' => '',//备注,
  178. 'diff_weight' =>0,//工差重量,
  179. 'diff_fee' =>0,//工差金额,
  180. 'area' =>$customer['companyName']??"",//公司,
  181. 'customerAttr' => $customer['parent']??"",//客户属性,
  182. 'branch' => $customer['branch']??"",//分公司,从客户表中查
  183. 'cgdNo' => $cgddcode,//采购单号,
  184. 'thNum' => 0,//退货数量,
  185. 'th_fee' => 0,//退货金额,
  186. 'is_del' => 0,//是否删除,
  187. 'addtime' => date("Y-m-d H:i:s"),
  188. 'updatetime' =>date("Y-m-d H:i:s"),
  189. 'inv_tag' => 0,//开票标签,
  190. 'pay_tag' => 0,//回款标签,
  191. 'inv_tag_fee' => 0,//开票票标签金额,
  192. 'pay_tag_fee' => 0,//回款标签金额,
  193. ];
  194. $cgd=[
  195. 'name' => $param['cgd_depart']."采购单",//采购单名称',
  196. 'sequenceNo' => $cgddcode,//采购单编号',
  197. 'ownerName' => $param['buyer'],//采购员名称',
  198. 'ownerid' => $param['buyerid'],//采购员id',
  199. 'department' => $param['cgd_depart'],//部门名称',
  200. 'createdTime' => date("Y-m-d H:i:s"),//订单创建时间',
  201. 'cgdType' =>$param['qrdType'],//采购单类型',
  202. 'cgdSource' =>10,//采购单来源',
  203. 'companyNo' => $param['companyNo'],//业务公司编号',
  204. 'companyName' => $companyName,//业务公司',
  205. 'cgdTime' => date("Y-m-d H:i:s"),//采购下单时间',
  206. 'bkCode' => '',//备库单编号',
  207. 'qrdCode' => $qrdcode,//确认单编号',
  208. 'goodNo' => $goodCode,//商品编号',
  209. 'goodName' => $param['goodName'],//商品名称',
  210. 'goodType' => 1,//商品类型',
  211. 'goodBrand' =>'',//商品品牌',
  212. 'goodModel' => '',//商品型号',
  213. 'firstCat' => $cat[0]['cat_name']??"",//商品一级分类',
  214. 'secCat' => $cat[1]['cat_name']??"",//二级分类',
  215. 'thirdCat' => $cat[2]['cat_name']??"",//三级分类',
  216. 'catInfo' => json_encode($cat,JSON_UNESCAPED_UNICODE),//分类明细',
  217. 'fundCode' => $cat[2]['fund_code']??"",//NOT NULL,
  218. 'goodMaterial' => '',//商品材质',
  219. 'goodUnit' => '',//商品单位',
  220. 'goodDesc' => '',//工艺说明',
  221. 'metalsType' => '',//贵金属种类',
  222. 'weight' => 0,//商品重量',
  223. 'goldPrice' => 0,//贵金属实时金价',
  224. 'is_diff' =>0,//是否有工差',
  225. 'deliveryDay' =>'',//物流天数',
  226. 'workDay' =>'',//产品工期',
  227. 'tax' => $taxinfo,//税点',
  228. 'barePrice' => 0,//裸价',
  229. 'markPrice' => 0,//加标费',
  230. 'packPrice' => 0,//包装费',
  231. 'certPrice' => 0,//证书费',
  232. 'openPrice' => 0,//开模费',
  233. 'costPrice' => 0,//工艺费',
  234. 'deliveryPrice' =>0,//物流费',
  235. 'goodPrice' => round( $param['goodPrice']*(1-$param['cgd_tax']),2),//成本合计/单价',
  236. 'isStock' =>0,//是否库存品',
  237. 'goodNum' => $param['goodNum'],//下单数量',
  238. 'totalPrice' => round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2),//采购总货款',
  239. 'supplierNo' => $param['supplierNo'],//供应商编号',
  240. 'supplierName' => $supplierName,//供应商名称',
  241. 'apay_fee' => 0,//已付款金额',
  242. 'wpay_fee' =>round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2),//采购总货款',
  243. 'ainv_fee' => 0,//已开票金额',
  244. 'winv_fee' =>round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2),//采购总货款',
  245. 'sendType' => 1,//发货方式',
  246. 'bkCreater' => '',//备库申请人',
  247. 'sendStatus' => 3,//发货状态',
  248. 'wsendNum' =>0,//未发货数量',
  249. 'sendNum' => $param['goodNum'],//已发货数量',
  250. 'wareHouse' => '',//仓库名称',
  251. 'wsmCode' =>'',//仓库编号',
  252. 'remark' => '',//备注',
  253. 'pay_status' =>1,//付款情况',
  254. 'inv_status' => 1,//开票情况',
  255. 'diff_weight' => 0,//工差重量',
  256. 'diff_fee' => 0,//工差金额',
  257. 'thNum' => 0,//退货数量',
  258. 'th_fee' => 0,//退货金额',
  259. 'check_rate' => '',//修正后的税率',
  260. 'is_del' => 0,
  261. 'addtime' => date("Y-m-d H:i:s"),
  262. 'updatetime' => date("Y-m-d H:i:s"),
  263. ];
  264. $good=[
  265. "spuCode"=>$goodCode,
  266. "good_name"=>$param['goodName'],
  267. "companyNo"=>$param['companyNo'],
  268. "supplierNo"=>$param['supplierNo'],
  269. "is_stock"=>0,
  270. "craft_desc"=>'',
  271. "after_sales"=>'',
  272. "good_img"=>'',
  273. "good_thumb_img"=>'',
  274. "good_info_img"=>'',
  275. "creater"=>$this->uname,
  276. "createrid"=>$this->uid,
  277. "cat_name"=>$cat[2]['cat_name'],
  278. "unit_name"=>'',
  279. "isZx"=>0,
  280. "status"=>0,
  281. "addtime"=>date("Y-m-d H:i:s"),
  282. "updatetime"=>date("Y-m-d H:i:s")
  283. ];
  284. $repostinsert=[
  285. "qrdNo"=>$qrdcode ,
  286. "seller_id"=>$param['sale_id'] ,
  287. "seller"=>$param['sale_name'] ,
  288. "cgder_id"=>$param['buyerid'] ,
  289. "cgder"=>$param['buyer'] ,
  290. "customerName"=>$customer['companyName']??"",
  291. "customerNo"=>$param['khNo'],//客户编号,
  292. "companyNo"=>$param['companyNo'],
  293. "companyName"=> $companyName ,
  294. "supplierNo"=>$param['supplierNo'],
  295. "supplierName"=> $supplierName ,
  296. "cgdNo"=>$cgddcode,
  297. ];
  298. Db::startTrans();
  299. try {
  300. $a = Db::name("qrd_info")->insert($qrd);
  301. $d = Db::name("inter_order")->insert($inter);
  302. $b = Db::name('cgd_info')->insert($cgd);
  303. $c = Db::name('good')->insert($good);
  304. $e=Db::name("report_code")->insert($repostinsert);
  305. if ($a && $b && $c && $d && $e) {
  306. Db::commit();
  307. return app_show(0,'新建成功');
  308. } else {
  309. Db::rollback();
  310. return error_show(1004,'新建失败');
  311. }
  312. } catch (\Exception $e) {
  313. Db::rollback();
  314. return error_show(1004, $e->getMessage());
  315. }
  316. }
  317. public function save(){
  318. $param =$this->request->only([
  319. "sale_name"=>"","sale_id"=>"","companyNo"=>'',"poCode"=>"","workCode"=>"","khNo"=>"","qrdType"=>"","goodName"=>"",
  320. "tax"=>"","goodNum"=>"","goodPrice"=>"","good_total"=>"","mobile"=>"","addr"=>"","contactor"=>"","id"=>"",
  321. "buyer"=>"","buyerid"=>"","sendtime"=>"","cat"=>'',"supplierNo"=>"","cgd_tax"=>"","sale_depart"=>"","cgd_depart"=>""
  322. ],"post");
  323. $valid =Validate::rule([
  324. "id|主键ID"=>"require|number|gt:0",
  325. "sale_name|业务员名称"=>"require|max:255|min:1",
  326. "sale_id|业务员名称"=>"require|number|gt:0",
  327. "companyNo|业务公司编号"=>"require|max:255|min:1",
  328. "supplierNo|业务公司编号"=>"require|max:255|min:1",
  329. "poCode|PO编号"=>"require|max:255|min:1",
  330. "workCode|单据编号"=>"require|max:255|min:1",
  331. "khNo|客户公司编号"=>"require|max:255|min:1",
  332. "qrdType|订单类型"=>"require|number|in:[1,2,3]",
  333. "goodName|商品名称"=>"require|max:255|min:1",
  334. "tax|税率"=>"require|number|gt:0",
  335. "goodNum|商品数量"=>"require|number|gt:0",
  336. "goodPrice|商品单价"=>"require|float|gt:0",
  337. "mobile|联系人电话"=>"require|number|mobile",
  338. "contactor|联系人"=>"require|max:255|min:1",
  339. "addr|收货地址"=>"require|max:255|min:1",
  340. "buyer|销售员"=>"require|max:255|min:1",
  341. "buyerid|销售员"=>"require|number|gt:0",
  342. "sendtime|发货时间"=>"require|date",
  343. "cat|商品分类"=>"require|number|gt:0",
  344. "cgd_tax|采购毛利率"=>"require|float|gt:0",
  345. "sale_depart|销售员部门"=>"require|max:255|min:1",
  346. "cgd_depart|采购员部门"=>"require|max:255|min:1",
  347. ]);
  348. if($valid->check($param)==false)return error_show(1004,$valid->getError());
  349. $inter_order=Db::name("inter_order")->where(["id"=>$param['id']])->findOrEmpty();
  350. if(empty($inter_order)) return error_show(1004,"未找到订单数据");
  351. $qrd_order=Db::name("qrd_info")->where(["sequenceNo"=>$inter_order['orderCode']])->findOrEmpty();
  352. if(empty($qrd_order)) return error_show(1004,"未找到销售单数据");
  353. $cgd_order=Db::name("cgd_info")->where(["sequenceNo"=>$inter_order['cgdNo']])->findOrEmpty();
  354. if(empty($cgd_order)) return error_show(1004,"未找到采购单数据");
  355. $goodinfo=Db::name("good")->where(["spuCode"=>$qrd_order['goodNo']])->findOrEmpty();
  356. if(empty($goodinfo)) return error_show(1004,"未找到商品数据");
  357. $param["cgd_tax"]=$param["cgd_tax"]/100;
  358. $customer =Db::name("customer_info")->where('companyNo', "=", $param['khNo'])->find();
  359. $supplierName =Db::name("supplier_info")->where('code', "=", $param['supplierNo'])->value("name","");
  360. $companyName =Db::name("supplier_info")->where('code', "=", $param['companyNo'])->value("name","");
  361. $taxinfo = Db::name("order_rate")->where(["id"=>$param["tax"],"status"=>1])->value("rate",0);
  362. $report = Db::name("report_code")->where(["qrdNo"=>$inter_order['orderCode'],"cgdNo"=>$inter_order['cgdNo']])
  363. ->findOrEmpty();
  364. $cat = [];
  365. if($qrd_order['status']!=0) return error_show(1004,"销售单已对账,无法修改");
  366. if($cgd_order['status']!=0) return error_show(1004,"采购单已对账,无法修改");
  367. $this->cat($param['cat'],$cat);
  368. if(empty($cat)) return error_show(1004,'分类信息为找到');
  369. $inter=[
  370. "id"=>$inter_order['id'],
  371. "rate"=>$param["cgd_tax"],
  372. "mobile"=>$param['mobile'],
  373. "contactor"=>$param['contactor'],
  374. "addr"=>$param['addr'],
  375. "sendtime"=>$param['sendtime'],
  376. "updatetime"=>date("Y-m-d H:i:s")
  377. ];
  378. $qrd =["id"=>$qrd_order['id'],
  379. 'name' => $param['sale_depart']."销售单",//确认单名称,
  380. 'ownerName' => $param['sale_name'],//销售员,
  381. 'ownerid' => $param['sale_id'],//销售员id,
  382. 'department' => $param['sale_depart'],//部门,
  383. 'qrdType' => $param['qrdType'],//销售单类型,
  384. 'companyNo' => $param['companyNo'],//业务企业编号,
  385. 'companyName' => $companyName,//业务企业名称,
  386. 'customerNo' => $param['khNo'],//客户编号,
  387. 'customerName' =>$customer['companyName']??"",//客户名称,
  388. 'poCode' => $param['poCode'],//po编号,
  389. 'workCode' =>$param['workCode'],//业务编号,
  390. 'goodName' => $param['goodName'],//商品名称,
  391. 'firstCat' => $cat[0]['cat_name']??"",//一级分类,
  392. 'secCat' => $cat[1]['cat_name']??"",//二级分类,
  393. 'thirdCat' => $cat[2]['cat_name']??"",//三级分类,
  394. 'catInfo' => json_encode($cat,JSON_UNESCAPED_UNICODE),//分类详情,
  395. 'fundCode' => $cat[2]['fund_code']??"",//核算编码,
  396. 'tax' => $taxinfo,//税率,
  397. // 'goodNum' => $param['goodNum'],//销售数量,
  398. // 'goodPrice' => $param['goodPrice'],//产品单价,
  399. // 'totalPrice' =>round( $param['goodPrice']*$param['goodNum'],2),//货款总额,
  400. // 'sendNum' => $param['goodNum'],//已发货数量,
  401. // 'wpay_fee' => round( $param['goodPrice']*$param['goodNum'],2),
  402. // 'winv_fee' =>round( $param['goodPrice']*$param['goodNum'],2),
  403. 'area' =>$customer['companyName']??"",//公司,
  404. 'customerAttr' => $customer['parent']??"",//客户属性,
  405. 'branch' => $customer['branch']??"",//分公司,从客户表中查
  406. 'updatetime' =>date("Y-m-d H:i:s"),
  407. ];
  408. $cgd=["id"=>$cgd_order['id'],
  409. 'name' => $param['cgd_depart']."采购单",//采购单名称',
  410. 'ownerName' => $param['buyer'],//采购员名称',
  411. 'ownerid' => $param['buyerid'],//采购员id',
  412. 'department' => $param['cgd_depart'],//部门名称',
  413. 'cgdType' =>$param['qrdType'],//采购单类型',
  414. 'companyNo' => $param['companyNo'],//业务公司编号',
  415. 'companyName' => $companyName,//业务公司',
  416. 'goodName' => $param['goodName'],//商品名称',
  417. 'firstCat' => $cat[0]['cat_name']??"",//商品一级分类',
  418. 'secCat' => $cat[1]['cat_name']??"",//二级分类',
  419. 'thirdCat' => $cat[2]['cat_name']??"",//三级分类',
  420. 'catInfo' => json_encode($cat,JSON_UNESCAPED_UNICODE),//分类明细',
  421. 'fundCode' => $cat[2]['fund_code']??"",//NOT NULL,
  422. 'tax' => $taxinfo,//税点',
  423. 'supplierNo' => $param['supplierNo'],//供应商编号',
  424. 'supplierName' => $supplierName,//供应商名称',
  425. 'updatetime' => date("Y-m-d H:i:s"),
  426. ];
  427. if($qrd_order['status']==0 && $cgd_order['status']==0){
  428. $qrd['goodNum'] = $param['goodNum'];//销售数量,
  429. $qrd['goodPrice'] = $param['goodPrice'];//销售数量,
  430. $qrd['totalPrice'] = round( $param['goodPrice']*$param['goodNum'],2);//销售数量,
  431. $qrd['sendNum'] = $param['goodNum'];//销售数量,
  432. $qrd['wpay_fee'] = round( $param['goodPrice']*$param['goodNum'],2);//销售数量,
  433. $qrd['winv_fee'] = round( $param['goodPrice']*$param['goodNum'],2);//销售数量,
  434. $cgd['goodNum'] = $param['goodNum'];//销售数量,
  435. $cgd['goodPrice'] =round( $param['goodPrice']*(1-$param['cgd_tax']),2);//销售数量,
  436. $cgd['totalPrice'] = round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2);//销售数量,
  437. $cgd['sendNum'] = $param['goodNum'];//销售数量,
  438. $cgd['wpay_fee'] = round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2);//销售数量,
  439. $cgd['winv_fee'] = round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2);//销售数量,
  440. }
  441. $good=[
  442. "id"=>$goodinfo['id'],
  443. "good_name"=>$param['goodName'],
  444. "companyNo"=>$param['companyNo'],
  445. "supplierNo"=>$param['supplierNo'],
  446. "cat_name"=>$cat[2]['cat_name'],
  447. "updatetime"=>date("Y-m-d H:i:s")
  448. ];
  449. $repostinsert=[
  450. "seller_id"=>$param['sale_id'] ,
  451. "seller"=>$param['sale_name'] ,
  452. "cgder_id"=>$param['buyerid'] ,
  453. "cgder"=>$param['buyer'] ,
  454. "customerName"=>$customer['companyName']??"",
  455. "customerNo"=>$param['khNo'],//客户编号,
  456. "companyNo"=>$param['companyNo'],
  457. "companyName"=> $companyName ,
  458. "supplierNo"=>$param['supplierNo'],
  459. "supplierName"=> $supplierName ,
  460. ];
  461. if(empty($report)){
  462. $repostinsert['qrdNo'] =$inter_order['orderCode'];
  463. $repostinsert['cgdNo'] =$inter_order['cgdNo'];
  464. }else{
  465. $repostinsert['id'] = $report['id'];
  466. }
  467. Db::startTrans();
  468. try {
  469. $a = Db::name("qrd_info")->save($qrd);
  470. $d = Db::name("inter_order")->save($inter);
  471. $b = Db::name('cgd_info')->save($cgd);
  472. $c = Db::name('good')->save($good);
  473. Db::name('report_code')->save($repostinsert);
  474. if ($a && $b && $d &&$c) {
  475. Db::commit();
  476. return app_show(0,'更新成功');
  477. } else {
  478. Db::rollback();
  479. return error_show(1004,'更新失败');
  480. }
  481. } catch (\Exception $e) {
  482. Db::rollback();
  483. return error_show(1004, $e->getMessage());
  484. }
  485. }
  486. public function info(){
  487. $post=$this->request->post();
  488. $id = isset($post['id'])&&$post['id']!='' ? $post['id'] :"";
  489. $condition = [['a.id',"=",$id],["b.is_del","=",0],["c.is_del","=",0],["b.qrdSource","=",10],["c.cgdSource","=",10]];
  490. $list=Db::name('inter_order')->alias('a')->join('qrd_info b',"a.orderCode=b.sequenceNo and b.is_del=0 and b.qrdSource=10",'left')
  491. ->join('cgd_info c',"a.cgdNo=c.sequenceNo and c.is_del=0 and c.cgdSource=10",'left')->json
  492. (["cat"])->where($condition)
  493. ->order("a.addtime desc")->field('a.id,
  494. b.goodNo ,
  495. a.orderCode,
  496. b.customerNo as khNo,
  497. b.customerName as khName,
  498. b.companyName,
  499. b.companyNo,
  500. b.poCode,
  501. b.workCode,
  502. a.addtime as ordertime,
  503. b.ownerName as sale_name,
  504. b.ownerid as sale_id,
  505. b.department as sale_depart,
  506. b.goodName,
  507. b.goodNo,
  508. b.tax,
  509. b.catInfo as cat,
  510. b.goodPrice,
  511. b.goodNum,
  512. b.totalPrice,
  513. b.qrdType,
  514. c.supplierName,
  515. c.supplierNo,
  516. a.cgdNo,
  517. c.ownerName as buyer,
  518. c.ownerid as buyerid,
  519. c.department as cgd_depart,
  520. a.sendtime ,
  521. a.rate*100 as cgd_tax,
  522. a.contactor,
  523. a.mobile,
  524. a.addr
  525. ')->findOrEmpty();
  526. if(empty($list)){
  527. return error_show(1004,'未找到数据');
  528. }
  529. $list['rateid'] = Db::name("order_rate")->where('rate',"=",$list['tax'])->value("id",'');
  530. return app_show(0,"获取成功",$list);
  531. }
  532. public function getCat(){
  533. $post=$this->request->post();
  534. $condition = [['status',"=",1],["is_del","=",0],['level',"=",3]];
  535. $cat_name=isset($post['cat_name']) && $post['cat_name'] !==""? trim($post['cat_name']) :"";
  536. if($cat_name!==""){
  537. $condition[]=['cat_name',"like","%$cat_name%"];
  538. }
  539. $search=isset($post['search']) && $post['search'] !==""? trim($post['search']) :"";
  540. if($search!==""){
  541. $condition[]=['search',"like","%$search%"];
  542. }
  543. $cat = Db::connect("mysql_wsm")->name("cat")->where($condition)->field("id,cat_name,fund_code,search")->order
  544. ("weight desc ,addtime desc")->select()->toArray();
  545. return app_show(0,"获取成功",$cat);
  546. }
  547. private function cat($id,&$cat=[]){
  548. $condition[]=["id","=",$id];
  549. $data= Db::connect("mysql_wsm")->name("cat")->where($condition)->field("id,cat_name,fund_code,pid")->findOrEmpty();
  550. array_unshift($cat,$data);
  551. if($data['pid']==0||empty($data)) return $cat;
  552. else $this->cat($data['pid'],$cat);
  553. }
  554. }