model = new Config(); } /** * 获取配置项列表 * @param array $where * @return array */ public function getPage(array $where = []) { $field = 'id,site_id,we_chat_pay_appid,we_chat_pay_app_id,we_chat_pay_miniapp_id,we_chat_pay_mch_id,we_chat_pay_key,we_chat_pay_miniapp_secret,we_chat_pay_notify_url,alipay_appId,alipay_rsa_private_key,alipay_public_key,alipay_notify_url,create_time,update_time,delete_time,we_chat_pay_mch_secret_cert,we_chat_pay_mch_public_cert_path'; $order = 'id desc'; $search_model = $this->model->where([ [ 'site_id' ,"=", $this->site_id ] ])->withSearch([''], $where)->field($field)->order($order);; $list = $this->pageQuery($search_model); return $list; } /** * 获取配置项信息 * @param int $id * @return array */ public function getInfo(int $id) { $field = 'id,site_id,h5_qrcode_url,we_chat_pay_appid,we_chat_pay_app_id,we_chat_pay_miniapp_id,we_chat_pay_mch_id,we_chat_pay_key,we_chat_pay_miniapp_secret,we_chat_pay_notify_url,alipay_appId,alipay_rsa_private_key,alipay_public_key,alipay_notify_url,create_time,update_time,delete_time,we_chat_pay_mch_secret_cert,we_chat_pay_mch_public_cert_path,h5_site_url'; $info = $this->model->field($field)->where('site_id', '=', $this->site_id)->findOrEmpty()->toArray(); //查看基础信息是否完全 if (!$info){ //创建基础信息 //添加 $data['site_id'] = $this->site_id; $dictionary = Dict::where('key','h5_site_url') ->value('dictionary'); $h5_site_url = json_decode($dictionary, true)[0]['value']; $data['h5_site_url'] = "{$h5_site_url}?site_id={$this->site_id}";//h5站点地址 $we_chat_pay_notify_url = Dict::where('key', 'we_chat_pay_notify_url') ->value('dictionary');//微信支付异步回调根路径 $we_chat_pay_notify_url = json_decode($we_chat_pay_notify_url, true)[0]['value']; $data['we_chat_pay_notify_url'] = "{$we_chat_pay_notify_url}/{$this->site_id}";//微信异步回调地址 $qRCode = $this->createUrlQRCode($data['h5_site_url']);//生成二维码 $data['h5_qrcode_url'] =$qRCode['url']; $this->add($data); $info = $data; } $info['ol_h5_qrcode_url'] = ''; if (!empty($info['h5_qrcode_url'])){ $info['ol_h5_qrcode_url'] = get_file_url($info['h5_qrcode_url']); } return $info; } /** * 重新生成H5站点二维码 * @param int $id * @return array */ public function resetH5SiteQRCode(int $id) { //查询h5站点首页域名 $h5_site_url = $this->model->where('id',$id)->value('h5_site_url'); $res = $this->createUrlQRCode($h5_site_url); return $res; } //根据url生成二维码 private function createUrlQRCode($url){ $site_id = $this->site_id; $date = date('Y_m_d'); $path = "config_h5_qrcode_url"; $save_path = "addon/hygl/upload/{$path}/{$site_id}/{$date}";//文件保存的路径, // 创建保存目录 if (!is_dir($save_path)) { mkdir($save_path, 0755, true); } //将网址url转成二维码 // 创建一个QR码实例 $code = new QRcode(); $source_file = $code->png($url)->getPath();//生成二维码,并返回路径 $source_file =ltrim($source_file,'/'); return [ 'url' => $source_file, 'ol_url' => get_file_url($source_file) ]; } /** * 添加配置项 * @param array $data * @return mixed */ public function add(array $data) { $data['site_id'] = $this->site_id; $res = $this->model->create($data); return $res->id; } /** * 配置项编辑 * @param int $id * @param array $data * @return bool */ public function edit(array $data) { //检测数据是否存在,存在就编辑,不存在就添加 $id = $this->model->where([['site_id', '=', $this->site_id]])->value('id'); if ($id){ //编辑 $this->model->where([['site_id', '=', $this->site_id]])->update($data); }else{ //添加 $data['site_id'] = $this->site_id; $dictionary = Dict::where('key','h5_site_url') ->value('dictionary'); $h5_site_url = json_decode($dictionary, true)[0]['value']; $data['h5_site_url'] = "{$h5_site_url}?site_id={$this->site_id}";//h5站点地址 $we_chat_pay_notify_url = Dict::where('key', 'we_chat_pay_notify_url') ->value('dictionary');//微信支付异步回调根路径 $we_chat_pay_notify_url = json_decode($we_chat_pay_notify_url, true)[0]['value']; $data['we_chat_pay_notify_url'] = "{$we_chat_pay_notify_url}/{$this->site_id}";//微信异步回调地址 $qRCode = $this->createUrlQRCode($data['h5_site_url']);//生成二维码 $data['h5_qrcode_url'] =$qRCode['url']; $this->add($data); } return true; } /** * 删除配置项 * @param int $id * @return bool */ public function del(int $id) { $model = $this->model->where([['id', '=', $id],['site_id', '=', $this->site_id]])->find(); $res = $model->delete(); return $res; } }