first commit
This commit is contained in:
1
金壶/ydyd_service/application/common/service/.pydio
Normal file
1
金壶/ydyd_service/application/common/service/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
ab472aa9-380e-4d5a-ab37-34ed1de23b80
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: HIAPAD
|
||||
* Date: 2018/9/25
|
||||
* Time: 10:48
|
||||
*/
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
|
||||
use think\Db;
|
||||
|
||||
class ActivityService
|
||||
{
|
||||
public function getActivityList($user_info,$parames = [])
|
||||
{
|
||||
$_where = [];
|
||||
$_where['online_status'] = 1;
|
||||
if(isset($parames['activity_belong']) && $parames['activity_belong']){
|
||||
$_where['activity_belong'] = $parames['activity_belong'];
|
||||
}
|
||||
if(isset($parames['activity_type']) && $parames['activity_type']){
|
||||
$_where['activity_type'] = $parames['activity_type'];
|
||||
}
|
||||
if(isset($parames['is_self'])){
|
||||
$_where['is_self'] = $parames['is_self'];
|
||||
}
|
||||
$_field = '';
|
||||
$_field.='id,activity_name,activity_belong,activity_type,is_self,cover_img';
|
||||
$result = Db::name('activity')
|
||||
->field($_field)
|
||||
->where($_where)
|
||||
->order('sort_num','desc')
|
||||
->select();
|
||||
foreach ($result as $key=>$value)
|
||||
{
|
||||
$result[$key]['goods_list'] = [];
|
||||
if($value['is_self']){
|
||||
$search_data['current_page'] = 1;
|
||||
$search_data['per_page'] = 6;
|
||||
$search_data['activity_id'] = $value['id'];
|
||||
$res = model(GoodsService::class)->getGoodsSearch($user_info,$search_data);
|
||||
unset($res['code']);
|
||||
unset($res['msg']);
|
||||
unset($res['to_select']);
|
||||
$result[$key]['goods_list'] = $res['data'];
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getActivityInfo($parames)
|
||||
{
|
||||
$_field = '';
|
||||
$_field.='id,activity_name,activity_belong,activity_type';
|
||||
$info = Db::name('activity')
|
||||
->field($_field)
|
||||
->find($parames['id']);
|
||||
$ids = Db::name('activity_goods_relation')->where('activity_id',$info['id'])->column('price_id');
|
||||
$search_data['page'] = 1;
|
||||
$search_data['limit'] = 20;
|
||||
if(isset($parames['page']) && $parames['page']){
|
||||
$search_data['page'] = $parames['page'];
|
||||
}
|
||||
if(isset($parames['limit']) && $parames['limit']){
|
||||
$search_data['limit'] = $parames['limit'];
|
||||
}
|
||||
$search_data['inIds'] = $ids;
|
||||
$info['goods_list'] = model(GoodsService::class)->getList($search_data);
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace app\common\service;
|
||||
|
||||
use think\facade\Env;
|
||||
|
||||
class AliyunOssService{
|
||||
|
||||
public function getStsToken($data=[]) {
|
||||
|
||||
$upload_type = $data['upload_type']??'';
|
||||
|
||||
$result['errcode']=0;
|
||||
$result['errmsg']='成功获取STS凭证';
|
||||
|
||||
$nowtime=time();
|
||||
|
||||
$sts_expire_time=session('sts_expire_time');
|
||||
if ($sts_expire_time && $nowtime < $sts_expire_time) {
|
||||
$result['data']=session('sts_data');
|
||||
} else {
|
||||
require_once Env::get('extend_path').'Aliyun/core/Config.php';
|
||||
$iClientProfile = \DefaultProfile::getProfile("cn-hangzhou", "LTAI8yWB5JgvunlT", "F7OWOL7OA1awQ6tELawWBKTQM5I32U");
|
||||
$client = new \DefaultAcsClient($iClientProfile);
|
||||
|
||||
// 角色资源描述符,在RAM的控制台的资源详情页上可以获取
|
||||
$roleArn = "acs:ram::1845636578658781:role/develop-files-role";
|
||||
$bucketname='ydyd-develop-file';
|
||||
if ($upload_type=='chat') {
|
||||
$bucketname='ydyd-chat-file';
|
||||
}
|
||||
if ($upload_type =='product') {
|
||||
$bucketname='ydyd-product-file';
|
||||
}
|
||||
$policy = [];
|
||||
$policy['Statement'][0]['Action']=array("oss:PutObject","oss:GetObject","oss:ListParts","oss:UploadPart");
|
||||
$policy['Statement'][0]['Effect']="Allow";
|
||||
$policy['Statement'][0]['Resource']="acs:oss:*:1845636578658781:".$bucketname."/*";
|
||||
$policy['Version']="1";
|
||||
|
||||
require_once Env::get('extend_path').'Aliyun/sts/AssumeRoleRequest.php';
|
||||
$request = new \AssumeRoleRequest();
|
||||
// RoleSessionName即临时身份的会话名称,用于区分不同的临时身份
|
||||
// 您可以使用您的客户的ID作为会话名称
|
||||
$request->setRoleSessionName("fortest");
|
||||
$request->setRoleArn($roleArn);
|
||||
$request->setPolicy(json_encode($policy));
|
||||
$request->setDurationSeconds(3600);
|
||||
$sts_expire_time=time()+1800;
|
||||
$response = $client->getAcsResponse($request);
|
||||
|
||||
if ($response->Credentials->AccessKeySecret) {
|
||||
$result['data']['Region']='oss-cn-hangzhou';
|
||||
$result['data']['AccessKeySecret']=$response->Credentials->AccessKeySecret;
|
||||
$result['data']['AccessKeyId']=$response->Credentials->AccessKeyId;
|
||||
$result['data']['Bucket']=$bucketname;
|
||||
$result['data']['SecurityToken']=$response->Credentials->SecurityToken;
|
||||
//结果写入session缓存
|
||||
session('sts_expire_time',$sts_expire_time);
|
||||
session('sts_data',$result['data']);
|
||||
} else {
|
||||
$result['errcode']=-2;
|
||||
$result['errmsg']='获取STS凭证失败';
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
161
金壶/ydyd_service/application/common/service/ExpressService.php
Normal file
161
金壶/ydyd_service/application/common/service/ExpressService.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\service;
|
||||
use think\Exception;
|
||||
use think\facade\Cache;
|
||||
|
||||
|
||||
class ExpressService
|
||||
{
|
||||
|
||||
|
||||
public $key = 'jhyyydydxxb';
|
||||
//暂时翻转key再连接起来md5
|
||||
public $md5_key = '5ec1092c4833247e3bae48a38c3364d4';
|
||||
|
||||
//快递appcode
|
||||
public $appcode='18a0cb65e1614f6197e661f64bd82245';
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
if(array_key_exists("HTTP_ORIGIN",$_SERVER)) {
|
||||
$domain = $_SERVER['HTTP_ORIGIN'];
|
||||
if(strstr($domain,'.ydyd.com') || strstr($domain,'.ydyd51.com') || strstr($domain,'.jinhu11.com')|| strstr($domain,'.jh.com')) {
|
||||
$origin = $domain;
|
||||
}
|
||||
|
||||
header("Access-Control-Allow-Credentials: true");
|
||||
header("Access-Control-Allow-Origin: ".$origin);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_express($parames){
|
||||
if($this->get_auth($this->key)){
|
||||
//验证成功 开始获取内容
|
||||
$type = trim(request()->param('type')); //get_type get_detail
|
||||
if($type == 'get_type'){
|
||||
$express_type_list = Cache::get('EXPRESS_TYPE_LIST');
|
||||
if(!$express_type_list){
|
||||
$express_type_list = json_decode($this->get_express_type(),TRUE );
|
||||
Cache::set("EXPRESS_TYPE_LIST", $express_type_list, 604800);
|
||||
}
|
||||
if($express_type_list['status'] == '200'){
|
||||
$result['errcode'] = 0;
|
||||
$result['errmsg'] = '获取快递厂家列表成功';
|
||||
$result['data']['list'] = $express_type_list['result'];
|
||||
}else{
|
||||
$result['errcode'] = -1;
|
||||
$result['errmsg'] = '获取快递厂家列表失败';
|
||||
$result['data']['list'] = $express_type_list;
|
||||
}
|
||||
return json($result);
|
||||
}elseif($type == 'get_detail'){
|
||||
$exp_num =$parames['exp_num'];
|
||||
$exp_type = explode('*',$parames['exp_type']);
|
||||
if(isset($exp_type[1])){
|
||||
$exp_type = $exp_type[1];
|
||||
if($exp_num && $exp_type){
|
||||
$express_detail = json_decode($this->get_express_detail($exp_num,$exp_type),true);
|
||||
$ret = [];
|
||||
if($express_detail['code'] == 'OK'){
|
||||
foreach ($express_detail['list'] as $value)
|
||||
{
|
||||
$item['title'] = $value['content'];
|
||||
$item['desc'] = $value['time'];
|
||||
$ret[] = $item;
|
||||
}
|
||||
if(!$ret){
|
||||
$item['title'] = '暂无轨迹信息';
|
||||
$item['desc'] = date("Y-m-d h:i:s", time());
|
||||
$ret[] = $item;
|
||||
}
|
||||
return $ret;
|
||||
}else{
|
||||
if(!$ret){
|
||||
$item['title'] = '暂无轨迹信息';
|
||||
$item['desc'] = date("Y-m-d h:i:s", time());
|
||||
$ret[] = $item;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
throw new Exception('请检查快递单号或者快递类型');
|
||||
}
|
||||
throw new Exception('未发送要查询的类型');
|
||||
}else{
|
||||
throw new Exception('未发送要查询的类型');
|
||||
}
|
||||
}else{
|
||||
throw new Exception('非法请求');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function get_auth($_key){
|
||||
$_md5_key = md5($this->key . strrev($_key));
|
||||
if($_md5_key == $this->md5_key){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_express_type($exp_type=''){
|
||||
$host = "https://cexpress.market.alicloudapi.com";
|
||||
$path = "/cExpressLists";
|
||||
$method = "GET";
|
||||
$headers = array();
|
||||
array_push($headers, "Authorization:APPCODE " . $this->appcode);
|
||||
$querys = "";
|
||||
$bodys = "";
|
||||
$url = $host . $path . "?" . $querys;
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
if (1 == strpos("$".$host, "https://"))
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
}
|
||||
$result = curl_exec($curl);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function get_express_detail($exp_num,$exp_type){
|
||||
$host = "https://cexpress.market.alicloudapi.com";
|
||||
$path = "/cexpress";
|
||||
$method = "GET";
|
||||
$appcode = $this->appcode;
|
||||
$headers = array();
|
||||
array_push($headers, "Authorization:APPCODE " . $appcode);
|
||||
$querys = "no=" . $exp_num . "&type=" . $exp_type;
|
||||
$bodys = "";
|
||||
$url = $host . $path . "?" . $querys;
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
//curl_setopt($curl, CURLOPT_HEADER, true); 如不输出json, 请打开这行代码,打印调试头部状态码。
|
||||
//状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误
|
||||
if (1 == strpos("$".$host, "https://"))
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
}
|
||||
$result = curl_exec($curl);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
981
金壶/ydyd_service/application/common/service/GoodsService.php
Normal file
981
金壶/ydyd_service/application/common/service/GoodsService.php
Normal file
@@ -0,0 +1,981 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\SkuModel;
|
||||
use app\facade\AppConstant;
|
||||
use app\facade\HyData;
|
||||
use app\facade\Pinyin;
|
||||
use think\Exception;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Config;
|
||||
use think\facade\Request;
|
||||
use traits\controller\Jump;
|
||||
use think\Db;
|
||||
|
||||
class GoodsService
|
||||
{
|
||||
use Jump;
|
||||
const SEARCH_LIMIT=10;
|
||||
const NO_HY_PRICE = '已售罄';
|
||||
const APP_DEFAULT_IMG_URL = 'ydyd-develop-file.oss-cn-hangzhou.aliyuncs.com/pc_shop_pic_url_1588925532218.jpg';
|
||||
|
||||
|
||||
/**
|
||||
* 商品管理列表20190907
|
||||
* 数据检索字段:名称、供应商、厂商、商品上下架状态、批次号、批次类型
|
||||
*/
|
||||
public function getList($search_data = [])
|
||||
{
|
||||
$_where = [];
|
||||
$_where[] = ['gba.is_delete','=',0];
|
||||
//默认排序
|
||||
$_order = ['gba.is_onshelf'=>'asc','g.goods_id'=>'desc'];
|
||||
|
||||
//提成比例排序
|
||||
if (isset($search_data['iSortCol_0'])&&isset($search_data['sSortDir_0'])&&($search_data['iSortCol_0']==10)&&in_array($search_data['sSortDir_0'],['asc','desc'])){
|
||||
$_order = ['gba.platform_royalty'=>$search_data['sSortDir_0'],'gba.is_onshelf'=>'asc','g.goods_id'=>'desc'];
|
||||
}
|
||||
//商品名称:拼音+中文
|
||||
if (isset($search_data['goods_name'])&&$search_data['goods_name']){
|
||||
//判断$search_data['goods_name']是否含有中文;注意:1.药品名称为英文也要搜索药品名称(此时不含中文) 2.药品名称中文+字母混合,搜索字母部分也要搜索药品名称
|
||||
//临时封装函数is_str_include_chinese,待完善
|
||||
if (is_str_include_chinese($search_data['goods_name'])){
|
||||
$_where[] = ['g.name','like','%'.$search_data['goods_name'].'%'];
|
||||
}else{
|
||||
$_where[] = ['g.name|g.simple_pinyin|g.pinyin','like','%'.$search_data['goods_name'].'%'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($search_data['batch_number'])&&$search_data['batch_number']){
|
||||
$_where[] = ['gb.batch_number','=',$search_data['batch_number']];
|
||||
}
|
||||
if (isset($search_data['batch_type'])&&in_array($search_data['batch_type'],['1','2','all'])){
|
||||
if (in_array($search_data['batch_type'],['1','2'])){
|
||||
$_where[] = ['gb.batch_type','=',$search_data['batch_type']];
|
||||
}
|
||||
}
|
||||
if (isset($search_data['supplier'])&&$search_data['supplier']){
|
||||
$_where[] = ['s.supplier_name','like','%'.$search_data['supplier'].'%'];
|
||||
}
|
||||
|
||||
if (isset($search_data['manufacturer'])&&$search_data['manufacturer']){
|
||||
$_where[] = ['m.name','like','%'.$search_data['manufacturer'].'%'];
|
||||
}
|
||||
if (isset($search_data['is_onshelf'])&&in_array($search_data['is_onshelf'],['0','1','2','all'])){
|
||||
if (in_array($search_data['is_onshelf'],['0','1','2'])){
|
||||
$_where[] = ['gba.is_onshelf','=',$search_data['is_onshelf']];
|
||||
}
|
||||
}
|
||||
if(isset($search_data['inIds']) && $search_data['inIds']){
|
||||
$_where[] = ['gba.id','in',$search_data['inIds']];
|
||||
}
|
||||
|
||||
if(isset($search_data['notIds']) && $search_data['notIds']){
|
||||
$_where[] = ['gba.id','not in',$search_data['notIds']];
|
||||
}
|
||||
|
||||
if(isset($search_data['isOnlySelf']) && $search_data['isOnlySelf']){
|
||||
$_where[] = ['gb.supplier_id','=',10000];
|
||||
}
|
||||
|
||||
$_field = '';
|
||||
//goods
|
||||
$_field.='g.goods_id,g.name,g.spec_desc,g.unit,g.drug_form,g.sort_order,app_thumb,pc_thumb,';
|
||||
//supplier
|
||||
$_field.='s.supplier_name,';
|
||||
//manufacturer
|
||||
$_field.='m.name as manufacturer_name,';
|
||||
//goods_batch
|
||||
$_field.='gb.batch_number,gb.retail_flag,gb.batch_type,gb.cost_price,gb.stock_num,';
|
||||
//gba
|
||||
$_field.='gba.id as gba_id,gba.is_onshelf,gba.area_id,gba.price,gba.platform_royalty,gba.discount_price,gba.discount_num,gba.sort';
|
||||
//药品列表数据
|
||||
$res_list = Db::name('goods_batch_area_relation')->alias('gba')->field($_field)
|
||||
->leftJoin('goods_batch gb','gba.batch_id=gb.batch_id')
|
||||
->leftJoin('goods g','g.goods_id=gb.goods_id')
|
||||
->leftJoin('goods_supplier_relation gsr','gb.relation_id=gsr.id')
|
||||
->leftJoin('suppliers s','s.supplier_id=gsr.supplier_id')
|
||||
->leftJoin('manufacturer m','m.id=g.manufacturer_id')
|
||||
->where($_where)
|
||||
->order($_order)
|
||||
->paginate($search_data['limit'], false, ['page' => $search_data['page']]);
|
||||
|
||||
return $res_list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 商品列表-默认
|
||||
*/
|
||||
public function getGoodsList($params){
|
||||
$per_page = $params['per_page']??20;
|
||||
$current_page = $params['current_page']??1;
|
||||
|
||||
$fields = 'g.goods_id,g.name as goods_name,g.show_price,g.is_online_sale,g.country_code,g.app_thumb,g.pc_thumb,g.drug_form,g.keyword,g.sketch,m.name as manufacturer_name,g.spec_desc,';
|
||||
$fields .= 'spu.batch_type,spu.retail_flag,spu.retail_num,spu.entirety_num,spu.batch_number,spu.stock_num,spu.term_validity,spu.supplier_sn,';
|
||||
$fields .= 'sku.id as sku_id,sku.area_id,sku.price,sku.price_type,sku.discount_price,sku.discount_num,sku.discount_start_time,sku.discount_end_time';
|
||||
|
||||
$where = [];
|
||||
$where[] = ['g.status','=',1];
|
||||
$where[] = ['spu.batch_status','=',1];
|
||||
$where[] = ['spu.stock_num','>',0];
|
||||
$where[] = ['sku.is_onshelf','=',1];
|
||||
$where[] = ['sku.is_delete','=',0];
|
||||
|
||||
$order_by = [];
|
||||
$order_by[] = ['sku.sort','asc'];
|
||||
$order_by[] = ['sku.id','desc'];
|
||||
$order_by[] = ['spu.batch_id','desc'];
|
||||
$order_by[] = ['g.goods_id','desc'];
|
||||
|
||||
$goods_list = Db::name('goods_batch_area_relation')->alias('sku')
|
||||
->field($fields)
|
||||
->join('goods_batch spu','spu.batch_id=sku.batch_id')
|
||||
->join('goods g','g.goods_id=spu.goods_id')
|
||||
->join('manufacturer m','m.id=g.manufacturer_id')
|
||||
->where($where)->order($order_by)
|
||||
->paginate($per_page,false,['page'=>$current_page])
|
||||
->toArray();
|
||||
|
||||
$res = [];
|
||||
$res['code'] = 200;
|
||||
$res['msg'] = 'success';
|
||||
$res['data'] = $goods_list;
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品详情
|
||||
* @done 用户收藏
|
||||
* @done 已购状态(首营逻辑已变更-无需处理(默认认证即完成首营资料))
|
||||
* @done 控销采购权
|
||||
* @todo 新人价:新人对应新人活动价,老客户对应常规销售价格
|
||||
* @todo 活动商品库存管理---订单处理---goods_batch add 活动库存字段 or 操作价格表库存字段discount_number
|
||||
* @todo 活动-关联sku设置
|
||||
*
|
||||
*/
|
||||
public function getGoodsDetail($init_data,$sku_id){
|
||||
//$sku_id = input('param.sku_id');
|
||||
$login = $init_data?true:false;
|
||||
|
||||
$fields = '"0" as is_collect,g.goods_id,g.name as goods_name,g.prescribe_flag,g.pc_content,g.app_content,g.show_price,g.is_online_sale,g.country_code,g.app_thumb,g.pc_thumb,g.drug_form,g.keyword,g.sketch,m.name as manufacturer_name,g.spec_desc,';
|
||||
//限购字段
|
||||
$fields .= 'g.max_purchase,g.max_purchase_period,g.unit,';
|
||||
$fields .= 'spu.batch_id,spu.batch_type,spu.retail_flag,spu.retail_num,spu.entirety_num,spu.batch_number,spu.stock_num,spu.term_validity,spu.supplier_id,spu.supplier_sn,';
|
||||
$fields .= 'sku.id as price_id,sku.original_price,sku.area_id,sku.price,sku.price_type,sku.new_price,sku.discount_price,sku.discount_num,sku.discount_start_time,sku.discount_end_time';
|
||||
|
||||
$where = [];
|
||||
$where[] = ['g.status','=',1];
|
||||
$where[] = ['g.is_online_sale','=',0];
|
||||
$where[] = ['spu.batch_status','=',1];
|
||||
$where[] = ['spu.stock_num','>',0];
|
||||
$where[] = ['sku.is_onshelf','=',1];
|
||||
$where[] = ['sku.is_delete','=',0];
|
||||
|
||||
$detail = Db::name('goods_batch_area_relation')->alias('sku')
|
||||
->field($fields)
|
||||
->join('goods_batch spu','spu.batch_id=sku.batch_id')
|
||||
->join('goods g','spu.goods_id=g.goods_id')->join('manufacturer m','m.id=g.manufacturer_id')
|
||||
->where('sku.id',$sku_id)->find();
|
||||
|
||||
if (!$detail){
|
||||
$res = [];
|
||||
$res['code'] = -107;
|
||||
$res['message'] = '商品不存在或者已下架';
|
||||
|
||||
return $res;
|
||||
}
|
||||
//库存预处理
|
||||
$sale_pack_num = '';
|
||||
if ($detail){
|
||||
$detail['is_buy'] = 1;//是否可以加入购物车
|
||||
$sale_pack_num = $detail['retail_flag']==0?$detail['retail_num']:$detail['entirety_num'];
|
||||
if (empty($detail['pc_thumb'])){
|
||||
$detail['pc_thumb'] = $detail['app_thumb']?:self::APP_DEFAULT_IMG_URL;
|
||||
}
|
||||
if($detail['pc_thumb'] == 'www.hyey.cn'){
|
||||
$detail['pc_thumb'] = self::APP_DEFAULT_IMG_URL;
|
||||
}
|
||||
//非网处理
|
||||
if (isset($detail['is_online_sale'])&&$detail['is_online_sale']==1){
|
||||
$detail['is_buy'] = 0;
|
||||
}
|
||||
|
||||
//是否已加入购物车
|
||||
$detail['is_in_cart'] = 0;
|
||||
$detail['num_in_cart'] = 0;
|
||||
if ($login){
|
||||
$cart_where = [];
|
||||
$cart_where[] = ['user_id','=',$init_data['user_id']];
|
||||
$cart_where[] = ['price_id','=',$sku_id];
|
||||
$cart_where[] = ['price_type','=',0];//冗余-兼容代理价格
|
||||
$num_in_cart = Db::name('user_cart')->where($cart_where)->value('goods_number');
|
||||
if ($num_in_cart){
|
||||
$detail['is_in_cart'] = 1;
|
||||
$detail['num_in_cart'] = $num_in_cart;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//处理hy商品价格更新
|
||||
//@todo hy被更改为自营待处理(列表已过滤,此处待完善)
|
||||
if ($detail['supplier_id']==10006){
|
||||
if ($login){
|
||||
$extend_price_rate = $init_data['extend_price_rate']??1.05;
|
||||
$hy_price = $this->getHyPrice($detail['supplier_sn'],$extend_price_rate);
|
||||
if ($hy_price){
|
||||
$detail['price'] = $hy_price;
|
||||
}else{
|
||||
$detail['price'] = self::NO_HY_PRICE;
|
||||
$detail['is_buy'] = 0;
|
||||
}
|
||||
}else{
|
||||
$detail['price'] = '登录后查看价格';
|
||||
$detail['is_buy'] = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//价格处理:活动价(特殊情况:新人活动价)/正常销售价
|
||||
/**
|
||||
* 新人活动:
|
||||
* 1.用户新人身份判定(users表判定字段)
|
||||
* 2.新人活动判定,activity_name='新人优惠' 查询对应activity_id 绑定的商品price_id
|
||||
* 3.当前商品sku_id是否包含于2的price_id
|
||||
*/
|
||||
//存在活动价格设置为0(数据库记录 0.0000/0.00)的情况
|
||||
if ($detail && $detail['supplier_id']!=10006 && isset($detail['discount_price'])){
|
||||
|
||||
//$sale_pack_num = $detail['retail_flag']==0?$detail['retail_num']:$detail['entirety_num'];
|
||||
|
||||
//discount_start_time/discount_end_time int(10)
|
||||
//@todo 活动价格与正常销售价格都存在,且当前活动状态正常(时间有效且库存满足),只保留活动价,不展示正常销售价格(else: 显示 活动价格+正常价格 ,当前处理为不共存)
|
||||
$date = time();
|
||||
// if ($detail['discount_start_time']<$date && $detail['discount_end_time']>$date && $detail['discount_num']>=$sale_pack_num){
|
||||
if (((!$detail['discount_start_time'] && !$detail['discount_end_time']) || ($detail['discount_start_time']<$date && $detail['discount_end_time']>$date)) && ($detail['discount_num']>=$sale_pack_num || $detail['discount_num']==0)){
|
||||
if ($detail['discount_price']*10000){
|
||||
$detail['price'] = $detail['discount_price'];
|
||||
}
|
||||
//$detail['stock_num'] = $detail['discount_num'];
|
||||
//unset($detail['price']);//保留new_price,后文处理
|
||||
unset($detail['discount_price']);
|
||||
}else{
|
||||
//活动状态无效,保留常规销售价格
|
||||
unset($detail['discount_start_time']);
|
||||
unset($detail['discount_end_time']);
|
||||
unset($detail['discount_price']);
|
||||
unset($detail['new_price']);//新人价格、活动价格 默认周期一样
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//收藏状态+新人价格处理(新人活动价or普通活动价or常规销售价)
|
||||
if ($login && $detail){
|
||||
$detail['is_collect'] = 0;
|
||||
$where = [];
|
||||
$where[] = ['user_id','=',$init_data['user_id']];
|
||||
$where[] = ['goods_id','=',$detail['goods_id']];
|
||||
$user_collect = Db::name('user_collect')->where($where)->find();
|
||||
if ($user_collect){
|
||||
$detail['is_collect'] = 1;
|
||||
}
|
||||
|
||||
//新人身份,活动有效性上文已判定
|
||||
$is_new_user = $init_data['is_new_user'];
|
||||
$date = time();
|
||||
if ($is_new_user && isset($detail['new_price']) && ((!$detail['discount_start_time'] && !$detail['discount_end_time']) || ($detail['discount_start_time']<$date && $detail['discount_end_time']>$date)) && ($detail['discount_num']>=$sale_pack_num || $detail['discount_num']==0)){
|
||||
//上文已处理,活动价与常规销售价不共存
|
||||
/* if (isset($detail['price'])){
|
||||
unset($detail['price']);
|
||||
}*/
|
||||
if (isset($detail['discount_price'])){
|
||||
unset($detail['discount_price']);
|
||||
}
|
||||
if ($detail['new_price']*10000){
|
||||
$detail['price'] = $detail['new_price'];
|
||||
}
|
||||
unset($detail['new_price']);
|
||||
//$detail['stock_num'] = $detail['discount_num'];
|
||||
//$detail['discount_num'] && $detail['stock_num'] = $detail['discount_num'];
|
||||
}
|
||||
|
||||
if (!$is_new_user){
|
||||
if (isset($detail['new_price'])){
|
||||
unset($detail['new_price']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//控销采购--只针对优势商品
|
||||
if ($detail && isset($detail['batch_type']) && $detail['batch_type']==2 && $login && $detail['supplier_id']!=10006){
|
||||
$where = [];
|
||||
$where[] = ['goods_id','=',$detail['goods_id']];
|
||||
$where[] = ['user_id','=',$init_data['user_id']];
|
||||
$where[] = ['status','=',1];
|
||||
|
||||
$goods_limit_check = Db::name('goods_limit_relation')->where($where)->find();
|
||||
if ($goods_limit_check){
|
||||
switch ($goods_limit_check['status']){
|
||||
case 0:
|
||||
$detail['purchase_right']= 0;
|
||||
$detail['purchase_right_remark'] = '采购权申请中,等待审核通过后购买!';
|
||||
break;
|
||||
case 1:
|
||||
$detail['purchase_right']= 1;
|
||||
$detail['purchase_right_remark'] = '采购权已通过!';
|
||||
break;
|
||||
case 2:
|
||||
$detail['purchase_right']= 2;
|
||||
$detail['purchase_right_remark'] = '采购权申请未通过!';
|
||||
$detail['purchase_right_verify_msg'] = $goods_limit_check['verify_remark'];
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
$detail['purchase_right'] = -1;
|
||||
$detail['purchase_right_remark'] = '当前商品为控销商品,尚未未申请采购权!';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//限购处理
|
||||
if ($detail){
|
||||
$detail['is_limit'] = 0;
|
||||
//限购逻辑:优势+限购周期+限购量
|
||||
if ($detail['supplier_id']!=10006 &&isset($detail['max_purchase'])&&isset($detail['max_purchase_period'])&&$detail['max_purchase']&&$detail['max_purchase_period']){
|
||||
$detail['is_limit'] = 1;
|
||||
$detail['limit_info'] = $detail['max_purchase_period'].'天内限购'.$detail['max_purchase'].$detail['unit'];
|
||||
}
|
||||
}
|
||||
|
||||
//登录状态-价格展示
|
||||
if(!$login){
|
||||
isset($detail['price'])&&($detail['price']= '登录后查价');
|
||||
isset($detail['new_price'])&&($detail['new_price']= '登录后查价');
|
||||
isset($detail['discount_price'])&&($detail['discount_price']= '登录后查看当前价格');
|
||||
isset($detail['original_price'])&&($detail['original_price']= '登录后查看价格');
|
||||
|
||||
}
|
||||
|
||||
//价格字段统一处理成price(discount_price、new_price、price)
|
||||
//优先级 new_price》discount_price》price
|
||||
if ($detail){
|
||||
if (isset($detail['new_price']) && $detail['new_price']*10000 && isset($detail['discount_price'])&&$detail['discount_price']*10000){
|
||||
$detail['price'] = $detail['new_price']??$detail['discount_price']??$detail['price'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//存在or空或0值
|
||||
|
||||
$res = [];
|
||||
|
||||
if ($detail){
|
||||
$res['code'] = 200;
|
||||
$res['message'] = 'success';
|
||||
$res['data'] = $detail;
|
||||
}else{
|
||||
$res['code'] = -100;
|
||||
$res['message'] = '商品不存在或者已下架';
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品数据-此处实现列表+搜索;
|
||||
* 活动+专区拆分独立
|
||||
*
|
||||
* 默认搜索支持:药品名称(关键词)、分类(cate_id)、
|
||||
* 药品分类(cate_id)+活动楼层:活动(activity_id)--列表页实现?
|
||||
*/
|
||||
public function getGoodsSearch($init_data,$param){
|
||||
|
||||
$login = $init_data?true:false;
|
||||
$fields = '';
|
||||
$order = [];
|
||||
//自营排序优先级>流通
|
||||
$order['spu.supplier_id'] = 'asc';
|
||||
$where = [];
|
||||
//基础条件
|
||||
$where[] = ['g.status','=',1];
|
||||
$where[] = ['g.is_online_sale','=',0];
|
||||
$where[] = ['spu.batch_status','=',1];
|
||||
$where[] = ['spu.stock_num','>',0];
|
||||
$where[] = ['sku.is_onshelf','=',1];
|
||||
$where[] = ['sku.is_delete','=',0];
|
||||
//有效期
|
||||
$where[] = ['spu.term_validity','>',date('Y-m-d')];
|
||||
|
||||
//@todo 导致筛选条件变更的因素关联筛选条件处理
|
||||
//分类
|
||||
if (isset($param['cate_id']) && $param['cate_id']){
|
||||
//goods_id
|
||||
$goods_id_list = Db::name('goods_cate_relation')->where('cate_id',$param['cate_id'])->column('goods_id');
|
||||
if ($goods_id_list){
|
||||
$where[] = ['g.goods_id','in',$goods_id_list];
|
||||
}else{
|
||||
$where[] = ['g.goods_id','=',0];
|
||||
}
|
||||
}
|
||||
|
||||
//搜索词---暂时只处理药品名称搜索,不考虑 药品+规格+厂商等
|
||||
$search_words = $param['search_words']??'';
|
||||
if ($search_words){
|
||||
$where[] = ['g.name|g.simple_pinyin|g.pinyin','like','%'.htmlspecialchars($search_words).'%'];
|
||||
}
|
||||
|
||||
//活动:关键词存在则不查询活动
|
||||
$is_activity = false;
|
||||
if (!$search_words && isset($param['activity_id']) && $param['activity_id']){
|
||||
$activity_sku_id_list = Db::name('activity_goods_relation')->where('activity_id',$param['activity_id'])->column('price_id');
|
||||
//$where[] = ['sku.id','in',$activity_sku_id_list];
|
||||
if ($activity_sku_id_list){
|
||||
$where[] = ['sku.id','in',$activity_sku_id_list];
|
||||
$is_activity = true;
|
||||
}else{
|
||||
$where[] = ['sku.id','=',0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//零整
|
||||
$retail_flag = $param['retail_flag']??'';//取值空/0/1/
|
||||
if ($retail_flag!==''){
|
||||
$where[] = ['spu.retail_flag','=',$retail_flag];
|
||||
}
|
||||
|
||||
//剂型
|
||||
$drug_form = $param['drug_form']??'';//后期剂型--改为int+维护剂型缓存数据
|
||||
if ($drug_form!==''){
|
||||
$where[] = ['g.drug_form','=',$drug_form];
|
||||
}
|
||||
|
||||
//有效期 0:半年以上,1:一年以上,2:所有,3:近效期
|
||||
$term_validity = $param['term_validity']??2;
|
||||
if ($term_validity!==2){
|
||||
switch ($term_validity){
|
||||
case 0:
|
||||
$where[] = ['spu.term_validity','>',date('Y-m-d',strtotime('+6 month'))];
|
||||
break;
|
||||
case 1:
|
||||
$where[] = ['spu.term_validity','>',date('Y-m-d',strtotime('+1 year'))];
|
||||
break;
|
||||
case 3:
|
||||
$where[] = ['spu.term_validity','<',date('Y-m-d',strtotime('+90 day'))];
|
||||
}
|
||||
}
|
||||
|
||||
//价格区间--销售价;活动价or正常销售价处于搜索价格区间
|
||||
$price_start = $param['price_start']??'';
|
||||
$price_end = $param['price_end']??'';
|
||||
if ($price_start!=='' && $price_end!==''){
|
||||
$where[] = ['sku.price|sku.discount_price','between',[$price_start,$price_end]];
|
||||
}
|
||||
|
||||
//排序处理
|
||||
if ($is_activity){
|
||||
$order['sku.sort'] = 'desc';
|
||||
}
|
||||
$sort_field = $param['sort_field']??'';
|
||||
$sort_order = $param['sort_order']??0;
|
||||
$sort_fields_limit = ['price','default','sale','term_validity'];
|
||||
if ($sort_field && in_array_case($sort_field,$sort_fields_limit)){
|
||||
$sort_order_seq = ['asc','desc'];
|
||||
$sort_order = $sort_order_seq[(int)$sort_order]??'asc';
|
||||
switch ($sort_field){
|
||||
case 'price':
|
||||
//$order[] = ['sku.price|sku.discount_price',$sort_order];
|
||||
$order['sku.price']=$sort_order;
|
||||
break;
|
||||
case 'sale':
|
||||
$order['spu.sale_num'] = $sort_order;
|
||||
break;
|
||||
case 'term_validity':
|
||||
$order['spu.term_validity'] = $sort_order;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//默认排序
|
||||
$order['sku.sort'] = 'asc';
|
||||
$order['sku.id'] = 'desc';
|
||||
$order['spu.batch_id'] = 'desc';
|
||||
$order['g.goods_id'] = 'desc';
|
||||
//初始化信息,登录状态、认证状态
|
||||
if ($login==false){
|
||||
$fields .='"价格登录可见" as price,"价格登录可见" as original_price,"活动价格登录可见" as discount_price,';//下文处理是否为活动商品
|
||||
}else{
|
||||
$fields .='sku.price,sku.original_price as original_price, sku.discount_price,';//活动价、正常销售价?
|
||||
}
|
||||
|
||||
$fields .= 'g.goods_id,g.name as goods_name,g.max_purchase_period,g.max_purchase,g.show_price,g.is_online_sale,g.country_code,g.app_thumb,g.pc_thumb,g.drug_form,g.keyword,g.sketch,m.name as manufacturer_name,g.spec_desc,';
|
||||
//限购字段
|
||||
$fields .= 'g.max_purchase,g.max_purchase_period,g.unit,';
|
||||
|
||||
$fields .= 'spu.batch_type,spu.supplier_id,spu.supplier_sn,spu.batch_id,spu.retail_flag,spu.retail_num,spu.entirety_num,spu.batch_number,spu.stock_num,spu.term_validity,spu.supplier_sn,spu.sale_num,';
|
||||
$fields .= 'sku.id as sku_id,sku.area_id,sku.price_type,sku.discount_num,sku.discount_start_time,sku.discount_end_time';
|
||||
|
||||
//筛选条件处理
|
||||
$manufacturer_name = $param['manufacturer']??'';
|
||||
|
||||
if ($manufacturer_name){
|
||||
$where[] = ['m.name|m.simple_pinyin','like','%'.htmlspecialchars($manufacturer_name).'%'];
|
||||
}
|
||||
//分页
|
||||
$per_page = $param['per_page']??30;
|
||||
$current_page = $param['current_page']??1;
|
||||
|
||||
//查询
|
||||
/**
|
||||
* paginate 返回数据(对象类型)如下
|
||||
* [
|
||||
* 'current_page'=>$current_page,
|
||||
* 'data'=>[],//查询结果$fields数组
|
||||
* 'last_page'=>'',
|
||||
* 'per_page'=>'',
|
||||
* 'total'=>''
|
||||
* ]
|
||||
*/
|
||||
$data = Db::name('goods_batch_area_relation')->alias('sku')->field($fields)
|
||||
->join('goods_batch spu','spu.batch_id=sku.batch_id')
|
||||
->join('goods g','g.goods_id=spu.goods_id')
|
||||
->join('manufacturer m','m.id=g.manufacturer_id')
|
||||
->where($where)->order($order)//->buildSql();exit();
|
||||
->paginate($per_page,false,['page'=>$current_page])
|
||||
->toArray();
|
||||
|
||||
$extend_price_rate = $init_data['extend_price_rate']??1.05;
|
||||
$up_hy = $param['is_update_hy']??true;//is_update_hy:0/1
|
||||
$to_del_num = 0;
|
||||
|
||||
//@todo 是否已加入购物车
|
||||
/* $user_cart_data_now = [];
|
||||
$uc_price_id_data_now = [];
|
||||
$uc_supplier_sn_now = [];
|
||||
if ($login){
|
||||
$user_cart_data = Db::name('user_cart')->field('id as uc_id,batch_id,price_id,type')->where('user_id',$init_data['user_id'])->select();
|
||||
|
||||
}*/
|
||||
if ($up_hy){
|
||||
foreach ($data['data'] as $key=>$value){
|
||||
if (empty($value['pc_thumb'])){
|
||||
$data['data'][$key]['pc_thumb'] = $value['app_thumb']?:self::APP_DEFAULT_IMG_URL;
|
||||
}
|
||||
if($value['pc_thumb'] == 'www.hyey.cn'){
|
||||
$data['data'][$key]['pc_thumb'] = self::APP_DEFAULT_IMG_URL;
|
||||
}
|
||||
$data['data'][$key]['is_buy'] = $login?1:0;
|
||||
//价格处理:活动价/正常销售价处理;
|
||||
if ($value['supplier_id']!=10006 && isset($value['discount_price']) && $value['discount_price'] * 10000){
|
||||
$date = strtotime(time());
|
||||
$sale_pack_num = $value['retail_flag']==0?$value['retail_num']:$value['entirety_num'];
|
||||
//未对分页结果数量产生影响
|
||||
if (((!$value['discount_start_time'] && !$value['discount_end_time']) || ($value['discount_start_time']<$date && $value['discount_end_time']>$date)) && ($value['discount_num']>=$sale_pack_num || $value['discount_num']==0)){
|
||||
$data['data'][$key]['price'] = $data['data'][$key]['discount_price'];
|
||||
// unset($data['data'][$key]['price']);
|
||||
}else{
|
||||
unset($data['data'][$key]['discount_start_time']);
|
||||
unset($data['data'][$key]['discount_end_time']);
|
||||
unset($data['data'][$key]['discount_price']);
|
||||
unset($data['data'][$key]['discount_num']);
|
||||
}
|
||||
}
|
||||
|
||||
//非网处理
|
||||
if (isset($data['data'][$key]['is_online_sale'])&& $data['data'][$key]['is_online_sale']==1){
|
||||
$data['data'][$key]['is_buy'] = 0;
|
||||
}
|
||||
|
||||
//限购
|
||||
$data['data'][$key]['is_limit'] = 0;
|
||||
if ($value['max_purchase_period'] && $value['max_purchase'] && $value['supplier_id']!=10006){
|
||||
$data['data'][$key]['is_limit'] = 1;
|
||||
$data['data'][$key]['limit_info'] = $value['max_purchase_period'].'天内限购'.$value['max_purchase'].$value['unit'];
|
||||
}
|
||||
|
||||
if ($value['supplier_id']==10006){
|
||||
if ($value['supplier_sn']){
|
||||
if ($login){
|
||||
$hy_price = $this->getHyPrice($value['supplier_sn'],$extend_price_rate);
|
||||
if ($hy_price){
|
||||
$data['data'][$key]['price'] = $hy_price;
|
||||
}else{
|
||||
//$data['data'][$key]['price'] = self::NO_HY_PRICE;
|
||||
//$data['data'][$key]['is_buy'] = 0;
|
||||
//获取hy价格失败-改为不展示
|
||||
$to_del_num++;
|
||||
unset($data['data'][$key]);
|
||||
}
|
||||
}else{
|
||||
$data['data'][$key]['price'] = '登录后查看价格';
|
||||
$data['data'][$key]['is_buy'] = 0;
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
$to_del_num++;
|
||||
unset($data['data'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//分页+数据(索引)整理
|
||||
if ($to_del_num){
|
||||
$data['total']-=$to_del_num;
|
||||
$data['last_page'] = ceil($data['total']/$data['per_page']);
|
||||
$data['data'] = array_merge($data['data']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$res = [];
|
||||
$res['code'] = 200;
|
||||
$res['msg'] = 'success';
|
||||
$res['data'] = $data;
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取hy商品价格-丁超-20200514
|
||||
* 单独采集hy价格入库ydyd_hy_data,保持定期更新,后期查询从中获取
|
||||
* @param $supplier_sn string hy商品id
|
||||
* @param $price_rate float 折扣等级
|
||||
* @return mixed 成功返回价格-失败返回false
|
||||
*
|
||||
* hy商品字段说明
|
||||
* {
|
||||
"RN": "15",//列表序号
|
||||
"BOSS": "a0540",//
|
||||
"YPBH": "8029034",//药品编号
|
||||
"ISRETAIL": "1",//零整标志
|
||||
"ID": "A74926EE-F7D9-412E-9C38-9A46A4A48D5D",//药品id
|
||||
"YPMC": "注射用阿莫西林钠克拉维酸钾",//药品名称
|
||||
"YPDM": "ZSYAMXLNKLWSJEYK",//药品编码?
|
||||
"GG": "0.6g",//规格
|
||||
"CDMC": "苏州二叶制药有限公司",//产地名称(厂家名称)
|
||||
"CDDM": "SZEYZYYXGS",//厂家编码
|
||||
"PH": "K1190901",//批号
|
||||
"SL": "2080",//库存数量
|
||||
"BZ": "600",//包装
|
||||
"ZBZ": "10",//中包装
|
||||
"NZBZ": "10",
|
||||
"DW": "瓶",//单位
|
||||
"DJ": "会员可查",//销售定价
|
||||
"LSJ": "25",//建议零售价=国规价
|
||||
"YXQ": "2021-08",//有效期
|
||||
"PZWH": "H20045122.",//批准文号=国药准字
|
||||
"CK": "aa",//仓库?
|
||||
"JX": "粉针剂",//剂型
|
||||
"PICNAME": "/uploadpic/600/a0540/8029034/8029034_0.jpg",//图片
|
||||
"PICNAME2": "",
|
||||
"FID": "",
|
||||
"SID": "",
|
||||
"ZRPZ": "0",
|
||||
"ISG": "0",
|
||||
"FGSMC": "自营",//分公司名称?
|
||||
"FGSID": "0",//分公司id?
|
||||
"PROMOTIONID": "0",//活动id 参考电商promotion概念
|
||||
"DISCOUNTRATE": "1"//折扣
|
||||
},
|
||||
*
|
||||
*/
|
||||
public function getHyPrice($supplier_sn,$price_rate=1.05){
|
||||
$price_cache = Cache::get($supplier_sn);//false、number
|
||||
if (!$price_cache){
|
||||
$price = Db::name('hy_data')->where('sn',$supplier_sn)->limit(1)->value('price');
|
||||
if ($price){
|
||||
Cache::set($supplier_sn,$price,86400);
|
||||
$price_cache = ceil($price*$price_rate*100)/100;
|
||||
}
|
||||
}else{
|
||||
$price_cache = ceil($price_cache*$price_rate*100)/100;
|
||||
}
|
||||
return $price_cache;
|
||||
|
||||
}
|
||||
//预留华源商品校验--调用HyData类的checkHyGoods()方法(默认校验价格+库存,支持校验更多字段)
|
||||
public function checkHyGoods($supplier_sn,$price_rate=1.05){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品搜索列表
|
||||
*/
|
||||
public function searchList($parames)
|
||||
{
|
||||
if (empty($parames['name'])) {
|
||||
throw new Exception('没有你需要的药品');
|
||||
}
|
||||
|
||||
$_where = [];
|
||||
//基础条件
|
||||
$_where[] = ['g.status', '=', 1];
|
||||
$_where[] = ['spu.batch_status', '=', 1];
|
||||
$_where[] = ['spu.stock_num', '>', 0];
|
||||
$_where[] = ['sku.is_onshelf', '=', 1];
|
||||
$_where[] = ['sku.is_delete', '=', 0];
|
||||
//有效期
|
||||
$_where[] = ['spu.term_validity', '>', date('Y-m-d')];
|
||||
|
||||
//搜索
|
||||
if (isset($parames['name']) && $parames['name']) {
|
||||
//药品名称 厂商 规格 搜索
|
||||
$search_array = explode(' ', trim($parames['name']));
|
||||
|
||||
switch (count($search_array)) {
|
||||
|
||||
case 1:
|
||||
$_where[] = ['g.name|m.name|g.simple_pinyin|g.pinyin|m.simple_pinyin', 'like', '%' .$search_array[0]. '%'];
|
||||
break;
|
||||
case 2:
|
||||
$_where[] = ['g.name|m.name|g.simple_pinyin|g.pinyin|m.simple_pinyin', 'like', '%' .$search_array[0]. '%'];
|
||||
$_where[] = ['g.name|m.name|g.simple_pinyin|g.pinyin|m.simple_pinyin', 'like', '%' .$search_array[1]. '%'];
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$_fields = 'g.name,g.goods_id,m.name as manufacturer_name,spu.supplier_id,spu.supplier_sn';
|
||||
|
||||
$res = Db::name('goods_batch_area_relation')->alias('sku')->distinct(true)->field($_fields)
|
||||
->join('goods_batch spu', 'spu.batch_id=sku.batch_id')
|
||||
->join('goods g', 'g.goods_id=spu.goods_id')
|
||||
->join('manufacturer m', 'm.id=g.manufacturer_id')
|
||||
->where($_where)
|
||||
->limit(100)->select();
|
||||
|
||||
$arr_hy_goods_id = [];
|
||||
foreach ($res as $k=>$v){
|
||||
if ($v['supplier_id']==10006){
|
||||
if ($v['supplier_sn']){
|
||||
$arr_hy_goods_id[] = $v['supplier_sn'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$hy = [];
|
||||
if(count($arr_hy_goods_id)>0){
|
||||
//hy商品-有价格
|
||||
$hy = Db::name('hy_data')->where('sn','in',$arr_hy_goods_id )->column('sn');
|
||||
}
|
||||
$res2 = [];
|
||||
foreach ($res as $val){
|
||||
if(count($res2)>=10) break;
|
||||
$tmp_data = $val;
|
||||
//$tmp_data = [];
|
||||
//$tmp_data['name'] = $val['name'];
|
||||
//$tmp_data['manufacturer_name'] = $val['manufacturer_name'];
|
||||
|
||||
if( $val['supplier_id'] != 10006){
|
||||
$res2[] = $tmp_data;
|
||||
}elseif(count($hy)>0 && $val['supplier_id']== 10006 && in_array($val['supplier_sn'], $hy)){
|
||||
$res2[] = $tmp_data;
|
||||
}
|
||||
}
|
||||
//$result = array_slice($tmp_arr,0,10);
|
||||
return $res2;
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* 商品收藏
|
||||
*
|
||||
*/
|
||||
public function addCollect_App($user_id,$goods_id,$status){
|
||||
//status == 1添加收藏 2删除收藏
|
||||
if($status == 1){
|
||||
$collect_arr = explode(",", $goods_id);
|
||||
$collect_arr = array_unique($collect_arr);
|
||||
if(count($collect_arr)>0){
|
||||
//bug 备注:find只查询单条
|
||||
$__where = [];
|
||||
$__where[] = ['user_id','=',$user_id];
|
||||
$__where[] = ['goods_id','in',$collect_arr];
|
||||
$tmp = Db::name('user_collect')->where($__where)->select();
|
||||
|
||||
//严格条数一致,未收藏的继续添加收藏
|
||||
if($tmp && count($tmp)==count($collect_arr)){
|
||||
$result['errmsg'] = '商品已收藏';
|
||||
return $result;
|
||||
}
|
||||
$has_collect = [];
|
||||
if ($tmp){
|
||||
$has_collect = array_column($tmp,'goods_id');
|
||||
}
|
||||
|
||||
$add_data = [];
|
||||
//新增user_collect表数据
|
||||
foreach ($collect_arr as $v) {
|
||||
if (!in_array($v,$has_collect)){
|
||||
$tmp_add_data=[];
|
||||
$tmp_add_data['goods_id'] = $v;
|
||||
$tmp_add_data['user_id'] = $user_id;
|
||||
//$tmp_add_data['collect_time'] = date("Y-m-d H:i:s");
|
||||
$add_data[]=$tmp_add_data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (count($add_data)>0) {
|
||||
Db::startTrans();
|
||||
try{
|
||||
foreach ($add_data as $val){
|
||||
$exist = Db::name('user_collect')->where($val)->find();
|
||||
if (!$exist){
|
||||
$tmp_x = $val;
|
||||
$tmp_x['collect_time'] = date("Y-m-d H:i:s");
|
||||
$res_insert = Db::name('user_collect')->insert($tmp_x);
|
||||
if ($res_insert){
|
||||
Db::name('goods')->where('goods_id',$tmp_x['goods_id'])->setInc('collect_count');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//事务结束
|
||||
Db::commit();
|
||||
}catch (Exception $exception){
|
||||
Db::rollback();
|
||||
$result['errmsg'] = $exception->getMessage();
|
||||
return $result;
|
||||
}
|
||||
|
||||
}else{
|
||||
$result['errmsg'] = '商品已收藏';
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result['errmsg'] = '收藏成功';
|
||||
return $result;
|
||||
}else{
|
||||
$result['errmsg'] = '参数为空!';
|
||||
return $result;
|
||||
}
|
||||
|
||||
}elseif ($status == 2){
|
||||
if($goods_id){
|
||||
$goods_id = explode(',',$goods_id);
|
||||
try{
|
||||
Db::name("user_collect")->where("user_id",$user_id)->where("goods_id",'in',$goods_id)->delete();
|
||||
$result['errmsg'] = '已取消收藏';
|
||||
return $result;
|
||||
}catch (Exception $exception){
|
||||
$result['errmsg'] = $exception->getMessage();
|
||||
return $result;
|
||||
}
|
||||
}else{
|
||||
$result['errmsg'] = '参数不能为空!';
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$result['errmsg'] = '参数不合法!';
|
||||
return $result;
|
||||
|
||||
}
|
||||
/**
|
||||
* 商品收藏列表
|
||||
*
|
||||
*/
|
||||
public function Collectlsit ($params){
|
||||
|
||||
// $data = Request::only(['now_page','page_size']);
|
||||
// if(!session('user_id')){
|
||||
// $result['errcode'] = -1;
|
||||
// $result['errmsg'] = '获取收藏商品列表异常';
|
||||
// return $result;
|
||||
// }
|
||||
// $_where['a.user_id'] = $params['user_id];
|
||||
$_where['a.user_id'] = $params['user_id'];
|
||||
$_goods_join = "goods b";
|
||||
$_goods_join_on = "a.goods_id = b.goods_id";
|
||||
|
||||
$_factory_join = "manufacturer m";
|
||||
$_factory_join_on = "m.id = b.manufacturer_id";
|
||||
$_field = "a.user_id,a.goods_id,a.collect_time,b.name,b.pinyin,b.sketch,b.spec_desc,b.status,'' as show_price,b.pc_thumb,b.pc_gallery,b.pc_content,b.app_thumb,b.app_gallery,b.app_content,b.country_code,b.drug_form,m.name as factory_name";
|
||||
$_order = "a.collect_time desc";
|
||||
|
||||
// $total_count = Db::name('user_collect')->alias('a')->join($_goods_join,$_goods_join_on,"RIGHT")->join($_factory_join,$_factory_join_on,"LEFT")->where($_where)->count();
|
||||
// $total_page = ceil($total_count/$data['page_size']);
|
||||
// $list = Db::name('user_collect')->alias('a')->join($_goods_join,$_goods_join_on,"RIGHT")->join($_factory_join,$_factory_join_on,"LEFT")->page($data['now_page'],$data['page_size'])->where($_where)->field($_field)->order($_order)->select();
|
||||
$list = Db::name('user_collect')->alias('a')->join($_goods_join,$_goods_join_on,"RIGHT")->join($_factory_join,$_factory_join_on,"LEFT")->where($_where)->field($_field)->order($_order)->select();
|
||||
foreach ($list as $k=>$v){
|
||||
if ($v['pc_thumb']=='' || $v['pc_thumb']=='www.hyey.cn'){
|
||||
$list[$k]['pc_thumb'] = self::APP_DEFAULT_IMG_URL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// $result['errcode'] = 0;
|
||||
$result['errmsg'] = '获取收藏商品列表成功';
|
||||
$result['data']['list'] = $list;
|
||||
// $result['data']['total_count'] = $total_count;
|
||||
// $result['data']['total_page'] = $total_page;
|
||||
return $result;
|
||||
|
||||
}
|
||||
/**
|
||||
* 药品排行
|
||||
*
|
||||
*/
|
||||
public function goodsRanking()
|
||||
{
|
||||
$param['sort_field'] = 'sale';
|
||||
$param['sort_order'] = 1;
|
||||
$param['is_update_hy'] = 0;
|
||||
$param['per_page'] = 30;
|
||||
$result = $this->getGoodsSearch(false,$param);
|
||||
|
||||
$list = $result['data']['data']??array();
|
||||
$ret = array();
|
||||
$int = 0;
|
||||
$nameArray = [];
|
||||
foreach ($list as $k=>$item)
|
||||
{
|
||||
$item['goods_name'] = str_replace("(","(",$item['goods_name']);
|
||||
$names = explode("(",$item['goods_name']);
|
||||
$item['goods_name'] = $names[0]??'';
|
||||
if($item['goods_name']){
|
||||
if(!in_array($item['goods_name'],$nameArray)){
|
||||
$nameArray[] = $item['goods_name'];
|
||||
$i['name'] = $item['goods_name'];
|
||||
$i['goods_id'] = $item['goods_id'];
|
||||
$ret[] = $i;
|
||||
++$int;
|
||||
}
|
||||
}
|
||||
if($int>=20){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* sku详情处理和下单校验(GoodsService/OrderGoodsControlService)
|
||||
* 一、价格处理
|
||||
* 用户身份+活动价格/新人活动价/常规活动价格
|
||||
* 二、采购权
|
||||
* 三、有限购需求的商品
|
||||
*/
|
||||
|
||||
public function goodsDetailProcess(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
51
金壶/ydyd_service/application/common/service/IndexService.php
Normal file
51
金壶/ydyd_service/application/common/service/IndexService.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
|
||||
use think\Db;
|
||||
|
||||
class IndexService
|
||||
{
|
||||
|
||||
public function submitSuggestion($parames)
|
||||
{
|
||||
$add_data['user_id'] = $parames['uid'] ?? '';
|
||||
$add_data['phone'] = $parames['phone'] ?? '';
|
||||
$add_data['suggestion_content'] = $parames['suggestion_content'];
|
||||
$add_data['type'] = $parames['type'];
|
||||
$parames['pic_url'] = substr($parames['pic_url'], 8);
|
||||
$add_data['pic_url'] = explode(',', $parames['pic_url']);
|
||||
$add_data['create_time'] = date("Y-m-d H:i:s", time());
|
||||
Db::name("user_suggestion")->insert($add_data);
|
||||
$res_return['errcode'] = 0;
|
||||
$res_return['errmsg'] = "提交成功";
|
||||
return $res_return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 客服
|
||||
*
|
||||
*/
|
||||
public function custOmer($parames)
|
||||
{
|
||||
$user = Db::name('users')->alias('u')
|
||||
->leftJoin('admin_user au', 'u.custom_service_id=au.admin_user_id')
|
||||
->field('au.nickname,au.mobile')
|
||||
->where('u.user_id', $parames['user_id'])
|
||||
->find();
|
||||
if($user && $user['mobile']){
|
||||
$users[] = $user;
|
||||
}else{
|
||||
$user['nickname'] = '刘伟';
|
||||
$user['mobile'] = '18356518082';
|
||||
$users[] = $user;
|
||||
$user['nickname'] = '严可馨';
|
||||
$user['mobile'] = '13706005656';
|
||||
$users[] = $user;
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
}
|
||||
227
金壶/ydyd_service/application/common/service/JpushServer.php
Normal file
227
金壶/ydyd_service/application/common/service/JpushServer.php
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2019/8/21
|
||||
* Time: 14:25
|
||||
*/
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use JPush\Client as JPush;
|
||||
use JPush\Exceptions\APIConnectionException;
|
||||
use JPush\Exceptions\APIRequestException;
|
||||
use think\facade\Log;
|
||||
|
||||
class JpushServer
|
||||
{
|
||||
public $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new JPush(config('app_key'),config('master_secret'),config('base_url'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $content string 推送内容
|
||||
* @param $alias array 推送对象
|
||||
* @param $alert string 消息弹出内容
|
||||
* @param $param array 参数
|
||||
* @return array
|
||||
*/
|
||||
public function pushMsg($content, $alias, $alert, $param)
|
||||
{
|
||||
try{
|
||||
$this->client->push()
|
||||
|
||||
->setPlatform(['ios', 'android'])
|
||||
// 一般情况下,关于 audience 的设置只需要调用 addAlias、addTag、addTagAnd 或 addRegistrationId
|
||||
// 这四个方法中的某一个即可,这里仅作为示例,当然全部调用也可以,多项 audience 调用表示其结果的交集
|
||||
// 即是说一般情况下,下面三个方法和没有列出的 addTagAnd 一共四个,只适用一个便可满足大多数的场景需求
|
||||
|
||||
->addAlias($alias)
|
||||
//->addTag(array('tag1', 'tag2'))
|
||||
// ->addRegistrationId($registration_id)
|
||||
|
||||
->setNotificationAlert($alert)
|
||||
//->setAudience('all')
|
||||
->iosNotification(array("body" => $content, 'title' => $alert), array(
|
||||
'sound' => 'sound.caf',
|
||||
// 'badge' => '+1',
|
||||
'content-available' => true,
|
||||
// 'mutable-content' => true,
|
||||
'category' => 'jiguang',
|
||||
'extras' => $param,
|
||||
))
|
||||
->androidNotification($content, array(
|
||||
'title' => $alert,
|
||||
// 'builder_id' => 2,
|
||||
'extras' => $param,
|
||||
))
|
||||
// ->message('message content', array(
|
||||
// 'title' => 'hello jpush',
|
||||
// 'extras' => $param,
|
||||
// ))
|
||||
->options(array(
|
||||
// sendno: 表示推送序号,纯粹用来作为 API 调用标识,
|
||||
// API 返回时被原样返回,以方便 API 调用方匹配请求与返回
|
||||
// 这里设置为 100 仅作为示例
|
||||
|
||||
//'sendno' => 100,
|
||||
|
||||
// time_to_live: 表示离线消息保留时长(秒),
|
||||
// 推送当前用户不在线时,为该用户保留多长时间的离线消息,以便其上线时再次推送。
|
||||
// 默认 86400 (1 天),最长 10 天。设置为 0 表示不保留离线消息,只有推送当前在线的用户可以收到
|
||||
// 这里设置为 1 仅作为示例
|
||||
|
||||
'time_to_live' => 864000,
|
||||
|
||||
// apns_production: 表示APNs是否生产环境,
|
||||
// True 表示推送生产环境,False 表示要推送开发环境;如果不指定则默认为推送开发环境
|
||||
|
||||
'apns_production' => false,
|
||||
|
||||
// big_push_duration: 表示定速推送时长(分钟),又名缓慢推送,把原本尽可能快的推送速度,降低下来,
|
||||
// 给定的 n 分钟内,均匀地向这次推送的目标用户推送。最大值为1400.未设置则不是定速推送
|
||||
// 这里设置为 1 仅作为示例
|
||||
))
|
||||
->send();
|
||||
}catch (APIConnectionException $e) {
|
||||
Log::error($e->getMessage());
|
||||
//file_put_contents('../runtime/err.log',json_encode($e->getMessage())."\r\n", FILE_APPEND);
|
||||
} catch (APIRequestException $e) {
|
||||
Log::error($e->getMessage());
|
||||
//file_put_contents('../runtime/err.log',json_encode($e->getMessage())."\r\n", FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $content
|
||||
* @param $alert
|
||||
* @param $param
|
||||
* @param array $platform
|
||||
*/
|
||||
public function pushAllMsg($content, $alert, $param, $platform = ['ios', 'android'])
|
||||
{
|
||||
try{
|
||||
$this->client->push()
|
||||
->setPlatform($platform)
|
||||
// 一般情况下,关于 audience 的设置只需要调用 addAlias、addTag、addTagAnd 或 addRegistrationId
|
||||
// 这四个方法中的某一个即可,这里仅作为示例,当然全部调用也可以,多项 audience 调用表示其结果的交集
|
||||
// 即是说一般情况下,下面三个方法和没有列出的 addTagAnd 一共四个,只适用一个便可满足大多数的场景需求
|
||||
|
||||
//->addAlias($alias)
|
||||
//->addTag(array('tag1', 'tag2'))
|
||||
// ->addRegistrationId($registration_id)
|
||||
|
||||
->setNotificationAlert($alert)
|
||||
->setAudience('all')
|
||||
->iosNotification(array("body" => $content, 'title' => $alert), array(
|
||||
'sound' => 'sound.caf',
|
||||
// 'badge' => '+1',
|
||||
'content-available' => true,
|
||||
// 'mutable-content' => true,
|
||||
'category' => 'jiguang',
|
||||
'extras' => $param,
|
||||
))
|
||||
->androidNotification($content, array(
|
||||
'title' => $alert,
|
||||
// 'builder_id' => 2,
|
||||
'extras' => $param,
|
||||
))
|
||||
->options(array(
|
||||
// sendno: 表示推送序号,纯粹用来作为 API 调用标识,
|
||||
// API 返回时被原样返回,以方便 API 调用方匹配请求与返回
|
||||
// 这里设置为 100 仅作为示例
|
||||
|
||||
//'sendno' => 100,
|
||||
|
||||
// time_to_live: 表示离线消息保留时长(秒),
|
||||
// 推送当前用户不在线时,为该用户保留多长时间的离线消息,以便其上线时再次推送。
|
||||
// 默认 86400 (1 天),最长 10 天。设置为 0 表示不保留离线消息,只有推送当前在线的用户可以收到
|
||||
// 这里设置为 1 仅作为示例
|
||||
|
||||
// 'time_to_live' => 1,
|
||||
|
||||
// apns_production: 表示APNs是否生产环境,
|
||||
// True 表示推送生产环境,False 表示要推送开发环境;如果不指定则默认为推送开发环境
|
||||
|
||||
'apns_production' => config('app_debug'),
|
||||
|
||||
// big_push_duration: 表示定速推送时长(分钟),又名缓慢推送,把原本尽可能快的推送速度,降低下来,
|
||||
// 给定的 n 分钟内,均匀地向这次推送的目标用户推送。最大值为1400.未设置则不是定速推送
|
||||
// 这里设置为 1 仅作为示例
|
||||
|
||||
// 'big_push_duration' => 1
|
||||
))
|
||||
->send();
|
||||
}catch (APIConnectionException $e) {
|
||||
Log::error($e->getMessage());
|
||||
//file_put_contents('../runtime/aaaa.log',json_encode($e)."\r\n", FILE_APPEND);
|
||||
} catch (APIRequestException $e) {
|
||||
Log::error($e->getMessage());
|
||||
//file_put_contents('../runtime/aaaa.log',json_encode($e)."\r\n", FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//定时指定人员发送
|
||||
public function pushMsgByTime($content, $alias, $alert, $param, $time)
|
||||
{
|
||||
try{
|
||||
$payload = $this->client->push()
|
||||
->setPlatform(['ios', 'android'])
|
||||
->addAlias($alias)
|
||||
->setNotificationAlert($alert)
|
||||
->iosNotification(array("body" => $content, 'title' => $alert), array(
|
||||
'sound' => 'sound.caf',
|
||||
// 'badge' => '+1',
|
||||
'content-available' => true,
|
||||
// 'mutable-content' => true,
|
||||
'category' => 'jiguang',
|
||||
'extras' => $param,
|
||||
))
|
||||
->androidNotification($content, array(
|
||||
'title' => $alert,
|
||||
// 'builder_id' => 2,
|
||||
'extras' => $param,
|
||||
))
|
||||
->build();
|
||||
$this->client->schedule()->createSingleSchedule("每天14点发送的定时任务", $payload, array("time"=>$time));
|
||||
}catch (APIConnectionException $e) {
|
||||
Log::error($e->getMessage());
|
||||
} catch (APIRequestException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//定时发送
|
||||
public function pushAllMsgByTime($content, $alert, $param, $time)
|
||||
{
|
||||
try{
|
||||
$payload = $this->client->push()
|
||||
->setPlatform("all")
|
||||
->addAllAudience()
|
||||
->setNotificationAlert($alert)
|
||||
->iosNotification(array("body" => $content, 'title' => $alert), array(
|
||||
'sound' => 'sound.caf',
|
||||
// 'badge' => '+1',
|
||||
'content-available' => true,
|
||||
// 'mutable-content' => true,
|
||||
'category' => 'jiguang',
|
||||
'extras' => $param,
|
||||
))
|
||||
->androidNotification($content, array(
|
||||
'title' => $alert,
|
||||
// 'builder_id' => 2,
|
||||
'extras' => $param,
|
||||
))
|
||||
->build();
|
||||
$this->client->schedule()->createSingleSchedule("每天14点发送的定时任务", $payload, array("time"=>$time));
|
||||
}catch (APIConnectionException $e) {
|
||||
Log::error($e->getMessage());
|
||||
} catch (APIRequestException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
|
||||
use app\ydyd_service\model\BuyerModel;
|
||||
use app\ydyd_service\model\UserAddressModel;
|
||||
use app\ydyd_service\model\UserBankCardModel;
|
||||
use app\ydyd_service\model\UserCertificateModel;
|
||||
use app\ydyd_service\model\UsersModel;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Config;
|
||||
|
||||
class MessageService
|
||||
{
|
||||
public function send($user_id,$biz)
|
||||
{
|
||||
if(!$user_id){
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
if(!isset($biz['biz_id'])){
|
||||
throw new Exception('缺少业务ID');
|
||||
}
|
||||
if(!isset($biz['biz_type'])){
|
||||
throw new Exception('缺少业务类型');
|
||||
}
|
||||
if(!isset($biz['biz_title'])){
|
||||
throw new Exception('缺少业务标题');
|
||||
}
|
||||
$biz['user_id'] = $user_id;
|
||||
$biz['create_time'] = time();
|
||||
$biz['update_time'] = time();
|
||||
$id = Db::name('user_message')->insertGetId($biz);
|
||||
$_return['message_id'] = $id;
|
||||
return $_return;
|
||||
}
|
||||
|
||||
public function getList($parames)
|
||||
{
|
||||
if(!$parames['user_id']){
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
$search_data['page'] = 1;
|
||||
$search_data['limit'] = 2;
|
||||
if(isset($parames['page']) && $parames['page']){
|
||||
$search_data['page'] = $parames['page'];
|
||||
}
|
||||
if(isset($parames['limit']) && $parames['limit']){
|
||||
$search_data['limit'] = $parames['limit'];
|
||||
}
|
||||
$_field = '';
|
||||
$_field.='id,biz_type,biz_id,biz_title,is_read,create_time';
|
||||
$message_list = Db::name('user_message')->field($_field)->where('user_id',$parames['user_id'])->order('id','desc')->paginate($search_data['limit'], false, ['page' => $search_data['page']])->each(function($item, $key){
|
||||
$item['biz_type_text'] = '';
|
||||
switch ($item['biz_type'])
|
||||
{
|
||||
case 1:
|
||||
$item['biz_type_text'] = '订单信息';
|
||||
break;
|
||||
case 2:
|
||||
$item['biz_type_text'] = '认证审核';
|
||||
break;
|
||||
case 3:
|
||||
$item['biz_type_text'] = '售后信息';
|
||||
break;
|
||||
}
|
||||
$item['create_time'] = date("Y-m-d",$item['create_time']);
|
||||
return $item;
|
||||
});;
|
||||
return $message_list;
|
||||
}
|
||||
}
|
||||
1192
金壶/ydyd_service/application/common/service/OrderService.php
Normal file
1192
金壶/ydyd_service/application/common/service/OrderService.php
Normal file
File diff suppressed because it is too large
Load Diff
276
金壶/ydyd_service/application/common/service/PayService.php
Normal file
276
金壶/ydyd_service/application/common/service/PayService.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: HIAPAD
|
||||
* Date: 2018/9/25
|
||||
* Time: 10:48
|
||||
*/
|
||||
|
||||
namespace app\common\service;
|
||||
use app\exceptions\PayException;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Config;
|
||||
use think\facade\Log;
|
||||
use wxpayNew\lib\WxPayApi;
|
||||
use wxpayNew\WxPayConfig;
|
||||
|
||||
class PayService
|
||||
{
|
||||
/**
|
||||
* 支付宝支付
|
||||
*/
|
||||
public static function aliPayInfo($orderInfo)
|
||||
{
|
||||
$timeout_express = ceil((strtotime($orderInfo['deadline_time']) - time()) / 60);
|
||||
$bodyData = [
|
||||
'subject' => '支付宝订单',
|
||||
'timeout_express' => $timeout_express.'m',
|
||||
'product_code' => 'QUICK_MSECURITY_PAY',
|
||||
'total_amount' => floatval($orderInfo['total_amount']),
|
||||
'out_trade_no' => $orderInfo['order_sn'],
|
||||
];
|
||||
//构造参数
|
||||
$path = realpath(dirname(__FILE__).'/../../../extend/alipay');
|
||||
require_once($path . '/AopSdk.php');
|
||||
$config = Config::pull('alipay');
|
||||
$aop = new \AopClient ();
|
||||
|
||||
$aop->gatewayUrl = $config['gatewayUrl'];
|
||||
//实际上线app id需真实的
|
||||
$aop->appId = $config['app_id'];
|
||||
$aop->rsaPrivateKey = $config['merchant_private_key'];
|
||||
$aop->format = $config['format'];
|
||||
$aop->charset = $config['charset'];
|
||||
$aop->signType = $config['sign_type'];
|
||||
$aop->alipayrsaPublicKey = $config['alipay_public_key'];
|
||||
|
||||
$request = new \AlipayTradeAppPayRequest();
|
||||
$request->setNotifyUrl($config['notify_url']);
|
||||
$request->setBizContent(json_encode($bodyData));
|
||||
$response = $aop->sdkExecute($request);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝回调
|
||||
* @param $param
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function aliPayCallback($param)
|
||||
{
|
||||
Log::record('进入支付宝订单支付回调');
|
||||
$path = realpath(dirname(__FILE__).'/../../../extend/alipay');
|
||||
require_once ($path . '/pagepay'.'/service/AlipayTradeService.php');
|
||||
$config = Config::pull('alipay');
|
||||
$arr=$param;
|
||||
$alipaySevice = new \AlipayTradeService($config);
|
||||
$alipaySevice->writeLog(var_export($param,true));
|
||||
$result = $alipaySevice->check($arr);
|
||||
/* 实际验证过程建议商户添加以下校验。
|
||||
1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
|
||||
2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
|
||||
3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
|
||||
4、验证app_id是否为该商户本身。
|
||||
*/
|
||||
if($result) {//验证成功
|
||||
//请在这里加上商户的业务逻辑程序代
|
||||
//——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
|
||||
//获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表
|
||||
//商户订单号
|
||||
$out_trade_no = $param['out_trade_no'];
|
||||
//支付宝交易号
|
||||
$trade_no = $param['trade_no'];
|
||||
//交易状态
|
||||
$trade_status = $param['trade_status'];
|
||||
//接受订单支付金额
|
||||
$money = $param['total_amount'];
|
||||
//支付宝返回的seller_id
|
||||
$seller_id = $param['seller_id'];
|
||||
//支付宝返回的app_id
|
||||
$app_id = $param['app_id'];
|
||||
//如果支付出错,则做退款信息返回
|
||||
$returnData = [];
|
||||
$returnData['out_trade_no'] = $out_trade_no;
|
||||
$returnData['trade_no'] = $trade_no;
|
||||
$returnData['money'] = $money;
|
||||
if($trade_status == 'TRADE_FINISHED') {
|
||||
//判断该笔订单是否在商户网站中已经做过处理
|
||||
//如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
|
||||
//请务必判断请求时的total_amount与通知时获取的total_fee为一致的
|
||||
//如果有做过处理,不执行商户的业务程序
|
||||
//注意:
|
||||
//退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
|
||||
} else if ($trade_status == 'TRADE_SUCCESS') {
|
||||
//通过商户订单号out_trade_no获取订单详情
|
||||
$orderInfo = Db::name('order_info')->where('order_sn',$out_trade_no)->find();
|
||||
if(!$orderInfo){
|
||||
//验证失败
|
||||
throw new PayException('订单验证失败', 0, null, $returnData);
|
||||
}
|
||||
Log::record('订单支付开始:'.$orderInfo['order_id']);
|
||||
if($orderInfo['total_amount'] * 100 != $money * 100){
|
||||
//TODO 如果订单现金支付金额不符 做退款取消订单处理
|
||||
throw new PayException('订单金额不符', 0, null, $returnData);
|
||||
}
|
||||
|
||||
if($seller_id != $config['seller_id'])
|
||||
{
|
||||
//TODO 如果订单seller_id不符 做退款取消订单处理
|
||||
throw new PayException('订单seller_id不符', 0, null, $returnData);
|
||||
}
|
||||
|
||||
|
||||
if($app_id != $config['app_id'])
|
||||
{
|
||||
//TODO 如果订单app_id不符 做退款取消订单处理
|
||||
throw new PayException('订单app_id不符', 0, null, $returnData);
|
||||
}
|
||||
|
||||
if($orderInfo['status'] != 0){
|
||||
//TODO 如果订单状态不符 做退款取消订单处理
|
||||
throw new PayException('订单状态验证失败', 0, null, $returnData);
|
||||
}
|
||||
//判断该笔订单是否在商户网站中已经做过处理
|
||||
//如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
|
||||
//请务必判断请求时的total_amount与通知时获取的total_fee为一致的
|
||||
//如果有做过处理,不执行商户的业务程序
|
||||
//注意:
|
||||
//付款完成后,支付宝系统发送该交易状态通知
|
||||
//订单支付方式
|
||||
$o['pay_type'] = 5;
|
||||
$o['pay_status'] = 1;
|
||||
$o['status'] = 6;
|
||||
$o['pay_time'] = date('Y-m-d H:i:s',time());
|
||||
try{
|
||||
Db::name('order_info')->where('order_sn',$out_trade_no)->update($o);
|
||||
}catch (Exception $exception){
|
||||
throw new \app\exceptions\Exception('订单状态修改失败', 0, null, $returnData);
|
||||
}
|
||||
}
|
||||
Log::record('支付宝订单支付回调成功:'.$orderInfo['order_id']);
|
||||
//——请根据您的业务逻辑来编写程序(以上代码仅作参考)——
|
||||
return true; //请不要修改或删除
|
||||
}else {
|
||||
//验证失败
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝退款
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function aliPayRefund($returnData)
|
||||
{
|
||||
if($returnData['money'] > 0){
|
||||
$path = realpath(dirname(__FILE__).'/../../../extend/alipay/pagepay');
|
||||
require_once $path.'/service/AlipayTradeService.php';
|
||||
require_once $path.'/buildermodel/AlipayTradeRefundContentBuilder.php';
|
||||
//获取阿里支付配置
|
||||
$config = Config::pull('alipay');
|
||||
//构造参数
|
||||
$refundRequestBuilder = new \AlipayTradeRefundContentBuilder();
|
||||
$refundRequestBuilder->setOutTradeNo($returnData['out_trade_no']);
|
||||
$refundRequestBuilder->setTradeNo($returnData['trade_no'] );
|
||||
$refundRequestBuilder->setRefundAmount(number_format($returnData['money'],2,'.',''));
|
||||
$refundRequestBuilder->setRefundReason('订单退款');
|
||||
$aop = new \AlipayTradeService($config);
|
||||
$response = $aop->Refund($refundRequestBuilder);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信支付
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function wxPayInfo($orderInfo) {
|
||||
$config = Config::pull('wxpay');
|
||||
$config['noncestr'] = strtoupper(md5(uniqid(rand(10000, 99999))));
|
||||
$timeout_express = ceil((strtotime($orderInfo['create_time']) + 86400 - time()) / 60);
|
||||
if($timeout_express < 0)
|
||||
{
|
||||
throw new Exception('订单已过期');
|
||||
}
|
||||
$param = [
|
||||
'body' => '金壶订单',
|
||||
'attach' => '支付订单',
|
||||
'out_trade_no' => $orderInfo['order_sn'],
|
||||
'total_fee' => $orderInfo['total_amount'] * 100,
|
||||
'spbill_create_ip' => "0.0.0.0",
|
||||
'notify_url' => $config['NOTIFYURL'],
|
||||
'trade_type' => 'APP',
|
||||
'time_expire' => $timeout_express
|
||||
];
|
||||
$wxpay=new WxPayService();
|
||||
$wxpay->setWxpayOrderData($param);
|
||||
return $wxpay->unifiedOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信回调
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function wxPayCallback($returnData) {
|
||||
$orderInfo = Db::name('order_info')->where('order_sn',$returnData['out_trade_no'])->find();
|
||||
if(!$orderInfo){
|
||||
//验证失败
|
||||
throw new PayException('订单验证失败', 0, null, $returnData);
|
||||
}
|
||||
Log::record('订单支付开始:'.$orderInfo['order_id']);
|
||||
if($orderInfo['total_amount'] * 100 != $returnData['money'] * 100){
|
||||
//TODO 如果订单现金支付金额不符 做退款取消订单处理
|
||||
throw new PayException('订单金额不符', 0, null, $returnData);
|
||||
}
|
||||
if($orderInfo['status'] != 0){
|
||||
//TODO 如果订单状态不符 做退款取消订单处理
|
||||
throw new PayException('订单状态验证失败', 0, null, $returnData);
|
||||
}
|
||||
$orderInfo['pay_type'] = 4;
|
||||
$orderInfo['pay_status'] = 1;
|
||||
$orderInfo['status'] = 6;
|
||||
$orderInfo['pay_time'] = date('Y-m-d H:i:s',time());
|
||||
try{
|
||||
Db::name('order_info')->where('order_sn',$returnData['out_trade_no'])->update($orderInfo);
|
||||
}catch (Exception $exception){
|
||||
throw new \app\exceptions\Exception('订单状态修改失败', 0, null, $returnData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信退款
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function wxPayRefund($returnData) {
|
||||
$config = Config::pull('wxpay');
|
||||
$wxPayConfig = new WxPayConfig($config);
|
||||
try {
|
||||
$wxPayFound = new \WxPayRefund();
|
||||
$wxPayFound->SetTransaction_id($returnData['trade_no']);
|
||||
$wxPayFound->SetTotal_fee($returnData['money']);
|
||||
$wxPayFound->SetRefund_fee($returnData['money']);
|
||||
$wxPayFound->SetOut_refund_no("sdkphp" . date("YmdHis"));
|
||||
$wxPayFound->SetOp_user_id($wxPayConfig->GetMerchantId());
|
||||
$res=WxPayApi::refund($wxPayConfig,$wxPayFound);
|
||||
//返回结果处理
|
||||
if(isset($res['return_code'])){
|
||||
if($res['return_code']=='FAIL'){
|
||||
throw new Exception("退款申请失败,原因:".$res['return_msg']);
|
||||
}
|
||||
if($res['return_code']=='SUCCESS'){
|
||||
if($res['result_code']=='FAIL'){
|
||||
throw new Exception("退款申请失败,原因:".$res['err_code_des']);
|
||||
}
|
||||
if($res['result_code']=='SUCCESS'){
|
||||
return $res;//申请成功
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Exception('退款申请失败,原因:未知');
|
||||
}catch (Exception $e) {
|
||||
throw new Exception( $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\facade\AppConstant;
|
||||
use app\ydyd_service\model\UserAddressModel;
|
||||
use think\facade\Request;
|
||||
class UserAddressService
|
||||
{
|
||||
|
||||
|
||||
const addr_num_limit = 1;
|
||||
|
||||
public function makeChangeAddress($parames){
|
||||
|
||||
//$data = Request::only(['area_id','address','consignee','tel','is_default']);
|
||||
$data['consignee'] = $parames['consignee'];
|
||||
|
||||
if(preg_match('/^1\d{10}$/ ', $parames['tel']) > 0){
|
||||
$data['tel'] = $parames['tel'];
|
||||
}else{
|
||||
$res_return['errcode'] = -9;
|
||||
$res_return['errmsg'] = "手机号格式不对,请重新输入";
|
||||
return $res_return;
|
||||
}
|
||||
|
||||
$data['area_id'] = $parames['area_id'];
|
||||
|
||||
$data['address'] = $parames['address'];
|
||||
$address_id = $parames['address_id'] ??'';
|
||||
|
||||
$data['user_id'] = $parames['user_id'];
|
||||
$_where[] = ['user_id',"=",$parames['user_id']];
|
||||
// $addr_count = UserAddressModel::where($_where)->count();
|
||||
// if ($addr_count >= self::addr_num_limit && empty($address_id)) {
|
||||
// $res_return['errcode'] = -1;
|
||||
// $res_return['errmsg'] = "不能新增更多的收货地址了";
|
||||
// return $res_return;
|
||||
// }
|
||||
//默认地址只有一个
|
||||
// if ($data['is_default'] == 1) {
|
||||
// $this->cancelDefaultAddress($data);
|
||||
// }
|
||||
|
||||
if ($address_id){
|
||||
$_where[] = ["id","=",$address_id];
|
||||
$usr_add = UserAddressModel::where($_where)->find();
|
||||
if (!empty($usr_add)) {
|
||||
UserAddressModel::where($_where)->update($data);
|
||||
}else{
|
||||
$res_return['errcode'] = -1;
|
||||
$res_return['errmsg'] = "地址信息不存在, 无法更新";
|
||||
return $res_return;
|
||||
}
|
||||
}else{
|
||||
$addr = UserAddressModel::create($data);
|
||||
$address_id = $addr->id;
|
||||
}
|
||||
|
||||
$res_return['errcode'] = 0;
|
||||
$res_return['errmsg'] = "操作成功";
|
||||
$res_return['data']['id'] = $address_id;
|
||||
return $res_return;
|
||||
}
|
||||
//删除地址
|
||||
public function deleteAddress($parames){
|
||||
|
||||
$_where[] = ['user_id','=',$parames['user_id']];
|
||||
$_where[] = ['id','=',$parames['address_id']];
|
||||
UserAddressModel::where($_where)->delete();
|
||||
$res_return['errmsg'] = "删除操作成功";
|
||||
return $res_return;
|
||||
}
|
||||
|
||||
//获取地址列表
|
||||
public function getAddressList($user_id){
|
||||
$_order = array("is_default" => 'desc');
|
||||
$_field = "id, area_id, address, consignee, tel, is_default";
|
||||
$address_list = UserAddressModel::field($_field)->order($_order)->where("user_id","=",$user_id)->select();
|
||||
if($address_list){
|
||||
foreach($address_list as $k =>$v){
|
||||
|
||||
$area_list = AppConstant::getAreaList();
|
||||
|
||||
$area_name = '';
|
||||
if (isset($area_list[$v['area_id']]['grand_pa_id'])){
|
||||
$grand_pa_id = $area_list[$v['area_id']]['grand_pa_id'];
|
||||
$area_name .= $area_list[$grand_pa_id]['area_name']." - ";
|
||||
}
|
||||
if (isset($area_list[$v['area_id']]['parent_area_id'])){
|
||||
$parent_area_id = $area_list[$v['area_id']]['parent_area_id'];
|
||||
$area_name .= $area_list[$parent_area_id]['area_name']. " - ";
|
||||
}
|
||||
$area_name .= $area_list[$v['area_id']]['area_name'];
|
||||
$address_list[$k]['area_name'] = $area_name;
|
||||
|
||||
$address_list[$k]['short_consignee'] = mb_substr($v['consignee'],0,2);
|
||||
}
|
||||
}
|
||||
|
||||
$res_return['errcode'] = 0;
|
||||
$res_return['errmsg'] = "";
|
||||
$res_return['data']['list'] = $address_list;
|
||||
$res_return['data']['has_address_num'] = count($address_list);
|
||||
$left_address_num = self::addr_num_limit - count($address_list);
|
||||
$res_return['data']['left_address_num'] = $left_address_num>=0?$left_address_num:0;
|
||||
|
||||
return $res_return;
|
||||
}
|
||||
//设置默认地址
|
||||
public function setDefaultAddress($parames)
|
||||
{
|
||||
|
||||
$_where[] = ['user_id', "=", $parames['user_id']];
|
||||
$_where[] = ['id', "=", $parames['address_id']];
|
||||
$addr_result = UserAddressModel::where($_where)->find();
|
||||
|
||||
if (empty($addr_result)) {
|
||||
$res_return['errcode'] = -1;
|
||||
$res_return['errmsg'] = "配送信息不存在, 无法设为默认地址!";
|
||||
return $res_return;
|
||||
}
|
||||
|
||||
$data['user_id'] = $parames['user_id'];
|
||||
$this->cancelDefaultAddress($data);
|
||||
$updatedata['is_default'] = 1;
|
||||
$status = UserAddressModel::where($_where)->update($updatedata);
|
||||
|
||||
if ($status) {
|
||||
|
||||
$res_return['errmsg'] = "默认地址设置成功";
|
||||
} else {
|
||||
|
||||
$res_return['errmsg'] = "默认地址设置失败";
|
||||
}
|
||||
return $res_return;
|
||||
}
|
||||
|
||||
private function cancelDefaultAddress($data){
|
||||
$_where['user_id'] = $data['user_id'];
|
||||
$updatedata['is_default'] = 0;
|
||||
UserAddressModel::where($_where)->update($updatedata);
|
||||
}
|
||||
//地区三级
|
||||
public function addresss(){
|
||||
$area_list = AppConstant::getAreaList();
|
||||
return $area_list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
340
金壶/ydyd_service/application/common/service/UserCartService.php
Normal file
340
金壶/ydyd_service/application/common/service/UserCartService.php
Normal file
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
namespace app\common\service;
|
||||
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class UserCartService{
|
||||
const APP_DEFAULT_IMG_URL = 'ydyd-develop-file.oss-cn-hangzhou.aliyuncs.com/pc_shop_pic_url_1588925532218.jpg';
|
||||
public function getAll($user_data){
|
||||
$order = [];
|
||||
$order['uc.update_time'] = 'desc';
|
||||
$order['uc.id'] = 'desc';
|
||||
$fields = 'uc.id,g.name,m.name as manufacturer_name,g.pc_thumb,g.spec_desc,g.unit,uc.unit_price as price,uc.user_id,uc.price_id,';
|
||||
$fields .= 'sku.batch_id,spu.goods_id,spu.retail_flag,spu.retail_num,spu.entirety_num,spu.batch_type,';
|
||||
$fields .= 'spu.term_validity,spu.supplier_user_id,spu.supplier_id,spu.supplier_sn,spu.batch_number,spu.batch_status,';
|
||||
$fields .= 'uc.goods_number as num,1 as can_select,';
|
||||
$fields .= 'spu.stock_num,g.status,g.is_online_sale,spu.batch_status,sku.is_onshelf,sku.is_delete,';//下文校验字段
|
||||
//限购字段
|
||||
$fields .= 'g.max_purchase,g.max_purchase_period,g.unit';
|
||||
|
||||
$data = Db::name('user_cart')->alias('uc')->field($fields)->field($fields)
|
||||
->join('goods_batch_area_relation sku','uc.price_id=sku.id')
|
||||
->join('goods_batch spu','sku.batch_id=spu.batch_id')
|
||||
->join('goods g','g.goods_id=spu.goods_id')
|
||||
->join('manufacturer m','m.id=g.manufacturer_id')->order($order)
|
||||
->where('user_id',$user_data['user_id'])->select();
|
||||
//校验
|
||||
$available_goods = [];
|
||||
$inavailable_goods = [];
|
||||
if ($data && is_array($data)){
|
||||
foreach ($data as $key=>$value){
|
||||
//限购
|
||||
$data[$key]['is_limit'] = 0;
|
||||
//$data[$key]['limit_info'] = '';
|
||||
//限购逻辑:优势+限购周期+限购量
|
||||
if ($value['supplier_id']!=10006 &&isset($value['max_purchase'])&&isset($value['max_purchase_period'])&&$value['max_purchase']&&$value['max_purchase_period']){
|
||||
$data[$key]['is_limit'] = 1;
|
||||
$data[$key]['limit_info'] = $value['max_purchase_period'].'天内限购'.$value['max_purchase'].$value['unit'];
|
||||
}
|
||||
|
||||
$errmsg = '';
|
||||
if ($value['status']!=1){
|
||||
$errmsg .= '商品状态异常!';
|
||||
}
|
||||
if ($value['batch_status']!=1){
|
||||
$errmsg .= '药品已下架';
|
||||
}
|
||||
if ($value['is_online_sale']==1){
|
||||
$errmsg .= '非网售药品,请联系客服!';
|
||||
}
|
||||
if ($value['is_onshelf']==0){
|
||||
$errmsg .= '已下架!';
|
||||
}
|
||||
if ($value['is_delete']==1){
|
||||
$errmsg .= 'sku is deleted!';
|
||||
}
|
||||
//采购权限暂不校验
|
||||
|
||||
//库存
|
||||
if ($value['stock_num']<$value['num'] || $value['stock_num']<=0){
|
||||
$errmsg .= '库存不足';
|
||||
}
|
||||
$tmp_data = $data[$key];
|
||||
if (empty($tmp_data['pc_thumb'])){
|
||||
$tmp_data['pc_thumb'] = $tmp_data['app_thumb']?:self::APP_DEFAULT_IMG_URL;
|
||||
}
|
||||
if($tmp_data['pc_thumb'] == 'www.hyey.cn'){
|
||||
$tmp_data['pc_thumb'] = self::APP_DEFAULT_IMG_URL;
|
||||
}
|
||||
$tmp_data['can_select'] = 1;
|
||||
$tmp_data['total_price'] = ceil($tmp_data['price']*$tmp_data['num']*100)/100;//金额保留两位小数
|
||||
if ($errmsg){
|
||||
$tmp_data['can_select'] = 0;
|
||||
$tmp_data['warn_info'] = $errmsg;
|
||||
$inavailable_goods[] = $tmp_data;
|
||||
}else{
|
||||
$available_goods[] = $tmp_data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$res = [];
|
||||
$res['errcode'] = 200;
|
||||
$res['errmsg'] = 'SUCCESS';
|
||||
$res['data'] = ['available_goods'=>$available_goods,'inavailable_goods'=>$inavailable_goods];
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
public function addGoods($user_data,$param){
|
||||
|
||||
$price_id = $param['gba_id'];
|
||||
//立即购买
|
||||
$add_type = false;
|
||||
if (isset($param['add_type']) && $param['add_type']=='buy'){
|
||||
$add_type = true;
|
||||
}
|
||||
if (isset($param['goods_number'])){
|
||||
$param['goods_number'] = (int)$param['goods_number'];
|
||||
if ($param['goods_number']<0){
|
||||
throw new Exception('数量不能为负!',-100);
|
||||
}
|
||||
}
|
||||
|
||||
$fields = 'g.name,g.goods_id,g.max_purchase_period,g.max_purchase,g.unit,g.pc_thumb,g.pc_gallery,g.sketch,g.drug_form,g.spec_desc,g.pc_content,g.show_price,g.country_code,';
|
||||
$fields .= 'spu.stock_num,spu.batch_id,spu.batch_type,spu.retail_num,spu.batch_number,spu.retail_flag,spu.entirety_num,spu.term_validity,spu.supplier_sn,spu.supplier_id,';
|
||||
$fields .= 'm.name as manufacturer_name,';
|
||||
$fields .= 'sku.price as unit_price,sku.price_type,sku.new_price,sku.discount_price,sku.discount_num,sku.discount_start_time,sku.discount_end_time';
|
||||
$add_data = Db::name('goods_batch_area_relation')->alias('sku')->field($fields)
|
||||
->join('goods_batch spu','sku.batch_id=spu.batch_id')
|
||||
->join('goods g','spu.goods_id=g.goods_id')
|
||||
->join('manufacturer m','m.id=g.manufacturer_id')
|
||||
->where('sku.id',$price_id)->find();
|
||||
//价格处理
|
||||
$date_now = time();
|
||||
$sale_pack_num = $add_data['retail_flag']==0?$add_data['retail_num']:$add_data['entirety_num'];
|
||||
//活动价
|
||||
if ( $add_data['supplier_id']!=10006 && isset($add_data['discount_price']) && ((!$add_data['discount_start_time'] && !$add_data['discount_end_time']) || ($add_data['discount_start_time']<$date_now && $add_data['discount_end_time']>$date_now)) && ($add_data['discount_num']>=$sale_pack_num || $add_data['discount_num']==0)){
|
||||
if ($add_data['discount_price']*10000){
|
||||
$add_data['unit_price'] = $add_data['discount_price'];
|
||||
}
|
||||
|
||||
//$add_data['stock_num'] = $add_data['discount_num'];
|
||||
}
|
||||
//新人价
|
||||
if ($user_data['is_new_user']==1){
|
||||
if ( $add_data['supplier_id']!=10006 && isset($add_data['new_price']) && ((!$add_data['discount_start_time'] && !$add_data['discount_end_time']) || ($add_data['discount_start_time']<$date_now && $add_data['discount_end_time']>$date_now)) && ($add_data['discount_num']>=$sale_pack_num || $add_data['discount_num']==0)){
|
||||
if ($add_data['new_price']*10000){
|
||||
$add_data['unit_price'] = $add_data['new_price'];
|
||||
}
|
||||
|
||||
//$add_data['stock_num'] = $add_data['discount_num'];
|
||||
}
|
||||
}
|
||||
//库存校验 自营+流通
|
||||
if ($param['goods_number'] > $add_data['stock_num']){
|
||||
throw new Exception('库存不足',-156);
|
||||
}
|
||||
|
||||
if ($add_data){
|
||||
$tmp = [];
|
||||
$tmp['user_id'] = $user_data['user_id'];
|
||||
$tmp['price_type'] = $add_data['price_type'];
|
||||
$tmp['price_id'] = $price_id;
|
||||
$exist_in_cart = [];//用于下文校验购物车中是否已存在where判断
|
||||
$exist_in_cart[] = ['user_id','=',$user_data['user_id']];
|
||||
$exist_in_cart[] = ['price_type','=',$add_data['price_type']];
|
||||
$exist_in_cart[] = ['price_id','=',$price_id];
|
||||
|
||||
$tmp['batch_id'] = $add_data['batch_id'];
|
||||
$tmp['unit_price'] = $add_data['unit_price'];
|
||||
$tmp['goods_number'] = $param['goods_number'];
|
||||
$date_time = date('Y-m-d H:i:s');
|
||||
$tmp['create_time'] = $date_time;
|
||||
$tmp['update_time'] = $date_time;
|
||||
$tmp['type'] = '';
|
||||
|
||||
|
||||
//流通
|
||||
if ($add_data['supplier_id']==10006){
|
||||
$price = Db::name('hy_data')->where('sn',$add_data['supplier_sn'])->limit(1)->value('price');
|
||||
if ($price){
|
||||
$extend_price_rate = $user_data['extend_price_rate']??1.05;
|
||||
$tmp['unit_price'] = ceil($price*$extend_price_rate*100)/100;
|
||||
$tmp['batch_id'] = $add_data['supplier_sn'];//兼容pc-此处存储extend_goods_id即supplier_sn
|
||||
|
||||
$extend_data = [];
|
||||
$extend_data['name'] = $add_data['name'];
|
||||
$extend_data['unit'] = $add_data['unit'];
|
||||
$extend_data['price'] = $add_data['unit_price'];
|
||||
$extend_data['sketch'] = $add_data['sketch'];
|
||||
$extend_data['gallery'] = $add_data['pc_gallery'];
|
||||
$extend_data['can_show'] = 1;
|
||||
$extend_data['batch_id_plat'] = $add_data['batch_id']??'';//冗余存储当前batch_id(已入库)
|
||||
$extend_data['drug_form'] = $add_data['drug_form'];
|
||||
$extend_data['spec_desc'] = $add_data['spec_desc'];
|
||||
$extend_data['stock_num'] = $add_data['stock_num'];
|
||||
$extend_data['pc_content'] = $add_data['pc_content'];
|
||||
$extend_data['retail_flag'] = $add_data['retail_flag'];
|
||||
$extend_data['batch_number'] = $add_data['retail_num'];
|
||||
$extend_data['country_code'] = $add_data['country_code'];
|
||||
$extend_data['retail_num'] = $add_data['retail_num'];
|
||||
$extend_data['entirety_num'] = $add_data['entirety_num'];
|
||||
$extend_data['term_validity'] = $add_data['term_validity'];
|
||||
$extend_data['extend_goods_id'] = $add_data['supplier_sn'];
|
||||
$extend_data['manufacturer_name'] = $add_data['manufacturer_name'];
|
||||
$extend_data['show_price_int'] = (int)$add_data['show_price'];
|
||||
$extend_data['show_price_float'] = explode('.',$add_data['show_price'])[1];
|
||||
|
||||
$extend_data_json = json_encode($extend_data,JSON_UNESCAPED_UNICODE);
|
||||
$tmp['type'] = 'extend';
|
||||
$tmp['extend_data'] = $extend_data_json;
|
||||
|
||||
}else{
|
||||
throw new Exception('商品已下架!',-504);
|
||||
}
|
||||
|
||||
}
|
||||
$exist = Db::name('user_cart')->field('id as uc_id,goods_number,user_id,price_id')->where($exist_in_cart)->find();
|
||||
|
||||
//自营商品控销权限
|
||||
if (isset($add_data['batch_type']) && $add_data['batch_type']==2 && $add_data['supplier_id']!=10006){
|
||||
$cart_num_now = $exist['goods_number']??0;
|
||||
$check_array = $this->checkPurchaseAuth($user_data['user_id'],$add_data['goods_id']);
|
||||
if ($check_array['errcode']!==200){
|
||||
throw new Exception($check_array['errmsg'],$check_array['errcode']);
|
||||
}
|
||||
|
||||
}
|
||||
//限购-自营商品
|
||||
if ($add_data['supplier_id']!=10006 && $add_data['max_purchase_period'] && $add_data['max_purchase']){
|
||||
$cart_num_now = $exist['goods_number']??0;
|
||||
$to_add_now = $param['goods_number']??0;
|
||||
$check_array = $this->checkMaxPurchase($user_data['user_id'],$add_data,$cart_num_now,$to_add_now);
|
||||
if ($check_array['errcode']!==200){
|
||||
throw new Exception($check_array['errmsg'],$check_array['errcode']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($exist){
|
||||
$uc_id = $exist['uc_id'];
|
||||
//非立即购买情况下,进行累加;立即购买情况下直接更新为当前提交数量
|
||||
if (!$add_type){
|
||||
$tmp['goods_number'] += $exist['goods_number'];
|
||||
}
|
||||
|
||||
$tmp['id'] = $uc_id;
|
||||
//首次加入购物车时间不更新
|
||||
unset($tmp['create_time']);
|
||||
Db::name('user_cart')->update($tmp);
|
||||
|
||||
}else{
|
||||
$uc_id = Db::name('user_cart')->insertGetId($tmp);
|
||||
}
|
||||
|
||||
if ($uc_id){
|
||||
$res = [];
|
||||
$res['errcode'] = 200;
|
||||
$res['errmsg'] = 'SUCCESS';
|
||||
$res['uc_id'] = $uc_id;
|
||||
|
||||
return $res;
|
||||
}else{
|
||||
throw new Exception('系统异常',-506);
|
||||
}
|
||||
|
||||
}else{
|
||||
throw new Exception('商品已下架',-505);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 采购权-控销
|
||||
*/
|
||||
public function checkPurchaseAuth($user_id,$goods_id){
|
||||
$where = [];
|
||||
$where[] = ['goods_id','=',$goods_id];
|
||||
$where[] = ['user_id','=',$user_id];
|
||||
$where[] = ['status','=',1];
|
||||
$res = [];
|
||||
$goods_limit_check = Db::name('goods_limit_relation')->where($where)->find();
|
||||
if ($goods_limit_check){
|
||||
switch ($goods_limit_check['status']){
|
||||
case 0:
|
||||
$res['errcode'] = 500;
|
||||
$res['errmsg'] = '采购权申请中,等待审核通过后购买!';
|
||||
break;
|
||||
case 1:
|
||||
$res['errcode'] = 200;
|
||||
$res['errmsg'] = '采购权已通过!';
|
||||
break;
|
||||
case 2:
|
||||
$res['errcode'] = 700;
|
||||
$res['errmsg'] = '采购权申请未通过!请咨询客服!';
|
||||
}
|
||||
}else{
|
||||
$res['errcode'] = -1;
|
||||
$res['errmsg'] = '当前商品为控销商品,尚未未申请采购权!';
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 限购处理
|
||||
* @param $user_id Int 用户id
|
||||
* @param $goods_data array 限购商品数据
|
||||
* @param $cart_num_now Int 购物车商品数量
|
||||
* @return array
|
||||
*/
|
||||
public function checkMaxPurchase($user_id,$goods_data,$cart_num_now=0,$to_add_now=0){
|
||||
//判断药品是否设了购买数量设置,未限制的max_purchase_period为0,不进入该处理过程
|
||||
$res_result = [];
|
||||
if ($goods_data['max_purchase_period']){
|
||||
$day_limit = $goods_data['max_purchase_period'];
|
||||
$limit_time = date("Y-m-d H:i:s",strtotime("- $day_limit days"));//截止至当前时间的该时间周期内
|
||||
$_where = [];
|
||||
$_where[] = ['oi.user_id','=',$user_id];
|
||||
$_where[] = ['oi.status','in',[0,1,6,7]];
|
||||
$_where[] = ['oi.create_time','>',$limit_time];
|
||||
$_where[] = ['og.goods_id','=',$goods_data['goods_id']];
|
||||
//上述时间周期内已购买商品数量总和
|
||||
$bought_goods_num = Db::name("order_info")->alias("oi")->join("order_goods og","oi.order_id = og.order_id")->where($_where)->sum("og.goods_number");
|
||||
|
||||
//可采购数量待处理; 标准 $can_buy_num = $goods_info['max_purchase'] - $bought_goods_num;(该值(负数、0、正数 )+ 包装数量)
|
||||
if ($goods_data['max_purchase'] <= $bought_goods_num){
|
||||
$res_result['errcode'] = -1;
|
||||
$res_result['errmsg'] = "限购商品,最近限购周期内已达最大采购量";//购物车中处理成失效商品?
|
||||
}else{
|
||||
|
||||
$can_put_in_cart_num = $goods_data['max_purchase'] - $bought_goods_num - $cart_num_now-$to_add_now;
|
||||
if ($can_put_in_cart_num>=0){
|
||||
//不阻断,允许继续加入购物车
|
||||
$res_result['errcode'] = 200;
|
||||
$res_result['errmsg'] = 'SUCCESS';
|
||||
}else{
|
||||
//阻断
|
||||
$res_result['errcode'] = 500;
|
||||
$res_result['errmsg'] = '限购商品,已达到最大可购买量';
|
||||
//$res_result['errmsg'] = '限购商品,'.$day_limit.'天内限购'.$goods_data['max_purchase'].$goods_data['unit'].',最近'.$day_limit.'天内已购'.$bought_goods_num.$goods_data['unit'].',当前最多可继续加入购物车'.$can_put_in_cart_num.$goods_data['unit'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
$res_result['errcode'] = 200;
|
||||
$res_result['errmsg'] = 'SUCCESS';
|
||||
}
|
||||
|
||||
return $res_result;
|
||||
}
|
||||
|
||||
}
|
||||
352
金壶/ydyd_service/application/common/service/UserService.php
Normal file
352
金壶/ydyd_service/application/common/service/UserService.php
Normal file
@@ -0,0 +1,352 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
|
||||
use app\api\controller\ApiController;
|
||||
use app\facade\AppConstant;
|
||||
use app\ydyd_service\model\BuyerModel;
|
||||
use app\ydyd_service\model\UserAddressModel;
|
||||
use app\ydyd_service\model\UserBankCardModel;
|
||||
use app\ydyd_service\model\UserCertificateModel;
|
||||
use app\ydyd_service\model\UsersModel;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Config;
|
||||
use think\facade\Log;
|
||||
|
||||
class UserService
|
||||
{
|
||||
public function checkAuth($params)
|
||||
{
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
$buy = BuyerModel::where("buyer_user_id", "=", $params['user_id'])->find();
|
||||
if (!$buy) {
|
||||
return 'authBaisc';
|
||||
}
|
||||
$count = UserCertificateModel::where([["user_id", "=", $params['user_id']], ["role_type", "=", "buyer"]])->count();
|
||||
if (!$count) {
|
||||
return 'authCertificate';
|
||||
}
|
||||
$count = UserBankCardModel::where("user_id", "=", $params['user_id'])->count();
|
||||
if (!$count) {
|
||||
return 'authBank';
|
||||
}
|
||||
// $status = UsersModel::where("user_id", "=", $params['user_id'])->value('buyer_status');
|
||||
if($buy['verify_status'] == 0){
|
||||
return 'auditing';
|
||||
}
|
||||
if($buy['verify_status'] == 2){
|
||||
return 'waiting';
|
||||
}
|
||||
if($buy['verify_status'] == 1){
|
||||
return 'finish';
|
||||
}
|
||||
}
|
||||
|
||||
public function authBaisc($params)
|
||||
{
|
||||
try {
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
if (!isset($params['name']) || !$params['name'] || $params['name'] == 'undefined') {
|
||||
throw new Exception('企业名称不能为空');
|
||||
}
|
||||
if (!isset($params['sub_type']) || !$params['sub_type'] || $params['sub_type'] == 'undefined') {
|
||||
throw new Exception('请先选择企业类型');
|
||||
}
|
||||
if (!isset($params['consignee']) || !$params['consignee'] || $params['consignee'] == 'undefined') {
|
||||
throw new Exception('联系人不能为空');
|
||||
}
|
||||
if (!isset($params['phone']) || !$params['phone'] || $params['phone'] == 'undefined' || !is_numeric($params['phone']) || !is_mobile($params['phone'])) {
|
||||
throw new Exception('手机号码不正确');
|
||||
}
|
||||
if(isset($params['area_id']) && $params['area_id'] || $params['phone'] != 'area_id'){
|
||||
$area_id = explode("-",$params['area_id']);
|
||||
if(count($area_id) == 3){
|
||||
$params['area_id'] = $area_id[2];
|
||||
}
|
||||
}else{
|
||||
throw new Exception('注册区域不能为空');
|
||||
}
|
||||
if(isset($params['business_address']) && $params['business_address'] == 'undefined'){
|
||||
$params['business_address'] = '';
|
||||
}
|
||||
Db::startTrans();
|
||||
//buyer表部分
|
||||
$buy = BuyerModel::where("buyer_user_id", "=", $params['user_id'])->find();
|
||||
$buyer_data['buyer_user_id'] = $params['user_id'];
|
||||
$buyer_data['name'] = $params['name'];
|
||||
$buyer_data['sub_type'] = $params['sub_type'];
|
||||
$buyer_data['business_address'] = $params['business_address'];
|
||||
$buyer_data['area_id'] = $params['area_id'];
|
||||
$buyer_data['consignee'] = $params['consignee'] ?? '';
|
||||
$buyer_data['tel'] = $params['phone'] ?? '';
|
||||
if ($buy) {
|
||||
$buyer_data['verify_status'] = 0;
|
||||
$buyer_data['business_address'] = $buyer_data['business_address'] ?? '';
|
||||
BuyerModel::where("buyer_user_id", "=", $params['user_id'])->update($buyer_data);
|
||||
if($buy['sub_type'] != $buyer_data['sub_type']){
|
||||
UserCertificateModel::where([["user_id", "=", $params['user_id']], ["role_type", "=", "buyer"]])->delete();
|
||||
}
|
||||
} else {
|
||||
$apply_time_string = date('Y-m-d H:i:s', time());
|
||||
$to_insert_data = $buyer_data;
|
||||
$to_insert_data['apply_time'] = $apply_time_string;
|
||||
BuyerModel::create($buyer_data);
|
||||
UserCertificateModel::where([["user_id", "=", $params['user_id']], ["role_type", "=", "buyer"]])->delete();
|
||||
}
|
||||
|
||||
//地址部分
|
||||
$usr_addr = Db::name("user_address")->where('user_id', $params['user_id'])->find();
|
||||
$addr_data['user_id'] = $params['user_id'];
|
||||
$addr_data['area_id'] = $params['area_id'];
|
||||
$addr_data['address'] = $params['business_address'] ?? '';
|
||||
$addr_data['consignee'] = $params['consignee'] ?? '';
|
||||
$addr_data['tel'] = $params['phone'] ?? '';
|
||||
if ($usr_addr) {
|
||||
UserAddressModel::where('user_id', $params['user_id'])->update($addr_data);
|
||||
} else {
|
||||
UserAddressModel::create($addr_data);
|
||||
}
|
||||
|
||||
//客服部分
|
||||
if (isset($params['service_number']) && $params['service_number']) {
|
||||
$cs_user_id = Db::name('admin_user')->where(['cs_code' => $params['service_number'], 'cs_status' => 1])->value('admin_user_id');
|
||||
if ($cs_user_id) {
|
||||
$update_data['custom_service_id'] = $cs_user_id;
|
||||
$update_data['custom_service_type'] = 2;
|
||||
$update_data['cs_assign_time'] = date('Y-m-d H:i:s',time());
|
||||
UsersModel::where(['user_id' => $params['user_id']])->update($update_data);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $exception) {
|
||||
Db::rollback();
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function viewBaisc($params)
|
||||
{
|
||||
try {
|
||||
$ret = [];
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
$count = Db::name('buyer')->where("buyer_user_id", "=", $params['user_id'])->count();
|
||||
if (!$count) {
|
||||
return $ret;
|
||||
}
|
||||
//buyer表部分
|
||||
$buyer_data = Db::name('buyer')->where("buyer_user_id", "=", $params['user_id'])
|
||||
->field('buyer_user_id,area_id,name,business_address,sub_type,consignee,tel')->find();
|
||||
if($buyer_data){
|
||||
if($buyer_data['business_address'] == 'undefined'){
|
||||
$buyer_data['business_address'] = '';
|
||||
}
|
||||
$ret = $buyer_data;
|
||||
$area_list = AppConstant::getAreaList();
|
||||
$area_name = [];
|
||||
if (isset($area_list[$buyer_data['area_id']]['grand_pa_id'])){
|
||||
$grand_pa_id = $area_list[$buyer_data['area_id']]['grand_pa_id'];
|
||||
$area_name[]['area_name'] = $area_list[$grand_pa_id]['area_name'];
|
||||
}
|
||||
if (isset($area_list[$buyer_data['area_id']]['parent_area_id'])){
|
||||
$parent_area_id = $area_list[$buyer_data['area_id']]['parent_area_id'];
|
||||
$area_name[]['area_name'] = $area_list[$parent_area_id]['area_name'];
|
||||
}
|
||||
$area_name[]['area_name'] = $area_list[$buyer_data['area_id']]['area_name'];
|
||||
$ret['area_name'] = $area_name;
|
||||
//客服部分
|
||||
$custom_service_id = Db::name('users')->where(['user_id' => $params['user_id']])->value('custom_service_id');
|
||||
$ret['service_number'] = Db::name('admin_user')->where(['admin_user_id' => $custom_service_id])->value('cs_code');
|
||||
$ret['service_number'] = $ret['service_number']?:'';
|
||||
}
|
||||
return $ret;
|
||||
} catch (Exception $exception) {
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function authCertificate($params)
|
||||
{
|
||||
try {
|
||||
// Log::error(json_encode($params));
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
if (!isset($params['role_type']) || !$params['role_type']) {
|
||||
throw new Exception('角色不能为空');
|
||||
}
|
||||
Db::startTrans();
|
||||
$sub_type = BuyerModel::where("buyer_user_id", "=", $params['user_id'])->value('sub_type');
|
||||
$params['sub_type'] = $sub_type;
|
||||
// UserBankCardModel::where("user_id", "=", $params['user_id'])->delete();
|
||||
//UserCertificate表部分
|
||||
if (isset($params['sub_type'])) {
|
||||
$buyer_role_cert_info = Config::get('const.ROLE_CERT_INFO')['buyer']['sub_type'][$params['sub_type']]['certificate_list'];
|
||||
$add_data = [];
|
||||
UserCertificateModel::where("user_id", "=", $params['user_id'])->where("role_type", "=", $params['role_type'])->delete();
|
||||
foreach ($params as $k => $url) {
|
||||
if(isset($buyer_role_cert_info[$k])){
|
||||
// Log::error($k.':'.$url);
|
||||
$tmp = [];
|
||||
if ((!$url || $url=='undefined') && $buyer_role_cert_info[$k]) {
|
||||
$name = get_certificate_type_text($k);
|
||||
throw new Exception($name.'资质证明不能为空');
|
||||
}
|
||||
$url = str_replace('https://','',$url);
|
||||
$url = str_replace('http://','',$url);
|
||||
$tmp['user_id'] = $params['user_id'];
|
||||
$tmp['role_type'] = $params['role_type'];
|
||||
$tmp['certificate_type'] = $k;
|
||||
$tmp['img_url'] = $url;
|
||||
$add_data[] = $tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($add_data) && $add_data) {
|
||||
$obj = new UserCertificateModel;
|
||||
$obj->saveAll($add_data);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $exception) {
|
||||
Db::rollback();
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function viewCertificate($params)
|
||||
{
|
||||
try {
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
$sub_type = BuyerModel::where("buyer_user_id", "=", $params['user_id'])->value('sub_type');
|
||||
if(!$sub_type){
|
||||
return [];
|
||||
}
|
||||
$array = UserCertificateModel::where([["user_id", "=", $params['user_id']], ["role_type", "=", 'buyer']])->column('certificate_type,img_url');
|
||||
$list = Config::get('const.ROLE_CERT_INFO')['buyer']['sub_type'][$sub_type];
|
||||
if(!isset($list['certificate_list'])){
|
||||
throw new Exception('企业类型不存在');
|
||||
}
|
||||
$data = $list['certificate_list'];
|
||||
$ret = [];
|
||||
foreach ($data as $k=>$v)
|
||||
{
|
||||
$item = [];
|
||||
$item['value'] = $k;
|
||||
$item['name'] = get_certificate_type_text($k);
|
||||
$item['required'] = $v;
|
||||
$item['image'] = $item['required']?get_certificate_type_img($k):'';
|
||||
$item['path'] = [];
|
||||
if($array && isset($array[$k]) && $array[$k] && $array[$k] != 'undefined'){
|
||||
$item['path'][] = 'https://'.$array[$k];
|
||||
}
|
||||
$ret[] = $item;
|
||||
}
|
||||
return $ret;
|
||||
} catch (Exception $exception) {
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function authBank($params)
|
||||
{
|
||||
try {
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
Log::info('user_id:'.$params['user_id']);
|
||||
Log::info('json:'.json_encode($params));
|
||||
if (!isset($params['invoice_rise']) || !$params['invoice_rise']) {
|
||||
throw new Exception('发票抬头不能为空');
|
||||
}
|
||||
if($params['invoice_rise'] == 'undefined'){
|
||||
$params['invoice_rise'] = '';
|
||||
}
|
||||
if (!isset($params['tax_number']) || !$params['tax_number'] || $params['tax_number'] == 'undefined') {
|
||||
throw new Exception('纳税人识别码不能为空');
|
||||
}
|
||||
if (!isset($params['bank_name']) || !$params['bank_name'] || $params['bank_name'] == 'undefined') {
|
||||
throw new Exception('开户行不能为空');
|
||||
}
|
||||
if (!isset($params['bank_account']) || !$params['bank_account'] || $params['bank_account'] == 'undefined') {
|
||||
throw new Exception('对公账号不能为空');
|
||||
}
|
||||
Db::startTrans();
|
||||
UserBankCardModel::where("user_id", "=", $params['user_id'])->delete();
|
||||
//UserBank表部分
|
||||
$bank_data['user_id'] = $params['user_id'];
|
||||
$bank_data['bank_name'] = $params['bank_name'] ?? '';
|
||||
$bank_data['bank_account'] = $params['bank_account'] ?? '';
|
||||
// $bank_data['account_name'] = $params['account_name'] ?? '';
|
||||
$bank_data['create_time'] = date('Y-m-d H:i:s',time());
|
||||
$buy_data['invoice_title'] = $params['invoice_rise'];
|
||||
$buy_data['tax_number'] = $params['tax_number'];
|
||||
$buy_data['invoice'] = 2;
|
||||
Db::name('buyer')->where('buyer_user_id', "=", $params['user_id'])->update($buy_data);
|
||||
if (isset($bank_data) && $bank_data) {
|
||||
$obj = new UserBankCardModel;
|
||||
$obj->save($bank_data);
|
||||
|
||||
Db::name('users')->where('user_id', "=", $params['user_id'])->update(['buyer_status'=>2]);
|
||||
Db::name('buyer')->where('buyer_user_id', "=", $params['user_id'])->update(['verify_status'=>0]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $exception) {
|
||||
Db::rollback();
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function viewBank($params)
|
||||
{
|
||||
try {
|
||||
$ret['is_new'] = false;
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
$count = UserBankCardModel::where("user_id", "=", $params['user_id'])->count();
|
||||
if (!$count) {
|
||||
$ret['is_new'] = true;
|
||||
return $ret;
|
||||
}
|
||||
$bank_data = Db::name('user_bank_card')->where("user_id", "=", $params['user_id'])->find();
|
||||
$buy_data = Db::name('buyer')->where('buyer_user_id', "=", $params['user_id'])->field('invoice_title,tax_number')->find();
|
||||
|
||||
if($bank_data && $buy_data){
|
||||
$ret = array_merge($bank_data,$buy_data);
|
||||
}
|
||||
return $ret;
|
||||
} catch (Exception $exception) {
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//修改密码
|
||||
public function editPassword($params)
|
||||
{
|
||||
try {
|
||||
//更新users表数据
|
||||
$secure_password_key = (string)mt_rand(100000, 999999);
|
||||
$adddata['password'] = md5($params['password'] . $secure_password_key);
|
||||
$adddata['secure_password_key'] = $secure_password_key;
|
||||
|
||||
$user_id = Db::name('users')->where('phone', $params['phone'])->update($adddata);
|
||||
Db::commit();
|
||||
return $user_id;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
131
金壶/ydyd_service/application/common/service/WxPayService.php
Normal file
131
金壶/ydyd_service/application/common/service/WxPayService.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: HIAPAD
|
||||
* Date: 2018/9/25
|
||||
* Time: 10:48
|
||||
*/
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use think\Exception;
|
||||
use think\facade\Config;
|
||||
use wxpayNew\lib\WxPayApi;
|
||||
use wxpayNew\WxPayConfig;
|
||||
|
||||
class WxPayService
|
||||
{
|
||||
private $wxPayConfig;//配置对象
|
||||
private $unifiedOrderObj;//统一下单输入对象
|
||||
private $config;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = Config::pull('wxpay');
|
||||
$this->wxPayConfig = new WxPayConfig($this->config);
|
||||
}
|
||||
|
||||
//统一下单
|
||||
public function setWxpayOrderData($data)
|
||||
{
|
||||
$this->unifiedOrderObj = new \WxPayUnifiedOrder();
|
||||
$this->unifiedOrderObj->SetBody($data['body']);
|
||||
$this->unifiedOrderObj->SetAttach($data['attach'] ?? 'test');//设置附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
|
||||
$this->unifiedOrderObj->SetOut_trade_no($data['out_trade_no']);
|
||||
$this->unifiedOrderObj->SetTotal_fee($data['total_fee']);
|
||||
$this->unifiedOrderObj->SetTime_start(date("YmdHis"));
|
||||
$this->unifiedOrderObj->SetTime_expire(date("YmdHis", time() + $data['time_expire']));
|
||||
$this->unifiedOrderObj->SetNotify_url($this->config['NOTIFYURL']);
|
||||
$this->unifiedOrderObj->SetTrade_type($data['trade_type']);
|
||||
}
|
||||
|
||||
//统一下单
|
||||
public function unifiedOrder()
|
||||
{
|
||||
$res = WxPayApi::unifiedOrder($this->wxPayConfig, $this->unifiedOrderObj);
|
||||
if ($res['return_code'] == "SUCCESS" && $res['result_code'] == "SUCCESS") {
|
||||
//根据微信支付返回的结果进行二次签名
|
||||
//二次签名剩余参数的补充
|
||||
$result = array(
|
||||
"appid" => $this->config['WXAPPID'],
|
||||
"partnerid" => $this->config['WXMCHID'],
|
||||
"prepayid" => $res['prepay_id'],
|
||||
"noncestr" => strtoupper(md5(uniqid(rand(10000, 99999)))),
|
||||
"package" => "Sign=WXPay",
|
||||
"timestamp" => time() . ""
|
||||
);
|
||||
|
||||
$sign = self::getSign($result, $this->config['WXKEY'], $this->config['SIGNTYPE']);
|
||||
|
||||
$result['sign'] = $sign;
|
||||
return $result;
|
||||
} else {
|
||||
throw new Exception('支付请求出现异常');
|
||||
}
|
||||
}
|
||||
|
||||
//二次签名
|
||||
private static function getSign($arr, $appkey, $signType = 'md5')
|
||||
{
|
||||
ksort($arr);
|
||||
|
||||
$strInfo = '';
|
||||
foreach ($arr as $key => $val) {
|
||||
if ($val === '') {
|
||||
continue;
|
||||
}
|
||||
if ($strInfo) {
|
||||
$strInfo .= "&" . $key . "=" . $val;
|
||||
} else {
|
||||
$strInfo = $key . "=" . $val;
|
||||
}
|
||||
}
|
||||
$strInfo = trim($strInfo, "&");
|
||||
if ($signType == 'md5') {
|
||||
return strtoupper(md5($strInfo . '&key=' . $appkey));
|
||||
} elseif ($signType == 'sha1') {
|
||||
return sha1($strInfo . '&key=' . $appkey);
|
||||
} elseif ($signType == "HMAC-SHA256") {
|
||||
return hash_hmac("sha256", $strInfo . '&key=' . $appkey, $appkey);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $transaction_id 微信订单号
|
||||
* @param $total_fee 订单总金额
|
||||
* @param $refund_fee 退款金额,不超过订单总金额
|
||||
* @return \wxpayNew\lib\成功时返回,其他抛异常
|
||||
* @throws Exception
|
||||
* @throws \wxpayNew\lib\WxPayException
|
||||
*/
|
||||
public function refund($transaction_id,$total_fee,$refund_fee)
|
||||
{
|
||||
try {
|
||||
$wxPayFound = new \WxPayRefund();
|
||||
$wxPayFound->SetTransaction_id($transaction_id);
|
||||
$wxPayFound->SetTotal_fee($total_fee);
|
||||
$wxPayFound->SetRefund_fee($refund_fee);
|
||||
$wxPayFound->SetOut_refund_no("sdkphp" . date("YmdHis"));
|
||||
$wxPayFound->SetOp_user_id($this->wxPayConfig->GetMerchantId());
|
||||
$res=WxPayApi::refund($this->wxPayConfig,$wxPayFound);
|
||||
//返回结果处理
|
||||
if(isset($res['return_code'])){
|
||||
if($res['return_code']=='FAIL'){
|
||||
throw new Exception("退款申请失败,原因:".$res['return_msg']);
|
||||
}
|
||||
if($res['return_code']=='SUCCESS'){
|
||||
if($res['result_code']=='FAIL'){
|
||||
throw new Exception("退款申请失败,原因:".$res['err_code_des']);
|
||||
}
|
||||
if($res['result_code']=='SUCCESS'){
|
||||
return $res;//申请成功
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Exception('退款申请失败,原因:未知');
|
||||
}catch (Exception $e) {
|
||||
throw new Exception( $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user