123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- /**
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/11/11
- */
- namespace app\admin\model\many;
- use crmeb\services\PHPExcelService;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- /**
- * Class StoreCategory
- * @package app\admin\model\store
- */
- class ManyOrder extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'many_order';
- use ModelTrait;
- protected $autoWriteTimestamp = true;
- public static function list($where)
- {
- $model = self::alias('a')
- ->field('a.*,b.name,u.nickname,u.phone')
- ->order('a.id DESC')
- ->leftJoin('many b', 'b.id = a.many_id')
- ->leftJoin('user u', 'u.uid = a.uid');
- if ($where['order_id'])$model->where('a.order_id' , '=', $where['order_id']);
- if ($where['status'] == 1)$model->where('a.status' , '=', 0);
- if ($where['status'] == 2)$model->where('a.status' , '=', 1);
- if ($where['status'] == 3)$model->where('a.status' , '=', 2);
- if ($where['stage'])$model->where('a.stage' , '=', $where['stage']);
- if (trim($where['many_id']) != '')$model->where('b.id' , '=', $where['many_id']);
- if (trim($where['name']) != '')$model->where('u.uid|u.account|u.nickname' , 'like', '%'.$where['name'].'%');
- if (trim($where['data']) != '') $model = self::getModelTime($where, $model, 'a.create_time');
- if ($where['type']){
- $data['price'] = ManyOrder::where('status', '=', 0)->sum('frozen');
- return $data;
- }
- $data['count'] = $model->count();
- if (isset($where['excel']) && $where['excel'] == 1) {
- $list = ($list = $model->select()) && count($list) ? $list->toArray() : [];
- } else {
- $list = ($list = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($list) ? $list->toArray() : [];
- }
- if (isset($where['excel']) && $where['excel'] == 1) {
- self::SaveExcel($list);
- }
- if ($where['page'] && $where['limit']){
- $model->page($where['page'], $where['limit']);
- }else{
- $model->page(20, 1);
- }
- $list = $model->select()->toArray();
- $data['data'] = $list;
- return $data;
- }
- /*
- * 保存并下载excel
- * $list array
- * return
- */
- public static function SaveExcel($list)
- {
- $export = [];
- foreach ($list as $index => $item) {
- $status = $item['status']== 0 ? '正常' : $item['status']== 1 ? '成功返还':$item['status']== 2 ? '失败返还': '未知';
- $export[] = [
- $item['order_id'],
- $item['nickname'],
- $item['name'],
- $item['stage'],
- $item['price'],
- $status,
- $item['create_time'],
- ];
- }
- PHPExcelService::setExcelHeader(['订单号', '用户', '众筹名称', '期数', '金额', '状态',
- '订单时间'])
- ->setExcelTile('订单导出' . date('YmdHis', time()), '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
- ->setExcelContent($export)
- ->ExcelSave();
- }
- }
|