SubMemFakerLogic.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * SubMemFakerLogic.php UTF-8
  4. *
  5. *
  6. * @date : 2018/9/18 21:16
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HuoMp 1.0
  11. */
  12. namespace huomp\logic\fill;
  13. use huomp\model\fill\MemFakerModel;
  14. use huolib\constant\CommonConst;
  15. use think\db\exception\DataNotFoundException;
  16. use think\db\exception\ModelNotFoundException;
  17. use think\exception\DbException;
  18. class SubMemFakerLogic {
  19. public function getWhere($param = []) {
  20. $_map = [];
  21. if (!empty($param['start_time']) && !empty($param['end_time'])) {
  22. $_map['create_time']
  23. = [
  24. 'between',
  25. [
  26. strtotime($param['start_time']),
  27. CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])
  28. ]
  29. ];
  30. } elseif (!empty($param['start_time'])) {
  31. $_map['create_time'] = ['egt', strtotime($param['start_time'])];
  32. } elseif (!empty($param['end_time'])) {
  33. $_map['create_time'] = ['elt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
  34. }
  35. if (!empty($param['nickname'])) {
  36. $_map['nickname'] = $param['nickname'];
  37. }
  38. if (!empty($param['is_delete'])) {
  39. $_map['is_delete'] = $param['is_delete'];
  40. }
  41. return $_map;
  42. }
  43. /**
  44. * 获取列表
  45. *
  46. * @param array $param
  47. * @param string $page
  48. * @param string $order
  49. *
  50. * @return array
  51. */
  52. public function getList($param = [], $page = '1,10', $order = '-sub_amount,-create_time') {
  53. $_map = $this->getWhere($param);
  54. $_rdata = ['count' => 0, 'list' => []];
  55. $_model = new MemFakerModel();
  56. $_count = $_model->where($_map)->count();
  57. if (empty($_count)) {
  58. return $_rdata;
  59. }
  60. $_order = $_model->orderFilter($order);
  61. try {
  62. $_list = $_model->where($_map)->order($_order)->page($page)->select();
  63. if (empty($_list)) {
  64. return $_rdata;
  65. }
  66. if (is_object($_list)) {
  67. $_list = $_list->toArray();
  68. }
  69. foreach ($_list as $key => $item) {
  70. $item['avatar'] = cmf_get_image_preview_url($item['avatar']);
  71. $_list[$key] = $item;
  72. }
  73. $_rdata = ['count' => $_count, 'list' => $_list];
  74. return $_rdata;
  75. } catch (DataNotFoundException $e) {
  76. return $_rdata;
  77. } catch (ModelNotFoundException $e) {
  78. return $_rdata;
  79. } catch (DbException $e) {
  80. return $_rdata;
  81. }
  82. }
  83. }