SaleReport.php 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\Db;
  4. use think\facade\Validate;
  5. //销售报表处理类
  6. class SaleReport extends Base
  7. {
  8. private $all_order_type = [1 => '备库', 2 => '非库存', 3 => '咨询采反', 4 => '项目采反', 5 => '平台部订单销售库存', 6 => '平台部订单销售非库存'];//订单类型
  9. private $all_stock = [0 => '非库存品', 1 => '库存品'];//是否库存品
  10. private $all_sale_status = [0 => '待发货', 1 => '待发货完成', 2 => '发货已完成', 3 => '订单已取消'];//订单状态(sale表里的status)
  11. private $is_addrs = [0 => '是', 1 => '否'];//是否一地(数据库中存的是'是否多地',逻辑相反)
  12. private $is_custom = [0 => '否', 1 => '是'];//是否定制
  13. private $consult_info_status = [1 => '招标进行中', 2 => '招标已结束', 3 => '等待议价结果', 4 => '确认商品', 5 => '成功转单', 6 => '取消转单', 7 => '招标已暂停'];//状态
  14. private $noble_metal = [1 => '18K', 2 => '24K', 3 => '白银'];//贵金属种类
  15. private $is_act = [0 => '否', 1 => '是'];//是否接受工差
  16. private $all_order_return_status = [1 => '待业务审核', 2 => '待采购审核', 3 => '待设置仓库', 4 => '待客户退货', 5 => '售后已完成', 6 => '业务已驳回', 7 => '采购已驳回', 8 => '申请已取消'];
  17. private $is_activity = [0 => '不参与活动', 1 => '参与活动'];
  18. private $good_type = [1 => '正常商品', 2 => '赠品', 3 => '样品'];
  19. private $sale_diff_status = [1 => '修改销售额', 2 => '不修改销售额'];
  20. //【一、管理报表】1.日报_列表
  21. public function consultDay()
  22. {
  23. $param = $this->request->only(['token', 'date' => date('Y-m-d')], 'post', 'trim');
  24. $rs_1 = Db::name('consult_info')
  25. ->alias('ci')
  26. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  27. ->where('ci.is_del', 0)
  28. ->whereBetween('ci.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  29. ->group('co.createrid,co.creater')
  30. ->column('COUNT(ci.id) 当日咨询单数量,SUM(ci.budget_price*ci.num) 金额,co.creater 创建人', 'co.createrid');
  31. $rs_2 = Db::name('sale')
  32. ->where('is_del', 0)
  33. ->whereBetween('addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  34. ->group('apply_id,apply_name')
  35. ->column('COUNT(id) 当日下单数量,SUM(total_price) 金额,apply_name 创建人', 'apply_id');
  36. $rs_3 = Db::name('order_out')
  37. ->alias('oo')
  38. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  39. ->where(['oo.status' => 3])
  40. ->whereBetween('oo.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  41. ->group('oo.apply_id,oo.apply_name')
  42. ->column('COUNT(oo.id) 当日签收数量,SUM(s.total_price) 金额,oo.apply_name 创建人', 'oo.apply_id');
  43. $rs_4 = Db::name('order_return')
  44. ->alias('or')
  45. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  46. ->where(['or.is_del' => 0])
  47. ->whereBetween('or.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  48. ->group('or.apply_id,or.apply_name')
  49. ->column('COUNT(or.id) 单日售后单数,SUM(s.total_price) 金额,or.apply_name 创建人', 'or.apply_id');
  50. $all_ids = array_unique(array_merge(array_keys($rs_1), array_keys($rs_2), array_keys($rs_3), array_keys($rs_4)));
  51. $list = [];
  52. foreach ($all_ids as $id) {
  53. $val = [];
  54. if (isset($rs_1[$id]['创建人'])) $val['creater'] = $rs_1[$id]['创建人'];
  55. elseif (isset($rs_2[$id]['创建人'])) $val['creater'] = $rs_2[$id]['创建人'];
  56. elseif (isset($rs_3[$id]['创建人'])) $val['creater'] = $rs_3[$id]['创建人'];
  57. elseif (isset($rs_4[$id]['创建人'])) $val['creater'] = $rs_4[$id]['创建人'];
  58. else $val['creater'] = '';
  59. $val['creater_company'] = get_company_name_by_uid($id);//获取创建人的所属部门
  60. $val['consult_num'] = isset($rs_1[$id]['当日咨询单数量']) ? $rs_1[$id]['当日咨询单数量'] : '';
  61. $val['consult_money'] = isset($rs_1[$id]['金额']) ? $rs_1[$id]['金额'] : '';
  62. $val['sale_num'] = isset($rs_2[$id]['当日下单数量']) ? $rs_2[$id]['当日下单数量'] : '';
  63. $val['sale_money'] = isset($rs_2[$id]['金额']) ? $rs_2[$id]['金额'] : '';
  64. $val['receipt_num'] = isset($rs_3[$id]['当日签收数量']) ? $rs_3[$id]['当日签收数量'] : '';
  65. $val['receipt_money'] = isset($rs_3[$id]['金额']) ? $rs_3[$id]['金额'] : '';
  66. $val['invoice_num'] = '';
  67. $val['invoice_money'] = '';
  68. $val['after_sales_num'] = isset($rs_4[$id]['单日售后单数']) ? $rs_4[$id]['单日售后单数'] : '';
  69. $val['after_sales_money'] = isset($rs_4[$id]['金额']) ? $rs_4[$id]['金额'] : '';
  70. $val['payment_num'] = '';
  71. $val['payment_money'] = '';
  72. $list[] = $val;
  73. }
  74. return app_show(0, '请求成功', ['list' => $list]);
  75. }
  76. //【一、管理报表】1.日报_导出
  77. public function consultDayExport()
  78. {
  79. $param = $this->request->only(['token', 'date' => date('Y-m-d')], 'post', 'trim');
  80. $rs_1 = Db::name('consult_info')
  81. ->alias('ci')
  82. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  83. ->where('ci.is_del', 0)
  84. ->whereBetween('ci.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  85. ->group('co.createrid,co.creater')
  86. ->column('COUNT(ci.id) 当日咨询单数量,SUM(ci.budget_price*ci.num) 金额,co.creater 创建人', 'co.createrid');
  87. $rs_2 = Db::name('sale')
  88. ->where('is_del', 0)
  89. ->whereBetween('addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  90. ->group('apply_id,apply_name')
  91. ->column('COUNT(id) 当日下单数量,SUM(total_price) 金额,apply_name 创建人', 'apply_id');
  92. $rs_3 = Db::name('order_out')
  93. ->alias('oo')
  94. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  95. ->where(['oo.status' => 3])
  96. ->whereBetween('oo.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  97. ->group('oo.apply_id,oo.apply_name')
  98. ->column('COUNT(oo.id) 当日签收数量,SUM(s.total_price) 金额,oo.apply_name 创建人', 'oo.apply_id');
  99. $rs_4 = Db::name('order_return')
  100. ->alias('or')
  101. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  102. ->where(['or.is_del' => 0])
  103. ->whereBetween('or.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  104. ->group('or.apply_id,or.apply_name')
  105. ->column('COUNT(or.id) 单日售后单数,SUM(s.total_price) 金额,or.apply_name 创建人', 'or.apply_id');
  106. $all_ids = array_unique(array_merge(array_keys($rs_1), array_keys($rs_2), array_keys($rs_3), array_keys($rs_4)));
  107. $list = [];
  108. foreach ($all_ids as $id) {
  109. $val = [];
  110. if (isset($rs_1[$id]['创建人'])) $val['创建人'] = $rs_1[$id]['创建人'];
  111. elseif (isset($rs_2[$id]['创建人'])) $val['创建人'] = $rs_2[$id]['创建人'];
  112. elseif (isset($rs_3[$id]['创建人'])) $val['创建人'] = $rs_3[$id]['创建人'];
  113. elseif (isset($rs_4[$id]['创建人'])) $val['创建人'] = $rs_4[$id]['创建人'];
  114. else $val['创建人'] = '';
  115. $val['创建人部门'] = get_company_name_by_uid($id);//获取创建人的所属部门
  116. $val['当日咨询单数量'] = isset($rs_1[$id]['当日咨询单数量']) ? $rs_1[$id]['当日咨询单数量'] : '';
  117. $val['当日咨询单金额'] = isset($rs_1[$id]['金额']) ? $rs_1[$id]['金额'] : '';
  118. $val['当日下单数量'] = isset($rs_2[$id]['当日下单数量']) ? $rs_2[$id]['当日下单数量'] : '';
  119. $val['当日下单金额'] = isset($rs_2[$id]['金额']) ? $rs_2[$id]['金额'] : '';
  120. $val['当日签收数量'] = isset($rs_3[$id]['当日签收数量']) ? $rs_3[$id]['当日签收数量'] : '';
  121. $val['当日签收金额'] = isset($rs_3[$id]['金额']) ? $rs_3[$id]['金额'] : '';
  122. $val['当日申报发票数量'] = '';
  123. $val['当日申报发票金额'] = '';
  124. $val['单日售后单数'] = isset($rs_4[$id]['单日售后单数']) ? $rs_4[$id]['单日售后单数'] : '';
  125. $val['单日售后金额'] = isset($rs_4[$id]['金额']) ? $rs_4[$id]['金额'] : '';
  126. $val['当日回款单数'] = '';
  127. $val['当日回款金额'] = '';
  128. $list[] = $val;
  129. }
  130. if (empty($list)) $list[] = '没有相关可导出的数据';
  131. excelSave('咨询单报表' . date('YmdHis'), array_keys($list[0]), $list);
  132. }
  133. //【一、管理报表】2.咨询单报表
  134. public function consultInfo()
  135. {
  136. $param = $this->request->only([
  137. 'token',
  138. 'start_date' => '',
  139. 'end_date' => '',
  140. 'page' => 1,
  141. 'size' => 15,
  142. ], 'post', 'trim');
  143. $where = [['ci.is_del', '=', 0]];
  144. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  145. $count = Db::name('consult_info')
  146. ->alias('ci')
  147. ->where($where)
  148. ->order('ci.addtime', 'desc')
  149. ->count('ci.id');
  150. $data = Db::name('consult_info')
  151. ->alias('ci')
  152. ->field('co.creater,ci.addtime,ci.zxNo,csi.companyName,ci.good_name,ci.num,u.unit,ci.budget_price,cb.id bid_id,ci.status,csi.itemid,co.createrid')
  153. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  154. ->leftJoin('unit u', 'u.id=ci.unit')
  155. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  156. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
  157. ->where($where)
  158. ->page($param['page'], $param['size'])
  159. ->order('ci.addtime', 'desc')
  160. ->cursor();
  161. $list = [];
  162. foreach ($data as $value) {
  163. $value['total_fee'] = round($value['budget_price'] * $value['num'], 2);
  164. $value['is_bids'] = is_null($value['bid_id']) ? '否' : '是';
  165. $value['is_zhuandan'] = $value['status'] == 5 ? '是' : '否';//5成功转单
  166. if (!empty($value['itemid'])) {
  167. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  168. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  169. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  170. }
  171. $value['creater_company'] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
  172. $list[] = $value;
  173. }
  174. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  175. }
  176. //【一、管理报表】2.咨询单报表_导出
  177. public function consultInfoExport()
  178. {
  179. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  180. $where = [['ci.is_del', '=', 0]];
  181. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  182. $data = Db::name('consult_info')
  183. ->alias('ci')
  184. ->field('co.creater 创建人,"" 创建人所属部门,ci.addtime 咨询时间,ci.zxNo 咨询单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,ci.good_name 商品名称,ci.num 数量,u.unit 单位,ci.budget_price 单价, "" 金额,cb.id 是否采反,ci.status 是否转单,csi.itemid,co.createrid')
  185. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  186. ->leftJoin('unit u', 'u.id=ci.unit')
  187. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  188. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
  189. ->where($where)
  190. ->order('ci.addtime', 'desc')
  191. ->cursor();
  192. $list = [];
  193. foreach ($data as $value) {
  194. $value['创建人所属部门'] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
  195. $value['金额'] = round($value['单价'] * $value['数量'], 2);
  196. $value['是否采反'] = is_null($value['是否采反']) ? '否' : '是';
  197. $value['是否转单'] = $value['是否转单'] == 5 ? '是' : '否';//5成功转单
  198. if (!empty($value['itemid'])) {
  199. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  200. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  201. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  202. }
  203. unset($value['createrid']);
  204. unset($value['itemid']);
  205. $list[] = $value;
  206. }
  207. if (empty($list)) $list[] = '没有相关可导出的数据';
  208. excelSave('咨询单报表' . date('YmdHis'), array_keys($list[0]), $list);
  209. }
  210. //【一、管理报表】3.订单报表
  211. public function saleList()
  212. {
  213. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 1], 'post', 'trim');
  214. $where = [['s.is_del', '=', 0]];
  215. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  216. $count = Db::name('sale')
  217. ->alias('s')
  218. ->where($where)
  219. ->count('s.id');
  220. $data = Db::name('sale')
  221. ->alias('s')
  222. ->field('s.apply_name,s.addtime,s.orderCode,csi.companyName,s.good_name,s.good_num,s.sale_price,s.total_price,s.is_stock,s.order_type,csi.itemid,s.good_code,s.apply_id')
  223. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  224. ->where($where)
  225. ->page($param['page'], $param['size'])
  226. ->order('s.addtime', 'desc')
  227. ->cursor();
  228. $list = [];
  229. foreach ($data as $value) {
  230. if (!empty($value['itemid'])) {
  231. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  232. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  233. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  234. }
  235. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['unit'] = Db::name("good_zixun")->alias('gz')->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  236. else $value['unit'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  237. $value['is_stock'] = isset($this->all_stock[$value['is_stock']]) ? $this->all_stock[$value['is_stock']] : '';
  238. $value['order_type'] = isset($this->all_order_type[$value['order_type']]) ? $this->all_order_type[$value['order_type']] : '';
  239. $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  240. $list[] = $value;
  241. }
  242. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  243. }
  244. //【一、管理报表】3.订单报表_导出
  245. public function saleExport()
  246. {
  247. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  248. $where = [['s.is_del', '=', 0]];
  249. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  250. $data = Db::name('sale')
  251. ->alias('s')
  252. ->field('s.apply_name 创建人,"" 创建人所属部门,s.addtime 下单时间,s.orderCode 订单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,s.good_name 商品名称,s.good_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,s.is_stock 是否库存,s.order_type 订单类型,csi.itemid,s.good_code,s.apply_id')
  253. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  254. ->where($where)
  255. ->order('s.addtime', 'desc')
  256. ->cursor();
  257. $list = [];
  258. foreach ($data as $value) {
  259. if (!empty($value['itemid'])) {
  260. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  261. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  262. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  263. }
  264. if ($value['订单类型'] == 3 || $value['订单类型'] == 4) {
  265. $value['单位'] = Db::name("good_zixun")
  266. ->alias('gz')
  267. ->leftJoin('unit u', 'u.id=gz.good_unit')
  268. ->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])
  269. ->value('u.unit');
  270. } else {
  271. $value['单位'] = Db::name('good_basic')
  272. ->alias('gb')
  273. ->leftJoin('unit u', 'u.id=gb.good_unit')
  274. ->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])
  275. ->value('u.unit');
  276. }
  277. $value['是否库存'] = isset($this->all_stock[$value['是否库存']]) ? $this->all_stock[$value['是否库存']] : '';
  278. $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
  279. $value['创建人所属部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  280. unset($value['itemid']);
  281. unset($value['apply_id']);
  282. unset($value['good_code']);
  283. $list[] = $value;
  284. }
  285. if (empty($list)) $list[] = '没有相关可导出的数据';
  286. excelSave('订单报表' . date('YmdHis'), array_keys($list[0]), $list);
  287. }
  288. //【一、管理报表】4.未发货报表_列表
  289. public function saleNotOut()
  290. {
  291. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_arrive_date' => '', 'end_arrive_date' => '', 'page' => 1, 'size' => 1], 'post', 'trim');
  292. $where = [['s.is_del', '=', 0]];
  293. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  294. if ($param['start_arrive_date'] != '' && $param['end_arrive_date'] != '') $where[] = ['s.arrive_time', 'between', [$param['start_arrive_date'] . ' 00:00:00', $param['end_arrive_date'] . ' 23:59:59']];
  295. $count = Db::name('sale')
  296. ->alias('s')
  297. ->field('s.apply_name,s.addtime,s.orderCode,csi.companyName,s.good_name,s.good_num,s.sale_price,s.total_price,s.arrive_time,csi.itemid,s.good_code,s.order_type,s.apply_id')
  298. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  299. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  300. ->where($where)
  301. ->order('s.addtime', 'desc')
  302. ->count('s.id');
  303. $data = Db::name('sale')
  304. ->alias('s')
  305. ->field('s.apply_name,s.addtime,s.orderCode,csi.companyName,s.good_name,s.good_num,s.sale_price,s.total_price,s.arrive_time,csi.itemid,s.good_code,s.order_type,s.apply_id')
  306. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  307. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  308. ->where($where)
  309. ->page($param['page'], $param['size'])
  310. ->order('s.addtime', 'desc')
  311. ->cursor();
  312. $list = [];
  313. foreach ($data as $value) {
  314. if (!empty($value['itemid'])) {
  315. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  316. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  317. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  318. }
  319. if ($value['order_type'] == 3 || $value['order_type'] == 4) {
  320. $value['unit'] = Db::name("good_zixun")
  321. ->alias('gz')
  322. ->leftJoin('unit u', 'u.id=gz.good_unit')
  323. ->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])
  324. ->value('u.unit');
  325. } else {
  326. $value['unit'] = Db::name('good_basic')
  327. ->alias('gb')
  328. ->leftJoin('unit u', 'u.id=gb.good_unit')
  329. ->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])
  330. ->value('u.unit');
  331. }
  332. $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  333. $list[] = $value;
  334. }
  335. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  336. }
  337. //【一、管理报表】4.未发货报表_导出
  338. public function saleNotOutExport()
  339. {
  340. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_arrive_date' => '', 'end_arrive_date' => ''], 'post', 'trim');
  341. $where = [['s.is_del', '=', 0]];
  342. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  343. if ($param['start_arrive_date'] != '' && $param['end_arrive_date'] != '') $where[] = ['s.arrive_time', 'between', [$param['start_arrive_date'] . ' 00:00:00', $param['end_arrive_date'] . ' 23:59:59']];
  344. $data = Db::name('sale')
  345. ->alias('s')
  346. ->field('s.apply_name 创建人,"" 创建人所属部门,s.addtime 下单时间,s.orderCode 订单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,s.good_name 商品名称,s.good_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,s.arrive_time 承诺发货时间,csi.itemid,s.good_code,s.order_type,s.apply_id')
  347. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  348. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  349. ->where($where)
  350. ->order('s.addtime', 'desc')
  351. ->cursor();
  352. $list = [];
  353. foreach ($data as $value) {
  354. if (!empty($value['itemid'])) {
  355. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  356. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  357. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  358. }
  359. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['单位'] = Db::name("good_zixun")->alias('gz')->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  360. else $value['单位'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  361. $value['创建人所属部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  362. unset($value['itemid']);
  363. unset($value['good_code']);
  364. unset($value['order_type']);
  365. unset($value['apply_id']);
  366. $list[] = $value;
  367. }
  368. if (empty($list)) $list[] = '没有相关可导出的数据';
  369. excelSave('未发货报表' . date('YmdHis'), array_keys($list[0]), $list);
  370. }
  371. //【一、管理报表】5.未签收报表
  372. public function saleNotSigned()
  373. {
  374. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  375. $where = [['s.is_del', '=', 0], ['oo.status', '=', 2]];
  376. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  377. $count = Db::name('order_out')
  378. ->alias('oo')
  379. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  380. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  381. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  382. ->where($where)
  383. ->count('oo.id');
  384. $data = Db::name('order_out')
  385. ->alias('oo')
  386. ->field('s.apply_name,s.addtime,s.orderCode,csi.companyName,s.good_name,s.good_num,s.sale_price,s.total_price,oo.sendtime,csi.itemid,s.good_code,s.order_type,s.apply_id')
  387. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  388. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  389. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  390. ->where($where)
  391. ->page($param['page'], $param['size'])
  392. ->order('s.addtime', 'desc')
  393. ->cursor();
  394. $list = [];
  395. foreach ($data as $value) {
  396. if (!empty($value['itemid'])) {
  397. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  398. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  399. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  400. }
  401. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['unit'] = Db::name("good_zixun")->alias('gz')->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  402. else $value['unit'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  403. $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  404. $list[] = $value;
  405. }
  406. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  407. }
  408. //【一、管理报表】5.未签收报表_导出
  409. public function saleNotSignedExport()
  410. {
  411. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  412. $where = [['s.is_del', '=', 0], ['oo.status', '=', 2]];
  413. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  414. $data = Db::name('order_out')
  415. ->alias('oo')
  416. ->field('s.apply_name 创建人,"" 创建人所属部门,s.addtime 下单时间,s.orderCode 订单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,s.good_name 商品名称,s.good_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,oo.sendtime 发货时间,csi.itemid,s.good_code,s.order_type,s.apply_id')
  417. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  418. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  419. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  420. ->where($where)
  421. ->order('s.addtime', 'desc')
  422. ->cursor();
  423. $list = [];
  424. foreach ($data as $value) {
  425. if (!empty($value['itemid'])) {
  426. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  427. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  428. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  429. }
  430. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['单位'] = Db::name("good_zixun")->alias('gz')->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  431. else $value['单位'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  432. $value['创建人所属部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  433. unset($value['itemid']);
  434. unset($value['good_code']);
  435. unset($value['order_type']);
  436. unset($value['apply_id']);
  437. $list[] = $value;
  438. }
  439. if (empty($list)) $list[] = '没有相关可导出的数据';
  440. excelSave('未签收报表' . date('YmdHis'), array_keys($list[0]), $list);
  441. }
  442. //【一、管理报表】6.售后报表
  443. public function orderReturn()
  444. {
  445. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'page' => 1, 'size' => 1], 'post', 'trim');
  446. $where = [];
  447. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  448. if ($param['status'] != '') $where[] = ['or.status', '=', $param['status']];
  449. $count = Db::name('order_return')
  450. ->alias('or')
  451. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  452. ->leftJoin('customer_info csi', 'csi.companyNo=or.customer_code')
  453. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  454. ->leftJoin('result_info ri', 'ri.id=or.error_code')
  455. ->where($where)
  456. ->count('or.id');
  457. $data = Db::name('order_return')
  458. ->alias('or')
  459. ->field('or.addtime,or.apply_name,or.orderCode,csi.companyName,or.good_name,or.total_num,s.sale_price,s.total_price,or.updatetime,ri.result,or.status,csi.itemid,or.good_code,or.order_type,or.apply_id')
  460. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  461. ->leftJoin('customer_info csi', 'csi.companyNo=or.customer_code')
  462. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  463. ->leftJoin('result_info ri', 'ri.id=or.error_code')
  464. ->where($where)
  465. ->page($param['page'], $param['size'])
  466. ->order('s.addtime', 'desc')
  467. ->cursor();
  468. $list = [];
  469. foreach ($data as $value) {
  470. if (!empty($value['itemid'])) {
  471. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  472. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  473. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  474. }
  475. $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  476. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['unit'] = Db::name("good_zixun")->alias('gz')->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  477. else $value['unit'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  478. $value['status'] = isset($this->all_order_return_status[$value['status']]) ? $this->all_order_return_status[$value['status']] : '';
  479. $list[] = $value;
  480. }
  481. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  482. }
  483. //【一、管理报表】6.售后报表_导出
  484. public function orderReturnExport()
  485. {
  486. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => ''], 'post', 'trim');
  487. $where = [];
  488. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  489. if ($param['status'] != '') $where[] = ['or.status', '=', $param['status']];
  490. $data = Db::name('order_return')
  491. ->alias('or')
  492. ->field('or.addtime 售后时间,or.apply_name 创建人,"" 创建人部门,or.orderCode 订单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,or.good_name 商品名称,or.total_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,or.updatetime 签收时间,ri.result 异常原因,or.status 异常状态,csi.itemid,or.good_code,or.order_type,or.apply_id')
  493. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  494. ->leftJoin('customer_info csi', 'csi.companyNo=or.customer_code')
  495. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  496. ->leftJoin('result_info ri', 'ri.id=or.error_code')
  497. ->where($where)
  498. ->order('s.addtime', 'desc')
  499. ->cursor();
  500. $list = [];
  501. foreach ($data as $value) {
  502. if (!empty($value['itemid'])) {
  503. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  504. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  505. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  506. }
  507. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['单位'] = Db::name("good_zixun")->alias('gz')->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  508. else $value['单位'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  509. $value['创建人部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  510. $value['异常状态'] = isset($this->all_order_return_status[$value['异常状态']]) ? $this->all_order_return_status[$value['异常状态']] : '';
  511. unset($value['itemid']);
  512. unset($value['good_code']);
  513. unset($value['order_type']);
  514. unset($value['apply_id']);
  515. $list[] = $value;
  516. }
  517. if (empty($list)) $list[] = '没有相关可导出的数据';
  518. excelSave('售后报表' . date('YmdHis'), array_keys($list[0]), $list);
  519. }
  520. //【一、管理报表】7.产品热销排行
  521. public function goodRankingList()
  522. {
  523. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 1], 'post', 'trim');
  524. $where = [['s.is_del', '=', 0]];
  525. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  526. $count = Db::name('sale')
  527. ->alias('s')
  528. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  529. ->where($where)
  530. ->group('s.good_code,s.good_name,csi.itemid,s.cat_id')
  531. ->count('s.id');
  532. $data = Db::name('sale')
  533. ->alias('s')
  534. ->field('s.good_code,s.good_name,SUM(s.good_num) total_num,SUM(s.total_price) total_price,csi.itemid,s.cat_id')
  535. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  536. ->where($where)
  537. ->group('s.good_code,s.good_name,csi.itemid,s.cat_id')
  538. ->page($param['page'], $param['size'])
  539. ->order('total_num', 'desc')
  540. ->cursor();
  541. $list = [];
  542. foreach ($data as $value) {
  543. if (!empty($value['itemid'])) {
  544. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  545. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  546. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  547. }
  548. $value['cat'] = implode('/', array_column(made($value['cat_id']), 'name'));
  549. $list[] = $value;
  550. }
  551. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  552. }
  553. //【一、管理报表】7.产品热销排行_导出
  554. public function goodRankingListExport()
  555. {
  556. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  557. $where = [['s.is_del', '=', 0]];
  558. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  559. $data = Db::name('sale')
  560. ->alias('s')
  561. ->field('s.good_code,"" 产品品类,s.good_name 产品名称,SUM(s.good_num) total_num,"" 数量,SUM(s.total_price) 金额,csi.itemid,s.cat_id')
  562. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  563. ->where($where)
  564. ->group('s.good_code,s.good_name,csi.itemid,s.cat_id')
  565. ->order('total_num', 'desc')
  566. ->cursor();
  567. $list = [];
  568. foreach ($data as $value) {
  569. if (!empty($value['itemid'])) {
  570. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  571. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  572. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  573. }
  574. $value['产品品类'] = implode('/', array_column(made($value['cat_id']), 'name'));
  575. $value['数量'] = $value['total_num'];
  576. unset($value['good_code']);
  577. unset($value['itemid']);
  578. unset($value['cat_id']);
  579. unset($value['total_num']);
  580. $list[] = $value;
  581. }
  582. if (empty($list)) $list[] = '没有相关可导出的数据';
  583. excelSave('产品热销排行' . date('YmdHis'), array_keys($list[0]), $list);
  584. }
  585. //【二、订单导出表】
  586. public function saleDetailed()
  587. {
  588. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'create_company' => '', 'company' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  589. $where = [['s.is_del', '=', 0]];
  590. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  591. if ($param['status'] != '') $where[] = ['s.status', '=', $param['status']];
  592. if ($param['create_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['create_company'] . '%'];
  593. if ($param['company'] != '') $where[] = ['b.company', 'like', '%' . $param['company'] . '%'];
  594. $count = Db::name('sale')
  595. ->alias('s')
  596. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  597. ->leftJoin('business b', 'b.companyNo=s.supplierNo')
  598. ->leftJoin('platform p', 'p.id=s.platform_id')
  599. ->leftJoin('good_basic gb', 'gb.spuCode=s.good_code')
  600. ->leftJoin('order_use ou', 'ou.id=s.use_order')
  601. ->leftJoin('depart_user u', 'u.uid=s.apply_id')
  602. ->leftJoin('company_item ci', 'ci.id=u.itemid')
  603. ->leftJoin('order_num on', 'on.orderCode=s.orderCode')
  604. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  605. ->where($where)
  606. ->order('s.addtime', 'desc')
  607. ->count('s.id');
  608. $data = Db::name('sale')
  609. ->alias('s')
  610. ->field('s.addtime,s.orderCode,s.order_type,s.status,s.apply_name,ci.name,b.company,csi.companyName,p.platform_name,s.platform_order,s.poNo,s.paytime,ou.order_use,s.good_name,gb.tax,s.sale_price,s.good_num,s.total_price,po.cgder,gb.customized,s.arrive_time,s.remark,s.is_stock,csi.itemid,s.cat_id,s.is_activity,s.good_type')
  611. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  612. ->leftJoin('business b', 'b.companyNo=s.supplierNo')
  613. ->leftJoin('platform p', 'p.id=s.platform_id')
  614. ->leftJoin('good_basic gb', 'gb.spuCode=s.good_code')
  615. ->leftJoin('order_use ou', 'ou.id=s.use_order')
  616. ->leftJoin('depart_user u', 'u.uid=s.apply_id')
  617. ->leftJoin('company_item ci', 'ci.id=u.itemid')
  618. ->leftJoin('order_num on', 'on.orderCode=s.orderCode')
  619. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  620. ->where($where)
  621. ->order('s.addtime', 'desc')
  622. ->page($param['page'], $param['size'])
  623. ->cursor();
  624. $list = [];
  625. foreach ($data as $value) {
  626. $value['order_type'] = isset($this->all_order_type[$value['order_type']]) ? $this->all_order_type[$value['order_type']] : '';
  627. $value['status'] = isset($this->all_sale_status[$value['status']]) ? $this->all_sale_status[$value['status']] : '';
  628. if (!empty($value['itemid'])) {
  629. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  630. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  631. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  632. }
  633. $cat = made($value['cat_id']);
  634. $value['first_cat_name'] = isset($cat[0]['name']) ? $cat[0]['name'] : '';
  635. $value['is_stock'] = isset($this->all_stock[$value['is_stock']]) ? $this->all_stock[$value['is_stock']] : '';
  636. $is_activity = isset($this->is_activity[$value['is_activity']]) ? $this->is_activity[$value['is_activity']] : '';
  637. $good_type = isset($this->good_type[$value['good_type']]) ? $this->good_type[$value['good_type']] : '';
  638. $value['activity_type'] = $is_activity . '/' . $good_type;
  639. $list[] = $value;
  640. }
  641. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  642. }
  643. //【二、订单导出表】
  644. public function saleDetailedExport()
  645. {
  646. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'create_company' => '', 'company' => ''], 'post', 'trim');
  647. $where = [['s.is_del', '=', 0]];
  648. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  649. if ($param['status'] != '') $where[] = ['s.status', '=', $param['status']];
  650. if ($param['create_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['create_company'] . '%'];
  651. if ($param['company'] != '') $where[] = ['b.company', 'like', '%' . $param['company'] . '%'];
  652. $data = Db::name('sale')
  653. ->alias('s')
  654. ->field('s.addtime 确认单下单时间,s.orderCode 订单编号,s.order_type 订单类型,s.status 订单状态,s.apply_name 创建人,ci.name 部门,b.company 销售方公司,"" 一级组织,"" 二级组织,csi.companyName 购买方公司,p.platform_name 所属平台,s.platform_order 平台订单号,s.poNo 其他单号,s.paytime 承诺回款时间,ou.order_use 订单用途,"" 活动类型,s.good_name 产品名称,"" 一级分类,gb.tax 税率,s.sale_price 销售单价,s.good_num 下单数量,s.total_price 销售总额,po.cgder 采购人,gb.customized 工期时间,s.arrive_time 要求到货时间,s.remark 备注,s.is_stock 是否库存品,csi.itemid,s.cat_id,s.is_activity,s.good_type')
  655. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  656. ->leftJoin('business b', 'b.companyNo=s.supplierNo')
  657. ->leftJoin('platform p', 'p.id=s.platform_id')
  658. ->leftJoin('good_basic gb', 'gb.spuCode=s.good_code')
  659. ->leftJoin('order_use ou', 'ou.id=s.use_order')
  660. ->leftJoin('depart_user u', 'u.uid=s.apply_id')
  661. ->leftJoin('company_item ci', 'ci.id=u.itemid')
  662. ->leftJoin('order_num on', 'on.orderCode=s.orderCode')
  663. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  664. ->where($where)
  665. ->order('s.addtime', 'desc')
  666. ->cursor();
  667. $list = [];
  668. foreach ($data as $value) {
  669. $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
  670. $value['订单状态'] = isset($this->all_sale_status[$value['订单状态']]) ? $this->all_sale_status[$value['订单状态']] : '';
  671. if (!empty($value['itemid'])) {
  672. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  673. $value['一级组织'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  674. $value['二级组织'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  675. }
  676. $cat = made($value['cat_id']);
  677. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : '';
  678. $value['是否库存品'] = isset($this->all_stock[$value['是否库存品']]) ? $this->all_stock[$value['是否库存品']] : '';
  679. $is_activity = isset($this->is_activity[$value['is_activity']]) ? $this->is_activity[$value['is_activity']] : '';
  680. $good_type = isset($this->good_type[$value['good_type']]) ? $this->good_type[$value['good_type']] : '';
  681. $value['活动类型'] = $is_activity . '/' . $good_type;
  682. unset($value['good_code']);
  683. unset($value['itemid']);
  684. unset($value['cat_id']);
  685. unset($value['is_activity']);
  686. unset($value['good_type']);
  687. $list[] = $value;
  688. }
  689. if (empty($list)) $list[] = '没有相关可导出的数据';
  690. excelSave('订单导出表' . date('YmdHis'), array_keys($list[0]), $list);
  691. }
  692. //【三、咨询单导出明细】
  693. public function consultDetailed()
  694. {
  695. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'use_desc' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  696. $where = [['ci.is_del', '=', 0]];
  697. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  698. if ($param['use_desc'] != '') $where[] = ['ci.use_desc', 'like', '%' . $param['use_desc'] . '%'];
  699. $count = Db::name('sale')
  700. ->alias('s')
  701. ->leftJoin('consult_bids cb', 'cb.bidNo=s.zxNo')
  702. ->leftJoin('consult_info ci', 'ci.zxNo=cb.zxNo')
  703. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  704. ->leftJoin('company_item item', 'item.id=co.depart')
  705. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  706. ->leftJoin('brand b', 'b.id=ci.brand_id')
  707. ->leftJoin('unit u', 'u.id=ci.unit')
  708. ->where($where)
  709. ->order('ci.addtime', 'desc')
  710. ->count('ci.id');
  711. $data = Db::name('sale')
  712. ->alias('s')
  713. ->field('ci.addtime,co.salesman,item.name,cb.zxNo,csi.companyName,ci.use_desc,ci.good_name,b.brand_name,ci.model,s.good_code,ci.cat_id,ci.budget_price,u.unit,ci.num,s.sale_price,ci.arrival_time,ci.is_addrs,ci.is_custom,ci.remark,ci.status,ci.bargain_code,csi.itemid')
  714. ->leftJoin('consult_bids cb', 'cb.bidNo=s.zxNo')
  715. ->leftJoin('consult_info ci', 'ci.zxNo=cb.zxNo')
  716. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  717. ->leftJoin('company_item item', 'item.id=co.depart')
  718. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  719. ->leftJoin('brand b', 'b.id=ci.brand_id')
  720. ->leftJoin('unit u', 'u.id=ci.unit')
  721. ->where($where)
  722. ->page($param['page'], $param['size'])
  723. ->order('ci.addtime', 'desc')
  724. ->cursor();
  725. $list = [];
  726. foreach ($data as $value) {
  727. if (!empty($value['itemid'])) {
  728. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  729. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  730. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  731. }
  732. $cat = made($value['cat_id']);
  733. $value['first_cat_name'] = isset($cat[0]['name']) ? $cat[0]['name'] : '';
  734. $value['budget_total_price'] = round($value['budget_price'] * $value['num'], 2);
  735. $value['is_addrs'] = isset($this->is_addrs[$value['is_addrs']]) ? $this->is_addrs[$value['is_addrs']] : '';
  736. $value['is_custom'] = isset($this->is_custom[$value['is_custom']]) ? $this->is_custom[$value['is_custom']] : '';
  737. $value['status'] = isset($this->consult_info_status[$value['status']]) ? $this->consult_info_status[$value['status']] : '';
  738. $list[] = $value;
  739. }
  740. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  741. }
  742. //【三、咨询单导出明细】
  743. public function consultDetailedExport()
  744. {
  745. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'use_desc' => ''], 'post', 'trim');
  746. $where = [['s.order_type', '=', 3], ['s.is_del', '=', 0]];
  747. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  748. if ($param['use_desc'] != '') $where[] = ['ci.use_desc', '=', $param['use_desc']];
  749. $data = Db::name('sale')
  750. ->alias('s')
  751. ->field('ci.addtime 咨询时间,co.salesman 业务员,item.name 业务部门,cb.zxNo 咨询单号,"" 一级组织,"" 二级组织,csi.companyName 客户名称,ci.use_desc 产品用途,ci.good_name 产品名称,b.brand_name 品牌,ci.model 型号,s.good_code 产品编码,"" 一级分类,ci.cat_id,ci.budget_price 预算单价,u.unit 单位,ci.num 需求数量,"" 预算总价,s.sale_price 单价,ci.arrival_time 要求到货时间,ci.is_addrs 是否一地,ci.is_custom 定制,ci.remark 咨询备注,ci.status 竞单状态,ci.bargain_code 上次咨询单单号,csi.itemid')
  752. ->leftJoin('consult_bids cb', 'cb.bidNo=s.zxNo')
  753. ->leftJoin('consult_info ci', 'ci.zxNo=cb.zxNo')
  754. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  755. ->leftJoin('company_item item', 'item.id=co.depart')
  756. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  757. ->leftJoin('brand b', 'b.id=ci.brand_id')
  758. ->leftJoin('unit u', 'u.id=ci.unit')
  759. ->where($where)
  760. ->order('ci.addtime', 'desc')
  761. ->cursor();
  762. $list = [];
  763. foreach ($data as $value) {
  764. if (!empty($value['itemid'])) {
  765. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  766. $value['一级组织'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  767. $value['二级组织'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  768. }
  769. $cat = made($value['cat_id']);
  770. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : '';
  771. $value['预算总价'] = round($value['预算单价'] * $value['需求数量'], 2);
  772. $value['是否一地'] = isset($this->is_addrs[$value['是否一地']]) ? $this->is_addrs[$value['是否一地']] : '';
  773. $value['定制'] = isset($this->is_custom[$value['定制']]) ? $this->is_custom[$value['定制']] : '';
  774. $value['竞单状态'] = isset($this->consult_info_status[$value['竞单状态']]) ? $this->consult_info_status[$value['竞单状态']] : '';
  775. unset($value['itemid']);
  776. unset($value['cat_id']);
  777. $list[] = $value;
  778. }
  779. if (empty($list)) $list[] = '没有相关可导出的数据';
  780. excelSave('咨询单导出明细' . date('YmdHis'), array_keys($list[0]), $list);
  781. }
  782. //【四、工差明细表】
  783. public function saleDiff()
  784. {
  785. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  786. $where = [['pd.is_del', '=', 0]];
  787. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['pd.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  788. $count = Db::name('purchease_diff')
  789. ->alias('pd')
  790. ->leftJoin('sale_diff sd', 'sd.cgd_diffid=pd.id')
  791. ->leftJoin('purchease_order po', 'po.cgdNo=pd.cgdNo')
  792. ->leftJoin('business b', 'b.companyNo=po.companyNo')
  793. ->leftJoin('good_basic gb', 'gb.spuCode=po.spuCode')
  794. ->where($where)
  795. ->order('pd.addtime', 'desc')
  796. ->count('pd.id');
  797. $data = Db::name('purchease_diff')
  798. ->alias('pd')
  799. ->field('pd.addtime,sd.diffCode,sd.orderCode,pd.apply_name,pd.apply_id,po.addtime poaddtime,pd.good_name,b.company,gb.noble_metal,pd.good_num,pd.sale_price,pd.good_weight,pd.diff_weight,pd.diff_price,sd.status')
  800. ->leftJoin('sale_diff sd', 'sd.cgd_diffid=pd.id')
  801. ->leftJoin('purchease_order po', 'po.cgdNo=pd.cgdNo')
  802. ->leftJoin('business b', 'b.companyNo=po.companyNo')
  803. ->leftJoin('good_basic gb', 'gb.spuCode=po.spuCode')
  804. ->where($where)
  805. ->page($param['page'], $param['size'])
  806. ->order('pd.addtime', 'desc')
  807. ->cursor();
  808. $list = [];
  809. foreach ($data as $value) {
  810. $value['apply_company'] = get_company_name_by_uid($value['apply_id']);
  811. $value['noble_metal'] = isset($this->noble_metal[$value['noble_metal']]) ? $this->noble_metal[$value['noble_metal']] : '';
  812. $value['total_price'] = round($value['sale_price'], $value['good_num'], 2);
  813. $value['is_update_sale'] = isset($this->sale_diff_status[$value['status']]) ? $this->sale_diff_status[$value['status']] : '';
  814. $list[] = $value;
  815. }
  816. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  817. }
  818. //【四、工差明细表】
  819. public function saleDiffExport()
  820. {
  821. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  822. $where = [['pd.is_del', '=', 0]];
  823. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['pd.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  824. $data = Db::name('purchease_diff')
  825. ->alias('pd')
  826. ->field('pd.addtime 发起时间,sd.diffCode 工差单号,sd.orderCode 关联确认单,pd.apply_name 创建人,"" 部门,pd.apply_id,po.addtime 确认单下单日期,pd.good_name 产品名称,b.company 客户名称,gb.noble_metal 贵金属种类,pd.good_num 下单数量,pd.sale_price 单价,"" 总额,pd.good_weight 商品总重量,pd.diff_weight 工差重量,pd.diff_price 销售工差总费用,sd.status 是否修改销售额')
  827. ->leftJoin('sale_diff sd', 'sd.cgd_diffid=pd.id')
  828. ->leftJoin('purchease_order po', 'po.cgdNo=pd.cgdNo')
  829. ->leftJoin('business b', 'b.companyNo=po.companyNo')
  830. ->leftJoin('good_basic gb', 'gb.spuCode=po.spuCode')
  831. ->where($where)
  832. ->order('pd.addtime', 'desc')
  833. ->cursor();
  834. $list = [];
  835. foreach ($data as $value) {
  836. $value['部门'] = get_company_name_by_uid($value['apply_id']);
  837. $value['贵金属种类'] = isset($this->noble_metal[$value['贵金属种类']]) ? $this->noble_metal[$value['贵金属种类']] : '';
  838. $value['总额'] = round($value['单价'], $value['下单数量'], 2);
  839. $value['是否修改销售额'] = isset($this->sale_diff_status[$value['是否修改销售额']]) ? $this->sale_diff_status[$value['是否修改销售额']] : '';
  840. unset($value['apply_id']);
  841. $list[] = $value;
  842. }
  843. if (empty($list)) $list[] = '没有相关可导出的数据';
  844. excelSave('工差明细表' . date('YmdHis'), array_keys($list[0]), $list);
  845. }
  846. //【五、退货明细表】
  847. public function thDataExport()
  848. {
  849. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  850. $where = [['pd.is_del', '=', 0]];
  851. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['pd.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  852. $data = Db::name('th_data')
  853. ->alias('pd')
  854. ->field('pd.addtime 退货时间,pd. 退货单号')
  855. // ->field('pd.addtime 发起时间,sd.diffCode 工差单号,sd.orderCode 关联确认单,pd.apply_name 创建人,"" 部门,pd.apply_id,po.addtime 确认单下单日期,pd.good_name 产品名称,b.company 客户名称,gb.noble_metal 贵金属种类,pd.good_num 下单数量,pd.sale_price 单价,"" 总额,pd.good_weight 商品总重量,pd.diff_weight 工差重量,pd.diff_price 销售工差总费用,sd.is_act 是否修改销售额')
  856. ->leftJoin('sale_diff sd', 'sd.cgd_diffid=pd.id')
  857. ->leftJoin('purchease_order po', 'po.cgdNo=pd.cgdNo')
  858. ->leftJoin('business b', 'b.companyNo=po.companyNo')
  859. ->leftJoin('good_basic gb', 'gb.spuCode=po.spuCode')
  860. ->where($where)
  861. ->order('pd.addtime', 'desc')
  862. ->cursor();
  863. $list = [];
  864. foreach ($data as $value) {
  865. $value['部门'] = get_company_name_by_uid($value['apply_id']);
  866. $value['贵金属种类'] = isset($this->noble_metal[$value['贵金属种类']]) ? $this->noble_metal[$value['贵金属种类']] : '';
  867. $value['总额'] = round($value['单价'], $value['下单数量'], 2);
  868. $value['是否修改销售额'] = isset($this->is_act[$value['是否修改销售额']]) ? $this->is_act[$value['是否修改销售额']] : '';
  869. unset($value['apply_id']);
  870. $list[] = $value;
  871. }
  872. if (empty($list)) $list[] = '没有相关可导出的数据';
  873. excelSave('工差明细表' . date('YmdHis'), array_keys($list[0]), $list);
  874. }
  875. }