Blame view

app-ht/modules/maintainer/controllers/UserController.php 5.48 KB
d11ff394   xu   app-ht(v0.0.1 bui...
1
2
3
4
<?php

namespace app\ht\modules\maintainer\controllers;

d11ff394   xu   app-ht(v0.0.1 bui...
5
use Yii;
afd2f743   xu   app-ht(v0.0.1 bui...
6
use yii\base\Exception;
d11ff394   xu   app-ht(v0.0.1 bui...
7
8
use yii\data\Pagination;
use app\ht\controllers\BaseController;
afd2f743   xu   app-ht(v0.0.1 bui...
9
10
use common\helpers\ImageManager;
use domain\user\User;
d11ff394   xu   app-ht(v0.0.1 bui...
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
use domain\user\UserRepository;
use stdClass;
use function strtotime;

/**
 * 维修厂管理
 */
class UserController extends BaseController
{

    /**
     * @return string
     */
    public function actionIndex()
    {
        $params = $this->dataList(1);
        /**
         * 渲染模板
         */
        return $this->render('index', $params);
    }

    /**
     * 查询数据列表
     */
    protected function dataList($type = '')
    {
        $request        = Yii::$app->request;
        $createTime     = $request->get('createTime');
        $endTime        = $request->get('endTime');
        $mobile         = $request->get('mobile');
        $name           = $request->get('name');
afd2f743   xu   app-ht(v0.0.1 bui...
43
        $status         = $request->get('status');
d11ff394   xu   app-ht(v0.0.1 bui...
44
45
46
47
48
49

        $gets = [
            'createTime'    => $createTime,
            'endTime'       => $endTime,
            'mobile'        => $mobile,
            'name'          => $name,
afd2f743   xu   app-ht(v0.0.1 bui...
50
            'status'        => $status,
d11ff394   xu   app-ht(v0.0.1 bui...
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
        ];

        $where = ['and'];
        if ($createTime) {
            $createTime = strtotime($createTime);
            $where[] = ['>=', 'user.created_at', $createTime];
        }
        if ($endTime) {
            $endTime = strtotime($endTime) + 86400;
            $where[] = ['<=', 'user.created_at', $endTime];
        }
        if ($mobile) {
            $where[] = ['like', 'user.mobile', $mobile];
        }
        if ($name) {
            $where[] = ['like', 'user.name', $name];
        }
afd2f743   xu   app-ht(v0.0.1 bui...
68
69
70
        if ($status) {
            $where[] = ['=', 'user.status', $status];
        }
d11ff394   xu   app-ht(v0.0.1 bui...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

        if ($type == 0) {
            $pageList = UserRepository::getAdminUserList(0, 0, $where);
            $pages = null;
        } else {
            $pageSize = 20;
            $pages = new Pagination(['totalCount' => UserRepository::getAdminUserListCount($where), 'pageSize' => $pageSize]);
            $pageList = UserRepository::getAdminUserList($pages->offset, $pages->limit, $where);
        }

        /**
         * 数据整理
         */
        return [
            'listdata'   => $pageList,
            'pages'      => $pages,
afd2f743   xu   app-ht(v0.0.1 bui...
87
88
            'gets'       => $gets,
            'statusList' => User::getStatusLabels(),
d11ff394   xu   app-ht(v0.0.1 bui...
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
        ];
    }
    /**
     * 导出订单数据
     * @return string
     */
    public function actionExportDa()
    {
        $data = $this->dataList(0);

        return $this->renderPartial("exportDa", $data);
    }

    /**
     * @return string
     */
    public function actionInfo()
    {
        $id = $this->request->get('id');

        $userModel = UserRepository::findOne(['id' => $id]);
        if (empty($userModel)) {
            $params = [];
            return $this->render('info', $params);
        }

afd2f743   xu   app-ht(v0.0.1 bui...
115
        $userProfile = $userModel->profile;
d11ff394   xu   app-ht(v0.0.1 bui...
116
117
118
119
120
121
        $user = [
            'id'            => $userModel->id,
            'uuid'          => $userModel->uuid,
            'mobile'        => $userModel->mobile,
            'username'      => $userModel->user_name,
            'name'          => $userModel->name,
afd2f743   xu   app-ht(v0.0.1 bui...
122
            'status'        => $userModel->status,
955204e8   xu   app-ht(v0.0.1 bui...
123
            'address'       => $userProfile->address,
afd2f743   xu   app-ht(v0.0.1 bui...
124
            'status_label'  => User::getStatusLabels($userModel->status),
bb9baa4c   xu   app-wx v0.1.0 bui...
125
126
127
128
            'emergencyContact' => $userProfile->emergency_contact,
            'emergencyPerson' => $userProfile->emergency_person,
            'licensePic'    => ImageManager::getUrl($userProfile->license_pic),
            'licensePicMin' => ImageManager::getUrl($userProfile->license_pic, 'min'),
afd2f743   xu   app-ht(v0.0.1 bui...
129
130
            'factoryHeadPic'    => ImageManager::getUrl($userProfile->factory_head_pic),
            'factoryHeadPicMin' => ImageManager::getUrl($userProfile->factory_head_pic, 'min'),
bb9baa4c   xu   app-wx v0.1.0 bui...
131
132
133
134
135
            'techChargePic'    => ImageManager::getUrl($userProfile->tech_charge_pic),
            'techChargePicMin' => ImageManager::getUrl($userProfile->tech_charge_pic, 'min'),
            'qaChargePic'    => ImageManager::getUrl($userProfile->qa_charge_pic),
            'qaChargePicMin' => ImageManager::getUrl($userProfile->qa_charge_pic, 'min'),
            'created_at'    => $userModel->created_at
d11ff394   xu   app-ht(v0.0.1 bui...
136
137
138
139
140
        ];
        $params['user'] = $user;

        return $this->render('info', $params);
    }
afd2f743   xu   app-ht(v0.0.1 bui...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

    /**
     * @return string
     * @throws \yii\db\Exception
     */
    public function actionApprove()
    {
        $e = new stdClass();
        $e->success = false;
        $e->message = '';
        $uuid = $this->request->post('id');
        $userModel = UserRepository::findOne(['uuid' => $uuid]);
        if (empty($userModel)) {
            $e->message = '找不到该维修厂';
            return $this->renderJson($e);
        }
        if (User::STATUS_APPROVE == $userModel->status) {
            $e->message = '改维修厂已经审核通过了,无需再次审核';
            return $this->renderJson($e);
        }
        $tran = Yii::$app->db->beginTransaction();
        try {
            $userModel->status = User::STATUS_APPROVE;
            $userModel->save();
            $userProfile = $userModel->profile;
            $userProfile->approve_at = time();
            $userProfile->save();
            $tran->commit();
            $e->success = true;
            $e->message = '审核成功';
        } catch(Exception $ex) {
            $tran->rollBack();
            $e->message = '审核失败';
        }


        return $this->renderJson($e);
    }
d11ff394   xu   app-ht(v0.0.1 bui...
179
}