Merchant.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\model\system;
  3. use library\traits\ModelTrait;
  4. use library\basic\BaseModel;
  5. /**
  6. * TODO 商家Model
  7. * Class Merchant
  8. * @package app\model\system
  9. */
  10. class Merchant extends BaseModel
  11. {
  12. /**
  13. * 数据表主键
  14. * @var string
  15. */
  16. protected $pk = 'id';
  17. /**
  18. * 模型名称
  19. * @var string
  20. */
  21. protected $name = 'merchant';
  22. use ModelTrait;
  23. /**
  24. * 商家列表
  25. * @param $where
  26. * @return array
  27. */
  28. public static function systemPage($where)
  29. {
  30. $model = self::setWhere($where);
  31. $count = $model->count();
  32. $list = $model->page((int)$where['page'], (int)$where['limit'])
  33. ->select()
  34. ->each(function ($item) {
  35. $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  36. });
  37. return compact('count', 'list');
  38. }
  39. /**
  40. * 设置商家 where 条件
  41. * @param $where
  42. * @param null $model
  43. * @return mixed
  44. */
  45. public static function setWhere($where, $model = null)
  46. {
  47. $model = $model === null ? new self() : $model;
  48. $model = $model->alias('c');
  49. $model = $model->field('c.*');
  50. if (isset($where['name']) && $where['name'] != '') $model = $model->where('c.id|c.name', 'LIKE', "%$where[name]%");
  51. return $model->order('c.id desc')->where('c.is_del', 0);
  52. }
  53. /**
  54. * 详情
  55. */
  56. public static function getOne($id)
  57. {
  58. $info = self::get($id);
  59. return $info;
  60. }
  61. }