ReportByRelaComNo.php 117 KB

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