Files
liche/api/controllers/wxapp/neta/Act.php
T
2024-02-02 15:43:30 +08:00

128 lines
4.1 KiB
PHP

<?php
defined('WXAPP_APP') or exit('No direct script access allowed');
ini_set('display_errors', 'On');
error_reporting(E_ERROR);
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
class Act extends Wxapp
{
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
$this->login_white = 'all';//登录白名单
$this->check_status = [];//用户状态校验
$this->check_mobile = [];//需要手机号
$this->check_headimg = [];//授权微信信息
$this->load->model('market/market_sylive_activity_model');
$this->load->model('market/market_sylive_order_model');
$this->load->model('market/market_sylive_customer_model');
}
protected function get_user()
{
$ukey = $this->input_param('ukey');
$activityId = 27;//活动id
$activity = $this->market_sylive_activity_model->get(['activityId' => $activityId]);
if (!$activity) {
//throw new Hd_exception('活动不存在', API_CODE_FAIL);
}
if (!$ukey) {
throw new Hd_exception('ukey不存在', API_CODE_FAIL);
}
$customer = $this->market_sylive_customer_model->get(['ukey' => $ukey]);
if(!$customer){
throw new Hd_exception('用户不存在', API_CODE_FAIL);
}
$data = [
'customerId' => $customer['customerId'],
];
return $data;
}
protected function post_reward()
{
$activityId = 27;//活动id
$ukey = $this->input_param('ukey');
$reward_id = $this->input_param('reward_id');
//$reward_id 对应 winType
$winTypes = array(
'5051' => '1', //电视机
'5052' => '2', //电冰箱
'5053' => '3', //平板
);
$activity = $this->market_sylive_activity_model->get(['activityId' => $activityId]);
if (!$activity) {
throw new Hd_exception('活动不存在', API_CODE_FAIL);
}
if (!$reward_id || !in_array($reward_id, $winTypes)) {
throw new Hd_exception('参数错误', API_CODE_FAIL);
}
if (!$ukey) {
throw new Hd_exception('ukey不存在', API_CODE_FAIL);
}
$customer = $this->market_sylive_customer_model->get(['ukey' => $ukey]);
if(!$customer){
throw new Hd_exception('用户不存在', API_CODE_FAIL);
}
$order = $this->market_sylive_order_model->get(['activityId' => $activityId, 'userId' => $customer['userId'], 'status' => 1,]);
if($order && $order['win'] == 0){
$data = [
'win' => 1,
'winType' => $winTypes[$reward_id],
'winTime' => date('Y-m-d H:i:s'),
];
$rt = $this->market_sylive_order_model->update($data, ['id' => $order['id']]);
}
if ($rt) {
throw new Hd_exception('执行成功', API_CODE_SUCCESS);
}
throw new Hd_exception('目标对象不存在', API_CODE_FAIL);
}
protected function post_car()
{
$activityId = 27;//活动id
$ukey = $this->input_param('ukey');
$car = $this->input_param('car');
$activity = $this->market_sylive_activity_model->get(['activityId' => $activityId]);
if (!$activity) {
throw new Hd_exception('活动不存在', API_CODE_FAIL);
}
if (!$car) {
throw new Hd_exception('参数错误', API_CODE_FAIL);
}
if (!$ukey) {
throw new Hd_exception('ukey不存在', API_CODE_FAIL);
}
$customer = $this->market_sylive_customer_model->get(['ukey' => $ukey]);
if(!$customer){
throw new Hd_exception('用户不存在', API_CODE_FAIL);
}else{
$data = ['visitTagId' => $car,];
$rt = $this->market_sylive_customer_model->update($data, ['customerId' => $customer['customerId']]);
}
if ($rt) {
throw new Hd_exception('执行成功', API_CODE_SUCCESS);
}
throw new Hd_exception('目标对象不存在', API_CODE_FAIL);
}
}