Commit 29fe079f authored by hujun's avatar hujun

key

parent a509916e
<?php <?php
namespace app\api\service; namespace app\api\service;
use app\api\untils\CouponNoEncodingUntils;
use app\extra\RedisExt; use app\extra\RedisExt;
use app\model\CActivity; use app\model\CActivity;
use app\model\CCoupon; use app\model\CCoupon;
...@@ -79,12 +80,14 @@ class CouponService{ ...@@ -79,12 +80,14 @@ class CouponService{
$save_data['status'] = 0; $save_data['status'] = 0;
$save_data['create_time'] = date('Y-m-d H:i:s'); $save_data['create_time'] = date('Y-m-d H:i:s');
$this->m_coupon->startTrans(); $this->m_coupon->startTrans();
$coupon_untils = new CouponNoEncodingUntils();
foreach ($activity_data as $k=>$v) { foreach ($activity_data as $k=>$v) {
$save_data['activity_id'] = $v['id']; $save_data['activity_id'] = $v['id'];
$save_data['rule_no'] = mt_rand(100,100000); $insert_id = $this->m_coupon->insertData($save_data);
$insert_status = $this->m_coupon->insertData($save_data); if ($insert_id) {
if ($insert_status) { $rule_no = $coupon_untils->encryptionCouponNo($insert_id);
$this->m_activity->plusGetNumber($v['id']); //增加用户领取数量 $this->m_coupon->updateData(['rule_no'=>$rule_no], ['id'=>$insert_id]);
$this->m_activity->plusGetNumber($v['id']); //增加用户领取数量
} }
} }
$this->redis_->del($key); $this->redis_->del($key);
...@@ -100,29 +103,23 @@ class CouponService{ ...@@ -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 * @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @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 = 'id,return_type,money,activity_start_time,activity_end_time,use_period,total,available,total';
$field .= ',available,get_number'; $field .= ',available,get_number';
$where['total'] = ['>', 0];
//奖励动作 0首次登陆 1邀请登陆 2邀请成交 if (is_array($return_action)) {
switch ($return_action) { $where['return_action'] = ['in', $return_action];
case 1 : } else {
$return_action = 1; $where['return_action'] = $return_action;
break;
case 2 :
$return_action = 2;
break;
default :
$return_action = 0;
} }
$where['total'] = ['>', 0];
$where['return_action'] = $return_action;
$where['status'] = 0; //0正常 1手动停止 2数量为空 3时间过期 4删除 5未开始 $where['status'] = 0; //0正常 1手动停止 2数量为空 3时间过期 4删除 5未开始
$where['activity_start_time'] = ['<>', '0000-00-00 00:00:00']; $where['activity_start_time'] = ['<>', '0000-00-00 00:00:00'];
$where['activity_end_time'] = ['<>', '0000-00-00 00:00:00']; $where['activity_end_time'] = ['<>', '0000-00-00 00:00:00'];
......
...@@ -15,12 +15,12 @@ class CouponNoEncodingUntils{ ...@@ -15,12 +15,12 @@ class CouponNoEncodingUntils{
} }
public function encryptionCouponNo($couponNo){ public function encryptionCouponNo($couponNo){
$couponNo = $this->reverse($couponNo . "1"); $couponNo = $this->reverse($couponNo );
return $couponNo ^ self::OR_NOT_VALUE; return $couponNo ^ self::OR_NOT_VALUE;
} }
public function decryptionCouponNo($couponNo){ public function decryptionCouponNo($couponNo){
$couponNo = $couponNo ^ self::OR_NOT_VALUE; $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 ...@@ -94,7 +94,7 @@ class CCoupon extends BaseModel
if (is_array($data[0])) { if (is_array($data[0])) {
$result = $this->db_->insertAll($data); $result = $this->db_->insertAll($data);
} else { } else {
$result = $this->db_->insert($data); $result = $this->db_->insertGetId($data);
} }
return $result; 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