Report.php 104 KB

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