提交其他文件
This commit is contained in:
182
app/adminapi/logic/StoreUserAccountLogLogic.php
Normal file
182
app/adminapi/logic/StoreUserAccountLogLogic.php
Normal file
@ -0,0 +1,182 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\logic;
|
||||
|
||||
|
||||
use app\common\model\StoreUserAccountLog;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\teastore\TeaStore;
|
||||
use app\common\model\teastore\TeaStoreRoom;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* StoreUserAccountLog逻辑
|
||||
* Class StoreUserAccountLogLogic
|
||||
* @package app\adminapi\logic
|
||||
*/
|
||||
class StoreUserAccountLogLogic extends BaseLogic
|
||||
{
|
||||
public static function lists($data){
|
||||
// 如果 $data 是 Json 响应对象,先获取其数据
|
||||
if ($data instanceof \think\response\Json) {
|
||||
$data = $data->getData();
|
||||
}
|
||||
foreach($data['data']['lists'] as $key=>$value){
|
||||
$data['data']['lists'][$key]['store_name'] = TeaStore::where("id",$value['store_id'])->value("name");
|
||||
$data['data']['lists'][$key]['room_name'] = TeaStoreRoom::where("id",$value['room_id'])->value("title");
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2026/02/02 02:00
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
StoreUserAccountLog::create([
|
||||
'sn' => $params['sn'],
|
||||
'change_type' => $params['change_type'],
|
||||
'action' => $params['action'],
|
||||
'amount' => $params['amount'],
|
||||
'before_amount' => $params['before_amount'],
|
||||
'after_amount' => $params['after_amount'],
|
||||
'source_sn' => $params['source_sn'],
|
||||
'sub_sn' => $params['sub_sn'],
|
||||
'store_id' => $params['store_id'],
|
||||
'room_id' => $params['room_id'],
|
||||
'remark' => $params['remark'],
|
||||
'create_time' => strtotime($params['create_time'])
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2026/02/02 02:00
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
StoreUserAccountLog::where('id', $params['id'])->update([
|
||||
'sn' => $params['sn'],
|
||||
'change_type' => $params['change_type'],
|
||||
'action' => $params['action'],
|
||||
'amount' => $params['amount'],
|
||||
'before_amount' => $params['before_amount'],
|
||||
'after_amount' => $params['after_amount'],
|
||||
'source_sn' => $params['source_sn'],
|
||||
'sub_sn' => $params['sub_sn'],
|
||||
'store_id' => $params['store_id'],
|
||||
'room_id' => $params['room_id'],
|
||||
'remark' => $params['remark'],
|
||||
'create_time' => strtotime($params['create_time'])
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2026/02/02 02:00
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return StoreUserAccountLog::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2026/02/02 02:00
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return StoreUserAccountLog::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
// 总收入
|
||||
public static function allTotal($params){
|
||||
$time = "";
|
||||
if(isset($params['start'])&&isset($params['end'])){
|
||||
$start = strtotime($params['start']);
|
||||
$end = strtotime($params['end']);
|
||||
$time = "create_time between '".$start."' and '".$end."'";
|
||||
}
|
||||
$change_type = "";
|
||||
if(isset($params['c_type'])){
|
||||
if($params['c_type']!=""&&$params['c_type']!=null){
|
||||
$change_type = "change_type = ".$params['c_type']."";
|
||||
}
|
||||
}
|
||||
$action = "";
|
||||
if(isset($params['action'])){
|
||||
if($params['action']!=""&&$params['action']!=null){
|
||||
$action = "action = ".$params['action']."";
|
||||
}
|
||||
}else{
|
||||
$action = "action = 1";
|
||||
}
|
||||
$store_id= "";
|
||||
if(isset($params['store_id'])){
|
||||
if($params['store_id']!=""&&$params['store_id']!=null){
|
||||
$store_id = "store_id = ".$params['store_id']."";
|
||||
}
|
||||
}
|
||||
$room_id= "";
|
||||
if(isset($params['room_id'])){
|
||||
if($params['room_id']!=""&&$params['room_id']!=null){
|
||||
$room_id = "room_id = ".$params['room_id']."";
|
||||
}
|
||||
}
|
||||
$amount = StoreUserAccountLog::where($time)
|
||||
->where($change_type)
|
||||
->where($action)
|
||||
->where($store_id)
|
||||
->where($room_id)
|
||||
->sum("amount");
|
||||
return $amount;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user