Printer.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\model;
  13. use app\common\model\Printer as PrinterModel;
  14. /**
  15. * 小票打印机模型
  16. * Class Printer
  17. * @package app\store\model
  18. */
  19. class Printer extends PrinterModel
  20. {
  21. /**
  22. * 获取全部记录
  23. * @return Printer[]|array|\think\Collection
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\DbException
  26. * @throws \think\db\exception\ModelNotFoundException
  27. */
  28. public static function getAll()
  29. {
  30. return (new static)->where('is_delete', '=', 0)
  31. ->order(['sort', 'create_time'])
  32. ->select();
  33. }
  34. /**
  35. * 获取列表记录
  36. * @param array $param
  37. * @return \think\Paginator
  38. * @throws \think\db\exception\DbException
  39. */
  40. public function getList(array $param = []): \think\Paginator
  41. {
  42. // 查询模型
  43. $query = $this->getNewQuery();
  44. // 查询参数
  45. $params = $this->setQueryDefaultValue($param, [
  46. 'search' => '', // 关键词
  47. 'printer_type' => '', // 打印机类型
  48. ]);
  49. // 检索关键词
  50. !empty($params['search']) && $query->where('printer_name', 'like', "%{$params['search']}%");
  51. // 检索打印机类型
  52. !empty($params['printer_type']) && $query->where('printer_type', '=', $params['printer_type']);
  53. // 查询数据
  54. return $query->where('is_delete', '=', 0)
  55. ->order(['sort', 'create_time'])
  56. ->paginate(15);
  57. }
  58. /**
  59. * 添加新记录
  60. * @param array $data
  61. * @return bool|false
  62. */
  63. public function add(array $data): bool
  64. {
  65. $data['store_id'] = self::$storeId;
  66. return $this->save($data);
  67. }
  68. /**
  69. * 编辑记录
  70. * @param array $data
  71. * @return bool
  72. */
  73. public function edit(array $data): bool
  74. {
  75. return $this->save($data);
  76. }
  77. /**
  78. * 删除记录
  79. * @return bool
  80. */
  81. public function setDelete(): bool
  82. {
  83. return $this->save(['is_delete' => 1]);
  84. }
  85. }