ReportByRelaComNo.php 115 KB

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