Orders.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Http\Requests\Admin\Orders as Request;
  3. use App\Models\Custom;
  4. use App\Models\CustomAddr;
  5. use App\Models\CustomScore;
  6. use App\Models\FilesManager;
  7. use App\Models\Product;
  8. use App\Models\Orders as Model;
  9. use App\Models\OrdersAddr;
  10. use App\Models\OrdersProduct;
  11. use Illuminate\Support\Facades\DB;
  12. use PhpOffice\PhpSpreadsheet\IOFactory;
  13. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  14. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  15. use PhpOffice\PhpSpreadsheet\Style\Fill;
  16. /**
  17. * 订单管理
  18. *
  19. * @author 刘相欣
  20. *
  21. */
  22. class Orders extends Auth{
  23. protected function _initialize(){
  24. parent::_initialize();
  25. $this->assign('breadcrumb1','销售管理');
  26. $this->assign('breadcrumb2','订单管理');
  27. }
  28. /**
  29. * 首页列表
  30. *
  31. * */
  32. public function index(Model $Model,OrdersProduct $OrdersProduct,Product $Product,Custom $Custom){
  33. // 接受参数
  34. $code = request('order_code','');
  35. $productCode = request('product_code','');
  36. $phone = request('phone','');
  37. $customCode = request('custom_code','');
  38. $productName = request('product_name','');
  39. $province = request('contact_province','');
  40. $city = request('contact_city','');
  41. $area = request('contact_area','');
  42. $status = request('status',0);
  43. $startTime = request('start_time','');
  44. $endTime = request('end_time','');
  45. // 编码转ID
  46. $id = $code ? $Model->codeToId($code) : 0;
  47. $productId = $productCode ? $Product->codeToId($productCode) : 0;
  48. $uid = $customCode ? $Custom->codeToId($customCode) : 0;
  49. // 查询条件
  50. $map = [];
  51. // 编码ID
  52. if( $id ) $map[] = ['orders_product.order_id','=',$id];
  53. if( $uid ) $map[] = ['custom.uid','=',$uid];
  54. if( $productId ) $map[] = ['orders_product.product_id','=',$productId];
  55. if( $productName ) $map[] = ['orders_product.product_name','=',$productName];
  56. if( $phone ) $map[] = ['orders_addr.contact_phone','=',$phone];
  57. if( $province ) $map[] = ['orders_addr.contact_province','LIKE','%'.$province.'%'];
  58. if( $city ) $map[] = ['orders_addr.contact_city','LIKE','%'.$city.'%'];
  59. if( $area ) $map[] = ['orders_addr.contact_area','LIKE','%'.$area.'%'];
  60. if( $startTime ) $map[] = ['orders_product.insert_time','>=',strtotime($startTime)];
  61. if( $endTime ) $map[] = ['orders_product.insert_time','<=',strtotime($endTime)];
  62. if( $status ) $map[] = ['orders_product.status','=',$status];
  63. // 查询数据
  64. $list = $OrdersProduct->query()
  65. ->join('custom','orders_product.custom_uid','=','custom.uid')
  66. ->join('orders_addr','orders_addr.order_id','=','orders_product.order_id')
  67. ->where($map)
  68. ->orderByDesc('id')
  69. ->select([
  70. 'orders_product.*','custom.username as custom_name',
  71. 'orders_addr.contact_name','orders_addr.contact_shop','orders_addr.contact_phone','orders_addr.contact_province','orders_addr.contact_city','orders_addr.contact_area','orders_addr.contact_addr'
  72. ])
  73. ->paginate(request('limit',config('page_num',10)))->appends(request()->all());
  74. // 循环处理数据
  75. foreach ($list as $key => $value) {
  76. // id转编号
  77. $value['order_code'] = $Model->idToCode($value['order_id']);
  78. $value['custom_code'] = $Custom->idToCode($value['custom_uid']);
  79. $value['state'] = $Model->getState($value['status'],'state');
  80. $value['product_code'] = $Product->idToCode($value['product_id']);
  81. // 重组
  82. $list[$key] = $value;
  83. }
  84. // 分配数据
  85. $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
  86. $this->assign('list', $list);
  87. // 加载模板
  88. return $this->fetch();
  89. }
  90. /**
  91. * 状态
  92. *
  93. * */
  94. public function set_status( Request $request, Model $Model,OrdersProduct $OrdersProduct,CustomScore $CustomScore){
  95. // 验证参数
  96. $request->scene('set_status')->validate();
  97. // 接收参数
  98. $id = request('id',0);
  99. $status = request('status',0);
  100. // 获取产品和数量
  101. $oldData = $Model->query()->find($id,['id','order_score','custom_uid','insert_time']);
  102. // 如果用户不存在
  103. if( !$oldData ) return json_send(['code'=>'error','msg'=>'订单不存在']);
  104. // 组合数据,写入订单表,子表
  105. DB::beginTransaction();
  106. try{
  107. // 查询数据
  108. $result = $Model->setOrderStatus($id,$status,$OrdersProduct);
  109. // 提示新增失败
  110. if( isset($result['error']) ) {
  111. // 回退数据
  112. DB::rollBack();
  113. // 提示信息
  114. return json_send(['code'=>'error','msg'=>$result['error'],'data'=>['error'=>$result['error']]]);
  115. }
  116. if( $status == 4 ){
  117. // 取消积分
  118. if( $oldData['order_score'] > 0 ) {
  119. // 如果扣减失败
  120. $result = $CustomScore->trade($oldData['custom_uid'],$oldData['id'],($oldData['order_score']*-1),6,1);
  121. // 提示新增失败
  122. if( isset($result['error']) ) {
  123. // 回退数据
  124. DB::rollBack();
  125. // 提示信息
  126. return json_send(['code'=>'error','msg'=>'取消赠送积分失败','data'=>['error'=>$result['error']]]);
  127. }
  128. }
  129. // 取消关联订单
  130. $result = $Model->cancelRelate($oldData['insert_time'],$oldData['custom_uid'],$OrdersProduct,$CustomScore);
  131. // 提示新增失败
  132. if( isset($result['error']) ) {
  133. // 回退数据
  134. DB::rollBack();
  135. // 提示信息
  136. return json_send(['code'=>'error','msg'=>'取消关联订单失败','data'=>['error'=>$result['error']]]);
  137. }
  138. }
  139. // 提交数据
  140. DB::commit();
  141. // 告知结果
  142. return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
  143. // 返回结果
  144. } catch (\Throwable $th) {
  145. // 回退数据
  146. DB::rollBack();
  147. // 下单失败提示
  148. return json_send(['code'=>'error','msg'=>'设置失败','data'=>['error'=>$th->getMessage().$th->getLine()]]);
  149. }
  150. }
  151. /**
  152. * 表格导入
  153. *
  154. * */
  155. public function import_execl( Request $request,Model $Model,Custom $Custom,OrdersAddr $OrdersAddr,OrdersProduct $OrdersProduct, FilesManager $FilesManager,CustomAddr $CustomAddr){
  156. // 验证参数
  157. $request->scene('import_execl')->validate();
  158. // 获取表格信息
  159. $file = request()->file('order_file');
  160. // 返回结果
  161. $sheetList = $FilesManager->excelToOrder($file);
  162. // 如果不存在结果
  163. if( isset($sheetList['error']) ) return json_send(['code'=>'error','msg'=>$sheetList['error']]);
  164. // 订单列表
  165. $orderList = [];
  166. // 当前时间
  167. $time = time();
  168. // 循环表格数据
  169. foreach ($sheetList as $value) {
  170. // 状态更改
  171. $value['status'] = $Model->getWeibanStatus($value['status']);
  172. // 客户手机号
  173. $orderList[$value['weizan_orderid']]['custom'] = ['phone'=>$value['contact_phone'],'username'=>$value['buyer_nick']];
  174. // 组合成订单的收件地址
  175. $orderList[$value['weizan_orderid']]['contact'] = [
  176. 'contact_name'=>$value['contact_name'],
  177. 'contact_phone'=>$value['contact_phone'],
  178. 'contact_province'=>$value['contact_province'],
  179. 'contact_city'=>$value['contact_city'],
  180. 'contact_area'=>$value['contact_area'],
  181. 'contact_addr'=>$value['contact_addr']
  182. ];
  183. // 组合成订单的收件地址
  184. $orderList[$value['weizan_orderid']]['product'][] = [
  185. 'status'=>$value['status'],
  186. 'product_name'=>$value['product_name'],
  187. 'sku_attr_names'=>$value['sku_attr_names'],
  188. 'buy_num'=>$value['buy_num'],
  189. 'pay_total'=>$value['pay_total'],
  190. 'price_total'=>$value['pay_total'],
  191. 'insert_time'=>$value['insert_time'],
  192. 'update_time'=>$time,
  193. ];
  194. // 组合成订单的需要的数据
  195. if( !isset($orderList[$value['weizan_orderid']]['order']) ) $orderList[$value['weizan_orderid']]['order'] = ['weizan_orderid'=>$value['weizan_orderid'],'status'=>$value['status'],'pay_total'=>0,'price_total'=>0,'insert_time'=>$value['insert_time']];
  196. // 价格
  197. $orderList[$value['weizan_orderid']]['order']['pay_total'] = $orderList[$value['weizan_orderid']]['order']['pay_total'] + $value['pay_total'];
  198. $orderList[$value['weizan_orderid']]['order']['price_total'] = $orderList[$value['weizan_orderid']]['order']['pay_total'];
  199. }
  200. // 新增地址
  201. $newAddrList = [];
  202. // 要更新的订单子表
  203. $orderProduct = [];
  204. // 循环订单列表
  205. foreach ($orderList as $value) {
  206. // 获取手机号,查询是否用客户
  207. $custom = $Custom->getOneByPhone($value['custom']['phone']);
  208. // 如果存在手机号
  209. $uid = $custom ? $custom['uid'] : $Custom->add($value['custom']);
  210. // 如果客户存在
  211. if( !$uid ) return json_send(['code'=>'error','msg'=>$value['custom']['username'].'【'.$value['custom']['phone'].'】'.'无法创建用户']);
  212. // 通过订单号查询是否存在系统订单
  213. $orderId = $Model->query()->where([['weizan_orderid','=',$value['order']['weizan_orderid']]])->value('id');
  214. // 客户ID
  215. $value['order']['custom_uid'] = $uid;
  216. // 存在订单获取订单ID,不存在则新增
  217. $orderId = $orderId ? $Model->edit($orderId,$value['order']) : $Model->add($value['order']);
  218. // 如果客户存在
  219. if( !$orderId ) return json_send(['code'=>'error','msg'=>$orderId.'订单写入失败']);
  220. // 联系地址
  221. $contact = $value['contact'];
  222. // 存在详细地址,才创建地址库
  223. if( $contact['contact_name'] && $contact['contact_phone'] && $contact['contact_province'] && $contact['contact_city'] && $contact['contact_area'] && $contact['contact_addr'] ) {
  224. // 收件地址是否存在
  225. $oldAddr = $CustomAddr->query()->where([['custom_uid','=',$uid]])->first();
  226. // 如果不存在地址
  227. if( !$oldAddr ) $CustomAddr->add(['custom_uid'=>$uid,'contact_name'=>$contact['contact_name'],'contact_phone'=>$contact['contact_phone'],'contact_province'=>$contact['contact_province'],'contact_city'=>$contact['contact_city'],'contact_area'=>$contact['contact_area'],'contact_addr'=>$contact['contact_addr']]);
  228. }
  229. // 订单地址库
  230. $addrId = $OrdersAddr->query()->where([['order_id','=',$orderId]])->value('id');
  231. // 订单ID
  232. $value['contact']['order_id'] = $orderId;
  233. // 订单地址ID
  234. $value['contact']['id'] = (int)$addrId;
  235. // 不存在地址的话
  236. $newAddrList[] = $value['contact'];
  237. // 循环子订单
  238. foreach ( $value['product'] as $product ) {
  239. // 数据结果
  240. $product['order_id'] = $orderId;
  241. $product['custom_uid'] = $uid;
  242. $product['id'] = (int) $OrdersProduct->query()->where([['order_id','=',$orderId],'product_name'=>$product['product_name'],'sku_attr_names'=>$product['sku_attr_names']])->value('id');
  243. $orderProduct[] = $product;
  244. }
  245. }
  246. // 新地址写入
  247. $OrdersProduct->query()->upsert($orderProduct,'id',['product_name','sku_attr_names','buy_num','pay_total','price_total','update_time']);
  248. // 新地址写入
  249. $OrdersAddr->query()->upsert($newAddrList,'id',['contact_name','contact_phone','contact_province','contact_city','contact_area','contact_addr']);
  250. // 提示成功
  251. return json_send(['code'=>'success','msg'=>'订单导入成功','path'=>'']);
  252. }
  253. /**
  254. * 导出表格导入
  255. *
  256. * */
  257. public function down_excel(Model $Model,OrdersProduct $OrdersProduct,Product $Product,Custom $Custom){
  258. // 接受参数
  259. $code = request('order_code','');
  260. $productCode = request('product_code','');
  261. $customCode = request('custom_code','');
  262. $productName = request('product_name','');
  263. $phone = request('phone','');
  264. $province = request('contact_province','');
  265. $city = request('contact_city','');
  266. $area = request('contact_area','');
  267. $status = request('status',0);
  268. $startTime = request('start_time','');
  269. $endTime = request('end_time','');
  270. // 编码转ID
  271. $id = $code ? $Model->codeToId($code) : 0;
  272. $productId = $productCode ? $Product->codeToId($productCode) : 0;
  273. $uid = $customCode ? $Custom->codeToId($customCode) : 0;
  274. // 查询条件
  275. $map = [];
  276. // 编码ID
  277. if( $id ) $map[] = ['orders_product.order_id','=',$id];
  278. if( $uid ) $map[] = ['custom.uid','=',$uid];
  279. if( $productId ) $map[] = ['orders_product.product_id','=',$productId];
  280. if( $productName ) $map[] = ['orders_product.product_name','=',$productName];
  281. if( $phone ) $map[] = ['orders_addr.contact_phone','=',$phone];
  282. if( $province ) $map[] = ['orders_addr.contact_province','LIKE','%'.$province.'%'];
  283. if( $city ) $map[] = ['orders_addr.contact_city','LIKE','%'.$city.'%'];
  284. if( $area ) $map[] = ['orders_addr.contact_area','LIKE','%'.$area.'%'];
  285. if( $startTime ) $map[] = ['orders_product.insert_time','>=',strtotime($startTime)];
  286. if( $endTime ) $map[] = ['orders_product.insert_time','<=',strtotime($endTime)];
  287. if( $status ) $map[] = ['orders_product.status','=',$status];
  288. // 查询数据
  289. $list = $OrdersProduct->query()
  290. ->join('custom','orders_product.custom_uid','=','custom.uid')
  291. ->join('orders_addr','orders_addr.order_id','=','orders_product.order_id')
  292. ->where($map)
  293. ->orderByDesc('orders_product.id')
  294. ->select([
  295. 'orders_product.id as id',
  296. 'orders_product.order_id',
  297. 'orders_product.custom_uid',
  298. 'orders_product.product_name',
  299. 'orders_product.sku_attr_names as product_spec',
  300. 'orders_product.product_thumb',
  301. 'orders_product.buy_num',
  302. 'orders_product.price_total',
  303. 'orders_product.coupon_total',
  304. 'orders_product.pay_total',
  305. 'orders_product.status',
  306. 'orders_product.insert_time',
  307. 'custom.username as custom_name','custom.weiban_extid as weiban_extid',
  308. 'orders_addr.contact_name','orders_addr.contact_shop','orders_addr.contact_phone','orders_addr.contact_province','orders_addr.contact_city','orders_addr.contact_area','orders_addr.contact_addr'
  309. ])->get()->toArray();
  310. // 返回结果
  311. $data = [];
  312. // 循环处理数据
  313. foreach ($list as $value) {
  314. // id转编号
  315. $value['order_id'] = $Model->idToCode($value['order_id']);
  316. $value['status'] = $Model->getState($value['status'],'state');
  317. $value['custom_uid'] = $Custom->idToCode($value['custom_uid']);
  318. $value['product_price'] = $value['buy_num'] ? ($value['price_total'] / $value['buy_num']) : $value['buy_num'];
  319. $value['pay_price'] = $value['buy_num'] ? ($value['pay_total'] / $value['buy_num']) : $value['buy_num'];
  320. // 重组
  321. $data[$value['order_id']]['order_id'] = $value['order_id'];
  322. $data[$value['order_id']]['custom_uid'] = $value['custom_uid'];
  323. $data[$value['order_id']]['custom_name'] = $value['custom_name'];
  324. $data[$value['order_id']]['weiban_extid'] = $value['weiban_extid'];
  325. $data[$value['order_id']]['status'] = $value['status'];
  326. $data[$value['order_id']]['insert_time'] = $value['insert_time'];
  327. // 地址
  328. $data[$value['order_id']]['contact_name'] = $value['contact_name'];
  329. $data[$value['order_id']]['contact_phone'] = $value['contact_phone'];
  330. $data[$value['order_id']]['contact_province'] = $value['contact_province'];
  331. $data[$value['order_id']]['contact_city'] = $value['contact_city'];
  332. $data[$value['order_id']]['contact_area'] = $value['contact_area'];
  333. $data[$value['order_id']]['contact_addr'] = $value['contact_addr'] .($value['contact_shop'] ? '【'.$value['contact_shop'].'】' : '');
  334. // 子订单
  335. $data[$value['order_id']]['product'][] = ['product_name'=>$value['product_name'],'product_spec'=>$value['product_spec'],'product_thumb'=>$value['product_thumb'],'product_price'=>$value['product_price'],'pay_price'=>$value['pay_price'],'buy_num'=>$value['buy_num'],'pay_total'=>$value['pay_total'],'price_total'=>$value['price_total'],'coupon_total'=>$value['coupon_total']];
  336. }
  337. try {
  338. // 去下载
  339. $this->toDown($data);
  340. } catch (\Throwable $th) {
  341. echo $th->getMessage();
  342. }
  343. }
  344. /**
  345. * 去下载
  346. */
  347. private function toDown($data){
  348. // 创建新的电子表格对象
  349. $spreadsheet = new Spreadsheet();
  350. // 设置合并单元格的行和列,例如合并A1到B2的单元格
  351. $sheet = $this->setStyle($spreadsheet);
  352. // 从第二行写入
  353. $row = 2;
  354. // 循环写入
  355. foreach ($data as $key => $value) {
  356. // 如果有多个商品
  357. $count = count($value['product']);
  358. // 如果有多个商品
  359. if( $count > 1 ) {
  360. // 合并单元格
  361. $sheet->mergeCells('A'.$row.':'.'A'.($row+$count-1));
  362. $sheet->mergeCells('B'.$row.':'.'B'.($row+$count-1));
  363. $sheet->mergeCells('C'.$row.':'.'C'.($row+$count-1));
  364. $sheet->mergeCells('D'.$row.':'.'D'.($row+$count-1));
  365. $sheet->mergeCells('E'.$row.':'.'E'.($row+$count-1));
  366. $sheet->mergeCells('F'.$row.':'.'F'.($row+$count-1));
  367. $sheet->mergeCells('G'.$row.':'.'G'.($row+$count-1));
  368. $sheet->mergeCells('H'.$row.':'.'H'.($row+$count-1));
  369. $sheet->mergeCells('I'.$row.':'.'I'.($row+$count-1));
  370. $sheet->mergeCells('J'.$row.':'.'J'.($row+$count-1));
  371. $sheet->mergeCells('R'.$row.':'.'R'.($row+$count-1));
  372. $sheet->mergeCells('S'.$row.':'.'S'.($row+$count-1));
  373. }
  374. // 单元格内容写入
  375. $sheet->setCellValue('A'.$row, $value['order_id']);
  376. $sheet->setCellValue('B'.$row, $value['custom_uid']);
  377. $sheet->setCellValue('C'.$row, $value['custom_name']);
  378. $sheet->setCellValue('D'.$row, $value['status']);
  379. $sheet->setCellValue('E'.$row, $value['contact_name']);
  380. $sheet->setCellValue('F'.$row, $value['contact_phone']);
  381. $sheet->setCellValue('G'.$row, $value['contact_province']);
  382. $sheet->setCellValue('H'.$row, $value['contact_city']);
  383. $sheet->setCellValue('I'.$row, $value['contact_area']);
  384. $sheet->setCellValue('J'.$row, $value['contact_addr']);
  385. $sheet->setCellValue('R'.$row, $value['weiban_extid']);
  386. $sheet->setCellValue('S'.$row, date('Y-m-d H:i:s',$value['insert_time']));
  387. // 循环产品
  388. foreach ($value['product'] as $v) {
  389. $sheet->setCellValue('K'.$row, $v['product_name']);
  390. $sheet->setCellValue('L'.$row, $v['product_spec']);
  391. $sheet->setCellValue('M'.$row, $v['product_price']);
  392. $sheet->setCellValue('N'.$row, $v['pay_price']);
  393. $sheet->setCellValue('O'.$row, $v['buy_num']);
  394. $sheet->setCellValue('P'.$row, $v['coupon_total']);
  395. $sheet->setCellValue('Q'.$row, $v['pay_total']);
  396. // 函数自增
  397. $row++;
  398. }
  399. }
  400. //
  401. // 创建内容
  402. $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  403. header('Pragma: public');
  404. header('Content-type:application/vnd.ms-excel');
  405. header('Content-Disposition: inline;filename=下载订单.xlsx');
  406. // 输出数据流
  407. return $writer->save('php://output');
  408. }
  409. /**
  410. * 设置表格样式
  411. *
  412. */
  413. private function setStyle(Spreadsheet $spreadsheet){
  414. // 选择当前活动的工作表
  415. $sheet = $spreadsheet->getActiveSheet();
  416. // 宽
  417. $sheet->getColumnDimension('A')->setWidth(15);
  418. $sheet->getColumnDimension('B')->setWidth(15);
  419. $sheet->getColumnDimension('C')->setWidth(15);
  420. $sheet->getColumnDimension('D')->setWidth(15);
  421. $sheet->getColumnDimension('E')->setWidth(15);
  422. $sheet->getColumnDimension('F')->setWidth(15);
  423. $sheet->getColumnDimension('G')->setWidth(15);
  424. $sheet->getColumnDimension('H')->setWidth(15);
  425. $sheet->getColumnDimension('I')->setWidth(15);
  426. $sheet->getColumnDimension('J')->setWidth(50);
  427. $sheet->getColumnDimension('K')->setWidth(80);
  428. $sheet->getColumnDimension('L')->setWidth(80);
  429. $sheet->getColumnDimension('M')->setWidth(10);
  430. $sheet->getColumnDimension('N')->setWidth(10);
  431. $sheet->getColumnDimension('O')->setWidth(10);
  432. $sheet->getColumnDimension('P')->setWidth(10);
  433. $sheet->getColumnDimension('Q')->setWidth(10);
  434. $sheet->getColumnDimension('R')->setWidth(50);
  435. $sheet->getColumnDimension('S')->setWidth(20);
  436. // 默认高度
  437. $sheet->getDefaultRowDimension()->setRowHeight(18);
  438. // 加粗第一行
  439. $sheet->getStyle('A:S')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  440. $sheet->getStyle('A1:S1')->getFont()->setBold(true);
  441. $sheet->getStyle('A1:S1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('FF00FF00'); // ARGB颜色代码,例如绿色
  442. // 设置表格标题
  443. $sheet
  444. ->setCellValue('A1', '订单ID')
  445. ->setCellValue('B1', '客户ID')
  446. ->setCellValue('C1', '客户昵称')
  447. ->setCellValue('D1', '订单状态')
  448. ->setCellValue('E1', '收货人')
  449. ->setCellValue('F1', '收货人手机号')
  450. ->setCellValue('G1', '省')
  451. ->setCellValue('H1', '市')
  452. ->setCellValue('I1', '区县')
  453. ->setCellValue('J1', '收货地址')
  454. ->setCellValue('K1', '产品名称')
  455. ->setCellValue('L1', '产品规格')
  456. ->setCellValue('M1', '产品单价')
  457. ->setCellValue('N1', '折后单价')
  458. ->setCellValue('O1', '产品数量')
  459. ->setCellValue('P1', '优惠金额')
  460. ->setCellValue('Q1', '产品金额')
  461. ->setCellValue('R1', '微伴ID')
  462. ->setCellValue('S1', '下单时间');
  463. // 返回结果
  464. return $sheet;
  465. }
  466. }