Files
2024-09-27 01:32:49 +08:00

244 lines
6.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\api\controller;
use app\common\service\ActivityService;
use PhpParser\Node\Expr\Array_;
use think\facade\Config;
use think\facade\Cache;
use think\Db;
class CommonController extends ApiController
{
protected $noAuth = ['userTypeList','userTypeInfo'];
/**
* @apiDefine Common 公共接口
*/
/**
* @apiVersion 1.0.0
* @api {post} /common/userTypeList 1.企业类型列表(朱晓伟)
* @apiName userTypeList
* @apiGroup Common
* @apiHeader {String} authentication 验证
* @apiSuccessExample Success-Response:
*{
"code": 200,
"message": "成功",
"data": [
{
"key": "clinic",
"name": "诊所"
},
{
"key": "hospital",
"name": "医院"
},
{
"key": "drugstore",
"name": "单体药房"
},
{
"key": "liansuo_drugstore",
"name": "连锁药房"
},
{
"key": "purchasing_enterprise",
"name": "医药采购企业"
},
{
"key": "manufacturer",
"name": "医药生产企业"
},
{
"key": "supply_enterprise",
"name": "医药供应企业"
},
{
"key": "agency_business",
"name": "医药代理企业"
}
]
}
*/
public function userTypeList() {
$list = Config::get('const.ROLE_CERT_INFO')['buyer']['sub_type'];
$data = [];
foreach ($list as $k => $v)
{
$item['key'] = $k;
$item['name'] = $v['name'];
$data[] = $item;
}
return self::returnMsg(self::SUCCESS, self::getMessage('SUCCESS'),$data);
}
/**
* @apiVersion 1.0.0
* @api {post} /common/userTypeInfo 2.企业类型详情(朱晓伟)
* @apiName userTypeInfo
* @apiGroup Common
* @apiHeader {String} authentication 验证
* @apiParam {String} key 企业类型key
* @apiSuccessExample Success-Response:
*{
"code": 200,
"message": "成功",
"data": {
"business_license": true,
"medical_license": true,
"purchase_identity": true,
"authority_purchase": true,
"tax_regcate": true,
"gsp_license": false,
"trade_license": false,
"peer_list": false,
"year_report": false,
"make_license": false,
"gmp_license": false,
"principal_identity": false,
"sales_commission": false,
"quality_agreement": false,
"acting_prove": false
}
}
*/
public function userTypeInfo() {
$key = input('key');
$list = Config::get('const.ROLE_CERT_INFO')['buyer']['sub_type'];
$data = [];
foreach ($list as $k => $v)
{
if($key == $k){
$data = $v['certificate_list'];
if(!isset($data['business_license'])){
$data['business_license'] = false;
}
if(!isset($data['gsp_license'])){
$data['gsp_license'] = false;
}
if(!isset($data['trade_license'])){
$data['trade_license'] = false;
}
if(!isset($data['purchase_identity'])){
$data['purchase_identity'] = false;
}
if(!isset($data['authority_purchase'])){
$data['authority_purchase'] = false;
}
if(!isset($data['tax_regcate'])){
$data['tax_regcate'] = false;
}
if(!isset($data['peer_list'])){
$data['peer_list'] = false;
}
if(!isset($data['year_report'])){
$data['year_report'] = false;
}
if(!isset($data['make_license'])){
$data['make_license'] = false;
}
if(!isset($data['gmp_license'])){
$data['gmp_license'] = false;
}
if(!isset($data['principal_identity'])){
$data['principal_identity'] = false;
}
if(!isset($data['sales_commission'])){
$data['sales_commission'] = false;
}
if(!isset($data['quality_agreement'])){
$data['quality_agreement'] = false;
}
if(!isset($data['acting_prove'])){
$data['acting_prove'] = false;
}
}
}
$list = [];
foreach ($data as $k=>$v)
{
if($v){
$item = [];
$item['name'] = $k;
$item['value'] = $k;
$item['path'][] = 'https://ydyd-develop-file.oss-cn-hangzhou.aliyuncs.com/app/business_license_15880512107935.png';
$list[] = $item;
}
}
return self::returnMsg(self::SUCCESS, self::getMessage('SUCCESS'),$list);
}
/**
*
* 系统常量初始化 (丁超 20200417)
* 沿用旧版common\SystemDeal(当前API工程系统初始化未调用)
* 建立缓存+返回系统常量
* 内含敏感数据,不可直接全部返回前端
* @access protected
* @version 1.0.0
* @return array
* 返回示例
*{
"WEB_NAME": "医点医滴电子商务-药品汇聚商城",
"PLAT_PUBLIC_ACCOUNT": {
"bank": "徽商银行合肥市肥东支行",
"name": "安徽金壶医药有限公司",
"account": "1027801021000008392"
},
"DRUG_FORM": [
"胶囊剂",
"颗粒剂",
"片剂",
],
"DRUG_UNITS_FORM": [
"盒",
"支",
"瓶",
"袋",
],
}
*/
protected function initSysConstant(){
//初始化系统常量
$system_constant = Cache::get("SYSTEM_CONSTANT");
if (!$system_constant) {
$list = Db::name('constants')->column("param_value","param_name");
$system_constant = array();
foreach ($list as $k => $v) {
$system_constant[$k] = json_decode($v,true);
}
Cache::set('SYSTEM_CONSTANT', $system_constant,120);
}
//注意区别于缓存config方式只对当前请求有效
config('SYSTEM_CONSTANT',$system_constant);
return $system_constant;
}
/**
* 用户信息 (丁超 20200417)
*/
protected function getUserInfo(){
if (!$this->uid){
$user_info = [];
}else{
$user_info = Cache::get('USER_INFO_API'.$this->uid);
if (!$user_info){
$field = 'u.user_id,u.is_new_user,u.user_name,u.avatar_url,u.phone,u.buyer_status,u.area_id,u.register_ip,u.last_login_time,u.last_login_ip,u.block_status,u.custom_service_id';
$field .= ',b.extend_level';
$user_info = Db::name('users')->alias('u')->field($field)->where('u.user_id',$this->uid)->leftJoin('buyer b','b.buyer_user_id=u.user_id')->find();
$system_constant = Cache::get('SYSTEM_CONSTANT')??[];
if (!$system_constant){
$system_constant = $this->initSysConstant();
}
$extend_price_rate = $system_constant['EXTEND_DISCOUNT_RATE'][$user_info['extend_level']??'level-5']??1.05;
$user_info['extend_price_rate'] = $extend_price_rate;
Cache::set('USER_INFO_API'.$this->uid,$user_info,360);
}
}
return $user_info;
}
}