ManyOrder.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. ->order('a.id DESC')
  33. ->leftJoin('many b', 'b.id = a.many_id')
  34. ->leftJoin('user u', 'u.uid = a.uid');
  35. if ($where['order_id'])$model->where('a.order_id' , '=', $where['order_id']);
  36. if ($where['status'] == 1)$model->where('a.status' , '=', 0);
  37. if ($where['status'] == 2)$model->where('a.status' , '=', 1);
  38. if ($where['status'] == 3)$model->where('a.status' , '=', 2);
  39. if ($where['stage'])$model->where('a.stage' , '=', $where['stage']);
  40. if (trim($where['many_id']) != '')$model->where('b.id' , '=', $where['many_id']);
  41. if (trim($where['name']) != '')$model->where('u.uid|u.account|u.nickname' , 'like', '%'.$where['name'].'%');
  42. if (trim($where['data']) != '') $model = self::getModelTime($where, $model, 'a.create_time');
  43. if ($where['type']){
  44. $data['user'] = count($model->column('a.uid'));
  45. $data['price'] = $model->sum('price');
  46. return $data;
  47. }
  48. $data['count'] = $model->count();
  49. if (isset($where['excel']) && $where['excel'] == 1) {
  50. $list = ($list = $model->select()) && count($list) ? $list->toArray() : [];
  51. } else {
  52. $list = ($list = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($list) ? $list->toArray() : [];
  53. }
  54. if (isset($where['excel']) && $where['excel'] == 1) {
  55. self::SaveExcel($list);
  56. }
  57. if ($where['page'] && $where['limit']){
  58. $model->page($where['page'], $where['limit']);
  59. }else{
  60. $model->page(20, 1);
  61. }
  62. $list = $model->select()->toArray();
  63. foreach ($list as &$item)
  64. {
  65. if ($item['return_time'] > 0){
  66. $item['return_time'] = date('Y-m-d H:i:s', $item['return_time']);
  67. }
  68. }
  69. $data['data'] = $list;
  70. return $data;
  71. }
  72. /*
  73. * 保存并下载excel
  74. * $list array
  75. * return
  76. */
  77. public static function SaveExcel($list)
  78. {
  79. $export = [];
  80. foreach ($list as $index => $item) {
  81. $status = $item['status']== 0 ? '正常' : $item['status']== 1 ? '成功返还':$item['status']== 2 ? '失败返还': '未知';
  82. $export[] = [
  83. $item['order_id'],
  84. $item['nickname'],
  85. $item['name'],
  86. $item['stage'],
  87. $item['price'],
  88. $status,
  89. $item['create_time'],
  90. ];
  91. }
  92. PHPExcelService::setExcelHeader(['订单号', '用户', '众筹名称', '期数', '金额', '状态',
  93. '订单时间'])
  94. ->setExcelTile('订单导出' . date('YmdHis', time()), '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  95. ->setExcelContent($export)
  96. ->ExcelSave();
  97. }
  98. }