diff --git a/admin/controllers/app/liche/Blindbox.php b/admin/controllers/app/liche/Blindbox.php new file mode 100644 index 00000000..bc426e9b --- /dev/null +++ b/admin/controllers/app/liche/Blindbox.php @@ -0,0 +1,268 @@ +load->model('app/liche/app_liche_blind_box_model', 'mdBlindBox'); + } + + public function index() + { + return $this->lists(); + } + + public function lists() + { + $params = $this->input->get(); + $params['page'] = $params['page'] ? intval($params['page']) : 1; + $params['size'] = $params['size'] ? intval($params['size']) : 20; + $lists = array(); + $where = array('status>' => -1); + $count = $this->mdBlindBox->count($where); + if ($count) { + $this->load->library('MyEncryption'); + $res = $this->mdBlindBox->select($where, 'id desc', $params['page'], $params['size']); + foreach ($res as $key => $value) { + $setValue = array(); + $setValue['id'] = $value['id']; + $setValue['title'] = $value['title']; + $setValue['s_time'] = $value['s_time']; + $setValue['e_time'] = $value['e_time']; + $setValue['c_time'] = date('Y-m-d H:i', $value['c_time']); + $setValue['status_name'] = $this->mdBlindBox->statusAry($value['status']); + $url = http_host_com('home') . "/h5/syt/blindbox?skey=" . $this->myencryption->base64url_encode("id=" . $value['id']); + $setValue['url'] = urlencode($url); + $lists[] = $setValue; + } + } + $this->data['_title'] = '盲盒抽奖列表'; + $this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count); + $this->data['lists'] = $lists; + $this->data['params'] = $params; + return $this->show_view('/app/liche/blindbox/lists', true); + } + + public function get() + { + $params = $this->input->get(); + $id = intval($params['id']); + $title = $time = $rule = $prizes_content = $prizes_note = $prizes_winning_ins = $share_desc = $bottom_word = + $bg_color = $lottery_num = ''; + $bg_img = $share_img = ['value' => '', 'src' => '']; + $prizes_list = []; + if ($id > 0) { + $re = $this->mdBlindBox->get(array('id' => $id)); + if (!$re || empty($re)) { + return $this->show_json(SYS_CODE_FAIL, '数据不存在!'); + } + $_title = '编辑盲盒抽奖'; + $dataInfo['editType'] = 0; + $dataInfo['edit_url'] = '/app/liche/blindbox/edit'; + $dataInfo['status'] = $re['status']; + $title = $re['title']; + $re['s_time'] && $time = $re['s_time'] . " ~ " . $re['e_time']; + $lottery_num = $re['lottery_num']; + if ($re['jsondata']) { + $jsondata = json_decode($re['jsondata'], true); + if ($jsondata['bg_img']) { + $bg_img['value'] = $jsondata['bg_img']; + $bg_img['src'] = build_qiniu_image_url($jsondata['bg_img']); + } + $jsondata['bg_color'] && $bg_color = $jsondata['bg_color']; + $jsondata['share_desc'] && $share_desc = $jsondata['share_desc']; + if ($jsondata['share_img']) { + $share_img['value'] = $jsondata['share_img']; + $share_img['src'] = build_qiniu_image_url($jsondata['share_img']); + } + $jsondata['bottom_word'] && $bottom_word = $jsondata['bottom_word']; + $jsondata['rule'] && $rule = $jsondata['rule']; + } + if ($re['prizes']) {//奖品配置 + $prizes = json_decode($re['prizes'], true); + $prizes_content = $prizes['content']; + $prizes_note = $prizes['note']; + $prizes_winning_ins = $prizes['winning_ins']; + foreach ($prizes['list'] as $key => $value) { + $value['img_src'] = $value['img_value'] ? build_qiniu_image_url($value['img_value']) : ''; + $prizes_list[] = $value; + } + } + } else { + $_title = '新增盲盒抽奖'; + $dataInfo['editType'] = 2; + $dataInfo['edit_url'] = '/app/liche/blindbox/add'; + $dataInfo['status'] = 0; + } + $status_list = []; + foreach ($this->mdBlindBox->statusAry() as $key => $value) { + $status_list[] = array("id" => $key, "name" => $value); + } + $dataInfo['id'] = $id; + $dataInfo['title'] = $title; + $dataInfo['bg_img'] = $bg_img; + $dataInfo['bg_color'] = $bg_color; + $dataInfo['time'] = $time; + $dataInfo['lottery_num'] = $lottery_num; + $dataInfo['share_desc'] = $share_desc; + $dataInfo['share_img'] = $share_img; + $dataInfo['bottom_word'] = $bottom_word; + $dataInfo['rule'] = $rule; + $dataInfo['prizes_content'] = $prizes_content; + $dataInfo['prizes_note'] = $prizes_note; + $dataInfo['prizes_winning_ins'] = $prizes_winning_ins; + $this->data['info'] = $dataInfo; + $this->data['status_list'] = $status_list; + $this->data['prizes_list'] = $prizes_list; + $this->data['_title'] = $_title; + return $this->show_view('/app/liche/blindbox/edit', true); + } + + public function add() + { + $info = $this->input->post('info'); + $checkData = $this->checkData($info); + if (!$checkData['code']) { + return $this->show_json($checkData['code'], $checkData['msg']); + } + $re = $this->mdBlindBox->get(array("title" => $info['title'], "status<>" => -1)); + if ($re) { + return $this->show_json(SYS_CODE_FAIL, '该标题已存在!'); + } + $json_data['bg_img'] = $info['bg_img']['value']; + $json_data['bg_color'] = $info['bg_color']; + $json_data['share_desc'] = $info['share_desc']; + $json_data['share_img'] = $info['share_img']['value']; + $json_data['bottom_word'] = $info['bottom_word']; + $json_data['rule'] = $info['rule']; + $jsondata = json_encode($json_data, JSON_UNESCAPED_UNICODE); + $prizes['content'] = $info['prizes_content']; + $prizes['note'] = $info['prizes_note']; + $prizes['winning_ins'] = $info['prizes_winning_ins']; + $prizes_list = []; + foreach ($info['prizes_list'] as $key => $value) { + unset($value['img_src']); + $prizes_list[] = $value; + } + $prizes['list'] = $prizes_list; + $prizes = json_encode($prizes, JSON_UNESCAPED_UNICODE); + $addData = ["title" => $info['title'], "lottery_num" => $info['lottery_num'], "jsondata" => $jsondata, "prizes" => $prizes + , "status" => $info['status'], "c_time" => time()]; + if ($info['time']) { + $time = explode(' ~ ', $info['time']); + $addData['s_time'] = $time[0]; + $addData['e_time'] = $time[1]; + } + $id = $this->mdBlindBox->add($addData); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '新增失败!'); + } + $this->data['type'] = 'add'; + $this->data['id'] = $id; + return $this->show_json(SYS_CODE_SUCCESS, '新增成功!'); + } + + public function edit() + { + $info = $this->input->post('info'); + $checkData = $this->checkData($info); + if (!$checkData['code']) { + return $this->show_json($checkData['code'], $checkData['msg']); + } + if (!$info['id']) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $json_data['bg_img'] = $info['bg_img']['value']; + $json_data['bg_color'] = $info['bg_color']; + $json_data['share_desc'] = $info['share_desc']; + $json_data['share_img'] = $info['share_img']['value']; + $json_data['bottom_word'] = $info['bottom_word']; + $json_data['rule'] = $info['rule']; + $jsondata = json_encode($json_data, JSON_UNESCAPED_UNICODE); + $prizes['content'] = $info['prizes_content']; + $prizes['note'] = $info['prizes_note']; + $prizes['winning_ins'] = $info['prizes_winning_ins']; + $prizes_list = []; + foreach ($info['prizes_list'] as $key => $value) { + unset($value['img_src']); + $prizes_list[] = $value; + } + $prizes['list'] = $prizes_list; + $prizes = json_encode($prizes, JSON_UNESCAPED_UNICODE); + $updateData = ["title" => $info['title'], "lottery_num" => $info['lottery_num'], "jsondata" => $jsondata, "prizes" => $prizes]; + if ($info['time']) { + $time = explode(' ~ ', $info['time']); + $updateData['s_time'] = $time[0]; + $updateData['e_time'] = $time[1]; + } + $this->mdBlindBox->update($updateData, ['id' => $info['id']]); + $this->data['type'] = 'edit'; + return $this->show_json(SYS_CODE_SUCCESS, '修改成功!'); + } + + /** + * Notes:修改状态 + * Created on: 2020/8/24 11:12 + * Created by: dengbw + * @return bool|void + */ + public function edit_status() + { + $info = $this->input->post('info'); + if (!$info['id']) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $this->mdBlindBox->update(array("status" => intval($info['status'])), array('id' => $info['id'])); + return $this->show_json(SYS_CODE_SUCCESS, '操作成功!'); + } + + + /** + * Notes:检查新增/修改数据 + * Created on: 2020/8/20 11:59 + * Created by: dengbw + * @param $info + * @return array + */ + private function checkData($info) + { + $msg = ''; + $code = SYS_CODE_FAIL; + if (!$info) { + $msg = '非法参数'; + } else if (!$info['title']) { + $msg = '请输入标题'; + } else if (!$info['bg_img']) { + $msg = '请上传背景图片'; + } else if (!$info['bg_color']) { + $msg = '请上传背景颜色'; + } else if (!$info['time']) { + $msg = '请选择活动时间'; + } else if (!$info['rule']) { + $msg = '请输入其它事项'; + } else { + $code = SYS_CODE_SUCCESS; + } + return array('code' => $code, 'msg' => $msg); + } + + public function del() + { + } + + public function batch() + { + // TODO: Implement batch() method. + } + + public function export() + { + } +} \ No newline at end of file diff --git a/admin/controllers/app/liche/Main.php b/admin/controllers/app/liche/Main.php index 19352844..4fc91282 100644 --- a/admin/controllers/app/liche/Main.php +++ b/admin/controllers/app/liche/Main.php @@ -21,6 +21,7 @@ class Main extends HD_Controller $this->load->model('bobing/bobing_user_model', 'mdBobingUser'); $this->load->model('app/user_accountlog_model'); $this->load->model('app/liche/app_liche_luckybag_users_model', 'mdLuckyBagUsers'); + $this->load->model('app/liche/app_liche_blind_box_model', 'mdBlindBox'); } public function index() @@ -57,6 +58,15 @@ class Main extends HD_Controller ), ); + $value = $this->mdBlindBox->count(['status>' => -1]); + $list[] = array( + 'title' => '盲盒抽奖(个)', + 'value' => $value, + 'btns' => array( + array('name' => '查看详情', 'url' => '/app/liche/blindbox'), + ), + ); + $value = $this->mdTopics->count(array('app_id' => $this->app_id)); $list[] = array( 'title' => '专题(个)', diff --git a/admin/controllers/app/licheb/Userslog.php b/admin/controllers/app/licheb/Userslog.php index 12600b46..73125bdd 100644 --- a/admin/controllers/app/licheb/Userslog.php +++ b/admin/controllers/app/licheb/Userslog.php @@ -58,7 +58,47 @@ class Userslog extends HD_Controller private function dataBizSelect($params) { - $lists = $where = []; + $lists = $where = $where_c = $where_dt = []; + $same_day = 0; + if ($params['time']) { + $time = explode(' ~ ', $params['time']); + $time[0] == $time[1] && $same_day = 1; + if ($time[0]) { + $where["log_date>="] = $time[0]; + $where_c["c_time>="] = strtotime("{$time[0]} 00:00:00"); + $where_dt["dt_time>="] = "{$time[0]} 00:00:00"; + } + if ($time[1]) { + $where["log_date<="] = $time[1]; + $where_c["c_time<="] = strtotime("{$time[1]} 23:59:59"); + $where_dt["dt_time<="] = "{$time[1]} 23:59:59"; + } + } else { + $where_c["c_time>="] = strtotime("2022-04-15 00:00:00"); + $where_dt["dt_time>="] = "2022-04-15 00:00:00"; + } + //门店搜索 + if (!$same_day && ($params['type'] || $params['biz_id'] || $params['city_id'] || $params['county_id'])) { + $where_cdt['status'] = 1; + $params['type'] && $where_cdt['type'] = $params['type']; + $params['biz_id'] && $where_cdt['id'] = $params['biz_id']; + $params['city_id'] && $where_cdt['city_id'] = $params['city_id']; + $params['county_id'] && $where_cdt['county_id'] = $params['county_id']; + $res_biz = $this->mdBiz->select($where_cdt, 'id desc', 0, 0, 'id'); + if ($res_biz) { + $str_ids = implode(',', array_column($res_biz, 'id')); + $where_c["biz_id in ({$str_ids})"] = null; + $where_dt["biz_id in ({$str_ids})"] = null; + } else { + $where_c['biz_id'] = -2; + $where_dt['biz_id'] = -2; + } + } + if ($params['type']) { + $where["type"] = $params['type']; + } else { + $params['type'] = ''; + } if ($params['biz_id']) { $where['biz_id'] = $params['biz_id']; } else if ($params['city_id']) { @@ -77,16 +117,6 @@ class Userslog extends HD_Controller $params['county_id'] = ''; $params['biz_id'] = ''; } - if ($params['type']) { - $where["type"] = $params['type']; - } else { - $params['type'] = ''; - } - if ($params['time']) { - $time = explode(' ~ ', $params['time']); - $time[0] && $where["log_date>="] = $time[0]; - $time[1] && $where["log_date<="] = $time[1]; - } $total = $this->mdBizsLog->count($where); $offlineSources = $this->mdCustomers->offlineSources(); if ($total) { @@ -163,15 +193,29 @@ class Userslog extends HD_Controller $customers = $c_num = $orders = 0; $customers_info = $c_num_info = $orders_info = ''; foreach ($offlineSources as $k => $v) { - $sum2 = $this->mdUsersLog->sum("customer_{$k}", $where);//客户数 - if ($sum2['customer_' . $k]) {//客户数 - $customers += $sum2['customer_' . $k]; - $customers_info .= "
{$v['name']}:{$sum2['customer_'.$k]}"; - } - $sum2 = $this->mdUsersLog->sum("c_num_{$k}", $where);//进店人数 - if ($sum2['c_num_' . $k]) { - $c_num += $sum2['c_num_' . $k]; - $c_num_info .= "
{$v['name']}:{$sum2['c_num_'.$k]}"; + if ($same_day) { + $sum2 = $this->mdUsersLog->sum("customer_{$k}", $where);//客户数 + if ($sum2['customer_' . $k]) {//客户数 + $customers += $sum2['customer_' . $k]; + $customers_info .= "
{$v['name']}:{$sum2['customer_'.$k]}"; + } + $sum2 = $this->mdUsersLog->sum("c_num_{$k}", $where);//进店人数 + if ($sum2['c_num_' . $k]) { + $c_num += $sum2['c_num_' . $k]; + $c_num_info .= "
{$v['name']}:{$sum2['c_num_'.$k]}"; + } + } else { + $count2 = $this->mdCustomers->count(array_merge($where_c, ['of_id' => $k]));//客户数 + if ($count2) { + $customers += $count2; + $customers_info .= "
{$v['name']}:{$count2}"; + } + $count2 = $this->mdCustomers->count(array_merge($where_dt, ['of_id' => $k]));//进店人数 + if ($count2) { + + $c_num += $count2; + $c_num_info .= "
{$v['name']}:{$count2}"; + } } $sum2 = $this->mdUsersLog->sum("order_{$k}", $where);//订单数 if ($sum2['order_' . $k]) { diff --git a/admin/views/app/liche/blindbox/edit.php b/admin/views/app/liche/blindbox/edit.php new file mode 100644 index 00000000..4d31fadd --- /dev/null +++ b/admin/views/app/liche/blindbox/edit.php @@ -0,0 +1,461 @@ +
+
+
+
+
+
+
+ 状态 +
+
+ + +
+
+
+ +
+
+
+
+
+ 活动信息 +
+
+
+ +
+ +
+
+
+ +
+
+ + 建议尺寸宽度690 + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + +
图片标题积分排序 + 添加 +
+ +
+ +
+
+
+ + +
+
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/admin/views/app/liche/blindbox/lists.php b/admin/views/app/liche/blindbox/lists.php new file mode 100644 index 00000000..e59b0840 --- /dev/null +++ b/admin/views/app/liche/blindbox/lists.php @@ -0,0 +1,68 @@ +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
ID标题开始时间结束时间创建时间状态
+ 分享链接 + 编辑 +
+
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/admin/views/app/licheb/userslog/lists.php b/admin/views/app/licheb/userslog/lists.php index 86982827..7962f5dd 100644 --- a/admin/views/app/licheb/userslog/lists.php +++ b/admin/views/app/licheb/userslog/lists.php @@ -19,7 +19,7 @@
- @@ -193,6 +193,10 @@ } }); }, + set_type: function () { + var that = this; + that.params.city_id = ''; + }, set_county: function () { var that = this; that.bizAry = []; @@ -245,6 +249,7 @@ data: { city_id: that.params.city_id, county_id: that.params.county_id, + type: that.params.type, status: 1 }, success: function (response) { diff --git a/api/controllers/wxapp/liche/Blindbox.php b/api/controllers/wxapp/liche/Blindbox.php new file mode 100644 index 00000000..78e43985 --- /dev/null +++ b/api/controllers/wxapp/liche/Blindbox.php @@ -0,0 +1,133 @@ +login_white = [];//登录白名单 + $this->check_status = [];//用户状态校验 + $this->check_mobile = [];//需要手机号 + $this->check_headimg = [];//授权微信信息 + $this->load->model('app/liche/app_liche_blind_box_model', 'mdBlindBox'); + $this->load->model('app/liche/app_liche_credits_log_model', 'mdCreditsLog'); + } + + protected function get() + { + $params = $this->input_param(); + $id = intval($params['id']);//活动id + $re = $this->mdBlindBox->get(["id" => $id, "status" => 1]); + if (!$re) { + throw new Hd_exception('活动不存在!', API_CODE_FAIL); + } + $bgimg = $bgcolor = $share_img = $share_desc = $rule_content = $prizes_content = $prizes_note = $bottom_word = ''; + $draw_value = 0; + if ($re['jsondata']) { + $jsondata = json_decode($re['jsondata'], true); + $jsondata['bg_img'] && $bgimg = build_qiniu_image_url($jsondata['bg_img']); + $jsondata['bg_color'] && $bgcolor = $jsondata['bg_color']; + $jsondata['rule'] && $rule_content = str_replace("\n", "
", $jsondata['rule']); + $jsondata['share_img'] && $share_img = build_qiniu_image_url($jsondata['share_img']); + $jsondata['share_desc'] && $share_desc = $jsondata['share_desc']; + $jsondata['bottom_word'] && $bottom_word = $jsondata['bottom_word']; + } + if ($re['prizes']) { + $prizes = json_decode($re['prizes'], true); + $prizes['content'] && $prizes_content = $prizes['content']; + $prizes['note'] && $prizes_note = $prizes['note']; + } + $info = ['title' => $re['title'], 'bgimg' => $bgimg, 'bgcolor' => $bgcolor]; + //计算抽奖机会 + if ($this->myuid) { + $lottery_log = $this->mdCreditsLog->count(["target_id" => $id, 'type' => 0, "credit_in>" => 0, "uid" => $this->myuid]); + $draw_value = $re['lottery_num'] - $lottery_log; + $draw_value < 0 && $draw_value = 0; + } + $info['draw'] = ['title' => '次抽奖机会', 'value' => $draw_value]; + $time = date('Y年m月d日', strtotime($re['s_time'])) . ' - ' . date('Y年m月d日', strtotime($re['e_time'])); + $info['rule'] = ['title' => '盲盒规则', 'time' => ['title' => '活动时间', 'value' => $time], + 'Other' => ['title' => '其它事项', 'value' => $rule_content]]; + $info['prizes'] = ['title' => '盲盒礼品说明', 'value' => $prizes_content, 'note' => $prizes_note]; + $info['bottom_word'] = $bottom_word; + $info['share'] = ["img" => $share_img, "desc" => $share_desc]; + return $info; + } + + + /** + * Notes:抽奖 + * Created on: 2022/7/19 11:05 + * Created by: dengbw + * @return mixed + * @throws Hd_exception + */ + protected function put() + { + $params = $this->input_param(); + $id = intval($params['id']);//活动id + $re = $this->mdBlindBox->get(["id" => $id, "status" => 1]); + if (!$re) { + throw new Hd_exception('活动不存在!', API_CODE_FAIL); + } + $this->checkData($re); + $prizes = json_decode($re['prizes'], true); + $count = count($prizes['list']) - 1; + $num = rand(0, $count); + $prizes_item = $prizes['list'][$num]; + $winning = []; + if ($prizes_item) { + $img = $prizes_item['img_value'] ? build_qiniu_image_url($prizes_item['img_value']) : ''; + $credit = intval($prizes_item['credit']); + $winning = ['title' => $prizes_item['title'], 'img' => $img, 'value' => "抽到{$credit}积分!"]; + $this->load->library('entity/credits_entity');//加积分 + $jsondata = ['id' => $prizes_item['id'], 'title' => $prizes_item['title'], 'credit' => $prizes_item['credit']]; + //积分变动 + $result = $this->credits_entity->change($this->myuid, $credit, 0, $id, '盲盒抽奖', $jsondata); + if (!$result['code']) { + throw new Hd_exception($result['msg'], API_CODE_FAIL); + } + //冻结资金 + $this->credits_entity->freeze($this->myuid, $credit, 0); + } + $info = ['title' => '恭喜您!', 'winning_ins' => $prizes['winning_ins'], 'winning' => $winning]; + return $info; + } + + protected function checkData($params) + { + if (!$this->myuid) { + throw new Hd_exception('需先登录,才能抽奖!', API_CODE_FAIL); + } + $date = date('Y-m-d H:i:s'); + if ($params['s_time'] > $date) { + throw new Hd_exception('活动未开始!', API_CODE_FAIL); + } + if ($params['e_time'] < $date) { + throw new Hd_exception('活动已结束!', API_CODE_FAIL); + } + if (!$params['prizes']) { + throw new Hd_exception('未配置奖项!', API_CODE_FAIL); + } + if ($params['lottery_num']) { + //查找抽奖记录 + $lottery_num = $this->mdCreditsLog->count(["target_id" => $params['id'], 'type' => 0, "credit_in>" => 0, "uid" => $this->myuid]); + if ($params['lottery_num'] <= $lottery_num) { + throw new Hd_exception('抽奖机会已用完!', API_CODE_FAIL); + } + } + } + + protected function post() + { + } +} diff --git a/common/models/app/App_model.php b/common/models/app/App_model.php index ce50a98a..681698d7 100644 --- a/common/models/app/App_model.php +++ b/common/models/app/App_model.php @@ -36,6 +36,7 @@ class App_model extends HD_Model 'pages_groupcode_detail' => 'pages/groupCode/index', 'pages_special2' => 'pages/special2/index', 'pages_storeInfo' => array('id' => 'biz_id', 'pages' => 'pages/storeInfo/index'), + 'pages_lantushijia' => 'pages/topicActivity/lantushijia/index', ), ), 2 => array( diff --git a/common/models/app/liche/App_liche_blind_box_model.php b/common/models/app/liche/App_liche_blind_box_model.php new file mode 100644 index 00000000..8bce152d --- /dev/null +++ b/common/models/app/liche/App_liche_blind_box_model.php @@ -0,0 +1,35 @@ +table_name, 'default'); + } + + /** + * Notes:状态 + * Created on: 2022/7/14 11:23 + * Created by: dengbw + * @param string $id + * @return array|mixed + */ + public function statusAry($id = '') + { + $arr = [-1 => '已删除', 0 => '待审核', 1 => '已通过', 2 => '未通过']; + if (strlen($id)) { + return $arr[$id]; + } else { + return $arr; + } + } +} \ No newline at end of file