Report.php 107 KB

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