NowReportHandle.php 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\command;
  4. use app\admin\common\User;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\Output;
  8. use think\Exception;
  9. use think\facade\Cache;
  10. use think\facade\Db;
  11. //处理报表预约记录,生成报表文件
  12. class NowReportHandle extends Command
  13. {
  14. //redis队列的key,在ReportReserve控制器中也有定义,要同步修改(轻易不要修改)
  15. private $key = 'cxreport';
  16. protected function configure()
  17. {
  18. // 指令配置
  19. $this->setName('"cxreport"')
  20. ->setDescription('定时处理报表预约,生成报表文件');
  21. }
  22. //处理报表预约记录,生成报表文件
  23. protected function execute(Input $input, Output $output)
  24. {
  25. ini_set('memory_limit', '-1');
  26. $info = Cache::store('redis')->handler()->rpop($this->key);
  27. try {
  28. if ($info) {
  29. $info = json_decode($info, true);
  30. //不同的方法处理不同的脚本
  31. switch ($info['code']) {
  32. // //【财务报表】退货台账-业务口径
  33. // case 'A':
  34. // $res = $this->A($info['start'], $info['end']);
  35. // break;
  36. // //【财务报表】库存日报及预警汇总表
  37. // case 'B':
  38. // $res = $this->B($info['start'], $info['end']);
  39. // break;
  40. //【财务报表】退货台账
  41. case 'C':
  42. $res = $this->C($info['start'], $info['end']);
  43. break;
  44. //【财务报表】出入库明细
  45. case 'D':
  46. $res = $this->D($info['start'], $info['end']);
  47. break;
  48. //【财务报表】库存品入库明细
  49. case 'E':
  50. $res = $this->E($info['start'], $info['end']);
  51. break;
  52. //【财务报表】库存品出库明细
  53. // case 'F':
  54. // $res = $this->F($info['start'], $info['end']);
  55. // break;
  56. //【销售】订单表导出
  57. case 'G':
  58. $res = $this->G($info['start'], $info['end']);
  59. break;
  60. //【库存报表】-库存日报及预警汇总表
  61. case 'H':
  62. $res = $this->H($info['start'], $info['end']);
  63. break;
  64. //【库存报表】-出入库明细
  65. case 'I':
  66. $res = $this->I($info['start'], $info['end']);
  67. break;
  68. //【库存报表】-库存品入库明细
  69. case 'J':
  70. $res = $this->J($info['start'], $info['end']);
  71. break;
  72. //【库存报表】-库存品出库明细
  73. case 'K':
  74. $res = $this->K($info['start'], $info['end']);
  75. break;
  76. //【库存报表】-库存品出库明细
  77. case 'L':
  78. $res = $this->NewOut($info['start'], $info['end']);
  79. break;
  80. //每日库存数据更新
  81. case 'M':
  82. $res = $this->EveryDayStock($info['start'], $info['end']);
  83. break;
  84. //商品成本信息
  85. case 'N':
  86. $res = $this->GetGoodNake();
  87. break;
  88. //商品售价信息
  89. case 'P':
  90. $res = $this->GetGoodLadder();
  91. break;
  92. case 'Q':
  93. $res = $this->GetBid($info['start'], $info['end']);
  94. break;
  95. default:
  96. throw new Exception('暂不支持这个报表');
  97. }
  98. $file = excelSaveFile($res, $info['name'] . date('YmdHis'));
  99. Db::name('exec')
  100. ->where(['id' => $info['id'], 'status' => 1])//status==1 待处理
  101. ->update([
  102. 'status' => 2, //status==2 处理完成
  103. 'down_url' => $file,
  104. 'updatetime' => date('Y-m-d H:i:s'),
  105. 'expiretime' => date('Y-m-d H:i:s', strtotime('+7 day'))
  106. ]);
  107. $output->writeln('【' . $info['id'] . '】该预约记录处理成功');
  108. } //else $output->writeln('没有可供处理的报表预约记录');
  109. } catch (\Exception $exception) {
  110. Db::name('exec')
  111. ->where(['id' => $info['id'], 'status' => 1])//status==1 待处理
  112. ->update([
  113. 'status' => 0, //status==2 处理完成
  114. 'down_url' => '',
  115. 'updatetime' => date('Y-m-d H:i:s'),
  116. 'expiretime' => date('Y-m-d H:i:s', strtotime('+7 day'))
  117. ]);
  118. $output->writeln($exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
  119. }
  120. }
  121. //【财务报表】退货台账-业务口径
  122. private function A(string $start_date = '', string $end_date = '')
  123. {
  124. $data = Db::name('order_back')
  125. ->alias('ob')
  126. ->field('ob.thNo 退货单号,ob.status 流程进度,ob.addtime 退货发起日期,"" 退货人所在部门,ob.apply_name 退货人,ob.return_num 退货数量,ob.total_fee 退货销售货款,ob.remark 退货备注,"" 客户名称,ob.customer_code 客户编码,"" 一级组织,"" 二级组织,"" 三级组织,p.platform_name 平台名称,s.poNo PO编号,s.orderCode 确认单编号,s.order_type 确认单类型,s.addtime 确认单下单时间,"" 业务人员所在部门,ob.cgder 业务人员,s.good_code 确认单产品编号,ob.good_name 产品名称,s.skuCode 产品编码,"" 一级分类,0 售前记录总数,ob.apply_id,ob.cgderid,s.cat_id')
  127. ->leftJoin('sale s', 's.orderCode=ob.orderCode')
  128. // ->leftJoin('customer_info c', 'c.companyNo=ob.customer_code AND c.is_del=0')
  129. ->leftJoin('platform p', 'p.id=ob.platform_id')
  130. ->where(['ob.is_del' => 0, 'ob.status' => 4])
  131. ->whereBetween('ob.addtime', [$start_date, $end_date])
  132. ->cursor();
  133. $all_status = [1 => '待业务审批', 2 => '待专员审批', 3 => '待主管审批', 4 => '退货完成', 5 => '业务驳回', 6 => '采购驳回', 7 => '专员审批不通过'];
  134. $all_order_type = [1 => '备库', 2 => '非库存', 3 => '咨询采反', 4 => '项目采反', 5 => '平台部订单库存品', 6 => '平台部订单非库存品'];
  135. $list = [];
  136. $tmp_customer = $tmp = [];
  137. $userCommon = User::getIns();
  138. foreach ($data as $value) {
  139. $value['流程进度'] = isset($all_status[$value['流程进度']]) ? $all_status[$value['流程进度']] : '';
  140. if (!isset($tmp_customer[$value['customer_code']])) {
  141. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  142. $tmp_customer[$value['customer_code']] = ['companyName' => $temp['data']['companyName'] ?? '', 'itemid' => $temp['data']['itemid'] ?? ''];
  143. }
  144. $value['客户名称'] = $tmp_customer[$value['customer_code']]['companyName'];
  145. $value['itemid'] = $tmp_customer[$value['customer_code']]['itemid'];
  146. if (!empty($value['itemid'])) {
  147. $customer_org1 = get_top_customer_org($value['itemid']);
  148. foreach ($customer_org1 as $vv) {
  149. switch ($vv['level']) {
  150. case 1:
  151. $value['一级组织'] = $vv['name'];
  152. break;
  153. case 2:
  154. $value['二级组织'] = $vv['name'];
  155. break;
  156. case 3:
  157. $value['三级组织'] = $vv['name'];
  158. break;
  159. }
  160. }
  161. }
  162. if (!isset($tmp[$value['apply_id']])) $tmp[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);
  163. if (!isset($tmp[$value['cgderid']])) $tmp[$value['cgderid']] = get_company_name_by_uid($value['cgderid']);
  164. $value['退货人所在部门'] = $tmp[$value['apply_id']] ?? '';
  165. $value['业务人员所在部门'] = $tmp[$value['cgderid']] ?? '';
  166. $value['确认单类型'] = isset($all_order_type[$value['确认单类型']]) ? $all_order_type[$value['确认单类型']] : '';
  167. $top = made($value['cat_id']);
  168. $value['一级分类'] = isset($top[0]['name']) ? $top[0]['name'] : '';
  169. $value['售前记录总数'] = Db::name('sale_return')->where(['orderCode' => $value['确认单编号'], 'is_del' => 0, 'status' => 5])->count('id');
  170. unset($value['cat_id']);
  171. unset($value['itemid']);
  172. unset($value['apply_id']);
  173. unset($value['cgderid']);
  174. yield $list[] = $value;
  175. }
  176. return $list;
  177. }
  178. //【财务报表】库存日报及预警汇总表
  179. private function B(string $start_date = '', string $end_date = '')
  180. {
  181. $data = Db::name('good_stock')
  182. ->alias('wgs')
  183. ->field(" wwi.companyName as '公司名称',
  184. wpo.bkcode as '备库单号',
  185. wpo.cgdNo as '采购单号',
  186. wp.apply_id as '申请部门',
  187. wp.apply_name as '申请人',
  188. cat_id '一级分类',
  189. wgb.good_name '产品名称',
  190. wp.good_num '备库数量',
  191. wgs.spuCode '产品编号',
  192. wpo.good_price as '成本单价',
  193. wait_in_stock '待入库存数量',
  194. wait_out_stock '待出库存数量',
  195. usable_stock '可用库存数量',
  196. wait_out_stock+usable_stock '当前库存数量',
  197. '' as '可用库存金额',
  198. '' as '当前库存金额',
  199. '' as '保质期时间',
  200. '' as '库存天数',
  201. wgb.creater as 'CGD.采购员',
  202. wgb.supplierName as '供应商名称',
  203. wwi.`name` as '仓库名称',
  204. wp.addtime as '备库创建时间' ,
  205. ")
  206. ->leftJoin('purchease_order wpo', 'wgs.spuCode = wpo.spuCode and order_source=0')
  207. ->leftJoin('purchease wp', 'wp.bk_code = wpo.bkcode')
  208. ->leftJoin('warehouse_info wwi', 'wwi.wsm_code = wgs.wsm_code')
  209. ->leftJoin('good_basic wgb', 'wgb.spuCode = wgs.spuCode')
  210. ->where('wgs.is_del', 0)
  211. ->where('wgb.is_stock', 1)
  212. ->whereBetween('wgs.updatetime', [$start_date, $end_date])
  213. ->order('wgs.updatetime', 'desc')
  214. ->cursor();
  215. $list = $tmp = [];
  216. foreach ($data as $value) {
  217. $cat = made($value['一级分类']);
  218. $value['申请部门'] = intval($value['申请部门']);
  219. if (!isset($tmp[$value['申请部门']])) $tmp[$value['申请部门']] = get_company_name_by_uid($value['申请部门']);
  220. $value['申请部门'] = $tmp[$value['申请部门']] ?? '';
  221. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
  222. $value['可用库存金额'] = bcmul((string)$value['可用库存数量'] ?? '0', (string)$value['成本单价'] ?? '0', 2);
  223. $value['当前库存金额'] = bcmul((string)$value['当前库存数量'] ?? '0', (string)$value['成本单价'] ?? '0', 2);
  224. // $value['最近入库时间'] =Db::name("purchease_order")->alias("a")->leftJoin("purchease_in c","a.cgdNo=c.cgdNo")->where(["spuCode"=>$value['产品编号'],"order_type"=>1,"order_source"=>0,"c.status"=>[4,6]])->order("a.addtime desc")->value("c.addtime","");
  225. if (!empty($value['备库创建时间'])) {
  226. $value['保质期时间'] = date('Y-m-d H:i:s', strtotime($value['备库创建时间']) + 31536000);//365天之后
  227. $value['库存天数'] = bcdiv((string)(time() - strtotime($value['备库创建时间'])), (string)(24 * 3600));//365天之后
  228. }
  229. yield $list[] = $value;
  230. }
  231. return $list;
  232. }
  233. //【财务报表】退货台账
  234. private function C(string $start_date = '', string $end_date = '')
  235. {
  236. $data = Db::name('th_data')
  237. ->alias('wtd')
  238. ->leftJoin('sale_return wsr', 'wtd.thCode = wsr.returnCode and wtd.th_type=1')
  239. ->leftJoin('order_return wor', 'wtd.thCode = wor.returnCode and wtd.th_type in (2,3)')
  240. ->leftJoin('sale ws', 'ws.orderCode=wtd.orderCode and ws.is_del=0')
  241. ->leftJoin('order_num won', 'won.orderCode=wtd.orderCode')
  242. ->leftJoin('purchease_order wpo', 'wpo.cgdNo=won.cgdNo and wpo.is_del=0')
  243. ->whereBetween('wtd.addtime', [$start_date, $end_date])
  244. ->field(" year(wtd.addtime) '年',
  245. month(wtd.addtime) '月',
  246. DAYOFMONTH(wtd.addtime) '日',
  247. wtd.addtime '退货单创建时间',
  248. wsr.companyName as '公司名称',
  249. thCode '退货单号',
  250. if(wtd.th_type=1,'售前','售后') '退货类型',
  251. '已完成' as '流程进度',
  252. wtd.apply_id '业务部门',
  253. wtd.apply_name '业务人员',
  254. wtd.orderCode '订单编号',
  255. ws.platform_id '平台类型',
  256. ws.platform_order '平台订单号',
  257. '' as '客户属性',
  258. wtd.spuCode '产品编码',
  259. '' as '财务核算码',
  260. '' as `一级分类`,
  261. '' as `二级分类`,
  262. wtd.cat_id as `三级分类`,
  263. wtd.good_name as '商品名称',
  264. ws.order_type as `单位`,
  265. wtd.th_num '退货数量',
  266. ws.sale_price '销售单价',
  267. wtd.th_fee '退货金额',
  268. ifnull(wsr.remark,wor.error_remark) as '退货备注',
  269. won.cgdNo '采购单单号',
  270. wpo.cgder '采购员',
  271. wpo.nake_fee '采购裸价',
  272. wpo.pakge_fee '包装费',
  273. wpo.delivery_fee '物流费',
  274. wpo.cert_fee '证书费',
  275. wpo.mark_fee '加标费',
  276. wpo.open_fee '开模费',
  277. wpo.diff_weight '工差',
  278. wpo.diff_fee '采购工差金额',
  279. wpo.good_price '成本合计',
  280. (wpo.good_price * wtd.th_num) '退货采购货款',
  281. '' as '税点',
  282. wpo.supplier_name '供应商名称',
  283. if(ws.is_stock=1,'是','否') '是否库存',
  284. '' as '发货方式',
  285. if(ifnull(wsr.is_th,wor.is_th)=0,'否','是') as '供应商是否同意退货',
  286. '' as '付款方式',
  287. ws.customer_code
  288. ")->order("wtd.addtime")->cursor();
  289. $platform = Db::name('platform')->where('is_del', 0)->column('platform_name', 'id');
  290. $fund_code = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('fund_code', 'id');
  291. $userCommon = User::getIns();
  292. $temp_customer = $tmp = [];
  293. $com = [];
  294. foreach ($data as $value) {
  295. if (!isset($temp_customer[$value['customer_code']])) {
  296. $tmp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  297. $temp_customer[$value['customer_code']] = [
  298. '分公司' => $tmp['data']['itemid'] ?? '',
  299. '客户名称' => $tmp['data']['companyName'] ?? '',
  300. ];
  301. }
  302. $value['分公司'] = $temp_customer[$value['customer_code']]['分公司'] ?? '';
  303. $value['客户名称'] = $temp_customer[$value['customer_code']]['客户名称'] ?? '';
  304. $value['业务部门'] = intval($value['业务部门']);
  305. if (!isset($tmp[$value['业务部门']])) $tmp[$value['业务部门']] = get_company_name_by_uid($value['业务部门']);
  306. $value['业务部门'] = $tmp[$value['业务部门']] ?? '';//get_company_name_by_uid(intval($value['业务部门']));
  307. $value['财务核算码'] = $fund_code[$value['三级分类']] ?? '';//Db::name("cat")->where(["id"=>$value['三级分类']])->value("fund_code",'');
  308. $comp = get_top_customer_org($value['分公司']);
  309. $value['客户属性'] = isset($comp[0]['name']) ? $comp[0]['name'] : "";
  310. $value['分公司'] = isset($comp[1]['name']) ? $comp[1]['name'] : "";
  311. $top = made($value['三级分类']);
  312. $value['一级分类'] = isset($top[0]['name']) ? $top[0]['name'] : '';
  313. $value['二级分类'] = isset($top[1]['name']) ? $top[1]['name'] : '';
  314. $value['三级分类'] = isset($top[2]['name']) ? $top[2]['name'] : '';
  315. if ($value['单位'] == 3) {
  316. $good = Db::name("good_zixun")->where(["spuCode" => $value['产品编码']])->find();
  317. } else {
  318. $good = Db::name("good_basic")->where(["spuCode" => $value['产品编码']])->find();
  319. }
  320. if ($value['单位'] == 1 && $value['退货采购货款'] == 0) {
  321. $returninfo = Db::name("return_info")->where(["returnCode" => $value['退货单号']])->field("sum(origin_price * num) as cgd_total")->find();
  322. $value['退货采购货款'] = $returninfo['cgd_total'] ?? 0;
  323. }
  324. if ($value['采购员'] == '' || $value['供应商名称'] == '') {
  325. $supplier = $userCommon->handle('sInfo', ['code' => $good['supplierNo']]);//Db::name("supplier")->where(["code"=>$good['supplierNo']])->field("name,person")->find();
  326. $value['采购员'] = $supplier['data']['person'] ?? '';
  327. $value['供应商名称'] = $supplier['data']['name'] ?? '';
  328. }
  329. $value['单位'] = isset($good['good_unit']) ? Db::name("unit")->where(["id" => $good['good_unit']])->value('unit', '') : "";
  330. $value['税点'] = isset($good['tax']) ? $good['tax'] . '%' : "";
  331. $value['平台类型'] = $platform[$value['平台类型']] ?? '';//Db::name("platform")->where(["id"=>$value['平台类型']])->value("platform_name",'');
  332. unset($value['customer_code']);
  333. yield $com[] = $value;
  334. }
  335. return $com;
  336. }
  337. //【财务报表】出入库明细
  338. public function D($start, $end)
  339. {
  340. $list = Db::name("order_out")
  341. ->alias('woo')
  342. ->leftJoin("sale a", "a.orderCode=woo.orderCode and a.is_del=0")
  343. ->leftJoin("order_back wor", "wor.outCode=woo.outCode and wor.status=4 and wor.is_del=0")
  344. ->leftJoin("order_num won", "won.orderCode=a.orderCode")
  345. ->leftJoin("purchease_order wpo", "wpo.cgdNo=won.cgdNo and wpo.is_del=0")
  346. ->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode and wgb.is_del=0")
  347. ->leftJoin("good_zixun wgz", "wgz.spuCode=wpo.spuCode and wgz.is_del=0")
  348. ->where('woo.status', ">=", 2)
  349. ->where('woo.is_del', "=", 0)
  350. ->where('wpo.order_type', "<>", 1)
  351. ->whereBetween('woo.sendtime', [$start, $end])
  352. ->field(" year(`a`.`addtime`) AS `年`,
  353. month(`a`.`addtime`) AS `月`,
  354. dayofmonth(`a`.`addtime`) AS `日`,
  355. a.supplierName as '公司名称',
  356. a.apply_id '业务部门名称' ,
  357. a.apply_name as '业务人员',
  358. if(a.pay_id>0,'是','否') 是否拆单,
  359. a.order_type as '订单类型',
  360. a.good_type as '商品类型',
  361. woo.outCode '发货编号',
  362. `woo`.`send_num` AS `本次发货数量`,
  363. `woo`.`sendtime` AS `本次发货时间`,
  364. `woo`.`orderCode` AS `确认单编号`,
  365. `a`.`good_code` AS `商品编号`,
  366. '' as '一级分类',
  367. '' as '二级分类',
  368. a.cat_id as '三级分类',
  369. '' as '财务核算编码',
  370. a.good_name as '商品名称',
  371. ifnull( `wgb`.`good_unit`, `wgz`.`good_unit` ) as '单位',
  372. `a`.`good_num` AS `下单数量`,
  373. `a`.`total_price` AS `销售货款`,
  374. `wpo`.`cgdNo` AS `采购单单号`,
  375. `wpo`.`cgder` AS `采购员`,
  376. `wpo`.`nake_fee` AS `采购裸价`,
  377. `wpo`.`mark_fee` AS `加标费`,
  378. `wpo`.`pakge_fee` AS `包装费`,
  379. `wpo`.`cert_fee` AS `证书费`,
  380. `wpo`.`open_fee` AS `开模费`,
  381. `wpo`.`teach_fee` AS `工艺费`,
  382. `wpo`.`delivery_fee` AS `物流费`,
  383. `wpo`.`diff_fee` AS `公差金额`,
  384. `wpo`.`good_price` AS `成本合计`,
  385. `wpo`.`total_fee` AS `采购货款`,
  386. ifnull( `wgb`.`tax`, `wgz`.`tax` )/100 AS `采购税点`,
  387. `wpo`.`supplier_name` AS `供应商名称`,
  388. `wgb`.`is_stock` as '是否库存品',
  389. if (`wgb`.`is_stock`=1,wpo.bkcode,wpo.cgdNo) as '发货方式',
  390. ifnull( `wor`.`thNo`, '' ) AS `退货编号`,
  391. ifnull( `wor`.`return_num`, '' ) AS `退货数量`,
  392. round(( ifnull( `wor`.`return_num`, 0 ) * `a`.`sale_price` ), 2 ) as '退货金额',
  393. '' as '售前退货数量',
  394. `a`.`sale_price` as '售前退货金额'
  395. ")->cursor();
  396. $order_tyepe = ["库存销售", '非库存销售', '咨询销售', '项目销售', '平台库存销售', '平台非库存销售'];
  397. $good_type = ["常规商品", '赠品', '样品'];
  398. $data = $tmp = [];
  399. $fund_code = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('fund_code', 'id');
  400. $unit = Db::name('unit')->where('is_del', 0)->column('unit', 'id');
  401. foreach ($list as $value) {
  402. if (!isset($tmp[$value['业务部门名称']])) $tmp[$value['业务部门名称']] = get_company_name_by_uid($value['业务部门名称']);
  403. $value['业务部门名称'] = $tmp[$value['业务部门名称']] ?? '';//get_company_name_by_uid($value['业务部门名称']);//Db::name("depart_user")->alias("a")->leftJoin("company_item ci","a.itemid=ci.id")->where(["a.uid"=>$value['业务部门名称'],"a.status"=>1,"a.is_del"=>0])->value('ci.name','');
  404. $value['订单类型'] = $order_tyepe[$value['订单类型'] - 1];
  405. $value['商品类型'] = $good_type[$value['商品类型'] - 1];
  406. $cat = made($value['三级分类']);
  407. $value['财务核算编码'] = $fund_code[$value['三级分类']] ?? '';//Db::name("cat")->where(["id"=>$value['三级分类']])->value("fund_code",'');
  408. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
  409. $value['二级分类'] = isset($cat[1]['name']) ? $cat[1]['name'] : "";
  410. $value['三级分类'] = isset($cat[2]['name']) ? $cat[2]['name'] : "";
  411. $value['单位'] = $unit[$value['单位']] ?? '';//Db::name("unit")->where(["id"=>$value['单位']])->value("unit",'');
  412. if ($value['是否库存品'] == 1) {
  413. $sendtype = Db::name("purchease_order")
  414. ->alias("a")
  415. ->leftJoin("purchease_in b", "a.cgdNo=b.cgdNo and b.is_del=0")
  416. ->where(["bkcode" => $value['发货方式'], "order_type" => 1, "order_source" => 0])
  417. ->order("b.addtime desc")
  418. ->value("b.sendtype", '');
  419. $value['是否库存品'] = '是';
  420. } else {
  421. $sendtype = Db::name("purchease_order")
  422. ->alias("a")
  423. ->leftJoin("purchease_in b", "a.cgdNo=b.cgdNo and b.is_del=0")
  424. ->where(["a.cgdNo" => $value['发货方式']])
  425. ->order("b.addtime desc")
  426. ->value("b.sendtype", '');
  427. $value['是否库存品'] = '否';
  428. }
  429. $value['发货方式'] = $sendtype == 1 ? '包邮' : ($sendtype == 2 ? '自提' : "");
  430. $value['售前退货数量'] = Db::name("sale_return")->where(["orderCode" => $value['确认单编号']])->sum('num');
  431. $value['售前退货金额'] = round($value['售前退货数量'] * $value['售前退货金额'], 2);
  432. yield $data[] = $value;
  433. }
  434. $cgd = $this->GetWlb($start, $end);
  435. foreach ($cgd as $key => $value) {
  436. yield $data[] = $value;
  437. }
  438. return $data;
  439. }
  440. //【财务报表】库存品入库明细
  441. public function E($start, $end)
  442. {
  443. $list = Db::name("purchease_in")
  444. ->alias('wpi')
  445. ->leftJoin("purchease_order wpo", "wpo.cgdNo=wpi.cgdNo")
  446. ->leftJoin("purchease wp", "wpo.bkcode=wp.bk_code and wp.is_del=0")
  447. ->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode and wgb.is_del=0")
  448. ->leftJoin("warehouse_info wwi", "wwi.wsm_code = wpo.wsm_code")
  449. // ->leftJoin("supplier ws","ws.code=wpo.supplierNo")
  450. ->where('wpi.status', "=", 2)
  451. ->where('wpi.is_del', "=", 0)
  452. ->where('wpo.order_type', "=", 1)
  453. ->where('wpo.order_source', "=", 0)
  454. ->whereBetween('wpi.addtime', [$start, $end])
  455. ->field("wpo.companyName '业务公司',
  456. bkcode '备库单号',
  457. wpi.wsm_in_code '入库单号',
  458. wpi.bnCode 'BN批次单号',
  459. wpi.cgdNo '采购单号',
  460. wpo.spuCode '商品编号',
  461. '' as '一级分类',
  462. '' as '二级分类',
  463. wgb.cat_id as '三级分类',
  464. wgb.cat_id as '财务核算编号',
  465. wpo.good_name as '商品名称',
  466. wpi.send_num '入库数量',
  467. wpi.send_num * good_price '入库金额',
  468. wpi.updatetime '本次入库时间',
  469. wgb.tax/100 '采购税率',
  470. '' as '不含税入库金额',
  471. '' as '税额',
  472. wp.apply_id as '业务部门',
  473. wp.apply_name as '业务员',
  474. wpo.cgder as '采购员',
  475. wpo.good_price '成本裸价',
  476. wsm_type '仓库类型',
  477. wpo.supplier_name '供应商名称',
  478. wwi.name '仓库名称',
  479. wp.addtime '备库创建时间'
  480. ")->cursor();
  481. $data = $tmp = [];
  482. $fund_code = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('fund_code', 'id');
  483. $warehouse_type = Db::name('warehouse_type')->column('name', 'id');
  484. foreach ($list as $value) {
  485. // $value['业务公司'] = Db::name("business")->where(["companyNo"=>$value['业务公司']])->value('company','');
  486. if (!isset($tmp[$value['业务部门']])) $tmp[$value['业务部门']] = get_company_name_by_uid($value['业务部门']);
  487. $value['业务部门'] = $tmp[$value['业务部门']] ?? '';//Db::name("depart_user")->alias("a")->leftJoin("company_item ci","a.itemid=ci.id")->where(["a.uid"=>$value['业务部门'],"a.status"=>1,"a.is_del"=>0])->value('ci.name','');
  488. $cat = made($value['三级分类']);
  489. $value['财务核算编号'] = $fund_code[$value['三级分类']] ?? '';//Db::name("cat")->where(["id"=>$value['三级分类']])->value("fund_code",'');
  490. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
  491. $value['二级分类'] = isset($cat[1]['name']) ? $cat[1]['name'] : "";
  492. $value['三级分类'] = isset($cat[2]['name']) ? $cat[2]['name'] : "";
  493. $value['不含税入库金额'] = round($value['入库金额'] / (1 + $value['采购税率']), 2);
  494. $value['税额'] = round(($value['入库金额'] / (1 + $value['采购税率'])) * $value['采购税率'], 2);
  495. $value['仓库类型'] = $warehouse_type[$value['仓库类型']] ?? '';//Db::name("warehouse_type")->where(["id"=>$value['仓库类型']])->value("name",'');
  496. yield $data[] = $value;
  497. }
  498. return $data;
  499. }
  500. //【财务报表】库存品出库明细
  501. public function F($start, $end)
  502. {
  503. $list = Db::name("order_out")->alias('woo')->leftJoin("sale a", "a.orderCode=woo.orderCode and a.is_del=0")
  504. ->leftJoin("order_num won", "won.orderCode=a.orderCode")
  505. ->leftJoin("order_back wor", "wor.outCode=woo.outCode and wor.status=4 and wor.is_del=0")
  506. ->leftJoin("purchease_order wpo", "wpo.cgdNo=won.cgdNo")
  507. ->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode and wgb.is_del=0")
  508. ->leftJoin("warehouse_info wwi", "wwi.wsm_code = wpo.wsm_code")
  509. ->where([['woo.status', ">=", 2], ['woo.is_del', "=", 0], ['a.order_type', "=", 1], ['woo.sendtime', "between", [$start, $end]]])
  510. ->field("wpo.companyName '业务公司',
  511. bkcode '备库单号',
  512. woo.orderCode '销售单号',
  513. woo.outCode '出库单号',
  514. wpo.cgdNo '采购单号',
  515. wpo.spuCode '商品编号',
  516. '' as '一级分类',
  517. '' as '二级分类',
  518. wgb.cat_id as '三级分类',
  519. wgb.cat_id as '财务核算编号',
  520. wpo.good_name as '商品名称',
  521. woo.send_num'出库数量',
  522. round( woo.send_num* wpo.good_price,2) '出库金额',
  523. woo.sendtime '本次出库时间',
  524. wgb.tax/100 '税率',
  525. '' as '不含税出库金额',
  526. ''as '税额',
  527. a.apply_id as '业务部门',
  528. a.apply_name as '业务员',
  529. wpo.cgder as '采购员',
  530. wpo.good_price '成本裸价',
  531. wor.return_num '出库退货数量',
  532. wwi.wsm_type '仓库类型',
  533. wpo.supplier_name '供应商名称',
  534. wwi.name '仓库名称'
  535. ")->cursor();
  536. $data = $tmp = [];
  537. $warehouse_type = Db::name('warehouse_type')->column('name', 'id');
  538. $fund_code = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('fund_code', 'id');
  539. foreach ($list as $value) {
  540. // $value['业务公司'] = Db::name("business")->where(["companyNo"=>$value['业务公司']])->value('company','');
  541. if (!isset($tmp[$value['业务部门']])) $tmp[$value['业务部门']] = get_company_name_by_uid($value['业务部门']);
  542. $value['业务部门'] = $tmp[$value['业务部门']] ?? '';//Db::name("depart_user")->alias("a")->leftJoin("company_item ci","a.itemid=ci.id")->where(["a.uid"=>$value['业务部门'],"a.status"=>1,"a.is_del"=>0])->value('ci.name','');
  543. $cat = made($value['三级分类']);
  544. $value['财务核算编号'] = $fund_code[$value['三级分类']] ?? '';//Db::name("cat")->where(["id"=>$value['三级分类']])->value("fund_code",'');
  545. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
  546. $value['二级分类'] = isset($cat[1]['name']) ? $cat[1]['name'] : "";
  547. $value['三级分类'] = isset($cat[2]['name']) ? $cat[2]['name'] : "";
  548. $value['不含税出库金额'] = round($value['出库金额'] / (1 + $value['税率']), 2);
  549. $value['税额'] = round(($value['出库金额'] / (1 + $value['税率'])) * $value['税率'], 2);
  550. $value['仓库类型'] = $warehouse_type[$value['仓库类型']] ?? '';//Db::name("warehouse_type")->where(["id"=>$value['仓库类型']])->value("name",'');
  551. yield $data[] = $value;
  552. }
  553. return $data;
  554. }
  555. //网络部出入库
  556. public function GetWlb($start, $end)
  557. {
  558. $db = Db::connect("mysql_cxinv");
  559. $list = $db->name("cgd_info")
  560. ->where(['cgdSource' => 10, "is_del" => 0])->whereBetweenTime('createdTime', $start, $end)->field(
  561. "year(createdTime) AS `年`,
  562. month(createdTime) AS `月`,
  563. dayofmonth(createdTime) AS `日`,
  564. companyName '公司名称',
  565. department '业务部门',
  566. ownerName '业务人员',
  567. if(cxCode='','否','是') '是否拆单',
  568. '网络部采购单' '订单类型',
  569. '' as '商品类型',
  570. '' as '发货编号',
  571. sendNum '本次发货数量',
  572. createdTime '本次发货时间',
  573. qrdCode '确认单编号',
  574. goodNo '商品编号',
  575. firstCat '一级分类',
  576. secCat as '二级分类',
  577. thirdCat as '三级分类',
  578. fundCode as '财务核算编码',
  579. goodName as '商品名称',
  580. goodUnit as '单位',
  581. goodNum '下单数量',
  582. '' AS `销售货款`,
  583. sequenceNo as '采购单单号',
  584. ownerName '采购员',
  585. barePrice AS `采购裸价`,
  586. markPrice AS `加标费`,
  587. packPrice AS `包装费`,
  588. certPrice AS `证书费`,
  589. openPrice AS `开模费`,
  590. costPrice AS `工艺费`,
  591. deliveryPrice AS `物流费`,
  592. deliveryPrice AS `物流费`,
  593. 0 AS `公差金额`,
  594. goodPrice AS `成本合计`,
  595. totalPrice AS `采购货款`,
  596. tax/100 AS `采购税点`,
  597. supplierName AS `供应商名称`,
  598. '否'as '是否库存品',
  599. '包邮' as '发货方式',
  600. '' AS `退货编号`,
  601. thNum AS `退货数量`,
  602. th_fee as '退货金额',
  603. '' as '售前退货数量',
  604. '' as '售前退货金额'
  605. ")->cursor();
  606. $data = [];
  607. foreach ($list as $value) {
  608. $value['销售货款'] = $db->name("qrd_info")->where(['sequenceNo' => $value['确认单编号']])->value('totalPrice', '');
  609. // $value['财务核算编码'] = $db->name("cat")->where(['cat_name'=>$value['一级分类']])->value('fund_code','');
  610. yield $data[] = $value;
  611. }
  612. return $data;
  613. }
  614. //【销售】订单表导出
  615. public function G(string $start_date = '', string $end_date = '')
  616. {
  617. $all_order_type = [1 => '备库', 2 => '非库存', 3 => '咨询采反', 4 => '项目采反', 5 => '平台部订单销售库存', 6 => '平台部订单销售非库存'];//订单类型
  618. $all_sale_status = [0 => '待发货', 1 => '待发货完成', 2 => '发货已完成', 3 => '订单已取消'];//订单状态(sale表里的status)
  619. $all_stock = [0 => '非库存品', 1 => '库存品'];//是否库存品
  620. $all_is_activity = [0 => '不参与活动', 1 => '参与活动'];
  621. $all_good_type = [1 => '正常商品', 2 => '赠品', 3 => '样品'];
  622. $data = Db::name('sale')
  623. ->alias('s')
  624. ->field('s.addtime 确认单下单时间,s.orderCode 订单编号,s.order_type 订单类型,s.status 订单状态,s.apply_name 创建人,
  625. "" 部门,s.supplierName 销售方公司,"" 一级组织,"" 二级组织,s.customerName 购买方公司,p.platform_name 所属平台,
  626. s.platform_order 平台订单号,s.poNo 其他单号,s.paytime 承诺回款时间,ou.order_use 订单用途,"" 活动类型,s.good_name 产品名称,
  627. "" 一级分类,gb.tax 税率,s.sale_price 销售单价,s.good_num 下单数量,s.total_price 销售总额,po.cgder 采购人,gb.customized 工期时间,
  628. s.arrive_time 要求到货时间,s.remark 备注,s.is_stock 是否库存品,s.cat_id,s.is_activity,s.good_type,s.customer_code,s.apply_id')
  629. ->leftJoin('platform p', 'p.id=s.platform_id')
  630. ->leftJoin('good_basic gb', 'gb.spuCode=s.good_code')
  631. ->leftJoin('order_use ou', 'ou.id=s.use_order')
  632. ->leftJoin('order_num on', 'on.orderCode=s.orderCode')
  633. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  634. ->where(['s.is_del' => 0])
  635. ->whereBetween('s.addtime', [$start_date, $end_date])
  636. ->order('s.addtime', 'desc')
  637. ->cursor();
  638. $list = $tmp_codes = $tmp_customer = $tmp_company_names = [];
  639. $userCommon = User::getIns();
  640. foreach ($data as $value) {
  641. if (!isset($tmp_company_names[$value['apply_id']])) $tmp_company_names[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);
  642. $value['部门'] = $tmp_company_names[$value['apply_id']];
  643. if (!isset($tmp_customer[$value['customer_code']])) {
  644. $tmp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  645. $tmp_customer[$value['customer_code']] = $tmp['data']['itemid']??0;
  646. }
  647. $value['itemid'] = $tmp_customer[$value['customer_code']]??"";
  648. $value['订单类型'] = isset($all_order_type[$value['订单类型']]) ? $all_order_type[$value['订单类型']] : '';
  649. $value['订单状态'] = isset($all_sale_status[$value['订单状态']]) ? $all_sale_status[$value['订单状态']] : '';
  650. if ($value['itemid']!='') {
  651. $customer_org1 = array_column(get_top_customer_org($value['itemid'])??[], 'name', 'level');
  652. $value['一级组织'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  653. $value['二级组织'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  654. }
  655. $cat = made($value['cat_id']);
  656. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : '';
  657. $value['是否库存品'] = isset($all_stock[$value['是否库存品']]) ? $all_stock[$value['是否库存品']] : '';
  658. $is_activity = isset($all_is_activity[$value['is_activity']]) ? $all_is_activity[$value['is_activity']] : '';
  659. $good_type = isset($all_good_type[$value['good_type']]) ? $all_good_type[$value['good_type']] : '';
  660. $value['活动类型'] = $is_activity . '/' . $good_type;
  661. unset($value['good_code']);
  662. unset($value['itemid']);
  663. unset($value['cat_id']);
  664. unset($value['is_activity']);
  665. unset($value['good_type']);
  666. unset($value['customer_code']);
  667. unset($value['supplierNo']);
  668. yield $list[] = $value;
  669. }
  670. return $list;
  671. }
  672. //【库存报表】库存日报及预警汇总表
  673. private function H(string $start_date = '', string $end_date = '')
  674. {
  675. $data = Db::name('good_stock')
  676. ->alias('wgs')
  677. ->field(" wwi.companyName '公司名称',wgs.spuCode '产品编号',cat_id '一级分类',good_name '产品名称',wait_in_stock '待入库存数量',wait_out_stock '待出库存数量',usable_stock '可用库存数量',wait_out_stock+usable_stock '当前库存','' as '保质期时间','' as '库存天数',wgb.creater as 'CGD.采购员','' as '备库单号',wgb.supplierName as '供应商名称',wwi.`name` as '仓库名称','' as '最近入库时间'")
  678. ->leftJoin('warehouse_info wwi', 'wwi.wsm_code = wgs.wsm_code')
  679. // ->leftJoin('business wb', 'wb.companyNo = wwi.companyNo')
  680. ->leftJoin('good_basic wgb', 'wgb.spuCode = wgs.spuCode')
  681. // ->leftJoin('supplier ws', 'ws.`code` = wgb.supplierNo')
  682. ->where('wgs.is_del', 0)
  683. ->where('wgb.is_stock', 1)
  684. ->whereBetween('wgs.addtime', [$start_date, $end_date])
  685. ->order('wgs.addtime', 'desc')
  686. ->cursor();
  687. $list = [];
  688. foreach ($data as $value) {
  689. $cat = made($value['一级分类']);
  690. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
  691. $value['最近入库时间'] = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in c", "a.cgdNo=c.cgdNo")
  692. ->where(["spuCode" => $value['产品编号'], "order_type" => 1, "order_source" => 0, "c.status" =>2])->order("a.addtime desc")->value("c.addtime", "");
  693. $value['备库单号'] = Db::name("purchease_order")->alias("a")->where(["spuCode" => $value['产品编号'], "order_type" => 1, "order_source" => 0])->order("a.addtime desc")->value("a.bkcode", "");
  694. if (!empty($value['最近入库时间'])) {
  695. $value['保质期时间'] = date('Y-m-d H:i:s', strtotime($value['最近入库时间']) + 31536000);//365天之后
  696. $value['库存天数'] = bcdiv((string)(time() - strtotime($value['最近入库时间'])), (string)(24 * 3600));//365天之后
  697. }
  698. yield $list[] = $value;
  699. }
  700. return $list;
  701. }
  702. //【库存报表】出入库明细
  703. public function I(string $start = '', string $end = '')
  704. {
  705. $list = Db::name("order_out")
  706. ->alias('woo')
  707. ->leftJoin("sale a", "a.orderCode=woo.orderCode")
  708. ->leftJoin("order_back wor", "wor.outCode=woo.outCode and wor.status=4")
  709. ->leftJoin("order_num won", "won.orderCode=a.orderCode")
  710. ->leftJoin("purchease_order wpo", "wpo.cgdNo=won.cgdNo")
  711. ->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode")
  712. ->leftJoin("good_zixun wgz", "wgz.spuCode=wpo.spuCode")
  713. // ->leftJoin("supplier ws", "ws.code=wpo.supplierNo")
  714. ->where('woo.status', ">=", 2)
  715. ->whereBetween('woo.sendtime', [$start, $end])
  716. ->field(" year(`a`.`addtime`) AS `年`,month(`a`.`addtime`) AS `月`,dayofmonth(`a`.`addtime`) AS `日`,a.supplierName as '公司名称', a.apply_id '业务部门名称' ,a.apply_name as '业务人员',a.order_type as '订单类型',a.good_type as '商品类型',woo.outCode '发货编号',`woo`.`send_num` AS `本次发货数量`,`woo`.`sendtime` AS `本次发货时间`,`woo`.`orderCode` AS `确认单编号`,`a`.`good_code` AS `商品编号`,'' as '一级分类','' as '二级分类',a.cat_id as '三级分类','' as '财务核算编码',a.good_name as '商品名称',ifnull( `wgb`.`good_unit`, `wgz`.`good_unit` ) as '单位',`a`.`good_num` AS `下单数量`,`wpo`.`cgdNo` AS `采购单单号`,`wpo`.`cgder` AS `采购员`,`wpo`.`supplier_name` AS `供应商名称`,`wgb`.`is_stock` as '是否库存品',if (`wgb`.`is_stock`=1,wpo.bkcode,wpo.cgdNo) as '发货方式',ifnull( `wor`.`thNo`, '' ) AS `退货编号`,ifnull( `wor`.`return_num`, '' ) AS `退货数量`,'' as '售前退货数量'")
  717. ->cursor();
  718. $order_tyepe = ["库存销售", '非库存销售', '咨询销售', '项目销售', '平台库存销售', '平台非库存销售'];
  719. $good_type = ["常规商品", '赠品', '样品'];
  720. $data = $tmp = [];
  721. $fund_code = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('fund_code', 'id');
  722. $unit = Db::name('unit')->where('is_del', 0)->column('unit', 'id');
  723. foreach ($list as $value) {
  724. // $value['公司名称'] = Db::name("business")->where(["companyNo" => $value['公司名称']])->value('company', '');
  725. if (!isset($tmp[$value['业务部门名称']])) $tmp[$value['业务部门名称']] = get_company_name_by_uid($value['业务部门名称']);
  726. $value['业务部门名称'] = $tmp[$value['业务部门名称']] ?? '';//Db::name("depart_user")->alias("a")->leftJoin("company_item ci", "a.itemid=ci.id")->where(["a.uid" => $value['业务部门名称'], "a.status" => 1, "a.is_del" => 0])->value('ci.name', '');
  727. $value['订单类型'] = $order_tyepe[$value['订单类型'] - 1];
  728. $value['商品类型'] = $good_type[$value['商品类型'] - 1];
  729. $cat = made($value['三级分类']);
  730. $value['财务核算编码'] = $fund_code[$value['三级分类']] ?? '';//Db::name("cat")->where(["id" => $value['三级分类']])->value("fund_code", '');
  731. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
  732. $value['二级分类'] = isset($cat[1]['name']) ? $cat[1]['name'] : "";
  733. $value['三级分类'] = isset($cat[2]['name']) ? $cat[2]['name'] : "";
  734. $value['单位'] = $unit[$value['单位']] ?? '';//Db::name("unit")->where(["id" => $value['单位']])->value("unit", '');
  735. if ($value['是否库存品'] == 1) {
  736. $sendtype = Db::name("purchease_order")->alias("a")
  737. ->leftJoin("purchease_in b", "a.cgdNo=b.cgdNo")
  738. ->where(["bkcode" => $value['发货方式'], "order_type" => 1, "order_source" => 0])
  739. ->order("b.addtime desc")->value("b.sendtype", '');
  740. $value['是否库存品'] = '是';
  741. } else {
  742. $sendtype = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in b", "a.cgdNo=b.cgdNo")->where(["a.cgdNo" => $value['发货方式']])->order("b.addtime desc")->value("b.sendtype", '');
  743. $value['是否库存品'] = '否';
  744. }
  745. $value['发货方式'] = $sendtype == 1 ? '包邮' : $sendtype == 2 ? '自提' : "";
  746. $value['售前退货数量'] = Db::name("sale_return")->where(["orderCode" => $value['确认单编号']])->sum('num');
  747. yield $data[] = $value;
  748. }
  749. $cgd = $this->GetWlb($start, $end);
  750. foreach ($cgd as $key => $value) {
  751. yield $data[] = $value;
  752. }
  753. return $data;
  754. }
  755. //【库存报表】-库存品入库明细
  756. public function J(string $start = '', string $end = '')
  757. {
  758. $list = Db::name("purchease_in")
  759. ->alias('wpi')
  760. ->leftJoin("purchease_order wpo", "wpo.cgdNo=wpi.cgdNo")
  761. ->leftJoin("purchease wp", "wpo.bkcode=wp.bk_code")
  762. ->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode")
  763. ->leftJoin("warehouse_info wwi", "wwi.wsm_code = wpo.wsm_code")
  764. // ->leftJoin("supplier ws", "ws.code=wpo.supplierNo")
  765. ->where('wpi.status', "=", 2)
  766. ->where('wpo.order_type', "=", 1)
  767. ->where('wpo.order_source', "=", 0)
  768. ->whereBetween('wpi.addtime', [$start, $end])
  769. ->field("wpo.companyName '业务公司',bkcode '备库单号',wpi.wsm_in_code '入库单号',wpi.cgdNo '采购单号',wpo.spuCode '商品编号','' as '一级分类','' as '二级分类',wgb.cat_id as '三级分类',wgb.cat_id as '财务核算编号',wpo.good_name as '商品名称',wpi.send_num '入库数量',wpo.updatetime '本次入库时间',wp.apply_id as '业务部门',wp.apply_name as '业务员',wpo.cgder as '采购员',wsm_type '仓库类型',wpo.supplier_name '供应商名称',wwi.name '仓库名称'")
  770. ->cursor();
  771. $data = [];
  772. $fund_code = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('fund_code', 'id');
  773. $warehouse_type = Db::name('warehouse_type')->column('name', 'id');
  774. foreach ($list as $value) {
  775. // $value['业务公司'] = Db::name("business")->where(["companyNo" => $value['业务公司']])->value('company', '');
  776. if (!isset($tmp[$value['业务部门']])) $tmp[$value['业务部门']] = get_company_name_by_uid($value['业务部门']);
  777. $value['业务部门'] = $tmp[$value['业务部门']] ?? '';//Db::name("depart_user")->alias("a")->leftJoin("company_item ci", "a.itemid=ci.id")->where(["a.uid" => $value['业务部门'], "a.status" => 1, "a.is_del" => 0])->value('ci.name', '');
  778. $cat = made($value['三级分类']);
  779. $value['财务核算编号'] = $fund_code[$value['三级分类']] ?? '';//Db::name("cat")->where(["id" => $value['三级分类']])->value("fund_code", '');
  780. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
  781. $value['二级分类'] = isset($cat[1]['name']) ? $cat[1]['name'] : "";
  782. $value['三级分类'] = isset($cat[2]['name']) ? $cat[2]['name'] : "";
  783. $value['仓库类型'] = $warehouse_type[$value['仓库类型']] ?? '';//Db::name("warehouse_type")->where(["id" => $value['仓库类型']])->value("name", '');
  784. yield $data[] = $value;
  785. }
  786. return $data;
  787. }
  788. //【库存报表】库存品出库明细
  789. public function K(string $start = '', string $end = '')
  790. {
  791. $list = Db::name("order_out")
  792. ->alias('woo')
  793. ->leftJoin("sale a", "a.orderCode=woo.orderCode and a.is_del=0")
  794. ->leftJoin("order_num won", "won.orderCode=a.orderCode")
  795. ->leftJoin("order_back wor", "wor.outCode=woo.outCode and wor.status=4 and wor.is_del=0")
  796. ->leftJoin("purchease_order wpo", "wpo.cgdNo=won.cgdNo and wpo.is_del=0")
  797. ->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode and wgb.is_del=0")
  798. // ->leftJoin("supplier ws", "ws.code=wpo.supplierNo")
  799. ->leftJoin("warehouse_info wwi", "wwi.wsm_code = wpo.wsm_code")
  800. ->where([['woo.status', ">=", 2], ['woo.is_del', "=", 0], ['a.order_type', "=", 1], ['woo.sendtime', 'between', [$start, $end]]])
  801. ->field("wpo.companyName '业务公司',bkcode '备库单号',woo.orderCode '销售单号',woo.outCode '出库单号',wpo.cgdNo '采购单号',wpo.spuCode '商品编号','' as '一级分类','' as '二级分类',wgb.cat_id as '三级分类',wpo.good_name as '商品名称',woo.send_num'出库数量',woo.sendtime '本次出库时间',a.apply_id as '业务部门',a.apply_name as '业务员',wpo.cgder as '采购员',wor.return_num '出库退货数量',wwi.wsm_type '仓库类型',wpo.supplier_name '供应商名称',wwi.name '仓库名称'")
  802. ->cursor();
  803. $data = $tmp = [];
  804. $warehouse_type = Db::name('warehouse_type')->column('name', 'id');
  805. foreach ($list as $value) {
  806. // $value['业务公司'] = Db::name("business")->where(["companyNo" => $value['业务公司']])->value('company', '');
  807. if (!isset($tmp[$value['业务部门']])) $tmp[$value['业务部门']] = get_company_name_by_uid($value['业务部门']);
  808. $value['业务部门'] = $tmp[$value['业务部门']] ?? '';//Db::name("depart_user")->alias("a")->leftJoin("company_item ci", "a.itemid=ci.id")->where(["a.uid" => $value['业务部门'], "a.status" => 1, "a.is_del" => 0])->value('ci.name', '');
  809. $cat = made($value['三级分类']);
  810. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
  811. $value['二级分类'] = isset($cat[1]['name']) ? $cat[1]['name'] : "";
  812. $value['三级分类'] = isset($cat[2]['name']) ? $cat[2]['name'] : "";
  813. $value['仓库类型'] = $warehouse_type[$value['仓库类型']] ?? '';//Db::name("warehouse_type")->where(["id" => $value['仓库类型']])->value("name", '');
  814. yield $data[] = $value;
  815. }
  816. return $data;
  817. }
  818. /**
  819. * 新出库单明细
  820. * @param string $start
  821. * @param string $end
  822. * @return \Generator
  823. * @throws \think\db\exception\DataNotFoundException
  824. * @throws \think\db\exception\DbException
  825. * @throws \think\db\exception\ModelNotFoundException
  826. *
  827. */
  828. private function NewOut(string $start, string $end)
  829. {
  830. $data = Db::name("order_out")
  831. ->alias("a")
  832. ->leftJoin("sale b", "a.orderCode=b.orderCode")
  833. ->field("b.supplierName '业务公司',a.orderCode AS '销售单号',outCode '出库单号',
  834. b.good_code '商品编号',b.cat_id ,'' as '一级分类','' as '二级分类','' as '三级分类','' as '财务核算编号',
  835. b.good_name '商品名称',a.send_num '出库数量','' as '出库金额',a.sendtime '本次出库时间',
  836. ''as '税率', b.apply_id as '业务部门',a.apply_name as '业务人员',cgder as '采购员','' as '成本裸价',
  837. '' as '供应商名称','' as '出库退货数量',b.order_type,b.addtime")
  838. ->where([["a.status", ">=", 2], ["a.is_del", "=", 0], ["b.order_type", "=", 1], ['a.sendtime', 'between', [$start, $end]]])
  839. ->cursor();
  840. $list = $tmp = [];
  841. $fund_code = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('fund_code', 'id');
  842. $date=strtotime("2023-04-15 00:00:00");
  843. foreach ($data as $value) {
  844. if (!isset($tmp[$value['业务部门']])) $tmp[$value['业务部门']] = get_company_name_by_uid($value['业务部门']);
  845. $value['业务部门'] = $tmp[$value['业务部门']] ?? '';
  846. $cat = made($value['cat_id']);
  847. $value['财务核算编号'] = $fund_code[$value['cat_id']] ?? '';
  848. unset($value['cat_id']);
  849. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
  850. $value['二级分类'] = isset($cat[1]['name']) ? $cat[1]['name'] : "";
  851. $value['三级分类'] = isset($cat[2]['name']) ? $cat[2]['name'] : "";
  852. if (in_array($value["order_type"], [3, 4])) {
  853. $good = Db::name("good_zixun")->where(["spuCode" => $value['商品编号']])->find();
  854. } else {
  855. $good = Db::name("good")->where(["spuCode" => $value['商品编号']])->find();
  856. }
  857. if(strtotime($value['addtime'])<=$date){
  858. $saleinfo = Db::name("sale_info")->where(["orderCode" => $value['销售单号']])->field("num,origin_price,num*origin_price as total_price")->select()
  859. ->toArray();
  860. if (empty($saleinfo)) {
  861. $value['成本裸价'] = Db::name("order_out")->alias("a")
  862. ->leftJoin("order_send b", "a.outCode=b.outCode")
  863. ->leftJoin("purchease_order c", "b.cgdNo=c.cgdNo")
  864. ->where(["a.outCode" => $value['出库单号']])->value("c.good_price", '0');
  865. } else {
  866. $num = array_sum(array_column($saleinfo, "num"));
  867. if ($num == 0) {
  868. $value['成本裸价'] = 0;
  869. } else {
  870. $value['成本裸价'] = round(array_sum(array_column($saleinfo, "total_price")) / array_sum(array_column($saleinfo, "num")), 2);
  871. }
  872. }
  873. }else{
  874. $mp= Db::name("child_bn")->where(["outCode"=> $value['出库单号']])->field("sum(origin_price * total_bn_num)/sum(total_bn_num) as total")->findOrEmpty();
  875. $value['成本裸价'] = $mp['total']??0;
  876. }
  877. $value['出库金额'] = $value['出库数量'] * $value['成本裸价'];
  878. $value['税率'] = $good['tax'] . "%";
  879. $value['供应商名称'] = $good['supplierName'];//Db::name("supplier")->where(["code"=>$good['supplierNo']])->value("name","");
  880. $value["出库退货数量"] = Db::name("order_back")->where(["outCode" => $value['出库单号']])->sum("return_num");
  881. unset($value['order_type']);
  882. unset($value['addtime']);
  883. yield $list[] = $value;
  884. }
  885. }
  886. /**每日库存记录
  887. * @param string $start
  888. * @param string $end
  889. * @return \Generator
  890. * @throws \think\db\exception\DataNotFoundException
  891. * @throws \think\db\exception\DbException
  892. * @throws \think\db\exception\ModelNotFoundException
  893. */
  894. private function EveryDayStock(string $start,string $end){
  895. $list = Db::name("good_stock")->alias("b")
  896. ->leftJoin("good_basic f","b.spuCode=f.spuCode")
  897. ->leftJoin("warehouse_info j","b.wsm_code=j.wsm_code")
  898. ->field(" f.companyName '业务公司',
  899. f.spuCode '产品编号' ,
  900. f.cat_id '一级分类' ,
  901. f.good_name '产品名称' ,
  902. f.cat_id,
  903. '' as '财务核算编号',
  904. f.tax/100 as '税率',
  905. '' as '成本单价',
  906. b.wait_in_stock '待入库数量',
  907. b.wait_out_stock '待出库数量',
  908. (b.wait_out_stock+b.usable_stock) '当前库存数量',
  909. b.usable_stock '可用库存数量',
  910. f.creater '采购员',
  911. f.supplierName as '供应商名称',
  912. j.`name` '仓库名称',
  913. ''as '最新备库时间'
  914. ")
  915. ->where(["f.is_stock"=>1])
  916. ->cursor();
  917. foreach ($list as $value){
  918. $cat = made($value['cat_id']);
  919. $value['财务核算编号'] = Db::name("cat")->where(["id"=>$value['cat_id']])->value("fund_code",'');
  920. unset($value['cat_id']);
  921. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
  922. $value['最新备库时间']= Db::name("purchease_order")->where(["spuCode"=>$value['产品编号'],"status"=>[2,3]])
  923. ->order("id desc")->value("addtime",'');
  924. yield $value;
  925. }
  926. }
  927. /**获取商品成本列表
  928. * @return \Generator
  929. */
  930. private function GetGoodNake()
  931. {
  932. $list = Db::name("good_platform")
  933. ->alias("a")
  934. ->leftJoin("good b", "a.spuCode=b.spuCode")
  935. ->leftJoin("good_nake c", "b.spuCode=c.spuCode and c.is_del=0")
  936. ->field("
  937. a.skuCode '上线商品编号',
  938. a.spuCode '成本商品编号',
  939. a.plat_code '平台商品编号',
  940. b.good_name '商品名称',
  941. b.brand_id '品牌',
  942. b.cat_id '分类',
  943. b.companyName '业务企业名称',
  944. a.creater '申请人',
  945. platform_code '上线平台',
  946. online_time '上线时间',
  947. exam_status '上线状态',
  948. if(b.is_stock=1,'库存','非库存') '是否库存',
  949. if(b.good_type=1,'定制','非定制')'是否定制',
  950. '' as '规格',
  951. '' as '型号',
  952. b.good_unit '单位',
  953. b.good_remark '商品备注',
  954. b.craft_desc '工艺说明',
  955. b.noble_metal '贵金属信息',
  956. b.cgd_gold_price '供应商采购金价',
  957. b.demo_fee '打样费',
  958. b.open_fee '开模费',
  959. b.sample_fee '调样费',
  960. c.min_num '起订量',
  961. c.nake_fee '成本单价',
  962. c.cost_fee '工艺费',
  963. c.delivery_fee '物流费',
  964. c.cert_fee '证书费',
  965. c.mark_fee '加标费',
  966. c.package_fee '包装费',
  967. c.other_fee '其他费用',
  968. c.nake_total '成本合计',
  969. b.tax '税点',
  970. if(b.supply_area=1,'全国','全国除偏远地区') '供货区域',
  971. b.supplierName '供应商名称'
  972. ")->cursor();
  973. $brand = Db::name('brand')->where('is_del', 0)->column('brand_name', 'id');
  974. $cat = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('cat_name', 'id');
  975. $platform = Db::name('platform')->where('is_del', 0)->column('platform_name', 'id');
  976. $unit = Db::name('unit')->where('is_del', 0)->column('unit', 'id');
  977. $arr = ["待提交", '待完善成本', '待产品审核', '待财务定价', '待财务审核定价', '待上线', '已上线', '审核失败', '已下线'];
  978. $noble = ["0" => "", "1" => "18K", "2" => "24K", "3" => "白银"];
  979. foreach ($list as $value) {
  980. $value["品牌"] = $brand[$value["品牌"]] ?? '';//Db::name("brand")->where("id",$value["品牌"])->value("brand_name",'');
  981. $value["分类"] = $cat[$value["分类"]] ?? '';//Db::name("cat")->where("id",$value["分类"])->value("cat_name",'');
  982. // $value["业务企业名称"]=Db::name("business")->where("companyNo",$value["业务企业名称"])->value("company","");
  983. $value["上线平台"] = $platform[$value["上线平台"]] ?? '';//Db::name("platform")->where("id", $value["上线平台"])->value("platform_name","");
  984. // $arr=["待提交",'待完善成本','待产品审核','待财务定价','待财务审核定价','待上线','已上线','审核失败','已下线'];
  985. $value["上线状态"] = $arr[$value["上线状态"]];
  986. $value['单位'] = $unit[$value['单位']] ?? '';//Db::name("unit")->where("id",$value['单位'])->value("unit",'');
  987. // $noble = [ "0"=>"", "1"=>"18K", "2"=>"24K", "3"=>"白银"];
  988. $value['贵金属信息'] = $noble[$value['贵金属信息']];
  989. // $value['供应商名称']=Db::name("supplier")->where("code",$value['供应商名称'])->value("name",'');
  990. yield $value;
  991. }
  992. }
  993. /**获取商品阶梯售价列表
  994. * @return \Generator
  995. */
  996. private function GetGoodLadder()
  997. {
  998. $list = Db::name("good_platform")->alias("a")
  999. ->leftJoin("good b", "a.spuCode=b.spuCode")
  1000. ->leftJoin("good_ladder c", "a.skuCode=c.skuCode and c.is_del=0")
  1001. ->field("
  1002. a.skuCode '上线商品编号',
  1003. a.spuCode '成本商品编号',
  1004. a.plat_code '平台商品编号',
  1005. b.good_name '商品名称',
  1006. b.brand_id '品牌',
  1007. b.cat_id '分类',
  1008. b.companyName '业务企业名称',
  1009. a.creater '申请人',
  1010. platform_code '上线平台',
  1011. online_time '上线时间',
  1012. exam_status '上线状态',
  1013. if(b.is_stock=1,'库存','非库存') '是否库存',
  1014. if(b.good_type=1,'定制','非定制')'是否定制',
  1015. '' as '规格',
  1016. '' as '型号',
  1017. b.good_unit '单位',
  1018. b.good_remark '商品备注',
  1019. b.craft_desc '工艺说明',
  1020. b.noble_metal '贵金属信息',
  1021. b.cgd_gold_price '供应商采购金价',
  1022. b.demo_fee '打样费',
  1023. b.open_fee '开模费',
  1024. b.sample_fee '调样费',
  1025. c.min_num '起订量',
  1026. c.sale_price '售价',
  1027. c.cost_fee '工艺费',
  1028. c.market_price '物流费',
  1029. c.market_platform '对比平台',
  1030. b.tax '税点',
  1031. if(b.supply_area=1,'全国','全国除偏远地区') '供货区域',
  1032. b.supplierName '供应商名称'
  1033. ")->cursor();
  1034. $noble = ["0" => "", "1" => "18K", "2" => "24K", "3" => "白银"];
  1035. $arr = ["待提交", '待完善成本', '待产品审核', '待财务定价', '待财务审核定价', '待上线', '已上线', '审核失败', '已下线'];
  1036. $brand = Db::name('brand')->where('is_del', 0)->column('brand_name', 'id');
  1037. $cat = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('cat_name', 'id');
  1038. $platform = Db::name('platform')->where('is_del', 0)->column('platform_name', 'id');
  1039. $unit = Db::name('unit')->where('is_del', 0)->column('unit', 'id');
  1040. foreach ($list as $value) {
  1041. $value["品牌"] = $brand[$value["品牌"]] ?? '';//Db::name("brand")->where("id",$value["品牌"])->value("brand_name",'');
  1042. $value["分类"] = $cat[$value["分类"]] ?? '';//Db::name("cat")->where("id",$value["分类"])->value("cat_name",'');
  1043. // $value["业务企业名称"]=Db::name("business")->where("companyNo",$value["业务企业名称"])->value("company","");
  1044. $value["上线平台"] = $platform[$value["上线平台"]] ?? '';//Db::name("platform")->where("id", $value["上线平台"])->value("platform_name","");
  1045. $value["上线状态"] = $arr[$value["上线状态"]];
  1046. $value['单位'] = $unit[$value['单位']] ?? '';//Db::name("unit")->where("id",$value['单位'])->value("unit",'');
  1047. $value['贵金属信息'] = $noble[$value['贵金属信息']];
  1048. // $value['供应商名称']=Db::name("supplier")->where("code",$value['供应商名称'])->value("name",'');
  1049. yield $value;
  1050. }
  1051. }
  1052. private function GetBid(string $start, string $end)
  1053. {
  1054. $list = Db::name("consult_info")->alias("a")
  1055. ->leftJoin("consult_bids d", "a.infoNo=d.infoNo")
  1056. ->leftJoin("consult_order c", "a.zxNo=c.zxNo")
  1057. ->leftJoin("bargain_order b", "d.bidNo=b.bidsNo and b.is_del=0")
  1058. ->field("c.companyNo '业务公司',
  1059. d.addtime '竞价时间',
  1060. d.infoNo '竞价单编号',
  1061. a.`status` '状态',
  1062. c.creater '申请人',
  1063. c.createrid '申请人部门',
  1064. c.khNo '客户名称',
  1065. c.platform_code '所属平台',
  1066. if(a.pgNo='','咨询','项目') as '竞价类型',
  1067. a.cat_id '商品分类',
  1068. a.good_name '商品名称',
  1069. a.budget_price '预算单价',
  1070. a.unit '单位',
  1071. a.num '数量',
  1072. a.budget_price*a.num '竞价单总额',
  1073. d.remark '商品备注',
  1074. d.addtime '反馈时间',
  1075. d.creater '反馈人',
  1076. d.bidNo '反馈商品编码',
  1077. d.status '反馈商品状态',
  1078. d.good_name '反馈商品名称',
  1079. d.sale_price*a.num '反馈单总额',
  1080. d.cat_id '反馈商品分类',
  1081. d.unit_id '反馈商品单位',
  1082. d.tax '反馈商品税点',
  1083. c.endtime '竞价有效期',
  1084. b.bargainNo '议价单编号',
  1085. b.sale_price '议价前售价',
  1086. b.after_price '议价后售价',
  1087. b.before_rate '议价前毛利率',
  1088. b.after_rate '议价后毛利率',
  1089. b.`status` '议价状态',
  1090. b.bargain_remark '议价备注',
  1091. b.result_info_id '议价原因'")
  1092. ->where("a.is_del", 0)
  1093. ->whereBetween("a.addtime", [$start, $end])
  1094. ->cursor();
  1095. $cat = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('cat_name', 'id');
  1096. $unit = Db::name('unit')->where('is_del', 0)->column('unit', 'id');
  1097. $platform = Db::name('platform')->where('is_del', 0)->column('platform_name', 'id');
  1098. $result = Db::name('result_info')->where(['is_del' => 0])->column('result_desc', 'id');
  1099. $arr1 = ["待提交", '招标进行中', '招标已结束', '等待议价结果', '确认商品', '成功转单', '取消转单', '招标已暂停'];
  1100. $arr2 = ["待提交", "待任务结束", "待咨询确认", "议价待财务定价", "待主管确认", "待咨询确认定价", "咨询确认"];
  1101. $arr3 = ['待业务主管审核', '业务主管通过', '待财务专员审核', '业务驳回', '财务专员通过', '财务专员驳回', '财务主管通过', '待boss审核', '财务主管驳回', 'boss审核通过', 'boss越线通过', 'boss驳回', '取消议价'];
  1102. $tmp = [];
  1103. foreach ($list as $value) {
  1104. // $value["品牌"]=Db::name("brand")->where("id",$value["品牌"])->value("brand_name",'');
  1105. $value["商品分类"] = $cat[$value["商品分类"]] ?? '';//Db::name("cat")->where("id",$value["商品分类"])->value("cat_name",'');
  1106. $value["反馈商品分类"] = $cat[$value["反馈商品分类"]] ?? '';//Db::name("cat")->where("id",$value["反馈商品分类"])->value("cat_name",'');
  1107. $value["反馈商品单位"] = $unit[$value["反馈商品单位"]] ?? '';//Db::name("unit")->where("id",$value["反馈商品单位"])->value("unit",'');
  1108. if (isset($tmp[$value['业务公司']])) $tmp[$value['业务公司']] = get_headquarters_code_and_name($value['业务公司'])[$value['业务公司']] ?? '';
  1109. $value["业务公司"] = $tmp[$value['业务公司']] ?? '';//Db::connect('mysql_sys')->name("business")->where("companyNo",$value["业务公司"])->value("company","");
  1110. $value["所属平台"] = $platform[$value["所属平台"]] ?? '';//Db::name("platform")->where("id", $value["所属平台"])->value("platform_name","");
  1111. if (isset($tmp[$value['申请人部门']])) $tmp[$value['申请人部门']] = get_company_name_by_uid($value['申请人部门']);
  1112. $value['申请人部门'] = $tmp[$value['申请人部门']] ?? '';//Db::name("depart_user")->alias("a")->leftJoin("company_item ci", "a.itemid=ci.id")->where(["a.uid" => $value['申请人部门'], "a.status" => 1, "a.is_del" => 0])->value('ci.name', '');
  1113. //状态 ;1招标进行中 2 招标已结束 3 等待议价结果 4.确认商品 5成功转单 6 取消转单 7 招标已暂
  1114. $value["状态"] = $arr1[$value["状态"]] ?? "";
  1115. //状态0 待提交 1 提交待确认 2 发起议价 3 财务定价4 主管定价5 确认采购
  1116. $value["反馈商品状态"] = $arr2[$value["反馈商品状态"]] ?? "";
  1117. //状态 1 待主管审批 2.待财务专员审批 3. 待财务主管审批 4 审批通过 5 主管驳回 6 财务主管驳回 7 已取消议价
  1118. $value["议价状态"] = $arr3[$value["议价状态"]] ?? "";
  1119. $value['单位'] = $unit[$value['单位']] ?? '';//Db::name("unit")->where("id",$value['单位'])->value("unit",'');
  1120. $value['议价原因'] = $result[$value['议价原因']] ?? '';//Db::name("result_info")->where("id",$value['议价原因'])->value("result_desc",'');
  1121. if (isset($tmp[$value['客户名称']])) $tmp[$value['客户名称']] = get_headquarters_code_and_name($value['客户名称'][$value['客户名称']]) ?? '';
  1122. $value['客户名称'] = $tmp[$value['客户名称']] ?? '';//Db::connect('mysql_sys')->name("customer_info")->where("companyNo",$value['客户名称'])->value("companyName",'');
  1123. yield $value;
  1124. }
  1125. }
  1126. }