116 lines
3.4 KiB
PHP
116 lines
3.4 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);
|
|
self::write_log($write, $total_vip, 0);
|
|
User::where('id', $order->uid)->inc('integral', $total_vip)->update();
|
|
} else {
|
|
$write = self::write($order, $total_vip, 0, 0);
|
|
self::write_log($write, $total_vip, 0);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 来自订单
|
|
*/
|
|
public static function OrderWrite($order)
|
|
{
|
|
$total_vip = bcmul($order['pay_price'], 0.1, 2);
|
|
|
|
//非收银台订单冻结里礼品卷
|
|
if ($order['source'] == 0) {
|
|
$write = self::write($order, $total_vip, 1, 0);
|
|
} else {
|
|
$write = self::write($order, $total_vip, 1, 1);
|
|
self::write_log($write, $total_vip, 1);
|
|
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);
|
|
|
|
}
|
|
}
|
|
/**
|
|
* 储存商品积分结算
|
|
*/
|
|
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);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public static function write($order, $total_vip, $order_type = 0, $status = 0, $title = 4, $pm = 1)
|
|
{
|
|
//礼品券得
|
|
$sing = [
|
|
'uid' => $order['uid'],
|
|
'order_id' => $order['order_id'],
|
|
'title' => $title,
|
|
'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);
|
|
}
|
|
public static function write_log($write, $total_vip, $order_type = 0, $title = 4, $pm = 1)
|
|
{
|
|
//礼品券日志记录
|
|
$sing = [
|
|
'uid' => $write['uid'],
|
|
'sid' => $write['id'],
|
|
'order_id' => $write['order_id'],
|
|
'title' => $title,
|
|
'financial_pm' => $pm,
|
|
'order_type' => $order_type,
|
|
'status' => 1,
|
|
'number' => $total_vip,
|
|
];
|
|
UserSignLog::create($sing);
|
|
}
|
|
|
|
}
|