AccountOut.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <?php
  2. /**
  3. * AccountOut.php UTF-8
  4. * 小号对外接口
  5. *
  6. * @date : 2018/6/12 18:44
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huoAccountDeal\controller;
  13. use huo\controller\common\Base;
  14. use huo\model\member\MemGameModel;
  15. use huo\model\member\MgRoleModel;
  16. use huoAccountDeal\logic\AccountLogic;
  17. use huoAccountDeal\logic\MemGameLogic;
  18. use huoAccountDeal\model\AccountGoodsModel;
  19. use huoAccountDeal\model\AccountMemLikeModel;
  20. use huoAccountDeal\model\AccountOrderModel;
  21. use huolib\constant\AccountConst;
  22. use huolib\status\AccountStatus;
  23. use huolib\status\CommonStatus;
  24. use huolib\tool\StrUtils;
  25. class AccountOut extends Base {
  26. /**
  27. * 首页数据
  28. *
  29. * @param int $mem_id 玩家ID
  30. *
  31. * @return array
  32. */
  33. public function getHomeIndex($mem_id) {
  34. //收藏数
  35. $_like_cnt = (new AccountMemLikeModel())->getLikeCnt($mem_id);
  36. //出售数
  37. $_sell_cnt = (new AccountOrderModel())->getSellCnt($mem_id);
  38. //已购买到数
  39. $_buy_cnt = (new AccountOrderModel())->getBuyCnt($mem_id);
  40. //获取玩家已玩过的游戏,正在出售的小号商品列表
  41. $_mg_sell_account_list = (new MemGameLogic())->getSellGameList($mem_id);
  42. $_rdata = [
  43. 'like_cnt' => $_like_cnt,
  44. 'sell_cnt' => $_sell_cnt,
  45. 'buy_cnt' => $_buy_cnt,
  46. 'game_account' => $_mg_sell_account_list,
  47. ];
  48. $_code = AccountStatus::NO_ERROR;
  49. return $this->huoSuccess($_code, AccountStatus::getMsg($_code), $_rdata);
  50. }
  51. /**
  52. * 出售小号
  53. *
  54. * @param integer $mem_id 玩家
  55. * @param integer $mg_mem_id 小号ID
  56. * @param integer $mg_role_id 玩家游戏角色ID
  57. * @param string $title 标题
  58. * @param string $description 描述
  59. * @param float $price 价格
  60. * @param string $image 图片
  61. *
  62. * @return array
  63. */
  64. public function sell($mem_id, $mg_mem_id, $mg_role_id, $title, $description, $price, $image) {
  65. //验证图片数据格式
  66. if (!StrUtils::isJson($image)) {
  67. $_code = AccountStatus::INVALID_JSON;
  68. return $this->huoError($_code, CommonStatus::getMsg($_code));
  69. }
  70. //验证玩家游戏角色ID
  71. $_mg_role = (new MgRoleModel())->getInfoById($mg_role_id);
  72. if (!$_mg_role) {
  73. $_code = AccountStatus::MG_ROLE_NOT_EXISTS;
  74. return $this->huoError($_code, AccountStatus::getMsg($_code));
  75. }
  76. //验证玩家游戏角色归属
  77. $_mem_game = (new MemGameModel())->getInfoById($_mg_role['mg_mem_id']);
  78. if (!$_mem_game) {
  79. $_code = AccountStatus::MEM_GAME_NOT_EXISTS;
  80. return $this->huoError($_code, AccountStatus::getMsg($_code));
  81. }
  82. if ($_mem_game['mem_id'] != $mem_id) {
  83. $_code = AccountStatus::ONLY_OPERATE_YOUR_OWN_ACCOUNT;
  84. return $this->huoError($_code, AccountStatus::getMsg($_code));
  85. }
  86. if ($_mem_game['id'] != $mg_mem_id) {
  87. $_code = AccountStatus::ONLY_OPERATE_YOUR_OWN_ACCOUNT;
  88. return $this->huoError($_code, AccountStatus::getMsg($_code));
  89. }
  90. //验证小号是否可以出售
  91. if (MemGameModel::STATUS_NORMAL != $_mem_game['status']) {
  92. $_code = AccountStatus::ACCOUNT_LOCKED;
  93. return $this->huoError($_code, AccountStatus::getMsg($_code));
  94. }
  95. //添加小号商品出售数据
  96. $_data = [
  97. 'mem_id' => $mem_id,
  98. 'app_id' => $_mg_role['app_id'],
  99. 'mg_mem_id' => $_mg_role['mg_mem_id'],
  100. 'server_id' => $_mg_role['server_id'],
  101. 'server_name' => $_mg_role['server_name'],
  102. 'role_id' => $_mg_role['role_id'],
  103. 'role_name' => $_mg_role['role_name'],
  104. 'title' => $title,
  105. 'price' => StrUtils::formatNumber($price),
  106. 'image' => $image,
  107. 'description' => $description,
  108. 'reason' => '',
  109. ];
  110. $_add_rs = (new AccountLogic())->addSellData($_data);
  111. if (true != $_add_rs) {
  112. $code = AccountStatus::INNER_ERROR;
  113. return $this->huoError($code, AccountStatus::getMsg($code));
  114. }
  115. $_code = AccountStatus::NO_ERROR;
  116. return $this->huoSuccess($_code, AccountStatus::getMsg($_code));
  117. }
  118. /**
  119. * 出售小号
  120. *
  121. * @param integer $goods_id 商品ID
  122. * @param integer $mem_id 玩家
  123. * @param integer $mg_role_id 玩家游戏角色ID
  124. * @param string $title 标题
  125. * @param string $description 描述
  126. * @param float $price 价格
  127. * @param string $image 图片
  128. *
  129. * @return array
  130. */
  131. public function edit($goods_id, $mem_id, $mg_role_id, $title, $description, $price, $image) {
  132. //验证图片数据格式
  133. if (!StrUtils::isJson($image)) {
  134. $_code = AccountStatus::INVALID_JSON;
  135. return $this->huoError($_code, CommonStatus::getMsg($_code));
  136. }
  137. //验证玩家游戏角色ID
  138. $_mg_role = (new MgRoleModel())->getInfoById($mg_role_id);
  139. if (!$_mg_role) {
  140. $_code = AccountStatus::MG_ROLE_NOT_EXISTS;
  141. return $this->huoError($_code, AccountStatus::getMsg($_code));
  142. }
  143. //验证玩家游戏角色归属
  144. $_mem_game = (new MemGameModel())->getInfoById($_mg_role['mg_mem_id']);
  145. if (!$_mem_game) {
  146. $_code = AccountStatus::MEM_GAME_NOT_EXISTS;
  147. return $this->huoError($_code, AccountStatus::getMsg($_code));
  148. }
  149. if ($_mem_game['mem_id'] != $mem_id) {
  150. $_code = AccountStatus::ONLY_OPERATE_YOUR_OWN_ACCOUNT;
  151. return $this->huoError($_code, AccountStatus::getMsg($_code));
  152. }
  153. $_al_logic = new AccountLogic();
  154. $_goods_data = $_al_logic->getDetail($goods_id);
  155. if (empty($_goods_data)) {
  156. $_code = AccountStatus::ACCOUNT_GOODS_NOT_EXISTS;
  157. return $this->huoError($_code, AccountStatus::getMsg($_code));
  158. }
  159. /* 不在审核中的商品不能编辑 */
  160. if (AccountConst::STATUS_AUDITING != $_goods_data['status']) {
  161. $_code = AccountStatus::GOODS_NOT_EDIT;
  162. return $this->huoError($_code, AccountStatus::getMsg($_code));
  163. }
  164. //添加小号商品出售数据
  165. $_goods_data = [
  166. 'mem_id' => $mem_id,
  167. 'app_id' => $_mg_role['app_id'],
  168. 'mg_mem_id' => $_mg_role['mg_mem_id'],
  169. 'server_id' => $_mg_role['server_id'],
  170. 'server_name' => $_mg_role['server_name'],
  171. 'role_id' => $_mg_role['role_id'],
  172. 'role_name' => $_mg_role['role_name'],
  173. 'title' => $title,
  174. 'price' => StrUtils::formatNumber($price),
  175. 'image' => $image,
  176. 'description' => $description,
  177. 'status' => AccountConst::STATUS_AUDITING,
  178. 'reason' => '',
  179. ];
  180. $_add_rs = (new AccountGoodsModel())->updateData($_goods_data, $goods_id);
  181. if (true != $_add_rs) {
  182. $code = AccountStatus::INNER_ERROR;
  183. return $this->huoError($code, AccountStatus::getMsg($code));
  184. }
  185. $_code = AccountStatus::NO_ERROR;
  186. return $this->huoSuccess($_code, AccountStatus::getMsg($_code));
  187. }
  188. /**
  189. * 下架小号
  190. *
  191. * @param integer $goods_id 商品ID
  192. *
  193. * @return array
  194. */
  195. public function cancel($goods_id) {
  196. $_al_logic = new AccountLogic();
  197. $_goods_data = $_al_logic->getDetail($goods_id);
  198. if (empty($_goods_data)) {
  199. $_code = AccountStatus::ACCOUNT_GOODS_NOT_EXISTS;
  200. return $this->huoError($_code, AccountStatus::getMsg($_code));
  201. }
  202. /* 不在审核中的商品不能下架 */
  203. if (AccountConst::STATUS_AUDITING != $_goods_data['status']) {
  204. $_code = AccountStatus::GOODS_CANNOT_CANCEL;
  205. return $this->huoError($_code, AccountStatus::getMsg($_code));
  206. }
  207. //添加小号商品出售数据
  208. $_goods_data = [
  209. 'status' => AccountConst::STATUS_PULL_OFF_SHELVES,
  210. ];
  211. $_rs = (new AccountGoodsModel())->updateData($_goods_data, $goods_id);
  212. if (true != $_rs) {
  213. $code = AccountStatus::INNER_ERROR;
  214. return $this->huoError($code, AccountStatus::getMsg($code));
  215. }
  216. $_code = AccountStatus::NO_ERROR;
  217. return $this->huoSuccess($_code, AccountStatus::getMsg($_code));
  218. }
  219. /**
  220. * 小号商品列表
  221. *
  222. * @param array $param 搜索条件
  223. * @param int $sort_type 排序方式
  224. * @param string $page
  225. *
  226. * @return array
  227. */
  228. public function goodsList($param = [], $sort_type = 1, $page = '1,10') {
  229. $order = $this->getOrderByType($sort_type);
  230. $_where = [];
  231. !empty($param['keyword']) && $_where['title'] = ['like', "%{$param['keyword']}%"];
  232. !empty($param['app_id']) && $_where['app_id'] = $param['app_id'];
  233. !empty($param['status']) && $_where['status'] = $param['status'];
  234. !empty($param['mem_id']) && $_where['mem_id'] = $param['mem_id'];
  235. !empty($param['is_like']) && $_where['is_like'] = $param['is_like'];
  236. !empty($param['is_me_sell']) && $_where['is_me_sell'] = $param['is_me_sell'];
  237. $_field = [
  238. 'id' => 'goods_id',
  239. 'title' => 'title',
  240. 'description' => 'description',
  241. 'price' => 'price',
  242. 'mg_mem_id' => 'mg_mem_id',
  243. 'server_id' => 'server_id',
  244. 'server_name' => 'server_name',
  245. 'role_id' => 'role_id',
  246. 'role_name' => 'role_name',
  247. 'image' => 'image',
  248. 'status' => 'status',
  249. 'create_time' => 'create_time',
  250. 'update_time' => 'update_time',
  251. ];
  252. $_data = (new AccountLogic())->getList($_field, $_where, $order, $page);
  253. $_code = CommonStatus::NO_ERROR;
  254. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_data);
  255. }
  256. /**
  257. * 小号商品详情
  258. *
  259. * @param int $goods_id 商品ID
  260. * @param int $mem_id 商品ID
  261. *
  262. * @return array
  263. */
  264. public function getGoodsDetail($goods_id, $mem_id = 0) {
  265. $_goods_detail = (new AccountLogic())->getDetail($goods_id);
  266. if (empty($_goods_detail)) {
  267. $_code = AccountStatus::ACCOUNT_GOODS_NOT_EXISTS;
  268. return $this->huoError($_code, AccountStatus::getMsg($_code));
  269. }
  270. $_rdata['goods_id'] = $_goods_detail['id'];
  271. $_rdata['title'] = $_goods_detail['title'];
  272. $_rdata['description'] = $_goods_detail['description'];
  273. $_rdata['price'] = $_goods_detail['price'];
  274. $_rdata['mg_mem_id'] = $_goods_detail['mg_mem_id'];
  275. $_rdata['server_id'] = $_goods_detail['server_id'];
  276. $_rdata['server_name'] = $_goods_detail['server_name'];
  277. $_rdata['role_id'] = $_goods_detail['role_id'];
  278. $_rdata['role_name'] = $_goods_detail['role_name'];
  279. $_rdata['image'] = $_goods_detail['image'];
  280. $_rdata['status'] = $_goods_detail['status'];
  281. $_rdata['create_time'] = $_goods_detail['create_time'];
  282. $_rdata['game_id'] = isset($_goods_detail['game']['id']) ? $_goods_detail['game']['id'] : 0;
  283. $_rdata['game_icon'] = isset($_goods_detail['game']['game_icon']) ? $_goods_detail['game']['game_icon'] : '';
  284. $_rdata['gamename'] = isset($_goods_detail['game']['name']) ? $_goods_detail['game']['name'] : '';
  285. $_rdata['game_publicity'] = isset($_goods_detail['game']['publicity']) ? $_goods_detail['game']['publicity']
  286. : '';
  287. $_rdata['is_mine'] = 1;
  288. if ($_goods_detail['mem_id'] == $mem_id) {
  289. $_rdata['is_mine'] = AccountConst::ACCOUNT_IS_MINE;
  290. }
  291. $_mg_detail = MemGameCache::ins()->getInfoById($_rdata['mg_mem_id']);
  292. $_rdata['sum_money'] = $_mg_detail['sum_money'];
  293. $_rdata['is_like'] = (new AccountMemLikeModel())->isLike($mem_id, $goods_id);
  294. $_code = CommonStatus::NO_ERROR;
  295. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
  296. }
  297. /**
  298. * 根据类型获取排序方式
  299. *
  300. * @param int $sort_type
  301. *
  302. * @return string
  303. */
  304. private function getOrderByType($sort_type = 1) {
  305. switch ($sort_type) {
  306. default:
  307. case 1:
  308. $order = '-create_time';
  309. break;
  310. case 2:
  311. $order = '-price';
  312. break;
  313. case 3:
  314. $order = '+price';
  315. break;
  316. }
  317. return $order;
  318. }
  319. /**
  320. * 收藏/取消收藏小号商品
  321. *
  322. * @param $mem_id
  323. * @param $ags_id
  324. *
  325. * @return array
  326. */
  327. public function like($mem_id, $ags_id) {
  328. $_account_goods = AccountGoodsModel::get($ags_id);
  329. if (!$_account_goods) {
  330. $_code = AccountStatus::INVALID_ACCOUNT_GOODS;
  331. $this->huoError($_code, AccountStatus::getMsg($_code));
  332. }
  333. $_aml_model = (new AccountMemLikeModel());
  334. $_aml = $_aml_model->getByMemIdAndAgsId($mem_id, $ags_id);
  335. if ($_aml) {
  336. $_status = ($_aml['status'] == AccountMemLikeModel::STATUS_NOT_LIKE) ?
  337. AccountMemLikeModel::STATUS_LIKED : AccountMemLikeModel::STATUS_NOT_LIKE;
  338. $_rs = $_aml_model->updateData(['status' => $_status], $_aml['id']);
  339. } else {
  340. $_rs = $_aml_model->addData(['mem_id' => $mem_id, 'ags_id' => $ags_id]);
  341. }
  342. if (false === $_rs) {
  343. $_code = AccountStatus::INNER_ERROR;
  344. return $this->huoError($_code, AccountStatus::getMsg($_code));
  345. }
  346. $_code = AccountStatus::NO_ERROR;
  347. return $this->huoSuccess($_code, AccountStatus::getMsg($_code));
  348. }
  349. }