GoodsController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /**
  3. * GoodsController.php UTF-8
  4. *
  5. *
  6. * @date : 2018/7/31 10:34
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : Huosdk 8.0
  11. */
  12. namespace api\accountdeal\controller;
  13. use api\common\controller\V2ApiBaseController;
  14. use huoAccountDeal\controller\AccountOut;
  15. use huoAccountDeal\controller\MemGameOut;
  16. use huolib\constant\AccountConst;
  17. use huolib\sms\Sms;
  18. use huolib\status\MemberStatus;
  19. use think\Lang;
  20. class GoodsController extends V2ApiBaseController {
  21. public function _initialize() {
  22. parent::_initialize();
  23. $langSet = $this->request->langset();
  24. Lang::load([APP_PATH.'accountdeal'.DS.'lang'.DS.$langSet.DS.'account'.EXT,]);
  25. }
  26. /**
  27. * 商品-商品列表
  28. * http://doc.huosdk.com/138?page_id=3426
  29. * 【域名】/account/goods/list
  30. */
  31. public function getGoodsList() {
  32. $_sort_type = $this->request->param('sort_type/d', 1);
  33. $_app_id = $this->request->param('game_id/d', 0);
  34. $_keyword = $this->request->param('keyword/s', '');
  35. $_is_like = $this->request->param('is_like/d', 0);
  36. $_status = $this->request->param('status/d', 0);
  37. $_is_me_sell = $this->request->param('is_me_sell/d', 0);
  38. $_page = $this->request->param('page/d', 1);
  39. $_offset = $this->request->param('offset/d', 10);
  40. $_where = [];
  41. !empty($_keyword) && $_where['keyword'] = trim($_keyword);
  42. !empty($_app_id) && $_where['app_id'] = $_app_id;
  43. !empty($_status) && $_where['status'] = $_status;
  44. !empty($_is_me_sell) && $_where['is_me_sell'] = $_is_me_sell;
  45. if (2 == $_is_like) {
  46. $_where['is_like'] = $_is_like;
  47. }
  48. $_where['mem_id'] = $this->mem_id;
  49. $_rdata = (new AccountOut())->goodsList($_where, $_sort_type, $_page.','.$_offset);
  50. $this->returnData($_rdata);
  51. }
  52. /**
  53. * 商品-商品详情
  54. * http://doc.huosdk.com/138?page_id=3802
  55. * 【域名】/account/goods/detail
  56. */
  57. public function getGoodsDetail() {
  58. $_goods_id = $this->request->param('goods_id/d', 0);
  59. $_mem_id = $this->mem_id;
  60. $_rdata = (new AccountOut())->getGoodsDetail($_goods_id, $_mem_id);
  61. $this->returnData($_rdata);
  62. }
  63. /**
  64. * 玩家-收藏(取消)
  65. * http://doc.huosdk.com/138?page_id=3431
  66. * 【域名】/user/goods/like
  67. */
  68. public function like() {
  69. $this->checkLogin();
  70. $_goods_id = $this->request->param('goods_id/d', 0);
  71. $_mem_id = $this->getMemId();
  72. $_rdata = (new AccountOut())->like($_mem_id, $_goods_id);
  73. $this->returnData($_rdata);
  74. }
  75. /**
  76. * 商品-游戏列表
  77. * http://doc.huosdk.com/138?page_id=3427
  78. * 【域名】/account/game/list
  79. */
  80. public function getGameList() {
  81. $_page = $this->request->param('page/d', 1);
  82. $_offset = $this->request->param('offset/d', 10);
  83. $_is_mine = $this->request->param('is_mine/d', 0);
  84. $_page = $_page.','.$_offset;
  85. if (AccountConst::ACCOUNT_IS_MINE == $_is_mine) {
  86. $this->checkLogin();
  87. $_rdata = (new MemGameOut())->getSellMyGameList($this->mem_id, $_page);
  88. } else {
  89. $_rdata = (new MemGameOut())->getSellGameList($_page);
  90. }
  91. $this->returnData($_rdata);
  92. }
  93. /**
  94. * 卖号-出售小号
  95. * http://doc.huosdk.com/138?page_id=3430
  96. * 【域名】/account/goods/sell
  97. */
  98. public function sell() {
  99. $this->checkLogin();
  100. $_param = $this->request->param();
  101. $_result = $this->validate($_param, 'Account.sell');
  102. if ($_result !== true) {
  103. $this->error($_result);
  104. }
  105. $_sms_data = $this->rq_data['sms'];
  106. $_mobile = $_sms_data['mobile'];
  107. $_type = $_sms_data['type'];
  108. $_code = $_sms_data['code'];
  109. /* 校验短信是否正确 */
  110. $_sms_rs = (new Sms())->check($_mobile, $_code, $_type);
  111. if (MemberStatus::NO_ERROR != $_sms_rs['code']) {
  112. $this->error($_sms_rs['msg'], [], $_sms_rs['code']);
  113. }
  114. $_mem_id = $this->mem_id;
  115. $_mg_mem_id = $this->request->param('mg_mem_id/d', 0);
  116. $_mg_role_id = $this->request->param('mg_role_id/d');
  117. $_title = $this->request->param('title/s');
  118. $_description = $this->request->param('description/s');
  119. $_price = $this->request->param('price/f', 0);
  120. $_image = $this->request->param('image', '', 'htmlspecialchars_decode');
  121. $_rs = (new AccountOut())->sell(
  122. $_mem_id, $_mg_mem_id, $_mg_role_id, $_title, $_description, $_price, $_image
  123. );
  124. $this->returnData($_rs);
  125. }
  126. /**
  127. * 卖号-小号商品修改
  128. * http://doc.huosdk.com/138?page_id=3851
  129. * 【域名】/account/goods/edit
  130. */
  131. public function edit() {
  132. $this->checkLogin();
  133. $_param = $this->request->param();
  134. $_result = $this->validate($_param, 'Account.edit');
  135. if ($_result !== true) {
  136. $this->error($_result);
  137. }
  138. $_sms_data = $this->rq_data['sms'];
  139. $_mobile = $_sms_data['mobile'];
  140. $_type = $_sms_data['type'];
  141. $_code = $_sms_data['code'];
  142. /* 校验短信是否正确 */
  143. $_sms_rs = (new Sms())->check($_mobile, $_code, $_type);
  144. if (MemberStatus::NO_ERROR != $_sms_rs['code']) {
  145. $this->error($_sms_rs['msg'], [], $_sms_rs['code']);
  146. }
  147. $_mem_id = $this->mem_id;
  148. $_mg_role_id = $this->request->param('mg_role_id/d');
  149. $_title = $this->request->param('title/s');
  150. $_description = $this->request->param('description/s');
  151. $_goods_id = $this->request->param('goods_id/d', '');
  152. $_price = $this->request->param('price/f', 0);
  153. $_image = $this->request->param('image', '', 'htmlspecialchars_decode');
  154. $_rs = (new AccountOut())->edit(
  155. $_goods_id, $_mem_id, $_mg_role_id, $_title, $_description, $_price, $_image
  156. );
  157. $this->returnData($_rs);
  158. }
  159. /**
  160. * http://doc.huosdk.com/138?page_id=3849
  161. * 卖号-下架小号
  162. * 【域名】/account/goods/cancel
  163. */
  164. public function cancel() {
  165. $this->checkLogin();
  166. $_param = $this->request->param();
  167. $_result = $this->validate($_param, 'Account.cancel');
  168. if ($_result !== true) {
  169. $this->error($_result);
  170. }
  171. $_goods_id = $this->request->param('goods_id/d', '');
  172. $_rs = (new AccountOut())->cancel($_goods_id);
  173. $this->returnData($_rs);
  174. }
  175. }