Commit 29fe079f authored by hujun's avatar hujun

key

parent a509916e
<?php
namespace app\api\service;
use app\api\untils\CouponNoEncodingUntils;
use app\extra\RedisExt;
use app\model\CActivity;
use app\model\CCoupon;
......@@ -79,11 +80,13 @@ class CouponService{
$save_data['status'] = 0;
$save_data['create_time'] = date('Y-m-d H:i:s');
$this->m_coupon->startTrans();
$coupon_untils = new CouponNoEncodingUntils();
foreach ($activity_data as $k=>$v) {
$save_data['activity_id'] = $v['id'];
$save_data['rule_no'] = mt_rand(100,100000);
$insert_status = $this->m_coupon->insertData($save_data);
if ($insert_status) {
$insert_id = $this->m_coupon->insertData($save_data);
if ($insert_id) {
$rule_no = $coupon_untils->encryptionCouponNo($insert_id);
$this->m_coupon->updateData(['rule_no'=>$rule_no], ['id'=>$insert_id]);
$this->m_activity->plusGetNumber($v['id']); //增加用户领取数量
}
}
......@@ -100,29 +103,23 @@ class CouponService{
/**
* 查询奖励动作
*
* @param int $return_action @奖励动作 0首次登陆 1邀请登陆 2邀请成交
* @param $return_action @奖励动作 0首次登陆 1邀请登陆 2邀请成交
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectActivity(int $return_action) {
public function selectActivity($return_action) {
$field = 'id,return_type,money,activity_start_time,activity_end_time,use_period,total,available,total';
$field .= ',available,get_number';
//奖励动作 0首次登陆 1邀请登陆 2邀请成交
switch ($return_action) {
case 1 :
$return_action = 1;
break;
case 2 :
$return_action = 2;
break;
default :
$return_action = 0;
}
$where['total'] = ['>', 0];
if (is_array($return_action)) {
$where['return_action'] = ['in', $return_action];
} else {
$where['return_action'] = $return_action;
}
$where['status'] = 0; //0正常 1手动停止 2数量为空 3时间过期 4删除 5未开始
$where['activity_start_time'] = ['<>', '0000-00-00 00:00:00'];
$where['activity_end_time'] = ['<>', '0000-00-00 00:00:00'];
......
......@@ -15,12 +15,12 @@ class CouponNoEncodingUntils{
}
public function encryptionCouponNo($couponNo){
$couponNo = $this->reverse($couponNo . "1");
$couponNo = $this->reverse($couponNo );
return $couponNo ^ self::OR_NOT_VALUE;
}
public function decryptionCouponNo($couponNo){
$couponNo = $couponNo ^ self::OR_NOT_VALUE;
return substr($couponNo,-1);
return $this->reverse($couponNo);
}
}
\ No newline at end of file
......@@ -94,7 +94,7 @@ class CCoupon extends BaseModel
if (is_array($data[0])) {
$result = $this->db_->insertAll($data);
} else {
$result = $this->db_->insert($data);
$result = $this->db_->insertGetId($data);
}
return $result;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment