SupportController.php
12.3 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<?php
namespace app\wx\controllers;
use Yii;
use yii\helpers\Html;
use common\exts\qqmap\QQMapSDK;
use common\helpers\FileHelper;
use common\helpers\Log as AppLog;
use common\helpers\Utils;
use common\helpers\WxHelper;
use common\models\BindDeviceApplyImg as BindDeviceApplyImgModel;
use common\models\Address as AddressModel;
use common\models\Engineer as EngineerModel;
use stdClass;
use function json_decode;
class SupportController extends BaseController
{
public function actionIndex(){
echo "index";
}
public function actionTest()
{
return $this->render('/site/test.php');
}
/**
* 获取地图坐标
* @return string
*/
public function actionGetMapInfo()
{
$lat= $this->request->post('lat');
$lng= $this->request->post('lng');
if (empty($lat) ||empty($lng)) {
return $this->renderJSON(null);
}
$res = QQMapSDK::getMapInfo(QQMapSDK::QQMAP_KEY_TYPE_ENGINEER, $lat, $lng, 1);
exit($res);
}
/** 更新工程师地址
* @return string
*/
public function actionUpdateAddress()
{
$sign = $this->request->get('sign');
$openid = $this->request->get('openid');
$tt = $this->request->get('time');
$location = $this->request->get('location');
$updateType = $this->request->get('updateType');
$address = $this->request->get('address');
$e = new stdClass();
$e->success = false;
$pars = $this->request->get();
AppLog::DEBUG('pars:'. json_encode($pars));
if (!Utils::checkSign($sign, $pars)) {
AppLog::DEBUG('update address signError');
exit();
}
if (empty($location) || !isset($location['x']) || empty($location['x'])) {
$e->msg = '参数为空!';
return $this->renderJson($e);
}
// 这里应该改为兼容 engineer id
$query = EngineerModel::find()
->select(['engineer.*'])
->where(['engineer.openid' => $openid]);
$query->asArray();
$userArray = $query->one();
if ($userArray) {
if ('service' == $updateType) {
$updateFlag = $this->updateServiceAddress($userArray,$location,$address);
} else {
$updateFlag = $this->updateEngineerAddress($userArray,$location);
}
if ($updateFlag) {
$e->success = true;
} else {
$e->msg = '更新地址失败';
}
} else {
$e->msg = '未找到工程师!';
}
return $this->renderJson($e);
}
/**
* @param $userArray
* @param $location
* @return bool
*/
private function updateEngineerAddress($userArray,$location)
{
// 如果工程师接单地址为空, 默认设置为当前工程师所在位置为接单位置
$service_address_id = null;
// 后面优化一下,工程师不是每次都要更新 地址的,坐标可以更新,地址暂时不用
$mapInfo = QQMapSDK::getMapInfo(QQMapSDK::QQMAP_KEY_TYPE_ENGINEER, $location['x'], $location['y'], 1);
//AppLog::DEBUG('====== getQQMapInfo ======== engineer id:'.$userArray['id'].' jsonEncode '.json_encode($mapInfo ));
$result = $mapInfo;
$mapInfo = json_decode($mapInfo,true);
//AppLog::DEBUG('=========== updateEngineerAddress ============'.$result);
if (!isset($mapInfo['result']) || $mapInfo['status'] > 0 ) {
AppLog::DEBUG('====== getQQMapInfo ======== engineer id:'.$userArray['id'].' mapInfo '.json_encode($mapInfo ));
return false;
}
$address = $mapInfo['result']['address'];
// 首次进来的时候是没有设置服务地址的,这里默认设置服务地址
if (empty($userArray['service_address_id'])) {
$service_addr = new AddressModel();
$service_addr->address = $address;
$service_addr->longitude = $location['y'];
$service_addr->latitude = $location['x'];
$service_addr->type = AddressModel::TYPE_SERVICE;
if(true == $service_addr->save()){
$service_address_id = $service_addr->id;
}
$engineer = EngineerModel::findOne($userArray['id']);
if ($service_address_id && $engineer) {
$engineer->service_address_id = $service_address_id;
$engineer->save();
}
}
if (empty($userArray['address_id'])) {
//保存地址
$addr = new AddressModel();
$address_id = null;
$addr->address = $address;
$addr->longitude = $location['y'];
$addr->latitude = $location['x'];
$addr->type = AddressModel::TYPE_LBS;
if(true == $addr->save()){
$address_id = $addr->id;
}
$engineer = EngineerModel::findOne($userArray['id']);
$re = false;
if ($address_id && $engineer) {
$engineer->address_id = $address_id;
//$engineer->id=$userArray['id'];
$re = $engineer->save();
}
return $re;
} else {
//AppLog::DEBUG("start update address->");
$addr = AddressModel::findOne($userArray['address_id']);
if (empty($addr)) {
AppLog::DEBUG("update address fail. address not found");
return false;
}
$addr->address = $address;
$addr->longitude = $location['y'];
$addr->latitude = $location['x'];
//AppLog::DEBUG("update address->3:".$userArray['address_id']);
//$addr->setIsNewRecord(false);
$re = $addr->save();
if ($re) {
return true;
} else {
AppLog::DEBUG("update address->fail address:".$address);
return false;
}
}
}
/** 更新服务地址
* @param $userArray
* @param $address
* @param $location
* @param $engineer 准备更新的 object
*/
private function updateServiceAddress($userArray,$location,$address = '')
{
if (empty($address)) {
return false;
}
$address = Html::encode($address);
if (empty($userArray['service_address_id'])) {
//保存地址
$addr = new AddressModel();
$address_id = null;
$addr->address = $address;
$addr->longitude = $location['y'];
$addr->latitude = $location['x'];
$addr->type = AddressModel::TYPE_SERVICE;
if (true == $addr->save()) {
$address_id = $addr->id;
}
//AppLog::DEBUG(' address is --------->'.$userArray['id']);
$engineer = EngineerModel::findOne($userArray['id']);
$re = false;
if ($address_id && $engineer) {
$engineer->service_address_id = $address_id;
//$engineer->id=$userArray['id'];
//AppLog::DEBUG(" update wx address result->".$address_id);
$re = $engineer->save();
}
return $re;
//AppLog::DEBUG("insert address->".$address_id." update wx address result->".$re.' address is '.$address);
} else {
//AppLog::DEBUG("start update address->");
$addr = AddressModel::findOne($userArray['service_address_id']);
if (!$addr) {
return false;
}
$addr->address = $address;
$addr->longitude = $location['y'];
$addr->latitude = $location['x'];
$addr->type = AddressModel::TYPE_SERVICE;
//AppLog::DEBUG("update address->3:".$userArray['address_id']);
//$addr->setIsNewRecord(false);
$re = $addr->save();
if ($re) {
return true;
//AppLog::DEBUG("update address->ok address:".$address);
} else {
AppLog::DEBUG("update service address->fail address:".$address);
return false;
}
}
}
// 获取贴码微信图片
public function actionUploadWxImg()
{
$req = Yii::$app->request;
$tt = $req->get('tt');
$applyImgId = $req->get('applyImgId');
$sign = $req->get('sign');
$qrcode = $req->get('qrcode'); //可以是qrcode 可也可以是 bind_apply_devce_apply id
$gets = array('tt' => $tt, 'applyImgId' => $applyImgId,'qrcode'=> $qrcode);
$e = new stdClass();
$e->success = false;
//AppLog::DEBUG('===== upload wx img sign ========'.$sign);
if (!Utils::checkSign($sign,$gets)) {
$e->msg = 'error sign';
return $this->renderJson($e);
}
$applyImgId = json_decode($applyImgId,true);
if (empty($applyImgId)) {
$e->msg = 'empty applyImgId';
return $this->renderJson($e);
}
//AppLog::DEBUG('===== upload wx img applyImgId ========'.json_encode($applyImgId));
$imageIdList = FileHelper::filterImage($applyImgId);
if (empty($imageIdList)) {
$e->msg = 'empty image ids';
return $this->renderJson($e);
}
if (!empty($imageIdList['wx'])) {
$this->getWxImage($imageIdList['wx'], $qrcode);
}
if (!empty($imageIdList['local'])) {
$this->getLocalServerImage($imageIdList['wx'], $qrcode);
}
}
/**
* @param $applyImgId
* @return array
*/
private function getWxImage($applyImgId, $qrcode)
{
$wechat = WxHelper::getWxPHPSDK();
$reArr = array();
foreach ($applyImgId as $k=>$v) {
if (empty($v)) {
continue;
}
//AppLog::DEBUG('===== getWxImage $images $v========'.$v);
$bindImgModel = BindDeviceApplyImgModel::findOne(['id'=>$v]);
if ($bindImgModel && empty($bindImgModel->path)) {
$bind_device_apply_img = FileHelper::saveWxImgToRemoveServer($wechat, $bindImgModel->wx_server_id, $bindImgModel->bind_device_apply_id);
//AppLog::DEBUG('===== getWxImage $bind_device_apply_img ========'.$bind_device_apply_img);
if (!empty($bind_device_apply_img)) {
$bindImgModel->path = $bind_device_apply_img;
$bindImgModel->save();
$reArr[]= $bind_device_apply_img;
}
}
}
return $reArr;
}
/**
* 图片不通过微信直接保存到服务器再传到OSS
*/
private function getLocalServerImage($applyImgNameIds, $qrcode = '')
{
$reArr = array();
foreach ($applyImgNameIds as $k => $v) {
if (empty($v)) {
continue;
}
$bindImgModel = BindDeviceApplyImgModel::findOne(['id'=>$v]);
if ($bindImgModel && empty($bindImgModel->path)) {
$bind_device_apply_img = FileHelper::saveLocalImgToRemoveServer($v, $bindImgModel->bind_device_apply_id);
if (!empty($bind_device_apply_img)) {
$bindImgModel->path = $bind_device_apply_img;
$bindImgModel->save();
$reArr[]= $bind_device_apply_img;
}
}
}
return $reArr;
}
/**
* 接单教程统计入口,这里只是做准备
*/
public function actionStat()
{
$gets = Yii::$app->request->get();
//AppLog::DEBUG('stat:'.json_encode($gets));
}
public function actionLogout()
{
$appUser = Yii::$app->getUser();
$appUser->logout();
echo "logout";
}
/**
* 极窝订单宝-服务协议
*/
public function actionLegal()
{
echo Yii::$app->view->renderFile('@app/views/layouts/legal.php');
}
/**
* 极办公平台订单-服务协议
*/
public function actionLegalJiwork()
{
echo Yii::$app->view->renderFile('@app/views/layouts/legal_jibangong.php');
}
/**
* 贴码规则条文
*/
public function actionQrcodeLegal()
{
echo Yii::$app->view->renderFile('@app/views/layouts/qrcode_legal.php');
//return $this->render('@app/views/layouts/legal');
}
}