AccountLogic.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  2. /**
  3. * AccountLogic.php UTF-8
  4. *
  5. *
  6. * @date : 2018/6/12 16:49
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huoAccountDeal\logic;
  13. use huo\controller\queue\AccountOrderQueue;
  14. use huo\model\common\CommonModel;
  15. use huo\model\member\MemGameModel;
  16. use huo\model\member\MgRoleModel;
  17. use huoAccountDeal\model\AccountGoodsModel;
  18. use huoAccountDeal\model\AccountMemLikeModel;
  19. use huoAccountDeal\model\AccountOrderModel;
  20. use huolib\constant\AccountConst;
  21. use huolib\constant\CommonConst;
  22. use huolib\status\AccountStatus;
  23. use huolib\tool\StrUtils;
  24. class AccountLogic extends CommonModel {
  25. /**
  26. * 添加小号商品出售数据
  27. *
  28. * @param $data
  29. *
  30. * @return bool
  31. */
  32. public function addSellData($data) {
  33. //添加小号商品
  34. $_rs = (new AccountGoodsModel())->addData($data);
  35. if (!$_rs) {
  36. return false;
  37. }
  38. //小号账号锁定
  39. MemGameModel::update(['status' => MemGameModel::STATUS_LOCKED], ['id' => $data['mg_mem_id']]);
  40. return true;
  41. }
  42. /**
  43. * 添加预下单数据
  44. *
  45. * @param $data
  46. *
  47. * @return bool
  48. */
  49. public function addPreorderData($data) {
  50. $_account_order_id = (new AccountOrderModel())->addData($data);
  51. if (!$_account_order_id) {
  52. return false;
  53. }
  54. //小号商品锁定
  55. (new AccountGoodsModel())->updateData(
  56. [
  57. 'status' => AccountConst::STATUS_LOCKED,
  58. 'lock_time' => time(),
  59. ], $data['ags_id']
  60. );
  61. //发送取消订单延时队列
  62. $_order_info = (new AccountOrderModel())->getInfoById($_account_order_id);
  63. (new AccountOrderQueue($_order_info))->pushQueue();
  64. return true;
  65. }
  66. /**
  67. * 小号商品列表
  68. *
  69. * @param array $field
  70. * @param array $where
  71. * @param string $order
  72. * @param string $page
  73. *
  74. * @return array
  75. */
  76. public function getList($field = [], $where = [], $order = '-create_time', $page = '1,10') {
  77. $_model = (new AccountGoodsModel());
  78. $_order = $this->orderFilter($order);
  79. if (isset($where['is_like'])) {
  80. $_is_like = AccountConst::STATUS_KEEP;
  81. unset($where['is_like']);
  82. if (isset($where['mem_id'])) {
  83. $_map['status'] = $_is_like;
  84. $_map['mem_id'] = $where['mem_id'];
  85. $_goods_ids = (new AccountMemLikeModel())->where($_map)->column('ags_id');
  86. if (!empty($_goods_ids)) {
  87. $where['id'] = ['in', $_goods_ids];
  88. }
  89. }
  90. }
  91. if (!isset($where['is_me_sell']) && isset($where['mem_id'])) {
  92. unset($where['mem_id']);
  93. }
  94. if (isset($where['is_me_sell'])) {
  95. unset($where['is_me_sell']);
  96. }
  97. $_ext_where = '';
  98. if (isset($where['status']) && AccountConst::STATUS_PULL_ON_SHELVES == $where['status']) {
  99. unset($where['status']);
  100. $_ex_time = time() - AccountConst::ACCOUNT_MAX_LOCK_TIME;
  101. $_ext_where = 'status='.AccountConst::STATUS_PULL_ON_SHELVES.' OR status='.AccountConst::STATUS_LOCKED
  102. .' AND lock_time<'.$_ex_time;
  103. }
  104. $_count = $_model->where($where)->where($_ext_where)->count();
  105. if (empty($_count)) {
  106. return [
  107. 'count' => $_count,
  108. 'list' => []
  109. ];
  110. }
  111. $_datas = $_model->with('game')
  112. ->field('*')
  113. ->field($field)
  114. ->where($where)
  115. ->where($_ext_where)
  116. ->order($_order)
  117. ->page($page)
  118. ->select();
  119. if (is_object($_datas)) {
  120. $_datas = $_datas->toArray();
  121. }
  122. $_list = [];
  123. $_data = [];
  124. $_now_time = time();
  125. foreach ($_datas as $_v) {
  126. foreach ($field as $f) {
  127. $_data[$f] = $_v[$f];
  128. }
  129. $_data['game_id'] = isset($_v['game']['id']) ? $_v['game']['id'] : 0;
  130. $_data['game_icon'] = isset($_v['game']['icon']) ? $_v['game']['icon'] : '';
  131. $_data['gamename'] = isset($_v['game']['name']) ? $_v['game']['name'] : '';
  132. if (StrUtils::compareNumber($_v['lock_time'] + AccountConst::ACCOUNT_MAX_LOCK_TIME, $_now_time) < 0
  133. && AccountConst::STATUS_LOCKED == $_v['status']) {
  134. /* 锁定已超期 重新上架 */
  135. $_data['status'] = AccountConst::STATUS_PULL_ON_SHELVES;
  136. }
  137. $_list[] = $_data;
  138. }
  139. return [
  140. 'count' => $_count,
  141. 'list' => $_list
  142. ];
  143. }
  144. /**
  145. * 小号商品列表
  146. *
  147. * @param $id
  148. *
  149. * @return array
  150. */
  151. public function getDetail($id) {
  152. $_map['id'] = $id;
  153. $_model = (new AccountGoodsModel());
  154. $_data = $_model->with('game')->where($_map)->find();
  155. if (is_object($_data)) {
  156. $_data = $_data->toArray();
  157. }
  158. /* 锁定已超期 重新上架 */
  159. $_now_time = time();
  160. if (StrUtils::compareNumber($_data['lock_time'] + AccountConst::ACCOUNT_MAX_LOCK_TIME, $_now_time) < 0
  161. && AccountConst::STATUS_LOCKED == $_data['status']) {
  162. /* 锁定已超期 重新上架 */
  163. $_data['status'] = AccountConst::STATUS_PULL_ON_SHELVES;
  164. }
  165. return $_data;
  166. }
  167. /**
  168. * 获取玩家游戏区服角色列表
  169. *
  170. * @param $mem_id
  171. * @param $account_id
  172. * @param $page
  173. * @param string $order
  174. *
  175. * @return array|int
  176. */
  177. public function getMgServerList($mem_id, $account_id, $page, $order = '-create_time') {
  178. //验证玩家游戏角色归属
  179. $_mem_game = (new MemGameModel())->getInfoById($account_id);
  180. if (!$_mem_game) {
  181. return AccountStatus::MEM_GAME_NOT_EXISTS;
  182. }
  183. if ($_mem_game['mem_id'] != $mem_id) {
  184. return AccountStatus::ONLY_OPERATE_YOUR_OWN_ACCOUNT;
  185. }
  186. $_where = ['mg_mem_id' => $account_id];
  187. $_field = [
  188. 'id' => 'mg_role_id',
  189. 'server_id' => 'server_id',
  190. 'server_name' => 'server_name',
  191. 'role_id' => 'role_id',
  192. 'role_name' => 'role_name',
  193. ];
  194. $_model = new MgRoleModel();
  195. $_count = $_model->where($_where)->count();
  196. if (empty($_count)) {
  197. return [
  198. 'count' => $_count,
  199. 'list' => []
  200. ];
  201. }
  202. $_order = $_model->orderFilter($order);
  203. $_datas = $_model->field($_field)->where($_where)->order($_order)->page($page)->select();
  204. if (is_object($_datas)) {
  205. $_datas = $_datas->toArray();
  206. }
  207. return [
  208. 'count' => $_count,
  209. 'list' => $_datas
  210. ];
  211. }
  212. public function adminGoodsList($where = [], $page = '1,10') {
  213. $_map = [];
  214. if (!empty($where['start_time']) && !empty($where['end_time'])) {
  215. $_map['create_time'] = ['between',
  216. [strtotime($where['start_time']),
  217. CommonConst::CONST_DAY_SECONDS + strtotime($where['end_time'])]];
  218. } else if (!empty($where['start_time'])) {
  219. $_map['create_time'] = ['gt', strtotime($where['start_time'])];
  220. } else if (!empty($where['end_time'])) {
  221. $_map['create_time'] = ['lt', CommonConst::CONST_DAY_SECONDS + strtotime($where['end_time'])];
  222. }
  223. if (!empty($where['status'])) {
  224. $_map['status'] = $where['status'];
  225. }
  226. $_field = [
  227. 'id' => 'id',
  228. 'mem_id' => 'mem_id',
  229. 'app_id' => 'app_id',
  230. 'mg_mem_id' => 'mg_mem_id',
  231. 'server_name' => 'server_name',
  232. 'role_name' => 'role_name',
  233. 'title' => 'title',
  234. 'price' => 'price',
  235. 'status' => 'status',
  236. 'lock_time' => 'lock_time',
  237. 'create_time' => 'create_time',
  238. 'update_time' => 'update_time',
  239. ];
  240. $_order = '-create_time';
  241. return $this->getListIncludeMemGame($_field, $_map, $_order, $page);
  242. }
  243. /**
  244. * 获取商品列表,包含玩家和游戏信息
  245. *
  246. * @param array $field
  247. * @param array $where
  248. * @param string $order
  249. * @param string $page
  250. *
  251. * @return array
  252. * @throws \think\db\exception\DataNotFoundException
  253. * @throws \think\db\exception\ModelNotFoundException
  254. * @throws \think\exception\DbException
  255. */
  256. public function getListIncludeMemGame($field = [], $where = [], $order = '-create_time', $page = '1,10') {
  257. $_model = (new AccountGoodsModel());
  258. $_order = $_model->orderFilter($order);
  259. $_count = $_model->where($where)->count();
  260. if (empty($_count)) {
  261. return [
  262. 'count' => $_count,
  263. 'list' => []
  264. ];
  265. }
  266. $_datas = $_model->with('mem,game')->field($field)->where($where)->order($_order)->page($page)->select();
  267. if (is_object($_datas)) {
  268. $_datas = $_datas->toArray();
  269. }
  270. $_list = [];
  271. $_now_time = time();
  272. foreach ($_datas as $_v) {
  273. $_data = $_v;
  274. if (StrUtils::compareNumber($_v['lock_time'] + AccountConst::ACCOUNT_MAX_LOCK_TIME, $_now_time) < 0
  275. && AccountConst::STATUS_LOCKED == $_v['status']) {
  276. /* 锁定已超期 重新上架 */
  277. $_data['status'] = AccountConst::STATUS_PULL_ON_SHELVES;
  278. }
  279. $_list[] = $_data;
  280. }
  281. return [
  282. 'count' => $_count,
  283. 'list' => $_list
  284. ];
  285. }
  286. public function getInfoById($id) {
  287. $_model = (new AccountGoodsModel());
  288. $_data = $_model->with('mem,game')->find($id);
  289. if (is_object($_data)) {
  290. $_data = $_data->toArray();
  291. }
  292. return $_data;
  293. }
  294. public function unlock($mg_mem_id) {
  295. $_rs = (new MemGameModel())->updateData(
  296. [
  297. 'status' => MemGameModel::STATUS_NORMAL,
  298. ], $mg_mem_id
  299. );
  300. return $_rs;
  301. }
  302. /**
  303. * 获取收藏游戏列表
  304. *
  305. * @param array $where
  306. * @param string $page
  307. *
  308. * @return array
  309. * @throws \think\db\exception\DataNotFoundException
  310. * @throws \think\db\exception\ModelNotFoundException
  311. * @throws \think\exception\DbException
  312. */
  313. public function getAmlList($where = [], $page = '1,10') {
  314. $_map = [];
  315. if (!empty($where['start_time']) && !empty($where['end_time'])) {
  316. $_map['create_time'] = ['between',
  317. [strtotime($where['start_time']),
  318. CommonConst::CONST_DAY_SECONDS + strtotime($where['end_time'])]];
  319. } else if (!empty($param['start_time'])) {
  320. $_map['create_time'] = ['gt', strtotime($param['start_time'])];
  321. } else if (!empty($param['end_time'])) {
  322. $_map['create_time'] = ['lt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
  323. }
  324. if (!empty($where['ags_id'])) {
  325. $_map['ags_id'] = $where['ags_id'];
  326. }
  327. if (!empty($where['status'])) {
  328. $_map['status'] = $where['status'];
  329. }
  330. if (!empty($where['mem_id'])) {
  331. $_map['mem_id'] = $where['mem_id'];
  332. }
  333. $_rdata = ['count' => 0, 'list' => []];
  334. $_mal_model = new AccountMemLikeModel();
  335. $_count = $_mal_model->where($_map)->count('id');
  336. if (empty($_count)) {
  337. return $_rdata;
  338. }
  339. $_data = $_mal_model->with('mem')->where($where)->page($page)->order('create_time desc')->select();
  340. if (is_object($_data)) {
  341. $_data = $_data->toArray();
  342. }
  343. $_list = [];
  344. foreach ($_data as $_k => $_v) {
  345. $_list[$_k]['id'] = $_v['id'];
  346. $_list[$_k]['username'] = isset($_v['mem']) ? $_v['mem']['username'] : '';
  347. $_list[$_k]['create_time'] = $_v['create_time'];
  348. $_list[$_k]['update_time'] = $_v['update_time'];
  349. $_list[$_k]['status'] = $_v['status'];
  350. }
  351. return ['count' => $_count, 'list' => $_list];
  352. }
  353. }