ExportService.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/13
  6. * Time: 下午2:04
  7. */
  8. namespace app\backend\modules\order\services;
  9. use app\backend\modules\order\services\models\ExcelModel;
  10. class ExportService
  11. {
  12. public $columns;
  13. public function __construct()
  14. {
  15. $this->columns = $this->getColumns();
  16. }
  17. public function export($orders)
  18. {
  19. foreach ($orders as &$order) {
  20. $order = $this->getOrder($order);
  21. }
  22. unset($order);
  23. $excel = new ExcelModel($this->columns);
  24. $excel->export($orders, [
  25. 'title' => '订单-' . date("Y-m-d-H-i", time()),
  26. 'columns' => $this->columns
  27. ]);
  28. }
  29. protected function getOrder($order){
  30. $order['pay_sn'] = $order['has_one_order_pay']['pay_sn'];
  31. $order['uid'] = $order['belongs_to_member']['uid'];
  32. $order['nickname'] = $order['belongs_to_member']['nickname'];
  33. $order['realname'] = $order['address']['realname'];
  34. $order['mobile'] = $order['address']['mobile'];
  35. $order['address'] = $order['address']['address'];
  36. $order += $this->getGoods($order);
  37. $order += $this->getStatus($order);
  38. $order += $this->setOrder($order);
  39. $order['pay_type'] = $order['has_one_pay_type']['name'];
  40. $order['pay_sn'] = $order['has_one_order_pay']['pay_sn'];
  41. $order['remark'] = $order['has_one_order_remark']['remark'];
  42. // $order['note'] = $order['note'];
  43. $order['express_company_name'] = $order['express']['express_company_name'];
  44. $order['express_sn'] = $order['express']['express_sn'];
  45. if (empty(strtotime($order['finish_time']))) {
  46. $order['finish_time'] = '';
  47. }
  48. if (empty(strtotime($order['pay_time']))) {
  49. $order['pay_time'] = '';
  50. }
  51. if (empty(strtotime($order['send_time']))) {
  52. $order['send_time'] = '';
  53. }
  54. return $order;
  55. }
  56. protected function setOrder($order)
  57. {
  58. return [];
  59. }
  60. protected function getStatus($order)
  61. {
  62. if ($order['status'] == 0) {
  63. $order['status'] = '待付款';
  64. } else if ($order['status'] == 1) {
  65. $order['status'] = '已支付';
  66. } else if ($order['status'] == 2) {
  67. $order['status'] = '待收货';
  68. } else if ($order['status'] == 3) {
  69. $order['status'] = '已完成';
  70. } else if ($order['status'] == -1) {
  71. $order['status'] = '已关闭';
  72. }
  73. return $order;
  74. }
  75. protected function getGoods($order)
  76. {
  77. $order['goods_title'] = '';
  78. $order['goods_sn'] = '';
  79. $order['total'] = '';
  80. foreach ($order['has_many_order_goods'] as $key => $goods) {
  81. $goods_title = $goods['title'];
  82. if ($goods['goods_option_title']) {
  83. $goods_title .= '['. $goods['goods_option_title'] .']';
  84. }
  85. $order['goods_title'] .= '【' . $goods_title . '*' . $goods['total'] . '】';
  86. $order['goods_sn'] .= $goods['goods']['goods_sn'].'/';
  87. $order['total'] .= $goods['total'].'/';
  88. }
  89. return $order;
  90. }
  91. protected function getColumns()
  92. {
  93. return [
  94. [
  95. "title" => "订单编号",
  96. "field" => "order_sn",
  97. "width" => 24
  98. ] ,
  99. [
  100. "title" => "支付单号",
  101. "field" => "pay_sn",
  102. "width" => 24
  103. ] ,
  104. [
  105. "title" => "粉丝ID",
  106. "field" => "uid",
  107. "width" => 12
  108. ] ,
  109. [
  110. "title" => "粉丝昵称",
  111. "field" => "nickname",
  112. "width" => 12
  113. ] ,
  114. [
  115. "title" => "会员姓名",
  116. "field" => "realname",
  117. "width" => 12
  118. ] ,
  119. [
  120. "title" => "联系电话",
  121. "field" => "mobile",
  122. "width" => 12
  123. ] ,
  124. [
  125. "title" => "收货地址",
  126. "field" => "address",
  127. "width" => 30
  128. ] ,
  129. [
  130. "title" => "商品名称",
  131. "field" => "goods_title",
  132. "width" => 24
  133. ] ,
  134. [
  135. "title" => "商品编码",
  136. "field" => "goods_sn",
  137. "width" => 12
  138. ] ,
  139. [
  140. "title" => "商品数量",
  141. "field" => "total",
  142. "width" => 12
  143. ] ,
  144. [
  145. "title" => "支付方式",
  146. "field" => "pay_type",
  147. "width" => 12
  148. ] ,
  149. [
  150. "title" => "商品小计",
  151. "field" => "goods_price",
  152. "width" => 12
  153. ] ,
  154. [
  155. "title" => "运费",
  156. "field" => "dispatch_price",
  157. "width" => 12
  158. ] ,
  159. [
  160. "title" => "应收款",
  161. "field" => "price",
  162. "width" => 12
  163. ] ,
  164. [
  165. "title" => "状态",
  166. "field" => "status_name",
  167. "width" => 12
  168. ] ,
  169. [
  170. "title" => "下单时间",
  171. "field" => "create_time",
  172. "width" => 24
  173. ] ,
  174. [
  175. "title" => "付款时间",
  176. "field" => "pay_time",
  177. "width" => 24
  178. ] ,
  179. [
  180. "title" => "发货时间",
  181. "field" => "send_time",
  182. "width" => 24
  183. ] ,
  184. [
  185. "title" => "完成时间",
  186. "field" => "finish_time",
  187. "width" => 24
  188. ] ,
  189. [
  190. "title" => "快递公司",
  191. "field" => "express_company_name",
  192. "width" => 24
  193. ] ,
  194. [
  195. "title" => "快递单号",
  196. "field" => "express_sn",
  197. "width" => 24
  198. ] ,
  199. [
  200. "title" => "订单备注",
  201. "field" => "remark",
  202. "width" => 36
  203. ],
  204. [
  205. "title" => "用户备注",
  206. "field" => "note",
  207. "width" => 36
  208. ],
  209. ];
  210. }
  211. }