Report.php 107 KB

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