Report.php 101 KB

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