Report.php 106 KB

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