84 lines
2.9 KiB
PHP
84 lines
2.9 KiB
PHP
<?php
|
|
/** ZJMall商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2022-2032 四川正今科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.zjphp.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道官方颁发授权证书,无纸质授权凭证书视为侵权行为。
|
|
* =========================================================
|
|
*/
|
|
|
|
namespace app\model\newModel\member;
|
|
|
|
use app\model\NewBaseModel;
|
|
use app\model\newModel\Config;
|
|
use app\model\newModel\goods\Goods;
|
|
use app\model\order\OrderCreate as OrderCreateModel;
|
|
use think\facade\Db;
|
|
|
|
class MemberLevelPrize extends NewBaseModel{
|
|
|
|
protected $pk = 'id'; // 默认主键id
|
|
protected $name = 'member_level_prize';
|
|
protected $autoWriteTimestamp = false; // 开启自动时间戳
|
|
protected $deleteTime = false; // 软删除字段
|
|
|
|
|
|
/**
|
|
* Common: 存储领取记录(领取前)
|
|
* Author: wu-hui
|
|
* Time: 2022/12/14 14:53
|
|
* @param $memberId
|
|
* @param $cardIds
|
|
* @param $popularizeNum
|
|
*/
|
|
public function addInfo($memberId,$cardIds,$popularizeNum){
|
|
$data = [
|
|
'member_id' => $memberId,
|
|
'site_id' => $this->site_id,
|
|
'cart_id' => implode(',',$cardIds),
|
|
'order_id' => 0,
|
|
'is_get' => 0,
|
|
'popularize_num' => $popularizeNum,
|
|
'create_time' => time()
|
|
];
|
|
$this->insert($data);
|
|
}
|
|
/**
|
|
* Common: 处理领奖名额信息
|
|
* Author: wu-hui
|
|
* Time: 2022/12/14 15:28
|
|
* @param $out_trade_no
|
|
* @param $cardIdStr
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function handleInfo($out_trade_no,$cardIdStr){
|
|
// 获取信息
|
|
$orderInfo = Db::name('order')
|
|
->field('order_id,member_id')
|
|
->where('out_trade_no',$out_trade_no)
|
|
->find();
|
|
$popularizeNum = $this->where('cart_id',$cardIdStr)->value('popularize_num');
|
|
// 处理名额信息
|
|
$ids = (new MemberLevelPopularize())->availableQuotaIds($orderInfo['member_id'],$popularizeNum);
|
|
(new MemberLevelPopularize())->whereIn('id',$ids)->update(['is_use' => 1]);
|
|
$this->where('cart_id',$cardIdStr)->update(['is_get'=>1]);
|
|
}
|
|
/**
|
|
* Common: 获取领奖次数
|
|
* Author: wu-hui
|
|
* Time: 2022/12/14 20:46
|
|
* @param $memberId
|
|
* @return int
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function isGetTotal($memberId){
|
|
return (int)$this->where('member_id',$memberId)->where('is_get',1)->count();
|
|
}
|
|
|
|
|
|
} |