getPk(); $qrCode = self::build( $row[$pk]); $qrCodeUrl = self::serverUrl().'/uploads/qrcode/'.$qrCode; $row->getQuery()->where($pk, $row[$pk])->update(['qr_code' => $qrCodeUrl]); //创建产品 }); } // 修改设备状态 public static function updateStatus($contract_id) { // 查找绑定对应合同的设备信息 $devices = self::where(['contract_id' => $contract_id, 'status' => 1])->select(); foreach ($devices as $device) { $device->status = 0; $device->customer_id = NULL; $device->contract_id = NULL; $device->save(); } } public function getStatusList() { return ['0' =>'未绑定','1'=>'已绑定']; } public static function serverUrl(){ $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; return $http_type . $_SERVER['HTTP_HOST']; } // 生成二维码 public static function build($text) { $config = get_addon_config('qrcode'); $params = $_GET; $params = array_intersect_key(array($text), array_flip(['text', 'size', 'padding', 'errorlevel', 'foreground', 'background', 'logo', 'logosize', 'logopath', 'label', 'labelfontsize', 'labelalignment'])); $params['text'] = $text; $params['label'] = ''; $qrCode = \addons\qrcode\library\Service::qrcode($params); $mimetype = $config['format'] == 'png' ? 'image/png' : 'image/svg+xml'; $response = Response::create()->header("Content-Type", $mimetype); // 直接显示二维码 // header('Content-Type: ' . $qrCode->getContentType()); // $response->content($qrCode->writeString()); // 写入到文件 if ($config['writefile']) { $qrcodePath = ROOT_PATH . 'public/uploads/qrcode/'; if (!is_dir($qrcodePath)) { @mkdir($qrcodePath); } if (is_really_writable($qrcodePath)) { $filePath = $qrcodePath . md5(implode('', $params)) . '.' . $config['format']; $qrCode->writeFile($filePath); $code_name = md5(implode('', $params)) . '.' . $config['format']; } } return $code_name; } public function getCateIdTextAttr($value,$data){ $list = Db::name('qingdongams_equipment_cate')->where(array('id' => array('in', $data['cate_id'])))->value('name'); return $list; } public function getTypeIdTextAttr($value, $data) { $list = Db::name('qingdongams_equipment_type')->where(array('id' => array('in', $data['type_id'])))->field('id,name')->select(); $store_name = ''; foreach ($list as $key => $val) { if ($store_name != '') { $store_name .= ' / '; } $store_name .= $val['name']; } return isset($store_name) ? $store_name : ''; } public function getWTimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['w_time']) ? $data['w_time'] : ''); return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } protected function setWTimeAttr($value) { return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); } public function cate() { return $this->belongsTo('app\admin\model\qingdongams\equipment\Cate', 'cate_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function type() { return $this->belongsTo('app\admin\model\qingdongams\equipment\Type', 'type_id', 'id', [], 'LEFT')->setEagerlyType(0); } }