ManyOrder.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/11/11
  5. */
  6. namespace app\admin\model\many;
  7. use crmeb\services\PHPExcelService;
  8. use crmeb\traits\ModelTrait;
  9. use crmeb\basic\BaseModel;
  10. /**
  11. * Class StoreCategory
  12. * @package app\admin\model\store
  13. */
  14. class ManyOrder extends BaseModel
  15. {
  16. /**
  17. * 数据表主键
  18. * @var string
  19. */
  20. protected $pk = 'id';
  21. /**
  22. * 模型名称
  23. * @var string
  24. */
  25. protected $name = 'many_order';
  26. use ModelTrait;
  27. protected $autoWriteTimestamp = true;
  28. public static function list($where)
  29. {
  30. $model = self::alias('a')
  31. ->field('a.*,b.name,u.nickname')
  32. ->leftJoin('many b', 'b.id = a.many_id')
  33. ->leftJoin('user u', 'u.uid = a.uid');
  34. if ($where['order_id'])$model->where('a.order_id' , '=', $where['order_id']);
  35. if ($where['status'])$model->where('a.status' , '=', $where['status']);
  36. if ($where['stage'])$model->where('a.stage' , '=', $where['stage']);
  37. if (trim($where['many_id']) != '')$model->where('b.id' , '=', $where['many_id']);
  38. if (trim($where['name']) != '')$model->where('u.uid|u.account|u.nickname' , 'like', '%'.$where['name'].'%');
  39. if (trim($where['data']) != '') $model = self::getModelTime($where, $model, 'a.create_time');
  40. $data['count'] = $model->count();
  41. if (isset($where['excel']) && $where['excel'] == 1) {
  42. $list = ($list = $model->select()) && count($list) ? $list->toArray() : [];
  43. } else {
  44. $list = ($list = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($list) ? $list->toArray() : [];
  45. }
  46. if (isset($where['excel']) && $where['excel'] == 1) {
  47. self::SaveExcel($list);
  48. }
  49. if ($where['page'] && $where['limit']){
  50. $model->page($where['page'], $where['limit']);
  51. }else{
  52. $model->page(20, 1);
  53. }
  54. $list = $model->select()->toArray();
  55. $data['data'] = $list;
  56. return $data;
  57. }
  58. /*
  59. * 保存并下载excel
  60. * $list array
  61. * return
  62. */
  63. public static function SaveExcel($list)
  64. {
  65. $export = [];
  66. foreach ($list as $index => $item) {
  67. $status = $item['status']== 0 ? '正常' : $item['status']== 1 ? '成功返还':$item['status']== 2 ? '失败返还': '未知';
  68. $export[] = [
  69. $item['order_id'],
  70. $item['nickname'],
  71. $item['name'],
  72. $item['stage'],
  73. $item['price'],
  74. $status,
  75. $item['create_time'],
  76. ];
  77. }
  78. PHPExcelService::setExcelHeader(['订单号', '用户', '众筹名称', '期数', '金额', '状态',
  79. '订单时间'])
  80. ->setExcelTile('订单导出' . date('YmdHis', time()), '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  81. ->setExcelContent($export)
  82. ->ExcelSave();
  83. }
  84. }