123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- <?php
- /**
- * AccountOut.php UTF-8
- * 小号对外接口
- *
- * @date : 2018/6/12 18:44
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huoAccountDeal\controller;
- use huo\controller\common\Base;
- use huo\model\member\MemGameModel;
- use huo\model\member\MgRoleModel;
- use huoAccountDeal\logic\AccountLogic;
- use huoAccountDeal\logic\MemGameLogic;
- use huoAccountDeal\model\AccountGoodsModel;
- use huoAccountDeal\model\AccountMemLikeModel;
- use huoAccountDeal\model\AccountOrderModel;
- use huolib\constant\AccountConst;
- use huolib\status\AccountStatus;
- use huolib\status\CommonStatus;
- use huolib\tool\StrUtils;
- class AccountOut extends Base {
- /**
- * 首页数据
- *
- * @param int $mem_id 玩家ID
- *
- * @return array
- */
- public function getHomeIndex($mem_id) {
- //收藏数
- $_like_cnt = (new AccountMemLikeModel())->getLikeCnt($mem_id);
- //出售数
- $_sell_cnt = (new AccountOrderModel())->getSellCnt($mem_id);
- //已购买到数
- $_buy_cnt = (new AccountOrderModel())->getBuyCnt($mem_id);
- //获取玩家已玩过的游戏,正在出售的小号商品列表
- $_mg_sell_account_list = (new MemGameLogic())->getSellGameList($mem_id);
- $_rdata = [
- 'like_cnt' => $_like_cnt,
- 'sell_cnt' => $_sell_cnt,
- 'buy_cnt' => $_buy_cnt,
- 'game_account' => $_mg_sell_account_list,
- ];
- $_code = AccountStatus::NO_ERROR;
- return $this->huoSuccess($_code, AccountStatus::getMsg($_code), $_rdata);
- }
- /**
- * 出售小号
- *
- * @param integer $mem_id 玩家
- * @param integer $mg_mem_id 小号ID
- * @param integer $mg_role_id 玩家游戏角色ID
- * @param string $title 标题
- * @param string $description 描述
- * @param float $price 价格
- * @param string $image 图片
- *
- * @return array
- */
- public function sell($mem_id, $mg_mem_id, $mg_role_id, $title, $description, $price, $image) {
- //验证图片数据格式
- if (!StrUtils::isJson($image)) {
- $_code = AccountStatus::INVALID_JSON;
- return $this->huoError($_code, CommonStatus::getMsg($_code));
- }
- //验证玩家游戏角色ID
- $_mg_role = (new MgRoleModel())->getInfoById($mg_role_id);
- if (!$_mg_role) {
- $_code = AccountStatus::MG_ROLE_NOT_EXISTS;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- //验证玩家游戏角色归属
- $_mem_game = (new MemGameModel())->getInfoById($_mg_role['mg_mem_id']);
- if (!$_mem_game) {
- $_code = AccountStatus::MEM_GAME_NOT_EXISTS;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- if ($_mem_game['mem_id'] != $mem_id) {
- $_code = AccountStatus::ONLY_OPERATE_YOUR_OWN_ACCOUNT;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- if ($_mem_game['id'] != $mg_mem_id) {
- $_code = AccountStatus::ONLY_OPERATE_YOUR_OWN_ACCOUNT;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- //验证小号是否可以出售
- if (MemGameModel::STATUS_NORMAL != $_mem_game['status']) {
- $_code = AccountStatus::ACCOUNT_LOCKED;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- //添加小号商品出售数据
- $_data = [
- 'mem_id' => $mem_id,
- 'app_id' => $_mg_role['app_id'],
- 'mg_mem_id' => $_mg_role['mg_mem_id'],
- 'server_id' => $_mg_role['server_id'],
- 'server_name' => $_mg_role['server_name'],
- 'role_id' => $_mg_role['role_id'],
- 'role_name' => $_mg_role['role_name'],
- 'title' => $title,
- 'price' => StrUtils::formatNumber($price),
- 'image' => $image,
- 'description' => $description,
- 'reason' => '',
- ];
- $_add_rs = (new AccountLogic())->addSellData($_data);
- if (true != $_add_rs) {
- $code = AccountStatus::INNER_ERROR;
- return $this->huoError($code, AccountStatus::getMsg($code));
- }
- $_code = AccountStatus::NO_ERROR;
- return $this->huoSuccess($_code, AccountStatus::getMsg($_code));
- }
- /**
- * 出售小号
- *
- * @param integer $goods_id 商品ID
- * @param integer $mem_id 玩家
- * @param integer $mg_role_id 玩家游戏角色ID
- * @param string $title 标题
- * @param string $description 描述
- * @param float $price 价格
- * @param string $image 图片
- *
- * @return array
- */
- public function edit($goods_id, $mem_id, $mg_role_id, $title, $description, $price, $image) {
- //验证图片数据格式
- if (!StrUtils::isJson($image)) {
- $_code = AccountStatus::INVALID_JSON;
- return $this->huoError($_code, CommonStatus::getMsg($_code));
- }
- //验证玩家游戏角色ID
- $_mg_role = (new MgRoleModel())->getInfoById($mg_role_id);
- if (!$_mg_role) {
- $_code = AccountStatus::MG_ROLE_NOT_EXISTS;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- //验证玩家游戏角色归属
- $_mem_game = (new MemGameModel())->getInfoById($_mg_role['mg_mem_id']);
- if (!$_mem_game) {
- $_code = AccountStatus::MEM_GAME_NOT_EXISTS;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- if ($_mem_game['mem_id'] != $mem_id) {
- $_code = AccountStatus::ONLY_OPERATE_YOUR_OWN_ACCOUNT;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- $_al_logic = new AccountLogic();
- $_goods_data = $_al_logic->getDetail($goods_id);
- if (empty($_goods_data)) {
- $_code = AccountStatus::ACCOUNT_GOODS_NOT_EXISTS;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- /* 不在审核中的商品不能编辑 */
- if (AccountConst::STATUS_AUDITING != $_goods_data['status']) {
- $_code = AccountStatus::GOODS_NOT_EDIT;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- //添加小号商品出售数据
- $_goods_data = [
- 'mem_id' => $mem_id,
- 'app_id' => $_mg_role['app_id'],
- 'mg_mem_id' => $_mg_role['mg_mem_id'],
- 'server_id' => $_mg_role['server_id'],
- 'server_name' => $_mg_role['server_name'],
- 'role_id' => $_mg_role['role_id'],
- 'role_name' => $_mg_role['role_name'],
- 'title' => $title,
- 'price' => StrUtils::formatNumber($price),
- 'image' => $image,
- 'description' => $description,
- 'status' => AccountConst::STATUS_AUDITING,
- 'reason' => '',
- ];
- $_add_rs = (new AccountGoodsModel())->updateData($_goods_data, $goods_id);
- if (true != $_add_rs) {
- $code = AccountStatus::INNER_ERROR;
- return $this->huoError($code, AccountStatus::getMsg($code));
- }
- $_code = AccountStatus::NO_ERROR;
- return $this->huoSuccess($_code, AccountStatus::getMsg($_code));
- }
- /**
- * 下架小号
- *
- * @param integer $goods_id 商品ID
- *
- * @return array
- */
- public function cancel($goods_id) {
- $_al_logic = new AccountLogic();
- $_goods_data = $_al_logic->getDetail($goods_id);
- if (empty($_goods_data)) {
- $_code = AccountStatus::ACCOUNT_GOODS_NOT_EXISTS;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- /* 不在审核中的商品不能下架 */
- if (AccountConst::STATUS_AUDITING != $_goods_data['status']) {
- $_code = AccountStatus::GOODS_CANNOT_CANCEL;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- //添加小号商品出售数据
- $_goods_data = [
- 'status' => AccountConst::STATUS_PULL_OFF_SHELVES,
- ];
- $_rs = (new AccountGoodsModel())->updateData($_goods_data, $goods_id);
- if (true != $_rs) {
- $code = AccountStatus::INNER_ERROR;
- return $this->huoError($code, AccountStatus::getMsg($code));
- }
- $_code = AccountStatus::NO_ERROR;
- return $this->huoSuccess($_code, AccountStatus::getMsg($_code));
- }
- /**
- * 小号商品列表
- *
- * @param array $param 搜索条件
- * @param int $sort_type 排序方式
- * @param string $page
- *
- * @return array
- */
- public function goodsList($param = [], $sort_type = 1, $page = '1,10') {
- $order = $this->getOrderByType($sort_type);
- $_where = [];
- !empty($param['keyword']) && $_where['title'] = ['like', "%{$param['keyword']}%"];
- !empty($param['app_id']) && $_where['app_id'] = $param['app_id'];
- !empty($param['status']) && $_where['status'] = $param['status'];
- !empty($param['mem_id']) && $_where['mem_id'] = $param['mem_id'];
- !empty($param['is_like']) && $_where['is_like'] = $param['is_like'];
- !empty($param['is_me_sell']) && $_where['is_me_sell'] = $param['is_me_sell'];
- $_field = [
- 'id' => 'goods_id',
- 'title' => 'title',
- 'description' => 'description',
- 'price' => 'price',
- 'mg_mem_id' => 'mg_mem_id',
- 'server_id' => 'server_id',
- 'server_name' => 'server_name',
- 'role_id' => 'role_id',
- 'role_name' => 'role_name',
- 'image' => 'image',
- 'status' => 'status',
- 'create_time' => 'create_time',
- 'update_time' => 'update_time',
- ];
- $_data = (new AccountLogic())->getList($_field, $_where, $order, $page);
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_data);
- }
- /**
- * 小号商品详情
- *
- * @param int $goods_id 商品ID
- * @param int $mem_id 商品ID
- *
- * @return array
- */
- public function getGoodsDetail($goods_id, $mem_id = 0) {
- $_goods_detail = (new AccountLogic())->getDetail($goods_id);
- if (empty($_goods_detail)) {
- $_code = AccountStatus::ACCOUNT_GOODS_NOT_EXISTS;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- $_rdata['goods_id'] = $_goods_detail['id'];
- $_rdata['title'] = $_goods_detail['title'];
- $_rdata['description'] = $_goods_detail['description'];
- $_rdata['price'] = $_goods_detail['price'];
- $_rdata['mg_mem_id'] = $_goods_detail['mg_mem_id'];
- $_rdata['server_id'] = $_goods_detail['server_id'];
- $_rdata['server_name'] = $_goods_detail['server_name'];
- $_rdata['role_id'] = $_goods_detail['role_id'];
- $_rdata['role_name'] = $_goods_detail['role_name'];
- $_rdata['image'] = $_goods_detail['image'];
- $_rdata['status'] = $_goods_detail['status'];
- $_rdata['create_time'] = $_goods_detail['create_time'];
- $_rdata['game_id'] = isset($_goods_detail['game']['id']) ? $_goods_detail['game']['id'] : 0;
- $_rdata['game_icon'] = isset($_goods_detail['game']['game_icon']) ? $_goods_detail['game']['game_icon'] : '';
- $_rdata['gamename'] = isset($_goods_detail['game']['name']) ? $_goods_detail['game']['name'] : '';
- $_rdata['game_publicity'] = isset($_goods_detail['game']['publicity']) ? $_goods_detail['game']['publicity']
- : '';
- $_rdata['is_mine'] = 1;
- if ($_goods_detail['mem_id'] == $mem_id) {
- $_rdata['is_mine'] = AccountConst::ACCOUNT_IS_MINE;
- }
- $_mg_detail = MemGameCache::ins()->getInfoById($_rdata['mg_mem_id']);
- $_rdata['sum_money'] = $_mg_detail['sum_money'];
- $_rdata['is_like'] = (new AccountMemLikeModel())->isLike($mem_id, $goods_id);
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
- }
- /**
- * 根据类型获取排序方式
- *
- * @param int $sort_type
- *
- * @return string
- */
- private function getOrderByType($sort_type = 1) {
- switch ($sort_type) {
- default:
- case 1:
- $order = '-create_time';
- break;
- case 2:
- $order = '-price';
- break;
- case 3:
- $order = '+price';
- break;
- }
- return $order;
- }
- /**
- * 收藏/取消收藏小号商品
- *
- * @param $mem_id
- * @param $ags_id
- *
- * @return array
- */
- public function like($mem_id, $ags_id) {
- $_account_goods = AccountGoodsModel::get($ags_id);
- if (!$_account_goods) {
- $_code = AccountStatus::INVALID_ACCOUNT_GOODS;
- $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- $_aml_model = (new AccountMemLikeModel());
- $_aml = $_aml_model->getByMemIdAndAgsId($mem_id, $ags_id);
- if ($_aml) {
- $_status = ($_aml['status'] == AccountMemLikeModel::STATUS_NOT_LIKE) ?
- AccountMemLikeModel::STATUS_LIKED : AccountMemLikeModel::STATUS_NOT_LIKE;
- $_rs = $_aml_model->updateData(['status' => $_status], $_aml['id']);
- } else {
- $_rs = $_aml_model->addData(['mem_id' => $mem_id, 'ags_id' => $ags_id]);
- }
- if (false === $_rs) {
- $_code = AccountStatus::INNER_ERROR;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- $_code = AccountStatus::NO_ERROR;
- return $this->huoSuccess($_code, AccountStatus::getMsg($_code));
- }
- }
|