Report.php 61 KB

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