InterOrder.php 33 KB

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