Commit 931eed21271f54a09e9c857da11825cf2e2b1f63
1 parent
aa2f3513
Exists in
master
1. A授权接口开发
2. A增加设备管理 3. F修改MAC地址生成算法
Showing
19 changed files
with
910 additions
and
852 deletions
Show diff stats
app-api/controllers/AuthDeviceController.php
... | ... | @@ -2,12 +2,15 @@ |
2 | 2 | |
3 | 3 | namespace app\api\controllers; |
4 | 4 | |
5 | -use Yii; | |
6 | 5 | |
6 | +use Yii; | |
7 | 7 | |
8 | 8 | use common\helpers\Utils; |
9 | +use domain\device\DeviceRepository; | |
10 | +use domain\device\Device; | |
11 | +use domain\device\DeviceStatus; | |
9 | 12 | use stdClass; |
10 | -use function sizeof; | |
13 | + | |
11 | 14 | use function date; |
12 | 15 | use function count; |
13 | 16 | use function time; |
... | ... | @@ -37,29 +40,40 @@ class AuthDeviceController extends BaseController |
37 | 40 | public function actionIndex() |
38 | 41 | { |
39 | 42 | $req = Yii::$app->request; |
40 | - $manufacture = $req->post('manufacture'); | |
41 | - $device_id = $req->post('device_id'); | |
42 | - $project = $req->post('project'); | |
43 | - $model = $req->post('model'); | |
43 | + $manufactureNo = $req->post('manufacture'); | |
44 | + $deviceId = $req->post('device_id'); | |
45 | + $projectNo = $req->post('project'); | |
46 | + $modelNo = $req->post('model'); | |
44 | 47 | $sign = $req->post('sign'); |
45 | - $production = $req->post('production'); | |
48 | + $productionNo = $req->post('production'); | |
46 | 49 | $timestamp = $req->post('timestamp'); |
47 | 50 | $e = new stdClass(); |
48 | 51 | $e->status = 0; |
49 | - $e->message = 'fail'; | |
52 | + $e->message = '授权失败'; | |
50 | 53 | $e->serial_no = '';; |
51 | 54 | $e->mac = ''; |
52 | 55 | |
53 | 56 | $salt = self::SIGN_SALT; |
54 | - $makeSign = md5($manufacture . $project. $model . $production . $timestamp . $salt); | |
57 | + $makeSign = md5($manufactureNo . $projectNo. $modelNo . $productionNo . $timestamp . $salt); | |
55 | 58 | if ($sign != $makeSign) { |
56 | - $e->message = 'sign 有误'; | |
59 | + $e->message = '签名有误'; | |
57 | 60 | return $e; |
58 | 61 | } |
62 | + // 检测是否授权过了的设备 | |
63 | + $deviceModel = DeviceRepository::findOne(['device_id' => $deviceId]); | |
64 | + if ($deviceModel && DeviceStatus::HAS_AUTH == $deviceModel->status) { | |
65 | + $e->mac = $deviceModel->mac; | |
66 | + $e->serial_no = $deviceModel->serial_no; | |
67 | + $e->status = 1; | |
68 | + return $e; | |
69 | + } | |
70 | + $authResult = Device::authDevice($deviceId, $manufactureNo, $projectNo, $modelNo, $productionNo); | |
59 | 71 | |
60 | - $e->status = 1; | |
61 | - $e->message = '授权成功'; | |
62 | - $e->mac = Utils::macGenerate(); | |
72 | + if ($authResult->success) { | |
73 | + $e->mac = $authResult->mac; | |
74 | + $e->serial_no = $authResult->serial_no; | |
75 | + $e->status = 1; | |
76 | + } | |
63 | 77 | |
64 | 78 | return $e; |
65 | 79 | } | ... | ... |
app-ht/modules/device/controllers/DeviceController.php
... | ... | @@ -4,10 +4,19 @@ namespace app\ht\modules\device\controllers; |
4 | 4 | |
5 | 5 | |
6 | 6 | use Yii; |
7 | +use yii\base\Exception; | |
7 | 8 | use yii\data\Pagination; |
8 | 9 | use app\ht\controllers\BaseController; |
9 | -use domain\DeviceRepository; | |
10 | -use domain\DeviceStatus; | |
10 | +use common\helpers\Utils; | |
11 | +use domain\device\DeviceStatus; | |
12 | +use domain\device\CreateBatchRepository; | |
13 | +use domain\device\Device; | |
14 | +use domain\device\DeviceRepository; | |
15 | +use domain\device\models\Device as DeviceModel; | |
16 | + | |
17 | +use domain\device\CreateBatch; | |
18 | + | |
19 | +use stdClass; | |
11 | 20 | |
12 | 21 | /** |
13 | 22 | * 设备管理 |
... | ... | @@ -22,15 +31,40 @@ class DeviceController extends BaseController |
22 | 31 | $request = Yii::$app->request; |
23 | 32 | $serialNo = $request->get('serial_no'); |
24 | 33 | $mac = $request->get('mac'); |
34 | + $project = $request->get('project'); | |
35 | + $model = $request->get('model'); | |
36 | + $production = $request->get('production'); | |
37 | + $manufacture = $request->get('manufacture'); | |
38 | + $deviceId = $request->get('device_id'); | |
39 | + $status = $request->get('status'); | |
25 | 40 | $page = $request->get('page'); |
26 | 41 | $where = [ |
27 | - 'and' | |
42 | + 'and', | |
43 | + ['=','a.is_delete', 0] | |
28 | 44 | ]; |
29 | - if (null !== $serialNo) { | |
30 | - $where[] = ['like', 'serial_no', $serialNo]; | |
45 | + if (!empty($serialNo)) { | |
46 | + $where[] = ['like', 'a.serial_no', $serialNo]; | |
47 | + } | |
48 | + if (!empty($project)) { | |
49 | + $where[] = ['like', 'p.name', $project]; | |
50 | + } | |
51 | + if (!empty($model)) { | |
52 | + $where[] = ['like', 'mo.name', $model]; | |
53 | + } | |
54 | + if (!empty($production)) { | |
55 | + $where[] = ['like', 'pd.name', $production]; | |
56 | + } | |
57 | + if (!empty($mac)) { | |
58 | + $where[] = ['like', 'a.mac', $mac]; | |
59 | + } | |
60 | + if (!empty($manufacture)) { | |
61 | + $where[] = ['like', 'm.name', $manufacture]; | |
31 | 62 | } |
32 | - if (isset($mac)) { | |
33 | - $where[] = ['like', 'mac', $mac]; | |
63 | + if (!empty($deviceId)) { | |
64 | + $where[] = ['like', 'a.device_id', $deviceId]; | |
65 | + } | |
66 | + if (isset($_GET['status']) && -1 != $status) { | |
67 | + $where[] = ['=', 'a.status', $status]; | |
34 | 68 | } |
35 | 69 | |
36 | 70 | if (0 >= $page) { |
... | ... | @@ -38,6 +72,7 @@ class DeviceController extends BaseController |
38 | 72 | } |
39 | 73 | $pageSize = 20; |
40 | 74 | $page = ($page -1) * $pageSize; |
75 | + // DeviceRepository::getList($where, $pageSize, $page); | |
41 | 76 | $deviceData = DeviceRepository::getList($where, $pageSize, $page); |
42 | 77 | $pages = new Pagination(['totalCount' => DeviceRepository::getListCount($where), 'pageSize' => $pageSize]); |
43 | 78 | $statusList = DeviceStatus::statusLabels(); // |
... | ... | @@ -48,13 +83,117 @@ class DeviceController extends BaseController |
48 | 83 | $params["gets"] = [ |
49 | 84 | 'serial_no' => $serialNo, |
50 | 85 | 'mac' => $mac, |
86 | + 'project' => $project, | |
87 | + 'model' => $model, | |
88 | + 'device_id' => $deviceId, | |
89 | + 'production' => $production, | |
90 | + 'manufacture' => $manufacture, | |
91 | + 'status' => $status | |
51 | 92 | ]; |
52 | 93 | |
53 | - | |
54 | 94 | return $this->render('index', $params); |
55 | 95 | } |
56 | 96 | |
57 | 97 | /** |
98 | + * @return string | |
99 | + */ | |
100 | + public function actionCreateDevice() | |
101 | + { | |
102 | + return $this->render('createDevice'); | |
103 | + } | |
104 | + | |
105 | + /** | |
106 | + * | |
107 | + */ | |
108 | + public function actionDoCreateDevice() | |
109 | + { | |
110 | + $req = Yii::$app->request; | |
111 | + $manufactureId = $req->post('manufactureId'); | |
112 | + $projectId = $req->post('projectId'); | |
113 | + $modelId = $req->post('modelId'); | |
114 | + $productionId = $req->post('productionId'); | |
115 | + | |
116 | + $manufactureNo = $req->post('manufactureNo'); | |
117 | + $projectNo = $req->post('projectNo'); | |
118 | + $modelNo = $req->post('modelNo'); | |
119 | + $productionNo = $req->post('productionNo'); | |
120 | + | |
121 | + $num = $req->post('num'); | |
122 | + $e = new stdClass(); | |
123 | + $e->success = false; | |
124 | + $e->message = 'fail'; | |
125 | + if (empty($num)) { | |
126 | + $e->message = '数量不能为0'; | |
127 | + return $this->renderJson($e); | |
128 | + } | |
129 | + if (1 * $num > 30000) { | |
130 | + $e->message = '数量不能超过3万0'; | |
131 | + return $this->renderJson($e); | |
132 | + } | |
133 | + | |
134 | + $batchNo = strtoupper(Device::getBatchNo($manufactureNo,$projectNo,$modelNo,$productionNo)); | |
135 | + $batchModel = CreateBatchRepository::findOne(['batch_no' => $batchNo]); | |
136 | + if ($batchModel) { | |
137 | + $e->message = '已经创建过这个批次序列号'; | |
138 | + return $this->renderJson($e); | |
139 | + } | |
140 | + | |
141 | + $item = [ | |
142 | + 'batch_no' => $batchNo, | |
143 | + 'manufacture_id' => $manufactureId, | |
144 | + 'project_id' => $projectId, | |
145 | + 'model_id' => $modelId, | |
146 | + 'num' => $num, | |
147 | + 'production_id' => $productionId, | |
148 | + ]; | |
149 | + $transaction = Yii::$app->db->beginTransaction(); | |
150 | + try { | |
151 | + $newBatchModel = CreateBatch::create($item); | |
152 | + $saveData = []; | |
153 | + $tt = time(); | |
154 | + for ($i = 1 ; $i <= $num; $i++) { | |
155 | + $saveData[] = [ | |
156 | + strtoupper($batchNo.sprintf('%04x', $i)), | |
157 | + Utils::macGenerate(), | |
158 | + 0, | |
159 | + $newBatchModel->id, | |
160 | + 0, | |
161 | + 0, | |
162 | + 0, | |
163 | + 0, | |
164 | + $tt, | |
165 | + $tt | |
166 | + ]; | |
167 | + | |
168 | + } | |
169 | + $res = Yii::$app->db->createCommand()->batchInsert(DeviceModel::tableName(), | |
170 | + array('serial_no','mac','status','batch_id','is_delete','has_re_auth','apply_at','auth_at','created_at','updated_at'), | |
171 | + $saveData)->execute();//执行批量添加 | |
172 | + $transaction->commit(); | |
173 | + $e->success = true; | |
174 | + } catch (Exception $exception) { | |
175 | + $transaction->rollBack(); | |
176 | + $e->message = '创建失败'; | |
177 | + } | |
178 | + | |
179 | + return $this->renderJson($e); | |
180 | + } | |
181 | + | |
182 | + /** | |
183 | + * @return string | |
184 | + */ | |
185 | + public function actionSearchItem() | |
186 | + { | |
187 | + $req = Yii::$app->request; | |
188 | + $type = $req->post('type'); | |
189 | + $keyword = $req->post('query'); | |
190 | + $e = new stdClass(); | |
191 | + $list = CreateBatchRepository::getSerialNoComponent($type, $keyword); | |
192 | + $e->list = $list; | |
193 | + | |
194 | + return $this->renderJson($e); | |
195 | + } | |
196 | + /** | |
58 | 197 | * 导出订单数据 |
59 | 198 | * @return string |
60 | 199 | */ |
... | ... | @@ -67,10 +206,67 @@ class DeviceController extends BaseController |
67 | 206 | /** |
68 | 207 | * @return string |
69 | 208 | */ |
70 | - public function actionInfo() | |
209 | + public function actionAuthDevice() | |
71 | 210 | { |
211 | + $req = Yii::$app->request; | |
212 | + $id = $req->post('id'); | |
213 | + $e = new stdClass(); | |
214 | + $e->success = false; | |
215 | + $e->message = 'fail'; | |
216 | + $deviceModel = DeviceRepository::findOne(['id' => $id]); | |
217 | + if (empty($deviceModel)) { | |
218 | + $e->message = '找不到该设备'; | |
219 | + return $this->renderJson($e); | |
220 | + } | |
221 | + if(DeviceStatus::HAS_AUTH == $deviceModel->status) { | |
222 | + $e->message = '设备已经授权了'; | |
223 | + return $this->renderJson($e); | |
224 | + } | |
225 | + if (empty($deviceModel->device_id)) { | |
226 | + $e->message = '设备ID为空,不能授权'; | |
227 | + return $this->renderJson($e); | |
228 | + } | |
229 | + $tt = time(); | |
230 | + $deviceModel->apply_at = $tt; | |
231 | + $deviceModel->auth_at = $tt; | |
232 | + $deviceModel->status = DeviceStatus::HAS_AUTH; | |
233 | + $result = $deviceModel->save(); | |
234 | + if ($result) { | |
235 | + $e->success = true; | |
236 | + } else { | |
237 | + $e->message = '授权失败'; | |
238 | + } | |
72 | 239 | |
240 | + return $this->renderJson($e); | |
73 | 241 | } |
74 | 242 | |
243 | + /** | |
244 | + * @return string | |
245 | + */ | |
246 | + public function actionDelDevice() | |
247 | + { | |
248 | + $req = Yii::$app->request; | |
249 | + $id = $req->post('id'); | |
250 | + $e = new stdClass(); | |
251 | + $e->success = false; | |
252 | + $e->message = 'fail'; | |
253 | + $deviceModel = DeviceRepository::findOne(['id' => $id]); | |
254 | + if (empty($deviceModel)) { | |
255 | + $e->message = '找不到该设备'; | |
256 | + return $this->renderJson($e); | |
257 | + } | |
258 | + | |
259 | + $tt = time(); | |
260 | + | |
261 | + $deviceModel->is_delete = 1; | |
262 | + $result = $deviceModel->save(); | |
263 | + if ($result) { | |
264 | + $e->success = true; | |
265 | + } else { | |
266 | + $e->message = '删除失败'; | |
267 | + } | |
268 | + | |
269 | + return $this->renderJson($e); | |
270 | + } | |
75 | 271 | |
76 | 272 | } |
77 | 273 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,138 @@ |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Url; | |
4 | +use app\ht\helpers\CssFiles; | |
5 | + | |
6 | +$this->title = '新建序列号'; | |
7 | +$this->params['breadcrumbs'][] = '序列号管理'; | |
8 | +$this->params['breadcrumbs'][] = ['label' => '序列号列表', 'url' => ['/device/deivce/index']]; | |
9 | +$this->params['breadcrumbs'][] = $this->title; | |
10 | + | |
11 | +CssFiles::register($this, 'exts/showimg/css/showimg.css'); | |
12 | + | |
13 | +?> | |
14 | +<style> | |
15 | + .create-div .form-group{padding:1rem 0} | |
16 | + .create-div .full-width{width:100%;} | |
17 | +</style> | |
18 | +<div class="panel panel-default"> | |
19 | + <div class="panel-body form-inline create-div"> | |
20 | + <form action="" method="get" id="create-form" class="filter-form"> | |
21 | + <div class="form-group col-sm-12"> | |
22 | + <label for="manufacture" class="col-sm-4 control-label text-right">厂商:</label> | |
23 | + <div class="col-sm-4 form-inline"> | |
24 | + <input type="text" class="form-control full-width searchInput" id="manufacture" name="manufacture" value="" autocomplete="off"> | |
25 | + </div> | |
26 | + <div class="col-sm-4"><a href="javascript:void(0)">+创建厂商</a></div> | |
27 | + </div> | |
28 | + <div class="form-group col-sm-12"> | |
29 | + <label for="project" class="col-sm-4 control-label text-right">项目名:</label> | |
30 | + <div class="col-sm-4 form-inline"> | |
31 | + <input type="text" class="form-control full-width searchInput" id="project" name="project" value="" autocomplete="off"> | |
32 | + </div> | |
33 | + <div class="col-sm-4"><a href="javascript:void(0)">+创建项目</a></div> | |
34 | + | |
35 | + </div> | |
36 | + <div class="form-group col-sm-12"> | |
37 | + <label for="model" class="col-sm-4 control-label text-right">设备型号:</label> | |
38 | + <div class="col-sm-4 form-inline"> | |
39 | + <input type="text" class="form-control full-width searchInput" id="model" name="model" value="" autocomplete="off"> | |
40 | + </div> | |
41 | + <div class="col-sm-4"><a href="javascript:void(0)">+创建型号</a></div> | |
42 | + </div> | |
43 | + <div class="form-group col-sm-12"> | |
44 | + <label for="production" class="col-sm-4 control-label text-right">生产日期:</label> | |
45 | + <div class="col-sm-4 form-inline"> | |
46 | + <input type="text" class="form-control full-width searchInput" id="production" name="production" value="" autocomplete="off"> | |
47 | + </div> | |
48 | + <div class="col-sm-4"><a href="javascript:void(0)">+生产日期</a></div> | |
49 | + </div> | |
50 | + | |
51 | + <div class="form-group col-sm-12"> | |
52 | + <label for="production" class="col-sm-4 control-label text-right">数量:</label> | |
53 | + <div class="col-sm-4 form-inline"> | |
54 | + <input type="number" class="form-control full-width" id="num" name="num" value="" autocomplete="off"> | |
55 | + </div> | |
56 | + </div> | |
57 | + | |
58 | + <div class="form-group col-sm-12" style="text-align: center;"> | |
59 | + <div><button type="submit" class="btn btn-primary font-1" id="createDeviceBtn">创建</button></div> | |
60 | + </div> | |
61 | + </form> | |
62 | + </div> | |
63 | + | |
64 | +</div> | |
65 | + | |
66 | +<script type="text/javascript" src="<?=Url::toRoute('/exts/base/1.0.0/ui/typeahead/bootstrap3-typeahead.min.js')?>" ></script> | |
67 | +<script type="text/javascript"> | |
68 | + var searchItemUrl = "<?=Url::toRoute('/device/device/search-item')?>"; | |
69 | + var saveUrl = "<?=Url::toRoute('/device/device/do-create-device')?>"; | |
70 | +$(function() { | |
71 | + | |
72 | + function typeaheadAll(id) { | |
73 | + var type = id; | |
74 | + $('#'+id).typeahead({ | |
75 | + minLength: 2, | |
76 | + items:15, | |
77 | + source: function(query, process) { | |
78 | + | |
79 | + var parameter = {query: query, type: type}; | |
80 | + $.post(searchItemUrl, parameter, function (res) { | |
81 | + var data = []; | |
82 | + var iList = res.list; | |
83 | + for(i in iList){ | |
84 | + var tItem = iList[i]; | |
85 | + data.push(JSON.stringify(tItem)); | |
86 | + } | |
87 | + process(data); | |
88 | + },'json'); | |
89 | + }, | |
90 | + highlighter: function(item) { | |
91 | + var itemObject = JSON.parse(item); | |
92 | + var title = itemObject.name; | |
93 | + $('#'+id).attr('data-id', itemObject.id); | |
94 | + $('#'+id).attr('data-no', itemObject[id+'_no']); | |
95 | + return title ; | |
96 | + }, | |
97 | + | |
98 | + updater: function(item) { | |
99 | + var itemObject = JSON.parse(item); | |
100 | + var title = itemObject.name; | |
101 | + $('#'+id).attr('data-id', itemObject.id); | |
102 | + $('#'+id).attr('data-no', itemObject[id+'_no']); | |
103 | + return title; | |
104 | + } | |
105 | + }); | |
106 | + } | |
107 | + typeaheadAll('manufacture'); | |
108 | + typeaheadAll('project'); | |
109 | + typeaheadAll('model'); | |
110 | + typeaheadAll('production'); | |
111 | + | |
112 | + $('#createDeviceBtn').click(function(e) { | |
113 | + e.preventDefault(); | |
114 | + var params = { | |
115 | + manufactureId: $('#manufacture').attr('data-id'), | |
116 | + manufactureNo: $('#manufacture').attr('data-no'), | |
117 | + projectId: $('#project').attr('data-id'), | |
118 | + projectNo: $('#project').attr('data-no'), | |
119 | + | |
120 | + modelId: $('#model').attr('data-id'), | |
121 | + modelNo: $('#model').attr('data-no'), | |
122 | + | |
123 | + productionId: $('#production').attr('data-id'), | |
124 | + productionNo: $('#production').attr('data-no'), | |
125 | + num: $('#num').val() | |
126 | + } | |
127 | + $.post(saveUrl, params, function(res) { | |
128 | + if (!res.success) { | |
129 | + alert(res.message); | |
130 | + return false; | |
131 | + } | |
132 | + return false; | |
133 | + //window.location.href = '<?=Url::toRoute('/device/device/index')?>' | |
134 | + }, 'json') | |
135 | + }) | |
136 | + | |
137 | +}) | |
138 | +</script> | ... | ... |
app-ht/modules/device/views/device/index.php
1 | 1 | <?php |
2 | 2 | use yii\helpers\Url; |
3 | 3 | use app\ht\widgets\LinkPager; |
4 | -use common\helpers\ImageManager; | |
5 | - | |
4 | +use domain\device\DeviceStatus; | |
6 | 5 | |
7 | 6 | $this->title = '序列号管理'; |
8 | 7 | $this->params['breadcrumbs'][] = '序列号管理'; |
9 | 8 | $this->params['breadcrumbs'][] = $this->title; |
10 | 9 | ?> |
11 | - | |
10 | +<style> | |
11 | + .cell-cls{width:60%;word-wrap: break-word} | |
12 | + .td-cls{padding:8px 0} | |
13 | +</style> | |
12 | 14 | <div class="panel panel-default"> |
13 | 15 | <div class="panel-body"> |
14 | 16 | <form action="" method="get" id="search-form" class="filter-form"> |
15 | - <table width="100%" class="table table-bordered"> | |
16 | - <tbody> | |
17 | - <tr > | |
18 | - <td width="10%" class="text-right">名称:</td> | |
19 | - <td width="20%" class="text-left"><input type="text" class="form-control" name="name" id="name" value="<?php if (!empty($gets['name'])){ echo $gets['name']; } ?>"></td> | |
20 | - <td width="10%" class="text-right">开始时间:</td> | |
21 | - <td width="20%" class="text-left"><input type="date" class="form-control" name="creatTime" value="<?php if (!empty($gets['creatTime'])){ echo $gets['creatTime']; } ?>"></td> | |
22 | - <td width="10%" class="text-right">结束时间:</td> | |
23 | - <td width="20%" class="text-left"><input type="date" class="form-control" name="endTime" value="<?php if (!empty($gets['endTime'])){ echo $gets['endTime']; } ?>"></td> | |
24 | - </tr> | |
25 | - <tr class="search"> | |
26 | - <td colspan="6" class="text-center"> | |
27 | - <button type="submit" class="btn btn-primary btncls" id="search"><i class="glyphicon glyphicon-search"></i> 查 询 </button> | |
28 | - <a class="btn btn-default btncls" href="<?=Url::toRoute(["/shop/goods/index"])?>">重 置</a> | |
29 | - </td> | |
30 | - </tr> | |
31 | - </tbody> | |
32 | - </table> | |
17 | + <div class="form-group col-sm-12"> | |
18 | + <label for="serial_no" class="col-sm-1 control-label text-right">序列号:</label> | |
19 | + <div class="col-sm-2 form-inline"> | |
20 | + <input type="text" class="form-control" id="serial_no" name="serial_no" value="<?php if (!empty($gets['serial_no'])){ echo $gets['serial_no'];} ?>" autocomplete="off"> | |
21 | + </div> | |
22 | + <label for="project" class="col-sm-1 control-label text-right">项目名:</label> | |
23 | + <div class="col-sm-2 form-inline"> | |
24 | + <input type="text" class="form-control" id="project" name="project" value="<?php if (!empty($gets['project'])){ echo $gets['project'];} ?>" autocomplete="off"> | |
25 | + </div> | |
26 | + <label for="model" class="col-sm-1 control-label text-right">型号:</label> | |
27 | + <div class="col-sm-2 form-inline"> | |
28 | + <input type="text" class="form-control" id="model" name="model" value="<?php if (!empty($gets['model'])){ echo $gets['model'];} ?>" autocomplete="off"> | |
29 | + </div> | |
30 | + <label for="status" class="col-sm-1 control-label text-right">状态:</label> | |
31 | + <div class="col-sm-2 form-inline"> | |
32 | + <select id="status" class="form-control" name="status"> | |
33 | + <option value="-1">全部</option> | |
34 | + <?php foreach($statusList as $k => $v):?> | |
35 | + <option value="<?=$k?>" <?php if($k == $gets['status']): ?>selected<?php endif; ?>><?=$v?></option> | |
36 | + <?php endforeach;?> | |
37 | + </select> | |
38 | + | |
39 | + </div> | |
40 | + </div> | |
41 | + | |
42 | + <div class="form-group col-sm-12"> | |
43 | + <label for="production" class="col-sm-1 control-label text-right">生产日期:</label> | |
44 | + <div class="col-sm-2 form-inline"> | |
45 | + <input type="text" class="form-control" id="production" name="production" value="<?php if (!empty($gets['production'])){ echo $gets['production'];} ?>" autocomplete="off"> | |
46 | + </div> | |
47 | + <label for="manufacture" class="col-sm-1 control-label text-right">厂商:</label> | |
48 | + <div class="col-sm-2 form-inline"> | |
49 | + <input type="text" class="form-control" id="manufacture" name="manufacture" value="<?php if (!empty($gets['manufacture'])){ echo $gets['manufacture'];} ?>" autocomplete="off"> | |
50 | + </div> | |
51 | + <label for="apply_at" class="col-sm-1 control-label text-right">申请时间:</label> | |
52 | + <div class="col-sm-2 form-inline"> | |
53 | + <input type="text" class="form-control" id="apply_at" name="apply_at" value="<?php if (!empty($gets['apply_at'])){ echo $gets['apply_at'];} ?>" autocomplete="off"> | |
54 | + </div> | |
55 | + <label for="auth_at" class="col-sm-1 control-label text-right">授权时间:</label> | |
56 | + <div class="col-sm-2 form-inline"> | |
57 | + <input type="text" class="form-control" id="auth_at" name="auth_at" value="<?php if (!empty($gets['auth_at'])){ echo $gets['auth_at'];} ?>" autocomplete="off"> | |
58 | + </div> | |
59 | + </div> | |
60 | + | |
61 | + <div class="form-group col-sm-12"> | |
62 | + <label for="mac" class="col-sm-1 control-label text-right">MAC地址:</label> | |
63 | + <div class="col-sm-2 form-inline"> | |
64 | + <input type="text" class="form-control" id="mac" name="mac" value="<?php if (!empty($gets['mac'])){ echo $gets['mac'];} ?>" autocomplete="off"> | |
65 | + </div> | |
66 | + <label for="device_id" class="col-sm-1 control-label text-right">设备ID:</label> | |
67 | + <div class="col-sm-2 form-inline"> | |
68 | + <input type="text" class="form-control" id="device_id" name="device_id" value="<?php if (!empty($gets['device_id'])){ echo $gets['device_id'];} ?>" autocomplete="off"> | |
69 | + </div> | |
70 | + <label for="handel" class="col-sm-1 control-label text-right">处理状态:</label> | |
71 | + <div class="col-sm-2 form-inline"> | |
72 | + <input type="text" class="form-control" id="handel" name="handel" value="<?php if (!empty($gets['handel'])){ echo $gets['handel'];} ?>" autocomplete="off"> | |
73 | + </div> | |
74 | + <label for="empty_serial" class="col-sm-1 control-label text-right">空序列号:</label> | |
75 | + <div class="col-sm-2 form-inline"> | |
76 | + <input type="text" class="form-control" id="empty_serial" name="empty_serial" value="<?php if (!empty($gets['empty_serial'])){ echo $gets['empty_serial'];} ?>" autocomplete="off"> | |
77 | + </div> | |
78 | + </div> | |
79 | + | |
80 | + <div class="form-group col-sm-12" style="text-align: center;"> | |
81 | + <button type="submit" class="btn btn-primary font-1" id="submitFilterBtn">查询</button> | |
82 | + </div> | |
33 | 83 | </form> |
34 | 84 | </div> |
35 | 85 | </div> |
... | ... | @@ -40,18 +90,17 @@ $this->params['breadcrumbs'][] = $this->title; |
40 | 90 | <thead> |
41 | 91 | <tr> |
42 | 92 | <th width="6%">ID</th> |
43 | - <th width="8%">序列号</th> | |
93 | + <th width="6%">序列号</th> | |
44 | 94 | <th width="8%">厂商</th> |
45 | - <th width="7%">项目</th> | |
46 | - | |
95 | + <th width="6%">项目</th> | |
47 | 96 | <th width="8%">设备型号</th> |
48 | - <th width="7%">生产日期</th> | |
49 | - <th width="8%">MAC地址</th> | |
50 | - <th width="8%">设备ID</th> | |
51 | - <th width="8%">申请时间</th> | |
52 | - <th width="8%">授权时间</th> | |
53 | - <th width="8%">状态</th> | |
54 | - <th width="7%">操作</th> | |
97 | + <th width="6%">生产日期</th> | |
98 | + <th>MAC地址</th> | |
99 | + <th width="7%">设备ID</th> | |
100 | + <th width="7%">申请时间</th> | |
101 | + <th width="7%">授权时间</th> | |
102 | + <th width="7%">状态</th> | |
103 | + <th >操作</th> | |
55 | 104 | </tr> |
56 | 105 | </thead> |
57 | 106 | |
... | ... | @@ -59,42 +108,42 @@ $this->params['breadcrumbs'][] = $this->title; |
59 | 108 | <?php if ($deviceList) { ?> |
60 | 109 | <?php foreach ($deviceList as $item) : ?> |
61 | 110 | <tr> |
62 | - <td style="padding:12px;"> | |
111 | + <td class="td-cls"> | |
63 | 112 | <?= $item['id'] ?> |
64 | 113 | </td> |
65 | - <td style="padding:12px;"> | |
66 | - <?= $item['serial_no'] ?> | |
114 | + <td class="td-cls"> | |
115 | + <div class="cell-cls"><?= $item['serial_no'] ?></div> | |
67 | 116 | </td> |
68 | - <td style="padding:12px;"> | |
117 | + <td class="td-cls"> | |
69 | 118 | <?= $item['manufacture'] ?> |
70 | 119 | </td> |
71 | - <td style="padding:12px;"> | |
120 | + <td class="td-cls"> | |
72 | 121 | <?= $item['project'] ?> |
73 | 122 | </td> |
74 | - <td style="padding:12px;"> | |
123 | + <td class="td-cls"> | |
75 | 124 | <?= $item['model'] ?> |
76 | 125 | </td> |
77 | - <td style="padding:12px;"> | |
126 | + <td class="td-cls"> | |
78 | 127 | <?= $item['production'] ?> |
79 | 128 | </td> |
80 | - <td style="padding:12px;"> | |
81 | - <?= $item['mac'] ?> | |
129 | + <td class="td-cls"> | |
130 | + <div class="cell-cls"><?= $item['mac'] ?></div> | |
82 | 131 | </td> |
83 | - <td style="padding:12px;"> | |
84 | - <?= $item['device_id'] ?> | |
132 | + <td class="td-cls"> | |
133 | + <?= $item['device_id']? $item['device_id']:'暂无'?> | |
85 | 134 | </td> |
86 | - <td style="padding:12px;"> | |
87 | - <?= date('Y-m-d H:i:s',$item['apply_at'] ) ?> | |
135 | + <td class="td-cls"> | |
136 | + <?= $item['apply_at']?date('Y-m-d H:i:s', $item['apply_at']):'暂无' ?> | |
88 | 137 | </td> |
89 | - <td style="padding:12px;"> | |
90 | - <?= date('Y-m-d H:i:s',$item['auth_at'] ) ?> | |
138 | + <td class="td-cls"> | |
139 | + <?= $item['auth_at']? date('Y-m-d H:i:s', $item['auth_at']):'暂无' ?> | |
91 | 140 | </td> |
92 | - <td style="padding:12px;"> | |
141 | + <td class="td-cls"> | |
93 | 142 | <?= $statusList[$item['status']] ?> |
94 | 143 | </td> |
95 | - <td style="padding:12px;"> | |
96 | - <button class="btn btn-info btn-sm btn_auth_success" aid="<?=$item['id'] ?>">编辑</button> | | |
97 | - <button class="btn btn-danger btn-sm btn_auth_fail" aid="<?=$item['id'] ?>">授权</button> | | |
144 | + <td class="td-cls"> | |
145 | + <button class="btn btn-info btn-sm btn_edit" aid="<?=$item['id'] ?>">编辑</button> | | |
146 | + <?php if(DeviceStatus::HAS_AUTH != $item['status']){?> <button class="btn btn-primary btn-sm btn_auth" aid="<?=$item['id'] ?>">授权</button> | <?php }?> | |
98 | 147 | <button class="btn btn-danger btn-sm btn_del" aid="<?=$item['id'] ?>">删除</button> |
99 | 148 | </td> |
100 | 149 | </tr> |
... | ... | @@ -119,8 +168,35 @@ $this->params['breadcrumbs'][] = $this->title; |
119 | 168 | </div> |
120 | 169 | </div> |
121 | 170 | </div> |
171 | + | |
122 | 172 | <script> |
123 | - $(document).ready(function () { | |
173 | + var authURL = "<?=Url::toRoute('/device/device/auth-device')?>"; | |
174 | + var delURL = "<?=Url::toRoute('/device/device/del-device')?>"; | |
175 | + $(function () { | |
176 | + $('.btn_auth').click(function(e) { | |
177 | + var aid = $(this).attr('aid'); | |
178 | + $.post(authURL, {id:aid}, function(res) { | |
179 | + if (!res.success) { | |
180 | + alert(res.message); | |
181 | + return false; | |
182 | + } | |
183 | + window.location.reload(); | |
184 | + }, 'json') | |
185 | + }) | |
124 | 186 | |
187 | + //btn_del | |
188 | + $('.btn_del').click(function(e) { | |
189 | + if (!confirm('确定删除!')) { | |
190 | + return false; | |
191 | + } | |
192 | + var aid = $(this).attr('aid'); | |
193 | + $.post(delURL, {id:aid}, function(res) { | |
194 | + if (!res.success) { | |
195 | + alert(res.message); | |
196 | + return false; | |
197 | + } | |
198 | + window.location.reload(); | |
199 | + }, 'json') | |
200 | + }) | |
125 | 201 | }); |
126 | 202 | </script> |
127 | 203 | \ No newline at end of file | ... | ... |
common/helpers/Utils.php
... | ... | @@ -523,20 +523,8 @@ class Utils |
523 | 523 | * 生成mac 地址 |
524 | 524 | * @return string |
525 | 525 | */ |
526 | - static function macGenerate() { | |
527 | - // 第二位必须是偶数 | |
528 | - /* | |
529 | - $rArray = [ | |
530 | - 0x1C, | |
531 | - 0x1C, | |
532 | - 0x1C, | |
533 | - mt_rand(0x00, 0x7f), | |
534 | - mt_rand(0x00, 0xff), | |
535 | - mt_rand(0x00, 0xff) | |
536 | - ]; | |
537 | - return implode(':', array_map(function($v) { | |
538 | - return sprintf("%02X", $v); | |
539 | - }, $rArray));*/ | |
526 | + static function macGenerate() | |
527 | + { | |
540 | 528 | $adrArray = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" ]; |
541 | 529 | $returnMAC = []; |
542 | 530 | |
... | ... | @@ -547,7 +535,7 @@ class Utils |
547 | 535 | } else { |
548 | 536 | //第二位只能是偶数 |
549 | 537 | $indexArray = [1, 3, 5, 7, 9, 11, 13, 15]; |
550 | - $index = $indexArray[mt_rand(1, 8)]; | |
538 | + $index = $indexArray[mt_rand(0, 7)]; | |
551 | 539 | } |
552 | 540 | |
553 | 541 | $returnMAC[] = $adrArray[$index]; | ... | ... |
console/controllers/TestController.php
... | ... | @@ -72,662 +72,10 @@ use yii\helpers\ArrayHelper; |
72 | 72 | class TestController extends Controller |
73 | 73 | { |
74 | 74 | |
75 | - public function actionCallT() | |
76 | - { | |
77 | - //设备报修:22.552092, 113.927124, 工程师 , | |
78 | - //echo Distance::getDistance(22.561575,113.891098, 22.554621,113.906006); | |
79 | - echo "start"; | |
80 | - echo (null !== '0'); | |
81 | - echo "end"; | |
82 | - | |
83 | - // | |
84 | - $mailList = array('xukexuzhun1@163.com', 'perelmen@qq.com'); | |
85 | - | |
86 | - /* | |
87 | - foreach ($mailList as $mail) { | |
88 | - $emailSendHandle = \yii::$app->invoice_mailer->compose(); | |
89 | - $emailSendHandle->setTo($mail); | |
90 | - $emailSendHandle->setTextBody('深圳下大雨了 delete'); | |
91 | - $emailSendHandle->setSubject('深圳下大雨了 subject ....'); | |
92 | - $result = $emailSendHandle->send(); | |
93 | - | |
94 | - echo $result ."\r\n"; | |
95 | - } | |
96 | - */ | |
97 | - //$str = "2018-09-04 09:00:00"; | |
98 | - //$result = DeviceSearch::splitText('[沧田中]税]x金典'); | |
99 | - //print_r($result); | |
100 | - //echo round('33.1',0); | |
101 | - | |
102 | - //echo Deduction::coverInt(0.9); | |
103 | - | |
104 | - //$returnArr = Deduction::randomUserTag(9, 4); | |
105 | - //shuffle($returnArr); | |
106 | - //print_r($returnArr); | |
107 | - //echo sprintf('%d', 2.00); | |
108 | - | |
109 | - } | |
110 | - | |
111 | - | |
112 | - | |
113 | - | |
114 | - public function actionBindPhone() | |
115 | - { | |
116 | - $numbers = PrivateNumber::getAllPrivateNumbers(); | |
117 | - $result = PrivateNumber::bindNumber( '17724017057','17004894899'); | |
118 | - //echo PrivateNumber::$postResponseStr; | |
119 | - echo "\r\n"; | |
120 | - echo $result; | |
121 | - } | |
122 | - | |
123 | - public function actionBatchBindPhone() | |
124 | - { | |
125 | - $query = new Query(); | |
126 | - $query->from("jwx_engineer"); | |
127 | - $query->select("id, mobile"); | |
128 | - $query->offset(0); | |
129 | - $query->orderBy("id asc"); | |
130 | - $query->limit(810); | |
131 | - $engineers = $query->all(); | |
132 | - | |
133 | - $engineerLen = count($engineers); | |
134 | - $pair = (int)$engineerLen /2; | |
135 | - | |
136 | - $st = time(); | |
137 | - echo 'start:'.$st; | |
138 | - echo "\r\n"; | |
139 | - $redis = \yii::$app->redis; | |
140 | - $count = 0; | |
141 | - for($i = 0; $i < $pair; $i++) { | |
142 | - $j = $pair + $i; | |
143 | - $rKey = 'mobile_'.$engineers[$i]['mobile']."__". $engineers[$j]['mobile']; | |
144 | - //$redis->del($rKey); | |
145 | - $result = PrivateNumber::bindNumber($engineers[$i]['mobile'], $engineers[$j]['mobile']); | |
146 | - //$redis->set($rKey,$result); | |
147 | - $resultJson = json_decode($result); | |
148 | - if ( '000000' == $resultJson->code) { | |
149 | - $count++; | |
150 | - } | |
151 | - echo $rKey; | |
152 | - echo $result ."\r\n"; | |
153 | - | |
154 | - } | |
155 | - echo "pair:".$pair; | |
156 | - echo "\r\n"; | |
157 | - $et = time(); | |
158 | - echo 'end:'.$et; | |
159 | - echo "\r\n"; | |
160 | - echo "t:".($et - $st); | |
161 | - echo "\r\n"; | |
162 | - echo "ok:".$count; | |
163 | - echo "\r\n"; | |
164 | - } | |
165 | - public function actionBatchUnbindPhone() | |
166 | - { | |
167 | - $ids = [269,301,314,316,320,322,330,339,344,345,350,369,378,380]; | |
168 | - $privateNumberRecordModel = PrivateNumberBindRecord::find(); | |
169 | - $privateNumberRecordModel->where(['id' => $ids]); | |
170 | - $privateNumberRecordModel->asArray(); | |
171 | - $records = $privateNumberRecordModel->all(); | |
172 | - $tt = time(); | |
173 | - foreach($records as $record){ | |
174 | - $recordModel = PrivateNumberBindRecord::findOne($record['id']); | |
175 | - if($recordModel) { | |
176 | - //$result = PrivateNumber::unbindNumber($record['subscription_id'], 2); | |
177 | - //echo $result. "\r\n"; | |
178 | - //$recordModel->status = 0; | |
179 | - //$recordModel->is_main = 2; | |
180 | - $recordModel->unbind_at = $tt; | |
181 | - $recordModel->unbind_desc = '超时手动解绑'; | |
182 | - $result2 = $recordModel->save(); | |
183 | - echo "result:". $result2. '__'; | |
184 | - | |
185 | - echo $recordModel->subscription_id. "\r\n"; | |
186 | - | |
187 | - } | |
188 | - } | |
189 | - } | |
190 | - public function actionAna() | |
191 | - { | |
192 | - $redis = \yii::$app->redis; | |
193 | - $records = $redis->hgetall('mobile*'); | |
194 | - print_r($records); | |
195 | - } | |
196 | - | |
197 | - public function actionUnbindPhone() | |
198 | - { | |
199 | - $subscriptionId = '17150372466'; //8617150372466 17150372300 | |
200 | - $result = PrivateNumber::unbindNumber($subscriptionId, 1); | |
201 | - //echo PrivateNumber::$postResponseStr; | |
202 | - echo "\r\n"; | |
203 | - echo $result; | |
204 | - | |
205 | - } | |
206 | - | |
207 | - public function actionQueryPhone() | |
208 | - { | |
209 | - $numbers = PrivateNumber::getAllPrivateNumbers(); | |
210 | - $result = PrivateNumber::queryOrderedNumber('17150372300'); | |
211 | - echo $result; | |
212 | - } | |
213 | - | |
214 | - public function actionQueryVoiceRecord() | |
215 | - { | |
216 | - $subscribeId = '66053756068216559371537933854093'; | |
217 | - $st = PrivateNumber::coverTimeStampToPHP('2018-09-26T03:46:07Z'); | |
218 | - $ed = PrivateNumber::coverTimeStampToPHP('2018-09-26T06:49:01Z'); | |
219 | - $result = PrivateNumber::queryVoiceRecord('fa2b53fb-2a95-49e5-9a5d-9f2b403a8295', '2018-09-26 14:30:00','2018-09-26 14:50:00'); | |
220 | - echo $result; | |
221 | - } | |
222 | - | |
223 | - public function actionGetVoice() | |
224 | - { | |
225 | - $arr = ['66261453769654176011542769693114']; | |
226 | - $privateModel = PrivateNumberVoice::find(); | |
227 | - $privateModel->where(['call_identifier' => $arr]); | |
228 | - $privateModel->asArray(); | |
229 | - $voiceArr = $privateModel->all(); | |
230 | - foreach($voiceArr as $k=>$v){ | |
231 | - $call_id = $v['call_identifier']; | |
232 | - echo $v['path']."\r\n"; | |
233 | - $result = PrivateNumber::getRecordDownloadURL($call_id); | |
234 | - | |
235 | - $path = \yii::getAlias('@app/runtime') . "/empty/".$call_id.".wav"; | |
236 | - | |
237 | - $local_file = fopen($path, 'w'); | |
238 | - if (false !== $local_file){ | |
239 | - if (false !== fwrite($local_file, $result)) { | |
240 | - fclose($local_file); | |
241 | - $savePath = $v['path']; | |
242 | - FileManager::add($path , $savePath); | |
243 | - } | |
244 | - } | |
245 | - } | |
246 | - } | |
247 | - | |
248 | - public function actionAddOssFile() | |
249 | - { | |
250 | - $file = '/s201812211218389859.pdf'; | |
251 | - $path = \yii::getAlias('@app/runtime') . $file ; | |
252 | - $ossSavePath = 'invoice/20181221/s201812211218389859.pdf'; | |
253 | - FileManager::add($path , $ossSavePath); | |
254 | - echo "end"; | |
255 | - } | |
256 | - | |
257 | - public function actionTestCall() | |
258 | - { | |
259 | - //$result = \common\exts\Aliyun\DYPLS\PrivateNumber::bindNumber('15622137119', '15999944931'); | |
260 | - //{"Message":"OK","RequestId":"1EE31873-4053-44F5-B2B4-031ECC4671F7","Code":"OK","SecretBindDTO":{"Extension":"15999944931","SecretNo":"13143439849","SubsId":"974715743568877041"} | |
261 | - //echo json_encode($result); | |
262 | - echo "\r\n"; | |
263 | - | |
264 | - //$result = \common\exts\Aliyun\DYPLS\PrivateNumber::unbindSubscription('974715743568877041', '13143439849'); | |
265 | - //echo json_encode($result); | |
266 | - | |
267 | - //$result = \common\exts\Aliyun\DYPLS\PrivateNumber::querySubscriptionDetail('134915943835832737', '17097534251'); | |
268 | - //echo json_encode($result, JSON_UNESCAPED_UNICODE);echo "\r\n"; | |
269 | - | |
270 | - | |
271 | - //$result = \common\exts\Aliyun\DYPLS\PrivateNumber::queryRecordFileDownloadUrl("415c0511041a2151", date('Y-m-d H:i:s', 1543835908)); | |
272 | - //echo json_encode($result, JSON_UNESCAPED_UNICODE);echo "\r\n"; | |
273 | - //{"Message":"OK","RequestId":"7CFD87F7-1FA9-4EFE-BBCA-CCF4CB6F1FD4","DownloadUrl":"http:\/\/secret-axb-record-files.oss-cn-shanghai.aliyuncs.com\/134915943835832737_415c0511041a2151.mp3?Expires=1543843500&OSSAccessKeyId=LTAI27GqAW1VrcQA&Signature=eEATuKSQDIxUurnSuqghV09D3yE%3D","Code":"OK"} | |
274 | - } | |
275 | - | |
276 | - public function actionDeduction() | |
277 | - { | |
278 | - $repairOrderModel = RepairOrder::findOne(['uuid' => '4ba0976b7a0d3d16ae1de634a6201134']); | |
279 | - $activityModel = DeductionActivityRepository::getCurrentActivity(); | |
280 | - $repairOrderDeduction = RepairOrderDeduction::findOne([ | |
281 | - 'repair_order_id' => $repairOrderModel->id, | |
282 | - 'activity_id' => $activityModel->id, | |
283 | - ]); | |
284 | - | |
285 | - $expireTime = $activityModel->expired_time; | |
286 | - $re = Deduction::canDeduction($repairOrderDeduction, $repairOrderModel, $expireTime); | |
287 | - Deduction::setRiseVale($repairOrderModel, $expireTime); | |
288 | - if (0 == $re->errCode) { | |
289 | - echo $re->error."--1\r\n"; | |
290 | - return ; | |
291 | - } | |
292 | - $saveData = ['userTagId' => rand(1,4)]; | |
293 | - $clientUserId = 8; | |
294 | - $addResult = Deduction::addDeductionAmount($activityModel, $repairOrderModel, $clientUserId, $saveData); | |
295 | - echo $addResult->error."\r\n"; | |
296 | - } | |
297 | - | |
298 | - /** | |
299 | - * 初始化5元抵扣券 | |
300 | - */ | |
301 | - public function actionAddDe() | |
302 | - { | |
303 | - $repairOrderModel = RepairOrder::findOne(['uuid' => '4ba0976b7a0d3d16ae1de634a6201134']); | |
304 | - $activityModel = DeductionActivityRepository::getCurrentActivity(); | |
305 | - | |
306 | - $result = Deduction::initOrderDeduction($repairOrderModel, $activityModel->uuid); | |
307 | - if (1 == $result->errCode) { | |
308 | - echo "add ok\r\n"; | |
309 | - } else { | |
310 | - echo $result->error."\r\n"; | |
311 | - } | |
312 | - Deduction::getActivityInfoByOrderUUId('4ba0976b7a0d3d16ae1de634a6201134s'); | |
313 | - } | |
314 | - | |
315 | - public function actionGetFriends() | |
316 | - { | |
317 | - $result = Deduction::getRecords('9a4ba1dcae263f11893e707d733e3593', 4, 0); | |
318 | - print_r($result); | |
319 | - } | |
320 | - | |
321 | - public function actionDeductionPage() | |
322 | - { | |
323 | - $orderUUId = '';//$this->request->post('id'); | |
324 | - $e = new \stdClass(); | |
325 | - $e->success = true; | |
326 | - $e->canClick = true; | |
327 | - $e->selectedTagId = ''; | |
328 | - $e->clickResult = 0; | |
329 | - $batchInfo = Deduction::getBatchInfoByOrderUUId($orderUUId); | |
330 | - $orderModel = $batchInfo['orderModel']; | |
331 | - $repairOrderDeduction = $batchInfo['repairOrderDeduction']; | |
332 | - $deductionActivity = $batchInfo['deductionActivity']; | |
333 | - //$userId = $this->getUserId(); | |
334 | - $clientUserId = 15;//$this->getClientUserId(); | |
335 | - | |
336 | - $expireTime = $deductionActivity->expired_time; | |
337 | - $re = Deduction::canDeduction($repairOrderDeduction, $orderModel, $expireTime); | |
338 | - if (0 == $re->errCode) { | |
339 | - $e->canClick = false; | |
340 | - $e->error = $re->error; | |
341 | - } | |
342 | - $checkResult = Deduction::hasClickDeduction($repairOrderDeduction, $orderModel, $clientUserId); | |
343 | - if (0 == $checkResult->errCode) { | |
344 | - $e->canClick = false; | |
345 | - $e->selectedTagId = $checkResult->selectedTag; | |
346 | - $e->clickResult = Deduction::coverInt($checkResult->clickResult); | |
347 | - $e->error = $re->error; | |
348 | - } | |
349 | - if (isset($deductionActivity['share_img'])) { | |
350 | - $deductionActivity['share_img'] = ImageManager::getUrl($deductionActivity['share_img']); | |
351 | - } | |
352 | - $e->shareTitle = isset($deductionActivity['share_title'])? $deductionActivity['share_title']: '帮我砍价'; | |
353 | - $e->shareImg = $deductionActivity['share_img']; | |
354 | - $e->userTagList = Deduction::randomUserTag(9, $e->selectedTagId); | |
355 | - return $e; | |
356 | - } | |
357 | - | |
358 | - public function actionSendMina() | |
359 | - { | |
360 | - $str = 'M,,'; | |
361 | - $pattern = "/^[A-Z](,[A-Z])+?$/"; | |
362 | - //$pattern = "/^[A-Z]$/"; | |
363 | - $rs = preg_match($pattern, $str); | |
364 | - print_r($rs); | |
365 | - } | |
366 | - public function actionPEngineer() | |
367 | - { | |
368 | - //echo Utils::hidePhoneNumber('15622137119'); | |
369 | - | |
370 | - } | |
371 | - | |
372 | - public function actionWebSocket() | |
373 | - { | |
374 | - $to_uid = "123"; | |
375 | - // 推送的url地址,使用自己的服务器地址 | |
376 | - $push_api_url = "http://192.168.0.106:20211/"; | |
377 | - global $argv; | |
378 | - $toId = isset($argv[2])?$argv[2]:''; | |
379 | - $content = isset($argv[3])?$argv[3]:'test ing'; | |
380 | - | |
381 | - $newPost = []; | |
382 | - $newPost['username'] = '张小小'; | |
383 | - $newPost['message'] = $content; | |
384 | - | |
385 | - $post_data = array( | |
386 | - "type" => "publish", | |
387 | - "content" => json_encode($newPost), | |
388 | - "to" => $toId, | |
389 | - ); | |
390 | - Http::post($push_api_url, $post_data); | |
391 | - } | |
392 | - | |
393 | - | |
394 | - public function actionSub() | |
395 | - { | |
396 | - $sTime = time(); | |
397 | - echo "== start time 导入数据 == \r\n"; | |
398 | - $startTime = strtotime('2019-01-01'); | |
399 | - $endTime = strtotime(date('Y-m-d')); | |
400 | - for ($i = 0 ;$startTime < $endTime ; $i++) { | |
401 | - if ($i == 29) { | |
402 | - break; | |
403 | - } | |
404 | - $startTime = $startTime + (24 * 3600); | |
405 | - $isTime = time(); | |
406 | - EngineerTask::archiveAchievement($startTime, false); | |
407 | - $ieTime = time(); | |
408 | - $sec = $ieTime - $isTime; | |
409 | - echo "date:".date('Y-m-d', $startTime) .' cost time:'. $sec ."\r\n"; | |
410 | - } | |
411 | - | |
412 | - } | |
413 | - | |
414 | - | |
415 | - public function actionSt() | |
416 | - { | |
417 | - $orders = $this->getOrdersInfo(); | |
418 | - $prefers = $this->getPreferList(); | |
419 | - | |
420 | - $round0 = 0; | |
421 | - $firstRound = 0; | |
422 | - $secondRound = 0; | |
423 | - $thriRound = 0; | |
424 | - $round4 = 0; | |
425 | - $round5 = 0; | |
426 | - $round6 = 0; | |
427 | - $round7 = 0; | |
428 | - $dispatchCount = 0; | |
429 | - $onSiteCount = 0; | |
430 | - $normalCount = 0; | |
431 | - foreach ($orders as $k => $order) { | |
432 | - $engineerIds = $prefers['user_id_'.$order['user_id']]; | |
433 | - $dispatchRecordsModel = RepairOrderDispatchRecords::find(); | |
434 | - $dispatchRecordsModel->where(['repair_order_id' => $order['id'] ]); | |
435 | - $dispatchRecordsModel->asArray(); | |
436 | - $findResult = $dispatchRecordsModel->all(); | |
437 | - $dispatchCount = $dispatchCount + count($findResult); | |
438 | - echo $order['id'].' ccccount:'.count($findResult)."----\r\n"; | |
439 | - if (empty($findResult)) { | |
440 | - $onSiteCount ++; | |
441 | - } else { | |
442 | - $normalCount++; | |
443 | - } | |
444 | - if (empty($findResult)) { | |
445 | - continue; | |
446 | - } | |
447 | - $orderFlag = 0; | |
448 | - foreach ($findResult as $kk => $vv) { | |
449 | - if (0 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) { | |
450 | - $round0++; | |
451 | - $orderFlag = true; | |
452 | - } | |
453 | - if (1 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) { | |
454 | - $firstRound++;$orderFlag = true; | |
455 | - } | |
456 | - if (2 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) { | |
457 | - $secondRound++;$orderFlag = true; | |
458 | - } | |
459 | - if (3 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) { | |
460 | - $thriRound++;$orderFlag = true; | |
461 | - } | |
462 | - if (4 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) { | |
463 | - $round4++;$orderFlag = true; | |
464 | - } | |
465 | - if (5 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) { | |
466 | - $round5++;$orderFlag = true; | |
467 | - } | |
468 | - if (6 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) { | |
469 | - $round6++;$orderFlag = true; | |
470 | - } | |
471 | - if (7 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) { | |
472 | - $round7++;$orderFlag = true; | |
473 | - } | |
474 | - } | |
475 | - if (false == $orderFlag ) { | |
476 | - echo "null:".$order['id']."\r\n"; | |
477 | - } | |
478 | - } | |
479 | - echo "dispatchCount:".$dispatchCount."\r\n"; | |
480 | - echo "onSiteCount:".$onSiteCount.' normalCount:'.$normalCount."\r\n"; | |
481 | - echo $round0.'_'.$firstRound.'_'.$secondRound.'_'.$thriRound.'_'.$round4.'_'.$round5.'_'.$round6.'_'.$round7; | |
482 | - } | |
483 | - | |
484 | - | |
485 | - /** | |
486 | - * 临时提交电子发票申请 | |
487 | - * @return string | |
488 | - */ | |
489 | - public function actionCreateInvoice() | |
490 | - { | |
491 | - $orderModel = RepairOrder::findOne(['order_no' => '201904241505438057' ]); | |
492 | - if (empty($orderModel)) { | |
493 | - echo "open invoice fail: repair order is null "; | |
494 | - return false; | |
495 | - } | |
496 | - // 只是开一单一票 | |
497 | - $info = [ | |
498 | - 'user_id' => $orderModel->user_id, | |
499 | - 'type' => Invoice::HEAD_TYPE_COMPANY, | |
500 | - 'head' => '深圳市星康科技有限公司', | |
501 | - 'taxpayer_id_number' => '91440300319568546J', | |
502 | - 'email' => 'perelmen@qq.com', | |
503 | - 'remark' => '订单号:201904241505438057', | |
504 | - 'register_address' => '', | |
505 | - 'register_tel' => '', | |
506 | - 'bank' => '', | |
507 | - 'bank_account' => '', | |
508 | - 'amount' => 329.20, | |
509 | - 'selectOrders' => [$orderModel->uuid] | |
510 | - ]; | |
511 | - $result = \domain\trade\Invoice::createInvoice($info); | |
512 | - echo json_encode($result); | |
513 | - } | |
514 | - | |
515 | - /** | |
516 | - * 直接开票,不要用记录到数据库里面,有些商品要开票,直接开票发送总局软件那里, | |
517 | - * 先发邮件到自己邮箱再发pdf 给客户 | |
518 | - */ | |
519 | - public function actionInvoiceStraight() | |
520 | - { | |
521 | - $amount = 20; //开票金额 | |
522 | - $sid = 'sg'.date('YmdHis').mt_rand(1000,9999); | |
523 | - $customerInfo = array( | |
524 | - 'ghdwsbh' => '', //公司纳税人识别码 | |
525 | - 'ghdwmc' => '许可', //抬头 | |
526 | - 'email' => 'perelmen@qq.com', | |
527 | - 'ghdwdzdh' => '', //'购货单位地址、电话' | |
528 | - 'ghdwyhzh' => '', //'购货单位开户行、银行帐号' | |
529 | - 'bz' => 'A4纸1箱' //备注 | |
530 | - ); | |
531 | - $serviceInfo = InvoiceApi::getGoodsCode(InvoiceApi::A4_PAPER_INVOICE); | |
532 | - $queryResult = InvoiceApi::makeOutAnInvoice($sid, $amount, $serviceInfo, $customerInfo); | |
533 | - var_dump($queryResult); | |
534 | - sleep(4); | |
535 | - echo "query1:"; | |
536 | - $queryResult = InvoiceApi::queryInvoice($sid); | |
537 | - var_dump($queryResult); | |
538 | - sleep(5); | |
539 | - echo "query2:"; | |
540 | - $queryResult = InvoiceApi::queryInvoice($sid); | |
541 | - var_dump($queryResult); | |
542 | - echo "end"; | |
543 | - | |
544 | - } | |
545 | - | |
546 | - public function actionExportD() | |
547 | - { | |
548 | - $postId = date('Ymd0001'); | |
549 | - $query = new Query(); | |
550 | - $query->select("repair_order.order_no,repair_order.repair_device_name as device, GROUP_CONCAT(device_fault.`name`) as faults, | |
551 | - | |
552 | - parent_device_cat.name as keyword, | |
553 | - brand.chinese_name as brand"); | |
554 | - $query->from("repair_order_repair_plans"); | |
555 | - $query->leftJoin("repair_order","repair_order.id = repair_order_repair_plans.repair_order_id and repair_order.repair_device_type = 1"); | |
556 | - $query->leftJoin("repair_order_detail","repair_order_detail.repair_order_id = repair_order_repair_plans.repair_order_id and repair_order_detail.pay_at > 0"); | |
557 | - $query->leftJoin("repair_plan","repair_plan.id = repair_order_repair_plans.repair_plan_id"); | |
558 | - $query->leftJoin("device_fault","device_fault.id = repair_plan.device_fault_id"); | |
559 | - $query->leftJoin("engineer_profile","engineer_profile.engineer_id = repair_order.engineer_id"); | |
560 | - | |
561 | - $query->leftJoin("user_device","user_device.id = repair_order.repair_device_id"); | |
562 | - $query->leftJoin("device","device.id = user_device.device_id"); | |
563 | - $query->leftJoin("model","model.id = device.model_id"); | |
564 | - $query->leftJoin("brand","brand.id = model.brand_id"); | |
565 | - $query->leftJoin("device_cat","device_cat.id = device.device_cat_id"); | |
566 | - $query->leftJoin("device_cat as parent_device_cat","parent_device_cat.id = device_cat.parent_id"); | |
567 | - $query->where("repair_order.is_system_delete = 0 and repair_order.pay_price > 0 and repair_order.repair_device_type = 1"); | |
568 | - $query->andWhere("repair_order.created_at > UNIX_TIMESTAMP('2019-01-01')"); | |
569 | - //$query->limit(3); | |
570 | - $query->groupBy("repair_order.order_no"); | |
571 | - $items = $query->all(); | |
572 | - | |
573 | - $totalCount = count($items); | |
574 | - $postItemsTmp = []; | |
575 | - foreach($items as $k => $item) { | |
576 | - unset($item['order_no']); | |
577 | - $key = $item['device'].'_'.$item['faults'].'_'.$item['keyword'].'_'.$item['brand']; | |
578 | - $postItemsTmp[$key] = $item; | |
579 | - } | |
580 | - $postItems = []; | |
581 | - foreach($postItemsTmp as $k => $vv) { | |
582 | - $vv['keyword'] = $vv['keyword'].'维修'; | |
583 | - $postItems[] = $vv; | |
584 | - } | |
585 | - | |
586 | - $dataStr = [ | |
587 | - "items" => $postItems, | |
588 | - "attribute" => [ "count" => $totalCount, "totalcount" => $totalCount, "id" => $postId, "seq" => 0] | |
589 | - ]; | |
590 | - | |
591 | - $postDataStr = json_encode($dataStr, JSON_UNESCAPED_UNICODE); | |
592 | - $postDataStr = str_replace('\/', '/', $postDataStr); | |
593 | - | |
594 | - $postData = [ | |
595 | - "data" => $postDataStr, | |
596 | - "lifespan" => 86400, | |
597 | - "query" => "{\"type\":1000078}", | |
598 | - "scene" => 1 | |
599 | - ]; | |
600 | - echo json_encode($postData, JSON_UNESCAPED_UNICODE); | |
601 | - | |
602 | - } | |
603 | - | |
604 | - public function actionTV() | |
605 | - { | |
606 | - $repairOrderModel = RepairOrder::find(); | |
607 | - $repairOrderModel->alias('ro'); | |
608 | - $repairOrderModel->select('count(*) as cc,GROUP_CONCAT(ro.created_at) as cr, ro.repair_device_id'); | |
609 | - $repairOrderModel->leftJoin('repair_order_detail rod', 'rod.repair_order_id = ro.id'); | |
610 | - $repairOrderModel->where('ro.repair_device_type = 1 and rod.pay_at >0 and ro.is_system_delete = 0'); | |
611 | - $repairOrderModel->groupBy('ro.repair_device_id'); | |
612 | - $repairOrderModel->having('cc >=2'); | |
613 | - $repairOrderModel->asArray(); | |
614 | - $repairOrderArr = $repairOrderModel->all(); | |
615 | - //print_r($repairOrderArr); | |
616 | - foreach($repairOrderArr as $k => $order) { | |
617 | - $timeArr = explode(',', $order['cr']); | |
618 | - sort($timeArr); | |
619 | - $timeDuration = []; | |
620 | - foreach($timeArr as $kk => $vv) { | |
621 | - if (isset($timeArr[$kk + 1])) { | |
622 | - $durationSecond = 0 - ($vv - $timeArr[$kk + 1]); | |
623 | - | |
624 | - if ($durationSecond<60) { | |
625 | - $sDur = $durationSecond. '秒'; | |
626 | - } elseif($durationSecond >= 60 && $durationSecond < 3600) { | |
627 | - $sDur = (round($durationSecond /60, 1)). '分'; | |
628 | - } elseif($durationSecond >= 3600 && $durationSecond < 86400){ | |
629 | - $sDur = (round($durationSecond /3600, 1)). '时'; | |
630 | - } elseif($durationSecond >= 86400 && $durationSecond < 604800) { | |
631 | - $sDur = (round($durationSecond /(3600*24), 1)). '天'; | |
632 | - } else { | |
633 | - $sDur = (round($durationSecond /(3600*24*7), 1)). '周'; | |
634 | - } | |
635 | - $timeDuration[] = $sDur; | |
636 | - } | |
637 | - } | |
638 | - $order['durations'] = implode(',', $timeDuration); | |
639 | - $repairOrderArr[$k] = $order; | |
640 | - //echo $order['cc'].'_'.$order['repair_device_id'].'_'.$order['durations']."\r\n"; | |
641 | - } | |
642 | - | |
643 | - $arr = [19,39,40]; | |
644 | - sort($arr); | |
645 | - print_r($arr); | |
646 | - | |
647 | - } | |
648 | - | |
649 | - public function actionSetPostData() | |
650 | - { | |
651 | - $str = ''; | |
652 | - | |
653 | - $postPackageId = 'D'.date('Ymd').'0000001'; | |
654 | - $postPackage = [ | |
655 | - "lifespan" => 86400, | |
656 | - "query" => "{\"type\":1000078}", | |
657 | - "scene" => 1, | |
658 | - "data" => "", | |
659 | - ]; | |
660 | - | |
661 | - $packageAttribute = [ | |
662 | - "count" => '', | |
663 | - "totalcount" => 100, | |
664 | - "id" => $postPackageId, | |
665 | - "seq" => 0 | |
666 | - | |
667 | - ]; | |
668 | - | |
669 | - $index = 0; | |
670 | - $keywords = ["打印机维修","复印机维修","电脑维修","Mac电脑维修","加碳粉","换墨盒","重装系统","上门维修打印机","上门维修电脑","上门维修复印机","电脑蓝屏","无法使用扫描","打印机无法开机","无法打印","打印效果差","打印卡纸","设备未共享","设备未安装","缺粉","打印颜色淡","打印不清晰","打印模糊","传真或扫描模糊","纸张进纸故障","无法上纸","换主板","换内存","色带用尽","键盘损坏","触摸板失灵","电池鼓包","电池不耐用","无法充电","风扇噪音大","屏幕外壳变形","设备无法开机","无法使用传真","墨水不足","屏幕按键失灵","外壳磨损变形","内屏损坏无显示","闪屏","花屏","碎屏","USB无法使用","上门安装电脑","黑屏","安装软件","安装驱动","无法上网","运行速度慢","忘记系统密码","无法登陆系统","无法连接投影仪","未知故障","复印效果差","无法发送邮件","无法共享打印机","无法打开文件","提示C盘空间不足","办公软件无法使用","无法使用拼音","浏览器无法播放视频","电脑中毒","键盘按键无反应","无法打开office文件","深圳修电脑","深圳修打印机","深圳修复印机","加墨水","福田修电脑","福田修打印机","福田修复印机","修佳能打印机","修惠普打印机","修京瓷打印机","修联想笔记本","修苹果笔记本","修爱普生打印机","喷墨打印机维修","换打印纸","维修三星打印机","针式打印机维修","激光打印机维修","喷墨打印机维修","黑白打印机维修","彩色复印维修","漏墨","复印机闪灯","复印无法联网"]; | |
671 | - $pageList = []; | |
672 | - foreach($keywords as $k => $v) { | |
673 | - $pageList[] = ["keyword" => $v]; | |
674 | - } | |
675 | - $totalcount = count($keywords); | |
676 | - $postRound = 0; | |
677 | - | |
678 | - //"attribute" => [ | |
679 | - $packageAttribute['count'] = $totalcount; | |
680 | - $packageAttribute['totalcount'] = $totalcount; | |
681 | - $packageAttribute['seq'] = $postRound; | |
682 | - | |
683 | - $postPackage['data'] = json_encode(["items" => $pageList, "attribute" => $packageAttribute], JSON_UNESCAPED_UNICODE); | |
684 | - $postPackage['data'] = str_replace('\/', '/', $postPackage['data']); | |
685 | - $postWxStr = json_encode($postPackage, JSON_UNESCAPED_UNICODE); | |
686 | - echo $postWxStr; | |
687 | - echo "\r\n"; | |
688 | - $minaWechat = MinaHelper::getWxPHPSDK(); | |
689 | - $result = $minaWechat->setDynamicData($postWxStr); | |
690 | - print_r($result); | |
691 | - echo $minaWechat->errCode."\r\n"; | |
692 | - echo $minaWechat->errMsg; | |
693 | - echo "\r\n"; | |
694 | - | |
695 | - } | |
696 | - | |
697 | - /** | |
698 | - * 贴码补贴发放 | |
699 | - * @return bool | |
700 | - */ | |
701 | - public function actionPasteAward() | |
702 | - { | |
703 | - $bindDeviceApplyFind = BindDeviceApply::find(); | |
704 | - $bindDeviceApplyFind->where("apply_at > UNIX_TIMESTAMP('2019-08-01') and apply_at <= UNIX_TIMESTAMP('2019-08-21') and status = 1 and id = 209227"); | |
705 | - $applyArr = $bindDeviceApplyFind->all(); | |
706 | - foreach ($applyArr as $k => $apply) { | |
707 | - $engineerModel = Engineer::findOne(['id' => $apply->engineer_id]); | |
708 | - $result = ApplyAwardRule::canReceivePasteAward($apply, $engineerModel); | |
709 | - //AppLog::DEBUG('= engineerAddPasteAward =result:'.$result); | |
710 | - if ($result) { | |
711 | - $addR = ApplyAwardRule::addPasteAward($apply, strtotime('2019-08-10 00:00:54')); | |
712 | - return $addR; | |
713 | - } | |
714 | - } | |
715 | - } | |
716 | - public function actionUserConfirmPrice() | |
717 | - { | |
718 | - $orderModel = RepairOrderRepository::findOne(['uuid' => '72c7fd2bb0003bcf8bd55caf3a90ab7b']); | |
719 | - $userId = $orderModel->user_id; | |
720 | - $success = PrivateOrderUserOp::confirmPrice($orderModel, $userId, 0, 0); | |
721 | - echo 'end'; | |
722 | - } | |
723 | - | |
724 | - public function actionClearLog() | |
725 | - { | |
726 | - $str = 'OKI 打印机'; | |
727 | - $splitResult = DeviceSearch::splitText($str); | |
728 | - print_r($splitResult); | |
729 | - } | |
730 | - | |
75 | + public function actionGen() | |
76 | + { | |
77 | + echo sprintf('%04x', 1); | |
78 | + } | |
731 | 79 | |
732 | 80 | |
733 | 81 | } | ... | ... |
domain/Device.php
domain/DeviceRepository.php
... | ... | @@ -1,50 +0,0 @@ |
1 | -<?php | |
2 | - | |
3 | -namespace domain; | |
4 | - | |
5 | -use domain\models\Device as DeviceModel; | |
6 | - | |
7 | -class DeviceRepository | |
8 | -{ | |
9 | - /** | |
10 | - * @param $where | |
11 | - * @return array|\yii\db\ActiveRecord[] | |
12 | - */ | |
13 | - static function getList($where, $limit = 0, $offset = 0) | |
14 | - { | |
15 | - $deviceFind = DeviceModel::find(); | |
16 | - $deviceFind->where($where); | |
17 | - $deviceFind->asArray(); | |
18 | - if ($offset) { | |
19 | - $deviceFind->offset($offset); | |
20 | - } | |
21 | - if ($limit) { | |
22 | - $deviceFind->limit($limit); | |
23 | - } | |
24 | - $all = $deviceFind->all(); | |
25 | - | |
26 | - return $all; | |
27 | - } | |
28 | - | |
29 | - /** | |
30 | - * @param $where | |
31 | - * @return int|string | |
32 | - */ | |
33 | - static function getListCount($where) | |
34 | - { | |
35 | - $deviceFind = DeviceModel::find(); | |
36 | - $deviceFind->where($where); | |
37 | - $all = $deviceFind->count(); | |
38 | - | |
39 | - return $all; | |
40 | - } | |
41 | - | |
42 | - /** | |
43 | - * @param $id | |
44 | - * @return null|static | |
45 | - */ | |
46 | - static function selectOne($id) | |
47 | - { | |
48 | - return DeviceModel::findOne($id); | |
49 | - } | |
50 | -} | |
51 | 0 | \ No newline at end of file |
domain/DeviceStatus.php
... | ... | @@ -1,33 +0,0 @@ |
1 | -<?php | |
2 | - | |
3 | -namespace domain; | |
4 | - | |
5 | - | |
6 | -class DeviceStatus | |
7 | -{ | |
8 | - const NO_AUTH = 0; //未授权, | |
9 | - const HAS_AUTH = 1; //已授权, | |
10 | - const FAIL_AUTH = 2; //授权失败 | |
11 | - | |
12 | - /** | |
13 | - * @param string $index | |
14 | - * @return array|string | |
15 | - */ | |
16 | - static function statusLabels($index = '') | |
17 | - { | |
18 | - $arr = [ | |
19 | - self::NO_AUTH => '未授权', | |
20 | - self::HAS_AUTH => '已授权', | |
21 | - self::FAIL_AUTH => '授权失败', | |
22 | - ]; | |
23 | - if ('' === $index) { | |
24 | - return $arr; | |
25 | - } | |
26 | - | |
27 | - if (isset($arr[$index])) { | |
28 | - return $arr[$index]; | |
29 | - } else { | |
30 | - return ''; | |
31 | - } | |
32 | - } | |
33 | -} | |
34 | 0 | \ No newline at end of file |
... | ... | @@ -0,0 +1,32 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace domain\device; | |
4 | + | |
5 | +use Yii; | |
6 | +use domain\device\models\CreateBatch as CreateBatchModel; | |
7 | + | |
8 | +class CreateBatch | |
9 | +{ | |
10 | + /** | |
11 | + * @param $item | |
12 | + * @return null|object | |
13 | + * @throws \yii\base\InvalidConfigException | |
14 | + */ | |
15 | + static function create($item) | |
16 | + { | |
17 | + $createBatch = Yii::createObject([ | |
18 | + 'class' => CreateBatchModel::className(), | |
19 | + 'batch_no' => $item['batch_no'], | |
20 | + 'manufacture_id' => $item['manufacture_id'], | |
21 | + 'project_id' => $item['project_id'], | |
22 | + 'model_id' => $item['model_id'], | |
23 | + 'num' => $item['num'], | |
24 | + 'production_id' => $item['production_id'], | |
25 | + ]); | |
26 | + if ($createBatch->save()) { | |
27 | + return $createBatch; | |
28 | + } else { | |
29 | + return null; | |
30 | + } | |
31 | + } | |
32 | +} | |
0 | 33 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,67 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace domain\device; | |
4 | + | |
5 | +use domain\device\models\CreateBatch as CreateBatchModel; | |
6 | +use yii\db\Query; | |
7 | + | |
8 | +class CreateBatchRepository | |
9 | +{ | |
10 | + /** | |
11 | + * @param $condition | |
12 | + * @return null|static | |
13 | + */ | |
14 | + static function findOne($condition) | |
15 | + { | |
16 | + return CreateBatchModel::findOne($condition); | |
17 | + } | |
18 | + | |
19 | + /** | |
20 | + * @param $type | |
21 | + * @param $keyword | |
22 | + * @return array | |
23 | + */ | |
24 | + static function getSerialNoComponent($type, $keyword) | |
25 | + { | |
26 | + if ('manufacture' == $type) { | |
27 | + $q = new Query(); | |
28 | + $q->select('id,manufacture_no, name'); | |
29 | + $q->from('manufacture'); | |
30 | + $q->where('name like "%'.$keyword.'%" or manufacture_no like "%'.$keyword.'%"'); | |
31 | + $q->limit(20); | |
32 | + $list = $q->all(); | |
33 | + | |
34 | + return $list; | |
35 | + } elseif('project' == $type) { | |
36 | + $q = new Query(); | |
37 | + $q->select('id,project_no, name'); | |
38 | + $q->from('project'); | |
39 | + $q->where('name like "%'.$keyword.'%" or project_no like "%'.$keyword.'%"'); | |
40 | + $q->limit(20); | |
41 | + $list = $q->all(); | |
42 | + | |
43 | + return $list; | |
44 | + } elseif ('model' == $type) { | |
45 | + $q = new Query(); | |
46 | + $q->select('id,model_no, name'); | |
47 | + $q->from('model'); | |
48 | + $q->where('name like "%'.$keyword.'%" or model_no like "%'.$keyword.'%"'); | |
49 | + $q->limit(20); | |
50 | + $list = $q->all(); | |
51 | + | |
52 | + return $list; | |
53 | + } elseif ('production' == $type) { | |
54 | + $q = new Query(); | |
55 | + $q->select('id,production_no, name'); | |
56 | + $q->from('production'); | |
57 | + $q->where('name like "%'.$keyword.'%" or production_no like "%'.$keyword.'%"'); | |
58 | + $q->limit(20); | |
59 | + $list = $q->all(); | |
60 | + | |
61 | + return $list; | |
62 | + } else { | |
63 | + return []; | |
64 | + } | |
65 | + } | |
66 | + | |
67 | +} | |
0 | 68 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,78 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace domain\device; | |
4 | + | |
5 | +use stdClass; | |
6 | +class Device | |
7 | +{ | |
8 | + /** | |
9 | + * 序列号前缀,也是batchNo | |
10 | + * @param $manufacture | |
11 | + * @param $project | |
12 | + * @param $model | |
13 | + * @param $production | |
14 | + * @return string | |
15 | + */ | |
16 | + static function getBatchNo($manufacture, $project, $model, $production) | |
17 | + { | |
18 | + return $manufacture. $project. $model. $production; | |
19 | + } | |
20 | + | |
21 | + /** | |
22 | + * @param $deviceId | |
23 | + * @param $manufactureNo | |
24 | + * @param $projectNo | |
25 | + * @param $modelNo | |
26 | + * @param $productionNo | |
27 | + * @return stdClass | |
28 | + */ | |
29 | + static function authDevice($deviceId, $manufactureNo, $projectNo, $modelNo, $productionNo) | |
30 | + { | |
31 | + $e = new stdClass(); | |
32 | + $e->success = false; | |
33 | + $e->message = ''; | |
34 | + $e->serial_no = ''; | |
35 | + $e->mac = ''; | |
36 | + $tt = time(); | |
37 | + $batchNo = self::getBatchNo($manufactureNo, $projectNo, $modelNo, $productionNo); | |
38 | + $batchModel = CreateBatchRepository::findOne(['batch_no' => $batchNo]); | |
39 | + if (empty($batchModel)) { | |
40 | + $e->message = '没有该批次'; | |
41 | + } | |
42 | + $count = DeviceRepository::rowsCount(['batch_id' => $batchModel->batch_id, 'is_delete' => 0]); | |
43 | + if ($count > $batchModel->num) { | |
44 | + // 超过了限制数,记录到另外一个表里面 | |
45 | + // to do 记录到表里面 | |
46 | + | |
47 | + $e->message = '授权失败'; | |
48 | + return $e; | |
49 | + } | |
50 | + $deviceModel = DeviceRepository::findOne(['device_id' => $deviceId, 'is_delete' => 0]); | |
51 | + if (empty($deviceModel)) { | |
52 | + $newDeviceModel = DeviceRepository::findOne(['device_id'=> null, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]); | |
53 | + $newDeviceModel->device_id = $deviceId; | |
54 | + $newDeviceModel->status = DeviceStatus::HAS_AUTH; | |
55 | + $newDeviceModel->apply_at = $tt ; | |
56 | + $newDeviceModel->auth_at = $tt; | |
57 | + $newDeviceModel->save(); | |
58 | + $e->message = '授权成功'; | |
59 | + $e->success = true; | |
60 | + $e->serial_no = $newDeviceModel->serial_no; | |
61 | + $e->mac = $newDeviceModel->mac; | |
62 | + | |
63 | + return $e; | |
64 | + } | |
65 | + if (DeviceStatus::HAS_AUTH == $deviceModel->status) { | |
66 | + $e->message = '授权成功'; | |
67 | + $e->success = true; | |
68 | + $e->serial_no = $deviceModel->serial_no; | |
69 | + $e->mac = $deviceModel->mac; | |
70 | + } elseif (DeviceStatus::FAIL_AUTH == $deviceModel->status) { | |
71 | + $e->message = '授权失败'; | |
72 | + } else { | |
73 | + $e->message = '授权失败!'; | |
74 | + } | |
75 | + | |
76 | + return $e; | |
77 | + } | |
78 | +} | |
0 | 79 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,89 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace domain\device; | |
4 | + | |
5 | +use domain\device\models\CreateBatch as CreateBatchModel; | |
6 | +use domain\device\models\Device as DeviceModel; | |
7 | + | |
8 | +class DeviceRepository | |
9 | +{ | |
10 | + /** | |
11 | + * @param $where | |
12 | + * @return array|\yii\db\ActiveRecord[] | |
13 | + */ | |
14 | + static function getList($where, $limit = 0, $offset = 0) | |
15 | + { | |
16 | + $deviceFind = DeviceModel::find(); | |
17 | + $deviceFind->alias('a'); | |
18 | + $deviceFind->select(['a.*', 'm.name as manufacture','p.name as project','pd.name as production','mo.name as model']); | |
19 | + $deviceFind->leftJoin(CreateBatchModel::tableName().' b','b.id = a.batch_id'); | |
20 | + $deviceFind->leftJoin('manufacture as m', 'm.id = b.manufacture_id'); | |
21 | + $deviceFind->leftJoin('project as p', 'p.id = b.project_id'); | |
22 | + $deviceFind->leftJoin('model as mo', 'mo.id = b.model_id'); | |
23 | + $deviceFind->leftJoin('production as pd', 'pd.id = b.production_id'); | |
24 | + | |
25 | + $deviceFind->where($where); | |
26 | + $deviceFind->asArray(); | |
27 | + if ($offset) { | |
28 | + $deviceFind->offset($offset); | |
29 | + } | |
30 | + if ($limit) { | |
31 | + $deviceFind->limit($limit); | |
32 | + } | |
33 | + $all = $deviceFind->all(); | |
34 | + | |
35 | + return $all; | |
36 | + } | |
37 | + | |
38 | + /** | |
39 | + * @param $where | |
40 | + * @return int|string | |
41 | + */ | |
42 | + static function getListCount($where) | |
43 | + { | |
44 | + $deviceFind = DeviceModel::find(); | |
45 | + $deviceFind->alias('a'); | |
46 | + $deviceFind->leftJoin(CreateBatchModel::tableName().' b','b.id = a.batch_id'); | |
47 | + $deviceFind->leftJoin('manufacture as m', 'm.id = b.manufacture_id'); | |
48 | + $deviceFind->leftJoin('project as p', 'p.id = b.project_id'); | |
49 | + $deviceFind->leftJoin('model as mo', 'mo.id = b.model_id'); | |
50 | + $deviceFind->leftJoin('production as pd', 'pd.id = b.production_id'); | |
51 | + $deviceFind->where($where); | |
52 | + $all = $deviceFind->count(); | |
53 | + | |
54 | + return $all; | |
55 | + } | |
56 | + | |
57 | + /** | |
58 | + * @param $condition | |
59 | + * @return null|static | |
60 | + */ | |
61 | + static function findOne($condition) | |
62 | + { | |
63 | + return DeviceModel::findOne($condition); | |
64 | + } | |
65 | + | |
66 | + /** | |
67 | + * @param $condition | |
68 | + * @return array|\yii\db\ActiveRecord[] | |
69 | + */ | |
70 | + static function findAll($condition) | |
71 | + { | |
72 | + $deviceModel = DeviceModel::find(); | |
73 | + $deviceModel->where($condition); | |
74 | + $list = $deviceModel->all(); | |
75 | + return $list; | |
76 | + } | |
77 | + | |
78 | + /** | |
79 | + * @param $condition | |
80 | + * @return int|string | |
81 | + */ | |
82 | + static function rowsCount($condition) | |
83 | + { | |
84 | + $deviceModel = DeviceModel::find(); | |
85 | + $deviceModel->where($condition); | |
86 | + $count = $deviceModel->count(); | |
87 | + return $count; | |
88 | + } | |
89 | +} | |
0 | 90 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,33 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace domain\device; | |
4 | + | |
5 | + | |
6 | +class DeviceStatus | |
7 | +{ | |
8 | + const NO_AUTH = 0; //未授权, | |
9 | + const HAS_AUTH = 1; //已授权, | |
10 | + const FAIL_AUTH = 2; //授权失败 | |
11 | + | |
12 | + /** | |
13 | + * @param string $index | |
14 | + * @return array|string | |
15 | + */ | |
16 | + static function statusLabels($index = '') | |
17 | + { | |
18 | + $arr = [ | |
19 | + self::NO_AUTH => '未授权', | |
20 | + self::HAS_AUTH => '已授权', | |
21 | + self::FAIL_AUTH => '授权失败', | |
22 | + ]; | |
23 | + if ('' === $index) { | |
24 | + return $arr; | |
25 | + } | |
26 | + | |
27 | + if (isset($arr[$index])) { | |
28 | + return $arr[$index]; | |
29 | + } else { | |
30 | + return ''; | |
31 | + } | |
32 | + } | |
33 | +} | |
0 | 34 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,28 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace domain\device\models; | |
4 | + | |
5 | +use yii\behaviors\TimestampBehavior; | |
6 | +use yii\db\ActiveRecord; | |
7 | + | |
8 | +class CreateBatch extends ActiveRecord | |
9 | +{ | |
10 | + /** | |
11 | + * @inheritdoc | |
12 | + */ | |
13 | + public static function tableName() | |
14 | + { | |
15 | + return '{{%create_batch}}'; | |
16 | + } | |
17 | + | |
18 | + public function behaviors() | |
19 | + { | |
20 | + return [ | |
21 | + 'time' => [ | |
22 | + 'class' => TimestampBehavior::className(), | |
23 | + 'createdAtAttribute' => 'created_at', | |
24 | + 'updatedAtAttribute' => 'updated_at', | |
25 | + ] | |
26 | + ]; | |
27 | + } | |
28 | +} | |
0 | 29 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace domain\device\models; | |
4 | + | |
5 | +use yii\behaviors\TimestampBehavior; | |
6 | +use yii\db\ActiveRecord; | |
7 | + | |
8 | +class Device extends ActiveRecord | |
9 | +{ | |
10 | + /** | |
11 | + * @inheritdoc | |
12 | + */ | |
13 | + public static function tableName() | |
14 | + { | |
15 | + return '{{%device}}'; | |
16 | + } | |
17 | + | |
18 | + /** | |
19 | + * 乐观锁使用版本号字段 | |
20 | + * @return string | |
21 | + */ | |
22 | + public function optimisticLock() | |
23 | + { | |
24 | + return 'ver'; | |
25 | + } | |
26 | + | |
27 | + public function behaviors() | |
28 | + { | |
29 | + return [ | |
30 | + 'time' => [ | |
31 | + 'class' => TimestampBehavior::className(), | |
32 | + 'createdAtAttribute' => 'created_at', | |
33 | + 'updatedAtAttribute' => 'updated_at', | |
34 | + ] | |
35 | + ]; | |
36 | + } | |
37 | +} | |
0 | 38 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,28 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace domain\device\models; | |
4 | + | |
5 | +use yii\behaviors\TimestampBehavior; | |
6 | +use yii\db\ActiveRecord; | |
7 | + | |
8 | +class DeviceAuthFail extends ActiveRecord | |
9 | +{ | |
10 | + /** | |
11 | + * @inheritdoc | |
12 | + */ | |
13 | + public static function tableName() | |
14 | + { | |
15 | + return '{{%device_auth_fail}}'; | |
16 | + } | |
17 | + | |
18 | + public function behaviors() | |
19 | + { | |
20 | + return [ | |
21 | + 'time' => [ | |
22 | + 'class' => TimestampBehavior::className(), | |
23 | + 'createdAtAttribute' => 'created_at', | |
24 | + 'updatedAtAttribute' => 'updated_at', | |
25 | + ] | |
26 | + ]; | |
27 | + } | |
28 | +} | |
0 | 29 | \ No newline at end of file | ... | ... |
domain/models/Device.php