WaterQuery.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/11/11
  5. */
  6. namespace app\admin\model\water;
  7. use crmeb\services\PHPExcelService;
  8. use crmeb\traits\ModelTrait;
  9. use crmeb\basic\BaseModel;
  10. use think\model\concern\SoftDelete;
  11. /**
  12. * Class StoreCategory
  13. * @package app\admin\model\store
  14. */
  15. class WaterQuery extends BaseModel
  16. {
  17. /**
  18. * 数据表主键
  19. * @var string
  20. */
  21. protected $pk = 'id';
  22. /**
  23. * 模型名称
  24. * @var string
  25. */
  26. protected $name = 'water_query';
  27. use ModelTrait;
  28. protected $autoWriteTimestamp = true;
  29. public static function list($where)
  30. {
  31. $model = self::alias('a')->field('a.*,u.nickname')->order('a.id DESC')
  32. ->leftJoin('user u', 'a.uid = u.uid');
  33. if ($where['name'])$model->where('u.uid|u.nickname' , 'like', '%'.$where['name'].'%');
  34. if ($where['uid'])$model->where('u.uid' , $where['uid']);
  35. if (isset($where['excel']) && $where['excel'] == 1) {
  36. $list = $model->select()->toArray();
  37. self::SaveExcel($list);
  38. }
  39. $data['count'] = $model->count();
  40. if ($where['page'] && $where['limit']){
  41. $model->page($where['page'], $where['limit']);
  42. }else{
  43. $model->page(20, 1);
  44. }
  45. $list = $model->select()->toArray();
  46. $data['data'] = $list;
  47. return $data;
  48. }
  49. /**
  50. * excel
  51. * @param $list
  52. * @return void
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public static function SaveExcel($list)
  58. {
  59. $export = [];
  60. foreach ($list as $index => $item) {
  61. $export[] = [
  62. $item['uid'],
  63. $item['nickname'],
  64. $item['long'],
  65. $item['wide'],
  66. $item['high'],
  67. $item['is_warm'] ? '保温' : '不保温',
  68. $item['is_channel'] ? '需要' : '不需要',
  69. $item['is_ladder'] ? '需要' : '不需要',
  70. $item['is_gc'] ? '大公差' : '正常公差',
  71. $item['price'],
  72. $item['weight'],
  73. $item['create_time'],
  74. ];
  75. }
  76. PHPExcelService::setExcelHeader(['UID', '昵称', '长','宽', '高', '是否保温', '槽钢','人梯', '公差',
  77. '总价','重量','计算时间'])
  78. ->setExcelTile('计算导出' . date('YmdHis', time()), '计算信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  79. ->setExcelContent($export)
  80. ->ExcelSave();
  81. }
  82. }