162 行
6.2 KiB
PHP
可执行文件
162 行
6.2 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Common\Model;
|
|
|
|
use Common\Business\CacheHandle;
|
|
|
|
//[1.7.86]
|
|
|
|
/**
|
|
* 充值赠送金额分期到账模型
|
|
* Class InstallAccountModel
|
|
* @package Common\Model
|
|
*/
|
|
class InstallAccountModel extends BaseModel
|
|
{
|
|
protected $tableName = 'vip_install_account';
|
|
const ID = 'id'; //int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
|
|
const MERCHANT_ID = 'merchant_id'; //int(11) DEFAULT '0' COMMENT '商户id',
|
|
const STORE_ID = 'store_id'; //int(11) DEFAULT '0' COMMENT '门店id',
|
|
const ORDER_ID = 'order_id'; //int(11) DEFAULT '0' COMMENT '订单id',
|
|
const VIP_ID = 'vip_id'; //int(11) DEFAULT '0' COMMENT '会员id',
|
|
const AGING_DATE = 'aging_date'; //date COMMENT '待更新金额日期',
|
|
const AGING_MONEY = 'aging_money'; //decimal(11,2) DEFAULT '0.00' COMMENT '待更新金额',
|
|
const IS_UPGRADE = 'is_upgrade'; // tinyint(1) DEFAULT '0' COMMENT '数据更新情况 0:未更新,1:已更新',
|
|
const STATE = 'state'; // tinyint(1) DEFAULT '0' COMMENT '数据是否有效 0:有效,1:无效',
|
|
|
|
/**
|
|
* 分期到账
|
|
* @param int $vip_id 会员id
|
|
* @param date $aging_date 待更新时间
|
|
* @param decimal $aging_money 待更新金额
|
|
* @param int $aging_time 设置->分期到账间隔
|
|
* @param int $aging_repay 设置->分期到账是否开启
|
|
* @param int $aging_cycle 设置->分期到账间隔时间
|
|
* @param int $active_aging_time 活动->分几期到账
|
|
* @param int $active_aging_repay 活动->分期到账是否开启
|
|
*/
|
|
public function waitUpgradeAccount(&$data)
|
|
{
|
|
if (!$data['vip_id'] && !$data['active_aging_repay'] && !$data['aging_repay']) {
|
|
return false;
|
|
}
|
|
for ($i = 0, $total_money = 0; $i < $data['active_aging_time']; $i++) {
|
|
|
|
$time = ($i + 1) * $data['aging_time'];
|
|
if ($data['aging_cycle'] == 0) {
|
|
$aging_date = date("Y-m-d", strtotime("+$time day", strtotime($data['aging_date'])));
|
|
} else {
|
|
$aging_date = date("Y-m-d", strtotime("+$time month", strtotime($data['aging_date'])));
|
|
}
|
|
$aging_money = round($data['aging_money'] / $data['active_aging_time'], 2);
|
|
$total_money += $aging_money;
|
|
if ($i == $data['active_aging_time'] - 1 && $total_money != $data['aging_money']) {
|
|
$aging_money = $aging_money + $data['aging_money'] - $total_money;
|
|
}
|
|
$update_data = array(
|
|
'vip_id' => $data['vip_id'],
|
|
'merchant_id' => $data['merchant_id'],
|
|
'order_id' => $data['order_id'],
|
|
'store_id' => $data['store_id'],
|
|
'aging_money' => $aging_money,
|
|
'is_upgrade' => 0,
|
|
'aging_date' => $aging_date,
|
|
);
|
|
|
|
$this->addOrder($update_data);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 更新数据
|
|
*/
|
|
public function updateData()
|
|
{
|
|
$VipModel = new RetailVipModel();
|
|
$RechargeOrderModel = new RetailRechargeOrderModel();
|
|
$time = date("Y-m-d", time());
|
|
$CacheHandle = new CacheHandle();
|
|
// 获取是否存在缓存,防止重复点击
|
|
$hasSetRedis = $CacheHandle->getSingleCache('install_account_update_' . $time);
|
|
if ($hasSetRedis) {
|
|
return true;
|
|
}
|
|
// 添加redis
|
|
$CacheHandle->addTimeCache('install_account_update_' . $time, 300, 1);
|
|
$map = [
|
|
'ia.aging_date' => array('elt', $time),
|
|
'ia.is_upgrade' => 0,
|
|
'ia.state' => 0,
|
|
'r.status' => 1,
|
|
];
|
|
$data = $this->alias('ia')
|
|
->join('ls_recharge_order as r on ia.order_id=r.id')
|
|
->where($map)
|
|
->field('ia.*')
|
|
->select();
|
|
foreach ($data as $val) {
|
|
$vip_data = $VipModel->getFind(array('id' => $val['vip_id']));
|
|
//更新余额
|
|
$VipModel->toSetInc(['id' => $vip_data['id']], 'balance', $val['aging_money']);
|
|
$RechargeOrderModel->toSetInc(['id' => $val['order_id']], 'all_money', $val['aging_money']);
|
|
//更新表中状态
|
|
$this->updateOrder(array('id' => $val['id']), array('is_upgrade' => 1));
|
|
|
|
$has_arrive = $this->where(array('vip_id' => $val['vip_id'], 'order_id' => $val['order_id'], 'is_upgrade' => 1))->count();
|
|
$un_arrive = $this->where(array('vip_id' => $val['vip_id'], 'order_id' => $val['order_id'], 'is_upgrade' => 0))->count();
|
|
//公众号推送
|
|
$tempSend = array(
|
|
'store_id' => $val['store_id'],
|
|
'type' => 7, //'分期到账',
|
|
'sendData' => array(
|
|
'aging_money' => $val['aging_money'],
|
|
'has_arrive' => $has_arrive,
|
|
'aging_date' => date('Y-m-d H:i:s'),
|
|
'un_arrive' => $un_arrive,
|
|
),
|
|
);
|
|
A('Vip/Mark')->installAccountT($tempSend, $val['vip_id'], $val['merchant_id']);
|
|
$tempSend['type'] = 3;
|
|
A('Api/XcxMark')->sendMark($tempSend); //小程序模板通知
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取分期到账数据
|
|
*/
|
|
public function installAccountData()
|
|
{
|
|
$vip_id = I('post.vip_id');
|
|
$store_id = I('post.store_id');
|
|
$merchant_id = I('post.merchant_id');
|
|
$MerchantModel = new RetailMerchantModel();
|
|
|
|
if (!$vip_id && !$merchant_id && !$store_id) {
|
|
return false;
|
|
}
|
|
|
|
$map = array(
|
|
'vip_id' => $vip_id,
|
|
'store_id' => $store_id,
|
|
'merchant_id' => $merchant_id,
|
|
);
|
|
|
|
$data = $this->getSelect($map);
|
|
|
|
// 获取商户充值设置
|
|
$map1 = array(
|
|
$MerchantModel::ID => $merchant_id,
|
|
$MerchantModel::STATUS => 1
|
|
);
|
|
$field = array($MerchantModel::AGING_REPAY);
|
|
$setting = $MerchantModel->getFind($map1, $field);
|
|
|
|
foreach ($data as $value) {
|
|
$value['aging_repay_name'] = $setting['aging_repay'] == 0 ? '直接到账' : '分期到账';
|
|
$value['upgrade_name'] = $value['is_upgrade'] == 0 ? '未到账' : '已到账';
|
|
}
|
|
|
|
$this->ajaxReturn($data);
|
|
}
|
|
}
|