AiccV6Logic.php
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace App\Http\Logic\Aside\Aicc;
use App\Enums\Common\Code;
use App\Http\Logic\Logic;
use App\Models\AICC\V6Aicc;
use Illuminate\Support\Facades\DB;
class AiccV6Logic extends Logic
{
public function saveData()
{
$v6_project_id = (int)request()->post('project_id', 0);
if (empty($v6_project_id)) {
$this->fail('请选择项目!', Code::USER_PARAMS_ERROE);
}
$status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
$aicc_user_id = (int)request()->post('aicc_user_id', 0);
if (empty($aicc_user_id) && $status) {
$this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE);
}
$aicc_project_id = (int)request()->post('aicc_project_id', 0);
if (empty($aicc_project_id) && $status) {
$this->fail('请选择要绑定的AICC项目!', Code::USER_PARAMS_ERROE);
}
$aicc_nickname = request()->post('aicc_nickname', '');
$aicc_user_name = request()->post('aicc_user_name', '');
$aicc_image = request()->post('aicc_image', '');
$data = compact('v6_project_id', 'aicc_project_id', 'aicc_nickname', 'aicc_user_id', 'aicc_user_name', 'aicc_image');
$aicc = new V6Aicc();
DB::beginTransaction();
try {
$status = $aicc->saveData($data);
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
$e->getMessage();
errorLog('V6与AICC关联失败', $aicc, $e);
$this->fail('请检查操作是否正确!', Code::SERVER_MYSQL_ERROR);
}
return $this->success($status);
}
/**
* @return array
*/
public function V6AiccLists()
{
$page = (int)request()->route('page', 1);
$status = 1; # 1 - 正常, 0 - 禁用
$perPage = (int)request()->route('perPage', 15); # 分页页数
$lists = V6Aicc::query()->where('status', $status)
->whereNotNull('aicc_project_id')
->whereNotNull('aicc_user_id')
->paginate($perPage, ['v6_project_id', 'aicc_project_id', 'aicc_user_id'], 'page', $page);
$items = $lists->Items();
$totalPage = $lists->lastPage();
$total = $lists->total();
$currentPage = $lists->currentPage();
return compact('total', 'items', 'totalPage', 'currentPage');
}
}