Report.php 107 KB

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