Report.php 104 KB

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