123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- /**
- * Goods.php UTF-8
- * 商品处理
- *
- * @date : 2018/5/7 22:43
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\controller\lottery;
- use huo\controller\common\Base;
- use huo\controller\member\MemCache;
- use huo\controller\posts\ShareAct;
- use huo\controller\shop\Award;
- use huo\controller\shop\GoodsCache;
- use huo\controller\shop\ItgOrder;
- use huo\logic\posts\PostsLogic;
- use huo\logic\shop\ItgOrderLogic;
- use huo\model\member\MemActivityModel;
- use huolib\constant\CacheConst;
- use huolib\constant\MemItgConst;
- use huolib\constant\NewsConst;
- use huolib\status\CommonStatus;
- use huolib\status\ShopStatus;
- use huolib\tool\Rand;
- use think\Cache;
- class Lottery extends Base {
- /**
- * 获取抽奖活动详情
- *
- * @param int $_mem_id
- * @param $_act_id int 活动id
- *
- * @return array
- */
- public function getDetail($_mem_id = 0, $_act_id) {
- if (!is_numeric($_act_id) || $_act_id < 0) {
- return $this->retErrMsg(CommonStatus::INVALID_PARAMS);
- }
- if (!empty($_mem_id)) {
- //当天首次进入,重置活动抽奖次数
- (new ShareAct())->resetLotteryCnt($_mem_id, $_act_id);
- }
- $_posts_data = (new PostsLogic())->getDetail($_act_id, NewsConst::NEWS_TYPE_AWARD);
- $_mem_act_model = new MemActivityModel();
- $_mem_act_data = $_mem_act_model->getMemAct($_mem_id, $_act_id);
- if (empty($_mem_act_data)) {
- if ($_mem_id > 0) {
- $_mem_act_data['mem_id'] = $_mem_id;
- $_mem_act_data['act_id'] = $_act_id;
- $_mem_act_id = $_mem_act_model->addMemAct($_mem_act_data);
- $_mem_act_data = $_mem_act_model->getMemActById($_mem_act_id);
- }
- }
- //获取最新的获奖记录20条
- $_where = array();
- $_where['act_id'] = $_act_id;
- $_itg_order_logic = new ItgOrderLogic();
- $_award_ad = $_itg_order_logic->getAwardOrderList($_where, "1,20");
- if ($_mem_id > 0) {//已登录
- $_me_data = MemCache::ins()->getMeInfoById($_mem_id);
- //获取我的抽奖记录
- $_where['mem_id'] = $_mem_id;
- $_rdata['my_integral'] = $_me_data['my_integral'];
- } else {
- $_rdata['my_integral'] = 0;
- }
- //我的奖品
- $_where['mem_id'] = $_mem_id;
- $_my_award = $_itg_order_logic->getAwardOrderList($_where, "1,20");;
- $_rdata['act_id'] = $_act_id;
- $_rdata['start_time'] = $_posts_data['start_time'];
- $_rdata['end_time'] = $_posts_data['end_time'];
- $_rdata['cost_integral'] = $_posts_data['cost_integral'];
- $_rdata['free_cnt'] = $_mem_act_data['free_cnt'] + $_mem_act_data['today_cnt'];
- $_rdata['roulette_img'] = $_posts_data['turntable'];
- $_rdata['pointer_img'] = $_posts_data['pointer'];
- $_rdata['award'] = Award::ins()->getAwards($_act_id);
- $_rdata['award_ad'] = $_award_ad;
- $_rdata['my_award'] = $_my_award;
- $_desc_list = explode("\n", $_posts_data['excerpt']);
- $_rdata['desc_list'] = $_desc_list;
- $_code = ShopStatus::NO_ERROR;
- return $this->huoSuccess($_code, ShopStatus::getMsg($_code), $_rdata);
- }
- /**
- * 抽奖
- *
- * @param $_mem_id
- * @param int $_act_id 活动id
- *
- * @return array
- */
- public function draw($_mem_id, $_act_id) {
- $_posts_data = (new PostsLogic())->getDetail($_act_id, NewsConst::NEWS_TYPE_AWARD);
- if (NewsConst::NEWS_PUBLISHED != $_posts_data['status']) { //未发布
- return $this->_getShopStatusReturn(ShopStatus::LOTTERY_HAS_NOT_STARTED);
- }
- $_time = time();
- if ($_time < $_posts_data['start_time']) { //活动未开始
- return $this->_getShopStatusReturn(ShopStatus::LOTTERY_HAS_NOT_STARTED);
- }
- if ($_time > $_posts_data['end_time']) { //活动已结束
- return $this->_getShopStatusReturn(ShopStatus::LOTTERY_HAS_ENDED);
- }
- $_award_datas = Award::ins()->getAwards($_act_id);
- $_arr = [];
- if (!empty($_award_datas)) {
- foreach ($_award_datas as $_k => $_v) {
- $_arr[$_k] = $_v['rate'];
- }
- }
- if (empty($_arr)) {
- return $this->_getShopStatusReturn(ShopStatus::LOTTERY_ERROR);
- }
- // /* 玩家重复点击抽奖临时处理 */
- // $_key = CacheConst::CACHE_MEM_LOTTERY_PREFIX.$_mem_id;
- // if (Cache::get($_key)) {
- // $_code = CommonStatus::TOO_MANY_REQUESTS;
- //
- // return $this->huoError($_code, CommonStatus::getMsg($_code));
- // } else {
- // Cache::set($_key, 1, MemItgConst::LOTTERY_LIMIT_TIME);
- // }
- $_key = Rand::getRand($_arr);
- $_award_data = $_award_datas[$_key];
- $_goods_id = $_award_data['goods_id'];
- if (empty($_goods_id)) {
- $_goods_id = MemItgConst::AWARD_NO_GOODS;
- }
- $_cost_integral = $_posts_data['cost_integral'];
- $_rs = (new ItgOrder())->drawExchange($_mem_id, $_goods_id, [], $_act_id, $_cost_integral);
- if (ShopStatus::NO_ERROR != $_rs['code']) {
- return $this->huoError($_rs['code'], $_rs['msg']);
- }
- $_goods_data = GoodsCache::ins()->getInfoByGoodsId($_goods_id);
- if ($_goods_data['object_name'] == MemItgConst::GOODS_IS_INTEGRAL
- || $_goods_data['object_name'] == MemItgConst::GOODS_IS_REDPACKET) {
- $shipping_status = MemItgConst::SHIP_STATUS_SUC;
- } else {
- $shipping_status = MemItgConst::SHIP_STATUS_WAIT_GET;
- }
- $_mem_act_model = new MemActivityModel();
- $_mem_act_data = $_mem_act_model->getMemAct($_mem_id, $_act_id);
- $_me_data = MemCache::ins()->getMeInfoById($_mem_id);
- //获取最新的获奖记录20条
- $_where = array();
- $_where['act_id'] = $_act_id;
- $_itg_order_logic = new ItgOrderLogic();
- $_award_ad = $_itg_order_logic->getAwardOrderList($_where, "1,20");
- //获取我的抽奖记录
- $_where['mem_id'] = $_mem_id;
- $_my_award = $_itg_order_logic->getAwardOrderList($_where, "1,20");;
- $_rdata['act_id'] = $_act_id;
- $_rdata['my_integral'] = $_me_data['my_integral'];
- $_rdata['cost_integral'] = $_cost_integral;
- $_rdata['free_cnt'] = $_mem_act_data['free_cnt'] + $_mem_act_data['today_cnt'];
- $_rdata['award_id'] = $_award_data['id'];
- $_rdata['order_id'] = $_rs['data']['order_id'];
- $_rdata['shipping_status'] = $shipping_status;
- $_rdata['list_order'] = $_award_data['list_order'];
- $_rdata['goods_id'] = $_goods_id;
- $_rdata['is_real'] = $_goods_data['is_real'];
- $_rdata['object_type'] = get_val($_goods_data, 'object_name', '');
- $_rdata['award_name'] = $_award_data['award_name'];
- $_rdata['original_img'] = $_goods_data['original_img'];
- if ($_goods_id == MemItgConst::AWARD_LOSE_GOODS_ID) {
- $_rdata['has_award'] = 1;
- } else {
- $_rdata['has_award'] = 2;
- }
- $_rdata['award_ad'] = $_award_ad;
- $_rdata['my_award'] = $_my_award;
- $_code = ShopStatus::NO_ERROR;
- return $this->huoSuccess($_code, ShopStatus::getMsg($_code), $_rdata);
- }
- protected function _getShopStatusReturn($code) {
- return $this->huoError($code, ShopStatus::getMsg($code));
- }
- }
|