1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /**
- * SubMemFakerLogic.php UTF-8
- *
- *
- * @date : 2018/9/18 21:16
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace huomp\logic\fill;
- use huomp\model\fill\MemFakerModel;
- use huolib\constant\CommonConst;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\ModelNotFoundException;
- use think\exception\DbException;
- class SubMemFakerLogic {
- public function getWhere($param = []) {
- $_map = [];
- if (!empty($param['start_time']) && !empty($param['end_time'])) {
- $_map['create_time']
- = [
- 'between',
- [
- strtotime($param['start_time']),
- CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])
- ]
- ];
- } elseif (!empty($param['start_time'])) {
- $_map['create_time'] = ['egt', strtotime($param['start_time'])];
- } elseif (!empty($param['end_time'])) {
- $_map['create_time'] = ['elt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
- }
- if (!empty($param['nickname'])) {
- $_map['nickname'] = $param['nickname'];
- }
- if (!empty($param['is_delete'])) {
- $_map['is_delete'] = $param['is_delete'];
- }
- return $_map;
- }
- /**
- * 获取列表
- *
- * @param array $param
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getList($param = [], $page = '1,10', $order = '-sub_amount,-create_time') {
- $_map = $this->getWhere($param);
- $_rdata = ['count' => 0, 'list' => []];
- $_model = new MemFakerModel();
- $_count = $_model->where($_map)->count();
- if (empty($_count)) {
- return $_rdata;
- }
- $_order = $_model->orderFilter($order);
- try {
- $_list = $_model->where($_map)->order($_order)->page($page)->select();
- if (empty($_list)) {
- return $_rdata;
- }
- if (is_object($_list)) {
- $_list = $_list->toArray();
- }
- foreach ($_list as $key => $item) {
- $item['avatar'] = cmf_get_image_preview_url($item['avatar']);
- $_list[$key] = $item;
- }
- $_rdata = ['count' => $_count, 'list' => $_list];
- return $_rdata;
- } catch (DataNotFoundException $e) {
- return $_rdata;
- } catch (ModelNotFoundException $e) {
- return $_rdata;
- } catch (DbException $e) {
- return $_rdata;
- }
- }
- }
|