Report.php 105 KB

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