Report.php 78 KB

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