117 lines
3.5 KiB
PHP
117 lines
3.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-5
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
|
|
namespace app\modules\admin\models\store;
|
|
|
|
use app\components\EncryptHelper;
|
|
use app\components\Utils;
|
|
use app\models\DevList;
|
|
use app\models\District;
|
|
use app\models\Model;
|
|
use app\models\OrderDetail;
|
|
use app\models\Store;
|
|
use app\models\StoreUser;
|
|
use app\models\User;
|
|
use app\modules\admin\models\AdminModel;
|
|
use app\models\common\CommonUserEditForm;
|
|
use yii\data\Pagination;
|
|
|
|
class DevListForm extends AdminModel
|
|
{
|
|
public $page;
|
|
public $limit;
|
|
|
|
public $keywords;
|
|
public $status;
|
|
public $province_id;
|
|
public $city_id;
|
|
public $area_id;
|
|
|
|
public $store_id;
|
|
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['keywords',], 'trim'],
|
|
[['keywords',], 'string'],
|
|
[['page', 'limit', 'status', 'province_id', 'city_id', 'area_id'], 'integer'],
|
|
[['page'], 'default', 'value' => 1],
|
|
[['limit'], 'default', 'value' => 20],
|
|
];
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
|
|
$query = DevList::find()->alias('dev')
|
|
->join('left join', ['store' => Store::tableName()], 'dev.store_id = store.id')
|
|
->where([
|
|
'dev.is_delete' => 0
|
|
])->andFilterWhere([
|
|
'dev.store_id' => $this->store_id
|
|
]);
|
|
$query->select('dev.*,store.name as store_name');
|
|
|
|
$count = $query->count();
|
|
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]);
|
|
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['created_at' => SORT_DESC])->asArray()->all();
|
|
foreach ($list as $index => $item) {
|
|
$item['address'] = $item['province'] . $item['city'] . $item['district'] . $item['address'];
|
|
$item['online_status_cn'] = $item['online_status'] == 1 ? '在线' : '离线';
|
|
|
|
$body_arr = [
|
|
'path' => "pages/index/scanPage?type=yp&sn={$item['dev_id']}",
|
|
];
|
|
$md5 = md5(json_encode($body_arr));
|
|
if(!file_exists(\Yii::$app->basePath.'/web/upload/devcode')){
|
|
// 创建目录
|
|
@mkdir(\Yii::$app->basePath.'/web/upload/devcode');
|
|
}
|
|
if(!is_file(\Yii::$app->basePath.'/web/upload/devcode/'.$md5.'.png')){
|
|
// 生成二维码
|
|
$qr_res = $this->wxmpQrcode($body_arr);
|
|
$res = file_put_contents(\Yii::$app->basePath.'/web/upload/devcode/'.$md5.'.png',$qr_res);
|
|
}
|
|
$file_name = \Yii::$app->basePath.'/web/upload/';
|
|
$item['qr_img'] = "/upload/devcode/{$md5}.png";
|
|
$list[$index] = $item;
|
|
}
|
|
|
|
|
|
|
|
$data = [];
|
|
$data['code'] = 0;
|
|
$data['msg'] = 'ok';
|
|
$data['data'] = $list;
|
|
$data['count'] = $count;
|
|
return $data;
|
|
|
|
}
|
|
|
|
//获取小程序二维码
|
|
public function wxmpQrcode($body)
|
|
{
|
|
$plugin = new \app\models\common\PluginService();
|
|
$wxmpService = $plugin->getWxmpService(0);
|
|
$accessToken = $wxmpService->getAccessToken();
|
|
if (empty($accessToken)) {
|
|
$accessToken = $wxmpService->getAccessToken(true);
|
|
}
|
|
$body = json_encode($body);
|
|
return $wxmpService->Qrcode->getWxappQrcodeLong($accessToken, $body);
|
|
}
|
|
|
|
} |