Report.php 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\Db;
  4. use think\facade\Validate;
  5. //报表处理类
  6. class Report extends Base
  7. {
  8. //商品表部分字段的中英文对照
  9. private $good_field_title = [
  10. 'spuCode' => '商品成本编号',
  11. 'good_code' => '商品编码',
  12. 'good_name' => '商品名称',
  13. 'cat_id' => '分类',
  14. 'brand_id' => '品牌',
  15. 'good_unit' => '商品单位',
  16. 'good_type' => '',
  17. 'companyNo' => '业务企业',
  18. 'moq' => '起订量',
  19. 'customized' => '定制工期',
  20. 'tax' => '税点',
  21. 'supplierNo' => '供应商',
  22. 'is_auth' => '是否有销售权限',
  23. 'is_stock' => '是否库存品',
  24. 'auth_img' => '销售授权图片',
  25. 'after_sales' => '售后说明',
  26. 'craft_desc' => '工艺说明',
  27. 'good_remark' => '商品备注',
  28. 'good_size' => '商品尺寸',
  29. 'weight' => '商品重量',
  30. 'packing_way' => '包装方式',
  31. 'packing_size' => '装箱尺寸',
  32. 'packing_spec' => '装箱规格',
  33. 'packing_list' => '包装清单',
  34. 'packing_weight' => '装箱重量',
  35. 'good_bar' => '商品条形码',
  36. 'supply_area' => '供货区域',
  37. 'delivery_place' => '发货地',
  38. 'origin_place' => '产地',
  39. 'delivery_day' => '物流时间',
  40. 'lead_time' => '供货周期',
  41. 'sample_day' => '调样周期',
  42. 'sample_fee' => '调样费用',
  43. 'good_img' => '商品详情主图 ',
  44. 'good_thumb_img' => '商品缩略图',
  45. 'good_info_img' => '商品详情图',
  46. 'cert_fee' => '证书费',
  47. 'packing_fee' => '包装费',
  48. 'cost_fee' => '工艺费',
  49. 'mark_fee' => '加标费',
  50. 'demo_fee' => '打样费',
  51. 'open_fee' => '开模费',
  52. 'noble_metal' => '贵金属种类',
  53. 'noble_weight' => '贵金属重量',
  54. 'is_gold_price' => '是否使用实时金价',
  55. 'cgd_gold_price' => '供应商采购金价',
  56. 'market_price' => '市场价',
  57. 'nake_price' => '含税成本价',
  58. 'is_step' => '阶梯价是否启用',
  59. 'is_online' => '是否上线',
  60. 'status' => '状态',
  61. 'createrid' => '创建人id',
  62. 'creater' => '创建人',
  63. 'is_del' => '是否删除',
  64. 'addtime' => '创建时间',
  65. 'updatetime' => '修改时间',
  66. 'is_exclusive' => '是否专属类型',
  67. 'is_diff' => '是否有工差',
  68. 'config' => '配置',
  69. 'other_config' => '其他配置',
  70. ];
  71. //产品价格和产品导出
  72. public function exportGood()
  73. {
  74. $param = $this->request->only(['start_date', 'end_date', 'platform_id', 'status'], 'post', 'trim');
  75. $val = Validate::rule([
  76. 'start_date|筛选开始时间' => 'require|date|elt:end_date',
  77. 'end_date|筛选结束时间' => 'require|date',
  78. 'platform_id|筛选平台ID' => 'require|number|gt:0',
  79. 'status|状态' => 'require|number|in:5,6,8',
  80. ]);
  81. if (!$val->check($param)) return error_show(1004, $val->getError());
  82. $where_ladder = [['gl.is_del', '=', 0]];
  83. $where_good = [['g.is_del', '=', 0]];
  84. if (!empty($param['start_date']) && !empty($param['end_date'])) {
  85. $where_ladder[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  86. $where_good[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  87. }
  88. if (!empty($param['platform_id'])) {
  89. $where_ladder[] = ['gp.platform_code', '=', $param['platform_id']];
  90. $where_good[] = ['gp.platform_code', '=', $param['platform_id']];
  91. }
  92. if (!empty($param['status'])) {
  93. $where_ladder[] = ['gp.exam_status', '=', $param['status']];
  94. $where_good[] = ['gp.exam_status', '=', $param['status']];
  95. }
  96. $data = [];
  97. //产品价格
  98. $rs_ladder = Db::name('good_ladder')
  99. ->alias('gl')
  100. ->field('g.good_name 商品名称,gl.market_price 市场价,g.tax 税率,gl.min_num 起订量,gl.sale_price 售价,gl.skuCode 商品编码,gl.cost_fee 工艺费,gl.market_platform 对比平台')
  101. ->where($where_ladder)
  102. ->leftJoin('good_platform gp', 'gp.skuCode=gl.skuCode')
  103. ->leftJoin('good g', 'g.spuCode=gp.spuCode')
  104. ->order('g.id')
  105. ->select()
  106. ->toArray();
  107. if (!empty($rs_ladder)) {
  108. $data[] = [
  109. 'head' => array_keys($rs_ladder[0]),
  110. 'list' => $rs_ladder,
  111. 'filename' => '产品价格' . date('YmdHis'),
  112. ];
  113. }
  114. //产品
  115. $rs_temp_good = Db::name('good')
  116. ->alias('g')
  117. ->field('"" 一级分类,"" 二级分类, g.cat_id 三级分类,g.good_name 商品名称,g.good_type 商品类型,g.brand_id 商品品牌,\'\' 型号,g.origin_place 产地,g.good_unit 计量单位,g.weight 重量g,\'\' 响应时间,g.lead_time 供货周期,g.good_size 商品尺寸,g.packing_size 装箱尺寸,g.packing_way 包装方式,g.packing_spec 装箱规格,g.packing_list 包装清单,g.delivery_place 发货地,g.delivery_day 物流时间,gp.skuCode 商品编码,s.name 供应商名称,g.creater 采购员,g.spuCode')
  118. ->where($where_good)
  119. ->leftJoin('good_platform gp', 'gp.spuCode=g.spuCode')
  120. ->leftJoin('supplier s', 's.code=g.supplierNo')
  121. ->order('g.id')
  122. ->select()
  123. ->toArray();
  124. $all_good_type = [0 => '非定制商品', 1 => '定制商品'];
  125. $all_brand = Db::name('brand')->whereIn('id', array_column($rs_temp_good, '商品品牌'))->where('is_del', 0)->column('brand_name', 'id');
  126. $all_cat = Db::name('cat')
  127. ->alias('c3')
  128. ->whereIn('c3.id', array_column($rs_temp_good, '三级分类'))
  129. ->where('c3.is_del', 0)
  130. ->leftJoin('cat c2', 'c2.id=c3.pid')
  131. ->leftJoin('cat c1', 'c1.id=c2.pid')
  132. ->column('c3.cat_name cat_name_3,c2.cat_name cat_name_2,c1.cat_name cat_name_1', 'c3.id');
  133. $all_unit = Db::name('unit')->whereIn('id', array_column($rs_temp_good, '计量单位'))->where('is_del', 0)->column('unit', 'id');
  134. foreach ($rs_temp_good as &$value) {
  135. $value['商品品牌'] = isset($all_brand[$value['商品品牌']]) ? $all_brand[$value['商品品牌']] : '';
  136. $value['商品类型'] = isset($all_good_type[$value['商品类型']]) ? $all_good_type[$value['商品类型']] : '';
  137. $value['一级分类'] = isset($all_cat[$value['三级分类']]['cat_name_1']) ? $all_cat[$value['三级分类']]['cat_name_1'] : '';
  138. $value['二级分类'] = isset($all_cat[$value['三级分类']]['cat_name_2']) ? $all_cat[$value['三级分类']]['cat_name_2'] : '';
  139. $value['三级分类'] = isset($all_cat[$value['三级分类']]['cat_name_3']) ? $all_cat[$value['三级分类']]['cat_name_3'] : '';
  140. $temp = explode(',', $value['产地']);
  141. $value['产地'] = GetAddr(json_encode(['provice_code' => isset($temp[0]) ? $temp[0] : '', 'city_code' => isset($temp[1]) ? $temp[1] : '', 'area_code' => isset($temp[2]) ? $temp[2] : '']));
  142. $value['计量单位'] = isset($all_unit[$value['计量单位']]) ? $all_unit[$value['计量单位']] : '';
  143. $temp_2 = explode(',', $value['发货地']);
  144. $value['发货地'] = GetAddr(json_encode(['provice_code' => isset($temp_2[0]) ? $temp_2[0] : '', 'city_code' => isset($temp_2[1]) ? $temp_2[1] : '', 'area_code' => isset($temp_2[2]) ? $temp_2[2] : '']));
  145. $value['型号'] = Db::name('good_spec')
  146. ->alias('gp')
  147. ->field('')
  148. ->leftJoin('specs s', 's.id=gp.spec_id')
  149. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  150. ->where([
  151. 'gp.spuCode' => $value['spuCode'],
  152. 'gp.is_del' => 0,
  153. 's.spec_name' => '型号',
  154. ])
  155. ->value('sv.spec_value', '');
  156. $value['响应时间'] = Db::name('good_spec')
  157. ->alias('gp')
  158. ->field('')
  159. ->leftJoin('specs s', 's.id=gp.spec_id')
  160. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  161. ->where([
  162. 'gp.spuCode' => $value['spuCode'],
  163. 'gp.is_del' => 0,
  164. 's.spec_name' => '响应时间',
  165. ])
  166. ->value('sv.spec_value', '');
  167. unset($value['spuCode']);
  168. }
  169. if (!empty($rs_temp_good)) {
  170. $data[] = [
  171. 'head' => array_keys($rs_temp_good[0]),
  172. 'list' => $rs_temp_good,
  173. 'filename' => '产品' . date('YmdHis'),
  174. ];
  175. }
  176. if (empty($data)) {
  177. $data[] = [
  178. 'head' => ['没有可供导出的数据'],
  179. 'list' => [],
  180. 'filename' => date('YmdHis'),
  181. ];
  182. }
  183. excelSaveBatch($data);
  184. }
  185. //【一、采购日报表】1.竞价单总数
  186. public function zixunTotal()
  187. {
  188. $param = $this->request->only([
  189. 'token',
  190. 'start_date' => '',
  191. 'end_date' => '',
  192. 'page' => 1,
  193. 'size' => 15,
  194. ], 'post', 'trim');
  195. $val_params = Validate::rule([
  196. 'start_date' => 'date|elt:end_date',
  197. 'end_date' => 'date',
  198. ]);
  199. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  200. $where = [['a.is_del', '=', 0]];
  201. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  202. $count = Db::name('consult_info')
  203. ->alias('a')
  204. ->field('DATE_FORMAT(a.addtime,"%Y-%m-%d") addtime,cii.name,count(a.id) total')
  205. ->leftJoin('consult_order b', 'b.zxNo=a.zxNo')
  206. ->leftJoin('company_item cii', 'cii.id=b.depart')
  207. ->where($where)
  208. ->group('addtime,b.depart')
  209. ->order('addtime')
  210. ->count();
  211. $list = Db::name('consult_info')
  212. ->alias('a')
  213. ->field('DATE_FORMAT(a.addtime,"%Y-%m-%d") addtime,cii.name,count(a.id) total')
  214. ->leftJoin('consult_order b', 'b.zxNo=a.zxNo')
  215. ->leftJoin('company_item cii', 'cii.id=b.depart')
  216. ->where($where)
  217. ->group('addtime,b.depart')
  218. ->order('addtime', 'desc')
  219. ->page($param['page'], $param['size'])
  220. ->select()
  221. ->toArray();
  222. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  223. }
  224. //【一、采购日报表】2.采购订单总金额
  225. public function purcheaseOrderSum()
  226. {
  227. $param = $this->request->only([
  228. 'token',
  229. 'start_date' => '',
  230. 'end_date' => '',
  231. // 'page' => 1,
  232. // 'size' => 15,
  233. ], 'post', 'trim');
  234. $val_params = Validate::rule([
  235. 'start_date|创建开始日期' => 'date|elt:end_date',
  236. 'end_date|创建结束日期' => 'date|egt:start_date',
  237. ]);
  238. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  239. $where = [['po.is_del', '=', 0]];
  240. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['po.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  241. //统计条数的时候,不能按照status分组,否则下方列表不准
  242. // $count = Db::name('purchease_order')
  243. // ->alias('po')
  244. // ->leftJoin('depart_user du', 'du.uid=po.cgder_id AND du.is_del=0')
  245. // ->leftJoin('company_item ci', 'ci.id=du.itemid')
  246. // ->where($where)
  247. // ->order('addtime,itemid')
  248. // ->field('DATE_FORMAT(po.addtime,"%Y-%m-%d") addtime,SUM(po.total_fee) total_fee,COUNT(po.id) total_num,du.itemid,ci.name,"" wait_total_fee,"" wait_total_num')
  249. // ->group('addtime,du.itemid')
  250. // ->count();
  251. // $list = Db::name('purchease_order')
  252. // ->alias('po')
  253. // ->field('DATE_FORMAT(po.addtime,"%Y-%m-%d") addtime,SUM(po.total_fee) total_fee,COUNT(po.id) total_num,po.status,du.itemid,ci.name,"" wait_total_fee,"" wait_total_num')
  254. // ->leftJoin('depart_user du', 'du.uid=po.cgder_id AND du.is_del=0')
  255. // ->leftJoin('company_item ci', 'ci.id=du.itemid')
  256. // ->where($where)
  257. // ->order(['addtime'=>'desc','itemid'=>'asc'])
  258. // ->page($param['page'], $param['size'])
  259. // ->group('addtime,du.itemid,po.status')
  260. // ->cursor();
  261. $list = Db::name('purchease_order')
  262. ->alias('po')
  263. ->field('po.id,DATE_FORMAT(po.addtime,"%Y%m%d") addtime,po.cgder_id,IF(ISNULL(`du`.`itemid`),0,`du`.`itemid`) itemid,IF(ISNULL(`ci`.`name`),"供应商端",`ci`.`name`) name,po.total_fee,po.good_num,po.status,po.supplierNo')
  264. ->leftJoin('depart_user du', 'du.uid=po.cgder_id AND du.is_del=0 AND du.nickname = po.cgder')
  265. ->leftJoin('company_item ci', 'ci.id=du.itemid')
  266. ->where($where)
  267. ->order(['addtime' => 'desc', 'itemid' => 'asc'])
  268. // ->cursor();
  269. ->select()
  270. ->toArray();
  271. $all_supplier_no = array_column($list, 'supplierNo');
  272. $all_supplier = checkHasAccountBySupplierNos($all_supplier_no);//检查这些供应商账号是否开通账户
  273. $all_supplier = array_keys($all_supplier);
  274. $data = [];
  275. foreach ($list as $value) {
  276. //把供应商端的数据单列出来
  277. if (in_array($value['supplierNo'], $all_supplier)) {
  278. $value['itemid'] = -1;
  279. $value['name'] = '供应商端';
  280. }
  281. if (!isset($data[$value['addtime']][$value['itemid']])) {
  282. $data[$value['addtime']][$value['itemid']] = [
  283. 'addtime' => date('Y-m-d', strtotime($value['addtime'])),
  284. // 'itemid' => $value['itemid'],
  285. 'name' => $value['name'],
  286. 'total_fee' => '0',
  287. 'total_num' => '0',
  288. 'good_num' => '0',
  289. 'wait_confirm_total_fee' => '0',//待与供应商确认-总金额
  290. 'wait_confirm_total_num' => '0',//待与供应商确认-总单数
  291. 'wait_in_total_fee' => '0',//待入库-总金额
  292. 'wait_in_total_num' => '0',//待入库-总单数
  293. ];
  294. }
  295. $data[$value['addtime']][$value['itemid']]['total_fee'] = bcadd($data[$value['addtime']][$value['itemid']]['total_fee'], $value['total_fee'], 2);
  296. $data[$value['addtime']][$value['itemid']]['total_num'] = bcadd($data[$value['addtime']][$value['itemid']]['total_num'], 1);
  297. $data[$value['addtime']][$value['itemid']]['good_num'] = bcadd($data[$value['addtime']][$value['itemid']]['good_num'], $value['good_num']);
  298. switch ($value['status']) {
  299. case 0:
  300. $data[$value['addtime']][$value['itemid']]['wait_confirm_total_fee'] = bcadd($data[$value['addtime']][$value['itemid']]['wait_confirm_total_fee'], $value['total_fee'], 2);
  301. $data[$value['addtime']][$value['itemid']]['wait_confirm_total_num'] = bcadd($data[$value['addtime']][$value['itemid']]['wait_confirm_total_num'], '1');
  302. break;
  303. case 1:
  304. $data[$value['addtime']][$value['itemid']]['wait_in_total_fee'] = bcadd($data[$value['addtime']][$value['itemid']]['wait_in_total_fee'], $value['total_fee'], 2);
  305. $data[$value['addtime']][$value['itemid']]['wait_in_total_num'] = bcadd($data[$value['addtime']][$value['itemid']]['wait_in_total_num'], 1);
  306. break;
  307. }
  308. // if ($value['status'] == 0) {
  309. // $data[$value['addtime']][$value['itemid']]['wait_total_fee'] += $value['total_fee'];
  310. // $data[$value['addtime']][$value['itemid']]['wait_total_num'] += $value['total_num'];
  311. // } else {
  312. // $data[$value['addtime']][$value['itemid']]['total_fee'] += $value['total_fee'];
  313. // $data[$value['addtime']][$value['itemid']]['total_num'] += $value['total_num'];
  314. // }
  315. }
  316. //去除下标
  317. $da = [];
  318. foreach ($data as $v) {
  319. foreach ($v as $vvv) {
  320. $da[] = $vvv;
  321. }
  322. }
  323. return app_show(0, '请求成功', $da);
  324. }
  325. //【一、采购日报表】3.采购员回复竞价单数
  326. public function consultBidsSum()
  327. {
  328. $param = $this->request->only([
  329. 'token',
  330. 'start_date' => '',
  331. 'end_date' => '',
  332. // 'page' => 1,
  333. // 'size' => 15,
  334. // 'supplier' => ''
  335. ], 'post', 'trim');
  336. $val_params = Validate::rule([
  337. 'start_date' => 'date|elt:end_date',
  338. 'end_date' => 'date',
  339. ]);
  340. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  341. $where = [['cb.is_del', '=', 0]];
  342. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['cb.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  343. // if ($param['supplier'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier'] . '%'];
  344. // $count = Db::name('consult_bids')
  345. // ->alias('cb')
  346. //// ->field('DATE_FORMAT(cb.addtime,"%Y-%m-%d") addtime,du.itemid,cb.createrid,SUM(c.num) num,COUNT(cb.id) total,du.nickname,ci.name')
  347. // ->leftJoin('consult_info c', 'c.infoNo=cb.infoNo')
  348. // ->leftJoin('depart_user du', 'du.uid=cb.createrid AND du.is_del=0')
  349. // ->leftJoin('company_item ci', 'ci.id=du.itemid')
  350. //// ->leftJoin('supplier s', 's.code=cb.supplierNo')
  351. // ->where($where)
  352. // ->group('addtime,du.itemid,ci.name ,cb.createrid,du.nickname')
  353. // ->order('addtime,du.itemid,ci.name ,cb.createrid,du.nickname')
  354. // ->count();
  355. $list = Db::name('consult_bids')
  356. ->alias('cb')
  357. ->field('DATE_FORMAT(cb.addtime,"%Y-%m-%d") addtime,du.itemid,cb.createrid,SUM(c.num) num,COUNT(cb.id) total,IF(ISNULL(`du`.`nickname`),`s`.`name`,`du`.`nickname`) nickname,IF(ISNULL(`ci`.`name`),"供应商",`ci`.`name`) name,s.name supplierName')
  358. ->leftJoin('consult_info c', 'c.infoNo=cb.infoNo')
  359. ->leftJoin('depart_user du', 'du.uid=cb.createrid AND du.is_del=0')
  360. ->leftJoin('company_item ci', 'ci.id=du.itemid')
  361. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  362. ->where($where)
  363. ->group('addtime,du.itemid,ci.name ,cb.createrid,du.nickname,s.name')
  364. ->order('addtime desc,du.itemid,ci.name ,cb.createrid,du.nickname')
  365. // ->page($param['page'], $param['size'])
  366. ->cursor();
  367. $data = [];
  368. foreach ($list as $value) {
  369. if ($value['name'] == '供应商') {
  370. $data[] = $value;
  371. continue;
  372. }
  373. if (!isset($data[$value['addtime']][$value['name']][$value['nickname']])) {
  374. $data[$value['addtime']][$value['name']][$value['nickname']] = [
  375. 'addtime' => $value['addtime'],
  376. 'name' => $value['name'],
  377. 'nickname' => $value['nickname'],
  378. 'num' => '0',
  379. 'total' => '0',
  380. ];
  381. }
  382. $data[$value['addtime']][$value['name']][$value['nickname']]['num'] = bcadd($data[$value['addtime']][$value['name']][$value['nickname']]['num'], $value['num']);
  383. $data[$value['addtime']][$value['name']][$value['nickname']]['total'] = bcadd($data[$value['addtime']][$value['name']][$value['nickname']]['total'], $value['total']);
  384. }
  385. //去除下标
  386. $da = [];
  387. foreach ($data as $key => $val) {
  388. if (is_numeric($key)) $da[] = $val;
  389. else {
  390. foreach ($val as $val2) {
  391. foreach ($val2 as $val3) {
  392. $da[] = $val3;
  393. }
  394. }
  395. }
  396. }
  397. $da[] = ['addtime' => '汇总', 'itemid' => 0, 'createrid' => 0, 'num' => array_sum(array_column($da, 'num')), 'total' => array_sum(array_column($da, 'total')), 'nickname' => '', 'name' => ''];
  398. return app_show(0, '请求成功', $da);
  399. }
  400. //【一、采购日报表】4.采购员订单金额
  401. public function purcheaseOrderSumByUser()
  402. {
  403. $param = $this->request->only([
  404. 'token',
  405. 'start_date' => '',
  406. 'end_date' => '',
  407. // 'page' => 1,
  408. // 'size' => 15
  409. ], 'post', 'trim');
  410. $val_params = Validate::rule([
  411. 'start_date' => 'date|elt:end_date',
  412. 'end_date' => 'date',
  413. ]);
  414. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  415. $where = [['is_del', '=', 0]];
  416. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  417. //先组织子查询
  418. $rs = Db::name('purchease_order')
  419. ->field('id,DATE_FORMAT(addtime, "%Y-%m-%d") addtime,cgder_id,cgder,total_fee,status,good_num,supplierNo,0 wait_total_fee,0 wait_good_num,0 count_num')
  420. ->where($where)
  421. ->select()
  422. ->order('addtime desc,cgder_id')
  423. ->toArray();
  424. // ->buildSql();
  425. // $count = Db::table($children_query)
  426. // ->alias('a')
  427. // ->group('addtime,cgder_id,cgder')
  428. // ->count();
  429. // $rs = Db::table($children_query)
  430. // ->alias('a')
  431. // ->field('a.addtime,a.cgder_id,a.cgder,SUM(a.total_fee) total_fee,SUM(a.good_num) good_num,COUNT(a.id) count_num,a.status,0 wait_total_fee,0 wait_good_num,supplierNo')
  432. // ->group('a.addtime,a.cgder_id,a.cgder,a.status')
  433. // ->order('a.addtime desc,a.cgder_id')
  434. // ->page($param['page'], $param['size'])
  435. // ->cursor();
  436. $all_supplier = array_column($rs, 'supplierNo');
  437. $has_account = checkHasAccountBySupplierNos($all_supplier);//检查供应商是否开通账号
  438. $supplier = Db::name('supplier')->whereIn('code',array_keys($has_account))->column('name','code');
  439. $data = [];
  440. foreach ($rs as $value) {
  441. if (!isset($data[$value['addtime']][$value['cgder_id']])) {
  442. $data[$value['addtime']][$value['cgder_id']] = [
  443. 'addtime' => $value['addtime'],
  444. 'cgder' => isset($has_account[$value['supplierNo']]) ? $supplier[$value['supplierNo']] ?? '' : $value['cgder'],
  445. 'name' => isset($has_account[$value['supplierNo']]) ? '供应商' : get_company_name_by_uid($value['cgder_id']),
  446. 'count_num' => '0',
  447. 'total_fee' => '0',
  448. 'good_num' => '0',
  449. 'wait_total_fee' => '0',
  450. 'wait_good_num' => '0',
  451. ];
  452. }
  453. if ($value['status'] == 0) {
  454. $data[$value['addtime']][$value['cgder_id']]['wait_total_fee'] = bcadd($data[$value['addtime']][$value['cgder_id']]['wait_total_fee'], $value['total_fee'], 2);
  455. $data[$value['addtime']][$value['cgder_id']]['wait_good_num'] = bcadd($data[$value['addtime']][$value['cgder_id']]['wait_good_num'], $value['good_num']);
  456. } else {
  457. $data[$value['addtime']][$value['cgder_id']]['total_fee'] = bcadd($data[$value['addtime']][$value['cgder_id']]['total_fee'], $value['total_fee'], 2);
  458. $data[$value['addtime']][$value['cgder_id']]['good_num'] = bcadd($data[$value['addtime']][$value['cgder_id']]['good_num'], $value['good_num']);
  459. }
  460. $data[$value['addtime']][$value['cgder_id']]['count_num'] = bcadd($data[$value['addtime']][$value['cgder_id']]['count_num'], 1);
  461. }
  462. $da = [];
  463. //去除下标
  464. foreach ($data as $v) {
  465. foreach ($v as $vv) {
  466. $da[] = $vv;
  467. }
  468. }
  469. return app_show(0, '请求成功', $da);
  470. }
  471. //【二、咨询单报表】1.已采反报价信息_列表
  472. public function consultInfoBidsSum()
  473. {
  474. $param = $this->request->only([
  475. 'token',
  476. 'zxNo' => [],
  477. 'start_date' => '',
  478. 'end_date' => '',
  479. 'cbaddtime_start_date' => '',
  480. 'cbaddtime_end_date' => '',
  481. 'supplier' => '',
  482. 'creater' => '',
  483. 'page' => 1,
  484. 'size' => 15,
  485. ], 'post', 'trim');
  486. $val_params = Validate::rule([
  487. 'start_date|竞价开始时间' => 'date|elt:end_date',
  488. 'end_date|竞价开始时间' => 'date|egt:start_date',
  489. 'cbaddtime_start_date|采购回复开始时间' => 'date|elt:cbaddtime_end_date',
  490. 'cbaddtime_end_date|采购回复开始时间' => 'date|egt:cbaddtime_start_date',
  491. ]);
  492. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  493. $where = [['cb.is_del', '=', 0]];
  494. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  495. if ($param['cbaddtime_start_date'] != '' && $param['cbaddtime_end_date'] != '') $where[] = ['cb.addtime', 'between', [$param['cbaddtime_start_date'] . ' 00:00:00', $param['cbaddtime_end_date'] . ' 23:59:59']];
  496. if ($param['supplier'] != '') $where[] = ['cb.supplierNo|s.name', 'like', '%' . $param['supplier'] . '%'];
  497. if ($param['creater'] != '') $where[] = ['cb.creater', 'like', '%' . $param['creater'] . '%'];
  498. if ($param['zxNo'] != '') $where[] = ['cb.infoNo', 'like', '%' . $param['zxNo'] . '%'];
  499. $count = Db::name('consult_bids')
  500. ->alias('cb')
  501. ->leftJoin('consult_info ci', 'ci.infoNo=cb.infoNo')
  502. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  503. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  504. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  505. ->where($where)
  506. ->count('cb.id');
  507. $data = Db::name('consult_bids')
  508. ->alias('cb')
  509. ->field('cb.id,ci.addtime,cb.bidNo,cb.infoNo zxNo,cb.addtime cbaddtime,cb.good_name,s.name supplier,cb.total_fee,cb.delivery_day,cb.work_day,cb.expire_day,cb.creater,cb.createrid,"" name,ci.num,ci.arrival_time,co.saleid,co.salesman,"" salesman_name,csi.companyName')
  510. ->leftJoin('consult_info ci', 'ci.infoNo=cb.infoNo')
  511. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  512. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  513. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  514. ->withAttr('name', function ($val, $data) {
  515. return get_company_name_by_uid($data['createrid']);
  516. })
  517. ->withAttr('salesman_name', function ($val, $data) {
  518. return get_company_name_by_uid($data['saleid']);
  519. })
  520. ->where($where)
  521. ->page($param['page'], $param['size'])
  522. ->order('ci.addtime', 'desc')
  523. ->select()
  524. ->toArray();
  525. //汇总
  526. $data[] = [
  527. 'id' => 0,
  528. 'addtime' => '汇总',
  529. 'bidNo' => '',
  530. 'zxNo' => '',
  531. 'cbaddtime' => '',
  532. 'good_name' => '',
  533. 'supplier' => '',
  534. 'total_fee' => array_sum(array_column($data, 'total_fee')),
  535. 'delivery_day' => '',
  536. 'work_day' => '',
  537. 'expire_day' => '',
  538. 'creater' => '',
  539. 'num' => array_sum(array_column($data, 'num')),
  540. 'arrival_time' => '',
  541. 'salesman' => '',
  542. 'companyName' => '',
  543. ];
  544. return app_show(0, '请求成功', ['count' => $count, 'list' => $data]);
  545. }
  546. //【二、咨询单报表】1.已采反报价信息_导出
  547. public function consultInfoBidsSumExport()
  548. {
  549. $param = $this->request->only([
  550. 'token',
  551. 'zxNo' => [],
  552. 'start_date' => '',
  553. 'end_date' => '',
  554. 'cbaddtime_start_date' => '',
  555. 'cbaddtime_end_date' => '',
  556. 'supplier' => '',
  557. 'creater' => '',
  558. 'page' => 1,
  559. 'size' => 15,
  560. ], 'post', 'trim');
  561. $val_params = Validate::rule([
  562. 'start_date|竞价开始时间' => 'date|elt:end_date',
  563. 'end_date|竞价开始时间' => 'date|egt:start_date',
  564. 'cbaddtime_start_date|采购回复开始时间' => 'date|elt:cbaddtime_end_date',
  565. 'cbaddtime_end_date|采购回复开始时间' => 'date|egt:cbaddtime_start_date',
  566. ]);
  567. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  568. $rs = Db::name('consult_bids')
  569. ->alias('cb')
  570. ->where('cb.is_del', 0);
  571. if ($param['start_date'] != '' && $param['end_date'] != '') $rs->whereBetween('ci.addtime', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']);
  572. if ($param['zxNo'] != '') $rs->whereIn('cb.infoNo', $param['zxNo']);
  573. if ($param['cbaddtime_start_date'] != '' && $param['cbaddtime_end_date'] != '') $rs->whereBetween('cb.addtime', [$param['cbaddtime_start_date'] . ' 00:00:00', $param['cbaddtime_end_date'] . ' 23:59:59']);
  574. if ($param['supplier'] != '') $rs->whereLike('cb.supplierNo|s.name', '%' . $param['supplier'] . '%');
  575. if ($param['creater'] != '') $rs->whereLike('cb.creater', '%' . $param['creater'] . '%');
  576. $data = $rs
  577. ->field('ci.addtime as 咨询时间,cb.bidNo as 采购单反馈单号,cb.infoNo as 咨询订单号,cb.addtime as 回复时间,cb.good_name as 产品名称,s.name as 供应商名称,cb.total_fee 成本合计,cb.delivery_day 物流时间,cb.work_day 产品工期,cb.expire_day 信息有效期,cb.creater 采购员,"" 采购员所属部门,ci.num 需求数量,ci.arrival_time 要求到货日期,co.salesman 业务人员,"" 业务人员所属部门,csi.companyName 客户名称,cb.createrid,co.saleid')
  578. ->leftJoin('consult_info ci', 'ci.infoNo=cb.infoNo')
  579. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  580. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  581. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  582. ->cursor();
  583. $list = [];
  584. foreach ($data as $value) {
  585. $value['采购员所属部门'] = get_company_name_by_uid($value['createrid']);
  586. $value['业务人员所属部门'] = get_company_name_by_uid($value['saleid']);
  587. unset($value['createrid']);
  588. unset($value['saleid']);
  589. $list[] = $value;
  590. }
  591. if (empty($list)) $list[] = '没有可供导出的数据';
  592. $headerArr = array_keys($list[0]);
  593. excelSave('咨询单报表-已采反报价信息' . date('YmdHis'), $headerArr, $list);
  594. }
  595. //【二、咨询单报表】2.未采反信息_列表
  596. public function consultInfoBidsSumNot()
  597. {
  598. $param = $this->request->only([
  599. 'token',
  600. 'companyName' => '',
  601. 'start_date' => '',
  602. 'end_date' => '',
  603. 'start_updatetime' => '',
  604. 'end_updatetime' => '',
  605. 'page' => 1,
  606. 'size' => 15,
  607. ], 'post', 'trim');
  608. $val_params = Validate::rule([
  609. 'start_date' => 'date|elt:end_date',
  610. 'end_date' => 'date',
  611. 'start_updatetime' => 'date|elt:end_updatetime',
  612. 'end_updatetime' => 'date',
  613. ]);
  614. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  615. $where = [['ci.is_del', '=', 0]];
  616. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  617. if ($param['companyName'] != '') $where[] = ['csi.companyName', 'like', '%' . $param['companyName'] . '%'];
  618. if ($param['start_updatetime'] != '' && $param['end_updatetime'] != '') $where[] = ['ci.updatetime', 'between', [$param['start_updatetime'] . ' 00:00:00', $param['end_updatetime'] . ' 23:59:59']];
  619. $status = [1 => '招标进行中', 2 => '招标已结束', 3 => '等待议价结果', 4 => '确认商品', 5 => '成功转单', 6 => '取消转单', 7 => '招标已暂停'];
  620. $count = Db::name('consult_info')
  621. ->alias('ci')
  622. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
  623. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  624. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  625. ->where($where)
  626. ->whereNull('cb.id')
  627. ->order('ci.arrival_time', 'desc')
  628. ->count('ci.id');
  629. $data = Db::name('consult_info')
  630. ->alias('ci')
  631. ->field('ci.infoNo zxNo,ci.good_name,ci.num,csi.companyName,ci.addtime,ci.arrival_time endtime,ci.updatetime,ci.status')
  632. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
  633. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  634. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  635. ->where($where)
  636. ->whereNull('cb.id')//未采反,即咨询单没有对应的反馈单,所以反馈单id应该是null
  637. ->order('ci.arrival_time', 'desc')
  638. ->page($param['page'], $param['size'])
  639. ->withAttr('status', function ($val) use ($status) {
  640. return isset($status[$val]) ? $status[$val] : '';
  641. })
  642. ->select()
  643. ->toArray();
  644. return app_show(0, '请求成功', ['list' => $data, 'count' => $count]);
  645. }
  646. //【二、咨询单报表】2.未采反信息_导出
  647. public function consultInfoBidsSumNotExport()
  648. {
  649. $param = $this->request->only([
  650. 'token',
  651. 'companyName' => '',
  652. 'start_date' => '',
  653. 'end_date' => '',
  654. 'start_updatetime' => '',
  655. 'end_updatetime' => '',
  656. ], 'post', 'trim');
  657. $val_params = Validate::rule([
  658. 'start_date' => 'date|elt:end_date',
  659. 'end_date' => 'date',
  660. 'start_updatetime' => 'date|elt:end_updatetime',
  661. 'end_updatetime' => 'date',
  662. ]);
  663. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  664. $where = [['ci.is_del', '=', 0]];
  665. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  666. if ($param['companyName'] != '') $where[] = ['csi.companyName', 'like', '%' . $param['companyName'] . '%'];
  667. if ($param['start_updatetime'] != '' && $param['end_updatetime'] != '') $where[] = ['ci.updatetime', 'between', [$param['start_updatetime'] . ' 00:00:00', $param['end_updatetime'] . ' 23:59:59']];
  668. $status = [1 => '招标进行中', 2 => '招标已结束', 3 => '等待议价结果', 4 => '确认商品', 5 => '成功转单', 6 => '取消转单', 7 => '招标已暂停'];
  669. $data = Db::name('consult_info')
  670. ->alias('ci')
  671. ->field('ci.infoNo 竞价订单号,ci.good_name 商品名称,ci.num 需求数量,csi.companyName 客户名称,ci.addtime 创建时间,ci.arrival_time 截止时间,ci.updatetime 结束时间,ci.status 状态')
  672. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
  673. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  674. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  675. ->where($where)
  676. ->whereNull('cb.id')
  677. ->order('ci.arrival_time', 'desc')
  678. ->withAttr('状态', function ($val) use ($status) {
  679. return isset($status[$val]) ? $status[$val] : '';
  680. })
  681. ->select()
  682. ->toArray();
  683. if (empty($data)) $data[] = '没有可供导出的数据';
  684. $headerArr = array_keys($data[0]);
  685. excelSave('咨询单报表-未采反信息' . date('YmdHis'), $headerArr, $data);
  686. }
  687. //【三、订单明细报表】列表
  688. public function orderListDetailed()
  689. {
  690. $param = $this->request->only([
  691. 'token',
  692. 'start_date' => '',
  693. 'end_date' => '',
  694. 'status' => '',
  695. 'page' => 1,
  696. 'size' => 15,
  697. ], 'post', 'trim');
  698. $val_params = Validate::rule([
  699. 'start_date' => 'date|elt:end_date',
  700. 'end_date' => 'date',
  701. ]);
  702. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  703. $where = [['po.is_del', '=', 0]];
  704. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['po.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  705. if ($param['status'] != '') $where[] = ['po.status', '=', $param['status']];
  706. $all_status = ['待与供应商确认', '待入库', '部分入库', '入库完成', '已取消订单'];
  707. $all_send_status = [1 => '未发货', 2 => '部分发货', 3 => '已发货'];
  708. $all_is_stock = [0 => '非库存品', 1 => '库存品'];
  709. $count = Db::name('purchease_order')
  710. ->alias('po')
  711. ->leftJoin('business b', 'b.companyNo=po.companyNo')
  712. ->where($where)
  713. ->count('po.id');
  714. $data = Db::name('purchease_order')
  715. ->alias('po')
  716. ->field('po.cgdNo,po.addtime,po.supplierNo,po.supplier_name,po.good_name,gb.is_stock,po.good_num,po.nake_fee,po.total_fee,po.status,po.send_status,po.wsend_num,"" creater,"" creater_name,b.company,po.cgder_id,po.cgder,"" name,"" send_time,on.orderCode,po.order_type,po.bkcode,po.spuCode')
  717. ->leftJoin('business b', 'b.companyNo=po.companyNo')
  718. ->leftJoin('order_num on', 'on.cgdNo=po.cgdNo')
  719. ->leftJoin('good_basic gb', 'gb.spuCode=po.spuCode AND gb.is_del=0')
  720. ->where($where)
  721. ->page($param['page'], $param['size'])
  722. ->order('po.addtime', 'desc')
  723. ->cursor();
  724. $list = [];
  725. foreach ($data as $v) {
  726. //单据状态
  727. $v['status'] = isset($all_status[$v['status']]) ? $all_status[$v['status']] : '';
  728. //发货状态
  729. $v['send_status'] = isset($all_send_status[$v['send_status']]) ? $all_send_status[$v['send_status']] : '';
  730. //商品库存性质
  731. $v['is_stock'] = isset($all_is_stock[$v['is_stock']]) ? $all_is_stock[$v['is_stock']] : '';
  732. //创建人//order_type==1备库单
  733. if ($v['order_type'] == 1) $temp = Db::name('purchease')->where(['bk_code' => $v['bkcode'], 'spuCode' => $v['spuCode'], 'is_del' => 0])->field('id,apply_name,apply_id')->find();
  734. else $temp = Db::name('sale')->where(['orderCode' => $v['orderCode'], 'is_del' => 0])->field('id,apply_id,apply_name')->find();
  735. $v['creater'] = isset($temp['apply_name']) ? $temp['apply_name'] : '';
  736. $v['creater_name'] = get_company_name_by_uid($temp['apply_id'] ?? 0);
  737. //创建时间
  738. $v['send_time'] = Db::name('order_out')
  739. ->where(['orderCode' => $v['orderCode']])
  740. ->order('addtime', 'desc')
  741. ->value('addtime');
  742. $v['name'] = get_company_name_by_uid($v['cgder_id'] ?? 0);
  743. $list[] = $v;
  744. }
  745. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  746. }
  747. //【三、订单明细报表】导出
  748. public function orderListDetailedExport()
  749. {
  750. $param = $this->request->only([
  751. 'token',
  752. 'start_date' => '',
  753. 'end_date' => '',
  754. 'status' => '',
  755. ], 'post', 'trim');
  756. $val_params = Validate::rule([
  757. 'start_date' => 'date|elt:end_date',
  758. 'end_date' => 'date',
  759. ]);
  760. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  761. $where = [['po.is_del', '=', 0]];
  762. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['po.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  763. if ($param['status'] != '') $where[] = ['po.status', '=', $param['status']];
  764. $all_status = ['待与供应商确认', '待入库', '部分入库', '入库完成', '已取消订单'];
  765. $all_send_status = [1 => '未发货', 2 => '部分发货', 3 => '已发货'];
  766. $all_is_stock = [0 => '非库存品', 1 => '库存品'];
  767. $data = Db::name('purchease_order')
  768. ->alias('po')
  769. ->field('po.cgdNo 采购单编号,po.addtime 创建时间,po.supplierNo 供应商编号,po.supplier_name 供应商名称,po.good_name 商品名称,gb.is_stock 商品库存性质,po.good_num 购买数量,po.nake_fee 裸价,po.total_fee 成本合计,po.status 单据状态,po.send_status 发货状态,po.wsend_num 未发货数量,"" 创建人,"" 创建人所属部门,b.company 客户名称,po.cgder 采购员,"" 采购员所属部门,"" 发货时间,on.orderCode,po.order_type,po.bkcode,po.spuCode,po.cgder_id')
  770. ->leftJoin('business b', 'b.companyNo=po.companyNo')
  771. ->leftJoin('order_num on', 'on.cgdNo=po.cgdNo')
  772. ->leftJoin('good_basic gb', 'gb.spuCode=po.spuCode AND gb.is_del=0')
  773. ->where($where)
  774. ->order('po.addtime', 'desc')
  775. ->cursor();
  776. $list = [];
  777. foreach ($data as $v) {
  778. //单据状态
  779. $v['单据状态'] = isset($all_status[$v['单据状态']]) ? $all_status[$v['单据状态']] : '';
  780. //发货状态
  781. $v['发货状态'] = isset($all_send_status[$v['发货状态']]) ? $all_send_status[$v['发货状态']] : '';
  782. //商品库存性质
  783. $v['商品库存性质'] = isset($all_is_stock[$v['商品库存性质']]) ? $all_is_stock[$v['商品库存性质']] : '';
  784. //创建人//order_type==1备库单
  785. if ($v['order_type'] == 1) $temp = Db::name('purchease')->where(['bk_code' => $v['bkcode'], 'spuCode' => $v['spuCode'], 'is_del' => 0])->field('id,apply_name,apply_id')->find();
  786. else $temp = Db::name('sale')->where(['orderCode' => $v['orderCode'], 'is_del' => 0])->field('id,apply_id,apply_name')->find();
  787. $v['创建人'] = isset($temp['apply_name']) ? $temp['apply_name'] : '';
  788. $v['创建人所属部门'] = get_company_name_by_uid($temp['apply_id'] ?? 0);
  789. //创建时间
  790. $v['发货时间'] = Db::name('order_out')
  791. ->where(['orderCode' => $v['orderCode']])
  792. ->order('addtime', 'desc')
  793. ->value('addtime');
  794. $v['采购员所属部门'] = get_company_name_by_uid($v['cgder_id'] ?? 0);
  795. unset($v['orderCode']);
  796. unset($v['order_type']);
  797. unset($v['bkcode']);
  798. unset($v['spuCode']);
  799. unset($v['cgder_id']);
  800. $list[] = $v;
  801. }
  802. if (empty($list)) $list[] = '没有可供导出的数据';
  803. $headerArr = array_keys($list[0]);
  804. excelSave('订单明细报表' . date('YmdHis'), $headerArr, $list);
  805. }
  806. //【四、售后明细报表】列表
  807. public function orderReturnList()
  808. {
  809. $param = $this->request->only([
  810. 'token',
  811. 'start_date' => '',
  812. 'end_date' => '',
  813. 'page' => 1,
  814. 'size' => 15,
  815. ], 'post', 'trim');
  816. $val_params = Validate::rule([
  817. 'start_date' => 'date|elt:end_date',
  818. 'end_date' => 'date',
  819. ]);
  820. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  821. $where = [['or.is_del', '=', 0]];
  822. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  823. $all_status = [1 => '待业务审核', 2 => '待采购审核', 3 => '待设置仓库', 4 => '待客户退货', 5 => '售后已完成', 6 => '业务已驳回', 7 => '采购已驳回', 8 => '申请已取消'];
  824. //总数
  825. $count = Db::name('order_return')
  826. ->alias('or')
  827. ->leftJoin('order_num on', 'on.orderCode=or.orderCode')
  828. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  829. ->leftJoin('order_out oo', 'oo.outCode=or.outCode AND oo.status=3 AND oo.is_del=0')
  830. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  831. ->where($where)
  832. ->count('or.id');
  833. $list = Db::name('order_return')
  834. ->alias('or')
  835. ->field('or.id,or.returnCode,or.addtime,on.cgdNo,po.supplierNo,po.supplier_name,or.good_name,or.total_num, oo.updatetime receipttime ,or.error_num,or.error_remark,ri.result error_reason,or.status,po.cgder,ci.name')
  836. ->leftJoin('order_num on', 'on.orderCode=or.orderCode')
  837. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  838. ->leftJoin('order_out oo', 'oo.outCode=or.outCode AND oo.status=3 AND oo.is_del=0')
  839. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  840. ->leftJoin('depart_user u', 'u.uid=po.cgder_id AND u.is_del=0')
  841. ->leftJoin('company_item ci', 'ci.id=u.itemid')
  842. ->where($where)
  843. ->withAttr('status', function ($val) use ($all_status) {
  844. return isset($all_status[$val]) ? $all_status[$val] : $val;
  845. })
  846. ->page($param['page'], $param['size'])
  847. ->order('or.addtime desc')
  848. ->select()
  849. ->toArray();
  850. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  851. }
  852. //【四、售后明细报表】导出
  853. public function orderReturnListExport()
  854. {
  855. $param = $this->request->only([
  856. 'token',
  857. 'start_date' => '',
  858. 'end_date' => '',
  859. ], 'post', 'trim');
  860. $val_params = Validate::rule([
  861. 'start_date' => 'date|elt:end_date',
  862. 'end_date' => 'date',
  863. ]);
  864. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  865. $where = [['or.is_del', '=', 0]];
  866. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  867. $all_status = [2 => '业务主管审核', 3 => '采购主管审核', 6 => '业务驳回', 7 => '采购驳回', 8 => '取消'];
  868. $list = Db::name('order_return')
  869. ->alias('or')
  870. ->field('or.returnCode 售后单编号,or.addtime 创建时间,on.cgdNo 采购单编号,po.supplier_name 供应商名称,or.good_name 产品名称,or.total_num 购买数量, oo.updatetime 签收日期,or.error_num 售后数量,or.error_remark 问题描述,ri.result 异常原因,or.status 售后状态,po.cgder 采购员,ci.name 采购员所属部门')
  871. ->leftJoin('order_num on', 'on.orderCode=or.orderCode')
  872. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  873. ->leftJoin('order_out oo', 'oo.outCode=or.outCode AND oo.status=3 AND oo.is_del=0')
  874. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  875. ->leftJoin('depart_user u', 'u.uid=po.cgder_id AND u.is_del=0')
  876. ->leftJoin('company_item ci', 'ci.id=u.itemid')
  877. ->where($where)
  878. ->withAttr('售后状态', function ($val) use ($all_status) {
  879. return isset($all_status[$val]) ? $all_status[$val] : $val;
  880. })
  881. ->order('or.addtime desc')
  882. ->select()
  883. ->toArray();
  884. if (empty($list)) $list[] = '没有可供导出的数据';
  885. $headerArr = array_keys($list[0]);
  886. excelSave('售后明细报表' . date('YmdHis'), $headerArr, $list);
  887. }
  888. //【五、供应商报表】列表
  889. public function supplierList()
  890. {
  891. $param = $this->request->only([
  892. 'token',
  893. 'start_date' => '',
  894. 'end_date' => '',
  895. 'update_start_date' => '',
  896. 'update_end_date' => '',
  897. 'page' => 1,
  898. 'size' => 15,
  899. ], 'post', 'trim');
  900. $val_params = Validate::rule([
  901. 'start_date' => 'date|elt:end_date',
  902. 'end_date' => 'date',
  903. 'update_start_date' => 'date|elt:update_end_date',
  904. 'update_end_date' => 'date',
  905. ]);
  906. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  907. $where = [];
  908. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  909. if ($param['update_start_date'] != '' && $param['update_end_date'] != '') $where[] = ['s.updatetime', 'between', [$param['update_start_date'] . ' 00:00:00', $param['update_end_date'] . ' 23:59:59']];
  910. $all_source = [0 => '客户提供', 1 => '供应商', 2 => '公司开发'];
  911. $all_pay_type = [0 => '现结', 1 => '月清', 2 => '双月清'];
  912. $all_delivery_way = [0 => '供应商发货', 1 => '公司自提'];
  913. //总数
  914. $count = Db::name('supplier')
  915. ->alias('s')
  916. ->where($where)
  917. ->count('s.id');
  918. $list = Db::name('supplier')
  919. ->alias('s')
  920. ->field('s.id,s.addtime,s.name,s.creater,s.createrid,"" company_name,s.nature,s.source,s.pay_type,s.delivery_way,s.updatetime')
  921. ->where($where)
  922. ->page($param['page'], $param['size'])
  923. ->withAttr('source', function ($val) use ($all_source) {
  924. return is_numeric($val) ? (isset($all_source[$val]) ? $all_source[$val] : '') : $val;
  925. })
  926. ->withAttr('pay_type', function ($val) use ($all_pay_type) {
  927. return is_numeric($val) ? (isset($all_pay_type[$val]) ? $all_pay_type[$val] : '') : $val;
  928. })
  929. ->withAttr('delivery_way', function ($val) use ($all_delivery_way) {
  930. return is_numeric($val) ? (isset($all_delivery_way[$val]) ? $all_delivery_way[$val] : '') : $val;
  931. })
  932. ->withAttr('company_name', function ($val, $data) {
  933. return get_company_name_by_uid($data['createrid']);
  934. })
  935. ->order('s.addtime desc')
  936. ->select()
  937. ->toArray();
  938. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  939. }
  940. //【五、供应商报表】导出
  941. public function supplierListExport()
  942. {
  943. $param = $this->request->only([
  944. 'token',
  945. 'start_date' => '',
  946. 'end_date' => '',
  947. 'update_start_date' => '',
  948. 'update_end_date' => '',
  949. ], 'post', 'trim');
  950. $val_params = Validate::rule([
  951. 'start_date' => 'date|elt:end_date',
  952. 'end_date' => 'date',
  953. 'update_start_date' => 'date|elt:update_end_date',
  954. 'update_end_date' => 'date',
  955. ]);
  956. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  957. $where = [];
  958. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  959. if ($param['update_start_date'] != '' && $param['update_end_date'] != '') $where[] = ['s.updatetime', 'between', [$param['update_start_date'] . ' 00:00:00', $param['update_end_date'] . ' 23:59:59']];
  960. $all_source = [0 => '客户提供', 1 => '供应商', 2 => '公司开发'];
  961. $all_pay_type = [0 => '现结', 1 => '月清', 2 => '双月清'];
  962. $all_delivery_way = [0 => '供应商发货', 1 => '公司自提'];
  963. $list = Db::name('supplier')
  964. ->alias('s')
  965. ->field('s.addtime 录入供应商时间,s.name 供应商名称,s.creater 采购维护人,"" 采购维护人所属部门,s.nature 供应商性质,s.source 供应商来源,s.pay_type 付款方式,s.delivery_way 发货方式,s.updatetime 修改供应商时间,s.createrid')
  966. ->where($where)
  967. ->order('s.addtime desc')
  968. ->cursor();
  969. $data = [];
  970. foreach ($list as $value) {
  971. $value['供应商来源'] = is_numeric($value['供应商来源']) ? (isset($all_source[$value['供应商来源']]) ? $all_source[$value['供应商来源']] : '') : $value['供应商来源'];
  972. $value['付款方式'] = is_numeric($value['付款方式']) ? (isset($all_pay_type[$value['付款方式']]) ? $all_pay_type[$value['付款方式']] : '') : $value['付款方式'];
  973. $value['发货方式'] = is_numeric($value['发货方式']) ? (isset($all_delivery_way[$value['发货方式']]) ? $all_delivery_way[$value['发货方式']] : '') : $value['发货方式'];
  974. $value['采购维护人所属部门'] = get_company_name_by_uid($value['createrid']);
  975. unset($value['createrid']);
  976. $data[] = $value;
  977. }
  978. if (empty($data)) $data[] = '没有可供导出的数据';
  979. $headerArr = array_keys($data[0]);
  980. excelSave('供应商报表' . date('YmdHis'), $headerArr, $data);
  981. }
  982. //【六、退货流水报表】列表
  983. public function SaleReturnList()
  984. {
  985. $param = $this->request->only([
  986. 'token',
  987. 'start_date' => '',
  988. 'end_date' => '',
  989. 'page' => 1,
  990. 'size' => 15,
  991. ], 'post', 'trim');
  992. $val_params = Validate::rule([
  993. 'start_date' => 'date|elt:end_date',
  994. 'end_date' => 'date'
  995. ]);
  996. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  997. $where = [['s.is_del', '=', 0]];
  998. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  999. $count = Db::name('sale_return')
  1000. ->alias('s')
  1001. ->where($where)
  1002. ->leftJoin('order_num on', 'on.orderCode=s.orderCode')
  1003. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  1004. ->leftJoin('good_basic gb', 'gb.spuCode=po.spuCode AND gb.is_del=0')
  1005. ->leftJoin('result_info ri', 'ri.result_code=s.error_code AND ri.is_del=0')
  1006. ->count('s.id');
  1007. $list = Db::name('sale_return')
  1008. ->alias('s')
  1009. ->field('s.returnCode,s.addtime,po.cgdNo,po.supplier_name,po.good_name,gb.is_stock,po.good_num,po.cgder_id,po.cgder,"" name,s.num,on.send_num,ri.result,s.is_th')
  1010. ->where($where)
  1011. ->leftJoin('order_num on', 'on.orderCode=s.orderCode')
  1012. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  1013. ->leftJoin('good_basic gb', 'gb.spuCode=po.spuCode AND gb.is_del=0')
  1014. ->leftJoin('result_info ri', 'ri.result_code=s.error_code AND ri.is_del=0')
  1015. ->page($param['page'], $param['size'])
  1016. ->order('s.addtime desc')
  1017. ->cursor();
  1018. $data = [];
  1019. foreach ($list as $value) {
  1020. $value['name'] = get_company_name_by_uid($value['cgder_id'] ?? 0);
  1021. $data[] = $value;
  1022. }
  1023. return app_show(0, '请求成功', ['list' => $data, 'count' => $count]);
  1024. }
  1025. //【六、退货流水报表】导出
  1026. public function SaleReturnExport()
  1027. {
  1028. $param = $this->request->only([
  1029. 'token',
  1030. 'start_date' => '',
  1031. 'end_date' => ''
  1032. ], 'post', 'trim');
  1033. $val_params = Validate::rule([
  1034. 'start_date' => 'date|elt:end_date',
  1035. 'end_date' => 'date'
  1036. ]);
  1037. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1038. $where = [['s.is_del', '=', 0]];
  1039. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1040. $all_is_th = [0 => '不可以', 1 => '可以'];
  1041. $all_is_stock = [0 => '非库存品', 1 => '库存品'];
  1042. $list = Db::name('sale_return')
  1043. ->alias('s')
  1044. ->field('s.returnCode 退货单号,s.addtime 退货时间,po.cgdNo 采购单编号,po.supplier_name 供应商名称,po.good_name 产品名称,gb.is_stock 商品库存性质,po.good_num 购买数量,po.cgder 采购员,"" 采购员所属部门,s.num 退货数量,on.send_num 已发货数量,ri.result 退货原因,s.is_th 供应商是否可以退货,po.cgder_id')
  1045. ->where($where)
  1046. ->leftJoin('order_num on', 'on.orderCode=s.orderCode')
  1047. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  1048. ->leftJoin('good_basic gb', 'gb.spuCode=po.spuCode AND gb.is_del=0')
  1049. ->leftJoin('result_info ri', 'ri.result_code=s.error_code AND ri.is_del=0')
  1050. ->order('s.addtime desc')
  1051. ->cursor();
  1052. $data = [];
  1053. foreach ($list as $value) {
  1054. $value['供应商是否可以退货'] = isset($all_is_th[$value['供应商是否可以退货']]) ? $all_is_th[$value['供应商是否可以退货']] : '';
  1055. $value['商品库存性质'] = isset($all_is_stock[$value['商品库存性质']]) ? $all_is_stock[$value['商品库存性质']] : '';
  1056. $value['采购员所属部门'] = get_company_name_by_uid($value['cgder_id'] ?? 0);
  1057. unset($value['cgder_id']);
  1058. $data[] = $value;
  1059. }
  1060. if (empty($data)) $data[] = '没有可供导出的数据';
  1061. $headerArr = array_keys($data[0]);
  1062. excelSave('退货流水报表' . date('YmdHis'), $headerArr, $data);
  1063. }
  1064. //【七、商品报表】1.商品上线报表_列表
  1065. public function GoodOnlineList()
  1066. {
  1067. $param = $this->request->only([
  1068. 'token',
  1069. 'creater' => '',
  1070. 'supplier_name' => '',
  1071. 'start_date' => '',
  1072. 'end_date' => '',
  1073. 'page' => 1,
  1074. 'size' => 15,
  1075. ], 'post', 'trim');
  1076. $val_params = Validate::rule([
  1077. 'start_date' => 'date|elt:end_date',
  1078. 'end_date' => 'date'
  1079. ]);
  1080. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1081. $where = [['s.is_del', '=', 0], ['gp.exam_status', '=', 6]]; //exam_status==6 上线成功
  1082. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.online_time', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];//当上面状态确定为exam_status==6时,上线时间也可以取 updatetime
  1083. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1084. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1085. $count = Db::name('good_platform')
  1086. ->alias('gp')
  1087. ->where($where)
  1088. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1089. ->leftJoin('brand b', 'b.id=gb.brand_id')
  1090. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1091. ->count('gp.id');
  1092. $list = Db::name('good_platform')
  1093. ->alias('gp')
  1094. ->field('gb.createrid,gb.creater,"" company_name,gp.skuCode,gp.spuCode,gb.good_name,b.brand_name,"" good_model,s.name,gb.tax,gb.nake_price,gp.online_time')
  1095. ->where($where)
  1096. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1097. ->leftJoin('brand b', 'b.id=gb.brand_id')
  1098. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1099. ->order('gp.updatetime desc')
  1100. ->page($param['page'], $param['size'])
  1101. ->cursor();
  1102. $data = [];
  1103. foreach ($list as $value) {
  1104. $value['company_name'] = get_company_name_by_uid($value['createrid']);
  1105. $value['good_model'] = Db::name('good_spec')
  1106. ->alias('gp')
  1107. ->field('')
  1108. ->leftJoin('specs s', 's.id=gp.spec_id')
  1109. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  1110. ->where([
  1111. 'gp.spuCode' => $value['spuCode'],
  1112. 'gp.is_del' => 0,
  1113. 's.spec_name' => '型号',
  1114. ])
  1115. ->value('sv.spec_value', '');
  1116. $data[] = $value;
  1117. }
  1118. return app_show(0, '请求成功', ['list' => $data, 'count' => $count]);
  1119. }
  1120. //【七、商品报表】1.商品上线报表_导出
  1121. public function GoodOnlineExport()
  1122. {
  1123. $param = $this->request->only([
  1124. 'token',
  1125. 'creater' => '',
  1126. 'supplier_name' => '',
  1127. 'start_date' => '',
  1128. 'end_date' => ''
  1129. ], 'post', 'trim');
  1130. $val_params = Validate::rule([
  1131. 'start_date' => 'date|elt:end_date',
  1132. 'end_date' => 'date'
  1133. ]);
  1134. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1135. $where = [['s.is_del', '=', 0], ['gp.exam_status', '=', 6]]; //exam_status==6 上线成功
  1136. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.online_time', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1137. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1138. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1139. $list = Db::name('good_platform')
  1140. ->alias('gp')
  1141. ->field('gb.creater 采购维护人,"" 采购维护人所属部门,gp.skuCode 商品上线编号,gp.spuCode 商品成本编号,gb.good_name 商品名称,b.brand_name 品牌名称,"" 商品型号,s.name 供应商名称,gb.tax 税点,gb.nake_price 成本价合计,gp.online_time 上线时间,gb.createrid')
  1142. ->where($where)
  1143. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1144. ->leftJoin('brand b', 'b.id=gb.brand_id')
  1145. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1146. ->order('gp.updatetime desc')
  1147. ->cursor();
  1148. $data = [];
  1149. foreach ($list as $value) {
  1150. $value['采购维护人所属部门'] = get_company_name_by_uid($value['createrid']);;
  1151. $value['商品型号'] = Db::name('good_spec')
  1152. ->alias('gp')
  1153. ->field('')
  1154. ->leftJoin('specs s', 's.id=gp.spec_id')
  1155. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  1156. ->where([
  1157. 'gp.spuCode' => $value['商品成本编号'],
  1158. 'gp.is_del' => 0,
  1159. 's.spec_name' => '型号',
  1160. ])
  1161. ->value('sv.spec_value', '');
  1162. unset($value['createrid']);
  1163. $data[] = $value;
  1164. }
  1165. if (empty($data)) $data[] = '没有可供导出的数据';
  1166. $headerArr = array_keys($data[0]);
  1167. excelSave('商品上线报表' . date('YmdHis'), $headerArr, $data);
  1168. }
  1169. //【七、商品报表】2.商品下线报表_列表
  1170. public function GoodOfflineList()
  1171. {
  1172. $param = $this->request->only([
  1173. 'token',
  1174. 'creater' => '',
  1175. 'supplier_name' => '',
  1176. 'start_date' => '',
  1177. 'end_date' => '',
  1178. 'page' => 1,
  1179. 'size' => 15,
  1180. ], 'post', 'trim');
  1181. $val_params = Validate::rule([
  1182. 'start_date' => 'date|elt:end_date',
  1183. 'end_date' => 'date'
  1184. ]);
  1185. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1186. $where = [['s.is_del', '=', 0], ['gp.exam_status', '=', 8]]; //exam_status==8 下线成功
  1187. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.updatetime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1188. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1189. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1190. $count = Db::name('good_platform')
  1191. ->alias('gp')
  1192. ->where($where)
  1193. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1194. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1195. ->count('gp.id');
  1196. $list = Db::name('good_platform')
  1197. ->alias('gp')
  1198. ->field('gp.updatetime,gb.createrid,gb.creater,"" company_name,gb.creater,gp.skuCode,gp.spuCode,gb.good_name,s.name')
  1199. ->where($where)
  1200. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1201. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1202. ->withAttr('company_name', function ($val, $data) {
  1203. return get_company_name_by_uid($data['createrid']);
  1204. })
  1205. ->page($param['page'], $param['size'])
  1206. ->select()
  1207. ->toArray();
  1208. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1209. }
  1210. //【七、商品报表】2.商品下线报表_导出
  1211. public function GoodOfflineExport()
  1212. {
  1213. $param = $this->request->only([
  1214. 'token',
  1215. 'creater' => '',
  1216. 'supplier_name' => '',
  1217. 'start_date' => '',
  1218. 'end_date' => ''
  1219. ], 'post', 'trim');
  1220. $val_params = Validate::rule([
  1221. 'start_date' => 'date|elt:end_date',
  1222. 'end_date' => 'date'
  1223. ]);
  1224. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1225. $where = [['s.is_del', '=', 0], ['gp.exam_status', '=', 8]]; //exam_status==8 下线成功
  1226. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.updatetime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1227. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1228. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1229. $list = Db::name('good_platform')
  1230. ->alias('gp')
  1231. ->field('gp.updatetime 商品下线时间,gb.creater 采购维护人,"" 采购维护人所属部门,gp.skuCode 商品上线编号,gp.spuCode 商品成本编号,gb.good_name 商品名称,s.name 供应商名称,gb.createrid')
  1232. ->where($where)
  1233. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1234. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1235. ->cursor();
  1236. $data = [];
  1237. foreach ($list as $value) {
  1238. $value['采购维护人所属部门'] = get_company_name_by_uid($value['createrid']);
  1239. unset($value['createrid']);
  1240. $data[] = $value;
  1241. }
  1242. if (empty($data)) $data[] = '没有可供导出的数据';
  1243. $headerArr = array_keys($data[0]);
  1244. excelSave('商品下线报表' . date('YmdHis'), $headerArr, $data);
  1245. }
  1246. //【七、商品报表】3.商品修改报表_列表
  1247. public function ChangeLogList()
  1248. {
  1249. $param = $this->request->only([
  1250. 'token',
  1251. 'creater' => '',
  1252. 'supplier_name' => '',
  1253. 'start_date' => '',
  1254. 'end_date' => '',
  1255. 'page' => 1,
  1256. 'size' => 15,
  1257. ], 'post', 'trim');
  1258. $val_params = Validate::rule([
  1259. 'start_date' => 'date|elt:end_date',
  1260. 'end_date' => 'date'
  1261. ]);
  1262. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1263. $where = [['cl.type', '=', 3]]; //type==3 商品成本变化记录
  1264. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['cl.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1265. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1266. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1267. $count = Db::name('change_log')
  1268. ->alias('cl')
  1269. ->leftJoin('good_basic gb', 'gb.spuCode=cl.code AND gb.is_del=0')
  1270. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1271. ->where($where)
  1272. ->count('cl.id');
  1273. $data = Db::name('change_log')
  1274. ->alias('cl')
  1275. ->field('cl.addtime,gb.createrid,gb.creater,"" company_name,cl.code,gb.good_name,s.name,cl.before_info,cl.after_info')
  1276. ->leftJoin('good_basic gb', 'gb.spuCode=cl.code AND gb.is_del=0')
  1277. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1278. ->where($where)
  1279. ->order('cl.addtime', 'desc')
  1280. ->page($param['page'], $param['size'])
  1281. ->cursor();
  1282. $list = [];
  1283. foreach ($data as $value) {
  1284. $before_info = json_decode($value['before_info'], true);
  1285. $after_info = json_decode($value['after_info'], true);
  1286. if (isset($after_info['field_change'])) unset($after_info['field_change']);
  1287. $value['before_info'] = [];
  1288. foreach ($after_info as $kk => $vv) {
  1289. //特殊字段处理
  1290. switch ($kk) {
  1291. //品牌
  1292. case 'brand_id':
  1293. $all_brand = Db::name('brand')
  1294. ->whereIn('id', [$before_info[$kk], $vv])
  1295. ->where('is_del', 0)
  1296. ->column('brand_name', 'id');
  1297. $value['before_info'][$kk] = isset($all_brand[$before_info[$kk]]) ? $all_brand[$before_info[$kk]] : '';
  1298. $after_info[$kk] = isset($all_brand[$vv]) ? $all_brand[$vv] : '';
  1299. break;
  1300. //分类
  1301. case 'cat_id':
  1302. $value['before_info'][$kk] = implode('/', array_column(made($before_info[$kk]), 'name'));
  1303. $after_info[$kk] = implode('/', array_column(made($vv), 'name'));
  1304. break;
  1305. //发货地
  1306. case 'delivery_place':
  1307. $delivery_place = explode(',', $before_info[$kk]);
  1308. $value['before_info'][$kk] = empty($delivery_place) ? $before_info[$kk] : GetAddr(json_encode(['provice_code' => $delivery_place[0] ?? '', 'city_code' => $delivery_place[1] ?? '', 'area_code' => $delivery_place[2] ?? '']));
  1309. $delivery_place_2 = explode(',', $vv);
  1310. $after_info[$kk] = empty($delivery_place_2) ? $vv : GetAddr(json_encode(['provice_code' => $delivery_place_2[0] ?? '', 'city_code' => $delivery_place_2[1] ?? '', 'area_code' => $delivery_place_2[2] ?? '']));
  1311. break;
  1312. //产地
  1313. case 'origin_place':
  1314. $origin_place = explode(',', $before_info[$kk]);
  1315. $value['before_info'][$kk] = empty($origin_place) ? $before_info[$kk] : GetAddr(json_encode(['provice_code' => $origin_place[0] ?? '', 'city_code' => $origin_place[1] ?? '', 'area_code' => $origin_place[2] ?? '']));
  1316. $origin_place_2 = explode(',', $vv);
  1317. $after_info[$kk] = empty($vv) ? $vv : GetAddr(json_encode(['provice_code' => $origin_place_2[0] ?? '', 'city_code' => $origin_place_2[1] ?? '', 'area_code' => $origin_place_2[2] ?? '']));
  1318. break;
  1319. //商品单位
  1320. case 'good_unit':
  1321. $all_unit = Db::name('unit')
  1322. ->whereIn('id', [$before_info[$kk], $vv])
  1323. ->where(['is_del' => 0])
  1324. ->column('unit', 'id');
  1325. $value['before_info'][$kk] = isset($all_unit[$before_info[$kk]]) ? $all_unit[$before_info[$kk]] : '';
  1326. $after_info[$kk] = isset($all_unit[$vv]) ? $all_unit[$vv] : '';
  1327. break;
  1328. //业务企业
  1329. case 'companyNo':
  1330. $all_business = Db::name('business')
  1331. ->whereIn('companyNo', [$before_info[$kk], $vv])
  1332. ->where(['is_del' => 0])
  1333. ->column('company', 'companyNo');
  1334. $value['before_info'][$kk] = isset($all_business[$before_info[$kk]]) ? $all_business[$before_info[$kk]] : '';
  1335. $after_info[$kk] = isset($all_business[$vv]) ? $all_business[$vv] : '';
  1336. break;
  1337. //供应商
  1338. case 'supplierNo':
  1339. $all_supplier = Db::name('supplier')
  1340. ->whereIn('code', [$before_info[$kk], $vv])
  1341. ->where(['is_del' => 0])
  1342. ->column('name', 'code');
  1343. $value['before_info'][$kk] = isset($all_supplier[$before_info[$kk]]) ? $all_supplier[$before_info[$kk]] : '';
  1344. $after_info[$kk] = isset($all_supplier[$vv]) ? $all_supplier[$vv] : '';
  1345. break;
  1346. //供货区域
  1347. case 'supply_area':
  1348. if ($before_info[$kk] == 1) $value['before_info'][$kk] = '全国';
  1349. elseif ($before_info[$kk] == 2) $value['before_info'][$kk] = '全国除偏远';
  1350. else $value['before_info'][$kk] = '';
  1351. if ($vv == 1) $after_info[$kk] = '全国';
  1352. elseif ($vv == 2) $after_info[$kk] = '全国除偏远';
  1353. else $after_info[$kk] = '';
  1354. break;
  1355. //贵金属种类
  1356. case 'noble_metal':
  1357. if ($before_info[$kk] == 1) $value['before_info'][$kk] = '18K';
  1358. elseif ($before_info[$kk] == 2) $value['before_info'][$kk] = '24K';
  1359. elseif ($before_info[$kk] == 3) $value['before_info'][$kk] = '白银';
  1360. else $value['before_info'][$kk] = '';
  1361. if ($vv == 1) $after_info[$kk] = '18K';
  1362. elseif ($vv == 2) $after_info[$kk] = '24K';
  1363. elseif ($vv == 3) $after_info[$kk] = '白银';
  1364. else $after_info[$kk] = '';
  1365. break;
  1366. //专属类型
  1367. case 'is_exclusive':
  1368. $value['before_info'][$kk] = implode('/', array_column(mai($before_info[$kk]), 'rname'));
  1369. $after_info[$kk] = implode('/', array_column(mai($vv), 'rname'));
  1370. break;
  1371. default:
  1372. $value['before_info'][$kk] = $before_info[$kk];
  1373. break;
  1374. }
  1375. }
  1376. $value['after_info'] = $after_info;
  1377. $value['company_name'] = get_company_name_by_uid($value['createrid']);
  1378. $list[] = $value;
  1379. }
  1380. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1381. }
  1382. //【七、商品报表】3.商品修改报表_导出
  1383. public function ChangeLogExport()
  1384. {
  1385. $param = $this->request->only([
  1386. 'token',
  1387. 'creater' => '',
  1388. 'supplier_name' => '',
  1389. 'start_date' => '',
  1390. 'end_date' => ''
  1391. ], 'post', 'trim');
  1392. $val_params = Validate::rule([
  1393. 'start_date' => 'date|elt:end_date',
  1394. 'end_date' => 'date'
  1395. ]);
  1396. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1397. $where = [['cl.type', '=', 3]]; //type==3 商品成本变化记录
  1398. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['cl.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1399. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1400. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1401. $data = Db::name('change_log')
  1402. ->alias('cl')
  1403. ->field('cl.addtime 商品操作时间,gb.creater 采购维护人,"" 采购维护人所在部门,cl.code 商品成本编号,gb.good_name 商品名称,s.name 供应商名称,cl.before_info 修改前的内容,cl.after_info 修改后的内容,gb.createrid')
  1404. ->leftJoin('good_basic gb', 'gb.spuCode=cl.code AND gb.is_del=0')
  1405. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1406. ->where($where)
  1407. ->cursor();
  1408. $list = [];
  1409. foreach ($data as $value) {
  1410. $before_info = json_decode($value['修改前的内容'], true);
  1411. $after_info = json_decode($value['修改后的内容'], true);
  1412. if (isset($after_info['field_change'])) {
  1413. $field_change = json_decode($after_info['field_change'], true);
  1414. $before_new = $after_new = [];
  1415. foreach ($field_change as $v) {
  1416. //特殊字段处理
  1417. switch ($v) {
  1418. //品牌
  1419. case 'brand_id':
  1420. $all_brand = Db::name('brand')
  1421. ->whereIn('id', [$before_info[$v] ?? 0, $after_info[$v] ?? 0])
  1422. ->where('is_del', 0)
  1423. ->column('brand_name', 'id');
  1424. if (isset($before_info[$v])) $before_info[$v] = isset($all_brand[$before_info[$v]]) ? $all_brand[$before_info[$v]] : '';
  1425. if (isset($after_info[$v])) $after_info[$v] = isset($all_brand[$after_info[$v]]) ? $all_brand[$after_info[$v]] : '';
  1426. break;
  1427. //分类
  1428. case 'cat_id':
  1429. if (isset($before_info[$v])) $before_info[$v] = implode('/', array_column(made($before_info[$v]), 'name'));
  1430. if (isset($after_info[$v])) $after_info[$v] = implode('/', array_column(made($after_info[$v]), 'name'));
  1431. break;
  1432. //发货地
  1433. case 'delivery_place':
  1434. $delivery_place = explode(',', $before_info[$v]);
  1435. $before_info[$v] = empty($delivery_place) ? $before_info[$v] : GetAddr(json_encode(['provice_code' => $delivery_place[0] ?? '', 'city_code' => $delivery_place[1] ?? '', 'area_code' => $delivery_place[2] ?? '']));
  1436. $delivery_place_2 = explode(',', $after_info[$v]);
  1437. $after_info[$v] = empty($delivery_place_2) ? $after_info[$v] : GetAddr(json_encode(['provice_code' => $delivery_place_2[0] ?? '', 'city_code' => $delivery_place_2[1] ?? '', 'area_code' => $delivery_place_2[2] ?? '']));
  1438. break;
  1439. //产地
  1440. case 'origin_place':
  1441. $origin_place = explode(',', $before_info[$v]);
  1442. $before_info[$v] = empty($origin_place) ? $before_info[$v] : GetAddr(json_encode(['provice_code' => $origin_place[0] ?? '', 'city_code' => $origin_place[1] ?? '', 'area_code' => $origin_place[2] ?? '']));
  1443. $origin_place_2 = explode(',', $after_info[$v]);
  1444. $after_info[$v] = empty($origin_place_2) ? $after_info[$v] : GetAddr(json_encode(['provice_code' => $origin_place_2[0] ?? '', 'city_code' => $origin_place_2[1] ?? '', 'area_code' => $origin_place_2[2] ?? '']));
  1445. break;
  1446. //商品单位
  1447. case 'good_unit':
  1448. $all_unit = Db::name('unit')
  1449. ->whereIn('id', [$before_info[$v] ?? 0, $after_info[$v] ?? 0])
  1450. ->where(['is_del' => 0])
  1451. ->column('unit', 'id');
  1452. if (isset($before_info[$v])) $before_info[$v] = isset($all_unit[$before_info[$v]]) ? $all_unit[$before_info[$v]] : '';
  1453. if (isset($after_info[$v])) $after_info[$v] = isset($all_unit[$after_info[$v]]) ? $all_unit[$after_info[$v]] : '';
  1454. break;
  1455. //业务企业
  1456. case 'companyNo':
  1457. $all_business = Db::name('business')
  1458. ->whereIn('companyNo', [$before_info[$v] ?? '', $after_info[$v] ?? ''])
  1459. ->where(['is_del' => 0])
  1460. ->column('company', 'companyNo');
  1461. if (isset($before_info[$v])) $before_info[$v] = isset($all_business[$before_info[$v]]) ? $all_business[$before_info[$v]] : '';
  1462. if (isset($after_info[$v])) $after_info[$v] = isset($all_business[$after_info[$v]]) ? $all_business[$after_info[$v]] : '';
  1463. break;
  1464. //供应商
  1465. case 'supplierNo':
  1466. $all_supplier = Db::name('supplier')
  1467. ->whereIn('code', [$before_info[$v], $after_info[$v]])
  1468. ->where(['is_del' => 0])
  1469. ->column('name', 'code');
  1470. $before_info[$v] = isset($all_supplier[$before_info[$v]]) ? $all_supplier[$before_info[$v]] : '';
  1471. $after_info[$v] = isset($all_supplier[$after_info[$v]]) ? $all_supplier[$after_info[$v]] : '';
  1472. break;
  1473. //供货区域
  1474. case 'supply_area':
  1475. if (isset($before_info[$v])) {
  1476. if ($before_info[$v] == 1) $before_info[$v] = '全国';
  1477. elseif ($before_info[$v] == 2) $before_info[$v] = '全国除偏远';
  1478. else $before_info[$v] = '';
  1479. }
  1480. if (isset($after_info[$v])) {
  1481. if ($after_info[$v] == 1) $after_info[$v] = '全国';
  1482. elseif ($after_info[$v] == 2) $after_info[$v] = '全国除偏远';
  1483. else $after_info[$v] = '';
  1484. }
  1485. break;
  1486. //贵金属种类
  1487. case 'noble_metal':
  1488. if (isset($before_info[$v])) {
  1489. if ($before_info[$v] == 1) $before_info[$v] = '18K';
  1490. elseif ($before_info[$v] == 2) $before_info[$v] = '24K';
  1491. elseif ($before_info[$v] == 3) $before_info[$v] = '白银';
  1492. else $before_info[$v] = '';
  1493. }
  1494. if (isset($after_info[$v])) {
  1495. if ($after_info[$v] == 1) $after_info[$v] = '18K';
  1496. elseif ($after_info[$v] == 2) $after_info[$v] = '24K';
  1497. elseif ($after_info[$v] == 3) $after_info[$v] = '白银';
  1498. else $after_info[$v] = '';
  1499. }
  1500. break;
  1501. //专属类型
  1502. case 'is_exclusive':
  1503. if (isset($before_info[$v])) $before_info[$v] = implode('/', array_column(mai($before_info[$v]), 'rname'));
  1504. if (isset($after_info[$v])) $after_info[$v] = implode('/', array_column(mai($after_info[$v]), 'rname'));
  1505. break;
  1506. //状态
  1507. case 'status':
  1508. $all_status = [1 => '待完善成本', 2 => '待产品审核', 3 => '待财务定价', 4 => '待财务审核定价', 5 => '待上线', 6 => '上线成功', 7 => '审核失败', 8 => '已下线'];
  1509. if (isset($before_info[$v])) $before_info[$v] = isset($all_status[$before_info[$v]]) ? $all_status[$before_info[$v]] : '';
  1510. if (isset($after_info[$v])) $after_info[$v] = isset($all_status[$after_info[$v]]) ? $all_status[$after_info[$v]] : '';
  1511. }
  1512. $key = isset($this->good_field_title[$v]) ? $this->good_field_title[$v] : $v;
  1513. if (isset($before_info[$v])) $before_new[$key] = $before_info[$v];
  1514. if (isset($after_info[$v])) $after_new[$key] = $after_info[$v];
  1515. }
  1516. $value['修改前的内容'] = json_encode($before_new, JSON_UNESCAPED_UNICODE);
  1517. $value['修改后的内容'] = json_encode($after_new, JSON_UNESCAPED_UNICODE);
  1518. $value['采购维护人所在部门'] = get_company_name_by_uid($value['createrid']);
  1519. unset($value['createrid']);
  1520. }
  1521. $list[] = $value;
  1522. }
  1523. if (empty($list)) $list[] = '没有可供导出的数据';
  1524. $headerArr = array_keys($list[0]);
  1525. excelSave('商品修改报表' . date('YmdHis'), $headerArr, $list);
  1526. }
  1527. //【八、结算报表】_列表(暂不做)
  1528. //【八、结算报表】_导出(暂不做)
  1529. //【九、出入库明细报表】_列表
  1530. public function GoodLogList()
  1531. {
  1532. /**
  1533. * $param = $this->request->only([
  1534. * 'token',
  1535. * 'creater' => '',
  1536. * 'supplier_name' => '',
  1537. * 'start_date' => '',
  1538. * 'end_date' => '',
  1539. * 'page' => 1,
  1540. * 'size' => 15
  1541. * ], 'post', 'trim');
  1542. * **/
  1543. }
  1544. //【九、出入库明细报表】_导出
  1545. public function GoodLogExport()
  1546. {
  1547. /**
  1548. * $param = $this->request->only([
  1549. * 'token',
  1550. * // 'creater' => '',
  1551. * // 'supplier_name' => '',
  1552. * // 'start_date' => '',
  1553. * // 'end_date' => ''
  1554. * ], 'post', 'trim');
  1555. *
  1556. * $val_params = Validate::rule([
  1557. * 'start_date' => 'date|elt:end_date',
  1558. * 'end_date' => 'date'
  1559. * ]);
  1560. *
  1561. * if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1562. *
  1563. * // $where = [['gl.action_type', '=', 'CGD']];
  1564. * // if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.updatetime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1565. * // if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1566. * // if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1567. *
  1568. *
  1569. * $list = Db::name('good_log')
  1570. * ->alias('gl')
  1571. * ->field('"" 创建人,"" 创建人公司,"" 创建人部门,"" 创建时间,"" 单据状态,"" 采购单号,gl.type 出入库类型,gb.good_name 商品名称,gb.spuCode 产品编码,gl.stock 出入库数量,gl.addtime 出入库日期,"" 维护人员,"" 发起人,wi.wsm_type 库房性质,s.name 库房公司,wi.name 库房名称')
  1572. * // ->where($where)
  1573. * ->leftJoin('good_stock gs', 'gs.id=gl.stock_id')
  1574. * ->leftJoin('good_basic gb', 'gb.spuCode=gs.spuCode AND gb.is_del=0')
  1575. * ->leftJoin('warehouse_info wi', 'wi.wsm_code=gs.wsm_code')
  1576. * ->leftJoin('supplier s', 's.code=wi.supplierNo')
  1577. * // ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1578. * ->select()
  1579. * ->toArray();
  1580. * halt($list);
  1581. * if (empty($list)) $list[] = '没有可供导出的数据';
  1582. *
  1583. * $headerArr = array_keys($list[0]);
  1584. * excelSave('出入库明细报表' . date('YmdHis'), $headerArr, $list);
  1585. **/
  1586. }
  1587. //【商品信息】基本信息(赵丹要的)_列表
  1588. public function goodSimpleZhao()
  1589. {
  1590. $param = $this->request->only([
  1591. 'token',
  1592. 'creater' => '',
  1593. 'supplier_name' => '',
  1594. 'start_date' => '',
  1595. 'end_date' => '',
  1596. 'page' => 1,
  1597. 'size' => 15
  1598. ], 'post', 'trim');
  1599. $val_params = Validate::rule([
  1600. 'start_date' => 'date|elt:end_date',
  1601. 'end_date' => 'date'
  1602. ]);
  1603. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1604. $where = [['s.is_del', '=', 0]];
  1605. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1606. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1607. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1608. $count = Db::name('good_platform')
  1609. ->alias('gp')
  1610. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1611. ->leftJoin('brand b', 'b.id=gb.brand_id')
  1612. ->leftJoin('unit u', 'u.id=gb.good_unit')
  1613. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1614. ->leftJoin('platform p', 'p.id=gp.platform_code')
  1615. ->where($where)
  1616. ->count('gp.id');
  1617. $list = Db::name('good_platform')
  1618. ->alias('gp')
  1619. ->field('gp.skuCode,gp.spuCode,gp.plat_code,gb.good_name,b.brand_name,gb.cat_id,bi.company,gb.creater,p.platform_name,gp.online_time,gp.exam_status,gb.is_stock,gb.good_type,u.unit,gb.good_remark,gb.craft_desc,gb.noble_metal,gb.cgd_gold_price,gb.demo_fee,gb.open_fee,gb.sample_fee,gb.tax,gb.supply_area,s.name,gp.addtime')
  1620. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1621. ->leftJoin('brand b', 'b.id=gb.brand_id')
  1622. ->leftJoin('unit u', 'u.id=gb.good_unit')
  1623. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1624. ->leftJoin('platform p', 'p.id=gp.platform_code')
  1625. ->leftJoin('business bi', 'bi.companyNo=gb.companyNo')
  1626. ->where($where)
  1627. ->order('gp.id', 'desc')
  1628. ->page($param['page'], $param['size'])
  1629. ->cursor();
  1630. $exam_status = [0 => '待提交', 1 => '待完善成本', 2 => '待产品审核', 3 => '待财务定价', 4 => '待财务审核定价', 5 => '待上线', 6 => '上线成功', 7 => '审核失败', 8 => '已下线'];
  1631. $is_stock = [0 => '不是', 1 => '是'];
  1632. $good_type = [0 => '不是', 1 => '是'];
  1633. $noble_metal = [1 => '18K', 2 => '24K', 3 => '白银'];
  1634. $supply_area = [1 => '全国', 2 => '全国除偏远'];
  1635. $data = [];
  1636. foreach ($list as $value) {
  1637. $value['catinfo'] = made($value['cat_id']);
  1638. $value['exam_status'] = isset($exam_status[$value['exam_status']]) ? $exam_status[$value['exam_status']] : '';
  1639. $value['is_stock'] = isset($is_stock[$value['is_stock']]) ? $is_stock[$value['is_stock']] : '';
  1640. $value['good_type'] = isset($good_type[$value['good_type']]) ? $good_type[$value['good_type']] : '';
  1641. $value['specifications'] = Db::name('good_spec')
  1642. ->alias('gp')
  1643. ->leftJoin('specs s', 's.id=gp.spec_id')
  1644. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  1645. ->where([
  1646. 'gp.spuCode' => $value['spuCode'],
  1647. 'gp.is_del' => 0,
  1648. 's.spec_name' => '规格',
  1649. ])->value('sv.spec_value', '');
  1650. $value['model'] = Db::name('good_spec')
  1651. ->alias('gp')
  1652. ->leftJoin('specs s', 's.id=gp.spec_id')
  1653. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  1654. ->where([
  1655. 'gp.spuCode' => $value['spuCode'],
  1656. 'gp.is_del' => 0,
  1657. 's.spec_name' => '型号',
  1658. ])->value('sv.spec_value', '');
  1659. $value['noble_metal'] = isset($noble_metal[$value['noble_metal']]) ? $noble_metal[$value['noble_metal']] : '';
  1660. $value['supply_area'] = isset($supply_area[$value['supply_area']]) ? $supply_area[$value['supply_area']] : '';
  1661. $data[] = $value;
  1662. }
  1663. return app_show(0, '请求成功', ['list' => $data, 'count' => $count]);
  1664. }
  1665. //【商品信息】基本信息(赵丹要的)_导出
  1666. public function goodSimpleZhaoExport()
  1667. {
  1668. $param = $this->request->only([
  1669. 'token',
  1670. 'creater' => '',
  1671. 'supplier_name' => '',
  1672. 'start_date' => '',
  1673. 'end_date' => ''
  1674. ], 'post', 'trim');
  1675. $val_params = Validate::rule([
  1676. 'start_date' => 'date|elt:end_date',
  1677. 'end_date' => 'date'
  1678. ]);
  1679. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1680. $where = [['s.is_del', '=', 0]]; //exam_status==6 上线成功
  1681. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1682. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1683. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1684. $list = Db::name('good_platform')
  1685. ->alias('gp')
  1686. ->field('gp.skuCode as 商品上线编号,gp.spuCode as 商品成本编号,gp.plat_code as 平台商品编码,gb.good_name as 商品名称,b.brand_name as 品牌名称,gb.cat_id as 分类,bi.company as 业务企业名称,gb.creater as 采购员,p.platform_name as 上线平台,gp.online_time as 上线完成时间,gp.exam_status as 上下线状态,gb.is_stock as 是否库存品,gb.good_type as 是否定制,"" as 规格,"" as 型号,u.unit as 单位,gb.good_remark as 商品备注,gb.craft_desc as 工艺说明,gb.noble_metal as 贵金属信息,gb.cgd_gold_price as 供应商采购金价,gb.demo_fee as 打样费,gb.open_fee as 开模费,gb.sample_fee as 调样费,gb.tax as 税点,gb.supply_area as 供货区域,s.name as 供应商名称,gp.addtime 申请上线时间')
  1687. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1688. ->leftJoin('brand b', 'b.id=gb.brand_id')
  1689. ->leftJoin('unit u', 'u.id=gb.good_unit')
  1690. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1691. ->leftJoin('platform p', 'p.id=gp.platform_code')
  1692. ->leftJoin('business bi', 'bi.companyNo=gb.companyNo')
  1693. ->where($where)
  1694. ->order('gp.id', 'desc')
  1695. ->cursor();
  1696. $exam_status = [0 => '待提交', 1 => '待完善成本', 2 => '待产品审核', 3 => '待财务定价', 4 => '待财务审核定价', 5 => '待上线', 6 => '上线成功', 7 => '审核失败', 8 => '已下线'];
  1697. $is_stock = [0 => '不是', 1 => '是'];
  1698. $good_type = [0 => '不是', 1 => '是'];
  1699. $noble_metal = [1 => '18K', 2 => '24K', 3 => '白银'];
  1700. $supply_area = [1 => '全国', 2 => '全国除偏远'];
  1701. $data = [];
  1702. foreach ($list as $value) {
  1703. $value['分类'] = implode('/', array_column(made($value['分类']), 'name'));
  1704. $value['上下线状态'] = isset($exam_status[$value['上下线状态']]) ? $exam_status[$value['上下线状态']] : '';
  1705. $value['是否库存品'] = isset($is_stock[$value['是否库存品']]) ? $is_stock[$value['是否库存品']] : '';
  1706. $value['是否定制'] = isset($good_type[$value['是否定制']]) ? $good_type[$value['是否定制']] : '';
  1707. $value['规格'] = Db::name('good_spec')
  1708. ->alias('gp')
  1709. ->leftJoin('specs s', 's.id=gp.spec_id')
  1710. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  1711. ->where([
  1712. 'gp.spuCode' => $value['商品成本编号'],
  1713. 'gp.is_del' => 0,
  1714. 's.spec_name' => '规格',
  1715. ])->value('sv.spec_value', '');
  1716. $value['型号'] = Db::name('good_spec')
  1717. ->alias('gp')
  1718. ->leftJoin('specs s', 's.id=gp.spec_id')
  1719. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  1720. ->where([
  1721. 'gp.spuCode' => $value['商品成本编号'],
  1722. 'gp.is_del' => 0,
  1723. 's.spec_name' => '型号',
  1724. ])->value('sv.spec_value', '');
  1725. $value['贵金属信息'] = isset($noble_metal[$value['贵金属信息']]) ? $noble_metal[$value['贵金属信息']] : '';
  1726. $value['供货区域'] = isset($supply_area[$value['供货区域']]) ? $supply_area[$value['供货区域']] : '';
  1727. $data[] = $value;
  1728. }
  1729. if (empty($data)) $data[] = '没有可供导出的数据';
  1730. $headerArr = array_keys($data[0]);
  1731. excelSave('商品信息导出表(基本信息)' . date('YmdHis'), $headerArr, $data);
  1732. }
  1733. //【商品信息】成本(赵丹要的)_列表
  1734. public function goodCostZhao()
  1735. {
  1736. $param = $this->request->only([
  1737. 'token',
  1738. 'start_date' => '',
  1739. 'end_date' => '',
  1740. 'spuCode' => '',
  1741. 'page' => 1,
  1742. 'size' => 15
  1743. ], 'post', 'trim');
  1744. $val_params = Validate::rule([
  1745. 'start_date' => 'date|elt:end_date',
  1746. 'end_date' => 'date'
  1747. ]);
  1748. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1749. $where = [];
  1750. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1751. if ($param['spuCode'] != '') $where[] = ['gp.spuCode', 'like', '%' . $param['spuCode'] . '%'];
  1752. $count = Db::name('good_platform')
  1753. ->alias('gp')
  1754. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1755. ->leftJoin('platform p', 'p.id=gp.platform_code')
  1756. ->leftJoin('good_nake gn', 'gn.spuCode=gb.spuCode')
  1757. ->leftJoin('good_ladder c', 'c.skuCode=gp.skuCode AND c.is_del=0')
  1758. ->where($where)
  1759. ->count('gp.id');
  1760. $data = Db::name('good_platform')
  1761. ->alias('gp')
  1762. ->field('gp.skuCode,gp.spuCode,gp.plat_code,gb.good_name,p.platform_name,gp.online_time,c.min_num moq,gn.nake_fee,gb.cost_fee,gn.delivery_fee,gb.cert_fee,gb.mark_fee,gb.packing_fee,gn.other_fee,gn.nake_total,gp.addtime')
  1763. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1764. ->leftJoin('platform p', 'p.id=gp.platform_code')
  1765. ->leftJoin('good_nake gn', 'gn.spuCode=gb.spuCode')
  1766. ->leftJoin('good_ladder c', 'c.skuCode=gp.skuCode AND c.is_del=0')//加入c.is_del可以命中索引
  1767. ->where($where)
  1768. ->order('gp.id', 'desc')
  1769. ->page($param['page'], $param['size'])
  1770. ->select()
  1771. ->toArray();
  1772. return app_show(0, '请求成功', ['list' => $data, 'count' => $count]);
  1773. }
  1774. //【商品信息】成本(赵丹要的)_导出
  1775. public function goodCostZhaoExport()
  1776. {
  1777. $param = $this->request->only([
  1778. 'token',
  1779. 'start_date' => '',
  1780. 'end_date' => '',
  1781. 'spuCode' => '',
  1782. ], 'post', 'trim');
  1783. $val_params = Validate::rule([
  1784. 'start_date' => 'date|elt:end_date',
  1785. 'end_date' => 'date'
  1786. ]);
  1787. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1788. $where = [];
  1789. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1790. if ($param['spuCode'] != '') $where[] = ['gp.spuCode', 'like', '%' . $param['spuCode'] . '%'];
  1791. $data = Db::name('good_platform')
  1792. ->alias('gp')
  1793. ->field('gp.skuCode as 商品上线编号,gp.spuCode as 商品成本编号,gp.plat_code as 平台商品编码,gb.good_name as 商品名称,p.platform_name as 上线平台,gp.online_time as 上线完成时间,c.min_num 起订量,gn.nake_fee 成本单价,gb.cost_fee 工艺费,gn.delivery_fee 物流费,gb.cert_fee 证书费,gb.mark_fee 加标费,gb.packing_fee 包装费,gn.other_fee 其他费用,gn.nake_total 成本合计,gp.addtime 申请上线时间')
  1794. ->where($where)
  1795. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1796. ->leftJoin('platform p', 'p.id=gp.platform_code')
  1797. ->leftJoin('good_nake gn', 'gn.spuCode=gb.spuCode')
  1798. ->leftJoin('good_ladder c', 'c.skuCode=gp.skuCode AND c.is_del=0')
  1799. ->order('gp.id', 'desc')
  1800. ->select()
  1801. ->toArray();
  1802. if (empty($data)) $data[] = '没有可供导出的数据';
  1803. $headerArr = array_keys($data[0]);
  1804. excelSave('商品信息导出表(成本)' . date('YmdHis'), $headerArr, $data);
  1805. }
  1806. //【商品信息】售价(赵丹要的)_列表
  1807. public function goodPriceZhao()
  1808. {
  1809. $param = $this->request->only([
  1810. 'token',
  1811. 'start_date' => '',
  1812. 'end_date' => '',
  1813. 'spuCode' => '',
  1814. 'page' => 1,
  1815. 'size' => 15
  1816. ], 'post', 'trim');
  1817. $val_params = Validate::rule([
  1818. 'start_date' => 'date|elt:end_date',
  1819. 'end_date' => 'date'
  1820. ]);
  1821. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1822. $where = [];
  1823. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1824. if ($param['spuCode'] != '') $where[] = ['gp.spuCode', 'like', '%' . $param['spuCode'] . '%'];
  1825. $count = Db::name('good_platform')
  1826. ->alias('gp')
  1827. ->where($where)
  1828. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1829. ->leftJoin('platform p', 'p.id=gp.platform_code')
  1830. ->leftJoin('good_ladder gl', 'gl.skuCode=gp.skuCode')
  1831. ->count('gp.id');
  1832. $data = Db::name('good_platform')
  1833. ->alias('gp')
  1834. ->field('gp.skuCode,gp.spuCode,gp.plat_code,gb.good_name,p.platform_name,gp.online_time,gl.min_num moq,gl.sale_price,gl.cost_fee,gl.market_price,gl.market_platform,gp.addtime')
  1835. ->where($where)
  1836. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1837. ->leftJoin('platform p', 'p.id=gp.platform_code')
  1838. ->leftJoin('good_ladder gl', 'gl.skuCode=gp.skuCode AND gl.is_del=0')//加入is_del可以命中索引
  1839. ->order('gp.id', 'desc')
  1840. ->page($param['page'], $param['size'])
  1841. ->select()
  1842. ->toArray();
  1843. return app_show(0, '请求成功', ['list' => $data, 'count' => $count]);
  1844. }
  1845. //【商品信息】售价(赵丹要的)_导出
  1846. public function goodPriceZhaoExport()
  1847. {
  1848. $param = $this->request->only([
  1849. 'token',
  1850. 'start_date' => '',
  1851. 'end_date' => '',
  1852. 'spuCode' => ''
  1853. ], 'post', 'trim');
  1854. $val_params = Validate::rule([
  1855. 'start_date' => 'date|elt:end_date',
  1856. 'end_date' => 'date'
  1857. ]);
  1858. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1859. $where = [];
  1860. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1861. if ($param['spuCode'] != '') $where[] = ['gp.spuCode', 'like', '%' . $param['spuCode'] . '%'];
  1862. $data = Db::name('good_platform')
  1863. ->alias('gp')
  1864. ->field('gp.skuCode as 商品上线编号,gp.spuCode as 商品成本编号,gp.plat_code as 平台商品编码,gb.good_name as 商品名称,p.platform_name as 上线平台,gp.online_time as 上线完成时间,gl.min_num 起订量,gl.sale_price 售价,gl.cost_fee 工艺费,gl.market_price 市场价,gl.market_platform 对比平台,gp.addtime 申请上线时间')
  1865. ->where($where)
  1866. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1867. ->leftJoin('platform p', 'p.id=gp.platform_code')
  1868. ->leftJoin('good_ladder gl', 'gl.skuCode=gp.skuCode AND gl.is_del=0')
  1869. ->order('gp.id', 'desc')
  1870. ->select()
  1871. ->toArray();
  1872. if (empty($data)) $data[] = '没有可供导出的数据';
  1873. $headerArr = array_keys($data[0]);
  1874. excelSave('商品信息导出表(售价)' . date('YmdHis'), $headerArr, $data);
  1875. }
  1876. }