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.
105 lines
3.6 KiB
105 lines
3.6 KiB
<?php
|
|
|
|
namespace app\model;
|
|
|
|
use think\Model;
|
|
|
|
class ConsumptionRecords extends Model
|
|
{
|
|
/**
|
|
* 创建消费记录
|
|
* @param $user_id // 用户id
|
|
* @param $z_g_id // 专区商品id
|
|
* @param $price // 原价
|
|
* @param $actual_price // 实际支付金额
|
|
* @param $residue_amount // 剩余余额
|
|
* @param $data // 剩余余额
|
|
*/
|
|
public static function createRecords($user_id,$z_g_id,$price,$actual_price,$residue_amount,$data)
|
|
{
|
|
$records = new ConsumptionRecords();
|
|
|
|
$records->user_id = $user_id;
|
|
$records->zone_goods_id = $z_g_id;
|
|
$records->price = $price;
|
|
$records->text_data = serialize($data);
|
|
$records->actual_price = $actual_price;
|
|
$records->residue_amount = $residue_amount;
|
|
$records->create_time = date("Y-m-d H:i:s",time());
|
|
$records->save();
|
|
return $records->id;
|
|
}
|
|
|
|
/**
|
|
* 保存消费记录
|
|
* @param $user_id // 用户id
|
|
* @param $z_g_id // 专区商品id
|
|
* @param $price // 原价
|
|
* @param $actual_price // 实际支付金额
|
|
* @param $residue_amount // 剩余余额
|
|
* @param $data // 剩余余额
|
|
* @param array $otherData // 其他数据
|
|
* @return mixed
|
|
*/
|
|
public static function saveRecords($user_id,$z_g_id,$price,$actual_price,$residue_amount,$data,array $otherData = [])
|
|
{
|
|
$records = new ConsumptionRecords();
|
|
|
|
$records->user_id = $user_id;
|
|
$records->zone_goods_id = $z_g_id;
|
|
$records->price = $price;
|
|
$records->text_data = serialize($data);
|
|
$records->actual_price = $actual_price;
|
|
$records->residue_amount = $residue_amount;
|
|
$records->create_time = date("Y-m-d H:i:s",time());
|
|
$records->status = 1;
|
|
if (isset($otherData['prizes_data']) && !empty($otherData['prizes_data'])) {
|
|
$records->prizes_data = serialize($otherData['prizes_data']);
|
|
}
|
|
if (isset($otherData['prizes_icon_data']) && !empty($otherData['prizes_icon_data'])) {
|
|
$records->prizes_icon_data = serialize($otherData['prizes_icon_data']);
|
|
}
|
|
$records->complete_time = date("Y-m-d H:i:s",time());
|
|
$records->awards_status = $otherData['awards_status'] ?? 0;
|
|
$records->actual_type = $otherData['actual_type'] ?? 1;
|
|
|
|
$records->save();
|
|
return $records->id;
|
|
}
|
|
|
|
/**
|
|
* 完成订单
|
|
* @param $c_r_id
|
|
* @param $awards_amount // 中奖金额
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public static function endOrder($c_r_id,$awards_amount)
|
|
{
|
|
|
|
$zoneOrder = ConsumptionRecords::find($c_r_id);
|
|
$zoneOrder->status = 1;
|
|
$zoneOrder->complete_time = date("Y-m-d H:i:s",time());
|
|
if ($awards_amount > 0) {
|
|
$zoneOrder->awards_status = 1;
|
|
}
|
|
$zoneOrder->save();
|
|
}
|
|
|
|
/**
|
|
* 保存是否中奖字段
|
|
* @param $data
|
|
* @param $id
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public static function awardsData($data,$id)
|
|
{
|
|
$ConsumptionRecords = ConsumptionRecords::find($id);
|
|
$ConsumptionRecords->text_data = serialize($data);
|
|
$ConsumptionRecords->save();
|
|
}
|
|
|
|
}
|