You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
282 lines
12 KiB
282 lines
12 KiB
<?php
|
|
|
|
defined('IN_IA') or exit('Access Denied');
|
|
class RightsModuleUniapp extends Uniapp
|
|
{
|
|
|
|
protected $typeArray = [
|
|
1 => ['plugin' => 'rights', 'payfor' => 'rights'],
|
|
2 => ['plugin' => 'rights', 'payfor' => 'rightsBag']
|
|
];
|
|
|
|
/**
|
|
* 我的权益首页展示数据
|
|
* @return void
|
|
*/
|
|
public function getRightsList() {
|
|
global $_W, $_GPC;
|
|
|
|
$rights = Rights::getRightsList();
|
|
$contentList = [];
|
|
foreach ($rights as $rightsKey => $rightsValue) {
|
|
$contentList[] = ($rightsKey + 1) . '.' . $rightsValue['content'];
|
|
}
|
|
|
|
$rightsBag = pdo_get(PDO_NAME . 'rights_bag',['id' => 2],['id','title','price']);
|
|
|
|
$this->renderSuccess('数据获取成功',[
|
|
'table_list' => Rights::getRightsMergeList(),
|
|
'content_list' => $contentList,
|
|
'member_rights_list' => Rights::getMemberRightsUsageInfo($_W['mid']),
|
|
'rights_bag_data' => $rightsBag?:[]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 权益详情页面展示数据
|
|
* @return void
|
|
*/
|
|
public function getRightsTypeInfo() {
|
|
global $_W, $_GPC;
|
|
|
|
$rightsid = $_GPC['rights_id'];
|
|
$mid = $_W['mid'];
|
|
if (empty($rightsid) || !is_numeric($rightsid)) $this->renderError('缺少权益id');
|
|
|
|
$rights = pdo_get(PDO_NAME . 'rights',['id' => $rightsid],['rights_type','calculate_method','price']);
|
|
if (!$rights) $this->renderError('权益信息不存在');
|
|
|
|
$rights_type = $rights['rights_type'];
|
|
|
|
$data = [
|
|
'rights_type' => $rights_type, // 权益类型
|
|
'remaining_amount' => 0, // 剩余数量
|
|
'price' => $rights['price'] // 单价
|
|
];
|
|
|
|
$memberRights = pdo_get(PDO_NAME . 'member_rights',['rightsid' => $rightsid,'mid' => $mid,'status' => 1]);
|
|
if ($memberRights) {
|
|
$use_amount = $memberRights['use_amount'];
|
|
// 现有数量
|
|
$data['remaining_amount'] = Rights::getUseAmount($rightsid,$memberRights['id'],$use_amount,$memberRights['total_amount']);
|
|
}
|
|
|
|
// 获取权益提交数据信息
|
|
switch ($rightsid) {
|
|
case 1:
|
|
|
|
break;
|
|
case 2:
|
|
$data['amount_unit'] = Rights::$unit[4]; // 数量单位
|
|
$data['num_data'] = Rights::$dayData; // 数量选择
|
|
$data['filter_data'] = [
|
|
'recruit' => Rights::getStoreRecruitInfo($mid) // 商户招聘职位信息
|
|
];
|
|
break;
|
|
case 3:
|
|
$data['amount_unit'] = Rights::$unit[4];
|
|
$data['num_data'] = Rights::$monthData;
|
|
break;
|
|
case 4:
|
|
$data['amount_unit'] = Rights::$unit[3];
|
|
$data['num_data'] = Rights::$numData;
|
|
break;
|
|
case 5:
|
|
$data['amount_unit'] = Rights::$unit[2];
|
|
$data['num_data'] = Rights::$copyData;
|
|
$data['filter_data'] = [
|
|
'recruit' => Rights::getStoreRecruitInfo($mid),
|
|
'graduated_school' => Rights::$graduatedSchool, // 毕业院校
|
|
'experience' => Rights::$experience // 经历
|
|
];
|
|
break;
|
|
}
|
|
|
|
$this->renderSuccess('数据返回成功',$data);
|
|
}
|
|
|
|
/**
|
|
* 创建权益支付接口
|
|
* @return void
|
|
*/
|
|
public function createRightsPay() {
|
|
global $_W, $_GPC;
|
|
|
|
$rightsid = $_GPC['rights_id']; // 权益ID
|
|
$type = $_GPC['type']; // 权益支付类型
|
|
$num = $_GPC['num']; // 购买数量
|
|
$contacts = $_GPC['contacts']; // 联系人名称
|
|
$contact_phone = $_GPC['contact_phone'] ?: ''; // 联系电话
|
|
|
|
if (empty($rightsid) || !is_numeric($rightsid)) $this->renderError('缺少权益id');
|
|
if (empty($type) || !in_array($type,array_keys($this->typeArray))) $this->renderError('权益支付类型数据有误');
|
|
if (!empty($contact_phone) && $contact_phone != 'undefined') {
|
|
if (!preg_match("/^1[3-9]\d{9}$/",$contact_phone)) $this->renderError('请输入正确的手机号');
|
|
}
|
|
|
|
if ($type == 2) {
|
|
$num = 1;
|
|
} else {
|
|
if (empty($num)) $this->renderError('请输入购买数量');
|
|
if (!preg_match("/^\d+$/",$num)) $this->renderError('购买数量必须是数字整数');
|
|
if ($num <= 0 || $num > 500) $this->renderError('购买数量最低不能小于0,最高不能大于500');
|
|
}
|
|
if (!empty($contacts)) {
|
|
$contactsRes = Filter::init($contacts,$_W['source'],1);
|
|
if ($contactsRes['errno'] == 0) $this->renderError('联系人名称'.$contactsRes['message']);
|
|
}
|
|
|
|
$typeData = $this->typeArray[$type];
|
|
|
|
// 获取权益价格
|
|
$oprice = 0;
|
|
if ($typeData['payfor'] == 'rights') {
|
|
$rights = pdo_get(PDO_NAME . 'rights',['id' => $rightsid],['price']);
|
|
$oprice = $rights['price'];
|
|
} elseif ($typeData['payfor'] == 'rightsBag') {
|
|
$rightsBag = pdo_get(PDO_NAME . 'rights_bag',['id' => $rightsid],['price']);
|
|
$oprice = $rightsBag['price'];
|
|
}
|
|
$price = bcmul($oprice,$num,2);
|
|
|
|
//生成订单
|
|
$orderdata = [
|
|
'uniacid' => $_W['uniacid'],
|
|
'mid' => $_W['mid'],
|
|
'aid' => $_W['aid'],
|
|
'fkid' => $rightsid,
|
|
'createtime' => time(),
|
|
'orderno' => createUniontid(),
|
|
'oprice' => $oprice,
|
|
'price' => $price,
|
|
'num' => $num,
|
|
'plugin' => $typeData['plugin'],
|
|
'payfor' => $typeData['payfor'],
|
|
'goodsprice' => $price,
|
|
'fightstatus' => 1,
|
|
'name' => $contacts,
|
|
'mobile' => $contact_phone
|
|
];
|
|
pdo_insert(PDO_NAME.'order',$orderdata);
|
|
$orderid = pdo_insertid();
|
|
if (empty($orderid)) {
|
|
$this->renderError('生成订单失败,请刷新重试');
|
|
|
|
} else {
|
|
$this->renderSuccess('发布成功',['status' => 1,'type' => $typeData['plugin'],'orderid' => $orderid]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 用户使用权益
|
|
* @return void
|
|
*/
|
|
public function memberUseRights() {
|
|
global $_W, $_GPC;
|
|
|
|
$mid = $_W['mid'];
|
|
$rightsid = $_GPC['rights_id']; // 权益id
|
|
$position = json_decode(html_entity_decode($_GPC['position']),true); // 使用权益 关联信息
|
|
if (empty($rightsid) || !is_numeric($rightsid)) $this->renderError('缺少权益id');
|
|
if (empty($position)) $this->renderError('position参数不能为空');
|
|
if (!is_array($position)) $this->renderError('position参数数据有误');
|
|
|
|
$sumNum = 0; // 总使用数量
|
|
// 验证请求数据
|
|
foreach($position as $value) {
|
|
|
|
$num = $value['num']; // 使用数量
|
|
$recruit_id = $value['recruit_id']; // 商户招聘信息ID
|
|
if (empty($num)) $this->renderError('请填写使用数量');
|
|
if ($num <= 0) $this->renderError('使用数量不能小于等于0');
|
|
if (empty($recruit_id) || !is_numeric($recruit_id)) $this->renderError('请选择要置顶的岗位');
|
|
|
|
$sumNum += $num;
|
|
}
|
|
|
|
// 获取用户是否购买权益
|
|
$memberRights = Rights::getMemberRights($mid,$rightsid);
|
|
if (!$memberRights) $this->renderError('您没有该权益,请先购买权益');
|
|
|
|
#$remaining_amount = $memberRights['total_amount'] - $memberRights['use_amount']; // 剩余权益数量
|
|
$remaining_amount = Rights::getUseAmount($rightsid,$memberRights['id'],$memberRights['use_amount'],$memberRights['total_amount']);
|
|
// 判断权益是否使用完
|
|
if ($memberRights['status'] == 0) $this->renderError('该权益的使用已到期,请重新购买使用');
|
|
if ($remaining_amount <= 0) $this->renderError('该权益的使用数量为零,请重新购买使用');
|
|
|
|
if ($sumNum > $remaining_amount) $this->renderError('填写数量不能大于剩余数量');
|
|
|
|
try {
|
|
pdo_begin();
|
|
|
|
switch ($rightsid) {
|
|
case 2:
|
|
// 生成使用信息
|
|
foreach ($position as $value) {
|
|
// 生成子权益使用
|
|
$saveMemberRightsUse = Rights::saveMemberRightsUse($rightsid,$memberRights['id'],$value['num'],$value['recruit_id']);
|
|
if (!$saveMemberRightsUse['status']) throw new Exception($saveMemberRightsUse['msg']);
|
|
|
|
// 判断是否可以置顶 可以及开始置顶
|
|
$isTopRes = Rights::recruitIsTop($value['recruit_id'],$memberRights['id'],$memberRights,$value['num']);
|
|
$num = 1;
|
|
if ($isTopRes == 2) $num = 0;
|
|
if ($isTopRes) Rights::useMemberRights($rightsid,$mid,$value['recruit_id'],'recruit_bout',$num);
|
|
}
|
|
break;
|
|
case 5:
|
|
$graduated_school = $_GPC['graduated_school']; // 毕业院校(待确认)
|
|
$experience = $_GPC['experience']; // 优先选项 - 经历(待确认)
|
|
$data = [];
|
|
if (!empty($graduated_school) && is_numeric($graduated_school)) $data['graduated_school'] = $graduated_school;
|
|
if (!empty($experience) && is_numeric($experience)) $data['experience'] = $experience;
|
|
foreach ($position as $value) {
|
|
$saveMemberRightsUse = Rights::saveMemberRightsUse($rightsid,$memberRights['id'],$value['num'],$value['recruit_id'],'recruit_resume',$data);
|
|
if (!$saveMemberRightsUse['status']) throw new Exception($saveMemberRightsUse['msg']);
|
|
}
|
|
break;
|
|
}
|
|
|
|
// $memberRightsUpdateArr = ['use_amount' => $memberRights['use_amount'] + $sumNum];
|
|
// $memberRightsUpdate = pdo_update(PDO_NAME . 'member_rights',$memberRightsUpdateArr,['id' => $memberRights['id']]);
|
|
// if (!$memberRightsUpdate) throw new Exception('使用失败');
|
|
|
|
} catch (Exception $e) {
|
|
pdo_rollback();
|
|
$this->renderError($e->getMessage());
|
|
}
|
|
|
|
pdo_commit();
|
|
|
|
$this->renderSuccess('使用成功');
|
|
}
|
|
|
|
public function getRightsOrderList()
|
|
{
|
|
global $_W, $_GPC;
|
|
|
|
$page = $_GPC['page'] ? : 1;
|
|
$pageIndex = $_GPC['page_index'] ? : 10;
|
|
|
|
$where = ['uniacid' => $_W['uniacid'], 'aid' => $_W['aid'], 'plugin' => 'rights','mid' => $_W['mid']?:4];
|
|
$field = "id,orderno,status,paytype,payfor,paytime,price,fkid,mid,num";
|
|
$orderData = Util::getNumData($field, PDO_NAME . 'order', $where, 'id desc', $page, $pageIndex, 1);
|
|
|
|
$list = $orderData[0];
|
|
|
|
foreach($list as &$item){
|
|
if ($item['payfor'] == 'rightsBag') {
|
|
|
|
$rightsBag = pdo_get(PDO_NAME . 'rights_bag',['id' => $item['fkid']]);
|
|
$item['storename'] = $rightsBag['title'];
|
|
} else {
|
|
$rights = pdo_get(PDO_NAME . 'rights',['id' => $item['fkid']]);
|
|
$item['storename'] = $rights['rights_type'];
|
|
}
|
|
|
|
Member::getMemberInfo($item,$item['mid']);
|
|
}
|
|
$this->renderSuccess('数据获取成功',$list);
|
|
}
|
|
|
|
}
|