123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- /**
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/11/11
- */
- namespace app\admin\model\water;
- use crmeb\services\PHPExcelService;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- use think\model\concern\SoftDelete;
- /**
- * Class StoreCategory
- * @package app\admin\model\store
- */
- class WaterQuery extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'water_query';
- use ModelTrait;
- protected $autoWriteTimestamp = true;
- public static function list($where)
- {
- $model = self::alias('a')->field('a.*,u.nickname')->order('a.id DESC')
- ->leftJoin('user u', 'a.uid = u.uid');
- if ($where['name'])$model->where('u.uid|u.nickname' , 'like', '%'.$where['name'].'%');
- if ($where['uid'])$model->where('u.uid' , $where['uid']);
- if (isset($where['excel']) && $where['excel'] == 1) {
- $list = $model->select()->toArray();
- self::SaveExcel($list);
- }
- $data['count'] = $model->count();
- 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
- * @param $list
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function SaveExcel($list)
- {
- $export = [];
- foreach ($list as $index => $item) {
- $export[] = [
- $item['uid'],
- $item['nickname'],
- $item['long'],
- $item['wide'],
- $item['high'],
- $item['is_warm'] ? '保温' : '不保温',
- $item['is_channel'] ? '需要' : '不需要',
- $item['is_ladder'] ? '需要' : '不需要',
- $item['is_gc'] ? '大公差' : '正常公差',
- $item['price'],
- $item['weight'],
- $item['create_time'],
- ];
- }
- PHPExcelService::setExcelHeader(['UID', '昵称', '长','宽', '高', '是否保温', '槽钢','人梯', '公差',
- '总价','重量','计算时间'])
- ->setExcelTile('计算导出' . date('YmdHis', time()), '计算信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
- ->setExcelContent($export)
- ->ExcelSave();
- }
- }
|