multi-store/app/common/logic/UserSignLogic.php

177 lines
5.6 KiB
PHP

<?php
namespace app\common\logic;
use app\common\logic\BaseLogic;
use app\common\model\user\User;
use app\common\model\user_sign\UserSign;
use app\common\model\user_sign_log\UserSignLog;
/**
* 会员积分逻辑
* Class UserSignLogic
*/
class UserSignLogic extends BaseLogic
{
/**
* 来自充值
*/
public static function dealRechargeFrozen($user, $order, $user_ship = 0)
{
$total_vip = bcmul($order['price'], 0.1, 2);
$count = UserSign::where('uid', $order->uid)->count();
if ($count == 0 && in_array($user_ship, [1, 2, 3, 5, 6, 7, 8])) {
//首充
$write = self::write($order, $total_vip, 0, 1, 9);
self::write_log($write, $total_vip, 0, 7);
self::write_log($write, $total_vip, 0, 9);
User::where('id', $order->uid)->inc('integral', $total_vip)->update();
}
return true;
}
/**
* 来自订单
*/
public static function OrderWrite($order)
{
$total_vip = bcmul($order['pay_price'], 0.1, 2);
if ($order['source'] == 0) {
//冻结礼品券
if ($order['pay_price'] >= 500) {
$write = self::write($order, $total_vip, 1, 0, 4);
self::write_log($write, $total_vip, 1, 1, 1);
}
} else {
//不冻结礼品券
if ($order['pay_price'] >= 500) {
$write = self::write($order, $total_vip, 1, 1, 4);
self::write_log($write, $total_vip, 1, 1);
self::write_log($write, $total_vip, 1, 4);
User::where('id', $order->uid)->inc('integral', $total_vip)->update();
}
}
}
/**
* 核销
*/
public static function WriteOff($order)
{
$find = UserSign::where(['order_id' => $order['order_id'], 'status' => 0, 'financial_pm' => 1, 'order_type' => 1])->find();
if ($find) {
$find->status = 1;
$find->save();
User::where('id', $order->uid)->inc('integral', $find['number'])->update();
self::write_log($find, $find['number'], 1, 2);
self::write_log($find, $find['number'], 1, 4);
}
}
/**
* 储存商品积分结算
*/
public static function storage($order)
{
$find = UserSign::where(['order_id' => $order['order_id'], 'status' => 0, 'financial_pm' => 1, 'order_type' => 1])->find();
if ($find) {
// if($or)
// $find->status=1;
// $find->save();
// User::where('id', $order->uid)->inc('integral', $find['number'])->update();
// self::write_log($find,$find['number'], 1);
}
}
/**
* @param type 1:购买商品冻结
* @param type 2:核销商品解冻
* @param type 3:退款扣除冻结
* @param type 4:核销金额获得
* @param type 5:兑换商品扣除
* @param type 6:退款扣除礼品
* @param type 7:充值冻结
* @param type 8:收银台支付增加
* @param type 9:首充获得
*/
public static function write($order, $total_vip, $order_type = 0, $status = 0, $type = 4, $pm = 1)
{
//礼品券得
$sing = [
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'type' => $type,
'financial_pm' => $pm,
'store_id' => $order['store_id'],
'status' => $status,
'number' => $total_vip,
'back_num' => $total_vip,
'order_type' => $order_type,
];
return UserSign::create($sing);
}
/**
* @param type 1:购买商品冻结
* @param type 2:核销商品解冻
* @param type 3:退款扣除冻结
* @param type 4:核销金额获得
* @param type 5:兑换商品扣除
* @param type 6:退款扣除礼品
* @param type 7:充值冻结
* @param type 8:收银台支付增加
* @param type 9:首充获得
*/
public static function write_log($write, $total_vip, $order_type = 0, $type = 4, $pm = 1)
{
//礼品券日志记录
$sing = [
'uid' => $write['uid'],
'sid' => $write['id'],
'order_id' => $write['order_id'],
'type' => $type,
'financial_pm' => $pm,
'order_type' => $order_type,
'status' => 1,
'number' => $total_vip,
];
UserSignLog::create($sing);
}
//礼品券相关对应文本
public static function getTitle($type, $amount,$number)
{
switch ($type) {
/**冻结券**/
//收入
case 1:
return "购买商品{$amount}元获得{$number}元冻结券";
case 7:
return "充值{$amount}元获得{$number}元冻结券";
//支出
case 2:
return "核销商品{$amount}元解冻{$number}元礼品券";
case 3:
return "退款{$amount}元扣除{$number}元冻结券";
/**礼品券**/
//收入
case 4:
return "核销金额{$amount}元获得{$number}元礼品券";
//支出
case 5:
return "兑换{$amount}元商品扣除{$number}元礼品券";
case 6:
return "退款{$amount}元扣除{$number}元礼品券";
case 8:
return "收银台支付{$amount}元增加{$number}元礼品券";
case 9:
return "充值{$amount}元解冻{$number}元礼品券";
default:
return "订单支付{$amount}";
}
}
}