Merchant.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if (isset($where['main']) && $where['main'] != '') $model = $model->where('c.main', $where['main']);
  52. return $model->order('c.id desc')->where('c.is_del', 0);
  53. }
  54. /**
  55. * 详情
  56. */
  57. public static function getOne($id)
  58. {
  59. $info = self::get($id);
  60. return $info;
  61. }
  62. }