Report.php 105 KB

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