57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace app\api\model;
|
|
|
|
|
|
|
|
use think\Db;
|
|
use think\Exception;
|
|
use think\Log;
|
|
|
|
/**
|
|
* 购卡记录
|
|
*/
|
|
class JunkaStore extends \app\common\model\JunkaStore
|
|
{
|
|
|
|
public static function moneychange($store, $money, $type, $notes, $order_no)
|
|
{
|
|
Db::startTrans();
|
|
$store = JunkaStore::lock(true)->where(['id' => $store->id])->find();
|
|
$before_money = $store->money;
|
|
try {
|
|
// +
|
|
if($type == 1) {
|
|
$after_money = $store->money + $money;
|
|
}else {
|
|
// -
|
|
$after_money = $store->money - $money;
|
|
}
|
|
|
|
$store->money = $after_money;
|
|
$store->save();
|
|
if($store) {
|
|
JunkaStoreMoneyLog::create([
|
|
'store_id' => $store->id,
|
|
'before_money' => $before_money,
|
|
'after_money' => $after_money,
|
|
'money' => $money,
|
|
'type' => $type,
|
|
'admin_id' => $store->admin_id,
|
|
'notes' => $notes,
|
|
'data_id' => $order_no,
|
|
]);
|
|
Db::commit();
|
|
}else {
|
|
Db::rollback();
|
|
Log::write('更新余额时商户未找到-'.$store);
|
|
}
|
|
}catch (Exception $e) {
|
|
Db::rollback();
|
|
Log::write($e->getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
}
|