WokerTask/app/adminapi/logic/informationg/UserInformationgLogic.php

167 lines
5.6 KiB
PHP
Raw Permalink Normal View History

2023-12-27 14:06:33 +08:00
<?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\informationg;
use app\common\model\informationg\UserInformationg;
use app\common\logic\BaseLogic;
use app\common\model\informationg\UserInformationgDemand;
use think\facade\Db;
/**
* UserInformationg逻辑
* Class UserInformationgLogic
* @package app\adminapi\logic\informationg
*/
class UserInformationgLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/01 15:00
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
UserInformationg::create([
'create_user_id' => $params['create_user_id'],
'user_id' => $params['user_id'],
'area_id' => $params['area_id'],
'street_id' => $params['street_id'],
'village_id' => $params['village_id'],
'brigade_id' => $params['brigade_id'],
'address' => $params['address'],
'name' => $params['name'],
'phone' => $params['phone'],
'sex' => $params['sex'],
'age' => $params['age'],
'wechat' => $params['wechat'],
'family' => $params['family'],
'child' => $params['child'],
'child_arr' => $params['child_arr'],
'highway' => $params['highway'],
'smart_phone' => $params['smart_phone'],
'status' => $params['status']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/01 15:00
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
UserInformationg::where('id', $params['id'])->update([
'create_user_id' => $params['create_user_id'],
'user_id' => $params['user_id'],
'area_id' => $params['area_id'],
'street_id' => $params['street_id'],
'village_id' => $params['village_id'],
'brigade_id' => $params['brigade_id'],
'address' => $params['address'],
'name' => $params['name'],
'phone' => $params['phone'],
'sex' => $params['sex'],
'age' => $params['age'],
'wechat' => $params['wechat'],
'family' => $params['family'],
'child' => $params['child'],
'child_arr' => $params['child_arr'],
'highway' => $params['highway'],
'smart_phone' => $params['smart_phone'],
'status' => $params['status']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/01 15:00
*/
public static function delete(array $params): bool
{
return UserInformationg::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/08/01 15:00
*/
public static function detail($params): array
{
$item = UserInformationg::where('id', $params['id'])->field('*,area_id area_name,street_id street_name,village_id village_name,brigade_id brigade_name')->find();
$item['family'] = json_decode($item['family'], true);
$item['child_arr'] = json_decode($item['child_arr'], true);
$data = UserInformationgDemand::where('information_id', $params['id'])->order('id', 'desc')->select();
$item['datas'] = [];
$datas = [];
if ($data) {
foreach ($data as $k => $v) {
$a = $v['data']; // json_decode($v['data'], true);
$arr = [
'id' => $v['id'],
'category_id' => $v['category_id'],
'category_child' => $v['category_child'],
'create_time' => $v['create_time'],
'update_time' => $v['update_time'],
'datas' => $a,
'data_field' => json_decode($v['data_field']),
'ai_question' => $v['ai_question'],
'ai_aianalyse' => $v['ai_aianalyse'],
];
if ($a) {
array_push($datas, $arr);
}
}
$item['datas'] = $datas;
}
return $item->toArray();
}
}