123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- <?php
- /**
- * AccountLogic.php UTF-8
- *
- *
- * @date : 2018/6/12 16:49
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huoAccountDeal\logic;
- use huo\controller\queue\AccountOrderQueue;
- use huo\model\common\CommonModel;
- use huo\model\member\MemGameModel;
- use huo\model\member\MgRoleModel;
- use huoAccountDeal\model\AccountGoodsModel;
- use huoAccountDeal\model\AccountMemLikeModel;
- use huoAccountDeal\model\AccountOrderModel;
- use huolib\constant\AccountConst;
- use huolib\constant\CommonConst;
- use huolib\status\AccountStatus;
- use huolib\tool\StrUtils;
- class AccountLogic extends CommonModel {
- /**
- * 添加小号商品出售数据
- *
- * @param $data
- *
- * @return bool
- */
- public function addSellData($data) {
- //添加小号商品
- $_rs = (new AccountGoodsModel())->addData($data);
- if (!$_rs) {
- return false;
- }
- //小号账号锁定
- MemGameModel::update(['status' => MemGameModel::STATUS_LOCKED], ['id' => $data['mg_mem_id']]);
- return true;
- }
- /**
- * 添加预下单数据
- *
- * @param $data
- *
- * @return bool
- */
- public function addPreorderData($data) {
- $_account_order_id = (new AccountOrderModel())->addData($data);
- if (!$_account_order_id) {
- return false;
- }
- //小号商品锁定
- (new AccountGoodsModel())->updateData(
- [
- 'status' => AccountConst::STATUS_LOCKED,
- 'lock_time' => time(),
- ], $data['ags_id']
- );
- //发送取消订单延时队列
- $_order_info = (new AccountOrderModel())->getInfoById($_account_order_id);
- (new AccountOrderQueue($_order_info))->pushQueue();
- return true;
- }
- /**
- * 小号商品列表
- *
- * @param array $field
- * @param array $where
- * @param string $order
- * @param string $page
- *
- * @return array
- */
- public function getList($field = [], $where = [], $order = '-create_time', $page = '1,10') {
- $_model = (new AccountGoodsModel());
- $_order = $this->orderFilter($order);
- if (isset($where['is_like'])) {
- $_is_like = AccountConst::STATUS_KEEP;
- unset($where['is_like']);
- if (isset($where['mem_id'])) {
- $_map['status'] = $_is_like;
- $_map['mem_id'] = $where['mem_id'];
- $_goods_ids = (new AccountMemLikeModel())->where($_map)->column('ags_id');
- if (!empty($_goods_ids)) {
- $where['id'] = ['in', $_goods_ids];
- }
- }
- }
- if (!isset($where['is_me_sell']) && isset($where['mem_id'])) {
- unset($where['mem_id']);
- }
- if (isset($where['is_me_sell'])) {
- unset($where['is_me_sell']);
- }
- $_ext_where = '';
- if (isset($where['status']) && AccountConst::STATUS_PULL_ON_SHELVES == $where['status']) {
- unset($where['status']);
- $_ex_time = time() - AccountConst::ACCOUNT_MAX_LOCK_TIME;
- $_ext_where = 'status='.AccountConst::STATUS_PULL_ON_SHELVES.' OR status='.AccountConst::STATUS_LOCKED
- .' AND lock_time<'.$_ex_time;
- }
- $_count = $_model->where($where)->where($_ext_where)->count();
- if (empty($_count)) {
- return [
- 'count' => $_count,
- 'list' => []
- ];
- }
- $_datas = $_model->with('game')
- ->field('*')
- ->field($field)
- ->where($where)
- ->where($_ext_where)
- ->order($_order)
- ->page($page)
- ->select();
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- $_list = [];
- $_data = [];
- $_now_time = time();
- foreach ($_datas as $_v) {
- foreach ($field as $f) {
- $_data[$f] = $_v[$f];
- }
- $_data['game_id'] = isset($_v['game']['id']) ? $_v['game']['id'] : 0;
- $_data['game_icon'] = isset($_v['game']['icon']) ? $_v['game']['icon'] : '';
- $_data['gamename'] = isset($_v['game']['name']) ? $_v['game']['name'] : '';
- if (StrUtils::compareNumber($_v['lock_time'] + AccountConst::ACCOUNT_MAX_LOCK_TIME, $_now_time) < 0
- && AccountConst::STATUS_LOCKED == $_v['status']) {
- /* 锁定已超期 重新上架 */
- $_data['status'] = AccountConst::STATUS_PULL_ON_SHELVES;
- }
- $_list[] = $_data;
- }
- return [
- 'count' => $_count,
- 'list' => $_list
- ];
- }
- /**
- * 小号商品列表
- *
- * @param $id
- *
- * @return array
- */
- public function getDetail($id) {
- $_map['id'] = $id;
- $_model = (new AccountGoodsModel());
- $_data = $_model->with('game')->where($_map)->find();
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- /* 锁定已超期 重新上架 */
- $_now_time = time();
- if (StrUtils::compareNumber($_data['lock_time'] + AccountConst::ACCOUNT_MAX_LOCK_TIME, $_now_time) < 0
- && AccountConst::STATUS_LOCKED == $_data['status']) {
- /* 锁定已超期 重新上架 */
- $_data['status'] = AccountConst::STATUS_PULL_ON_SHELVES;
- }
- return $_data;
- }
- /**
- * 获取玩家游戏区服角色列表
- *
- * @param $mem_id
- * @param $account_id
- * @param $page
- * @param string $order
- *
- * @return array|int
- */
- public function getMgServerList($mem_id, $account_id, $page, $order = '-create_time') {
- //验证玩家游戏角色归属
- $_mem_game = (new MemGameModel())->getInfoById($account_id);
- if (!$_mem_game) {
- return AccountStatus::MEM_GAME_NOT_EXISTS;
- }
- if ($_mem_game['mem_id'] != $mem_id) {
- return AccountStatus::ONLY_OPERATE_YOUR_OWN_ACCOUNT;
- }
- $_where = ['mg_mem_id' => $account_id];
- $_field = [
- 'id' => 'mg_role_id',
- 'server_id' => 'server_id',
- 'server_name' => 'server_name',
- 'role_id' => 'role_id',
- 'role_name' => 'role_name',
- ];
- $_model = new MgRoleModel();
- $_count = $_model->where($_where)->count();
- if (empty($_count)) {
- return [
- 'count' => $_count,
- 'list' => []
- ];
- }
- $_order = $_model->orderFilter($order);
- $_datas = $_model->field($_field)->where($_where)->order($_order)->page($page)->select();
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- return [
- 'count' => $_count,
- 'list' => $_datas
- ];
- }
- public function adminGoodsList($where = [], $page = '1,10') {
- $_map = [];
- if (!empty($where['start_time']) && !empty($where['end_time'])) {
- $_map['create_time'] = ['between',
- [strtotime($where['start_time']),
- CommonConst::CONST_DAY_SECONDS + strtotime($where['end_time'])]];
- } else if (!empty($where['start_time'])) {
- $_map['create_time'] = ['gt', strtotime($where['start_time'])];
- } else if (!empty($where['end_time'])) {
- $_map['create_time'] = ['lt', CommonConst::CONST_DAY_SECONDS + strtotime($where['end_time'])];
- }
- if (!empty($where['status'])) {
- $_map['status'] = $where['status'];
- }
- $_field = [
- 'id' => 'id',
- 'mem_id' => 'mem_id',
- 'app_id' => 'app_id',
- 'mg_mem_id' => 'mg_mem_id',
- 'server_name' => 'server_name',
- 'role_name' => 'role_name',
- 'title' => 'title',
- 'price' => 'price',
- 'status' => 'status',
- 'lock_time' => 'lock_time',
- 'create_time' => 'create_time',
- 'update_time' => 'update_time',
- ];
- $_order = '-create_time';
- return $this->getListIncludeMemGame($_field, $_map, $_order, $page);
- }
- /**
- * 获取商品列表,包含玩家和游戏信息
- *
- * @param array $field
- * @param array $where
- * @param string $order
- * @param string $page
- *
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getListIncludeMemGame($field = [], $where = [], $order = '-create_time', $page = '1,10') {
- $_model = (new AccountGoodsModel());
- $_order = $_model->orderFilter($order);
- $_count = $_model->where($where)->count();
- if (empty($_count)) {
- return [
- 'count' => $_count,
- 'list' => []
- ];
- }
- $_datas = $_model->with('mem,game')->field($field)->where($where)->order($_order)->page($page)->select();
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- $_list = [];
- $_now_time = time();
- foreach ($_datas as $_v) {
- $_data = $_v;
- if (StrUtils::compareNumber($_v['lock_time'] + AccountConst::ACCOUNT_MAX_LOCK_TIME, $_now_time) < 0
- && AccountConst::STATUS_LOCKED == $_v['status']) {
- /* 锁定已超期 重新上架 */
- $_data['status'] = AccountConst::STATUS_PULL_ON_SHELVES;
- }
- $_list[] = $_data;
- }
- return [
- 'count' => $_count,
- 'list' => $_list
- ];
- }
- public function getInfoById($id) {
- $_model = (new AccountGoodsModel());
- $_data = $_model->with('mem,game')->find($id);
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- return $_data;
- }
- public function unlock($mg_mem_id) {
- $_rs = (new MemGameModel())->updateData(
- [
- 'status' => MemGameModel::STATUS_NORMAL,
- ], $mg_mem_id
- );
- return $_rs;
- }
- /**
- * 获取收藏游戏列表
- *
- * @param array $where
- * @param string $page
- *
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getAmlList($where = [], $page = '1,10') {
- $_map = [];
- if (!empty($where['start_time']) && !empty($where['end_time'])) {
- $_map['create_time'] = ['between',
- [strtotime($where['start_time']),
- CommonConst::CONST_DAY_SECONDS + strtotime($where['end_time'])]];
- } else if (!empty($param['start_time'])) {
- $_map['create_time'] = ['gt', strtotime($param['start_time'])];
- } else if (!empty($param['end_time'])) {
- $_map['create_time'] = ['lt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
- }
- if (!empty($where['ags_id'])) {
- $_map['ags_id'] = $where['ags_id'];
- }
- if (!empty($where['status'])) {
- $_map['status'] = $where['status'];
- }
- if (!empty($where['mem_id'])) {
- $_map['mem_id'] = $where['mem_id'];
- }
- $_rdata = ['count' => 0, 'list' => []];
- $_mal_model = new AccountMemLikeModel();
- $_count = $_mal_model->where($_map)->count('id');
- if (empty($_count)) {
- return $_rdata;
- }
- $_data = $_mal_model->with('mem')->where($where)->page($page)->order('create_time desc')->select();
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- $_list = [];
- foreach ($_data as $_k => $_v) {
- $_list[$_k]['id'] = $_v['id'];
- $_list[$_k]['username'] = isset($_v['mem']) ? $_v['mem']['username'] : '';
- $_list[$_k]['create_time'] = $_v['create_time'];
- $_list[$_k]['update_time'] = $_v['update_time'];
- $_list[$_k]['status'] = $_v['status'];
- }
- return ['count' => $_count, 'list' => $_list];
- }
- }
|