mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-01-25 12:38:13 +00:00
删除2.5小程序模块
This commit is contained in:
parent
7e4041ee32
commit
58f76bc3a1
@ -1,182 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 流年 <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 应用公共文件
|
||||
if(!function_exists('unThumb')){
|
||||
function unThumb($src){
|
||||
return str_replace('/s_','/',$src);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*判断拼团是否结束*/
|
||||
function isPinkStatus($pink){
|
||||
if(!$pink) return false;
|
||||
return \app\wap\model\store\StorePink::isSetPinkOver($pink);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置浏览信息
|
||||
* @param $uid
|
||||
* @param int $product_id
|
||||
* @param int $cate
|
||||
* @param string $type
|
||||
* @param string $content
|
||||
* @param int $min
|
||||
*/
|
||||
function setView($uid,$product_id=0,$cate=0,$type='',$content='',$min=20){
|
||||
$Db=think\Db::name('store_visit');
|
||||
$view=$Db->where(['uid'=>$uid,'product_id'=>$product_id])->field('count,add_time,id')->find();
|
||||
if($view && $type!='search'){
|
||||
$time=time();
|
||||
if(($view['add_time']+$min)<$time){
|
||||
$Db->where(['id'=>$view['id']])->update(['count'=>$view['count']+1,'add_time'=>time()]);
|
||||
}
|
||||
}else{
|
||||
$cate = explode(',',$cate)[0];
|
||||
$Db->insert([
|
||||
'add_time'=>time(),
|
||||
'count'=>1,
|
||||
'product_id'=>$product_id,
|
||||
'cate_id'=>$cate,
|
||||
'type'=>$type,
|
||||
'uid'=>$uid,
|
||||
'content'=>$content
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建海报图片
|
||||
* @param array $product
|
||||
* @return bool|string
|
||||
*/
|
||||
function createPoster($product = array()){
|
||||
header("Content-type: image/jpg");
|
||||
$filePath = 'public/uploads/poster/'.time().'.jpg';
|
||||
$dir = iconv("UTF-8", "GBK", "public/uploads/poster");
|
||||
if(!file_exists($dir)) mkdir($dir,0775,true);
|
||||
$config = array(
|
||||
'text'=>array(
|
||||
array(
|
||||
'text'=>substr(iconv_substr($product['store_name'],0,mb_strlen($product['store_name']),'utf-8'),0,24).'...',
|
||||
'left'=>50,
|
||||
'top'=>500,
|
||||
'fontPath'=>ROOT_PATH.'public/static/font/simsunb.ttf', //字体文件
|
||||
'fontSize'=>16, //字号
|
||||
'fontColor'=>'40,40,40', //字体颜色
|
||||
'angle'=>0,
|
||||
),
|
||||
array(
|
||||
'text'=>'¥'.$product['price'],
|
||||
'left'=>50,
|
||||
'top'=>580,
|
||||
'fontPath'=>ROOT_PATH.'public/static/font/simsunb.ttf', //字体文件
|
||||
'fontSize'=>16, //字号
|
||||
'fontColor'=>'40,40,40', //字体颜色
|
||||
'angle'=>0,
|
||||
)
|
||||
),
|
||||
'image'=>array(
|
||||
array(
|
||||
'url'=>$product['image'],
|
||||
'left'=>50,
|
||||
'top'=>70,
|
||||
'right'=>0,
|
||||
'stream'=>0,
|
||||
'bottom'=>0,
|
||||
'width'=>350,
|
||||
'height'=>350,
|
||||
'opacity'=>100,
|
||||
),
|
||||
array(
|
||||
'url'=>$product['code_path'],
|
||||
'left'=>250,
|
||||
'top'=>480,
|
||||
'right'=>0,
|
||||
'stream'=>0,
|
||||
'bottom'=>0,
|
||||
'width'=>160,
|
||||
'height'=>180,
|
||||
'opacity'=>100,
|
||||
),
|
||||
),
|
||||
'background'=>ROOT_PATH.UPLOAD_PATH.'/poster/background.jpg' //背景图
|
||||
);
|
||||
$imageDefault = array(
|
||||
'left'=>0,
|
||||
'top'=>0,
|
||||
'right'=>0,
|
||||
'bottom'=>0,
|
||||
'width'=>100,
|
||||
'height'=>100,
|
||||
'opacity'=>100
|
||||
);
|
||||
$textDefault = array(
|
||||
'text'=>'2222222222',
|
||||
'left'=>0,
|
||||
'top'=>0,
|
||||
'fontSize'=>32, //字号
|
||||
'fontColor'=>'255,255,255', //字体颜色
|
||||
'angle'=>0,
|
||||
);
|
||||
$background = $config['background'];//海报最底层得背景
|
||||
//背景方法
|
||||
$backgroundInfo = getimagesize($background);
|
||||
$backgroundFun = 'imagecreatefrom'.image_type_to_extension($backgroundInfo[2], false);
|
||||
$background = $backgroundFun($background);
|
||||
// $backgroundWidth = imagesx($background); //背景宽度
|
||||
// $backgroundHeight = imagesy($background); //背景高度
|
||||
$backgroundWidth = 460; //背景宽度
|
||||
$backgroundHeight = 700; //背景高度
|
||||
$imageRes = imageCreatetruecolor($backgroundWidth,$backgroundHeight);
|
||||
$color = imagecolorallocate($imageRes, 0, 0, 0);
|
||||
imagefill($imageRes, 0, 0, $color);
|
||||
// imageColorTransparent($imageRes, $color); //颜色透明
|
||||
imagecopyresampled($imageRes,$background,0,0,0,0,imagesx($background),imagesy($background),imagesx($background),imagesy($background)); //处理了图片
|
||||
if(!empty($config['image'])){
|
||||
foreach ($config['image'] as $key => $val) {
|
||||
$val = array_merge($imageDefault,$val);
|
||||
$info = getimagesize($val['url']);
|
||||
$function = 'imagecreatefrom'.image_type_to_extension($info[2], false);
|
||||
if($val['stream']){ //如果传的是字符串图像流
|
||||
$info = getimagesizefromstring($val['url']);
|
||||
$function = 'imagecreatefromstring';
|
||||
}
|
||||
$res = $function($val['url']);
|
||||
$resWidth = $info[0];
|
||||
$resHeight = $info[1];
|
||||
//建立画板 ,缩放图片至指定尺寸
|
||||
$canvas=imagecreatetruecolor($val['width'], $val['height']);
|
||||
imagefill($canvas, 0, 0, $color);
|
||||
//关键函数,参数(目标资源,源,目标资源的开始坐标x,y, 源资源的开始坐标x,y,目标资源的宽高w,h,源资源的宽高w,h)
|
||||
imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'],$resWidth,$resHeight);
|
||||
$val['left'] = $val['left']<0?$backgroundWidth- abs($val['left']) - $val['width']:$val['left'];
|
||||
$val['top'] = $val['top']<0?$backgroundHeight- abs($val['top']) - $val['height']:$val['top'];
|
||||
//放置图像
|
||||
imagecopymerge($imageRes,$canvas, $val['left'],$val['top'],$val['right'],$val['bottom'],$val['width'],$val['height'],$val['opacity']);//左,上,右,下,宽度,高度,透明度
|
||||
} }
|
||||
//处理文字
|
||||
if(!empty($config['text'])){
|
||||
foreach ($config['text'] as $key => $val) {
|
||||
$val = array_merge($textDefault,$val);
|
||||
list($R,$G,$B) = explode(',', $val['fontColor']);
|
||||
$fontColor = imagecolorallocate($imageRes, $R, $G, $B);
|
||||
$val['left'] = $val['left']<0?$backgroundWidth- abs($val['left']):$val['left'];
|
||||
$val['top'] = $val['top']<0?$backgroundHeight- abs($val['top']):$val['top'];
|
||||
imagettftext($imageRes,$val['fontSize'],$val['angle'],$val['left'],$val['top'],$fontColor,$val['fontPath'],$val['text']);
|
||||
}
|
||||
}
|
||||
//生成图片
|
||||
$res = imagejpeg ($imageRes,$filePath,90); //保存到本地
|
||||
imagedestroy($imageRes);
|
||||
if(!$res) return false;
|
||||
return $filePath;
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
return [
|
||||
'session' => [
|
||||
// SESSION 前缀
|
||||
'prefix' => 'routine',
|
||||
// 驱动方式 支持redis memcache memcached
|
||||
'type' => '',
|
||||
// 是否自动开启 SESSION
|
||||
'auto_start' => true,
|
||||
],
|
||||
];
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/11
|
||||
*/
|
||||
|
||||
namespace app\routine\controller;
|
||||
|
||||
use app\routine\model\user\User;
|
||||
use service\JsonService;
|
||||
use think\Controller;
|
||||
use think\Request;
|
||||
use think\Session;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public $userInfo = [];
|
||||
protected function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$uid = Request::instance()->get('uid',0);
|
||||
$userInfo = User::get($uid);
|
||||
if($userInfo) $userInfo->toArray();
|
||||
else return JsonService::fail('没有获取用户UID');
|
||||
$this->userInfo = $userInfo;//根据uid获取用户信息
|
||||
}
|
||||
}
|
||||
@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\routine\controller;
|
||||
|
||||
use app\admin\model\system\SystemConfig;
|
||||
use app\routine\model\routine\RoutineServer;
|
||||
use app\routine\model\user\RoutineUser;
|
||||
use service\JsonService;
|
||||
use service\UtilService;
|
||||
use think\Controller;
|
||||
use think\Request;
|
||||
|
||||
class Login extends Controller{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
|
||||
public function index(Request $request){
|
||||
$data = UtilService::postMore([['info',[]]],$request);//获取前台传的code
|
||||
$data = $data['info'];
|
||||
unset($data['info']);
|
||||
$res = $this->setCode($data['code']);
|
||||
if(!isset($res['openid'])) return JsonService::fail('openid获取失败');
|
||||
if(isset($res['unionid'])) $data['unionid'] = $res['unionid'];
|
||||
else $data['unionid'] = '';
|
||||
$data['routine_openid'] = $res['openid'];
|
||||
$data['session_key'] = $res['session_key'];
|
||||
$dataOauthInfo = RoutineUser::routineOauth($data);
|
||||
$data['uid'] = $dataOauthInfo['uid'];
|
||||
$data['page'] = $dataOauthInfo['page'];
|
||||
$data['status'] = RoutineUser::isUserStatus($data['uid']);
|
||||
return JsonService::successful($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据前台传code 获取 openid 和 session_key //会话密匙
|
||||
* @param string $code
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function setCode($code = ''){
|
||||
if($code == '') return [];
|
||||
$routineAppId = SystemConfig::getValue('routine_appId');//小程序appID
|
||||
$routineAppSecret = SystemConfig::getValue('routine_appsecret');//小程序AppSecret
|
||||
$url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$routineAppId.'&secret='.$routineAppSecret.'&js_code='.$code.'&grant_type=authorization_code';
|
||||
return json_decode(RoutineServer::curlGet($url),true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取网站logo
|
||||
*/
|
||||
public function get_enter_logo(){
|
||||
$siteLogo = SystemConfig::getValue('routine_logo');
|
||||
$siteName = SystemConfig::getValue('routine_name');
|
||||
$data['site_logo'] = $siteLogo;
|
||||
$data['site_name'] = $siteName;
|
||||
return JsonService::successful($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取网站顶部颜色
|
||||
*/
|
||||
public function get_routine_style(){
|
||||
$routineStyle = SystemConfig::getValue('routine_style');
|
||||
$data['routine_style'] = $routineStyle;
|
||||
return JsonService::successful($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客服电话
|
||||
*/
|
||||
public function get_site_service_phone(){
|
||||
$siteServicePhone = SystemConfig::getValue('site_service_phone');
|
||||
$data['site_service_phone'] = $siteServicePhone;
|
||||
return JsonService::successful($data);
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
namespace app\routine\controller;
|
||||
use behavior\wechat\PaymentBehavior;
|
||||
use service\HookService;
|
||||
use service\RoutineNotify;
|
||||
|
||||
|
||||
/**
|
||||
* 小程序支付回调
|
||||
* Class Routine
|
||||
* @package app\routine\controller
|
||||
*/
|
||||
class Routine
|
||||
{
|
||||
/**
|
||||
* 支付 异步回调
|
||||
*/
|
||||
public function notify()
|
||||
{
|
||||
$result = RoutineNotify::notify();
|
||||
if($result) HookService::listen('wechat_pay_success_'.strtolower($result['attach']),$result['out_trade_no'],$result,true,PaymentBehavior::class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1 +0,0 @@
|
||||
<?php
namespace app\routine\model\article;
use think\Db;
use traits\ModelTrait;
use basic\ModelBasic;
/**
* Class Article
* @package app\routine\model\article
*/
class Article extends ModelBasic {
use ModelTrait;
/**
* 获取一条新闻
* @param int $id
* @return array|false|\PDOStatement|string|\think\Model
*/
public static function getArticleOne($id = 0){
if(!$id) return [];
$list = self::where('status',1)->where('hide',0)->where('id',$id)->order('id desc')->find();
if($list){
$list = $list->toArray();
$list["content"] = Db::name('articleContent')->where('nid',$id)->value('content');
return $list;
}
else return [];
}
/**
* 获取某个分类底下的文章
* @param $cid
* @param $first
* @param $limit
* @param string $field
* @return mixed
*/
public static function cidByArticleList($cid, $first, $limit, $field = 'id,title,image_input,visit,add_time,synopsis,url')
{
$model = new self();
if ($cid) $model->where("CONCAT(',',cid,',')" ,'LIKE'," '%,$cid,%'");
$model = $model->field($field);
$model = $model->where('status', 1);
$model = $model->where('hide', 0);
$model = $model->order('sort DESC,add_time DESC');
if($limit) $model = $model->limit($first, $limit);
return $model->select();
}
/**
* 获取热门文章
* @param string $field
* @return mixed
*/
public static function getArticleListHot($field = 'id,title,image_input,visit,add_time,synopsis,url'){
$model = new self();
$model = $model->field($field);
$model = $model->where('status', 1);
$model = $model->where('hide', 0);
$model = $model->where('is_hot', 1);
$model = $model->order('sort DESC,add_time DESC');
return $model->select();
}
/**
* 获取轮播文章
* @param string $field
* @return mixed
*/
public static function getArticleListBanner($field = 'id,title,image_input,visit,add_time,synopsis,url'){
$model = new self();
$model = $model->field($field);
$model = $model->where('status', 1);
$model = $model->where('hide', 0);
$model = $model->where('is_banner', 1);
$model = $model->order('sort DESC,add_time DESC');
return $model->select();
}
}
|
||||
@ -1,16 +0,0 @@
|
||||
<?php /** * * @author: xaboy<365615158@qq.com> * @day: 2017/11/02 */
|
||||
namespace app\routine\model\article;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
|
||||
/**
|
||||
* Class ArticleCategory
|
||||
* @package app\routine\model\article
|
||||
*/
|
||||
class ArticleCategory extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
namespace app\routine\model\routine;
|
||||
|
||||
|
||||
class RoutineCode{
|
||||
|
||||
/**
|
||||
* 获取分销二维码
|
||||
* @param int $uid yonghuID
|
||||
* @param array $color 二维码线条颜色
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getCode($uid = 0,$imgUrl = '',$color = array(),$page = '',$thirdType = 'spread'){
|
||||
$accessToken = RoutineServer::get_access_token();
|
||||
$res = RoutineQrcode::setRoutineQrcodeForever($uid,$thirdType,$page,$imgUrl);
|
||||
if($res){
|
||||
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$accessToken;
|
||||
if($uid) $data['scene'] = $res->id;
|
||||
else $data['scene'] = 0;
|
||||
if(empty($color)){
|
||||
$color['r'] = 0;
|
||||
$color['g'] = 0;
|
||||
$color['b'] = 0;
|
||||
}
|
||||
$data['page'] = '';
|
||||
$data['width'] = 430;
|
||||
$data['auto_color'] = false;
|
||||
$data['line_color'] = $color;
|
||||
$data['is_hyaline'] = false;
|
||||
$resCode = RoutineServer::curlPost($url,json_encode($data));
|
||||
if($resCode){
|
||||
$dataQrcode['status'] = 1;
|
||||
$dataQrcode['url_time'] = time();
|
||||
$res = RoutineQrcode::setRoutineQrcodeFind($res->id,$dataQrcode);
|
||||
if($res) return $resCode;
|
||||
else return false;
|
||||
}else return false;
|
||||
}else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小程序内访问页面的二维码
|
||||
* @param string $path
|
||||
* @param int $width
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getPages($path = '',$width = 430){
|
||||
$accessToken = RoutineServer::get_access_token();
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=".$accessToken;
|
||||
$data['path'] = $path;
|
||||
$data['width'] = $width;
|
||||
return RoutineServer::curlPost($url,json_encode($data));
|
||||
}
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
namespace app\routine\model\routine;
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
/**
|
||||
* 表单ID表
|
||||
* Class RoutineFormId
|
||||
* @package app\routine\model\routine
|
||||
*/
|
||||
class RoutineFormId extends ModelBasic {
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 删除已失效的formID
|
||||
* @return int
|
||||
*/
|
||||
public static function delStatusInvalid(){
|
||||
return self::where('status',2)->where('stop_time','LT',time())->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个可以使用的formId
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function getFormIdOne($uid = 0){
|
||||
$formId = self::where('status',1)->where('stop_time','GT',time())->where('uid',$uid)->order('id asc')->find();
|
||||
if($formId) return $formId['form_id'];
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改一个FormID为已使用
|
||||
* @param string $formId
|
||||
* @return $this|bool
|
||||
*/
|
||||
public static function delFormIdOne($formId = ''){
|
||||
if($formId == '') return true;
|
||||
return self::where('form_id',$formId)->update(['status'=>2]);
|
||||
}
|
||||
}
|
||||
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
namespace app\routine\model\routine;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
/**
|
||||
* 小程序二维码Model
|
||||
* Class RoutineQrcode
|
||||
* @package app\routine\model\routine
|
||||
*/
|
||||
class RoutineQrcode extends ModelBasic {
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 添加二维码记录
|
||||
* @param string $thirdType
|
||||
* @param int $thirdId
|
||||
* @return object
|
||||
*/
|
||||
public static function setRoutineQrcodeForever($thirdId = 0,$thirdType = 'spread',$page = '',$imgUrl = ''){
|
||||
$data['third_type'] = $thirdType;
|
||||
$data['third_id'] = $thirdId;
|
||||
$data['status'] = 0;
|
||||
$data['add_time'] = time();
|
||||
$data['page'] = $page;
|
||||
$data['url_time'] = '';
|
||||
$data['qrcode_url'] = $imgUrl;
|
||||
return self::set($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改二维码地址
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public static function setRoutineQrcodeFind($id = 0,$data = array()){
|
||||
if(!$id) return false;
|
||||
$count = self::getRoutineQrcodeFind($id);
|
||||
if(!$count) return false;
|
||||
return self::edit($data,$id,'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取二维码是否存在
|
||||
* @param int $id
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getRoutineQrcodeFind($id = 0){
|
||||
if(!$id) return 0;
|
||||
return self::where('id',$id)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小程序二维码信息
|
||||
* @param int $id
|
||||
* @param string $field
|
||||
* @return array|bool|false|\PDOStatement|string|\think\Model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getRoutineQrcodeFindType($id = 0,$field = 'third_type,third_id,page'){
|
||||
if(!$id) return false;
|
||||
$count = self::getRoutineQrcodeFind($id);
|
||||
if(!$count) return false;
|
||||
return self::where('id',$id)->where('status',1)->field($field)->find();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,88 +0,0 @@
|
||||
<?php
|
||||
namespace app\routine\model\routine;
|
||||
|
||||
use app\admin\model\system\SystemConfig;
|
||||
use think\Db;
|
||||
class RoutineServer{
|
||||
/**
|
||||
* curl get方式
|
||||
* @param string $url
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public static function curlGet($url = '', $options = array())
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
if (!empty($options)) {
|
||||
curl_setopt_array($ch, $options);
|
||||
}
|
||||
//https请求 不验证证书和host
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
$data = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* curl post
|
||||
* @param string $url
|
||||
* @param string $postData
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public static function curlPost($url = '', $postData = '', $options = array())
|
||||
{
|
||||
if (is_array($postData)) {
|
||||
$postData = http_build_query($postData);
|
||||
}
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //设置cURL允许执行的最长秒数
|
||||
if (!empty($options)) {
|
||||
curl_setopt_array($ch, $options);
|
||||
}
|
||||
//https请求 不验证证书和host
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
$data = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信公众号
|
||||
* @param string $routineAppId
|
||||
* @param string $routineAppSecret
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getAccessToken($routineAppId = '',$routineAppSecret = ''){
|
||||
$routineAppId = SystemConfig::getValue('routine_appId');
|
||||
$routineAppSecret = SystemConfig::getValue('routine_appsecret');
|
||||
$url ="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$routineAppId."&secret=".$routineAppSecret;
|
||||
return json_decode(self::curlGet($url),true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取access_token 数据库
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_access_token(){
|
||||
$accessToken = Db::name('routine_access_token')->where('id',1)->find();
|
||||
if($accessToken['stop_time'] > time()) return $accessToken['access_token'];
|
||||
else{
|
||||
$accessToken = self::getAccessToken();
|
||||
if(isset($accessToken['access_token'])){
|
||||
$data['access_token'] = $accessToken['access_token'];
|
||||
$data['stop_time'] = bcadd($accessToken['expires_in'],time(),0);
|
||||
Db::name('routine_access_token')->where('id',1)->update($data);
|
||||
}
|
||||
return $accessToken['access_token'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,90 +0,0 @@
|
||||
<?php
|
||||
namespace app\routine\model\routine;
|
||||
|
||||
use app\routine\model\store\StoreOrder;
|
||||
use app\routine\model\user\RoutineUser;
|
||||
use app\routine\model\user\WechatUser;
|
||||
use service\RoutineTemplateService;
|
||||
|
||||
/**
|
||||
* 小程序模板消息
|
||||
* Class RoutineTemplate
|
||||
* @package app\routine\model\routine
|
||||
*/
|
||||
class RoutineTemplate{
|
||||
/**
|
||||
* 退款成功发送消息
|
||||
* @param array $order
|
||||
*/
|
||||
public static function sendOrderRefundSuccess($order = array()){
|
||||
$formId = RoutineFormId::getFormIdOne($order['uid']);
|
||||
$data['keyword1']['value'] = $order['order_id'];
|
||||
$data['keyword2']['value'] = date('Y-m-d H:i:s',time());
|
||||
$data['keyword3']['value'] = $order['pay_price'];
|
||||
if($order['pay_type'] == 'yue') $data['keyword4']['value'] = '余额支付';
|
||||
else if($order['pay_type'] == 'weixin') $data['keyword4']['value'] = '微信支付';
|
||||
else if($order['pay_type'] == 'offline') $data['keyword4']['value'] = '线下支付';
|
||||
$data['keyword5']['value'] = '已成功退款';
|
||||
RoutineFormId::delFormIdOne($formId);
|
||||
RoutineTemplateService::sendTemplate(WechatUser::getOpenId($order['uid']),RoutineTemplateService::setTemplateId(RoutineTemplateService::ORDER_REFUND_SUCCESS),'',$data,$formId);
|
||||
}
|
||||
/**
|
||||
* 用户申请退款给管理员发送消息
|
||||
* @param array $order
|
||||
* @param string $refundReasonWap
|
||||
* @param array $adminList
|
||||
*/
|
||||
public static function sendOrderRefundStatus($order = array(),$refundReasonWap = '',$adminList = array()){
|
||||
$data['keyword1']['value'] = $order['order_id'];
|
||||
$data['keyword2']['value'] = $refundReasonWap;
|
||||
$data['keyword3']['value'] = date('Y-m-d H:i:s',time());
|
||||
$data['keyword4']['value'] = $order['pay_price'];
|
||||
$data['keyword5']['value'] = '原路返回';
|
||||
foreach ($adminList as $uid){
|
||||
$formId = RoutineFormId::getFormIdOne($order['uid']);
|
||||
if($formId){
|
||||
RoutineFormId::delFormIdOne($formId);
|
||||
RoutineTemplateService::sendTemplate(WechatUser::getOpenId($uid),RoutineTemplateService::setTemplateId(RoutineTemplateService::ORDER_REFUND_STATUS),'',$data,$formId);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 砍价成功通知
|
||||
* @param array $bargain
|
||||
* @param array $bargainUser
|
||||
* @param int $bargainUserId
|
||||
*/
|
||||
public static function sendBargainSuccess($bargain = array(),$bargainUser = array(),$bargainUserId = 0){
|
||||
$data['keyword1']['value'] = $bargain['title'];
|
||||
$data['keyword2']['value'] = $bargainUser['bargain_price'];
|
||||
$data['keyword3']['value'] = $bargainUser['bargain_price_min'];
|
||||
$data['keyword4']['value'] = $bargainUser['price'];
|
||||
$data['keyword5']['value'] = $bargainUser['bargain_price_min'];
|
||||
$data['keyword6']['value'] = '恭喜您,已经砍到最低价了';
|
||||
$formId = RoutineFormId::getFormIdOne($bargainUserId);
|
||||
if($formId){
|
||||
$dataFormId['formId'] = $formId;
|
||||
RoutineTemplateService::sendTemplate(WechatUser::getOpenId($bargainUser['uid']),RoutineTemplateService::setTemplateId(RoutineTemplateService::BARGAIN_SUCCESS),'',$data,$formId);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 订单支付成功发送模板消息
|
||||
* @param string $formId
|
||||
* @param string $orderId
|
||||
*/
|
||||
public static function sendOrderSuccess($formId = '',$orderId = ''){
|
||||
if($orderId == '') return ;
|
||||
$order = StoreOrder::where('order_id',$orderId)->find();
|
||||
if($formId == '') $formId = RoutineFormId::getFormIdOne($order['uid']);
|
||||
$data['keyword1']['value'] = $orderId;
|
||||
$data['keyword2']['value'] = date('Y-m-d H:i:s',time());
|
||||
$data['keyword3']['value'] = '已支付';
|
||||
$data['keyword4']['value'] = $order['pay_price'];
|
||||
if($order['pay_type'] == 'yue') $data['keyword5']['value'] = '余额支付';
|
||||
else if($order['pay_type'] == 'weixin') $data['keyword5']['value'] = '微信支付';
|
||||
// else if($order['pay_type'] == 'offline') $data['keyword5']['value'] = '线下支付';
|
||||
RoutineFormId::delFormIdOne($formId);
|
||||
RoutineTemplateService::sendTemplate(WechatUser::getOpenId($order['uid']),RoutineTemplateService::setTemplateId(RoutineTemplateService::ORDER_PAY_SUCCESS),'',$data,$formId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,159 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/18
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreBargain extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 正在开启的砍价活动
|
||||
* @return $this
|
||||
*/
|
||||
public static function validWhere($status = 1){
|
||||
return self::where('is_del',0)->where('status',$status)->where('start_time','LT',time())->where('stop_time','GT',time());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断砍价产品是否开启
|
||||
* @param int $bargainId
|
||||
* @return int|string
|
||||
*/
|
||||
public static function validBargain($bargainId = 0){
|
||||
$model = self::validWhere();
|
||||
return $model->where('id',$bargainId)->count();
|
||||
}
|
||||
/**
|
||||
* 获取正在进行中的砍价产品
|
||||
* @param string $field
|
||||
*/
|
||||
public static function getList($field = 'id,product_id,title,price,min_price,image'){
|
||||
$model = self::validWhere();
|
||||
$list = $model->field($field)->select();
|
||||
if($list) return $list->toArray();
|
||||
else return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一条正在进行中的砍价产品
|
||||
* @param int $bargainId
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public static function getBargainTerm($bargainId = 0,$field = 'id,product_id,bargain_num,num,unit_name,image,title,price,min_price,image,description,start_time,stop_time,rule'){
|
||||
if(!$bargainId) return [];
|
||||
$model = self::validWhere();
|
||||
$bargain = $model->field($field)->where('id',$bargainId)->find();
|
||||
if($bargain) return $bargain->toArray();
|
||||
else return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一条砍价产品
|
||||
* @param int $bargainId
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public static function getBargain($bargainId = 0,$field = 'id,product_id,title,price,min_price,image'){
|
||||
if(!$bargainId) return [];
|
||||
$model = new self();
|
||||
$bargain = $model->field($field)->where('id',$bargainId)->find();
|
||||
if($bargain) return $bargain->toArray();
|
||||
else return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最高价和最低价
|
||||
* @param int $bargainId
|
||||
* @return array
|
||||
*/
|
||||
public static function getBargainMaxMinPrice($bargainId = 0){
|
||||
if(!$bargainId) return [];
|
||||
return self::where('id',$bargainId)->field('bargain_min_price,bargain_max_price')->find()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取砍价次数
|
||||
* @param int $bargainId
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getBargainNum($bargainId = 0){
|
||||
return self::where('id',$bargainId)->value('bargain_num');
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前砍价是否活动进行中
|
||||
* @param int $bargainId
|
||||
* @return bool
|
||||
*/
|
||||
public static function setBargainStatus($bargainId = 0){
|
||||
$model = self::validWhere();
|
||||
$count = $model->where('id',$bargainId)->count();
|
||||
if($count) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取库存
|
||||
* @param int $bargainId
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getBargainStock($bargainId = 0){
|
||||
return self::where('id',$bargainId)->value('stock');
|
||||
}
|
||||
/**
|
||||
* 修改销量和库存
|
||||
* @param $num
|
||||
* @param $CombinationId
|
||||
* @return bool
|
||||
*/
|
||||
public static function decBargainStock($num,$bargainId)
|
||||
{
|
||||
$res = false !== self::where('id',$bargainId)->dec('stock',$num)->inc('sales',$num)->update();
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有砍价产品的浏览量
|
||||
* @return array|false|\PDOStatement|string|\think\Model
|
||||
*/
|
||||
public static function getBargainLook(){
|
||||
return self::field('sum(look) as look')->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有砍价产品的分享量
|
||||
* @return array|false|\PDOStatement|string|\think\Model
|
||||
*/
|
||||
public static function getBargainShare(){
|
||||
return self::field('sum(share) as share')->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加砍价产品分享次数
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function addBargainShare($id = 0){
|
||||
if(!$id) return false;
|
||||
return self::where('id',$id)->inc('share',1)->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加砍价产品浏览次数
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function addBargainLook($id = 0){
|
||||
if(!$id) return false;
|
||||
return self::where('id',$id)->inc('look',1)->update();
|
||||
}
|
||||
}
|
||||
@ -1,202 +0,0 @@
|
||||
<?php
|
||||
namespace app\routine\model\store;
|
||||
|
||||
use app\routine\model\user\User;
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
/**
|
||||
* 参与砍价Model
|
||||
* Class StoreBargainUser
|
||||
* @package app\routine\model\store
|
||||
*/
|
||||
class StoreBargainUser extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 根据砍价产品获取正在参与的用户头像
|
||||
* @param array $bargain
|
||||
* @return array
|
||||
*/
|
||||
public static function getUserList($bargain = array(),$limit = 10){
|
||||
if(count($bargain) < 1) return [];
|
||||
foreach ($bargain as $k=>$v){
|
||||
if(is_array($v)){
|
||||
$uid = self::getUserIdList($v['id']);
|
||||
if(count($uid) > 0) {
|
||||
$userInfo = User::where('uid','IN',implode(',',$uid))->limit($limit)->column('avatar','uid');
|
||||
$bargain[$k]['userInfo'] = $userInfo;
|
||||
$bargain[$k]['userInfoCount'] = count($userInfo);
|
||||
}
|
||||
else {
|
||||
$bargain[$k]['userInfo'] = [];
|
||||
$bargain[$k]['userInfoCount'] = 0;
|
||||
}
|
||||
}else{
|
||||
$uid = self::getUserIdList($bargain['id']);
|
||||
if(count($uid) > 0) $bargain['userInfo'] = User::where('uid','IN',implode(',',$uid))->column('avatar','uid');
|
||||
else $bargain['userInfo'] = [];
|
||||
}
|
||||
}
|
||||
return $bargain;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据砍价产品ID获取正在参与人的uid
|
||||
* @param int $bargainId $bargainId 砍价产品ID
|
||||
* @param int $status $status 状态 1 进行中 2 结束失败 3结束成功
|
||||
* @return array
|
||||
*/
|
||||
public static function getUserIdList($bargainId = 0,$status = 1){
|
||||
if(!$bargainId) return [];
|
||||
return self::where('bargain_id',$bargainId)->where('status',$status)->column('uid','id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参与的ID
|
||||
* @param int $bargainId
|
||||
* @param int $uid
|
||||
* @param int $status
|
||||
* @return array|mixed
|
||||
*/
|
||||
public static function setUserBargain($bargainId = 0,$uid = 0,$status = 1){
|
||||
if(!$bargainId || !$uid) return [];
|
||||
$bargainIdUserTableId = self::where('bargain_id',$bargainId)->where('uid',$uid)->where('status',$status)->value('id');
|
||||
return $bargainIdUserTableId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 添加一条砍价记录
|
||||
* @param int $bargainId
|
||||
* @param int $uid
|
||||
* @return bool|object
|
||||
*/
|
||||
public static function setBargain($bargainId = 0,$uid = 0){
|
||||
if(!$bargainId || !$uid || !StoreBargain::validBargain($bargainId) || self::be(['bargain_id'=>$bargainId,'uid'=>$uid,'status'=>1])) return false;
|
||||
$data['bargain_id'] = $bargainId;
|
||||
$data['uid'] = $uid;
|
||||
$data['bargain_price_min'] = StoreBargain::where('id',$bargainId)->value('min_price');
|
||||
$data['bargain_price'] = StoreBargain::where('id',$bargainId)->value('price');
|
||||
$data['price'] = 0;
|
||||
$data['status'] = 1;
|
||||
$data['add_time'] = time();
|
||||
return self::set($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断当前人是否已经参与砍价
|
||||
* @param int $bargainId
|
||||
* @param int $uid
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function isBargainUser($bargainId = 0,$uid = 0){
|
||||
if(!$bargainId || !$uid || !StoreBargain::validBargain($bargainId)) return false;
|
||||
return self::where('bargain_id',$bargainId)->where('uid',$uid)->value('uid');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户砍掉的价格
|
||||
* @param int $bargainUserId
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getBargainUserPrice($bargainUserId = 0){
|
||||
return (float)self::where('id',$bargainUserId)->value('price');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户可以砍掉的价格
|
||||
* @param int $bargainUserId
|
||||
* @return string
|
||||
*/
|
||||
public static function getBargainUserDiffPrice($bargainId = 0,$bargainUserId = 0){
|
||||
$price = self::where('bargain_id',$bargainId)->where('uid',$bargainUserId)->field('bargain_price,bargain_price_min')->find()->toArray();
|
||||
return (float)bcsub($price['bargain_price'],$price['bargain_price_min'],0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取砍价表ID
|
||||
* @param int $bargainId
|
||||
* @param int $bargainUserId
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getBargainUserTableId($bargainId = 0,$bargainUserId = 0,$status = 1){
|
||||
return self::where('bargain_id',$bargainId)->where('uid',$bargainUserId)->where('status',$status)->value('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改砍价价格
|
||||
* @param int $bargainUserTableId
|
||||
* @param array $price
|
||||
* @return $this|bool
|
||||
*/
|
||||
public static function setBargainUserPrice($bargainUserTableId = 0, $price = array()){
|
||||
if(!$bargainUserTableId) return false;
|
||||
return self::where('id',$bargainUserTableId)->update($price);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的砍价产品
|
||||
* @param $uid
|
||||
* @return array
|
||||
*/
|
||||
public static function getBargainUserAll($uid = 0){
|
||||
if(!$uid) return [];
|
||||
$model = new self;
|
||||
$model = $model->alias('u');
|
||||
$model = $model->field('u.id,u.bargain_id,u.bargain_price,u.bargain_price_min,u.price,u.status,b.title,b.image,b.stop_time');
|
||||
$model = $model->join('StoreBargain b','b.id=u.bargain_id');
|
||||
$model = $model->where('u.uid',$uid);
|
||||
$model = $model->order('u.id desc');
|
||||
$list = $model->select();
|
||||
if($list) return $list->toArray();
|
||||
else return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户砍价状态 支付订单
|
||||
* @param int $bargainId
|
||||
* @param int $uid
|
||||
* @return $this|bool
|
||||
*/
|
||||
public static function setBargainUserStatus($bargainId = 0, $uid = 0){
|
||||
$count = self::where('uid',$uid)->where('bargain_id',$bargainId)->where('status',1)->count();
|
||||
if(!$count) return false;
|
||||
$userPrice = (float)self::where('uid',$uid)->where('bargain_id',$bargainId)->where('status',1)->value('price');
|
||||
$price = self::getBargainUserDiffPrice($bargainId,$uid);
|
||||
if(bcsub($price,$userPrice,0) > 0) return false;
|
||||
return self::where('uid',$uid)->where('bargain_id',$bargainId)->where('status',1)->update(['status'=>3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改砍价状态为 砍价失败
|
||||
* @param int $bargainUserTableId
|
||||
* @return $this|bool
|
||||
*/
|
||||
public static function editBargainUserStatus($bargainUserTableId = 0){
|
||||
if(!$bargainUserTableId) return false;
|
||||
return self::where('id',$bargainUserTableId)->update(['status'=>2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取砍价成功的用户信息
|
||||
* @return array|false|\PDOStatement|string|\think\Collection
|
||||
*/
|
||||
public static function getBargainUserStatusSuccess(){
|
||||
$bargainUser = self::where('status',3)->order('id desc')->field('uid,bargain_price_min,bargain_id')->select();
|
||||
if($bargainUser) {
|
||||
$bargainUser = $bargainUser->toArray();
|
||||
foreach ($bargainUser as $k=>$v){
|
||||
$bargainUser[$k]['info'] = User::where('uid',$v['uid'])->value('nickname').'砍价成功了'.$v['bargain_price_min'].'砍到了'.StoreBargain::where('id',$v['bargain_id'])->value('title');
|
||||
}
|
||||
}
|
||||
else{
|
||||
$bargainUser[]['info'] = '砍价上线了,快邀请您的好友来砍价';
|
||||
}
|
||||
return $bargainUser;
|
||||
}
|
||||
}
|
||||
@ -1,142 +0,0 @@
|
||||
<?php
|
||||
namespace app\routine\model\store;
|
||||
|
||||
use app\routine\model\user\User;
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
/**
|
||||
* 砍价帮砍Model
|
||||
* Class StoreBargainUser
|
||||
* @package app\routine\model\store
|
||||
*/
|
||||
class StoreBargainUserHelp extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 获取砍价帮
|
||||
* @param int $bargainUserId
|
||||
* @return array
|
||||
*/
|
||||
public static function getList($bargainUserId = 0,$limit = 15){
|
||||
if(!$bargainUserId) return [];
|
||||
$list = self::where('bargain_user_id',$bargainUserId)->limit($limit)->column('uid,price','id');
|
||||
if($list){
|
||||
foreach ($list as $k=>$v){
|
||||
$userInfo = self::getBargainUserHelpUserInfo($v['uid']);
|
||||
$list[$k]['nickname'] = $userInfo[$v['uid']]['nickname'];
|
||||
$list[$k]['avatar'] = $userInfo[$v['uid']]['avatar'];
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用的昵称和头像
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public static function getBargainUserHelpUserInfo($uid = 0){
|
||||
if(!$uid) return [];
|
||||
$userInfo = User::where('uid',$uid)->column('nickname,avatar','uid');
|
||||
return $userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 帮忙砍价
|
||||
* @param int $bargainId
|
||||
* @param int $bargainUserId
|
||||
* @param int $uid
|
||||
* @return bool|object
|
||||
*/
|
||||
public static function setBargainUserHelp($bargainId = 0,$bargainUserId = 0,$uid = 0){
|
||||
if(!self::isBargainUserHelpCount($bargainId,$bargainUserId,$uid) || !$bargainId || !$bargainUserId || !$uid || !StoreBargain::validBargain($bargainId) || !StoreBargainUser::be(['bargain_id'=>$bargainId,'uid'=>$bargainUserId,'status'=>1])) return false;
|
||||
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
|
||||
$priceSection = StoreBargain::getBargainMaxMinPrice($bargainId); //获取砍价的价格区间
|
||||
$coverPrice = StoreBargainUser::getBargainUserDiffPrice($bargainId,$bargainUserId);//用户可以砍掉的金额
|
||||
$alreadyPrice= StoreBargainUser::getBargainUserPrice($bargainUserTableId);//用户已经砍掉的价格
|
||||
$surplusPrice = (float)bcsub($coverPrice,$alreadyPrice,2);//用户剩余要砍掉的价格
|
||||
$data['uid'] = $uid;
|
||||
$data['bargain_id'] = $bargainId;
|
||||
$data['bargain_user_id'] = $bargainUserTableId;
|
||||
$data['price'] = self::randomFloat($priceSection['bargain_min_price'],$priceSection['bargain_max_price']);
|
||||
$data['add_time'] = time();
|
||||
if($data['price'] > $surplusPrice) $data['price'] = $surplusPrice;
|
||||
$price = bcadd($alreadyPrice,$data['price'],2);
|
||||
$bargainUserData['price'] = $price;
|
||||
self::beginTrans();
|
||||
$res1 = StoreBargainUser::setBargainUserPrice($bargainUserTableId,$bargainUserData);
|
||||
$res2 = self::set($data);
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
if($res) return $data;
|
||||
else return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取俩个数之间的随机数
|
||||
* @param int $min
|
||||
* @param int $max
|
||||
* @return string
|
||||
*/
|
||||
public static function randomFloat($min = 0,$max = 1){
|
||||
$num = $min + mt_rand() / mt_getrandmax() * ($max - $min);
|
||||
return sprintf("%.2f",$num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户是否还可以砍价
|
||||
* @param int $bargainId
|
||||
* @param int $bargainUserUid
|
||||
* @param int $bargainUserHelpUid
|
||||
* @return bool
|
||||
*/
|
||||
public static function isBargainUserHelpCount($bargainId = 0,$bargainUserUid = 0,$bargainUserHelpUid = 0){
|
||||
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserUid);
|
||||
$bargainNum = StoreBargain::getBargainNum($bargainId);
|
||||
$count = self::where('bargain_id',$bargainId)->where('bargain_user_id',$bargainUserTableId)->where('uid',$bargainUserHelpUid)->count();
|
||||
if($count < $bargainNum) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取砍价帮总人数
|
||||
* @param int $bargainId
|
||||
* @param int $bargainUserId
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getBargainUserHelpPeopleCount($bargainId = 0,$bargainUserId = 0){
|
||||
if(!$bargainId || !$bargainUserId) return 0;
|
||||
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
|
||||
if($bargainUserTableId) return self::where('bargain_user_id',$bargainUserTableId)->where('bargain_id',$bargainId)->count();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户还剩余的砍价金额
|
||||
* @param int $bargainId
|
||||
* @param int $bargainUserId
|
||||
* @return float
|
||||
*/
|
||||
public static function getSurplusPrice($bargainId = 0,$bargainUserId = 0){
|
||||
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
|
||||
$coverPrice = StoreBargainUser::getBargainUserDiffPrice($bargainId,$bargainUserId);//用户可以砍掉的金额
|
||||
$alreadyPrice= StoreBargainUser::getBargainUserPrice($bargainUserTableId);//用户已经砍掉的价格
|
||||
$surplusPrice = (float)bcsub($coverPrice,$alreadyPrice,2);//用户剩余要砍掉的价格
|
||||
return $surplusPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取砍价进度条
|
||||
* @param int $bargainId
|
||||
* @param int $bargainUserId
|
||||
* @return string
|
||||
*/
|
||||
public static function getSurplusPricePercent($bargainId = 0,$bargainUserId = 0){
|
||||
$coverPrice = StoreBargainUser::getBargainUserDiffPrice($bargainId,$bargainUserId);//用户可以砍掉的金额
|
||||
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
|
||||
$alreadyPrice= StoreBargainUser::getBargainUserPrice($bargainUserTableId);//用户已经砍掉的价格
|
||||
return bcmul(bcdiv($alreadyPrice,$coverPrice,2),100,0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,224 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/18
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use app\routine\model\store\StoreCombination;
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreCart extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['add_time'];
|
||||
|
||||
protected function setAddTimeAttr()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
public static function setCart($uid,$product_id,$cart_num = 1,$product_attr_unique = '',$type='product',$is_new = 0,$combination_id=0,$seckill_id = 0,$bargain_id = 0)
|
||||
{
|
||||
if($cart_num < 1) $cart_num = 1;
|
||||
if($seckill_id){
|
||||
$StoreSeckillinfo = StoreSeckill::getValidProduct($seckill_id);
|
||||
if(!$StoreSeckillinfo)
|
||||
return self::setErrorInfo('该产品已下架或删除');
|
||||
$userbuycount = StoreOrder::where(['uid'=>$uid,'paid'=>1,'seckill_id'=>$seckill_id])->count();
|
||||
if($StoreSeckillinfo['num'] <= $userbuycount)
|
||||
return self::setErrorInfo('每人限购'.$StoreSeckillinfo['num'].'一件');
|
||||
if(StoreSeckill::getProductStock($seckill_id) < $cart_num)
|
||||
return self::setErrorInfo('该产品库存不足'.$cart_num);
|
||||
$where = ['type'=>$type,'uid'=>$uid,'product_id'=>$product_id,'product_attr_unique'=>$product_attr_unique,'is_new'=>$is_new,'is_pay'=>0,'is_del'=>0,'seckill_id'=>$seckill_id];
|
||||
if($cart = self::where($where)->find()){
|
||||
$cart->cart_num = $cart_num;
|
||||
$cart->add_time = time();
|
||||
$cart->save();
|
||||
return $cart;
|
||||
}else{
|
||||
return self::set(compact('uid','product_id','cart_num','product_attr_unique','is_new','type','seckill_id'));
|
||||
}
|
||||
}elseif($bargain_id){
|
||||
if(!StoreBargain::validBargain($bargain_id))
|
||||
return self::setErrorInfo('该产品已下架或删除');
|
||||
if(StoreBargain::getBargainStock($bargain_id) < $cart_num)
|
||||
return self::setErrorInfo('该产品库存不足'.$cart_num);
|
||||
$where = ['type'=>$type,'uid'=>$uid,'product_id'=>$product_id,'product_attr_unique'=>$product_attr_unique,'is_new'=>$is_new,'is_pay'=>0,'is_del'=>0,'bargain_id'=>$bargain_id];
|
||||
if($cart = self::where($where)->find()){
|
||||
$cart->cart_num = $cart_num;
|
||||
$cart->add_time = time();
|
||||
$cart->save();
|
||||
return $cart;
|
||||
}else{
|
||||
return self::set(compact('uid','product_id','cart_num','product_attr_unique','is_new','type','bargain_id'));
|
||||
}
|
||||
}elseif($combination_id){//拼团
|
||||
if(!StoreCombination::getCombinationStock($combination_id,$cart_num))
|
||||
return self::setErrorInfo('该产品库存不足'.$cart_num);
|
||||
if(!StoreCombination::isValidCombination($combination_id))
|
||||
return self::setErrorInfo('该产品已下架或删除');
|
||||
}else{
|
||||
if(!StoreProduct::isValidProduct($product_id))
|
||||
return self::setErrorInfo('该产品已下架或删除');
|
||||
if(!StoreProductAttr::issetProductUnique($product_id,$product_attr_unique))
|
||||
return self::setErrorInfo('请选择有效的产品属性');
|
||||
if(StoreProduct::getProductStock($product_id,$product_attr_unique) < $cart_num)
|
||||
return self::setErrorInfo('该产品库存不足'.$cart_num);
|
||||
}
|
||||
$where = ['type'=>$type,'uid'=>$uid,'product_id'=>$product_id,'product_attr_unique'=>$product_attr_unique,'is_new'=>$is_new,'is_pay'=>0,'is_del'=>0,'combination_id'=>$combination_id];
|
||||
if($cart = self::where($where)->find()){
|
||||
$cart->cart_num = $cart_num;
|
||||
$cart->add_time = time();
|
||||
$cart->save();
|
||||
return $cart;
|
||||
}else{
|
||||
return self::set(compact('uid','product_id','cart_num','product_attr_unique','is_new','type','combination_id'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function removeUserCart($uid,$ids)
|
||||
{
|
||||
return self::where('uid',$uid)->where('id','IN',$ids)->update(['is_del'=>1]);
|
||||
}
|
||||
|
||||
public static function getUserCartNum($uid,$type)
|
||||
{
|
||||
return self::where('uid',$uid)->where('type',$type)->where('is_pay',0)->where('is_del',0)->where('is_new',0)->count();
|
||||
}
|
||||
|
||||
public static function changeUserCartNum($cartId,$cartNum,$uid)
|
||||
{
|
||||
return self::where('uid',$uid)->where('id',$cartId)->update(['cart_num'=>$cartNum]);
|
||||
}
|
||||
|
||||
public static function getUserProductCartList($uid,$cartIds='',$status=0)
|
||||
{
|
||||
$productInfoField = 'id,image,slider_image,price,ot_price,vip_price,postage,mer_id,give_integral,cate_id,sales,stock,store_name,store_info,unit_name,is_show,is_del,is_postage,cost';
|
||||
$seckillInfoField = 'id,image,price,ot_price,postage,give_integral,sales,stock,title as store_name,unit_name,is_show,is_del,is_postage,cost';
|
||||
$bargainInfoField = 'id,image,min_price as price,price as ot_price,postage,give_integral,sales,stock,title as store_name,unit_name,status as is_show,is_del,is_postage,cost';
|
||||
$combinationInfoField = 'id,image,price,postage,sales,stock,title as store_name,is_show,is_del,is_postage,cost';
|
||||
$model = new self();
|
||||
$valid = $invalid = [];
|
||||
$model = $model->where('uid',$uid)->where('type','product')->where('is_pay',0)
|
||||
->where('is_del',0);
|
||||
if(!$status) $model->where('is_new',0);
|
||||
if($cartIds) $model->where('id','IN',$cartIds);
|
||||
$list = $model->select()->toArray();
|
||||
if(!count($list)) return compact('valid','invalid');
|
||||
foreach ($list as $k=>$cart){
|
||||
if($cart['seckill_id']){
|
||||
$product = StoreSeckill::field($seckillInfoField)
|
||||
->find($cart['seckill_id'])->toArray();
|
||||
}elseif($cart['bargain_id']){
|
||||
$product = StoreBargain::field($bargainInfoField)
|
||||
->find($cart['bargain_id'])->toArray();
|
||||
}elseif($cart['combination_id']){
|
||||
$product = StoreCombination::field($combinationInfoField)
|
||||
->find($cart['combination_id'])->toArray();
|
||||
}else{
|
||||
$product = StoreProduct::field($productInfoField)
|
||||
->find($cart['product_id'])->toArray();
|
||||
}
|
||||
$cart['productInfo'] = $product;
|
||||
//商品不存在
|
||||
if(!$product){
|
||||
$model->where('id',$cart['id'])->update(['is_del'=>1]);
|
||||
//商品删除或无库存
|
||||
}else if(!$product['is_show'] || $product['is_del'] || !$product['stock']){
|
||||
$invalid[] = $cart;
|
||||
//商品属性不对应
|
||||
}else if(!StoreProductAttr::issetProductUnique($cart['product_id'],$cart['product_attr_unique']) && !$cart['combination_id'] && !$cart['seckill_id']){
|
||||
$invalid[] = $cart;
|
||||
//正常商品
|
||||
}else{
|
||||
if($cart['product_attr_unique']){
|
||||
$attrInfo = StoreProductAttr::uniqueByAttrInfo($cart['product_attr_unique']);
|
||||
//商品没有对应的属性
|
||||
if(!$attrInfo || !$attrInfo['stock'])
|
||||
$invalid[] = $cart;
|
||||
else{
|
||||
$cart['productInfo']['attrInfo'] = $attrInfo;
|
||||
$cart['truePrice'] = (float)$attrInfo['price'];
|
||||
$cart['trueStock'] = $attrInfo['stock'];
|
||||
$cart['costPrice'] = $cart['productInfo']['cost'];
|
||||
$cart['productInfo']['image'] = empty($attrInfo['image']) ? $cart['productInfo']['image'] : $attrInfo['image'];
|
||||
$valid[] = $cart;
|
||||
}
|
||||
}else{
|
||||
$cart['truePrice'] = (float)$cart['productInfo']['price'];
|
||||
$cart['trueStock'] = $cart['productInfo']['stock'];
|
||||
$cart['costPrice'] = $cart['productInfo']['cost'];
|
||||
$valid[] = $cart;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($valid as $k=>$cart){
|
||||
if($cart['trueStock'] < $cart['cart_num']){
|
||||
$cart['cart_num'] = $cart['trueStock'];
|
||||
$model->where('id',$cart['id'])->update(['cart_num'=>$cart['cart_num']]);
|
||||
$valid[$k] = $cart;
|
||||
}
|
||||
}
|
||||
|
||||
return compact('valid','invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团
|
||||
* @param $uid
|
||||
* @param string $cartIds
|
||||
* @return array
|
||||
*/
|
||||
public static function getUserCombinationProductCartList($uid,$cartIds='')
|
||||
{
|
||||
$productInfoField = 'id,image,slider_image,price,cost,ot_price,vip_price,postage,mer_id,give_integral,cate_id,sales,stock,store_name,unit_name,is_show,is_del,is_postage';
|
||||
$model = new self();
|
||||
$valid = $invalid = [];
|
||||
$model = $model->where('uid',$uid)->where('type','product')->where('is_pay',0)
|
||||
->where('is_del',0);
|
||||
if($cartIds) $model->where('id','IN',$cartIds);
|
||||
$list = $model->select()->toArray();
|
||||
if(!count($list)) return compact('valid','invalid');
|
||||
foreach ($list as $k=>$cart){
|
||||
$product = StoreProduct::field($productInfoField)
|
||||
->find($cart['product_id'])->toArray();
|
||||
$cart['productInfo'] = $product;
|
||||
//商品不存在
|
||||
if(!$product){
|
||||
$model->where('id',$cart['id'])->update(['is_del'=>1]);
|
||||
//商品删除或无库存
|
||||
}else if(!$product['is_show'] || $product['is_del'] || !$product['stock']){
|
||||
$invalid[] = $cart;
|
||||
//商品属性不对应
|
||||
// }else if(!StoreProductAttr::issetProductUnique($cart['product_id'],$cart['product_attr_unique'])){
|
||||
// $invalid[] = $cart;
|
||||
//正常商品
|
||||
}else{
|
||||
$cart['truePrice'] = (float)StoreCombination::where('id',$cart['combination_id'])->value('price');
|
||||
$cart['costPrice'] = (float)StoreCombination::where('id',$cart['combination_id'])->value('cost');
|
||||
$cart['trueStock'] = StoreCombination::where('id',$cart['combination_id'])->value('stock');
|
||||
$valid[] = $cart;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($valid as $k=>$cart){
|
||||
if($cart['trueStock'] < $cart['cart_num']){
|
||||
$cart['cart_num'] = $cart['trueStock'];
|
||||
$model->where('id',$cart['id'])->update(['cart_num'=>$cart['cart_num']]);
|
||||
$valid[$k] = $cart;
|
||||
}
|
||||
}
|
||||
|
||||
return compact('valid','invalid');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/12
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
|
||||
class StoreCategory extends ModelBasic
|
||||
{
|
||||
public static function pidByCategory($pid,$field = '*',$limit = 0)
|
||||
{
|
||||
$model = self::where('pid',$pid)->where('is_show',1)->field($field);
|
||||
if($limit) $model->limit($limit);
|
||||
return $model->select();
|
||||
}
|
||||
|
||||
public static function pidBySidList($pid)
|
||||
{
|
||||
return self::where('pid',$pid)->field('id,cate_name,pid')->select();
|
||||
}
|
||||
|
||||
public static function cateIdByPid($cateId)
|
||||
{
|
||||
return self::where('id',$cateId)->value('pid');
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,160 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 拼团model
|
||||
* Class StoreCombination
|
||||
* @package app\routine\model\store
|
||||
*/
|
||||
class StoreCombination extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function get_list($length=10){
|
||||
if($post=input('post.')){
|
||||
$where=$post['where'];
|
||||
$model = new self();
|
||||
$model = $model->alias('c');
|
||||
$model = $model->join('StoreProduct s','s.id=c.product_id');
|
||||
$model = $model->where('c.is_show',1)->where('c.is_del',0)->where('c.start_time','LT',time())->where('c.stop_time','GT',time());
|
||||
if(!empty($where['search'])){
|
||||
$model = $model->where('c.title','like',"%{$where['search']}%");
|
||||
$model = $model->whereOr('s.keyword','like',"{$where['search']}%");
|
||||
}
|
||||
$model = $model->field('c.*,s.price as product_price');
|
||||
if($where['key']){
|
||||
if($where['sales']==1){
|
||||
$model = $model->order('c.sales desc');
|
||||
}else if($where['sales']==2){
|
||||
$model = $model->order('c.sales asc');
|
||||
}
|
||||
if($where['price']==1){
|
||||
$model = $model->order('c.price desc');
|
||||
}else if($where['price']==2){
|
||||
$model = $model->order('c.price asc');
|
||||
}
|
||||
if($where['people']==1){
|
||||
$model = $model->order('c.people asc');
|
||||
}
|
||||
if($where['default']==1){
|
||||
$model = $model->order('c.sort desc,c.id desc');
|
||||
}
|
||||
}else{
|
||||
$model = $model->order('c.sort desc,c.id desc');
|
||||
}
|
||||
$page=is_string($where['page'])?(int)$where['page']+1:$where['page']+1;
|
||||
$list = $model->page($page,$length)->select()->toArray();
|
||||
return ['list'=>$list,'page'=>$page];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有拼团数据
|
||||
* @param int $limit
|
||||
* @param int $length
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getAll($limit = 0,$length = 0){
|
||||
$model = new self();
|
||||
$model = $model->alias('c');
|
||||
$model = $model->join('StoreProduct s','s.id=c.product_id');
|
||||
$model = $model->field('c.*,s.price as product_price');
|
||||
$model = $model->order('c.sort desc,c.id desc');
|
||||
$model = $model->where('c.is_show',1);
|
||||
$model = $model->where('c.is_del',0);
|
||||
$model = $model->where('c.start_time','LT',time());
|
||||
$model = $model->where('c.stop_time','GT',time());
|
||||
if($limit && $length) $model = $model->limit($limit,$length);
|
||||
$list = $model->select();
|
||||
if($list) return $list->toArray();
|
||||
else return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一条拼团数据
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getCombinationOne($id){
|
||||
$model = new self();
|
||||
$model = $model->alias('c');
|
||||
$model = $model->join('StoreProduct s','s.id=c.product_id');
|
||||
$model = $model->field('c.*,s.price as product_price');
|
||||
$model = $model->where('c.is_show',1);
|
||||
$model = $model->where('c.is_del',0);
|
||||
$model = $model->where('c.id',$id);
|
||||
// $model = $model->where('c.start_time','LT',time());
|
||||
// $model = $model->where('c.stop_time','GT',time()-86400);
|
||||
$list = $model->find();
|
||||
if($list) return $list->toArray();
|
||||
else return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推荐的拼团产品
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getCombinationHost($limit = 0){
|
||||
$model = new self();
|
||||
$model = $model->alias('c');
|
||||
$model = $model->join('StoreProduct s','s.id=c.product_id');
|
||||
$model = $model->field('c.id,c.image,c.price,c.sales,c.title,c.people,s.price as product_price');
|
||||
$model = $model->where('c.is_del',0);
|
||||
$model = $model->where('c.is_host',1);
|
||||
$model = $model->where('c.start_time','LT',time());
|
||||
$model = $model->where('c.stop_time','GT',time());
|
||||
if($limit) $model = $model->limit($limit);
|
||||
$list = $model->select();
|
||||
if($list) return $list->toArray();
|
||||
else return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改销量和库存
|
||||
* @param $num
|
||||
* @param $CombinationId
|
||||
* @return bool
|
||||
*/
|
||||
public static function decCombinationStock($num,$CombinationId)
|
||||
{
|
||||
$res = false !== self::where('id',$CombinationId)->dec('stock',$num)->inc('sales',$num)->update();
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* 判断库存是否足够
|
||||
* @param $id
|
||||
* @param $cart_num
|
||||
* @return int|mixed
|
||||
*/
|
||||
public static function getCombinationStock($id,$cart_num){
|
||||
$stock = self::where('id',$id)->value('stock');
|
||||
return $stock > $cart_num ? $stock : 0;
|
||||
}
|
||||
/**
|
||||
* 获取产品状态
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public static function isValidCombination($id){
|
||||
$model = new self();
|
||||
$model = $model->where('id',$id);
|
||||
$model = $model->where('is_del',0);
|
||||
$model = $model->where('is_show',1);
|
||||
return $model->count();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2018/01/22
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreCoupon extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2018/01/18
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreCouponIssue extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param string $prefix
|
||||
* @return $this
|
||||
*/
|
||||
public static function validWhere($prefix = '')
|
||||
{
|
||||
$model = new self;
|
||||
if($prefix){
|
||||
$model->alias($prefix);
|
||||
$prefix .= '.';
|
||||
}
|
||||
$newTime = time();
|
||||
return $model->where("{$prefix}status",1)
|
||||
->where(function($query) use($newTime,$prefix){
|
||||
$query->where(function($query) use($newTime,$prefix){
|
||||
$query->where("{$prefix}start_time",'<',$newTime)->where("{$prefix}end_time",'>',$newTime);
|
||||
})->whereOr(function ($query) use($prefix){
|
||||
$query->where("{$prefix}start_time",0)->where("{$prefix}end_time",0);
|
||||
});
|
||||
})->where("{$prefix}is_del",0);
|
||||
}
|
||||
|
||||
|
||||
public static function issueUserCoupon($id,$uid)
|
||||
{
|
||||
$issueCouponInfo = self::validWhere()->where('id',$id)->find();
|
||||
if(!$issueCouponInfo) return self::setErrorInfo('领取的优惠劵已领完或已过期!');
|
||||
if(StoreCouponIssueUser::be(['uid'=>$uid,'issue_coupon_id'=>$id]))
|
||||
return self::setErrorInfo('已领取过该优惠劵!');
|
||||
self::beginTrans();
|
||||
$res1 = false != StoreCouponUser::addUserCoupon($uid,$issueCouponInfo['cid']);
|
||||
$res2 = false != StoreCouponIssueUser::addUserIssue($uid,$id);
|
||||
$res3 = true;
|
||||
if($issueCouponInfo['total_count'] > 0){
|
||||
$issueCouponInfo['remain_count'] -= 1;
|
||||
$res3 = false !== $issueCouponInfo->save();
|
||||
}
|
||||
$res = $res1 && $res2 & $res3;
|
||||
self::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2018/01/22
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreCouponIssueUser extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
public static function addUserIssue($uid,$issue_coupon_id)
|
||||
{
|
||||
$add_time = time();
|
||||
return self::set(compact('uid','issue_coupon_id','add_time'));
|
||||
}
|
||||
}
|
||||
@ -1,146 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/20
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreCouponUser extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
/**
|
||||
* 获取用户优惠券(全部)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public static function getUserAllCoupon($uid)
|
||||
{
|
||||
self::checkInvalidCoupon();
|
||||
$couponList = self::where('uid',$uid)->order('is_fail ASC,status ASC,add_time DESC')->select()->toArray();
|
||||
return self::tidyCouponList($couponList);
|
||||
}
|
||||
/**
|
||||
* 获取用户优惠券(未使用)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public static function getUserValidCoupon($uid)
|
||||
{
|
||||
self::checkInvalidCoupon();
|
||||
$couponList = self::where('uid',$uid)->where('status',0)->order('is_fail ASC,status ASC,add_time DESC')->select()->toArray();
|
||||
return self::tidyCouponList($couponList);
|
||||
}
|
||||
/**
|
||||
* 获取用户优惠券(已使用)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public static function getUserAlreadyUsedCoupon($uid)
|
||||
{
|
||||
self::checkInvalidCoupon();
|
||||
$couponList = self::where('uid',$uid)->where('status',1)->order('is_fail ASC,status ASC,add_time DESC')->select()->toArray();
|
||||
return self::tidyCouponList($couponList);
|
||||
}
|
||||
/**
|
||||
* 获取用户优惠券(已过期)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public static function getUserBeOverdueCoupon($uid)
|
||||
{
|
||||
self::checkInvalidCoupon();
|
||||
$couponList = self::where('uid',$uid)->where('status',2)->order('is_fail ASC,status ASC,add_time DESC')->select()->toArray();
|
||||
return self::tidyCouponList($couponList);
|
||||
}
|
||||
public static function beUsableCoupon($uid,$price)
|
||||
{
|
||||
return self::where('uid',$uid)->where('is_fail',0)->where('status',0)->where('use_min_price','<=',$price)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户可以使用的优惠券
|
||||
* @param $uid
|
||||
* @param $price
|
||||
* @return false|\PDOStatement|string|\think\Collection
|
||||
*/
|
||||
public static function beUsableCouponList($uid,$price){
|
||||
return self::where('uid',$uid)->where('is_fail',0)->where('status',0)->where('use_min_price','<=',$price)->select();
|
||||
}
|
||||
|
||||
public static function validAddressWhere($model=null,$prefix = '')
|
||||
{
|
||||
self::checkInvalidCoupon();
|
||||
if($prefix) $prefix .='.';
|
||||
$model = self::getSelfModel($model);
|
||||
return $model->where("{$prefix}is_fail",0)->where("{$prefix}status",0);
|
||||
}
|
||||
|
||||
public static function checkInvalidCoupon()
|
||||
{
|
||||
self::where('end_time','<',time())->where('status',0)->update(['status'=>2]);
|
||||
}
|
||||
|
||||
public static function tidyCouponList($couponList)
|
||||
{
|
||||
$time = time();
|
||||
foreach ($couponList as $k=>$coupon){
|
||||
$coupon['_add_time'] = date('Y/m/d',$coupon['add_time']);
|
||||
$coupon['_end_time'] = date('Y/m/d',$coupon['end_time']);
|
||||
$coupon['use_min_price'] = floatval($coupon['use_min_price']);
|
||||
$coupon['coupon_price'] = floatval($coupon['coupon_price']);
|
||||
if($coupon['is_fail']){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已失效';
|
||||
}else if ($coupon['status'] == 1){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已使用';
|
||||
}else if ($coupon['status'] == 2){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已过期';
|
||||
}else if($coupon['add_time'] > $time || $coupon['end_time'] < $time){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已过期';
|
||||
}else{
|
||||
if($coupon['add_time']+ 3600*24 > $time){
|
||||
$coupon['_type'] = 2;
|
||||
$coupon['_msg'] = '可使用';
|
||||
}else{
|
||||
$coupon['_type'] = 1;
|
||||
$coupon['_msg'] = '可使用';
|
||||
}
|
||||
}
|
||||
$couponList[$k] = $coupon;
|
||||
}
|
||||
return $couponList;
|
||||
}
|
||||
|
||||
public static function getUserValidCouponCount($uid)
|
||||
{
|
||||
self::checkInvalidCoupon();
|
||||
return self::where('uid',$uid)->where('status',0)->order('is_fail ASC,status ASC,add_time DESC')->count();
|
||||
}
|
||||
|
||||
public static function useCoupon($id)
|
||||
{
|
||||
return self::where('id',$id)->update(['status'=>1,'use_time'=>time()]);
|
||||
}
|
||||
|
||||
public static function addUserCoupon($uid,$cid,$type = 'get')
|
||||
{
|
||||
$couponInfo = StoreCoupon::find($cid);
|
||||
if(!$couponInfo) return self::setErrorInfo('优惠劵不存在!');
|
||||
$data = [];
|
||||
$data['cid'] = $couponInfo['id'];
|
||||
$data['uid'] = $uid;
|
||||
$data['coupon_title'] = $couponInfo['title'];
|
||||
$data['coupon_price'] = $couponInfo['coupon_price'];
|
||||
$data['use_min_price'] = $couponInfo['use_min_price'];
|
||||
$data['add_time'] = time();
|
||||
$data['end_time'] = $data['add_time']+$couponInfo['coupon_time']*86400;
|
||||
$data['type'] = $type;
|
||||
return self::set($data);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,753 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/20
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use app\routine\model\store\StoreCombination;
|
||||
use app\routine\model\routine\RoutineFormId;
|
||||
use app\routine\model\routine\RoutineTemplate;
|
||||
use app\routine\model\store\StoreOrderCartInfo;
|
||||
use app\routine\model\store\StoreOrderStatus;
|
||||
use app\routine\model\store\StoreCart;
|
||||
use app\routine\model\store\StoreProductReply;
|
||||
use app\routine\model\user\User;
|
||||
use app\routine\model\user\UserAddress;
|
||||
use app\routine\model\user\UserBill;
|
||||
use app\routine\model\user\WechatUser;
|
||||
use basic\ModelBasic;
|
||||
use behavior\routine\StoreProductBehavior;
|
||||
use behavior\wechat\PaymentBehavior;
|
||||
use service\HookService;
|
||||
use service\RoutineService;
|
||||
use service\SystemConfigService;
|
||||
use service\WechatService;
|
||||
use service\WechatTemplateService;
|
||||
use think\Cache;
|
||||
use think\Url;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreOrder extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['add_time'];
|
||||
|
||||
protected static $payType = ['weixin'=>'微信支付','yue'=>'余额支付','offline'=>'线下支付'];
|
||||
|
||||
protected static $deliveryType = ['send'=>'商家配送','express'=>'快递配送'];
|
||||
|
||||
protected function setAddTimeAttr()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
protected function setCartIdAttr($value)
|
||||
{
|
||||
return is_array($value) ? json_encode($value) : $value;
|
||||
}
|
||||
|
||||
protected function getCartIdAttr($value)
|
||||
{
|
||||
return json_decode($value,true);
|
||||
}
|
||||
|
||||
public static function getOrderPriceGroup($cartInfo)
|
||||
{
|
||||
$storePostage = floatval(SystemConfigService::get('store_postage'))?:0;
|
||||
$storeFreePostage = floatval(SystemConfigService::get('store_free_postage'))?:0;
|
||||
$totalPrice = self::getOrderTotalPrice($cartInfo);
|
||||
$costPrice = self::getOrderCostPrice($cartInfo);
|
||||
if(!$storeFreePostage) {
|
||||
$storePostage = 0;
|
||||
}else{
|
||||
foreach ($cartInfo as $cart){
|
||||
if(!$cart['productInfo']['is_postage'])
|
||||
$storePostage = bcadd($storePostage,$cart['productInfo']['postage'],2);
|
||||
|
||||
}
|
||||
if($storeFreePostage <= $totalPrice) $storePostage = 0;
|
||||
}
|
||||
return compact('storePostage','storeFreePostage','totalPrice','costPrice');
|
||||
}
|
||||
|
||||
public static function getOrderTotalPrice($cartInfo)
|
||||
{
|
||||
$totalPrice = 0;
|
||||
foreach ($cartInfo as $cart){
|
||||
$totalPrice = bcadd($totalPrice,bcmul($cart['cart_num'],$cart['truePrice'],2),2);
|
||||
}
|
||||
return $totalPrice;
|
||||
}
|
||||
public static function getOrderCostPrice($cartInfo)
|
||||
{
|
||||
$costPrice=0;
|
||||
foreach ($cartInfo as $cart){
|
||||
$costPrice = bcadd($costPrice,bcmul($cart['cart_num'],$cart['costPrice'],2),2);
|
||||
}
|
||||
return $costPrice;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 拼团
|
||||
* @param $cartInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function getCombinationOrderPriceGroup($cartInfo)
|
||||
{
|
||||
$storePostage = floatval(SystemConfigService::get('store_postage'))?:0;
|
||||
$storeFreePostage = floatval(SystemConfigService::get('store_free_postage'))?:0;
|
||||
$totalPrice = self::getCombinationOrderTotalPrice($cartInfo);
|
||||
$costPrice = self::getCombinationOrderCostPrice($cartInfo);
|
||||
if(!$storeFreePostage) {
|
||||
$storePostage = 0;
|
||||
}else{
|
||||
foreach ($cartInfo as $cart){
|
||||
if(!StoreCombination::where('id',$cart['combination_id'])->value('is_postage'))
|
||||
$storePostage = bcadd($storePostage,StoreCombination::where('id',$cart['combination_id'])->value('postage'),2);
|
||||
}
|
||||
if($storeFreePostage <= $totalPrice) $storePostage = 0;
|
||||
}
|
||||
return compact('storePostage','storeFreePostage','totalPrice','costPrice');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 拼团价格
|
||||
* @param $cartInfo
|
||||
* @return float
|
||||
*/
|
||||
public static function getCombinationOrderTotalPrice($cartInfo)
|
||||
{
|
||||
$totalPrice = 0;
|
||||
foreach ($cartInfo as $cart){
|
||||
if($cart['combination_id']){
|
||||
$totalPrice = bcadd($totalPrice,bcmul($cart['cart_num'],StoreCombination::where('id',$cart['combination_id'])->value('price'),2),2);
|
||||
}
|
||||
}
|
||||
return (float)$totalPrice;
|
||||
}
|
||||
public static function getCombinationOrderCostPrice($cartInfo)
|
||||
{
|
||||
$costPrice = 0;
|
||||
foreach ($cartInfo as $cart){
|
||||
if($cart['combination_id']){
|
||||
$totalPrice = bcadd($costPrice,bcmul($cart['cart_num'],StoreCombination::where('id',$cart['combination_id'])->value('price'),2),2);
|
||||
}
|
||||
}
|
||||
return (float)$costPrice;
|
||||
}
|
||||
|
||||
|
||||
public static function cacheOrderInfo($uid,$cartInfo,$priceGroup,$other = [],$cacheTime = 600)
|
||||
{
|
||||
$key = md5(time());
|
||||
Cache::set('user_order_'.$uid.$key,compact('cartInfo','priceGroup','other'),$cacheTime);
|
||||
return $key;
|
||||
}
|
||||
|
||||
public static function getCacheOrderInfo($uid,$key)
|
||||
{
|
||||
$cacheName = 'user_order_'.$uid.$key;
|
||||
if(!Cache::has($cacheName)) return null;
|
||||
return Cache::get($cacheName);
|
||||
}
|
||||
|
||||
public static function clearCacheOrderInfo($uid,$key)
|
||||
{
|
||||
Cache::clear('user_order_'.$uid.$key);
|
||||
}
|
||||
|
||||
public static function cacheKeyCreateOrder($uid,$key,$addressId,$payType,$useIntegral = false,$couponId = 0,$mark = '',$combinationId = 0,$pinkId = 0,$seckill_id=0,$bargain_id=0)
|
||||
{
|
||||
if(!array_key_exists($payType,self::$payType)) return self::setErrorInfo('选择支付方式有误!');
|
||||
if(self::be(['unique'=>$key,'uid'=>$uid])) return self::setErrorInfo('请勿重复提交订单');
|
||||
$userInfo = User::getUserInfo($uid);
|
||||
if(!$userInfo) return self::setErrorInfo('用户不存在!');
|
||||
$cartGroup = self::getCacheOrderInfo($uid,$key);
|
||||
if(!$cartGroup) return self::setErrorInfo('订单已过期,请刷新当前页面!');
|
||||
$cartInfo = $cartGroup['cartInfo'];
|
||||
$priceGroup = $cartGroup['priceGroup'];
|
||||
$other = $cartGroup['other'];
|
||||
$payPrice = $priceGroup['totalPrice'];
|
||||
$payPostage = $priceGroup['storePostage'];
|
||||
if(!$addressId) return self::setErrorInfo('请选择收货地址!');
|
||||
if(!UserAddress::be(['uid'=>$uid,'id'=>$addressId,'is_del'=>0]) || !($addressInfo = UserAddress::find($addressId)))
|
||||
return self::setErrorInfo('地址选择有误!');
|
||||
|
||||
//使用优惠劵
|
||||
$res1 = true;
|
||||
if($couponId){
|
||||
$couponInfo = StoreCouponUser::validAddressWhere()->where('id',$couponId)->where('uid',$uid)->find();
|
||||
if(!$couponInfo) return self::setErrorInfo('选择的优惠劵无效!');
|
||||
if($couponInfo['use_min_price'] > $payPrice)
|
||||
return self::setErrorInfo('不满足优惠劵的使用条件!');
|
||||
$payPrice = bcsub($payPrice,$couponInfo['coupon_price'],2);
|
||||
$res1 = StoreCouponUser::useCoupon($couponId);
|
||||
$couponPrice = $couponInfo['coupon_price'];
|
||||
}else{
|
||||
$couponId = 0;
|
||||
$couponPrice = 0;
|
||||
}
|
||||
if(!$res1) return self::setErrorInfo('使用优惠劵失败!');
|
||||
|
||||
//是否包邮
|
||||
if((isset($other['offlinePostage']) && $other['offlinePostage'] && $payType == 'offline')) $payPostage = 0;
|
||||
$payPrice = bcadd($payPrice,$payPostage,2);
|
||||
|
||||
//积分抵扣
|
||||
$res2 = true;
|
||||
if($useIntegral && $userInfo['integral'] > 0){
|
||||
$deductionPrice = bcmul($userInfo['integral'],$other['integralRatio'],2);
|
||||
if($deductionPrice < $payPrice){
|
||||
$payPrice = bcsub($payPrice,$deductionPrice,2);
|
||||
$usedIntegral = $userInfo['integral'];
|
||||
$res2 = false !== User::edit(['integral'=>0],$userInfo['uid'],'uid');
|
||||
}else{
|
||||
$deductionPrice = $payPrice;
|
||||
$usedIntegral = bcdiv($payPrice,$other['integralRatio'],2);
|
||||
$res2 = false !== User::bcDec($userInfo['uid'],'integral',$usedIntegral,'uid');
|
||||
$payPrice = 0;
|
||||
}
|
||||
$res2 = $res2 && false != UserBill::expend('积分抵扣',$uid,'integral','deduction',$usedIntegral,$key,$userInfo['integral'],'购买商品使用'.floatval($usedIntegral).'积分抵扣'.floatval($deductionPrice).'元');
|
||||
}else{
|
||||
$deductionPrice = 0;
|
||||
$usedIntegral = 0;
|
||||
}
|
||||
if(!$res2) return self::setErrorInfo('使用积分抵扣失败!');
|
||||
|
||||
$cartIds = [];
|
||||
$totalNum = 0;
|
||||
$gainIntegral = 0;
|
||||
foreach ($cartInfo as $cart){
|
||||
$cartIds[] = $cart['id'];
|
||||
$totalNum += $cart['cart_num'];
|
||||
$gainIntegral = bcadd($gainIntegral,isset($cart['productInfo']['give_integral']) ? : 0,2);
|
||||
}
|
||||
$orderInfo = [
|
||||
'uid'=>$uid,
|
||||
'order_id'=>self::getNewOrderId(),
|
||||
'real_name'=>$addressInfo['real_name'],
|
||||
'user_phone'=>$addressInfo['phone'],
|
||||
'user_address'=>$addressInfo['province'].' '.$addressInfo['city'].' '.$addressInfo['district'].' '.$addressInfo['detail'],
|
||||
'cart_id'=>$cartIds,
|
||||
'total_num'=>$totalNum,
|
||||
'total_price'=>$priceGroup['totalPrice'],
|
||||
'total_postage'=>$priceGroup['storePostage'],
|
||||
'coupon_id'=>$couponId,
|
||||
'coupon_price'=>$couponPrice,
|
||||
'pay_price'=>$payPrice,
|
||||
'pay_postage'=>$payPostage,
|
||||
'deduction_price'=>$deductionPrice,
|
||||
'paid'=>0,
|
||||
'pay_type'=>$payType,
|
||||
'use_integral'=>$usedIntegral,
|
||||
'gain_integral'=>$gainIntegral,
|
||||
'mark'=>htmlspecialchars($mark),
|
||||
'combination_id'=>$combinationId,
|
||||
'pink_id'=>$pinkId,
|
||||
'seckill_id'=>$seckill_id,
|
||||
'bargain_id'=>$bargain_id,
|
||||
'cost'=>$priceGroup['costPrice'],
|
||||
'is_channel'=>1,
|
||||
'unique'=>$key
|
||||
];
|
||||
$order = self::set($orderInfo);
|
||||
if(!$order)return self::setErrorInfo('订单生成失败!');
|
||||
$res5 = true;
|
||||
foreach ($cartInfo as $cart){
|
||||
//减库存加销量
|
||||
if($combinationId) $res5 = $res5 && StoreCombination::decCombinationStock($cart['cart_num'],$combinationId);
|
||||
else if($seckill_id) $res5 = $res5 && StoreSeckill::decSeckillStock($cart['cart_num'],$seckill_id);
|
||||
else if($bargain_id) $res5 = $res5 && StoreBargain::decBargainStock($cart['cart_num'],$bargain_id);
|
||||
else $res5 = $res5 && StoreProduct::decProductStock($cart['cart_num'],$cart['productInfo']['id'],isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique']:'');
|
||||
}
|
||||
//保存购物车商品信息
|
||||
$res4 = false !== StoreOrderCartInfo::setCartInfo($order['id'],$cartInfo);
|
||||
//购物车状态修改
|
||||
$res6 = false !== StoreCart::where('id','IN',$cartIds)->update(['is_pay'=>1]);
|
||||
if(!$res4 || !$res5 || !$res6) return self::setErrorInfo('订单生成失败!');
|
||||
try{
|
||||
HookService::listen('store_product_order_create',$order,compact('cartInfo','addressId'),false,StoreProductBehavior::class);
|
||||
}catch (\Exception $e){
|
||||
return self::setErrorInfo($e->getMessage());
|
||||
}
|
||||
self::clearCacheOrderInfo($uid,$key);
|
||||
self::commitTrans();
|
||||
StoreOrderStatus::status($order['id'],'cache_key_create_order','订单生成');
|
||||
return $order;
|
||||
}
|
||||
|
||||
public static function getNewOrderId()
|
||||
{
|
||||
$count = (int) self::where('add_time',['>=',strtotime(date("Y-m-d"))],['<',strtotime(date("Y-m-d",strtotime('+1 day')))])->count();
|
||||
return 'wx'.date('YmdHis',time()).(10000+$count+1);
|
||||
}
|
||||
|
||||
public static function changeOrderId($orderId)
|
||||
{
|
||||
$ymd = substr($orderId,2,8);
|
||||
$key = substr($orderId,16);
|
||||
return 'wx'.$ymd.date('His').$key;
|
||||
}
|
||||
|
||||
public static function jsPay($orderId,$field = 'order_id')
|
||||
{
|
||||
if(is_string($orderId))
|
||||
$orderInfo = self::where($field,$orderId)->find();
|
||||
else
|
||||
$orderInfo = $orderId;
|
||||
if(!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
|
||||
if($orderInfo['paid']) exception('支付已支付!');
|
||||
if($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
|
||||
$openid = WechatUser::getOpenId($orderInfo['uid']);
|
||||
return RoutineService::payRoutine($openid,$orderInfo['order_id'],$orderInfo['pay_price'],'productr',SystemConfigService::get('site_name'));
|
||||
}
|
||||
|
||||
public static function yuePay($order_id,$uid,$formId = '')
|
||||
{
|
||||
$orderInfo = self::where('uid',$uid)->where('order_id',$order_id)->where('is_del',0)->find();
|
||||
if(!$orderInfo) return self::setErrorInfo('订单不存在!');
|
||||
if($orderInfo['paid']) return self::setErrorInfo('该订单已支付!');
|
||||
if($orderInfo['pay_type'] != 'yue') return self::setErrorInfo('该订单不能使用余额支付!');
|
||||
$userInfo = User::getUserInfo($uid);
|
||||
if($userInfo['now_money'] < $orderInfo['pay_price'])
|
||||
return self::setErrorInfo('余额不足'.floatval($orderInfo['pay_price']));
|
||||
self::beginTrans();
|
||||
$res1 = false !== User::bcDec($uid,'now_money',$orderInfo['pay_price'],'uid');
|
||||
$res2 = UserBill::expend('购买商品',$uid,'now_money','pay_product',$orderInfo['pay_price'],$orderInfo['id'],$userInfo['now_money'],'余额支付'.floatval($orderInfo['pay_price']).'元购买商品');
|
||||
$res3 = self::paySuccess($order_id,$formId);
|
||||
try{
|
||||
// HookService::listen('yue_pay_product',$userInfo,$orderInfo,false,PaymentBehavior::class);
|
||||
}catch (\Exception $e){
|
||||
self::rollbackTrans();
|
||||
return self::setErrorInfo($e->getMessage());
|
||||
}
|
||||
$res = $res1 && $res2 && $res3;
|
||||
self::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信支付 为 0元时
|
||||
* @param $order_id
|
||||
* @param $uid
|
||||
* @return bool
|
||||
*/
|
||||
public static function jsPayPrice($order_id,$uid,$formId = ''){
|
||||
$orderInfo = self::where('uid',$uid)->where('order_id',$order_id)->where('is_del',0)->find();
|
||||
if(!$orderInfo) return self::setErrorInfo('订单不存在!');
|
||||
if($orderInfo['paid']) return self::setErrorInfo('该订单已支付!');
|
||||
$userInfo = User::getUserInfo($uid);
|
||||
self::beginTrans();
|
||||
$res1 = UserBill::expend('购买商品',$uid,'now_money','pay_product',$orderInfo['pay_price'],$orderInfo['id'],$userInfo['now_money'],'微信支付'.floatval($orderInfo['pay_price']).'元购买商品');
|
||||
$res2 = self::paySuccess($order_id,$formId);
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户申请退款
|
||||
* @param $uni
|
||||
* @param $uid
|
||||
* @param string $refundReasonWap
|
||||
* @return bool
|
||||
*/
|
||||
public static function orderApplyRefund($uni, $uid,$refundReasonWap = '',$refundReasonWapExplain = '',$refundReasonWapImg = array())
|
||||
{
|
||||
$order = self::getUserOrderDetail($uid,$uni);
|
||||
if(!$order) return self::setErrorInfo('支付订单不存在!');
|
||||
if($order['refund_status'] == 2) return self::setErrorInfo('订单已退款!');
|
||||
if($order['refund_status'] == 1) return self::setErrorInfo('正在申请退款中!');
|
||||
if($order['status'] == 1) return self::setErrorInfo('订单当前无法退款!');
|
||||
self::beginTrans();
|
||||
$res1 = false !== StoreOrderStatus::status($order['id'],'apply_refund','用户申请退款,原因:'.$refundReasonWap);
|
||||
$res2 = false !== self::edit(['refund_status'=>1,'refund_reason_time'=>time(),'refund_reason_wap'=>$refundReasonWap,'refund_reason_wap_explain'=>$refundReasonWapExplain,'refund_reason_wap_img'=>json_encode($refundReasonWapImg)],$order['id'],'id');
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
if(!$res)
|
||||
return self::setErrorInfo('申请退款失败!');
|
||||
else{
|
||||
$adminIds = SystemConfigService::get('site_store_admin_uids');
|
||||
if(!empty($adminIds)){
|
||||
try{
|
||||
if(!($adminList = array_unique(array_filter(explode(',',trim($adminIds)))))){
|
||||
self::setErrorInfo('申请退款成功,');
|
||||
return false;
|
||||
}
|
||||
RoutineTemplate::sendOrderRefundStatus($order,$refundReasonWap,$adminList);//小程序 发送模板消息
|
||||
}catch (\Exception $e){}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* //TODO 支付成功后
|
||||
* @param $orderId
|
||||
* @param $notify
|
||||
* @return bool
|
||||
*/
|
||||
public static function paySuccess($orderId,$formId = '')
|
||||
{
|
||||
$order = self::where('order_id',$orderId)->find();
|
||||
$resPink = true;
|
||||
$res1 = self::where('order_id',$orderId)->update(['paid'=>1,'pay_time'=>time()]);
|
||||
User::bcInc($order['uid'],'pay_count',1,'uid');
|
||||
if($order->combination_id && $res1 && !$order->refund_status) $resPink = StorePink::createPink($order);//创建拼团
|
||||
$oid = self::where('order_id',$orderId)->value('id');
|
||||
StoreOrderStatus::status($oid,'pay_success','用户付款成功');
|
||||
RoutineTemplate::sendOrderSuccess($formId,$orderId);
|
||||
$res = $res1 && $resPink;
|
||||
return false !== $res;
|
||||
}
|
||||
|
||||
public static function createOrderTemplate($order)
|
||||
{
|
||||
$goodsName = StoreOrderCartInfo::getProductNameList($order['id']);
|
||||
WechatTemplateService::sendTemplate(WechatUser::getOpenId($order['uid']),WechatTemplateService::ORDER_CREATE, [
|
||||
'first'=>'亲,您购买的商品已支付成功',
|
||||
'keyword1'=>date('Y/m/d H:i',$order['add_time']),
|
||||
'keyword2'=>implode(',',$goodsName),
|
||||
'keyword3'=>$order['order_id'],
|
||||
'remark'=>'点击查看订单详情'
|
||||
],Url::build('/wap/My/order',['uni'=>$order['order_id']],true,true));
|
||||
WechatTemplateService::sendAdminNoticeTemplate([
|
||||
'first'=>"亲,您有一个新订单 \n订单号:{$order['order_id']}",
|
||||
'keyword1'=>'新订单',
|
||||
'keyword2'=>'线下支付',
|
||||
'keyword3'=>date('Y/m/d H:i',time()),
|
||||
'remark'=>'请及时处理'
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getUserOrderDetail($uid,$key)
|
||||
{
|
||||
return self::where('order_id|unique',$key)->where('uid',$uid)->where('is_del',0)->find();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 订单发货
|
||||
* @param array $postageData 发货信息
|
||||
* @param string $oid orderID
|
||||
*/
|
||||
public static function orderPostageAfter($postageData, $oid)
|
||||
{
|
||||
$order = self::where('id',$oid)->find();
|
||||
$openid = WechatUser::getOpenId($order['uid']);
|
||||
$url = Url::build('wap/My/order',['uni'=>$order['order_id']],true,true);
|
||||
$group = [
|
||||
'first'=>'亲,您的订单已发货,请注意查收',
|
||||
'remark'=>'点击查看订单详情'
|
||||
];
|
||||
if($postageData['delivery_type'] == 'send'){//送货
|
||||
$goodsName = StoreOrderCartInfo::getProductNameList($order['id']);
|
||||
$group = array_merge($group,[
|
||||
'keyword1'=>$goodsName,
|
||||
'keyword2'=>$order['pay_type'] == 'offline' ? '线下支付' : date('Y/m/d H:i',$order['pay_time']),
|
||||
'keyword3'=>$order['user_address'],
|
||||
'keyword4'=>$postageData['delivery_name'],
|
||||
'keyword5'=>$postageData['delivery_id']
|
||||
]);
|
||||
WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_DELIVER_SUCCESS,$group,$url);
|
||||
|
||||
}else if($postageData['delivery_type'] == 'express'){//发货
|
||||
$group = array_merge($group,[
|
||||
'keyword1'=>$order['order_id'],
|
||||
'keyword2'=>$postageData['delivery_name'],
|
||||
'keyword3'=>$postageData['delivery_id']
|
||||
]);
|
||||
WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_POSTAGE_SUCCESS,$group,$url);
|
||||
}
|
||||
}
|
||||
|
||||
public static function orderTakeAfter($order)
|
||||
{
|
||||
$openid = WechatUser::getOpenId($order['uid']);
|
||||
WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_TAKE_SUCCESS,[
|
||||
'first'=>'亲,您的订单以成功签收,快去评价一下吧',
|
||||
'keyword1'=>$order['order_id'],
|
||||
'keyword2'=>'已收货',
|
||||
'keyword3'=>date('Y/m/d H:i',time()),
|
||||
'keyword4'=>implode(',',StoreOrderCartInfo::getProductNameList($order['id'])),
|
||||
'remark'=>'点击查看订单详情'
|
||||
],Url::build('My/order',['uni'=>$order['order_id']],true,true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除订单
|
||||
* @param $uni
|
||||
* @param $uid
|
||||
* @return bool
|
||||
*/
|
||||
public static function removeOrder($uni, $uid)
|
||||
{
|
||||
$order = self::getUserOrderDetail($uid,$uni);
|
||||
if(!$order) return self::setErrorInfo('订单不存在!');
|
||||
$order = self::tidyOrder($order);
|
||||
if($order['_status']['_type'] != 0 && $order['_status']['_type']!= -2 && $order['_status']['_type'] != 4)
|
||||
return self::setErrorInfo('该订单无法删除!');
|
||||
if(false !== self::edit(['is_del'=>1],$order['id'],'id') &&
|
||||
false !==StoreOrderStatus::status($order['id'],'remove_order','删除订单'))
|
||||
return true;
|
||||
else
|
||||
return self::setErrorInfo('订单删除失败!');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* //TODO 用户确认收货
|
||||
* @param $uni
|
||||
* @param $uid
|
||||
*/
|
||||
public static function takeOrder($uni, $uid)
|
||||
{
|
||||
$order = self::getUserOrderDetail($uid,$uni);
|
||||
if(!$order) return self::setErrorInfo('订单不存在!');
|
||||
$order = self::tidyOrder($order);
|
||||
if($order['_status']['_type'] != 2) return self::setErrorInfo('订单状态错误!');
|
||||
self::beginTrans();
|
||||
if(false !== self::edit(['status'=>2],$order['id'],'id') &&
|
||||
false !== StoreOrderStatus::status($order['id'],'user_take_delivery','用户已收货')){
|
||||
try{
|
||||
HookService::listen('store_product_order_user_take_delivery',$order,$uid,false,StoreProductBehavior::class);
|
||||
}catch (\Exception $e){
|
||||
return self::setErrorInfo($e->getMessage());
|
||||
}
|
||||
self::commitTrans();
|
||||
return true;
|
||||
}else{
|
||||
self::rollbackTrans();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function tidyOrder($order,$detail = false)
|
||||
{
|
||||
if($detail == true && isset($order['id'])){
|
||||
$cartInfo = self::getDb('StoreOrderCartInfo')->where('oid',$order['id'])->column('cart_info','unique')?:[];
|
||||
foreach ($cartInfo as $k=>$cart){
|
||||
$cartInfo[$k] = json_decode($cart, true);
|
||||
$cartInfo[$k]['unique'] = $k;
|
||||
}
|
||||
$order['cartInfo'] = $cartInfo;
|
||||
}
|
||||
|
||||
$status = [];
|
||||
if(!$order['paid'] && $order['pay_type'] == 'offline' && !$order['status'] >= 2){
|
||||
$status['_type'] = 9;
|
||||
$status['_title'] = '线下付款';
|
||||
$status['_msg'] = '等待商家处理,请耐心等待';
|
||||
$status['_class'] = 'nobuy';
|
||||
}else if(!$order['paid']){
|
||||
$status['_type'] = 0;
|
||||
$status['_title'] = '未支付';
|
||||
$status['_msg'] = '立即支付订单吧';
|
||||
$status['_class'] = 'nobuy';
|
||||
}else if($order['refund_status'] == 1){
|
||||
$status['_type'] = -1;
|
||||
$status['_title'] = '申请退款中';
|
||||
$status['_msg'] = '商家审核中,请耐心等待';
|
||||
$status['_class'] = 'state-sqtk';
|
||||
}else if($order['refund_status'] == 2){
|
||||
$status['_type'] = -2;
|
||||
$status['_title'] = '已退款';
|
||||
$status['_msg'] = '已为您退款,感谢您的支持';
|
||||
$status['_class'] = 'state-sqtk';
|
||||
}else if(!$order['status']){
|
||||
if($order['pink_id']){
|
||||
if(StorePink::where('id',$order['pink_id'])->where('status',1)->count()){
|
||||
$status['_type'] = 1;
|
||||
$status['_title'] = '拼团中';
|
||||
$status['_msg'] = '等待其他人参加拼团';
|
||||
$status['_class'] = 'state-nfh';
|
||||
}else{
|
||||
$status['_type'] = 1;
|
||||
$status['_title'] = '未发货';
|
||||
$status['_msg'] = '商家未发货,请耐心等待';
|
||||
$status['_class'] = 'state-nfh';
|
||||
}
|
||||
}else{
|
||||
$status['_type'] = 1;
|
||||
$status['_title'] = '未发货';
|
||||
$status['_msg'] = '商家未发货,请耐心等待';
|
||||
$status['_class'] = 'state-nfh';
|
||||
}
|
||||
}else if($order['status'] == 1){
|
||||
$status['_type'] = 2;
|
||||
$status['_title'] = '待收货';
|
||||
$status['_msg'] = date('m月d日H时i分',StoreOrderStatus::getTime($order['id'],'delivery_goods')).'服务商已发货';
|
||||
$status['_class'] = 'state-ysh';
|
||||
}else if($order['status'] == 2){
|
||||
$status['_type'] = 3;
|
||||
$status['_title'] = '待评价';
|
||||
$status['_msg'] = '已收货,快去评价一下吧';
|
||||
$status['_class'] = 'state-ypj';
|
||||
}else if($order['status'] == 3){
|
||||
$status['_type'] = 4;
|
||||
$status['_title'] = '交易完成';
|
||||
$status['_msg'] = '交易完成,感谢您的支持';
|
||||
$status['_class'] = 'state-ytk';
|
||||
}
|
||||
if(isset($order['pay_type']))
|
||||
$status['_payType'] = isset(self::$payType[$order['pay_type']]) ? self::$payType[$order['pay_type']] : '其他方式';
|
||||
if(isset($order['delivery_type']))
|
||||
$status['_deliveryType'] = isset(self::$deliveryType[$order['delivery_type']]) ? self::$deliveryType[$order['delivery_type']] : '其他方式';
|
||||
$order['_status'] = $status;
|
||||
return $order;
|
||||
}
|
||||
|
||||
public static function statusByWhere($status,$model = null)
|
||||
{
|
||||
$orderId = StorePink::where('uid',User::getActiveUid())->where('status',1)->column('order_id','id');//获取正在拼团的订单编号
|
||||
if($model == null) $model = new self;
|
||||
if('' === $status)
|
||||
return $model;
|
||||
else if($status == 0)
|
||||
return $model->where('paid',0)->where('status',0)->where('refund_status',0);
|
||||
else if($status == 1)//待发货
|
||||
return $model->where('paid',1)->where('order_id','NOT IN',implode(',',$orderId))->where('status',0)->where('refund_status',0);
|
||||
else if($status == 2)
|
||||
return $model->where('paid',1)->where('status',1)->where('refund_status',0);
|
||||
else if($status == 3)
|
||||
return $model->where('paid',1)->where('status',2)->where('refund_status',0);
|
||||
else if($status == 4)
|
||||
return $model->where('paid',1)->where('status',3)->where('refund_status',0);
|
||||
else if($status == -1)
|
||||
return $model->where('paid',1)->where('refund_status',1);
|
||||
else if($status == -2)
|
||||
return $model->where('paid',1)->where('refund_status',2);
|
||||
else if($status == -3)
|
||||
return $model->where('paid',1)->where('refund_status','IN','1,2');
|
||||
else if($status == 11){
|
||||
return $model->where('order_id','IN',implode(',',$orderId));
|
||||
}
|
||||
else
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getUserOrderList($uid,$status = '',$first = 0,$limit = 8)
|
||||
{
|
||||
$list = self::statusByWhere($status)->where('is_del',0)->where('uid',$uid)
|
||||
->field('seckill_id,bargain_id,combination_id,id,order_id,pay_price,total_num,total_price,pay_postage,total_postage,paid,status,refund_status,pay_type,coupon_price,deduction_price,pink_id,delivery_type')
|
||||
->order('add_time DESC')->limit($first,$limit)->select()->toArray();
|
||||
foreach ($list as $k=>$order){
|
||||
$list[$k] = self::tidyOrder($order,true);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推广人地下用户的订单金额
|
||||
* @param string $uid
|
||||
* @param string $status
|
||||
* @return array
|
||||
*/
|
||||
public static function getUserOrderCount($uid = '',$status = ''){
|
||||
$res = self::statusByWhere($status)->where('uid','IN',$uid)->column('pay_price');
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function searchUserOrder($uid,$order_id)
|
||||
{
|
||||
$order = self::where('uid',$uid)->where('order_id',$order_id)->where('is_del',0)->field('seckill_id,bargain_id,combination_id,id,order_id,pay_price,total_num,total_price,pay_postage,total_postage,paid,status,refund_status,pay_type,coupon_price,deduction_price,delivery_type')
|
||||
->order('add_time DESC')->find();
|
||||
if(!$order)
|
||||
return false;
|
||||
else
|
||||
return self::tidyOrder($order->toArray(),true);
|
||||
|
||||
}
|
||||
|
||||
public static function orderOver($oid)
|
||||
{
|
||||
$res = self::edit(['status'=>'3'],$oid,'id');
|
||||
if(!$res) exception('评价后置操作失败!');
|
||||
StoreOrderStatus::status($oid,'check_order_over','用户评价');
|
||||
}
|
||||
|
||||
public static function checkOrderOver($oid)
|
||||
{
|
||||
$uniqueList = StoreOrderCartInfo::where('oid',$oid)->column('unique');
|
||||
if(StoreProductReply::where('unique','IN',$uniqueList)->where('oid',$oid)->count() == count($uniqueList)){
|
||||
HookService::listen('store_product_order_over',$oid,null,false,StoreProductBehavior::class);
|
||||
self::orderOver($oid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function getOrderStatusNum($uid)
|
||||
{
|
||||
$noBuy = self::where('uid',$uid)->where('paid',0)->where('is_del',0)->where('pay_type','<>','offline')->count();
|
||||
$noPostageNoPink = self::where('o.uid',$uid)->alias('o')->where('o.paid',1)->where('o.pink_id',0)->where('o.is_del',0)->where('o.status',0)->where('o.pay_type','<>','offline')->count();
|
||||
$noPostageYesPink = self::where('o.uid',$uid)->alias('o')->join('StorePink p','o.pink_id = p.id')->where('p.status',2)->where('o.paid',1)->where('o.is_del',0)->where('o.status',0)->where('o.pay_type','<>','offline')->count();
|
||||
$noPostage = bcadd($noPostageNoPink,$noPostageYesPink);
|
||||
$noTake = self::where('uid',$uid)->where('paid',1)->where('is_del',0)->where('status',1)->where('pay_type','<>','offline')->count();
|
||||
$noReply = self::where('uid',$uid)->where('paid',1)->where('is_del',0)->where('status',2)->count();
|
||||
$noPink = self::where('o.uid',$uid)->alias('o')->join('StorePink p','o.pink_id = p.id')->where('p.status',1)->where('o.paid',1)->where('o.is_del',0)->where('o.status',0)->where('o.pay_type','<>','offline')->count();
|
||||
$noRefund = self::where('uid',$uid)->where('paid',1)->where('is_del',0)->where('refund_status','IN','1,2')->count();
|
||||
return compact('noBuy','noPostage','noTake','noReply','noPink','noRefund');
|
||||
}
|
||||
|
||||
public static function gainUserIntegral($order)
|
||||
{
|
||||
if($order['gain_integral'] > 0){
|
||||
$userInfo = User::getUserInfo($order['uid']);
|
||||
ModelBasic::beginTrans();
|
||||
$res1 = false != User::where('uid',$userInfo['uid'])->update(['integral'=>bcadd($userInfo['integral'],$order['gain_integral'],2)]);
|
||||
$res2 = false != UserBill::income('购买商品赠送积分',$order['uid'],'integral','gain',$order['gain_integral'],$order['id'],$userInfo['integral'],'购买商品赠送'.floatval($order['gain_integral']).'积分');
|
||||
$res = $res1 && $res2;
|
||||
ModelBasic::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前订单中有没有拼团存在
|
||||
* @param $pid
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getIsOrderPink($pid = 0 ,$uid = 0){
|
||||
return self::where('uid',$uid)->where('pink_id',$pid)->where('refund_status',0)->where('is_del',0)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取order_id
|
||||
* @param $pid
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getStoreIdPink($pid = 0 ,$uid = 0){
|
||||
return self::where('uid',$uid)->where('pink_id',$pid)->where('is_del',0)->value('order_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除当前用户拼团未支付的订单
|
||||
*/
|
||||
public static function delCombination(){
|
||||
self::where('combination','GT',0)->where('paid',0)->where('uid',User::getActiveUid())->delete();
|
||||
}
|
||||
|
||||
public static function getUserPrice($uid =0){
|
||||
if(!$uid) return 0;
|
||||
$price = self::where('paid',1)->where('uid',$uid)->where('status',2)->where('refund_status',0)->column('pay_price','id');
|
||||
$count = 0;
|
||||
if($price){
|
||||
foreach ($price as $v){
|
||||
$count = bcadd($count,$v,2);
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/26
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreOrderCartInfo extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
public static function getCartInfoAttr($value)
|
||||
{
|
||||
return json_decode($value,true)?:[];
|
||||
}
|
||||
|
||||
public static function setCartInfo($oid,array $cartInfo)
|
||||
{
|
||||
$group = [];
|
||||
foreach ($cartInfo as $cart){
|
||||
$group[] = [
|
||||
'oid'=>$oid,
|
||||
'cart_id'=>$cart['id'],
|
||||
'product_id'=>$cart['productInfo']['id'],
|
||||
'cart_info'=>json_encode($cart),
|
||||
'unique'=>md5($cart['id'].''.$oid)
|
||||
];
|
||||
}
|
||||
return self::setAll($group);
|
||||
}
|
||||
|
||||
public static function getProductNameList($oid)
|
||||
{
|
||||
$cartInfo = self::where('oid',$oid)->select();
|
||||
$goodsName = [];
|
||||
foreach ($cartInfo as $cart){
|
||||
$suk = isset($cart['cart_info']['productInfo']['attrInfo']) ? '('.$cart['cart_info']['productInfo']['attrInfo']['suk'].')' : '';
|
||||
$goodsName[] = $cart['cart_info']['productInfo']['store_name'].$suk;
|
||||
}
|
||||
return $goodsName;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/28
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreOrderStatus extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
public static function status($oid,$change_type,$change_message,$change_time = null)
|
||||
{
|
||||
if($change_time == null) $change_time = time();
|
||||
return self::set(compact('oid','change_type','change_message','change_time'));
|
||||
}
|
||||
|
||||
public static function getTime($oid,$change_type)
|
||||
{
|
||||
return self::where('oid',$oid)->where('change_type',$change_type)->value('change_time');
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,373 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/18
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
use app\routine\model\store\StoreCombination;
|
||||
use app\routine\model\user\User;
|
||||
use app\routine\model\user\UserBill;
|
||||
use app\routine\model\user\WechatUser;
|
||||
use basic\ModelBasic;
|
||||
use service\SystemConfigService;
|
||||
use service\WechatTemplateService;
|
||||
use think\Url;
|
||||
use traits\ModelTrait;
|
||||
|
||||
/**
|
||||
* 拼团Model
|
||||
* Class StorePink
|
||||
* @package app\wap\model\store
|
||||
*/
|
||||
class StorePink extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
|
||||
/**
|
||||
* 获取一条拼团数据
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getPinkUserOne($id){
|
||||
$model = new self();
|
||||
$model = $model->alias('p');
|
||||
$model = $model->field('p.*,u.nickname,u.avatar');
|
||||
$model = $model->where('id',$id);
|
||||
$model = $model->join('__USER__ u','u.uid = p.uid');
|
||||
$list = $model->find();
|
||||
if($list) return $list->toArray();
|
||||
else return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取拼团的团员
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getPinkMember($id){
|
||||
$model = new self();
|
||||
$model = $model->alias('p');
|
||||
$model = $model->field('p.*,u.nickname,u.avatar');
|
||||
$model = $model->where('k_id',$id);
|
||||
$model = $model->where('is_refund',0);
|
||||
$model = $model->join('__USER__ u','u.uid = p.uid');
|
||||
$model = $model->order('id asc');
|
||||
$list = $model->select();
|
||||
if($list) return $list->toArray();
|
||||
else return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置结束时间
|
||||
* @param $idAll
|
||||
* @return $this
|
||||
*/
|
||||
public static function setPinkStopTime($idAll){
|
||||
$model = new self();
|
||||
$model = $model->where('id','IN',$idAll);
|
||||
return $model->update(['stop_time'=>time(),'status'=>2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取正在拼团的数据 团长
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getPinkAll($cid){
|
||||
$model = new self();
|
||||
$model = $model->alias('p');
|
||||
$model = $model->field('p.*,u.nickname,u.avatar');
|
||||
$model = $model->where('stop_time','GT',time());
|
||||
$model = $model->where('cid',$cid);
|
||||
$model = $model->where('k_id',0);
|
||||
$model = $model->where('is_refund',0);
|
||||
$model = $model->order('add_time desc');
|
||||
$model = $model->join('__USER__ u','u.uid = p.uid');
|
||||
$list = $model->select();
|
||||
if($list) return $list->toArray();
|
||||
else return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取还差几人
|
||||
*/
|
||||
public static function getPinkPeople($kid,$people){
|
||||
$model = new self();
|
||||
$model = $model->where('k_id',$kid)->where('is_refund',0);
|
||||
$count = bcadd($model->count(),1,0);
|
||||
return bcsub($people,$count,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断订单是否在当前的拼团中
|
||||
* @param $orderId
|
||||
* @param $kid
|
||||
* @return bool
|
||||
*/
|
||||
public static function getOrderIdAndPink($orderId,$kid){
|
||||
$model = new self();
|
||||
$pink = $model->where('k_id',$kid)->whereOr('id',$kid)->column('order_id');
|
||||
if(in_array($orderId,$pink))return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户是否在团内
|
||||
* @param $id
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getIsPinkUid($id = 0,$uid = 0){
|
||||
$pinkT = self::where('id',$id)->where('uid',$uid)->where('is_refund',0)->count();
|
||||
$pink = self::whereOr('k_id',$id)->where('uid',$uid)->where('is_refund',0)->count();
|
||||
if($pinkT) return true;
|
||||
if($pink) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断是否发送模板消息 0 未发送 1已发送
|
||||
* @param $uidAll
|
||||
* @return int|string
|
||||
*/
|
||||
public static function isTpl($uidAll,$pid){
|
||||
if(is_array($uidAll)){
|
||||
$countK = self::where('uid','IN',implode(',',$uidAll))->where('is_tpl',0)->where('id',$pid)->count();
|
||||
$count = self::where('uid','IN',implode(',',$uidAll))->where('is_tpl',0)->where('k_id',$pid)->count();
|
||||
}
|
||||
else {
|
||||
$countK = self::where('uid',$uidAll)->where('is_tpl',0)->where('id',$pid)->count();
|
||||
$count = self::where('uid',$uidAll)->where('is_tpl',0)->where('k_id',$pid)->count();
|
||||
}
|
||||
return bcadd($countK,$count,0);
|
||||
}
|
||||
/**
|
||||
* 拼团成功提示模板消息
|
||||
* @param $uidAll
|
||||
* @param $pid
|
||||
*/
|
||||
public static function orderPinkAfter($uidAll,$pid){
|
||||
// foreach ($uidAll as $v){
|
||||
// $openid = WechatUser::uidToOpenid($v);
|
||||
// WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_USER_GROUPS_SUCCESS,[
|
||||
// 'first'=>'亲,您的拼团已经完成了',
|
||||
// 'keyword1'=> self::where('id',$pid)->whereOr('k_id',$pid)->where('uid',$v)->value('order_id'),
|
||||
// 'keyword2'=> self::alias('p')->where('p.id',$pid)->whereOr('p.k_id',$pid)->where('p.uid',$v)->join('__STORE_COMBINATION__ c','c.id=p.cid')->value('c.title'),
|
||||
// 'remark'=>'点击查看订单详情'
|
||||
// ],Url::build('My/order_pink_after',['id'=>$pid],true,true));
|
||||
// }
|
||||
self::beginTrans();
|
||||
$res1 = self::where('uid','IN',implode(',',$uidAll))->where('id',$pid)->whereOr('k_id',$pid)->update(['is_tpl'=>1]);
|
||||
$res2 = true;
|
||||
// if(SystemConfigService::get('colonel_status')) $res2 = self::setRakeBackColonel($pid);
|
||||
// else $res2 = true;
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团失败发送的模板消息
|
||||
* @param $uid
|
||||
* @param $pid
|
||||
*/
|
||||
public static function orderPinkAfterNo($uid,$pid){
|
||||
$openid = WechatUser::uidToOpenid($uid);
|
||||
WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_USER_GROUPS_LOSE,[
|
||||
'first'=>'亲,您的拼团失败',
|
||||
'keyword1'=> self::alias('p')->where('p.id',$pid)->whereOr('p.k_id',$pid)->where('p.uid',$uid)->join('__STORE_COMBINATION__ c','c.id=p.cid')->value('c.title'),
|
||||
'keyword2'=> self::where('id',$pid)->whereOr('k_id',$pid)->where('uid',$uid)->value('price'),
|
||||
'keyword3'=> self::alias('p')->where('p.id',$pid)->whereOr('p.k_id',$pid)->where('p.uid',$uid)->join('__STORE_ORDER__ c','c.order_id=p.order_id')->value('c.pay_price'),
|
||||
'remark'=>'点击查看订单详情'
|
||||
],Url::build('My/order_pink_after',['id'=>$pid],true,true));
|
||||
self::where('id',$pid)->update(['status'=>3]);
|
||||
self::where('k_id',$pid)->update(['status'=>3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前拼团数据返回订单编号
|
||||
* @param $id
|
||||
* @return array|false|\PDOStatement|string|\think\Model
|
||||
*/
|
||||
public static function getCurrentPink($id){
|
||||
$uid = User::getActiveUid();//获取当前登录人的uid
|
||||
$pink = self::where('id',$id)->where('uid',$uid)->find();
|
||||
if(!$pink) $pink = self::where('k_id',$id)->where('uid',$uid)->find();
|
||||
return StoreOrder::where('id',$pink['order_id_key'])->value('order_id');
|
||||
}
|
||||
|
||||
public static function systemPage($where){
|
||||
$model = new self;
|
||||
$model = $model->alias('p');
|
||||
$model = $model->field('p.*,c.title');
|
||||
if($where['data'] !== ''){
|
||||
list($startTime,$endTime) = explode(' - ',$where['data']);
|
||||
$model = $model->where('p.add_time','>',strtotime($startTime));
|
||||
$model = $model->where('p.add_time','<',strtotime($endTime));
|
||||
}
|
||||
if($where['status']) $model = $model->where('p.status',$where['status']);
|
||||
$model = $model->where('p.k_id',0);
|
||||
$model = $model->order('p.id desc');
|
||||
$model = $model->join('StoreCombination c','c.id=p.cid');
|
||||
return self::page($model,function($item)use($where){
|
||||
$item['count_people'] = bcadd(self::where('k_id',$item['id'])->count(),1,0);
|
||||
},$where);
|
||||
}
|
||||
|
||||
public static function isPinkBe($data,$id){
|
||||
$data['id'] = $id;
|
||||
$count = self::where($data)->count();
|
||||
if($count) return $count;
|
||||
$data['k_id'] = $id;
|
||||
$count = self::where($data)->count();
|
||||
if($count) return $count;
|
||||
else return 0;
|
||||
}
|
||||
public static function isPinkStatus($pinkId){
|
||||
if(!$pinkId) return false;
|
||||
$stopTime = self::where('id',$pinkId)->value('stop_time');
|
||||
if($stopTime < time()) return true; //拼团结束
|
||||
else return false;//拼团未结束
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断拼团结束 后的状态
|
||||
* @param $pinkId
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSetPinkOver($pinkId){
|
||||
$people = self::where('id',$pinkId)->value('people');
|
||||
$stopTime = self::where('id',$pinkId)->value('stop_time');
|
||||
if($stopTime < time()){
|
||||
$countNum = self::getPinkPeople($pinkId,$people);
|
||||
if($countNum) return false;//拼团失败
|
||||
else return true;//拼团成功
|
||||
}else return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团退款
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function setRefundPink($oid){
|
||||
$res = true;
|
||||
$order = StoreOrder::where('id',$oid)->find();
|
||||
if($order['pink_id']) $id = $order['pink_id'];
|
||||
else return $res;
|
||||
$count = self::where('id',$id)->where('uid',$order['uid'])->find();//正在拼团 团长
|
||||
$countY = self::where('k_id',$id)->where('uid',$order['uid'])->find();//正在拼团 团员
|
||||
if(!$count && !$countY) return $res;
|
||||
if($count){//团长
|
||||
//判断团内是否还有其他人 如果有 团长为第二个进团的人
|
||||
$kCount = self::where('k_id',$id)->order('add_time asc')->find();
|
||||
if($kCount){
|
||||
$res11 = self::where('k_id',$id)->update(['k_id'=>$kCount['id']]);
|
||||
$res12 = self::where('id',$kCount['id'])->update(['stop_time'=>$count['add_time']+86400,'k_id'=>0]);
|
||||
$res1 = $res11 && $res12;
|
||||
$res2 = self::where('id',$id)->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$kCount['id'],'status'=>3]);
|
||||
}else{
|
||||
$res1 = true;
|
||||
$res2 = self::where('id',$id)->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$id,'status'=>3]);
|
||||
}
|
||||
//修改结束时间为前一秒 团长ID为0
|
||||
$res = $res1 && $res2;
|
||||
}else if($countY){//团员
|
||||
$res = self::where('id',$countY['id'])->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$id,'status'=>3]);
|
||||
}
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 拼团人数完成时,判断全部人都是未退款状态
|
||||
* @param $pinkIds
|
||||
* @return bool
|
||||
*/
|
||||
public static function setPinkStatus($pinkIds){
|
||||
$orderPink = self::where('id','IN',$pinkIds)->where('is_refund',1)->count();
|
||||
if(!$orderPink) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建拼团
|
||||
* @param $order
|
||||
* @return mixed
|
||||
*/
|
||||
public static function createPink($order){
|
||||
$order = StoreOrder::tidyOrder($order,true)->toArray();
|
||||
if($order['pink_id']){//拼团存在
|
||||
$res = false;
|
||||
$pink['uid'] = $order['uid'];//用户id
|
||||
if(self::isPinkBe($pink,$order['pink_id'])) return false;
|
||||
$pink['order_id'] = $order['order_id'];//订单id 生成
|
||||
$pink['order_id_key'] = $order['id'];//订单id 数据库id
|
||||
$pink['total_num'] = $order['total_num'];//购买个数
|
||||
$pink['total_price'] = $order['pay_price'];//总金额
|
||||
$pink['k_id'] = $order['pink_id'];//拼团id
|
||||
foreach ($order['cartInfo'] as $v){
|
||||
$pink['cid'] = $v['combination_id'];//拼团产品id
|
||||
$pink['pid'] = $v['product_id'];//产品id
|
||||
$pink['people'] = StoreCombination::where('id',$v['combination_id'])->value('people');//几人拼团
|
||||
$pink['price'] = $v['productInfo']['price'];//单价
|
||||
$pink['stop_time'] = 0;//结束时间
|
||||
$pink['add_time'] = time();//开团时间
|
||||
$res = StorePink::set($pink)->toArray();
|
||||
}
|
||||
if($res) return true;
|
||||
else return false;
|
||||
}else{
|
||||
$res = false;
|
||||
$pink['uid'] = $order['uid'];//用户id
|
||||
$pink['order_id'] = $order['order_id'];//订单id 生成
|
||||
$pink['order_id_key'] = $order['id'];//订单id 数据库id
|
||||
$pink['total_num'] = $order['total_num'];//购买个数
|
||||
$pink['total_price'] = $order['pay_price'];//总金额
|
||||
$pink['k_id'] = 0;//拼团id
|
||||
foreach ($order['cartInfo'] as $v){
|
||||
$pink['cid'] = $v['combination_id'];//拼团产品id
|
||||
$pink['pid'] = $v['product_id'];//产品id
|
||||
$pink['people'] = StoreCombination::where('id',$v['combination_id'])->value('people');//几人拼团
|
||||
$pink['price'] = $v['productInfo']['price'];//单价
|
||||
// $stopTime = StoreCombination::where('id',$v['combination_id'])->value('stop_time');//获取拼团产品结束的时间
|
||||
// if($stopTime < time()+86400) $pink['stop_time'] = $stopTime;//结束时间
|
||||
$pink['stop_time'] = time()+86400;//结束时间
|
||||
$pink['add_time'] = time();//开团时间
|
||||
$res1 = self::set($pink)->toArray();
|
||||
$res2 = StoreOrder::where('id',$order['id'])->update(['pink_id'=>$res1['id']]);
|
||||
$res = $res1 && $res2;
|
||||
}
|
||||
if($res) return true;
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团成功后给团长返佣金
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
// public static function setRakeBackColonel($id = 0){
|
||||
// if(!$id) return false;
|
||||
// $pinkRakeBack = self::where('id',$id)->field('people,price,uid,id')->find()->toArray();
|
||||
// $countPrice = bcmul($pinkRakeBack['people'],$pinkRakeBack['price'],2);
|
||||
// if(bcsub((float)$countPrice,0,2) <= 0) return true;
|
||||
// $rakeBack = (SystemConfigService::get('rake_back_colonel') ?: 0)/100;
|
||||
// if($rakeBack <= 0) return true;
|
||||
// $rakeBackPrice = bcmul($countPrice,$rakeBack,2);
|
||||
// if($rakeBackPrice <= 0) return true;
|
||||
// $mark = '拼团成功,奖励佣金'.floatval($rakeBackPrice);
|
||||
// self::beginTrans();
|
||||
// $res1 = UserBill::income('获得拼团佣金',$pinkRakeBack['uid'],'now_money','colonel',$rakeBackPrice,$id,0,$mark);
|
||||
// $res2 = User::bcInc($pinkRakeBack['uid'],'now_money',$rakeBackPrice,'uid');
|
||||
// $res = $res1 && $res2;
|
||||
// self::checkTrans($res);
|
||||
// return $res;
|
||||
// }
|
||||
}
|
||||
@ -1,148 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/12
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use app\admin\model\store\StoreProductAttrValue as StoreProductAttrValuemodel;
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreProduct extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected function getSliderImageAttr($value)
|
||||
{
|
||||
return json_decode($value,true)?:[];
|
||||
}
|
||||
|
||||
public static function getValidProduct($productId,$field = '*')
|
||||
{
|
||||
return self::where('is_del',0)->where('is_show',1)->where('id',$productId)->field($field)->find();
|
||||
}
|
||||
|
||||
public static function validWhere()
|
||||
{
|
||||
return self::where('is_del',0)->where('is_show',1)->where('mer_id',0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新品产品
|
||||
* @param string $field
|
||||
* @param int $limit
|
||||
* @return false|\PDOStatement|string|\think\Collection
|
||||
*/
|
||||
public static function getNewProduct($field = '*',$limit = 0)
|
||||
{
|
||||
$model = self::where('is_new',1)->where('is_del',0)->where('mer_id',0)
|
||||
->where('stock','>',0)->where('is_show',1)->field($field)
|
||||
->order('sort DESC, id DESC');
|
||||
if($limit) $model->limit($limit);
|
||||
return $model->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 热卖产品
|
||||
* @param string $field
|
||||
* @param int $limit
|
||||
* @return false|\PDOStatement|string|\think\Collection
|
||||
*/
|
||||
public static function getHotProduct($field = '*',$limit = 0)
|
||||
{
|
||||
$model = self::where('is_hot',1)->where('is_del',0)->where('mer_id',0)
|
||||
->where('stock','>',0)->where('is_show',1)->field($field)
|
||||
->order('sort DESC, id DESC');
|
||||
if($limit) $model->limit($limit);
|
||||
return $model->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 热卖产品
|
||||
* @param string $field
|
||||
* @param int $limit
|
||||
* @return false|\PDOStatement|string|\think\Collection
|
||||
*/
|
||||
public static function getHotProductLoading($field = '*',$offset = 0,$limit = 0)
|
||||
{
|
||||
$model = self::where('is_hot',1)->where('is_del',0)->where('mer_id',0)
|
||||
->where('stock','>',0)->where('is_show',1)->field($field)
|
||||
->order('sort DESC, id DESC');
|
||||
if($limit) $model->limit($offset,$limit);
|
||||
return $model->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 精品产品
|
||||
* @param string $field
|
||||
* @param int $limit
|
||||
* @return false|\PDOStatement|string|\think\Collection
|
||||
*/
|
||||
public static function getBestProduct($field = '*',$limit = 0)
|
||||
{
|
||||
$model = self::where('is_best',1)->where('is_del',0)->where('mer_id',0)
|
||||
->where('stock','>',0)->where('is_show',1)->field($field)
|
||||
->order('sort DESC, id DESC');
|
||||
if($limit) $model->limit($limit);
|
||||
return $model->select();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 优惠产品
|
||||
* @param string $field
|
||||
* @param int $limit
|
||||
* @return false|\PDOStatement|string|\think\Collection
|
||||
*/
|
||||
public static function getBenefitProduct($field = '*',$limit = 0)
|
||||
{
|
||||
$model = self::where('is_benefit',1)
|
||||
->where('is_del',0)->where('mer_id',0)->where('stock','>',0)
|
||||
->where('is_show',1)->field($field)
|
||||
->order('sort DESC, id DESC');
|
||||
if($limit) $model->limit($limit);
|
||||
return $model->select();
|
||||
}
|
||||
|
||||
public static function cateIdBySimilarityProduct($cateId,$field='*',$limit = 0)
|
||||
{
|
||||
$pid = StoreCategory::cateIdByPid($cateId)?:$cateId;
|
||||
$cateList = StoreCategory::pidByCategory($pid,'id') ?:[];
|
||||
$cid = [$pid];
|
||||
foreach ($cateList as $cate){
|
||||
$cid[] = $cate['id'];
|
||||
}
|
||||
$model = self::where('cate_id','IN',$cid)->where('is_show',1)->where('is_del',0)
|
||||
->field($field)->order('sort DESC,id DESC');
|
||||
if($limit) $model->limit($limit);
|
||||
return $model->select();
|
||||
}
|
||||
|
||||
public static function isValidProduct($productId)
|
||||
{
|
||||
return self::be(['id'=>$productId,'is_del'=>0,'is_show'=>1]) > 0;
|
||||
}
|
||||
|
||||
public static function getProductStock($productId,$uniqueId = '')
|
||||
{
|
||||
return $uniqueId == '' ?
|
||||
self::where('id',$productId)->value('stock')?:0
|
||||
: StoreProductAttr::uniqueByStock($uniqueId);
|
||||
}
|
||||
|
||||
public static function decProductStock($num,$productId,$unique = '')
|
||||
{
|
||||
if($unique){
|
||||
$res = false !== StoreProductAttrValuemodel::decProductAttrStock($productId,$unique,$num);
|
||||
$res = $res && self::where('id',$productId)->setInc('sales',$num);
|
||||
}else{
|
||||
$res = false !== self::where('id',$productId)->dec('stock',$num)->inc('sales',$num)->update();
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/13
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use think\Db;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreProductAttr extends ModelBasic
|
||||
{
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
protected function getAttrValuesAttr($value)
|
||||
{
|
||||
return explode(',',$value);
|
||||
}
|
||||
|
||||
public static function storeProductAttrValueDb()
|
||||
{
|
||||
return Db::name('StoreProductAttrValue');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取商品属性数据
|
||||
* @param $productId
|
||||
* @return array
|
||||
*/
|
||||
public static function getProductAttrDetail($productId)
|
||||
{
|
||||
$attr = self::where('product_id',$productId)->select()->toArray()?:[];
|
||||
$_values = self::storeProductAttrValueDb()->where('product_id',$productId)->select();
|
||||
$values = [];
|
||||
foreach ($_values as $value){
|
||||
$values[$value['suk']] = $value;
|
||||
}
|
||||
return [$attr,$values];
|
||||
}
|
||||
|
||||
public static function uniqueByStock($unique)
|
||||
{
|
||||
return self::storeProductAttrValueDb()->where('unique',$unique)->value('stock')?:0;
|
||||
}
|
||||
|
||||
public static function uniqueByAttrInfo($unique, $field = '*')
|
||||
{
|
||||
return self::storeProductAttrValueDb()->field($field)->where('unique',$unique)->find();
|
||||
}
|
||||
|
||||
public static function issetProductUnique($productId,$unique)
|
||||
{
|
||||
$res = self::be(['product_id'=>$productId]);
|
||||
if($unique){
|
||||
return $res && self::storeProductAttrValueDb()->where('product_id',$productId)->where('unique',$unique)->count() > 0;
|
||||
}else{
|
||||
return !$res;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,118 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
use behavior\wap\StoreProductBehavior;
|
||||
use service\HookService;
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 点赞收藏model
|
||||
* Class StoreProductRelation
|
||||
* @package app\routine\model\store
|
||||
*/
|
||||
class StoreProductRelation extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 获取用户点赞所有产品的个数
|
||||
* @param $uid
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getUserIdLike($uid = 0){
|
||||
$count = self::where('uid',$uid)->where('type','like')->count();
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户收藏所有产品的个数
|
||||
* @param $uid
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getUserIdCollect($uid = 0){
|
||||
$count = self::where('uid',$uid)->where('type','collect')->count();
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加点赞 收藏
|
||||
* @param $productId
|
||||
* @param $uid
|
||||
* @param $relationType
|
||||
* @param string $category
|
||||
* @return bool
|
||||
*/
|
||||
public static function productRelation($productId,$uid,$relationType,$category = 'product')
|
||||
{
|
||||
if(!$productId) return self::setErrorInfo('产品不存在!');
|
||||
$relationType = strtolower($relationType);
|
||||
$category = strtolower($category);
|
||||
$data = ['uid'=>$uid,'product_id'=>$productId,'type'=>$relationType,'category'=>$category];
|
||||
if(self::be($data)) return true;
|
||||
$data['add_time'] = time();
|
||||
self::set($data);
|
||||
HookService::afterListen('store_'.$category.'_'.$relationType,$productId,$uid,false,StoreProductBehavior::class);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量 添加点赞 收藏
|
||||
* @param $productIdS
|
||||
* @param $uid
|
||||
* @param $relationType
|
||||
* @param string $category
|
||||
* @return bool
|
||||
*/
|
||||
public static function productRelationAll($productIdS,$uid,$relationType,$category = 'product'){
|
||||
$res = true;
|
||||
if(is_array($productIdS)){
|
||||
self::beginTrans();
|
||||
foreach ($productIdS as $productId){
|
||||
$res = $res && self::productRelation($productId,$uid,$relationType,$category);
|
||||
}
|
||||
self::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消 点赞 收藏
|
||||
* @param $productId
|
||||
* @param $uid
|
||||
* @param $relationType
|
||||
* @param string $category
|
||||
* @return bool
|
||||
*/
|
||||
public static function unProductRelation($productId,$uid,$relationType,$category = 'product')
|
||||
{
|
||||
if(!$productId) return self::setErrorInfo('产品不存在!');
|
||||
$relationType = strtolower($relationType);
|
||||
$category = strtolower($category);
|
||||
self::where(['uid'=>$uid,'product_id'=>$productId,'type'=>$relationType,'category'=>$category])->delete();
|
||||
HookService::afterListen('store_'.$category.'_un_'.$relationType,$productId,$uid,false,StoreProductBehavior::class);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function productRelationNum($productId,$relationType,$category = 'product')
|
||||
{
|
||||
$relationType = strtolower($relationType);
|
||||
$category = strtolower($category);
|
||||
return self::where('type',$relationType)->where('product_id',$productId)->where('category',$category)->count();
|
||||
}
|
||||
|
||||
public static function isProductRelation($product_id,$uid,$relationType,$category = 'product')
|
||||
{
|
||||
$type = strtolower($relationType);
|
||||
$category = strtolower($category);
|
||||
return self::be(compact('product_id','uid','type','category'));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,98 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/29
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use service\UtilService;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreProductReply extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['add_time'];
|
||||
|
||||
protected function setAddTimeAttr()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
protected function setPicsAttr($value)
|
||||
{
|
||||
return is_array($value) ? json_encode($value) : $value;
|
||||
}
|
||||
|
||||
protected function getPicsAttr($value)
|
||||
{
|
||||
return json_decode($value,true);
|
||||
}
|
||||
|
||||
public static function reply($group,$type = 'product')
|
||||
{
|
||||
$group['reply_type'] = $type;
|
||||
return self::set($group);
|
||||
}
|
||||
|
||||
public static function productValidWhere($alias = '')
|
||||
{
|
||||
$model = new self;
|
||||
if($alias){
|
||||
$model->alias($alias);
|
||||
$alias .= '.';
|
||||
}
|
||||
return $model->where("{$alias}is_del",0)->where("{$alias}reply_type",'product');
|
||||
}
|
||||
|
||||
public static function getProductReplyList($productId,$order = 'All',$first = 0,$limit = 8)
|
||||
{
|
||||
$model = self::productValidWhere('A')->where('A.product_id',$productId)
|
||||
->field('A.product_score,A.service_score,A.comment,A.merchant_reply_content,A.merchant_reply_time,A.pics,A.add_time,B.nickname,B.avatar,C.cart_info,A.merchant_reply_content')
|
||||
->join('__USER__ B','A.uid = B.uid')
|
||||
->join('__STORE_ORDER_CART_INFO__ C','A.unique = C.unique');
|
||||
$baseOrder = 'A.add_time DESC,A.product_score DESC, A.service_score DESC';
|
||||
if($order == 'new') $model->order($baseOrder);
|
||||
else if($order == 'pic') $model->where('A.pics',['<>',''],['<>','[]'])->order('A.add_time DESC,'.$baseOrder);
|
||||
else $model->order('A.add_time DESC,'.$baseOrder);
|
||||
$list = $model->limit($first,$limit)->select()->toArray()?:[];
|
||||
foreach ($list as $k=>$reply){
|
||||
$list[$k] = self::tidyProductReply($reply);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function tidyProductReply($res)
|
||||
{
|
||||
$res['cart_info'] = json_decode($res['cart_info'],true)?:[];
|
||||
$res['suk'] = isset($res['cart_info']['productInfo']['attrInfo']) ? $res['cart_info']['productInfo']['attrInfo']['suk'] : '';
|
||||
$res['nickname'] = UtilService::anonymity($res['nickname']);
|
||||
$res['merchant_reply_time'] = date('Y-m-d H:i',$res['merchant_reply_time']);
|
||||
$res['add_time'] = date('Y-m-d H:i',$res['add_time']);
|
||||
$res['star'] = ceil(($res['product_score'] + $res['service_score'])/2);
|
||||
$res['comment'] = $res['comment']?:'此用户没有填写评价';
|
||||
unset($res['cart_info']);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function isReply($unique,$reply_type = 'product')
|
||||
{
|
||||
return self::be(['unique'=>$unique,'reply_type'=>$reply_type]);
|
||||
}
|
||||
|
||||
public static function getRecProductReply($productId)
|
||||
{
|
||||
$res = self::productValidWhere('A')->where('A.product_id',$productId)
|
||||
->field('A.product_score,A.service_score,A.comment,A.merchant_reply_content,A.merchant_reply_time,A.pics,A.add_time,B.nickname,B.avatar,C.cart_info')
|
||||
->join('__USER__ B','A.uid = B.uid')
|
||||
->join('__STORE_ORDER_CART_INFO__ C','A.unique = C.unique')
|
||||
->order('A.add_time DESC,A.product_score DESC, A.service_score DESC, A.add_time DESC')->find();
|
||||
if(!$res) return null;
|
||||
return self::tidyProductReply($res->toArray());
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,109 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/18
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
|
||||
class StoreSeckill extends ModelBasic
|
||||
{
|
||||
|
||||
protected function getImagesAttr($value)
|
||||
{
|
||||
return json_decode($value,true)?:[];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有秒杀产品
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public static function getListAll($offset = 0,$limit = 10,$field = 'id,product_id,image,title,price,ot_price,start_time,stop_time,stock,sales'){
|
||||
$time = time();
|
||||
$model = self::where('is_del',0)->where('status',1)->where('stock','>',0)->field($field)
|
||||
->where('start_time','<',$time)->where('stop_time','>',$time)->order('sort DESC,add_time DESC');
|
||||
$model = $model->limit($offset,$limit);
|
||||
$list = $model->select();
|
||||
if($list) return $list->toArray();
|
||||
else return [];
|
||||
}
|
||||
/**
|
||||
* 获取热门推荐的秒杀产品
|
||||
* @param int $limit
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public static function getHotList($limit = 0,$field = 'id,product_id,image,title,price,ot_price,start_time,stop_time,stock')
|
||||
{
|
||||
$time = time();
|
||||
$model = self::where('is_hot',1)->where('is_del',0)->where('status',1)->where('stock','>',0)->field($field)
|
||||
->where('start_time','<',$time)->where('stop_time','>',$time)->order('sort DESC,add_time DESC');
|
||||
if($limit) $model->limit($limit);
|
||||
$list = $model->select();
|
||||
if($list) return $list->toArray();
|
||||
else return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一条秒杀产品
|
||||
* @param $id
|
||||
* @param string $field
|
||||
* @return array|false|\PDOStatement|string|\think\Model
|
||||
*/
|
||||
public static function getValidProduct($id,$field = '*')
|
||||
{
|
||||
$time = time();
|
||||
return self::where('id',$id)->where('is_del',0)->where('status',1)->where('start_time','<',$time)->where('stop_time','>',$time)
|
||||
->field($field)->find();
|
||||
}
|
||||
|
||||
public static function initFailSeckill()
|
||||
{
|
||||
self::where('is_hot',1)->where('is_del',0)->where('status','<>',1)->where('stop_time','<',time())->update(['status'=>'-1']);
|
||||
}
|
||||
|
||||
public static function idBySimilaritySeckill($id,$limit = 4,$field='*')
|
||||
{
|
||||
$time = time();
|
||||
$list = [];
|
||||
$productId = self::where('id',$id)->value('product_id');
|
||||
if($productId){
|
||||
$list = array_merge($list, self::where('product_id',$productId)->where('id','<>',$id)
|
||||
->where('is_del',0)->where('status',1)->where('stock','>',0)
|
||||
->field($field)->where('start_time','<',$time)->where('stop_time','>',$time)
|
||||
->order('sort DESC,add_time DESC')->limit($limit)->select()->toArray());
|
||||
}
|
||||
$limit = $limit - count($list);
|
||||
if($limit){
|
||||
$list = array_merge($list,self::getHotList($limit,$field));
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function getProductStock($id){
|
||||
$stock = self::where('id',$id)->value('stock');
|
||||
if(self::where('id',$id)->where('num','gt',$stock)->count()){//单次购买的产品多于库存
|
||||
return $stock;
|
||||
}else{
|
||||
return self::where('id',$id)->value('num');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改秒杀库存
|
||||
* @param int $num
|
||||
* @param int $seckillId
|
||||
* @return bool
|
||||
*/
|
||||
public static function decSeckillStock($num = 0,$seckillId = 0){
|
||||
$res = false !== self::where('id',$seckillId)->dec('stock',$num)->inc('sales',$num)->update();
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/23
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreService extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/23
|
||||
*/
|
||||
|
||||
namespace app\routine\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreServiceLog extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
}
|
||||
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/21
|
||||
*/
|
||||
|
||||
namespace app\routine\model\user;
|
||||
|
||||
use app\routine\model\routine\RoutineQrcode;
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
use app\routine\model\user\User;
|
||||
use app\routine\model\user\WechatUser;
|
||||
class RoutineUser extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 小程序创建用户后返回uid
|
||||
* @param $routineInfo
|
||||
* @return mixed
|
||||
*/
|
||||
public static function routineOauth($routine){
|
||||
$routineInfo['nickname'] = $routine['nickName'];//姓名
|
||||
$routineInfo['sex'] = $routine['gender'];//性别
|
||||
$routineInfo['language'] = $routine['language'];//语言
|
||||
$routineInfo['city'] = $routine['city'];//城市
|
||||
$routineInfo['province'] = $routine['province'];//省份
|
||||
$routineInfo['country'] = $routine['country'];//国家
|
||||
$routineInfo['headimgurl'] = $routine['avatarUrl'];//头像
|
||||
// $routineInfo[''] = $routine['code'];//临时登录凭证 是获取用户openid和session_key(会话密匙)
|
||||
$routineInfo['routine_openid'] = $routine['routine_openid'];//openid
|
||||
$routineInfo['session_key'] = $routine['session_key'];//会话密匙
|
||||
$routineInfo['unionid'] = $routine['unionid'];//用户在开放平台的唯一标识符
|
||||
$routineInfo['user_type'] = 'routine';//用户类型
|
||||
$page = '';//跳转小程序的页面
|
||||
$spid = 0;//绑定关系uid
|
||||
//获取是否有扫码进小程序
|
||||
if($routine['spid']){
|
||||
$info = RoutineQrcode::getRoutineQrcodeFindType($routine['spid']);
|
||||
if($info){
|
||||
$spid = $info['third_id'];
|
||||
$page = $info['page'];
|
||||
}
|
||||
}
|
||||
// 判断unionid 存在根据unionid判断
|
||||
if($routineInfo['unionid'] != '' && WechatUser::be(['unionid'=>$routineInfo['unionid']])){
|
||||
WechatUser::edit($routineInfo,$routineInfo['unionid'],'unionid');
|
||||
$uid = WechatUser::where('unionid',$routineInfo['unionid'])->value('uid');
|
||||
User::updateWechatUser($routineInfo,$uid);
|
||||
}else if(WechatUser::be(['routine_openid'=>$routineInfo['routine_openid']])){ //根据小程序openid判断
|
||||
WechatUser::edit($routineInfo,$routineInfo['routine_openid'],'routine_openid');
|
||||
$uid = WechatUser::where('routine_openid',$routineInfo['routine_openid'])->value('uid');
|
||||
User::updateWechatUser($routineInfo,$uid);
|
||||
}else{
|
||||
$routineInfo['add_time'] = time();//用户添加时间
|
||||
$routineInfo = WechatUser::set($routineInfo);
|
||||
if(User::isUserSpread($spid)) {
|
||||
$res = User::setRoutineUser($routineInfo,$spid); //用户上级
|
||||
}else $res = User::setRoutineUser($routineInfo);
|
||||
$uid = $res->uid;
|
||||
}
|
||||
$data['page'] = $page;
|
||||
$data['uid'] = $uid;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是小程序用户
|
||||
* @param int $uid
|
||||
* @return bool|int|string
|
||||
*/
|
||||
public static function isRoutineUser($uid = 0){
|
||||
if(!$uid) return false;
|
||||
return WechatUser::where('uid',$uid)->where('user_type','routine')->count();
|
||||
}
|
||||
|
||||
public static function isUserStatus($uid = 0){
|
||||
if(!$uid) return 0;
|
||||
$user = User::getUserInfo($uid);
|
||||
return $user['status'];
|
||||
}
|
||||
}
|
||||
@ -1,148 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/21
|
||||
*/
|
||||
|
||||
namespace app\routine\model\user;
|
||||
|
||||
use basic\ModelBasic;
|
||||
use service\SystemConfigService;
|
||||
use think\Request;
|
||||
use think\Session;
|
||||
use traits\ModelTrait;
|
||||
|
||||
/**
|
||||
* 用户model
|
||||
* Class User
|
||||
* @package app\routine\model\user
|
||||
*/
|
||||
class User extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
public static function updateWechatUser($wechatUser,$uid)
|
||||
{
|
||||
return self::edit([
|
||||
'nickname'=>$wechatUser['nickname']?:'',
|
||||
'avatar'=>$wechatUser['headimgurl']?:'',
|
||||
'last_time'=>time(),
|
||||
'last_ip'=>Request::instance()->ip(),
|
||||
],$uid,'uid');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 小程序用户添加
|
||||
* @param $routineUser
|
||||
* @param int $spread_uid
|
||||
* @return object
|
||||
*/
|
||||
public static function setRoutineUser($routineUser,$spread_uid = 0){
|
||||
return self::set([
|
||||
'account'=>'rt'.$routineUser['uid'].time(),
|
||||
'pwd'=>md5(123456),
|
||||
'nickname'=>$routineUser['nickname']?:'',
|
||||
'avatar'=>$routineUser['headimgurl']?:'',
|
||||
'spread_uid'=>$spread_uid,
|
||||
'uid'=>$routineUser['uid'],
|
||||
'add_time'=>$routineUser['add_time'],
|
||||
'add_ip'=>Request::instance()->ip(),
|
||||
'last_time'=>time(),
|
||||
'last_ip'=>Request::instance()->ip(),
|
||||
'user_type'=>$routineUser['user_type']
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前登陆用户UID
|
||||
* @return int $uid
|
||||
*/
|
||||
public static function getActiveUid()
|
||||
{
|
||||
$uid = null;
|
||||
$uid = Session::get('LoginUid');
|
||||
if($uid) return $uid;
|
||||
else return 0;
|
||||
}
|
||||
public static function getUserInfo($uid)
|
||||
{
|
||||
$userInfo = self::where('uid',$uid)->find();
|
||||
if(!$userInfo) exception('读取用户信息失败!');
|
||||
return $userInfo->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前用户是否推广员
|
||||
* @param int $uid
|
||||
* @return bool
|
||||
*/
|
||||
public static function isUserSpread($uid = 0){
|
||||
if(!$uid) return false;
|
||||
$status = (int)SystemConfigService::get('store_brokerage_statu');
|
||||
$isPromoter = true;
|
||||
if($status == 1) $isPromoter = self::where('uid',$uid)->value('is_promoter');
|
||||
if($isPromoter) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序用户一级分销
|
||||
* @param $orderInfo
|
||||
* @return bool
|
||||
*/
|
||||
public static function backOrderBrokerage($orderInfo)
|
||||
{
|
||||
$userInfo = User::getUserInfo($orderInfo['uid']);
|
||||
if(!$userInfo || !$userInfo['spread_uid']) return true;
|
||||
$storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ? : 1;//获取后台分销类型
|
||||
if($storeBrokerageStatu == 1){
|
||||
if(!User::be(['uid'=>$userInfo['spread_uid'],'is_promoter'=>1])) return true;
|
||||
}
|
||||
$brokerageRatio = (SystemConfigService::get('store_brokerage_ratio') ?: 0)/100;
|
||||
if($brokerageRatio <= 0) return true;
|
||||
$cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
|
||||
if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
|
||||
$brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
|
||||
if($brokeragePrice <= 0) return true;
|
||||
$mark = $userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
|
||||
self::beginTrans();
|
||||
$res1 = UserBill::income('获得推广佣金',$userInfo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],0,$mark);
|
||||
$res2 = self::bcInc($userInfo['spread_uid'],'now_money',$brokeragePrice,'uid');
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
if($res) self::backOrderBrokerageTwo($orderInfo);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序 二级推广
|
||||
* @param $orderInfo
|
||||
* @return bool
|
||||
*/
|
||||
public static function backOrderBrokerageTwo($orderInfo){
|
||||
$userInfo = User::getUserInfo($orderInfo['uid']);
|
||||
$userInfoTwo = User::getUserInfo($userInfo['spread_uid']);
|
||||
if(!$userInfoTwo || !$userInfoTwo['spread_uid']) return true;
|
||||
$storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ? : 1;//获取后台分销类型
|
||||
if($storeBrokerageStatu == 1){
|
||||
if(!User::be(['uid'=>$userInfoTwo['spread_uid'],'is_promoter'=>1])) return true;
|
||||
}
|
||||
$brokerageRatio = (SystemConfigService::get('store_brokerage_ratio_two') ?: 0)/100;
|
||||
if($brokerageRatio <= 0) return true;
|
||||
$cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
|
||||
if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
|
||||
$brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
|
||||
if($brokeragePrice <= 0) return true;
|
||||
$mark = '二级推广人'.$userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
|
||||
self::beginTrans();
|
||||
$res1 = UserBill::income('获得推广佣金',$userInfoTwo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],0,$mark);
|
||||
$res2 = self::bcInc($userInfoTwo['spread_uid'],'now_money',$brokeragePrice,'uid');
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/25
|
||||
*/
|
||||
|
||||
namespace app\routine\model\user;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class UserAddress extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['add_time'];
|
||||
|
||||
protected function setAddTimeAttr()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
public static function setDefaultAddress($id,$uid)
|
||||
{
|
||||
self::beginTrans();
|
||||
$res1 = self::where('uid',$uid)->update(['is_default'=>0]);
|
||||
$res2 = self::where('id',$id)->where('uid',$uid)->update(['is_default'=>1]);
|
||||
$res =$res1 !== false && $res2 !== false;
|
||||
self::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function userValidAddressWhere($model=null,$prefix = '')
|
||||
{
|
||||
if($prefix) $prefix .='.';
|
||||
$model = self::getSelfModel($model);
|
||||
return $model->where("{$prefix}is_del",0);
|
||||
}
|
||||
|
||||
public static function getUserValidAddressList($uid,$field = '*')
|
||||
{
|
||||
return self::userValidAddressWhere()->where('uid',$uid)->order('add_time DESC')->field($field)->select()->toArray()?:[];
|
||||
}
|
||||
|
||||
public static function getUserDefaultAddress($uid,$field = '*')
|
||||
{
|
||||
return self::userValidAddressWhere()->where('uid',$uid)->where('is_default',1)->field($field)->find();
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/30
|
||||
*/
|
||||
|
||||
namespace app\routine\model\user;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class UserBill extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['add_time'];
|
||||
|
||||
protected function setAddTimeAttr()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
public static function income($title,$uid,$category,$type,$number,$link_id = 0,$balance = 0,$mark = '',$status = 1)
|
||||
{
|
||||
$pm = 1;
|
||||
return self::set(compact('title','uid','link_id','category','type','number','balance','mark','status','pm'));
|
||||
}
|
||||
|
||||
public static function expend($title,$uid,$category,$type,$number,$link_id = 0,$balance = 0,$mark = '',$status = 1)
|
||||
{
|
||||
$pm = 0;
|
||||
return self::set(compact('title','uid','link_id','category','type','number','balance','mark','status','pm'));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,118 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2018/3/3
|
||||
*/
|
||||
|
||||
namespace app\routine\model\user;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use service\SystemConfigService;
|
||||
use service\WechatTemplateService;
|
||||
use think\Url;
|
||||
use traits\ModelTrait;
|
||||
use app\routine\model\user\WechatUser;
|
||||
class UserExtract extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
//审核中
|
||||
const AUDIT_STATUS = 0;
|
||||
//未通过
|
||||
const FAIL_STATUS = -1;
|
||||
//已提现
|
||||
const SUCCESS_STATUS = 1;
|
||||
|
||||
protected static $extractType = ['alipay','bank','weixin'];
|
||||
|
||||
protected static $extractTypeMsg = ['alipay'=>'支付宝','bank'=>'银行卡','weixin'=>'微信'];
|
||||
|
||||
protected static $status = array(
|
||||
-1=>'未通过',
|
||||
0 =>'审核中',
|
||||
1 =>'已提现'
|
||||
);
|
||||
|
||||
public static function userExtract($userInfo,$data){
|
||||
if(!in_array($data['extract_type'],self::$extractType))
|
||||
return self::setErrorInfo('提现方式不存在');
|
||||
$userInfo = User::get($userInfo['uid']);
|
||||
if($data['money'] > $userInfo['now_money']) return self::setErrorInfo('余额不足');;
|
||||
$balance = bcsub($userInfo['now_money'],$data['money'],2);
|
||||
$insertData = [
|
||||
'uid'=>$userInfo['uid'],
|
||||
'extract_type'=>$data['extract_type'],
|
||||
'extract_price'=>(int)$data['money'],
|
||||
'add_time'=>time(),
|
||||
'balance'=>$balance,
|
||||
'status'=>self::AUDIT_STATUS
|
||||
];
|
||||
if(isset($data['$name'])){
|
||||
$insertData['real_name']=$data['$name'];
|
||||
}else{
|
||||
$insertData['real_name']='';
|
||||
}
|
||||
if(isset($data['cardnum'])){
|
||||
$insertData['bank_code']=$data['cardnum'];
|
||||
}else{
|
||||
$insertData['bank_code']='';
|
||||
}
|
||||
if(isset($data['bankname'])){
|
||||
$insertData['bank_address']=$data['bankname'];
|
||||
}else{
|
||||
$insertData['bank_address']='';
|
||||
}
|
||||
if(isset($data['weixin'])){
|
||||
$insertData['wechat']=$data['weixin'];
|
||||
}else{
|
||||
$insertData['wechat']='';
|
||||
}
|
||||
if($data['extract_type'] == 'alipay'){
|
||||
if(!$data['alipay_code']) return self::setErrorInfo('请输入支付宝账号');
|
||||
$insertData['alipay_code'] = $data['alipay_code'];
|
||||
$mark = '使用支付宝提现'.$insertData['extract_price'].'元';
|
||||
}elseif($data['extract_type'] == 'bank'){
|
||||
if(!$data['cardnum']) return self::setErrorInfo('请输入银行卡账号');
|
||||
if(!$data['bankname']) return self::setErrorInfo('请输入开户行信息');
|
||||
$mark = '使用银联卡'.$insertData['bank_code'].'提现'.$insertData['extract_price'].'元';
|
||||
}else{
|
||||
if(!$data['weixin']) return self::setErrorInfo('请输入微信号');
|
||||
$mark = '使用微信提现'.$insertData['extract_price'].'元';
|
||||
}
|
||||
self::beginTrans();
|
||||
$res1 = self::set($insertData);
|
||||
if(!$res1) return self::setErrorInfo('提现失败');
|
||||
$res2 = User::edit(['now_money'=>$balance],$userInfo['uid'],'uid');
|
||||
$res3 = UserBill::expend('余额提现',$userInfo['uid'],'now_money','extract',$data['money'],$res1['id'],$balance,$mark);
|
||||
$res = $res2 && $res3;
|
||||
self::checkTrans($res);
|
||||
if($res){
|
||||
//发送模板消息
|
||||
return true;
|
||||
}
|
||||
else return self::setErrorInfo('提现失败!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得用户最后一次提现信息
|
||||
* @param $openid
|
||||
* @return mixed
|
||||
*/
|
||||
public static function userLastInfo($uid)
|
||||
{
|
||||
return self::where(compact('uid'))->order('add_time DESC')->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得用户提现总金额
|
||||
* @param $uid
|
||||
* @return mixed
|
||||
*/
|
||||
public static function userExtractTotalPrice($uid)
|
||||
{
|
||||
return self::where('uid',$uid)->where('status',self::SUCCESS_STATUS)->value('SUM(extract_price)')?:0;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\routine\model\user;
|
||||
|
||||
use app\admin\model\user\UserNoticeSee;
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 用户通知 model
|
||||
* Class UserNotice
|
||||
* @package app\admin\model\user
|
||||
*/
|
||||
class UserNotice extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
public static function getNotice($uid){
|
||||
$count_notice = self::where('uid','like',"%,$uid,%")->where("is_send",1)->count();
|
||||
$see_notice = UserNoticeSee::where("uid",$uid)->count();
|
||||
return $count_notice-$see_notice;
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getNoticeList($uid,$page,$limit = 8){
|
||||
//定义分页信息
|
||||
$count = self::where('uid','like',"%,$uid,%")->count();
|
||||
$data["lastpage"] = ceil($count/$limit) <= ($page+1) ? 1 : 0;
|
||||
|
||||
$where['uid'] = array("like","%,$uid,%");
|
||||
// $where['uid'] = array(array("like","%,$uid,%"),array("eq",""), 'or');
|
||||
$where['is_send'] = 1;
|
||||
$list = self::where($where)->field('id,user,title,content,add_time')->order("add_time desc")->limit($page*$limit,$limit)->select()->toArray();
|
||||
foreach ($list as $key => $value) {
|
||||
$list[$key]["add_time"] = date("Y-m-d H:i:s",$value["add_time"]);
|
||||
$list[$key]["is_see"] = UserNoticeSee::where("uid",$uid)->where("nid",$value["id"])->count() > 0 ? 1 : 0;
|
||||
}
|
||||
$data["list"] = $list;
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function seeNotice($uid,$nid){
|
||||
if(UserNoticeSee::where("uid",$uid)->where("nid",$nid)->count() <= 0){
|
||||
$data["nid"] = $nid;
|
||||
$data["uid"] = $uid;
|
||||
$data["add_time"] = time();
|
||||
UserNoticeSee::set($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2018/01/05
|
||||
*/
|
||||
|
||||
namespace app\routine\model\user;
|
||||
|
||||
use basic\ModelBasic;
|
||||
use service\RoutineService;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class UserRecharge extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['add_time'];
|
||||
|
||||
protected function setAddTimeAttr()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
public static function addRecharge($uid,$price,$recharge_type = 'weixin',$paid = 0)
|
||||
{
|
||||
$order_id = self::getNewOrderId($uid);
|
||||
return self::set(compact('order_id','uid','price','recharge_type','paid'));
|
||||
}
|
||||
|
||||
public static function getNewOrderId($uid = 0)
|
||||
{
|
||||
if(!$uid) return false;
|
||||
$count = (int) self::where('add_time',['>=',strtotime(date("Y-m-d"))],['<',strtotime(date("Y-m-d",strtotime('+1 day')))])->count();
|
||||
return 'wx1'.date('YmdHis',time()).(10000+$count+$uid);
|
||||
}
|
||||
|
||||
public static function jsPay($orderInfo)
|
||||
{
|
||||
return RoutineService::payRoutine(WechatUser::uidToOpenid($orderInfo['uid']),$orderInfo['order_id'],$orderInfo['price'],'user_recharge','用户充值');
|
||||
}
|
||||
|
||||
/**
|
||||
* //TODO用户充值成功后
|
||||
* @param $orderId
|
||||
*/
|
||||
public static function rechargeSuccess($orderId)
|
||||
{
|
||||
$order = self::where('order_id',$orderId)->where('paid',0)->find();
|
||||
if(!$order) return false;
|
||||
$user = User::getUserInfo($order['uid']);
|
||||
self::beginTrans();
|
||||
$res1 = self::where('order_id',$order['order_id'])->update(['paid'=>1,'pay_time'=>time()]);
|
||||
$res2 = UserBill::income('用户余额充值',$order['uid'],'now_money','recharge',$order['price'],$order['id'],$user['now_money'],'成功充值余额'.floatval($order['price']).'元');
|
||||
$res3 = User::edit(['now_money'=>bcadd($user['now_money'],$order['price'],2)],$order['uid'],'uid');
|
||||
$res = $res1 && $res2 && $res3;
|
||||
self::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2018/02/28
|
||||
*/
|
||||
|
||||
namespace app\routine\model\user;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use service\SystemConfigService;
|
||||
use think\Model;
|
||||
|
||||
class UserSign
|
||||
{
|
||||
public static function checkUserSigned($uid)
|
||||
{
|
||||
return UserBill::be(['uid'=>$uid,'add_time'=>['>',strtotime('today')],'category'=>'integral','type'=>'sign']);
|
||||
}
|
||||
|
||||
public static function userSignedCount($uid)
|
||||
{
|
||||
return self::userSignBillWhere($uid)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
* @return Model
|
||||
*/
|
||||
public static function userSignBillWhere($uid)
|
||||
{
|
||||
return UserBill::where(['uid'=>$uid,'category'=>'integral','type'=>'sign']);
|
||||
}
|
||||
|
||||
public static function sign($userInfo)
|
||||
{
|
||||
$uid = $userInfo['uid'];
|
||||
$min = SystemConfigService::get('sx_sign_min_int')?:0;
|
||||
$max = SystemConfigService::get('sx_sign_max_int')?:5;
|
||||
$integral = rand($min,$max);
|
||||
ModelBasic::beginTrans();
|
||||
$res1 = UserBill::income('用户签到',$uid,'integral','sign',$integral,0,$userInfo['integral'],'签到获得'.floatval($integral).'积分');
|
||||
$res2 = User::bcInc($uid,'integral',$integral,'uid');
|
||||
$res = $res1 && $res2;
|
||||
ModelBasic::checkTrans($res);
|
||||
if($res)
|
||||
return $integral;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/21
|
||||
*/
|
||||
|
||||
namespace app\routine\model\user;
|
||||
|
||||
use app\routine\model\store\StoreCouponUser;
|
||||
use basic\ModelBasic;
|
||||
use service\SystemConfigService;
|
||||
use traits\ModelTrait;
|
||||
/**
|
||||
* 微信用户model
|
||||
* Class WechatUser
|
||||
* @package app\routine\model\user
|
||||
*/
|
||||
class WechatUser extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
public static function getOpenId($uid = ''){
|
||||
if($uid == '') return false;
|
||||
return self::where('uid',$uid)->value('routine_openid');
|
||||
}
|
||||
/**
|
||||
* 用uid获得openid
|
||||
* @param $uid
|
||||
* @return mixed
|
||||
*/
|
||||
public static function uidToOpenid($uid)
|
||||
{
|
||||
$openid = self::where('uid',$uid)->value('routine_openid');
|
||||
return $openid;
|
||||
}
|
||||
|
||||
public static function userTakeOrderGiveCoupon($uid)
|
||||
{
|
||||
$couponId = SystemConfigService::get('store_order_give_coupon');
|
||||
if($couponId) StoreCouponUser::addUserCoupon($uid,$couponId);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user