Report.php 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\Db;
  4. use think\facade\Validate;
  5. //报表处理类
  6. class Report extends Base
  7. {
  8. //商品表部分字段的中英文对照
  9. private $good_field_title = [
  10. 'spuCode' => '商品成本编号',
  11. 'good_code' => '商品编码',
  12. 'good_name' => '商品名称',
  13. 'cat_id' => '分类',
  14. 'brand_id' => '品牌',
  15. 'good_unit' => '商品单位',
  16. 'good_type' => '',
  17. 'companyNo' => '业务企业',
  18. 'moq' => '起订量',
  19. 'customized' => '定制工期',
  20. 'tax' => '税点',
  21. 'supplierNo' => '供应商',
  22. 'is_auth' => '是否有销售权限',
  23. 'is_stock' => '是否库存品',
  24. 'auth_img' => '销售授权图片',
  25. 'after_sales' => '售后说明',
  26. 'craft_desc' => '工艺说明',
  27. 'good_remark' => '商品备注',
  28. 'good_size' => '商品尺寸',
  29. 'weight' => '商品重量',
  30. 'packing_way' => '包装方式',
  31. 'packing_size' => '装箱尺寸',
  32. 'packing_spec' => '装箱规格',
  33. 'packing_list' => '包装清单',
  34. 'packing_weight' => '装箱重量',
  35. 'good_bar' => '商品条形码',
  36. 'supply_area' => '供货区域',
  37. 'delivery_place' => '发货地',
  38. 'origin_place' => '产地',
  39. 'delivery_day' => '物流时间',
  40. 'lead_time' => '供货周期',
  41. 'sample_day' => '调样周期',
  42. 'sample_fee' => '调样费用',
  43. 'good_img' => '商品详情主图 ',
  44. 'good_thumb_img' => '商品缩略图',
  45. 'good_info_img' => '商品详情图',
  46. 'cert_fee' => '证书费',
  47. 'packing_fee' => '包装费',
  48. 'cost_fee' => '工艺费',
  49. 'mark_fee' => '加标费',
  50. 'demo_fee' => '打样费',
  51. 'open_fee' => '开模费',
  52. 'noble_metal' => '贵金属种类',
  53. 'noble_weight' => '贵金属重量',
  54. 'is_gold_price' => '是否使用实时金价',
  55. 'cgd_gold_price' => '供应商采购金价',
  56. 'market_price' => '市场价',
  57. 'nake_price' => '含税成本价',
  58. 'is_step' => '阶梯价是否启用',
  59. 'is_online' => '是否上线',
  60. 'status' => '状态',
  61. 'createrid' => '创建人id',
  62. 'creater' => '创建人',
  63. 'is_del' => '是否删除',
  64. 'addtime' => '创建时间',
  65. 'updatetime' => '修改时间',
  66. 'is_exclusive' => '是否专属类型',
  67. 'is_diff' => '是否有工差',
  68. 'config' => '配置',
  69. 'other_config' => '其他配置',
  70. ];
  71. //产品价格和产品导出
  72. public function exportGood()
  73. {
  74. $param = $this->request->only(['date', 'platform_id', 'status'], 'post', 'trim');
  75. $val = Validate::rule([
  76. 'date|筛选时间' => 'require|date',
  77. 'platform_id|筛选平台ID' => 'require|number|gt:0',
  78. 'status|状态' => 'require|number|in:5,6,8',
  79. ]);
  80. if (!$val->check($param)) return error_show(1004, $val->getError());
  81. $where_ladder = [['gl.is_del', '=', 0]];
  82. $where_good = [['g.is_del', '=', 0]];
  83. if (!empty($param['date'])) {
  84. $where_ladder[] = ['gp.online_time', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']];
  85. $where_good[] = ['g.addtime', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']];
  86. }
  87. if (!empty($param['platform_id'])) {
  88. $where_ladder[] = ['gp.platform_code', '=', $param['platform_id']];
  89. $where_good[] = ['gp.platform_code', '=', $param['platform_id']];
  90. }
  91. if (!empty($param['status'])) {
  92. $where_ladder[] = ['gp.exam_status', '=', $param['status']];
  93. $where_good[] = ['gp.exam_status', '=', $param['status']];
  94. }
  95. $data = [];
  96. //产品价格
  97. $rs_ladder = Db::name('good_ladder')
  98. ->alias('gl')
  99. ->field('g.good_name 商品名称,gl.market_price 市场价,g.tax 税率,gl.min_num 起订量,gl.sale_price 售价,gl.skuCode 商品编码,gl.cost_fee 工艺费,gl.market_platform 对比平台')
  100. ->where($where_ladder)
  101. ->leftJoin('good_platform gp', 'gp.skuCode=gl.skuCode')
  102. ->leftJoin('good g', 'g.spuCode=gp.spuCode')
  103. ->order('gl.id')
  104. ->select()
  105. ->toArray();
  106. if (!empty($rs_ladder)) {
  107. $data[] = [
  108. 'head' => array_keys($rs_ladder[0]),
  109. 'list' => $rs_ladder,
  110. 'filename' => '产品价格' . date('YmdHis'),
  111. ];
  112. }
  113. //产品
  114. $rs_temp_good = Db::name('good')
  115. ->alias('g')
  116. ->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.spuCode')
  117. ->where($where_good)
  118. ->leftJoin('good_platform gp', 'gp.spuCode=g.spuCode')
  119. ->order('g.id')
  120. ->select()
  121. ->toArray();
  122. $all_good_type = [0 => '非定制商品', 1 => '定制商品'];
  123. $all_brand = Db::name('brand')->whereIn('id', array_column($rs_temp_good, '商品品牌'))->where('is_del', 0)->column('brand_name', 'id');
  124. $all_cat = Db::name('cat')
  125. ->alias('c3')
  126. ->whereIn('c3.id', array_column($rs_temp_good, '三级分类'))
  127. ->where('c3.is_del', 0)
  128. ->leftJoin('cat c2', 'c2.id=c3.pid')
  129. ->leftJoin('cat c1', 'c1.id=c2.pid')
  130. ->column('c3.cat_name cat_name_3,c2.cat_name cat_name_2,c1.cat_name cat_name_1', 'c3.id');
  131. $all_unit = Db::name('unit')->whereIn('id', array_column($rs_temp_good, '计量单位'))->where('is_del', 0)->column('unit', 'id');
  132. foreach ($rs_temp_good as &$value) {
  133. $value['商品品牌'] = isset($all_brand[$value['商品品牌']]) ? $all_brand[$value['商品品牌']] : '';
  134. $value['商品类型'] = isset($all_good_type[$value['商品类型']]) ? $all_good_type[$value['商品类型']] : '';
  135. $value['一级分类'] = isset($all_cat[$value['三级分类']]['cat_name_1']) ? $all_cat[$value['三级分类']]['cat_name_1'] : '';
  136. $value['二级分类'] = isset($all_cat[$value['三级分类']]['cat_name_2']) ? $all_cat[$value['三级分类']]['cat_name_2'] : '';
  137. $value['三级分类'] = isset($all_cat[$value['三级分类']]['cat_name_3']) ? $all_cat[$value['三级分类']]['cat_name_3'] : '';
  138. $temp = explode(',', $value['产地']);
  139. $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] : '']));
  140. $value['计量单位'] = isset($all_unit[$value['计量单位']]) ? $all_unit[$value['计量单位']] : '';
  141. $temp_2 = explode(',', $value['发货地']);
  142. $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] : '']));
  143. $value['型号'] = Db::name('good_spec')
  144. ->alias('gp')
  145. ->field('')
  146. ->leftJoin('specs s', 's.id=gp.spec_id')
  147. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  148. ->where([
  149. 'gp.spuCode' => $value['spuCode'],
  150. 'gp.is_del' => 0,
  151. 's.spec_name' => '型号',
  152. ])
  153. ->value('sv.spec_value', '');
  154. $value['响应时间'] = Db::name('good_spec')
  155. ->alias('gp')
  156. ->field('')
  157. ->leftJoin('specs s', 's.id=gp.spec_id')
  158. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  159. ->where([
  160. 'gp.spuCode' => $value['spuCode'],
  161. 'gp.is_del' => 0,
  162. 's.spec_name' => '响应时间',
  163. ])
  164. ->value('sv.spec_value', '');
  165. unset($value['spuCode']);
  166. }
  167. if (!empty($rs_temp_good)) {
  168. $data[] = [
  169. 'head' => array_keys($rs_temp_good[0]),
  170. 'list' => $rs_temp_good,
  171. 'filename' => '产品' . date('YmdHis'),
  172. ];
  173. }
  174. if (empty($data)) {
  175. $data[] = [
  176. 'head' => ['没有可供导出的数据'],
  177. 'list' => [],
  178. 'filename' => date('YmdHis'),
  179. ];
  180. }
  181. excelSaveBatch($data);
  182. }
  183. //【一、采购日报表】1.咨询单总数
  184. public function zixunTotal()
  185. {
  186. $param = $this->request->only([
  187. 'token',
  188. 'start_date' => '',
  189. 'end_date' => '',
  190. 'page' => 1,
  191. 'size' => 15,
  192. ], 'post', 'trim');
  193. $val_params = Validate::rule([
  194. 'start_date' => 'date|elt:end_date',
  195. 'end_date' => 'date',
  196. ]);
  197. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  198. $where = [['co.is_del', '=', 0]];
  199. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['co.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  200. $count = Db::name('consult_order')
  201. ->alias('co')
  202. ->field('DATE_FORMAT(co.addtime,"%Y-%m-%d") addtime,cii.name,count(ci.id) total')
  203. ->leftJoin('consult_info ci', 'ci.zxNo=co.zxNo AND ci.bargain_code!="" ')
  204. ->leftJoin('company_item cii', 'cii.id=co.depart')
  205. ->where($where)
  206. ->group('addtime,co.depart')
  207. ->count();
  208. $list = Db::name('consult_order')
  209. ->alias('co')
  210. ->field('DATE_FORMAT(co.addtime,"%Y-%m-%d") addtime,cii.name,count(ci.id) total')
  211. ->leftJoin('consult_info ci', 'ci.zxNo=co.zxNo AND ci.bargain_code!="" ')
  212. ->leftJoin('company_item cii', 'cii.id=co.depart')
  213. ->where($where)
  214. ->group('addtime,co.depart')
  215. ->order('addtime')
  216. ->page($param['page'], $param['size'])
  217. ->select()
  218. ->toArray();
  219. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  220. }
  221. //【一、采购日报表】2.采购订单总金额
  222. public function purcheaseOrderSum()
  223. {
  224. $param = $this->request->only([
  225. 'token',
  226. 'start_date' => '',
  227. 'end_date' => '',
  228. 'page' => 1,
  229. 'size' => 15,
  230. ], 'post', 'trim');
  231. $val_params = Validate::rule([
  232. 'start_date' => 'date|elt:end_date',
  233. 'end_date' => 'date',
  234. ]);
  235. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  236. $where = [['po.is_del', '=', 0]];
  237. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['po.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  238. //统计条数的时候,不能按照status分组,否则下方列表不准
  239. $count = Db::name('purchease_order')
  240. ->alias('po')
  241. ->leftJoin('depart_user du', 'du.uid=po.cgder_id AND du.is_del=0')
  242. ->leftJoin('company_item ci', 'ci.id=du.itemid')
  243. ->where($where)
  244. ->order('addtime,itemid')
  245. ->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')
  246. ->group('addtime,du.itemid')
  247. ->count();
  248. $list = Db::name('purchease_order')
  249. ->alias('po')
  250. ->leftJoin('depart_user du', 'du.uid=po.cgder_id AND du.is_del=0')
  251. ->leftJoin('company_item ci', 'ci.id=du.itemid')
  252. ->where($where)
  253. ->order('addtime,itemid')
  254. ->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')
  255. ->page($param['page'], $param['size'])
  256. ->group('addtime,du.itemid,po.status')
  257. ->cursor();
  258. $data = [];
  259. foreach ($list as $value) {
  260. if (!isset($data[$value['addtime']][$value['itemid']])) {
  261. $data[$value['addtime']][$value['itemid']] = [
  262. 'addtime' => $value['addtime'],
  263. 'itemid' => $value['itemid'],
  264. 'name' => $value['name'],
  265. 'total_fee' => 0,
  266. 'total_num' => 0,
  267. 'wait_total_fee' => 0,
  268. 'wait_total_num' => 0,
  269. ];
  270. }
  271. if ($value['status'] == 0) {
  272. $data[$value['addtime']][$value['itemid']]['wait_total_fee'] += $value['total_fee'];
  273. $data[$value['addtime']][$value['itemid']]['wait_total_num'] += $value['total_num'];
  274. } else {
  275. $data[$value['addtime']][$value['itemid']]['total_fee'] += $value['total_fee'];
  276. $data[$value['addtime']][$value['itemid']]['total_num'] += $value['total_num'];
  277. }
  278. }
  279. //去除下标
  280. $da = [];
  281. foreach ($data as $v) {
  282. foreach ($v as $vvv) {
  283. $da[] = $vvv;
  284. }
  285. }
  286. return app_show(0, '请求成功', ['list' => $da, 'count' => $count]);
  287. }
  288. //【一、采购日报表】3.采购员回复咨询单数
  289. public function consultBidsSum()
  290. {
  291. $param = $this->request->only([
  292. 'token',
  293. 'start_date' => '',
  294. 'end_date' => '',
  295. 'page' => 1,
  296. 'size' => 15,
  297. ], 'post', 'trim');
  298. $val_params = Validate::rule([
  299. 'start_date' => 'date|elt:end_date',
  300. 'end_date' => 'date',
  301. ]);
  302. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  303. $where = [['cb.is_del', '=', 0]];
  304. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['cb.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  305. $count = Db::name('consult_bids')
  306. ->alias('cb')
  307. ->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')
  308. ->leftJoin('consult_info c', 'c.zxNo=cb.zxNo')
  309. ->leftJoin('depart_user du', 'du.uid=cb.createrid AND du.is_del=0')
  310. ->leftJoin('company_item ci', 'ci.id=du.itemid')
  311. ->where($where)
  312. ->group('addtime,du.itemid,ci.name ,cb.createrid,du.nickname')
  313. ->order('addtime,du.itemid,ci.name ,cb.createrid,du.nickname')
  314. ->count();
  315. $list = Db::name('consult_bids')
  316. ->alias('cb')
  317. ->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')
  318. ->leftJoin('consult_info c', 'c.zxNo=cb.zxNo')
  319. ->leftJoin('depart_user du', 'du.uid=cb.createrid AND du.is_del=0')
  320. ->leftJoin('company_item ci', 'ci.id=du.itemid')
  321. ->where($where)
  322. ->group('addtime,du.itemid,ci.name ,cb.createrid,du.nickname')
  323. ->order('addtime,du.itemid,ci.name ,cb.createrid,du.nickname')
  324. ->page($param['page'], $param['size'])
  325. ->select()
  326. ->toArray();
  327. $list[] = ['addtime' => '汇总', 'itemid' => 0, 'createrid' => 0, 'num' => array_sum(array_column($list, 'num')), 'total' => array_sum(array_column($list, 'total')), 'nickname' => '', 'name' => ''];
  328. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  329. }
  330. //【一、采购日报表】4.采购员订单金额
  331. public function purcheaseOrderSumByUser()
  332. {
  333. $param = $this->request->only([
  334. 'token',
  335. 'start_date' => '',
  336. 'end_date' => '',
  337. 'page' => 1,
  338. 'size' => 15
  339. ], 'post', 'trim');
  340. $val_params = Validate::rule([
  341. 'start_date' => 'date|elt:end_date',
  342. 'end_date' => 'date',
  343. ]);
  344. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  345. $where = [['is_del', '=', 0]];
  346. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  347. //先组织子查询
  348. $children_query = Db::name('purchease_order')
  349. ->field('DATE_FORMAT(addtime, "%Y-%m-%d") addtime,cgder_id,cgder,total_fee,status,good_num')
  350. ->where($where)
  351. ->buildSql();
  352. $count = Db::table($children_query)
  353. ->alias('a')
  354. ->group('addtime,cgder_id,cgder')
  355. ->count();
  356. $rs = Db::table($children_query)
  357. ->alias('a')
  358. ->field('addtime,cgder_id,cgder,SUM(total_fee) total_fee,SUM(good_num) good_num,status,0 wait_total_fee,0 wait_good_num')
  359. ->group('addtime,cgder_id,cgder,status')
  360. ->order('addtime,cgder_id')
  361. ->page($param['page'], $param['size'])
  362. ->cursor();
  363. $data = [];
  364. foreach ($rs as $value) {
  365. if (!isset($data[$value['addtime']][$value['cgder_id']])) {
  366. $data[$value['addtime']][$value['cgder_id']] = [
  367. 'addtime' => $value['addtime'],
  368. 'cgder' => $value['cgder'],
  369. 'total_fee' => 0.00,
  370. 'good_num' => 0,
  371. 'wait_total_fee' => 0.00,
  372. 'wait_good_num' => 0,
  373. ];
  374. }
  375. if ($value['status'] == 0) {
  376. $data[$value['addtime']][$value['cgder_id']]['wait_total_fee'] += $value['total_fee'];
  377. $data[$value['addtime']][$value['cgder_id']]['wait_good_num'] += $value['good_num'];
  378. } else {
  379. $data[$value['addtime']][$value['cgder_id']]['total_fee'] += $value['total_fee'];
  380. $data[$value['addtime']][$value['cgder_id']]['good_num'] += $value['good_num'];
  381. }
  382. }
  383. $da = [];
  384. //去除下标
  385. foreach ($data as $v) {
  386. foreach ($v as $vv) {
  387. $da[] = $vv;
  388. }
  389. }
  390. return app_show(0, '请求成功', ['list' => $da, 'count' => $count]);
  391. }
  392. //【二、咨询单报表】1.已采反报价信息_列表
  393. public function consultInfoBidsSum()
  394. {
  395. $param = $this->request->only([
  396. 'token',
  397. 'zxNo' => [],
  398. 'start_date' => '',
  399. 'end_date' => '',
  400. 'page' => 1,
  401. 'size' => 15,
  402. ], 'post', 'trim');
  403. $val_params = Validate::rule([
  404. 'start_date' => 'date|elt:end_date',
  405. 'end_date' => 'date',
  406. ]);
  407. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  408. $where = [['cb.is_del', '=', 0]];
  409. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  410. if (!empty($param['zxNo'])) $where[] = ['cb.zxNo', 'in', $param['zxNo']];
  411. $count = Db::name('consult_bids')
  412. ->alias('cb')
  413. ->leftJoin('consult_info ci', 'ci.infoNo=cb.infoNo')
  414. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  415. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  416. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  417. ->where($where)
  418. ->count('cb.id');
  419. $data = Db::name('consult_bids')
  420. ->alias('cb')
  421. ->field('cb.id,ci.addtime,cb.bidNo,cb.zxNo,cb.addtime cbaddtime,cb.good_name,s.name supplier,cb.total_fee,cb.delivery_day,cb.work_day,cb.expire_day,cb.creater,ci.num,ci.arrival_time,co.salesman,csi.companyName')
  422. ->leftJoin('consult_info ci', 'ci.infoNo=cb.infoNo')
  423. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  424. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  425. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  426. ->where($where)
  427. ->page($param['page'], $param['size'])
  428. ->order('ci.addtime', 'desc')
  429. ->select()
  430. ->toArray();
  431. //汇总
  432. $data[] = [
  433. 'id' => 0,
  434. 'addtime' => '汇总',
  435. 'bidNo' => '',
  436. 'zxNo' => '',
  437. 'cbaddtime' => '',
  438. 'good_name' => '',
  439. 'supplier' => '',
  440. 'total_fee' => array_sum(array_column($data, 'total_fee')),
  441. 'delivery_day' => '',
  442. 'work_day' => '',
  443. 'expire_day' => '',
  444. 'creater' => '',
  445. 'num' => array_sum(array_column($data, 'num')),
  446. 'arrival_time' => '',
  447. 'salesman' => '',
  448. 'companyName' => '',
  449. ];
  450. return app_show(0, '请求成功', ['list' => $data, 'count' => $count]);
  451. }
  452. //【二、咨询单报表】1.已采反报价信息_导出
  453. public function consultInfoBidsSumExport()
  454. {
  455. $param = $this->request->only([
  456. 'token',
  457. 'zxNo' => [],
  458. 'start_date' => '',
  459. 'end_date' => '',
  460. 'page' => 1,
  461. 'size' => 15,
  462. ], 'post', 'trim');
  463. $val_params = Validate::rule([
  464. 'start_date' => 'date|elt:end_date',
  465. 'end_date' => 'date',
  466. ]);
  467. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  468. $rs = Db::name('consult_bids')
  469. ->alias('cb')
  470. ->where('cb.is_del', 0);
  471. if ($param['start_date'] != '' && $param['end_date'] != '') $rs->whereBetween('ci.addtime', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']);
  472. if (!empty($param['zxNo'])) $rs->whereIn('cb.zxNo', $param['zxNo']);
  473. $data = $rs
  474. ->field('ci.addtime as 咨询时间,cb.bidNo as 采购单反馈单号,cb.zxNo as 咨询订单号,cb.addtime as 回复时间,cb.good_name as 产品名称,s.name as 供应商名称,cb.total_fee 成本合计,cb.delivery_day 物流时间,cb.work_day 产品工期,cb.expire_day 信息有效期,cb.creater 采购员,ci.num 需求数量,ci.arrival_time 要求到货日期,co.salesman 业务人员,csi.companyName 客户名称')
  475. ->leftJoin('consult_info ci', 'ci.infoNo=cb.infoNo')
  476. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  477. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  478. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  479. ->select()
  480. ->toArray();
  481. if (empty($data)) $data[] = '没有可供导出的数据';
  482. $headerArr = array_keys($data[0]);
  483. excelSave('咨询单报表-已采反报价信息' . date('YmdHis'), $headerArr, $data);
  484. }
  485. //【二、咨询单报表】2.未采反信息_列表
  486. public function consultInfoBidsSumNot()
  487. {
  488. $param = $this->request->only([
  489. 'token',
  490. 'companyName' => '',
  491. 'start_date' => '',
  492. 'end_date' => '',
  493. 'page' => 1,
  494. 'size' => 15,
  495. ], 'post', 'trim');
  496. $val_params = Validate::rule([
  497. 'start_date' => 'date|elt:end_date',
  498. 'end_date' => 'date',
  499. ]);
  500. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  501. $where = [['cb.is_del', '=', 0]];
  502. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  503. if ($param['companyName'] != '') $where[] = ['csi.companyName', 'like', '%' . $param['companyName'] . '%'];
  504. $count = Db::name('consult_bids')
  505. ->alias('cb')
  506. ->leftJoin('consult_info ci', 'ci.infoNo=cb.infoNo')
  507. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  508. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  509. ->where($where)
  510. ->order('co.endtime', 'desc')
  511. ->count('cb.id');
  512. $data = Db::name('consult_bids')
  513. ->alias('cb')
  514. ->field('cb.zxNo,cb.good_name,ci.num,csi.companyName,ci.addtime,co.endtime')
  515. ->leftJoin('consult_info ci', 'ci.infoNo=cb.infoNo')
  516. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  517. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  518. ->where($where)
  519. ->order('co.endtime', 'desc')
  520. ->page($param['page'], $param['size'])
  521. ->select()
  522. ->toArray();
  523. return app_show(0, '请求成功', ['list' => $data, 'count' => $count]);
  524. }
  525. //【二、咨询单报表】2.未采反信息_导出
  526. public function consultInfoBidsSumNotExport()
  527. {
  528. $param = $this->request->only([
  529. 'token',
  530. 'companyName' => '',
  531. 'start_date' => '',
  532. 'end_date' => '',
  533. ], 'post', 'trim');
  534. $val_params = Validate::rule([
  535. 'start_date' => 'date|elt:end_date',
  536. 'end_date' => 'date',
  537. ]);
  538. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  539. $rs = Db::name('consult_bids')
  540. ->alias('cb')
  541. ->leftJoin('consult_info ci', 'ci.infoNo=cb.infoNo')
  542. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  543. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  544. ->where('cb.is_del', 0)
  545. ->order('co.endtime', 'desc');
  546. if ($param['start_date'] != '' && $param['end_date'] != '') $rs->whereBetween('ci.addtime', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']);
  547. if ($param['companyName'] != '') $rs->whereLike('csi.companyName', '%' . $param['companyName'] . '%');
  548. $data = $rs
  549. ->field('cb.zxNo 咨询订单号,cb.good_name 产品名称,ci.num 需求数量,csi.companyName 客户名称,ci.addtime 咨询时间,co.endtime 截止时间')
  550. ->select()
  551. ->toArray();
  552. if (empty($data)) $data[] = '没有可供导出的数据';
  553. $headerArr = array_keys($data[0]);
  554. excelSave('咨询单报表-未采反信息' . date('YmdHis'), $headerArr, $data);
  555. }
  556. //【三、订单明细报表】列表
  557. public function orderListDetailed()
  558. {
  559. $param = $this->request->only([
  560. 'token',
  561. 'start_date' => '',
  562. 'end_date' => '',
  563. 'status' => '',
  564. 'page' => 1,
  565. 'size' => 15,
  566. ], 'post', 'trim');
  567. $val_params = Validate::rule([
  568. 'start_date' => 'date|elt:end_date',
  569. 'end_date' => 'date',
  570. ]);
  571. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  572. $where = [];
  573. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['po.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  574. if ($param['status'] != '') $where[] = ['po.status', '=', $param['status']];
  575. $all_status = ['待与供应商确认', '待入库', '部分入库', '入库完成', '已取消订单'];
  576. $all_send_status = [1 => '未发货', 2 => '部分发货', 3 => '已发货'];
  577. $count = Db::name('purchease_order')
  578. ->alias('po')
  579. ->leftJoin('business b', 'b.companyNo=po.companyNo')
  580. ->where($where)
  581. ->count('po.id');
  582. $data = Db::name('purchease_order')
  583. ->alias('po')
  584. ->field('po.cgdNo,po.addtime,po.supplierNo,po.supplier_name,po.good_name,po.good_num,po.nake_fee,po.total_fee,po.status,po.send_status,po.wsend_num,"" creater,b.company,po.cgder,"" send_time,on.orderCode,po.order_type,po.bkcode,po.spuCode')
  585. ->leftJoin('business b', 'b.companyNo=po.companyNo')
  586. ->leftJoin('order_num on', 'on.cgdNo=po.cgdNo')
  587. ->where($where)
  588. ->page($param['page'], $param['size'])
  589. ->order('po.addtime', 'desc')
  590. ->cursor();
  591. $list = [];
  592. foreach ($data as $v) {
  593. //单据状态
  594. $v['status'] = isset($all_status[$v['status']]) ? $all_status[$v['status']] : '';
  595. //发货状态
  596. $v['send_status'] = isset($all_send_status[$v['send_status']]) ? $all_send_status[$v['send_status']] : '';
  597. //创建人//order_type==1备库单
  598. if ($v['order_type'] == 1) $v['creater'] = Db::name('purchease')->where(['bk_code' => $v['bkcode'], 'spuCode' => $v['spuCode'], 'is_del' => 0])->value('apply_name', '');
  599. else $v['creater'] = Db::name('sale')->where(['orderCode' => $v['orderCode'], 'is_del' => 0])->value('apply_name', '');
  600. //创建时间
  601. $v['send_time'] = Db::name('order_out')
  602. ->where(['orderCode' => $v['orderCode']])
  603. ->order('addtime', 'desc')
  604. ->value('addtime');
  605. $list[] = $v;
  606. }
  607. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  608. }
  609. //【三、订单明细报表】导出
  610. public function orderListDetailedExport()
  611. {
  612. $param = $this->request->only([
  613. 'token',
  614. 'start_date' => '',
  615. 'end_date' => '',
  616. 'status' => '',
  617. ], 'post', 'trim');
  618. $val_params = Validate::rule([
  619. 'start_date' => 'date|elt:end_date',
  620. 'end_date' => 'date',
  621. ]);
  622. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  623. $where = [];
  624. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['po.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  625. if ($param['status'] != '') $where[] = ['po.status', '=', $param['status']];
  626. $all_status = ['待与供应商确认', '待入库', '部分入库', '入库完成', '已取消订单'];
  627. $all_send_status = [1 => '未发货', 2 => '部分发货', 3 => '已发货'];
  628. $data = Db::name('purchease_order')
  629. ->alias('po')
  630. ->field('po.cgdNo 采购单编号,po.addtime 创建时间,po.supplierNo 供应商编号,po.supplier_name 供应商名称,po.good_name 产品名称,po.good_num 购买数量,po.nake_fee 裸价,po.total_fee 成本合计,po.status 单据状态,po.send_status 发货状态,po.wsend_num 未发货数量,"" 创建人,b.company 客户名称,po.cgder 采购员,"" 发货时间,on.orderCode,po.order_type,po.bkcode,po.spuCode')
  631. ->leftJoin('business b', 'b.companyNo=po.companyNo')
  632. ->leftJoin('order_num on', 'on.cgdNo=po.cgdNo')
  633. ->where($where)
  634. ->order('po.addtime', 'desc')
  635. ->cursor();
  636. $list = [];
  637. foreach ($data as $v) {
  638. //单据状态
  639. $v['单据状态'] = isset($all_status[$v['单据状态']]) ? $all_status[$v['单据状态']] : '';
  640. //发货状态
  641. $v['发货状态'] = isset($all_send_status[$v['发货状态']]) ? $all_send_status[$v['发货状态']] : '';
  642. //创建人//order_type==1备库单
  643. if ($v['order_type'] == 1) $v['创建人'] = Db::name('purchease')->where(['bk_code' => $v['bkcode'], 'spuCode' => $v['spuCode'], 'is_del' => 0])->value('apply_name', '');
  644. else $v['创建人'] = Db::name('sale')->where(['orderCode' => $v['orderCode'], 'is_del' => 0])->value('apply_name', '');
  645. //创建时间
  646. $v['发货时间'] = Db::name('order_out')
  647. ->where(['orderCode' => $v['orderCode']])
  648. ->order('addtime', 'desc')
  649. ->value('addtime');
  650. unset($v['orderCode']);
  651. unset($v['order_type']);
  652. unset($v['bkcode']);
  653. unset($v['spuCode']);
  654. $list[] = $v;
  655. }
  656. if (empty($list)) $list[] = '没有可供导出的数据';
  657. $headerArr = array_keys($list[0]);
  658. excelSave('订单明细报表' . date('YmdHis'), $headerArr, $list);
  659. }
  660. //【四、售后报表】列表
  661. public function orderReturnList()
  662. {
  663. $param = $this->request->only([
  664. 'token',
  665. 'start_date' => '',
  666. 'end_date' => '',
  667. 'page' => 1,
  668. 'size' => 15,
  669. ], 'post', 'trim');
  670. $val_params = Validate::rule([
  671. 'start_date' => 'date|elt:end_date',
  672. 'end_date' => 'date',
  673. ]);
  674. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  675. $where = [];
  676. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  677. $all_status = [2 => '业务主管审核', 3 => '采购主管审核', 6 => '业务驳回', 7 => '采购驳回', 8 => '取消'];
  678. //总数
  679. $count = Db::name('order_return')
  680. ->alias('or')
  681. ->leftJoin('order_num on', 'on.orderCode=or.orderCode')
  682. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  683. ->leftJoin('order_out oo', 'oo.outCode=or.outCode AND oo.status=3')
  684. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  685. ->where($where)
  686. ->count('or.id');
  687. $list = Db::name('order_return')
  688. ->alias('or')
  689. ->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')
  690. ->leftJoin('order_num on', 'on.orderCode=or.orderCode')
  691. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  692. ->leftJoin('order_out oo', 'oo.outCode=or.outCode AND oo.status=3')
  693. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  694. ->where($where)
  695. ->withAttr('status', function ($val) use ($all_status) {
  696. return isset($all_status[$val]) ? $all_status[$val] : $val;
  697. })
  698. ->page($param['page'], $param['size'])
  699. ->select()
  700. ->toArray();
  701. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  702. }
  703. //【四、售后报表】导出
  704. public function orderReturnListExport()
  705. {
  706. $param = $this->request->only([
  707. 'token',
  708. 'start_date' => '',
  709. 'end_date' => '',
  710. ], 'post', 'trim');
  711. $val_params = Validate::rule([
  712. 'start_date' => 'date|elt:end_date',
  713. 'end_date' => 'date',
  714. ]);
  715. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  716. $where = [];
  717. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  718. $all_status = [2 => '业务主管审核', 3 => '采购主管审核', 6 => '业务驳回', 7 => '采购驳回', 8 => '取消'];
  719. $list = Db::name('order_return')
  720. ->alias('or')
  721. ->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 售后状态')
  722. ->leftJoin('order_num on', 'on.orderCode=or.orderCode')
  723. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  724. ->leftJoin('order_out oo', 'oo.outCode=or.outCode AND oo.status=3')
  725. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  726. ->where($where)
  727. ->withAttr('售后状态', function ($val) use ($all_status) {
  728. return isset($all_status[$val]) ? $all_status[$val] : $val;
  729. })
  730. ->select()
  731. ->toArray();
  732. if (empty($list)) $list[] = '没有可供导出的数据';
  733. $headerArr = array_keys($list[0]);
  734. excelSave('售后明细报表' . date('YmdHis'), $headerArr, $list);
  735. }
  736. //【五、供应商报表】列表
  737. public function supplierList()
  738. {
  739. $param = $this->request->only([
  740. 'token',
  741. 'start_date' => '',
  742. 'end_date' => '',
  743. 'update_start_date' => '',
  744. 'update_end_date' => '',
  745. 'page' => 1,
  746. 'size' => 15,
  747. ], 'post', 'trim');
  748. $val_params = Validate::rule([
  749. 'start_date' => 'date|elt:end_date',
  750. 'end_date' => 'date',
  751. 'update_start_date' => 'date|elt:update_end_date',
  752. 'update_end_date' => 'date',
  753. ]);
  754. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  755. $where = [];
  756. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  757. 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']];
  758. //总数
  759. $count = Db::name('supplier')
  760. ->alias('s')
  761. ->where($where)
  762. ->count('s.id');
  763. $list = Db::name('supplier')
  764. ->alias('s')
  765. ->field('s.id,s.addtime,s.name,s.creater,s.nature,s.source,s.pay_type,s.delivery_way,s.updatetime')
  766. ->where($where)
  767. ->page($param['page'], $param['size'])
  768. ->select()
  769. ->toArray();
  770. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  771. }
  772. //【五、供应商报表】导出
  773. public function supplierListExport()
  774. {
  775. $param = $this->request->only([
  776. 'token',
  777. 'start_date' => '',
  778. 'end_date' => '',
  779. 'update_start_date' => '',
  780. 'update_end_date' => '',
  781. ], 'post', 'trim');
  782. $val_params = Validate::rule([
  783. 'start_date' => 'date|elt:end_date',
  784. 'end_date' => 'date',
  785. 'update_start_date' => 'date|elt:update_end_date',
  786. 'update_end_date' => 'date',
  787. ]);
  788. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  789. $where = [];
  790. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  791. 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']];
  792. $list = Db::name('supplier')
  793. ->alias('s')
  794. ->field('s.addtime 录入供应商时间,s.name 供应商名称,s.creater 采购维护人,s.nature 供应商性质,s.source 供应商来源,s.pay_type 付款方式,s.delivery_way 发货方式,s.updatetime 修改供应商时间')
  795. ->where($where)
  796. ->select()
  797. ->toArray();
  798. if (empty($list)) $list[] = '没有可供导出的数据';
  799. $headerArr = array_keys($list[0]);
  800. excelSave('供应商报表' . date('YmdHis'), $headerArr, $list);
  801. }
  802. //【六、退货流水报表】列表
  803. public function SaleReturnList()
  804. {
  805. $param = $this->request->only([
  806. 'token',
  807. 'start_date' => '',
  808. 'end_date' => '',
  809. 'page' => 1,
  810. 'size' => 15,
  811. ], 'post', 'trim');
  812. $val_params = Validate::rule([
  813. 'start_date' => 'date|elt:end_date',
  814. 'end_date' => 'date'
  815. ]);
  816. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  817. $where = [['s.is_del', '=', 0]];
  818. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  819. $count = Db::name('sale_return')
  820. ->alias('s')
  821. ->where($where)
  822. ->leftJoin('order_num on', 'on.orderCode=s.orderCode')
  823. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  824. ->leftJoin('result_info ri', 'ri.result_code=s.error_code')
  825. ->count('s.id');
  826. $list = Db::name('sale_return')
  827. ->alias('s')
  828. ->field('s.returnCode,s.addtime,po.cgdNo,po.supplier_name,po.good_name,po.good_num,po.cgder,s.num,on.send_num,ri.result,s.is_th')
  829. ->where($where)
  830. ->leftJoin('order_num on', 'on.orderCode=s.orderCode')
  831. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  832. ->leftJoin('result_info ri', 'ri.result_code=s.error_code')
  833. ->page($param['page'], $param['size'])
  834. ->select()
  835. ->toArray();
  836. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  837. }
  838. //【六、退货流水报表】导出
  839. public function SaleReturnExport()
  840. {
  841. $param = $this->request->only([
  842. 'token',
  843. 'start_date' => '',
  844. 'end_date' => ''
  845. ], 'post', 'trim');
  846. $val_params = Validate::rule([
  847. 'start_date' => 'date|elt:end_date',
  848. 'end_date' => 'date'
  849. ]);
  850. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  851. $where = [['s.is_del', '=', 0]];
  852. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  853. $all_is_th = [0 => '不可以', 1 => '可以'];
  854. $list = Db::name('sale_return')
  855. ->alias('s')
  856. ->field('s.returnCode 退货单号,s.addtime 退货时间,po.cgdNo 采购单编号,po.supplier_name 供应商名称,po.good_name 产品名称,po.good_num 购买数量,po.cgder 采购员,s.num 退货数量,on.send_num 已发货数量,ri.result 退货原因,s.is_th 供应商是否可以退货')
  857. ->where($where)
  858. ->leftJoin('order_num on', 'on.orderCode=s.orderCode')
  859. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  860. ->leftJoin('result_info ri', 'ri.result_code=s.error_code')
  861. ->withAttr('供应商是否可以退货', function ($val) use ($all_is_th) {
  862. return isset($all_is_th[$val]) ? $all_is_th[$val] : '';
  863. })
  864. ->select()
  865. ->toArray();
  866. if (empty($list)) $list[] = '没有可供导出的数据';
  867. $headerArr = array_keys($list[0]);
  868. excelSave('退货流水报表' . date('YmdHis'), $headerArr, $list);
  869. }
  870. //【七、商品报表】1.商品上线报表_列表
  871. public function GoodOnlineList()
  872. {
  873. $param = $this->request->only([
  874. 'token',
  875. 'creater' => '',
  876. 'supplier_name' => '',
  877. 'start_date' => '',
  878. 'end_date' => '',
  879. 'page' => 1,
  880. 'size' => 15,
  881. ], 'post', 'trim');
  882. $val_params = Validate::rule([
  883. 'start_date' => 'date|elt:end_date',
  884. 'end_date' => 'date'
  885. ]);
  886. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  887. $where = [['s.is_del', '=', 0], ['gp.exam_status', '=', 6]]; //exam_status==6 上线成功
  888. 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
  889. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  890. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  891. $count = Db::name('good_platform')
  892. ->alias('gp')
  893. ->where($where)
  894. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
  895. ->leftJoin('brand b', 'b.id=gb.brand_id')
  896. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  897. ->count('gp.id');
  898. $list = Db::name('good_platform')
  899. ->alias('gp')
  900. ->field('gb.creater,gp.skuCode,gp.spuCode,gb.good_name,b.brand_name,"" good_model,s.name,gb.tax,gb.nake_price,gp.online_time')
  901. ->where($where)
  902. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
  903. ->leftJoin('brand b', 'b.id=gb.brand_id')
  904. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  905. ->withAttr('good_model', function ($val, $data) {
  906. return Db::name('good_spec')
  907. ->alias('gp')
  908. ->field('')
  909. ->leftJoin('specs s', 's.id=gp.spec_id')
  910. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  911. ->where([
  912. 'gp.spuCode' => $data['spuCode'],
  913. 'gp.is_del' => 0,
  914. 's.spec_name' => '型号',
  915. ])
  916. ->value('sv.spec_value', '');
  917. })
  918. ->page($param['page'], $param['size'])
  919. ->select()
  920. ->toArray();
  921. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  922. }
  923. //【七、商品报表】1.商品上线报表_导出
  924. public function GoodOnlineExport()
  925. {
  926. $param = $this->request->only([
  927. 'token',
  928. 'creater' => '',
  929. 'supplier_name' => '',
  930. 'start_date' => '',
  931. 'end_date' => ''
  932. ], 'post', 'trim');
  933. $val_params = Validate::rule([
  934. 'start_date' => 'date|elt:end_date',
  935. 'end_date' => 'date'
  936. ]);
  937. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  938. $where = [['s.is_del', '=', 0], ['gp.exam_status', '=', 6]]; //exam_status==6 上线成功
  939. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.online_time', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  940. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  941. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  942. $list = Db::name('good_platform')
  943. ->alias('gp')
  944. ->field('gb.creater 采购维护人,gp.skuCode 商品上线编号,gp.spuCode 商品成本编号,gb.good_name 商品名称,b.brand_name 品牌名称,"" 商品型号,s.name 供应商名称,gb.tax 税点,gb.nake_price 成本价合计,gp.online_time 上线时间')
  945. ->where($where)
  946. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
  947. ->leftJoin('brand b', 'b.id=gb.brand_id')
  948. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  949. ->withAttr('商品型号', function ($val, $data) {
  950. return Db::name('good_spec')
  951. ->alias('gp')
  952. ->field('')
  953. ->leftJoin('specs s', 's.id=gp.spec_id')
  954. ->leftJoin('spec_value sv', 'sv.id=gp.spec_value_id')
  955. ->where([
  956. 'gp.spuCode' => $data['商品成本编号'],
  957. 'gp.is_del' => 0,
  958. 's.spec_name' => '型号',
  959. ])
  960. ->value('sv.spec_value', '');
  961. })
  962. ->select()
  963. ->toArray();
  964. if (empty($list)) $list[] = '没有可供导出的数据';
  965. $headerArr = array_keys($list[0]);
  966. excelSave('商品上线报表' . date('YmdHis'), $headerArr, $list);
  967. }
  968. //【七、商品报表】2.商品下线报表_列表
  969. public function GoodOfflineList()
  970. {
  971. $param = $this->request->only([
  972. 'token',
  973. 'creater' => '',
  974. 'supplier_name' => '',
  975. 'start_date' => '',
  976. 'end_date' => '',
  977. 'page' => 1,
  978. 'size' => 15,
  979. ], 'post', 'trim');
  980. $val_params = Validate::rule([
  981. 'start_date' => 'date|elt:end_date',
  982. 'end_date' => 'date'
  983. ]);
  984. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  985. $where = [['s.is_del', '=', 0], ['gp.exam_status', '=', 8]]; //exam_status==8 下线成功
  986. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.updatetime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  987. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  988. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  989. $count = Db::name('good_platform')
  990. ->alias('gp')
  991. ->where($where)
  992. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
  993. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  994. ->count('gp.id');
  995. $list = Db::name('good_platform')
  996. ->alias('gp')
  997. ->field('gp.updatetime,gb.creater,gp.skuCode,gp.spuCode,gb.good_name,s.name')
  998. ->where($where)
  999. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
  1000. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1001. ->page($param['page'], $param['size'])
  1002. ->select()
  1003. ->toArray();
  1004. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1005. }
  1006. //【七、商品报表】2.商品下线报表_导出
  1007. public function GoodOfflineExport()
  1008. {
  1009. $param = $this->request->only([
  1010. 'token',
  1011. 'creater' => '',
  1012. 'supplier_name' => '',
  1013. 'start_date' => '',
  1014. 'end_date' => ''
  1015. ], 'post', 'trim');
  1016. $val_params = Validate::rule([
  1017. 'start_date' => 'date|elt:end_date',
  1018. 'end_date' => 'date'
  1019. ]);
  1020. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1021. $where = [['s.is_del', '=', 0], ['gp.exam_status', '=', 8]]; //exam_status==8 下线成功
  1022. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.updatetime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1023. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1024. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1025. $list = Db::name('good_platform')
  1026. ->alias('gp')
  1027. ->field('gp.updatetime 商品下线时间,gb.creater 采购维护人,gp.skuCode 商品上线编号,gp.spuCode 商品成本编号,gb.good_name 商品名称,s.name 供应商名称')
  1028. ->where($where)
  1029. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
  1030. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1031. ->select()
  1032. ->toArray();
  1033. if (empty($list)) $list[] = '没有可供导出的数据';
  1034. $headerArr = array_keys($list[0]);
  1035. excelSave('商品下线报表' . date('YmdHis'), $headerArr, $list);
  1036. }
  1037. //【七、商品报表】3.商品修改报表_列表
  1038. public function ChangeLogList()
  1039. {
  1040. $param = $this->request->only([
  1041. 'token',
  1042. 'creater' => '',
  1043. 'supplier_name' => '',
  1044. 'start_date' => '',
  1045. 'end_date' => '',
  1046. 'page' => 1,
  1047. 'size' => 15,
  1048. ], 'post', 'trim');
  1049. $val_params = Validate::rule([
  1050. 'start_date' => 'date|elt:end_date',
  1051. 'end_date' => 'date'
  1052. ]);
  1053. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1054. $where = [['cl.type', '=', 3]]; //type==3 商品成本变化记录
  1055. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['cl.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1056. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1057. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1058. $count = Db::name('change_log')
  1059. ->alias('cl')
  1060. ->leftJoin('good_basic gb', 'gb.spuCode=cl.code')
  1061. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1062. ->where($where)
  1063. ->count('cl.id');
  1064. $data = Db::name('change_log')
  1065. ->alias('cl')
  1066. ->field('cl.addtime,gb.creater,cl.code,gb.good_name,s.name,cl.before_info,cl.after_info')
  1067. ->leftJoin('good_basic gb', 'gb.spuCode=cl.code')
  1068. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1069. ->where($where)
  1070. ->order('cl.addtime', 'desc')
  1071. ->page($param['page'], $param['size'])
  1072. ->cursor();
  1073. $list = [];
  1074. foreach ($data as $value) {
  1075. $before_info = json_decode($value['before_info'], true);
  1076. $after_info = json_decode($value['after_info'], true);
  1077. if (isset($after_info['field_change'])) unset($after_info['field_change']);
  1078. $value['before_info'] = [];
  1079. foreach ($after_info as $kk => $vv) {
  1080. //特殊字段处理
  1081. switch ($kk) {
  1082. //品牌
  1083. case 'brand_id':
  1084. $all_brand = Db::name('brand')
  1085. ->whereIn('id', [$before_info[$kk], $vv])
  1086. ->where('is_del', 0)
  1087. ->column('brand_name', 'id');
  1088. $value['before_info'][$kk] = isset($all_brand[$before_info[$kk]]) ? $all_brand[$before_info[$kk]] : '';
  1089. $after_info[$kk] = isset($all_brand[$vv]) ? $all_brand[$vv] : '';
  1090. break;
  1091. //分类
  1092. case 'cat_id':
  1093. $value['before_info'][$kk] = implode('/', array_column(made($before_info[$kk]), 'name'));
  1094. $after_info[$kk] = implode('/', array_column(made($vv), 'name'));
  1095. break;
  1096. //发货地
  1097. case 'delivery_place':
  1098. $delivery_place = explode(',', $before_info[$kk]);
  1099. $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] ?? '']));
  1100. $delivery_place_2 = explode(',', $vv);
  1101. $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] ?? '']));
  1102. break;
  1103. //产地
  1104. case 'origin_place':
  1105. $origin_place = explode(',', $before_info[$kk]);
  1106. $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] ?? '']));
  1107. $origin_place_2 = explode(',', $vv);
  1108. $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] ?? '']));
  1109. break;
  1110. //商品单位
  1111. case 'good_unit':
  1112. $all_unit = Db::name('unit')
  1113. ->whereIn('id', [$before_info[$kk], $vv])
  1114. ->where(['is_del' => 0])
  1115. ->column('unit', 'id');
  1116. $value['before_info'][$kk] = isset($all_unit[$before_info[$kk]]) ? $all_unit[$before_info[$kk]] : '';
  1117. $after_info[$kk] = isset($all_unit[$vv]) ? $all_unit[$vv] : '';
  1118. break;
  1119. //业务企业
  1120. case 'companyNo':
  1121. $all_business = Db::name('business')
  1122. ->whereIn('companyNo', [$before_info[$kk], $vv])
  1123. ->where(['is_del' => 0])
  1124. ->column('company', 'companyNo');
  1125. $value['before_info'][$kk] = isset($all_business[$before_info[$kk]]) ? $all_business[$before_info[$kk]] : '';
  1126. $after_info[$kk] = isset($all_business[$vv]) ? $all_business[$vv] : '';
  1127. break;
  1128. //供应商
  1129. case 'supplierNo':
  1130. $all_supplier = Db::name('supplier')
  1131. ->whereIn('code', [$before_info[$kk], $vv])
  1132. ->where(['is_del' => 0])
  1133. ->column('name', 'code');
  1134. $value['before_info'][$kk] = isset($all_supplier[$before_info[$kk]]) ? $all_supplier[$before_info[$kk]] : '';
  1135. $after_info[$kk] = isset($all_supplier[$vv]) ? $all_supplier[$vv] : '';
  1136. break;
  1137. //供货区域
  1138. case 'supply_area':
  1139. if ($before_info[$kk] == 1) $value['before_info'][$kk] = '全国';
  1140. elseif ($before_info[$kk] == 2) $value['before_info'][$kk] = '全国除偏远';
  1141. else $value['before_info'][$kk] = '';
  1142. if ($vv == 1) $after_info[$kk] = '全国';
  1143. elseif ($vv == 2) $after_info[$kk] = '全国除偏远';
  1144. else $after_info[$kk] = '';
  1145. break;
  1146. //贵金属种类
  1147. case 'noble_metal':
  1148. if ($before_info[$kk] == 1) $value['before_info'][$kk] = '18K';
  1149. elseif ($before_info[$kk] == 2) $value['before_info'][$kk] = '24K';
  1150. elseif ($before_info[$kk] == 3) $value['before_info'][$kk] = '白银';
  1151. else $value['before_info'][$kk] = '';
  1152. if ($vv == 1) $after_info[$kk] = '18K';
  1153. elseif ($vv == 2) $after_info[$kk] = '24K';
  1154. elseif ($vv == 3) $after_info[$kk] = '白银';
  1155. else $after_info[$kk] = '';
  1156. break;
  1157. //专属类型
  1158. case 'is_exclusive':
  1159. $value['before_info'][$kk] = implode('/', array_column(mai($before_info[$kk]), 'rname'));
  1160. $after_info[$kk] = implode('/', array_column(mai($vv), 'rname'));
  1161. break;
  1162. default:
  1163. $value['before_info'][$kk] = $before_info[$kk];
  1164. break;
  1165. }
  1166. }
  1167. $value['after_info'] = $after_info;
  1168. $list[] = $value;
  1169. }
  1170. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1171. }
  1172. //【七、商品报表】3.商品修改报表_导出
  1173. public function ChangeLogExport()
  1174. {
  1175. $param = $this->request->only([
  1176. 'token',
  1177. 'creater' => '',
  1178. 'supplier_name' => '',
  1179. 'start_date' => '',
  1180. 'end_date' => ''
  1181. ], 'post', 'trim');
  1182. $val_params = Validate::rule([
  1183. 'start_date' => 'date|elt:end_date',
  1184. 'end_date' => 'date'
  1185. ]);
  1186. if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1187. $where = [['cl.type', '=', 3]]; //type==3 商品成本变化记录
  1188. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['cl.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1189. if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1190. if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1191. $data = Db::name('change_log')
  1192. ->alias('cl')
  1193. ->field('cl.addtime 商品操作时间,gb.creater 采购维护人,cl.code 商品成本编号,gb.good_name 商品名称,s.name 供应商名称,cl.before_info 修改前的内容,cl.after_info 修改后的内容')
  1194. ->leftJoin('good_basic gb', 'gb.spuCode=cl.code')
  1195. ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1196. ->where($where)
  1197. ->cursor();
  1198. $list = [];
  1199. foreach ($data as $value) {
  1200. $before_info = json_decode($value['修改前的内容'], true);
  1201. $after_info = json_decode($value['修改后的内容'], true);
  1202. if (isset($after_info['field_change'])) {
  1203. $field_change = json_decode($after_info['field_change'], true);
  1204. $before_new = $after_new = [];
  1205. foreach ($field_change as $v) {
  1206. //特殊字段处理
  1207. switch ($v) {
  1208. //品牌
  1209. case 'brand_id':
  1210. $all_brand = Db::name('brand')
  1211. ->whereIn('id', [$before_info[$v] ?? 0, $after_info[$v] ?? 0])
  1212. ->where('is_del', 0)
  1213. ->column('brand_name', 'id');
  1214. if (isset($before_info[$v])) $before_info[$v] = isset($all_brand[$before_info[$v]]) ? $all_brand[$before_info[$v]] : '';
  1215. if (isset($after_info[$v])) $after_info[$v] = isset($all_brand[$after_info[$v]]) ? $all_brand[$after_info[$v]] : '';
  1216. break;
  1217. //分类
  1218. case 'cat_id':
  1219. if (isset($before_info[$v])) $before_info[$v] = implode('/', array_column(made($before_info[$v]), 'name'));
  1220. if (isset($after_info[$v])) $after_info[$v] = implode('/', array_column(made($after_info[$v]), 'name'));
  1221. break;
  1222. //发货地
  1223. case 'delivery_place':
  1224. $delivery_place = explode(',', $before_info[$v]);
  1225. $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] ?? '']));
  1226. $delivery_place_2 = explode(',', $after_info[$v]);
  1227. $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] ?? '']));
  1228. break;
  1229. //产地
  1230. case 'origin_place':
  1231. $origin_place = explode(',', $before_info[$v]);
  1232. $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] ?? '']));
  1233. $origin_place_2 = explode(',', $after_info[$v]);
  1234. $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] ?? '']));
  1235. break;
  1236. //商品单位
  1237. case 'good_unit':
  1238. $all_unit = Db::name('unit')
  1239. ->whereIn('id', [$before_info[$v] ?? 0, $after_info[$v] ?? 0])
  1240. ->where(['is_del' => 0])
  1241. ->column('unit', 'id');
  1242. if (isset($before_info[$v])) $before_info[$v] = isset($all_unit[$before_info[$v]]) ? $all_unit[$before_info[$v]] : '';
  1243. if (isset($after_info[$v])) $after_info[$v] = isset($all_unit[$after_info[$v]]) ? $all_unit[$after_info[$v]] : '';
  1244. break;
  1245. //业务企业
  1246. case 'companyNo':
  1247. $all_business = Db::name('business')
  1248. ->whereIn('companyNo', [$before_info[$v] ?? '', $after_info[$v] ?? ''])
  1249. ->where(['is_del' => 0])
  1250. ->column('company', 'companyNo');
  1251. if (isset($before_info[$v])) $before_info[$v] = isset($all_business[$before_info[$v]]) ? $all_business[$before_info[$v]] : '';
  1252. if (isset($after_info[$v])) $after_info[$v] = isset($all_business[$after_info[$v]]) ? $all_business[$after_info[$v]] : '';
  1253. break;
  1254. //供应商
  1255. case 'supplierNo':
  1256. $all_supplier = Db::name('supplier')
  1257. ->whereIn('code', [$before_info[$v], $after_info[$v]])
  1258. ->where(['is_del' => 0])
  1259. ->column('name', 'code');
  1260. $before_info[$v] = isset($all_supplier[$before_info[$v]]) ? $all_supplier[$before_info[$v]] : '';
  1261. $after_info[$v] = isset($all_supplier[$after_info[$v]]) ? $all_supplier[$after_info[$v]] : '';
  1262. break;
  1263. //供货区域
  1264. case 'supply_area':
  1265. if (isset($before_info[$v])) {
  1266. if ($before_info[$v] == 1) $before_info[$v] = '全国';
  1267. elseif ($before_info[$v] == 2) $before_info[$v] = '全国除偏远';
  1268. else $before_info[$v] = '';
  1269. }
  1270. if (isset($after_info[$v])) {
  1271. if ($after_info[$v] == 1) $after_info[$v] = '全国';
  1272. elseif ($after_info[$v] == 2) $after_info[$v] = '全国除偏远';
  1273. else $after_info[$v] = '';
  1274. }
  1275. break;
  1276. //贵金属种类
  1277. case 'noble_metal':
  1278. if (isset($before_info[$v])) {
  1279. if ($before_info[$v] == 1) $before_info[$v] = '18K';
  1280. elseif ($before_info[$v] == 2) $before_info[$v] = '24K';
  1281. elseif ($before_info[$v] == 3) $before_info[$v] = '白银';
  1282. else $before_info[$v] = '';
  1283. }
  1284. if (isset($after_info[$v])) {
  1285. if ($after_info[$v] == 1) $after_info[$v] = '18K';
  1286. elseif ($after_info[$v] == 2) $after_info[$v] = '24K';
  1287. elseif ($after_info[$v] == 3) $after_info[$v] = '白银';
  1288. else $after_info[$v] = '';
  1289. }
  1290. break;
  1291. //专属类型
  1292. case 'is_exclusive':
  1293. if (isset($before_info[$v])) $before_info[$v] = implode('/', array_column(mai($before_info[$v]), 'rname'));
  1294. if (isset($after_info[$v])) $after_info[$v] = implode('/', array_column(mai($after_info[$v]), 'rname'));
  1295. break;
  1296. //状态
  1297. case 'status':
  1298. $all_status = [1 => '待完善成本', 2 => '待产品审核', 3 => '待财务定价', 4 => '待财务审核定价', 5 => '待上线', 6 => '上线成功', 7 => '审核失败', 8 => '已下线'];
  1299. if (isset($before_info[$v])) $before_info[$v] = isset($all_status[$before_info[$v]]) ? $all_status[$before_info[$v]] : '';
  1300. if (isset($after_info[$v])) $after_info[$v] = isset($all_status[$after_info[$v]]) ? $all_status[$after_info[$v]] : '';
  1301. }
  1302. $key = isset($this->good_field_title[$v]) ? $this->good_field_title[$v] : $v;
  1303. if (isset($before_info[$v])) $before_new[$key] = $before_info[$v];
  1304. if (isset($after_info[$v])) $after_new[$key] = $after_info[$v];
  1305. }
  1306. $value['修改前的内容'] = json_encode($before_new, JSON_UNESCAPED_UNICODE);
  1307. $value['修改后的内容'] = json_encode($after_new, JSON_UNESCAPED_UNICODE);
  1308. }
  1309. $list[] = $value;
  1310. }
  1311. if (empty($list)) $list[] = '没有可供导出的数据';
  1312. $headerArr = array_keys($list[0]);
  1313. excelSave('商品修改报表' . date('YmdHis'), $headerArr, $list);
  1314. }
  1315. //【八、结算报表】_列表(暂不做)
  1316. //【八、结算报表】_导出(暂不做)
  1317. //【九、出入库明细报表】_列表
  1318. public function GoodLogList()
  1319. {
  1320. /**
  1321. * $param = $this->request->only([
  1322. * 'token',
  1323. * 'creater' => '',
  1324. * 'supplier_name' => '',
  1325. * 'start_date' => '',
  1326. * 'end_date' => '',
  1327. * 'page' => 1,
  1328. * 'size' => 15
  1329. * ], 'post', 'trim');
  1330. * **/
  1331. }
  1332. //【九、出入库明细报表】_导出
  1333. public function GoodLogExport()
  1334. {
  1335. /**
  1336. * $param = $this->request->only([
  1337. * 'token',
  1338. * // 'creater' => '',
  1339. * // 'supplier_name' => '',
  1340. * // 'start_date' => '',
  1341. * // 'end_date' => ''
  1342. * ], 'post', 'trim');
  1343. *
  1344. * $val_params = Validate::rule([
  1345. * 'start_date' => 'date|elt:end_date',
  1346. * 'end_date' => 'date'
  1347. * ]);
  1348. *
  1349. * if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
  1350. *
  1351. * // $where = [['gl.action_type', '=', 'CGD']];
  1352. * // if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.updatetime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1353. * // if ($param['creater'] != '') $where[] = ['gb.creater', 'like', '%' . $param['creater'] . '%'];
  1354. * // if ($param['supplier_name'] != '') $where[] = ['s.name', 'like', '%' . $param['supplier_name'] . '%'];
  1355. *
  1356. *
  1357. * $list = Db::name('good_log')
  1358. * ->alias('gl')
  1359. * ->field('"" 创建人,"" 创建人公司,"" 创建人部门,"" 创建时间,"" 单据状态,"" 采购单号,gl.type 出入库类型,gb.good_name 商品名称,gb.spuCode 产品编码,gl.stock 出入库数量,gl.addtime 出入库日期,"" 维护人员,"" 发起人,wi.wsm_type 库房性质,s.name 库房公司,wi.name 库房名称')
  1360. * // ->where($where)
  1361. * ->leftJoin('good_stock gs', 'gs.id=gl.stock_id')
  1362. * ->leftJoin('good_basic gb', 'gb.spuCode=gs.spuCode')
  1363. * ->leftJoin('warehouse_info wi', 'wi.wsm_code=gs.wsm_code')
  1364. * ->leftJoin('supplier s', 's.code=wi.supplierNo')
  1365. * // ->leftJoin('supplier s', 's.code=gb.supplierNo')
  1366. * ->select()
  1367. * ->toArray();
  1368. * halt($list);
  1369. * if (empty($list)) $list[] = '没有可供导出的数据';
  1370. *
  1371. * $headerArr = array_keys($list[0]);
  1372. * excelSave('出入库明细报表' . date('YmdHis'), $headerArr, $list);
  1373. **/
  1374. }
  1375. }